2
* Copyright © 2008 Neil Roberts
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.
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.
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/>.
22
#include <cogl/cogl.h>
24
#include "ar-runtime.h"
26
/* Special version of ClutterTexture that repeats the texture to fill
27
the entire stage. This is used to paint the baize background */
29
static void aisleriot_baize_paint (ClutterActor *actor);
31
G_DEFINE_TYPE (AisleriotBaize, aisleriot_baize, CLUTTER_TYPE_TEXTURE);
34
aisleriot_baize_class_init (AisleriotBaizeClass *klass)
36
ClutterActorClass *actor_class = (ClutterActorClass *) klass;
38
actor_class->paint = aisleriot_baize_paint;
42
aisleriot_baize_init (AisleriotBaize *baize)
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);
57
aisleriot_baize_new (void)
59
return g_object_new (AISLERIOT_TYPE_BAIZE, NULL);
63
aisleriot_baize_paint (ClutterActor *actor)
67
ClutterGeometry stage_geom;
68
guint tex_width, tex_height;
70
if ((stage = clutter_actor_get_stage (actor)) == NULL)
73
if ((tex = clutter_texture_get_cogl_texture (CLUTTER_TEXTURE (actor)))
74
== COGL_INVALID_HANDLE)
77
tex_width = cogl_texture_get_width (tex);
78
tex_height = cogl_texture_get_height (tex);
80
if (tex_width < 1 || tex_height < 1)
83
clutter_actor_get_allocation_geometry (stage, &stage_geom);
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,
89
(gfloat) stage_geom.width / tex_width,
90
(gfloat) stage_geom.height / tex_height);