| 1 |
#include <stdlib.h> |
| 2 |
#include <gmodule.h> |
| 3 |
#include <clutter/clutter.h> |
| 4 |
|
| 5 |
/* each time the timeline animating the label completes, swap the direction */ |
| 6 |
static void |
| 7 |
timeline_completed (ClutterTimeline *timeline, |
| 8 |
gpointer user_data) |
| 9 |
{ |
| 10 |
clutter_timeline_set_direction (timeline, |
| 11 |
!clutter_timeline_get_direction (timeline)); |
| 12 |
clutter_timeline_start (timeline); |
| 13 |
} |
| 14 |
|
| 15 |
static ClutterActor *raise_actor[2]; |
| 16 |
static gboolean raise_no = 0; |
| 17 |
|
| 18 |
static gboolean |
| 19 |
raise_top (gpointer ignored G_GNUC_UNUSED) |
| 20 |
{ |
| 21 |
ClutterActor *parent = clutter_actor_get_parent (raise_actor[raise_no]); |
| 22 |
|
| 23 |
clutter_actor_set_child_above_sibling (parent, raise_actor[raise_no], NULL); |
| 24 |
raise_no = !raise_no; |
| 25 |
|
| 26 |
return G_SOURCE_CONTINUE; |
| 27 |
} |
| 28 |
|
| 29 |
static ClutterActor * |
| 30 |
clone_box (ClutterActor *original) |
| 31 |
{ |
| 32 |
gfloat width, height; |
| 33 |
ClutterActor *group; |
| 34 |
ClutterActor *clone; |
| 35 |
|
| 36 |
clutter_actor_get_size (original, &width, &height); |
| 37 |
|
| 38 |
group = clutter_actor_new (); |
| 39 |
clone = clutter_clone_new (original); |
| 40 |
clutter_actor_add_child (group, clone); |
| 41 |
clutter_actor_set_depth (clone, width / 2); |
| 42 |
|
| 43 |
clone = clutter_clone_new (original); |
| 44 |
clutter_actor_add_child (group, clone); |
| 45 |
clutter_actor_set_rotation (clone, CLUTTER_Y_AXIS, 180, width / 2, 0, 0); |
| 46 |
clutter_actor_set_depth (clone, -width / 2); |
| 47 |
|
| 48 |
clone = clutter_clone_new (original); |
| 49 |
clutter_actor_add_child (group, clone); |
| 50 |
clutter_actor_set_rotation (clone, CLUTTER_Y_AXIS, 90, 0, 0, 0); |
| 51 |
clutter_actor_set_depth (clone, width / 2); |
| 52 |
clutter_actor_set_position (clone, 0, 0); |
| 53 |
|
| 54 |
clone = clutter_clone_new (original); |
| 55 |
clutter_actor_add_child (group, clone); |
| 56 |
clutter_actor_set_rotation (clone, CLUTTER_Y_AXIS, 90, 0, 0, 0); |
| 57 |
clutter_actor_set_depth (clone, width / 2); |
| 58 |
clutter_actor_set_position (clone, width, 0); |
| 59 |
|
| 60 |
clone = clutter_clone_new (original); |
| 61 |
clutter_actor_add_child (group, clone); |
| 62 |
clutter_actor_set_rotation (clone, CLUTTER_X_AXIS, 90, 0, 0, 0); |
| 63 |
clutter_actor_set_depth (clone, -width / 2); |
| 64 |
clutter_actor_set_position (clone, 0, height); |
| 65 |
|
| 66 |
clone = clutter_clone_new (original); |
| 67 |
clutter_actor_add_child (group, clone); |
| 68 |
clutter_actor_set_rotation (clone, CLUTTER_X_AXIS, 90, 0, 0, 0); |
| 69 |
clutter_actor_set_depth (clone, -width / 2); |
| 70 |
clutter_actor_set_position (clone, 0, 0); |
| 71 |
|
| 72 |
return group; |
| 73 |
} |
| 74 |
|
| 75 |
static ClutterActor * |
| 76 |
janus_group (const gchar *front_text, |
| 77 |
const gchar *back_text) |
| 78 |
{ |
| 79 |
ClutterActor *group, *rectangle, *front, *back; |
| 80 |
gfloat width, height; |
| 81 |
gfloat width2, height2; |
| 82 |
|
| 83 |
group = clutter_actor_new (); |
| 84 |
rectangle = clutter_actor_new (); |
| 85 |
clutter_actor_set_background_color (rectangle, CLUTTER_COLOR_White); |
| 86 |
front = clutter_text_new_with_text ("Sans 50px", front_text); |
| 87 |
back = clutter_text_new_with_text ("Sans 50px", back_text); |
| 88 |
clutter_text_set_color (CLUTTER_TEXT (front), CLUTTER_COLOR_Red); |
| 89 |
clutter_text_set_color (CLUTTER_TEXT (back), CLUTTER_COLOR_Green); |
| 90 |
|
| 91 |
clutter_actor_get_size (front, &width, &height); |
| 92 |
clutter_actor_get_size (back, &width2, &height2); |
| 93 |
|
| 94 |
if (width2 > width) |
| 95 |
width = width2; |
| 96 |
|
| 97 |
if (height2 > height) |
| 98 |
height = height2; |
| 99 |
|
| 100 |
clutter_actor_set_size (rectangle, width, height); |
| 101 |
clutter_actor_set_rotation (back, CLUTTER_Y_AXIS, 180, width / 2, 0, 0); |
| 102 |
|
| 103 |
clutter_actor_add_child (group, back); |
| 104 |
clutter_actor_add_child (group, rectangle); |
| 105 |
clutter_actor_add_child (group, front); |
| 106 |
|
| 107 |
return group; |
| 108 |
} |
| 109 |
|
| 110 |
G_MODULE_EXPORT gint |
| 111 |
test_depth_main (int argc, char *argv[]) |
| 112 |
{ |
| 113 |
ClutterTimeline *timeline; |
| 114 |
ClutterBehaviour *d_behave; |
| 115 |
ClutterBehaviour *r_behave; |
| 116 |
ClutterActor *stage; |
| 117 |
ClutterActor *group, *hand, *label, *rect, *janus, *box; |
| 118 |
GError *error; |
| 119 |
|
| 120 |
if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) |
| 121 |
return EXIT_FAILURE; |
| 122 |
|
| 123 |
stage = clutter_stage_new (); |
| 124 |
clutter_stage_set_title (CLUTTER_STAGE (stage), "Depth Test"); |
| 125 |
clutter_actor_set_background_color (stage, CLUTTER_COLOR_Aluminium2); |
| 126 |
g_signal_connect (stage, |
| 127 |
"destroy", G_CALLBACK (clutter_main_quit), |
| 128 |
NULL); |
| 129 |
g_signal_connect (stage, |
| 130 |
"button-press-event", G_CALLBACK (clutter_main_quit), |
| 131 |
NULL); |
| 132 |
|
| 133 |
group = clutter_actor_new (); |
| 134 |
clutter_actor_add_child (stage, group); |
| 135 |
|
| 136 |
label = clutter_text_new_with_text ("Mono 26", "Clutter"); |
| 137 |
clutter_actor_set_position (label, 120, 200); |
| 138 |
clutter_actor_add_child (stage, label); |
| 139 |
|
| 140 |
error = NULL; |
| 141 |
hand = clutter_texture_new_from_file (TESTS_DATADIR |
| 142 |
G_DIR_SEPARATOR_S |
| 143 |
"redhand.png", |
| 144 |
&error); |
| 145 |
if (error) |
| 146 |
g_error ("Unable to load redhand.png: %s", error->message); |
| 147 |
clutter_actor_set_position (hand, 240, 100); |
| 148 |
|
| 149 |
rect = clutter_rectangle_new_with_color (CLUTTER_COLOR_Black); |
| 150 |
clutter_actor_set_position (rect, 340, 100); |
| 151 |
clutter_actor_set_size (rect, 200, 200); |
| 152 |
clutter_actor_set_opacity (rect, 128); |
| 153 |
|
| 154 |
clutter_actor_add_child (group, hand); |
| 155 |
clutter_actor_add_child (group, rect); |
| 156 |
|
| 157 |
timeline = clutter_timeline_new (3000); |
| 158 |
g_signal_connect (timeline, |
| 159 |
"completed", G_CALLBACK (timeline_completed), |
| 160 |
NULL); |
| 161 |
|
| 162 |
d_behave = |
| 163 |
clutter_behaviour_depth_new (clutter_alpha_new_full (timeline, |
| 164 |
CLUTTER_LINEAR), |
| 165 |
-100, 100); |
| 166 |
clutter_behaviour_apply (d_behave, label); |
| 167 |
|
| 168 |
/* add two faced actor */ |
| 169 |
janus = janus_group ("GREEN", "RED"); |
| 170 |
clutter_container_add_actor (CLUTTER_CONTAINER (stage), janus); |
| 171 |
clutter_actor_set_position (janus, 300, 350); |
| 172 |
|
| 173 |
r_behave = |
| 174 |
clutter_behaviour_rotate_new (clutter_alpha_new_full (timeline, |
| 175 |
CLUTTER_LINEAR), |
| 176 |
CLUTTER_Y_AXIS, |
| 177 |
CLUTTER_ROTATE_CW, |
| 178 |
0, 360); |
| 179 |
clutter_behaviour_apply (r_behave, janus); |
| 180 |
|
| 181 |
/* add hand box */ |
| 182 |
box = clone_box (hand); |
| 183 |
clutter_actor_add_child (stage, box); |
| 184 |
clutter_actor_set_position (box, 200, 250); |
| 185 |
clutter_actor_set_scale (box, 0.5, 0.5); |
| 186 |
clutter_actor_set_rotation (box, CLUTTER_X_AXIS, 45, 0, 0, 0); |
| 187 |
clutter_actor_set_opacity (box, 0x44); |
| 188 |
|
| 189 |
r_behave = |
| 190 |
clutter_behaviour_rotate_new (clutter_alpha_new_full (timeline, |
| 191 |
CLUTTER_LINEAR), |
| 192 |
CLUTTER_Y_AXIS, |
| 193 |
CLUTTER_ROTATE_CW, |
| 194 |
0, 360); |
| 195 |
clutter_behaviour_apply (r_behave, box); |
| 196 |
|
| 197 |
clutter_actor_show (stage); |
| 198 |
|
| 199 |
clutter_timeline_start (timeline); |
| 200 |
|
| 201 |
raise_actor[0] = rect; |
| 202 |
raise_actor[1] = hand; |
| 203 |
clutter_threads_add_timeout (2000, raise_top, NULL); |
| 204 |
|
| 205 |
clutter_main (); |
| 206 |
|
| 207 |
g_object_unref (d_behave); |
| 208 |
g_object_unref (timeline); |
| 209 |
|
| 210 |
return EXIT_SUCCESS; |
| 211 |
} |