~taylorp36/ubuntu/wily/aisleriot/bug-1490189

« back to all changes in this revision

Viewing changes to src/baize.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2011-09-26 12:54:22 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: package-import@ubuntu.com-20110926125422-fhnx2xyc0qcpgyh2
Tags: 1:3.2.0-0ubuntu1
* New upstream stable release.
  - Distribute a copy of the LGPL
  - Update card theme install info for Debian, Ubuntu & OpenSUSE
  - Build help with yelp-tools instead of gnome-doc-utils
  - Fix game restart
  - Translation updates
* debian/control: Build-depends on yelp-tools
* debian/copyright: Fixed a few lintian warnings
* 03_update_theme_install_data.patch: Dropped, applied upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright © 2008 Neil Roberts
3
 
 *
4
 
 * This program is free software: you can redistribute it and/or modify
5
 
 * it under the terms of the GNU General Public License as published by
6
 
 * the Free Software Foundation, either version 3 of the License, or
7
 
 * (at your option) any later version.
8
 
 *
9
 
 * This program is distributed in the hope that it will be useful,
10
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
 * GNU General Public License for more details.
13
 
 *
14
 
 * You should have received a copy of the GNU General Public License
15
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 
 */
17
 
 
18
 
#include <config.h>
19
 
 
20
 
#include "baize.h"
21
 
 
22
 
#include <cogl/cogl.h>
23
 
 
24
 
#include "ar-runtime.h"
25
 
 
26
 
/* Special version of ClutterTexture that repeats the texture to fill
27
 
   the entire stage. This is used to paint the baize background */
28
 
 
29
 
static void aisleriot_baize_paint (ClutterActor *actor);
30
 
 
31
 
G_DEFINE_TYPE (AisleriotBaize, aisleriot_baize, CLUTTER_TYPE_TEXTURE);
32
 
 
33
 
static void
34
 
aisleriot_baize_class_init (AisleriotBaizeClass *klass)
35
 
{
36
 
  ClutterActorClass *actor_class = (ClutterActorClass *) klass;
37
 
 
38
 
  actor_class->paint = aisleriot_baize_paint;
39
 
}
40
 
 
41
 
static void
42
 
aisleriot_baize_init (AisleriotBaize *baize)
43
 
{
44
 
  char *path;
45
 
  GError *error = NULL;
46
 
 
47
 
  path = ar_runtime_get_file (AR_RUNTIME_PIXMAP_DIRECTORY, "baize.png");
48
 
  if (!clutter_texture_set_from_file (CLUTTER_TEXTURE (baize), path, &error)) {
49
 
    g_warning ("Failed to load the baize from '%s': %s\n", path, error->message);
50
 
    g_error_free (error);
51
 
  }
52
 
 
53
 
  g_free (path);
54
 
}
55
 
 
56
 
ClutterActor *
57
 
aisleriot_baize_new (void)
58
 
{
59
 
  return g_object_new (AISLERIOT_TYPE_BAIZE, NULL);
60
 
}
61
 
 
62
 
static void
63
 
aisleriot_baize_paint (ClutterActor *actor)
64
 
{
65
 
  ClutterActor *stage;
66
 
  CoglHandle tex;
67
 
  ClutterGeometry stage_geom;
68
 
  guint tex_width, tex_height;
69
 
 
70
 
  if ((stage = clutter_actor_get_stage (actor)) == NULL)
71
 
    return;
72
 
 
73
 
  if ((tex = clutter_texture_get_cogl_texture (CLUTTER_TEXTURE (actor)))
74
 
      == COGL_INVALID_HANDLE)
75
 
    return;
76
 
 
77
 
  tex_width = cogl_texture_get_width (tex);
78
 
  tex_height = cogl_texture_get_height (tex);
79
 
 
80
 
  if (tex_width < 1 || tex_height < 1)
81
 
    return;
82
 
 
83
 
  clutter_actor_get_allocation_geometry (stage, &stage_geom);
84
 
 
85
 
  /* Repeat the texture to fill the size of the stage */
86
 
  cogl_set_source_texture (tex);
87
 
  cogl_rectangle_with_texture_coords (0, 0, stage_geom.width, stage_geom.height,
88
 
                                      0, 0,
89
 
                                      (gfloat) stage_geom.width / tex_width,
90
 
                                      (gfloat) stage_geom.height / tex_height);
91
 
}