| 1 |
#include <stdlib.h> |
| 2 |
#include <gmodule.h> |
| 3 |
#include <clutter/clutter.h> |
| 4 |
|
| 5 |
static gboolean |
| 6 |
fullscreen_clicked_cb (ClutterStage *stage) |
| 7 |
{ |
| 8 |
clutter_stage_set_fullscreen (stage, !clutter_stage_get_fullscreen (stage)); |
| 9 |
return CLUTTER_EVENT_STOP; |
| 10 |
} |
| 11 |
|
| 12 |
static gboolean |
| 13 |
resize_clicked_cb (ClutterStage *stage) |
| 14 |
{ |
| 15 |
clutter_stage_set_user_resizable (stage, |
| 16 |
!clutter_stage_get_user_resizable (stage)); |
| 17 |
return CLUTTER_EVENT_STOP; |
| 18 |
} |
| 19 |
|
| 20 |
static gboolean |
| 21 |
shrink_clicked_cb (ClutterActor *stage) |
| 22 |
{ |
| 23 |
gfloat width, height; |
| 24 |
clutter_actor_get_size (stage, &width, &height); |
| 25 |
clutter_actor_set_size (stage, MAX (0, width - 10.f), MAX (0, height - 10.f)); |
| 26 |
return CLUTTER_EVENT_STOP; |
| 27 |
} |
| 28 |
|
| 29 |
static gboolean |
| 30 |
expand_clicked_cb (ClutterActor *stage) |
| 31 |
{ |
| 32 |
gfloat width, height; |
| 33 |
clutter_actor_get_size (stage, &width, &height); |
| 34 |
clutter_actor_set_size (stage, width + 10.f, height + 10.f); |
| 35 |
return CLUTTER_EVENT_STOP; |
| 36 |
} |
| 37 |
|
| 38 |
static void |
| 39 |
on_fullscreen (ClutterStage *stage) |
| 40 |
{ |
| 41 |
float width, height; |
| 42 |
gboolean is_fullscreen; |
| 43 |
|
| 44 |
is_fullscreen = clutter_stage_get_fullscreen (stage); |
| 45 |
|
| 46 |
clutter_actor_get_size (CLUTTER_ACTOR (stage), &width, &height); |
| 47 |
|
| 48 |
g_print ("Stage size [%s]: %d x %d\n", |
| 49 |
is_fullscreen ? "fullscreen" : "not fullscreen", |
| 50 |
(int) width, |
| 51 |
(int) height); |
| 52 |
} |
| 53 |
|
| 54 |
G_MODULE_EXPORT int |
| 55 |
test_stage_sizing_main (int argc, char *argv[]) |
| 56 |
{ |
| 57 |
ClutterActor *stage, *rect, *label, *box; |
| 58 |
ClutterMargin margin = { 12.f, 12.f, 6.f, 6.f }; |
| 59 |
|
| 60 |
if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) |
| 61 |
return 1; |
| 62 |
|
| 63 |
stage = clutter_stage_new (); |
| 64 |
clutter_stage_set_title (CLUTTER_STAGE (stage), "Stage Sizing"); |
| 65 |
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); |
| 66 |
g_signal_connect_after (stage, "notify::fullscreen-set", G_CALLBACK (on_fullscreen), NULL); |
| 67 |
|
| 68 |
box = clutter_actor_new (); |
| 69 |
clutter_actor_set_layout_manager (box, clutter_box_layout_new ()); |
| 70 |
clutter_actor_add_constraint (box, clutter_align_constraint_new (stage, CLUTTER_ALIGN_BOTH, 0.5)); |
| 71 |
clutter_actor_add_child (stage, box); |
| 72 |
|
| 73 |
rect = clutter_actor_new (); |
| 74 |
clutter_actor_set_layout_manager (rect, |
| 75 |
clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER, |
| 76 |
CLUTTER_BIN_ALIGNMENT_CENTER)); |
| 77 |
clutter_actor_set_background_color (rect, CLUTTER_COLOR_LightScarletRed); |
| 78 |
clutter_actor_set_reactive (rect, TRUE); |
| 79 |
g_signal_connect_swapped (rect, "button-press-event", |
| 80 |
G_CALLBACK (fullscreen_clicked_cb), |
| 81 |
stage); |
| 82 |
label = clutter_text_new_with_text ("Sans 16", "Toggle fullscreen"); |
| 83 |
clutter_actor_set_margin (label, &margin); |
| 84 |
clutter_actor_add_child (rect, label); |
| 85 |
clutter_actor_add_child (box, rect); |
| 86 |
|
| 87 |
rect = clutter_actor_new (); |
| 88 |
clutter_actor_set_layout_manager (rect, |
| 89 |
clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER, |
| 90 |
CLUTTER_BIN_ALIGNMENT_CENTER)); |
| 91 |
clutter_actor_set_background_color (rect, CLUTTER_COLOR_Chameleon); |
| 92 |
clutter_actor_set_reactive (rect, TRUE); |
| 93 |
g_signal_connect_swapped (rect, "button-press-event", |
| 94 |
G_CALLBACK (resize_clicked_cb), stage); |
| 95 |
label = clutter_text_new_with_text ("Sans 16", "Toggle resizable"); |
| 96 |
clutter_actor_set_margin (label, &margin); |
| 97 |
clutter_actor_add_child (rect, label); |
| 98 |
clutter_actor_add_child (box, rect); |
| 99 |
|
| 100 |
rect = clutter_actor_new (); |
| 101 |
clutter_actor_set_layout_manager (rect, |
| 102 |
clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER, |
| 103 |
CLUTTER_BIN_ALIGNMENT_CENTER)); |
| 104 |
clutter_actor_set_background_color (rect, CLUTTER_COLOR_SkyBlue); |
| 105 |
clutter_actor_set_reactive (rect, TRUE); |
| 106 |
g_signal_connect_swapped (rect, "button-press-event", |
| 107 |
G_CALLBACK (shrink_clicked_cb), stage); |
| 108 |
label = clutter_text_new_with_text ("Sans 16", "Shrink"); |
| 109 |
clutter_actor_set_margin (label, &margin); |
| 110 |
clutter_actor_add_child (rect, label); |
| 111 |
clutter_actor_add_child (box, rect); |
| 112 |
|
| 113 |
rect = clutter_actor_new (); |
| 114 |
clutter_actor_set_layout_manager (rect, |
| 115 |
clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER, |
| 116 |
CLUTTER_BIN_ALIGNMENT_CENTER)); |
| 117 |
clutter_actor_set_background_color (rect, CLUTTER_COLOR_Butter); |
| 118 |
clutter_actor_set_reactive (rect, TRUE); |
| 119 |
g_signal_connect_swapped (rect, "button-press-event", |
| 120 |
G_CALLBACK (expand_clicked_cb), stage); |
| 121 |
label = clutter_text_new_with_text ("Sans 16", "Expand"); |
| 122 |
clutter_actor_set_margin (label, &margin); |
| 123 |
clutter_actor_add_child (rect, label); |
| 124 |
clutter_actor_add_child (box, rect); |
| 125 |
|
| 126 |
clutter_stage_set_minimum_size (CLUTTER_STAGE (stage), |
| 127 |
clutter_actor_get_width (box), |
| 128 |
clutter_actor_get_height (box)); |
| 129 |
|
| 130 |
clutter_actor_show (stage); |
| 131 |
|
| 132 |
clutter_main (); |
| 133 |
|
| 134 |
return EXIT_SUCCESS; |
| 135 |
} |
| 136 |
|
| 137 |
G_MODULE_EXPORT const char * |
| 138 |
test_stage_sizing_describe (void) |
| 139 |
{ |
| 140 |
return "Check stage sizing policies."; |
| 141 |
} |