interactive/stage-sizing: Clean up

This commit is contained in:
Emmanuele Bassi 2012-04-10 12:12:28 +01:00
parent f6da5ea616
commit 612b714149

View File

@ -6,7 +6,7 @@ static gboolean
fullscreen_clicked_cb (ClutterStage *stage)
{
clutter_stage_set_fullscreen (stage, !clutter_stage_get_fullscreen (stage));
return TRUE;
return CLUTTER_EVENT_STOP;
}
static gboolean
@ -14,7 +14,7 @@ resize_clicked_cb (ClutterStage *stage)
{
clutter_stage_set_user_resizable (stage,
!clutter_stage_get_user_resizable (stage));
return TRUE;
return CLUTTER_EVENT_STOP;
}
static gboolean
@ -23,7 +23,7 @@ shrink_clicked_cb (ClutterActor *stage)
gfloat width, height;
clutter_actor_get_size (stage, &width, &height);
clutter_actor_set_size (stage, MAX (0, width - 10.f), MAX (0, height - 10.f));
return TRUE;
return CLUTTER_EVENT_STOP;
}
static gboolean
@ -32,14 +32,30 @@ expand_clicked_cb (ClutterActor *stage)
gfloat width, height;
clutter_actor_get_size (stage, &width, &height);
clutter_actor_set_size (stage, width + 10.f, height + 10.f);
return TRUE;
return CLUTTER_EVENT_STOP;
}
static void
on_fullscreen (ClutterStage *stage)
{
float width, height;
gboolean is_fullscreen;
is_fullscreen = clutter_stage_get_fullscreen (stage);
clutter_actor_get_size (CLUTTER_ACTOR (stage), &width, &height);
g_print ("Stage size [%s]: %d x %d\n",
is_fullscreen ? "fullscreen" : "not fullscreen",
(int) width,
(int) height);
}
G_MODULE_EXPORT int
test_stage_sizing_main (int argc, char *argv[])
{
gfloat width;
ClutterActor *stage, *rect, *label;
ClutterActor *stage, *rect, *label, *box;
ClutterMargin margin = { 12.f, 12.f, 6.f, 6.f };
if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
return 1;
@ -47,61 +63,69 @@ test_stage_sizing_main (int argc, char *argv[])
stage = clutter_stage_new ();
clutter_stage_set_title (CLUTTER_STAGE (stage), "Stage Sizing");
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
g_signal_connect_after (stage, "notify::fullscreen-set", G_CALLBACK (on_fullscreen), NULL);
label = clutter_text_new_with_text ("Sans 16", "Toggle fullscreen");
rect = clutter_rectangle_new_with_color (CLUTTER_COLOR_LightScarletRed);
clutter_actor_set_size (rect,
clutter_actor_get_width (label) + 20,
clutter_actor_get_height (label) + 20);
clutter_container_add (CLUTTER_CONTAINER (stage), rect, label, NULL);
clutter_actor_set_position (label, 10, 10);
box = clutter_actor_new ();
clutter_actor_set_layout_manager (box, clutter_box_layout_new ());
clutter_actor_add_constraint (box, clutter_align_constraint_new (stage, CLUTTER_ALIGN_BOTH, 0.5));
clutter_actor_add_child (stage, box);
rect = clutter_actor_new ();
clutter_actor_set_layout_manager (rect,
clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
CLUTTER_BIN_ALIGNMENT_CENTER));
clutter_actor_set_background_color (rect, CLUTTER_COLOR_LightScarletRed);
clutter_actor_set_reactive (rect, TRUE);
g_signal_connect_swapped (rect, "button-press-event",
G_CALLBACK (fullscreen_clicked_cb), stage);
width = clutter_actor_get_width (rect);
G_CALLBACK (fullscreen_clicked_cb),
stage);
label = clutter_text_new_with_text ("Sans 16", "Toggle fullscreen");
clutter_actor_set_margin (label, &margin);
clutter_actor_add_child (rect, label);
clutter_actor_add_child (box, rect);
label = clutter_text_new_with_text ("Sans 16", "Toggle resizable");
rect = clutter_rectangle_new_with_color (CLUTTER_COLOR_Chameleon);
clutter_actor_set_size (rect,
clutter_actor_get_width (label) + 20,
clutter_actor_get_height (label) + 20);
clutter_container_add (CLUTTER_CONTAINER (stage), rect, label, NULL);
clutter_actor_set_x (rect, width);
clutter_actor_set_position (label, 10 + width, 10);
rect = clutter_actor_new ();
clutter_actor_set_layout_manager (rect,
clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
CLUTTER_BIN_ALIGNMENT_CENTER));
clutter_actor_set_background_color (rect, CLUTTER_COLOR_Chameleon);
clutter_actor_set_reactive (rect, TRUE);
g_signal_connect_swapped (rect, "button-press-event",
G_CALLBACK (resize_clicked_cb), stage);
width += clutter_actor_get_width (rect);
label = clutter_text_new_with_text ("Sans 16", "Toggle resizable");
clutter_actor_set_margin (label, &margin);
clutter_actor_add_child (rect, label);
clutter_actor_add_child (box, rect);
label = clutter_text_new_with_text ("Sans 16", "Shrink");
rect = clutter_rectangle_new_with_color (CLUTTER_COLOR_SkyBlue);
clutter_actor_set_size (rect,
clutter_actor_get_width (label) + 20,
clutter_actor_get_height (label) + 20);
clutter_container_add (CLUTTER_CONTAINER (stage), rect, label, NULL);
clutter_actor_set_x (rect, width);
clutter_actor_set_position (label, 10 + width, 10);
rect = clutter_actor_new ();
clutter_actor_set_layout_manager (rect,
clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
CLUTTER_BIN_ALIGNMENT_CENTER));
clutter_actor_set_background_color (rect, CLUTTER_COLOR_SkyBlue);
clutter_actor_set_reactive (rect, TRUE);
g_signal_connect_swapped (rect, "button-press-event",
G_CALLBACK (shrink_clicked_cb), stage);
width += clutter_actor_get_width (rect);
label = clutter_text_new_with_text ("Sans 16", "Shrink");
clutter_actor_set_margin (label, &margin);
clutter_actor_add_child (rect, label);
clutter_actor_add_child (box, rect);
label = clutter_text_new_with_text ("Sans 16", "Expand");
rect = clutter_rectangle_new_with_color (CLUTTER_COLOR_Butter);
clutter_actor_set_size (rect,
clutter_actor_get_width (label) + 20,
clutter_actor_get_height (label) + 20);
clutter_container_add (CLUTTER_CONTAINER (stage), rect, label, NULL);
clutter_actor_set_x (rect, width);
clutter_actor_set_position (label, 10 + width, 10);
rect = clutter_actor_new ();
clutter_actor_set_layout_manager (rect,
clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
CLUTTER_BIN_ALIGNMENT_CENTER));
clutter_actor_set_background_color (rect, CLUTTER_COLOR_Butter);
clutter_actor_set_reactive (rect, TRUE);
g_signal_connect_swapped (rect, "button-press-event",
G_CALLBACK (expand_clicked_cb), stage);
width += clutter_actor_get_width (rect);
label = clutter_text_new_with_text ("Sans 16", "Expand");
clutter_actor_set_margin (label, &margin);
clutter_actor_add_child (rect, label);
clutter_actor_add_child (box, rect);
clutter_stage_set_minimum_size (CLUTTER_STAGE (stage),
width,
clutter_actor_get_height (rect));
clutter_actor_get_width (box),
clutter_actor_get_height (box));
clutter_actor_show (stage);