| 1 |
#include <stdlib.h> |
| 2 |
#include <gmodule.h> |
| 3 |
#include <clutter/clutter.h> |
| 4 |
|
| 5 |
static const ClutterGravity gravities[] = { |
| 6 |
CLUTTER_GRAVITY_NORTH_EAST, |
| 7 |
CLUTTER_GRAVITY_NORTH, |
| 8 |
CLUTTER_GRAVITY_NORTH_WEST, |
| 9 |
CLUTTER_GRAVITY_WEST, |
| 10 |
CLUTTER_GRAVITY_SOUTH_WEST, |
| 11 |
CLUTTER_GRAVITY_SOUTH, |
| 12 |
CLUTTER_GRAVITY_SOUTH_EAST, |
| 13 |
CLUTTER_GRAVITY_EAST, |
| 14 |
CLUTTER_GRAVITY_CENTER, |
| 15 |
CLUTTER_GRAVITY_NONE |
| 16 |
}; |
| 17 |
|
| 18 |
static gint gindex = 0; |
| 19 |
static ClutterActor *label; |
| 20 |
|
| 21 |
static void |
| 22 |
set_next_gravity (ClutterActor *actor) |
| 23 |
{ |
| 24 |
ClutterGravity gravity = gravities[gindex]; |
| 25 |
GEnumClass *eclass; |
| 26 |
GEnumValue *evalue; |
| 27 |
|
| 28 |
clutter_actor_move_anchor_point_from_gravity (actor, gravities[gindex]); |
| 29 |
|
| 30 |
eclass = g_type_class_ref (CLUTTER_TYPE_GRAVITY); |
| 31 |
evalue = g_enum_get_value (eclass, gravity); |
| 32 |
clutter_text_set_text (CLUTTER_TEXT (label), evalue->value_nick); |
| 33 |
g_type_class_unref (eclass); |
| 34 |
|
| 35 |
if (++gindex >= G_N_ELEMENTS (gravities)) |
| 36 |
gindex = 0; |
| 37 |
} |
| 38 |
|
| 39 |
static gdouble |
| 40 |
my_ramp_func (ClutterAlpha *alpha, |
| 41 |
gpointer unused) |
| 42 |
{ |
| 43 |
ClutterTimeline *timeline = clutter_alpha_get_timeline (alpha); |
| 44 |
|
| 45 |
return clutter_timeline_get_progress (timeline); |
| 46 |
} |
| 47 |
|
| 48 |
G_MODULE_EXPORT int |
| 49 |
test_scale_main (int argc, char *argv[]) |
| 50 |
{ |
| 51 |
ClutterActor *stage, *rect; |
| 52 |
ClutterColor rect_color = { 0xff, 0xff, 0xff, 0x99 }; |
| 53 |
ClutterTimeline *timeline; |
| 54 |
ClutterAlpha *alpha; |
| 55 |
ClutterBehaviour *behave; |
| 56 |
|
| 57 |
if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) |
| 58 |
return 1; |
| 59 |
|
| 60 |
stage = clutter_stage_new (); |
| 61 |
clutter_stage_set_title (CLUTTER_STAGE (stage), "Scaling"); |
| 62 |
clutter_actor_set_background_color (stage, CLUTTER_COLOR_Black); |
| 63 |
clutter_actor_set_size (stage, 300, 300); |
| 64 |
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); |
| 65 |
|
| 66 |
rect = clutter_rectangle_new_with_color (&rect_color); |
| 67 |
clutter_actor_set_size (rect, 100, 100); |
| 68 |
clutter_actor_set_position (rect, 100, 100); |
| 69 |
|
| 70 |
clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect); |
| 71 |
|
| 72 |
label = clutter_text_new_with_text ("Sans 20px", ""); |
| 73 |
clutter_text_set_color (CLUTTER_TEXT (label), CLUTTER_COLOR_White); |
| 74 |
clutter_actor_set_position (label, |
| 75 |
clutter_actor_get_x (rect), |
| 76 |
clutter_actor_get_y (rect) |
| 77 |
+ clutter_actor_get_height (rect)); |
| 78 |
|
| 79 |
clutter_container_add_actor (CLUTTER_CONTAINER (stage), label); |
| 80 |
|
| 81 |
rect_color.alpha = 0xff; |
| 82 |
rect = clutter_rectangle_new_with_color (&rect_color); |
| 83 |
clutter_actor_set_position (rect, 100, 100); |
| 84 |
clutter_actor_set_size (rect, 100, 100); |
| 85 |
set_next_gravity (rect); |
| 86 |
|
| 87 |
clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect); |
| 88 |
|
| 89 |
timeline = clutter_timeline_new (750); |
| 90 |
alpha = clutter_alpha_new_with_func (timeline, |
| 91 |
my_ramp_func, |
| 92 |
NULL, NULL); |
| 93 |
|
| 94 |
behave = clutter_behaviour_scale_new (alpha, |
| 95 |
0.0, 0.0, /* scale start */ |
| 96 |
1.0, 1.0); /* scale end */ |
| 97 |
|
| 98 |
clutter_behaviour_apply (behave, rect); |
| 99 |
|
| 100 |
clutter_timeline_set_repeat_count (timeline, -1); |
| 101 |
g_signal_connect_swapped (timeline, "completed", |
| 102 |
G_CALLBACK (set_next_gravity), rect); |
| 103 |
clutter_timeline_start (timeline); |
| 104 |
|
| 105 |
clutter_actor_show_all (stage); |
| 106 |
|
| 107 |
clutter_main(); |
| 108 |
|
| 109 |
g_object_unref (timeline); |
| 110 |
g_object_unref (behave); |
| 111 |
|
| 112 |
return EXIT_SUCCESS; |
| 113 |
} |
| 114 |
|
| 115 |
G_MODULE_EXPORT const char * |
| 116 |
test_scale_describe (void) |
| 117 |
{ |
| 118 |
return "Scaling animation and scaling center changes"; |
| 119 |
} |