3
#include <cairo/cairo.h>
4
#include <clutter/clutter.h>
7
make_background (const ClutterColor *color,
11
ClutterActor *tex = clutter_cairo_texture_new (width, height);
12
cairo_t *cr = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE (tex));
16
#define BG_ROUND_RADIUS 12
20
cairo_move_to (cr, BG_ROUND_RADIUS, y);
21
cairo_line_to (cr, width - BG_ROUND_RADIUS, y);
22
cairo_curve_to (cr, width, y, width, y, width, BG_ROUND_RADIUS);
23
cairo_line_to (cr, width, height - BG_ROUND_RADIUS);
24
cairo_curve_to (cr, width, height, width, height, width - BG_ROUND_RADIUS, height);
25
cairo_line_to (cr, BG_ROUND_RADIUS, height);
26
cairo_curve_to (cr, x, height, x, height, x, height - BG_ROUND_RADIUS);
27
cairo_line_to (cr, x, BG_ROUND_RADIUS);
28
cairo_curve_to (cr, x, y, x, y, BG_ROUND_RADIUS, y);
30
cairo_close_path (cr);
32
clutter_cairo_set_source_color (cr, color);
40
cairo_move_to (cr, BG_ROUND_RADIUS, y);
41
cairo_line_to (cr, width - BG_ROUND_RADIUS, y);
42
cairo_curve_to (cr, width, y, width, y, width, BG_ROUND_RADIUS);
43
cairo_line_to (cr, width, height - BG_ROUND_RADIUS);
44
cairo_curve_to (cr, width, height, width, height, width - BG_ROUND_RADIUS, height);
45
cairo_line_to (cr, BG_ROUND_RADIUS, height);
46
cairo_curve_to (cr, x, height, x, height, x, height - BG_ROUND_RADIUS);
47
cairo_line_to (cr, x, BG_ROUND_RADIUS);
48
cairo_curve_to (cr, x, y, x, y, BG_ROUND_RADIUS, y);
50
cairo_close_path (cr);
52
pat = cairo_pattern_create_linear (0, 0, 0, height);
53
cairo_pattern_add_color_stop_rgba (pat, 1, .85, .85, .85, 1);
54
cairo_pattern_add_color_stop_rgba (pat, .95, 1, 1, 1, 1);
55
cairo_pattern_add_color_stop_rgba (pat, .05, 1, 1, 1, 1);
56
cairo_pattern_add_color_stop_rgba (pat, 0, .85, .85, .85, 1);
58
cairo_set_source (cr, pat);
61
cairo_pattern_destroy (pat);
64
#undef BG_ROUND_RADIUS
70
on_box_enter (ClutterActor *box,
74
clutter_actor_animate (emblem, CLUTTER_LINEAR, 150,
82
on_box_leave (ClutterActor *box,
86
clutter_actor_animate (emblem, CLUTTER_LINEAR, 150,
94
test_bin_layout_main (int argc, char *argv[])
96
ClutterActor *stage, *box, *rect;
97
ClutterLayoutManager *layout;
98
ClutterColor stage_color = { 0xe0, 0xf2, 0xfc, 0xff };
99
ClutterColor bg_color = { 0xcc, 0xcc, 0xcc, 0x99 };
102
clutter_init (&argc, &argv);
104
stage = clutter_stage_get_default ();
105
clutter_stage_set_title (CLUTTER_STAGE (stage), "Box test");
106
clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);
107
clutter_actor_set_size (stage, 640, 480);
109
layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
110
CLUTTER_BIN_ALIGNMENT_CENTER);
112
box = clutter_box_new (layout);
113
clutter_container_add_actor (CLUTTER_CONTAINER (stage), box);
114
clutter_actor_set_anchor_point_from_gravity (box, CLUTTER_GRAVITY_CENTER);
115
clutter_actor_set_position (box, 320, 240);
116
clutter_actor_set_reactive (box, TRUE);
117
clutter_actor_set_name (box, "box");
119
rect = make_background (&bg_color, 200, 200);
121
/* first method: use clutter_box_pack() */
122
clutter_box_pack (CLUTTER_BOX (box), rect,
123
"x-align", CLUTTER_BIN_ALIGNMENT_FILL,
124
"y-align", CLUTTER_BIN_ALIGNMENT_FILL,
127
clutter_actor_lower_bottom (rect);
128
clutter_actor_set_name (rect, "background");
136
file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL);
137
tex = clutter_texture_new_from_file (file, &error);
139
g_error ("Unable to create texture: %s", error->message);
141
clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (tex), TRUE);
143
/* second method: use clutter_bin_layout_add() */
144
clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout), tex,
145
CLUTTER_BIN_ALIGNMENT_CENTER,
146
CLUTTER_BIN_ALIGNMENT_CENTER);
148
clutter_actor_raise (tex, rect);
149
clutter_actor_set_width (tex, 175);
150
clutter_actor_set_name (tex, "texture");
155
color = clutter_color_new (g_random_int_range (0, 255),
156
g_random_int_range (0, 255),
157
g_random_int_range (0, 255),
160
rect = clutter_rectangle_new_with_color (color);
162
/* third method: container_add() and set_alignment() */
163
clutter_container_add_actor (CLUTTER_CONTAINER (box), rect);
164
clutter_bin_layout_set_alignment (CLUTTER_BIN_LAYOUT (layout), rect,
165
CLUTTER_BIN_ALIGNMENT_END,
166
CLUTTER_BIN_ALIGNMENT_END);
168
clutter_actor_set_size (rect, 50, 50);
169
clutter_actor_set_opacity (rect, 0);
170
clutter_actor_raise_top (rect);
171
clutter_actor_set_name (rect, "emblem");
174
g_signal_connect (box,
175
"enter-event", G_CALLBACK (on_box_enter),
177
g_signal_connect (box,
178
"leave-event", G_CALLBACK (on_box_leave),
181
clutter_actor_show_all (stage);
185
clutter_color_free (color);