Use a 9 grid for the constraints test

Let's complicate the interactive constraints test a little bit by adding
more actors and animating two constraints at a time.
This commit is contained in:
Emmanuele Bassi 2010-05-19 18:17:49 +01:00
parent 6457f66976
commit 5d1b18669b

View File

@ -3,10 +3,23 @@
#include <clutter/clutter.h> #include <clutter/clutter.h>
#define H_PADDING 32 #define H_PADDING 32
#define V_PADDING 32
static ClutterActor *center_rect = NULL; enum
static ClutterActor *left_rect = NULL; {
static ClutterActor *right_rect = NULL; NorthWest, North, NorthEast,
West, Center, East,
SouthWest, South, SouthEast,
N_RECTS
};
static ClutterActor *rects[N_RECTS] = { NULL, };
static const gchar *colors[N_RECTS] = {
"#8ae234", "#73d216", "#4e9a06",
"#729fcf", "#3465a4", "#204a87",
"#ef2929", "#cc0000", "#a40000"
};
static gboolean is_expanded = FALSE; static gboolean is_expanded = FALSE;
@ -17,35 +30,82 @@ on_button_release (ClutterActor *actor,
{ {
if (!is_expanded) if (!is_expanded)
{ {
gfloat left_offset = (clutter_actor_get_width (left_rect) + H_PADDING) gfloat north_offset, south_offset;
* -1.0f; gfloat west_offset, east_offset;
gfloat right_offset = clutter_actor_get_width (right_rect) + H_PADDING;
clutter_actor_animate (center_rect, CLUTTER_LINEAR, 500, north_offset = (clutter_actor_get_height (rects[Center]) + V_PADDING)
* -1.0f;
south_offset = (clutter_actor_get_height (rects[Center]) + V_PADDING);
west_offset = (clutter_actor_get_width (rects[Center]) + H_PADDING)
* -1.0f;
east_offset = (clutter_actor_get_width (rects[Center]) + H_PADDING);
clutter_actor_animate (rects[Center], CLUTTER_LINEAR, 500,
"opacity", 128, "opacity", 128,
NULL); NULL);
clutter_actor_animate (left_rect, CLUTTER_EASE_OUT_CUBIC, 500,
clutter_actor_animate (rects[NorthWest], CLUTTER_EASE_OUT_CUBIC, 500,
"opacity", 255, "opacity", 255,
"@constraints.x-bind.offset", left_offset, "@constraints.x-bind.offset", west_offset,
"@constraints.y-bind.offset", north_offset,
NULL); NULL);
clutter_actor_animate (right_rect, CLUTTER_EASE_OUT_CUBIC, 500, clutter_actor_animate (rects[North], CLUTTER_EASE_OUT_CUBIC, 500,
"opacity", 255, "opacity", 255,
"@constraints.x-bind.offset", right_offset, "@constraints.y-bind.offset", north_offset,
NULL);
clutter_actor_animate (rects[NorthEast], CLUTTER_EASE_OUT_CUBIC, 500,
"opacity", 255,
"@constraints.x-bind.offset", east_offset,
"@constraints.y-bind.offset", north_offset,
NULL);
clutter_actor_animate (rects[West], CLUTTER_EASE_OUT_CUBIC, 500,
"opacity", 255,
"@constraints.x-bind.offset", west_offset,
NULL);
clutter_actor_animate (rects[Center], CLUTTER_LINEAR, 500,
"opacity", 128,
NULL);
clutter_actor_animate (rects[East], CLUTTER_EASE_OUT_CUBIC, 500,
"opacity", 255,
"@constraints.x-bind.offset", east_offset,
NULL);
clutter_actor_animate (rects[SouthWest], CLUTTER_EASE_OUT_CUBIC, 500,
"opacity", 255,
"@constraints.x-bind.offset", west_offset,
"@constraints.y-bind.offset", south_offset,
NULL);
clutter_actor_animate (rects[South], CLUTTER_EASE_OUT_CUBIC, 500,
"opacity", 255,
"@constraints.y-bind.offset", south_offset,
NULL);
clutter_actor_animate (rects[SouthEast], CLUTTER_EASE_OUT_CUBIC, 500,
"opacity", 255,
"@constraints.x-bind.offset", east_offset,
"@constraints.y-bind.offset", south_offset,
NULL); NULL);
} }
else else
{ {
clutter_actor_animate (center_rect, CLUTTER_LINEAR, 500, gint i;
clutter_actor_animate (rects[Center], CLUTTER_LINEAR, 500,
"opacity", 255, "opacity", 255,
NULL); NULL);
clutter_actor_animate (left_rect, CLUTTER_EASE_OUT_CUBIC, 500,
"opacity", 0, for (i = NorthWest; i < N_RECTS; i++)
"@constraints.x-bind.offset", 0.0f, {
NULL); if (i == Center)
clutter_actor_animate (right_rect, CLUTTER_EASE_OUT_CUBIC, 500, continue;
"opacity", 0,
"@constraints.x-bind.offset", 0.0f, clutter_actor_animate (rects[i], CLUTTER_EASE_OUT_CUBIC, 500,
NULL); "opacity", 0,
"@constraints.x-bind.offset", 0.0f,
"@constraints.y-bind.offset", 0.0f,
NULL);
}
} }
is_expanded = !is_expanded; is_expanded = !is_expanded;
@ -57,8 +117,9 @@ G_MODULE_EXPORT int
test_constraints_main (int argc, char *argv[]) test_constraints_main (int argc, char *argv[])
{ {
ClutterActor *stage, *rect; ClutterActor *stage, *rect;
ClutterColor rect_color;
ClutterConstraint *constraint; ClutterConstraint *constraint;
ClutterColor rect_color;
gint i;
clutter_init (&argc, &argv); clutter_init (&argc, &argv);
@ -68,7 +129,7 @@ test_constraints_main (int argc, char *argv[])
clutter_actor_set_size (stage, 800, 600); clutter_actor_set_size (stage, 800, 600);
/* main rect */ /* main rect */
clutter_color_from_string (&rect_color, "#73d216ff"); clutter_color_from_string (&rect_color, "#3465a4");
rect = clutter_rectangle_new (); rect = clutter_rectangle_new ();
g_signal_connect (rect, "button-release-event", g_signal_connect (rect, "button-release-event",
G_CALLBACK (on_button_release), G_CALLBACK (on_button_release),
@ -86,43 +147,30 @@ test_constraints_main (int argc, char *argv[])
clutter_actor_meta_set_name (CLUTTER_ACTOR_META (constraint), "y-align"); clutter_actor_meta_set_name (CLUTTER_ACTOR_META (constraint), "y-align");
clutter_actor_add_constraint (rect, constraint); clutter_actor_add_constraint (rect, constraint);
center_rect = rect; rects[Center] = rect;
/* left rectangle */ for (i = 0; i < N_RECTS; i++)
clutter_color_from_string (&rect_color, "#cc0000ff"); {
rect = clutter_rectangle_new (); if (i == Center)
clutter_rectangle_set_color (CLUTTER_RECTANGLE (rect), &rect_color); continue;
clutter_actor_set_size (rect, 128, 128);
clutter_actor_set_opacity (rect, 0);
clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect);
constraint = clutter_bind_constraint_new (center_rect, CLUTTER_BIND_X, 0.0f); clutter_color_from_string (&rect_color, colors[i]);
clutter_actor_meta_set_name (CLUTTER_ACTOR_META (constraint), "x-bind"); rect = clutter_rectangle_new ();
clutter_actor_add_constraint (rect, constraint); clutter_rectangle_set_color (CLUTTER_RECTANGLE (rect), &rect_color);
clutter_actor_set_size (rect, 128, 128);
clutter_actor_set_opacity (rect, 0);
clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect);
constraint = clutter_align_constraint_new (stage, CLUTTER_ALIGN_Y_AXIS, 0.5); constraint = clutter_bind_constraint_new (rects[Center], CLUTTER_BIND_X, 0.0);
clutter_actor_meta_set_name (CLUTTER_ACTOR_META (constraint), "y-align"); clutter_actor_meta_set_name (CLUTTER_ACTOR_META (constraint), "x-bind");
clutter_actor_add_constraint (rect, constraint); clutter_actor_add_constraint (rect, constraint);
left_rect = rect; constraint = clutter_bind_constraint_new (rects[Center], CLUTTER_BIND_Y, 0.0);
clutter_actor_meta_set_name (CLUTTER_ACTOR_META (constraint), "y-bind");
clutter_actor_add_constraint (rect, constraint);
/* right rectangle */ rects[i] = rect;
clutter_color_from_string (&rect_color, "#3465a4ff"); }
rect = clutter_rectangle_new ();
clutter_rectangle_set_color (CLUTTER_RECTANGLE (rect), &rect_color);
clutter_actor_set_size (rect, 128, 128);
clutter_actor_set_opacity (rect, 0);
clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect);
constraint = clutter_bind_constraint_new (center_rect, CLUTTER_BIND_X, 0.0f);
clutter_actor_meta_set_name (CLUTTER_ACTOR_META (constraint), "x-bind");
clutter_actor_add_constraint (rect, constraint);
constraint = clutter_align_constraint_new (stage, CLUTTER_ALIGN_Y_AXIS, 0.5);
clutter_actor_meta_set_name (CLUTTER_ACTOR_META (constraint), "y-align");
clutter_actor_add_constraint (rect, constraint);
right_rect = rect;
clutter_actor_show (stage); clutter_actor_show (stage);