cookbook: Added layout introduction and "stacking actors" recipe
Expanded the layout introduction and added a recipe about stacking actors using ClutterBinLayout, with two examples.
This commit is contained in:
2
doc/cookbook/examples/.gitignore
vendored
2
doc/cookbook/examples/.gitignore
vendored
@ -3,3 +3,5 @@
|
||||
/textures-reflection
|
||||
/textures-split-go
|
||||
/textures-sub-texture
|
||||
/layouts-stacking
|
||||
/layouts-stacking-diff-sized-actors
|
||||
|
@ -8,6 +8,8 @@ noinst_PROGRAMS = \
|
||||
textures-reflection \
|
||||
textures-split-go \
|
||||
textures-sub-texture \
|
||||
layouts-stacking \
|
||||
layouts-stacking-diff-sized-actors \
|
||||
$(NULL)
|
||||
|
||||
INCLUDES = \
|
||||
@ -29,8 +31,10 @@ AM_CFLAGS = \
|
||||
|
||||
AM_LDFLAGS = $(CLUTTER_LIBS)
|
||||
|
||||
animations_rotating_SOURCES = animations-rotating.c
|
||||
text_shadow_SOURCES = text-shadow.c
|
||||
textures_reflection_SOURCES = textures-reflection.c
|
||||
textures_split_go_SOURCES = textures-split-go.c
|
||||
textures_sub_texture_SOURCES = textures-sub-texture.c
|
||||
animations_rotating_SOURCES = animations-rotating.c
|
||||
text_shadow_SOURCES = text-shadow.c
|
||||
textures_reflection_SOURCES = textures-reflection.c
|
||||
textures_split_go_SOURCES = textures-split-go.c
|
||||
textures_sub_texture_SOURCES = textures-sub-texture.c
|
||||
layouts_stacking_SOURCES = layouts-stacking.c
|
||||
layouts_stacking_diff_sized_actors_SOURCES = layouts-stacking-diff-sized-actors.c
|
||||
|
78
doc/cookbook/examples/layouts-stacking-diff-sized-actors.c
Normal file
78
doc/cookbook/examples/layouts-stacking-diff-sized-actors.c
Normal file
@ -0,0 +1,78 @@
|
||||
#include <clutter/clutter.h>
|
||||
|
||||
static const ClutterColor dark_grey = { 0x66, 0x66, 0x66, 0xff };
|
||||
static const ClutterColor light_grey = { 0xcc, 0xcc, 0xcc, 0xff };
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
ClutterActor *stage;
|
||||
ClutterLayoutManager *layout;
|
||||
ClutterActor *box;
|
||||
ClutterActor *rect1, *rect2;
|
||||
guint align_x, align_y, diff_x, diff_y;
|
||||
|
||||
clutter_init (&argc, &argv);
|
||||
|
||||
stage = clutter_stage_get_default ();
|
||||
clutter_actor_set_size (stage, 400, 400);
|
||||
|
||||
layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_START,
|
||||
CLUTTER_BIN_ALIGNMENT_START);
|
||||
|
||||
box = clutter_box_new (layout);
|
||||
|
||||
rect1 = clutter_rectangle_new_with_color (&dark_grey);
|
||||
clutter_actor_set_size (rect1, 400, 200);
|
||||
|
||||
rect2 = clutter_rectangle_new_with_color (&light_grey);
|
||||
clutter_actor_set_size (rect2, 200, 400);
|
||||
|
||||
clutter_container_add (CLUTTER_CONTAINER (box),
|
||||
rect1,
|
||||
rect2,
|
||||
NULL);
|
||||
|
||||
/*
|
||||
* 2 = CLUTTER_BIN_ALIGNMENT_START
|
||||
* 3 = CLUTTER_BIN_ALIGNMENT_END
|
||||
* 4 = CLUTTER_BIN_ALIGNMENT_CENTER
|
||||
*/
|
||||
for (align_x = 2; align_x < 5; align_x++)
|
||||
{
|
||||
for (align_y = 2; align_y < 5; align_y++)
|
||||
{
|
||||
diff_x = align_x - 1;
|
||||
if (align_x == 3)
|
||||
diff_x = 3;
|
||||
else if (align_x == 4)
|
||||
diff_x = 2;
|
||||
|
||||
diff_y = align_y - 1;
|
||||
if (align_y == 3)
|
||||
diff_y = 3;
|
||||
else if (align_y == 4)
|
||||
diff_y = 2;
|
||||
|
||||
ClutterColor *color = clutter_color_new (255 - diff_x * 50,
|
||||
100 + diff_y * 50,
|
||||
0,
|
||||
255);
|
||||
ClutterActor *rect = clutter_rectangle_new_with_color (color);
|
||||
clutter_actor_set_size (rect, 100, 100);
|
||||
clutter_bin_layout_set_alignment (CLUTTER_BIN_LAYOUT (layout),
|
||||
rect,
|
||||
align_x,
|
||||
align_y);
|
||||
clutter_container_add_actor (CLUTTER_CONTAINER (box), rect);
|
||||
}
|
||||
}
|
||||
|
||||
clutter_container_add_actor (CLUTTER_CONTAINER (stage), box);
|
||||
|
||||
clutter_actor_show (stage);
|
||||
|
||||
clutter_main ();
|
||||
|
||||
return 0;
|
||||
}
|
80
doc/cookbook/examples/layouts-stacking.c
Normal file
80
doc/cookbook/examples/layouts-stacking.c
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Display multiple rotated copies of an image on top of each other
|
||||
*
|
||||
* Invoke with the path to a file to load a custom image
|
||||
*/
|
||||
#include <clutter/clutter.h>
|
||||
|
||||
#define STAGE_SIDE 512
|
||||
|
||||
static const ClutterColor box_color = { 0x33, 0x33, 0x55, 0xff };
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
gchar *filename = TESTS_DATA_DIR "/redhand.png";
|
||||
|
||||
if (argc > 1)
|
||||
filename = argv[1];
|
||||
|
||||
ClutterLayoutManager *layout;
|
||||
ClutterActor *box;
|
||||
ClutterActor *stage;
|
||||
ClutterActor *texture;
|
||||
CoglHandle *cogl_texture;
|
||||
GError *error = NULL;
|
||||
gfloat width;
|
||||
|
||||
clutter_init (&argc, &argv);
|
||||
|
||||
stage = clutter_stage_get_default ();
|
||||
clutter_actor_set_size (stage, STAGE_SIDE, STAGE_SIDE);
|
||||
|
||||
layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
|
||||
CLUTTER_BIN_ALIGNMENT_CENTER);
|
||||
|
||||
box = clutter_box_new (layout);
|
||||
clutter_box_set_color (CLUTTER_BOX (box), &box_color);
|
||||
|
||||
texture = clutter_texture_new_from_file (filename, &error);
|
||||
|
||||
if (error != NULL)
|
||||
g_error ("Error loading file %s; message was:\n%s",
|
||||
filename,
|
||||
error->message);
|
||||
|
||||
/*
|
||||
* get a reference to the underlying Cogl texture
|
||||
* for copying onto each Clutter texture placed into the layout
|
||||
*/
|
||||
cogl_texture = clutter_texture_get_cogl_texture (CLUTTER_TEXTURE (texture));
|
||||
|
||||
/*
|
||||
* add gradually turning and shrinking textures,
|
||||
* smallest one last; each actor ends up on top
|
||||
* of the one added just before it
|
||||
*/
|
||||
for (width = STAGE_SIDE * 0.75; width >= STAGE_SIDE * 0.0625; width -= STAGE_SIDE * 0.0625)
|
||||
{
|
||||
ClutterActor *texture_copy = clutter_texture_new ();
|
||||
clutter_texture_set_cogl_texture (CLUTTER_TEXTURE (texture_copy),
|
||||
cogl_texture);
|
||||
clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (texture_copy),
|
||||
TRUE);
|
||||
clutter_actor_set_z_rotation_from_gravity (texture_copy,
|
||||
(gfloat)(width * 0.5) - (STAGE_SIDE * 0.03125),
|
||||
CLUTTER_GRAVITY_CENTER);
|
||||
clutter_actor_set_width (texture_copy, width);
|
||||
clutter_container_add_actor (CLUTTER_CONTAINER (box), texture_copy);
|
||||
}
|
||||
|
||||
clutter_actor_add_constraint (box, clutter_align_constraint_new (stage, CLUTTER_ALIGN_X_AXIS, 0.5));
|
||||
clutter_actor_add_constraint (box, clutter_align_constraint_new (stage, CLUTTER_ALIGN_Y_AXIS, 0.5));
|
||||
clutter_container_add_actor (CLUTTER_CONTAINER (stage), box);
|
||||
|
||||
clutter_actor_show (stage);
|
||||
|
||||
clutter_main ();
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user