[clutter] cookbook: Begin porting examples to the new API
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [clutter] cookbook: Begin porting examples to the new API
- Date: Tue, 24 Jan 2012 15:14:45 +0000 (UTC)
commit 1c01554e6a06db0e6afc9a76deea99daa44f9fba
Author: Emmanuele Bassi <ebassi linux intel com>
Date: Tue Jan 24 15:01:00 2012 +0000
cookbook: Begin porting examples to the new API
Start dropping the usage of deprecated classes and API.
doc/cookbook/examples/actors-composite-main.c | 2 +-
doc/cookbook/examples/animations-moving-animator.c | 43 ++++++++++---------
doc/cookbook/examples/cb-button.c | 6 +--
doc/cookbook/examples/events-buttons-click.c | 18 +++++---
doc/cookbook/examples/events-mouse-scroll.c | 6 +-
.../examples/layouts-bind-constraint-allocation.c | 12 +++--
doc/cookbook/examples/layouts-box.c | 41 ++++++++++---------
7 files changed, 68 insertions(+), 60 deletions(-)
---
diff --git a/doc/cookbook/examples/actors-composite-main.c b/doc/cookbook/examples/actors-composite-main.c
index b9a8ea3..bcbe935 100644
--- a/doc/cookbook/examples/actors-composite-main.c
+++ b/doc/cookbook/examples/actors-composite-main.c
@@ -70,7 +70,7 @@ main (int argc,
clutter_actor_add_constraint (button, align_x_constraint);
clutter_actor_add_constraint (button, align_y_constraint);
- clutter_container_add_actor (CLUTTER_CONTAINER (stage), button);
+ clutter_actor_add_child (stage, button);
clutter_actor_show (stage);
diff --git a/doc/cookbook/examples/animations-moving-animator.c b/doc/cookbook/examples/animations-moving-animator.c
index b13d57c..091e37e 100644
--- a/doc/cookbook/examples/animations-moving-animator.c
+++ b/doc/cookbook/examples/animations-moving-animator.c
@@ -17,11 +17,9 @@ static const ClutterColor blue_color = { 0x00, 0x00, 0xff, 0xff };
* to a random x position
*/
static void
-add_keys_for_actor (ClutterActor *actor,
- gpointer user_data)
+add_keys_for_actor (ClutterActor *actor,
+ ClutterAnimator *animator)
{
- ClutterAnimator *animator = CLUTTER_ANIMATOR (user_data);
-
gfloat x, end_x;
x = clutter_actor_get_x (actor);
@@ -41,7 +39,8 @@ move_actors (ClutterActor *actor,
ClutterEvent *event,
gpointer user_data)
{
- State *state = (State *) user_data;
+ State *state = user_data;
+ ClutterActor *child;
/* do nothing if the animator is already running */
if (clutter_timeline_is_playing (clutter_animator_get_timeline (state->animator)))
@@ -51,9 +50,12 @@ move_actors (ClutterActor *actor,
clutter_animator_remove_key (state->animator, NULL, NULL, -1);
/* add keys for all actors in the group */
- clutter_container_foreach (CLUTTER_CONTAINER (state->group),
- add_keys_for_actor,
- state->animator);
+ for (child = clutter_actor_get_first_child (state->group);
+ child != NULL;
+ child = clutter_actor_get_next_sibling (child))
+ {
+ add_keys_for_actor (child, state->animator);
+ }
/* start the animation */
clutter_animator_start (state->animator);
@@ -68,12 +70,13 @@ main (int argc,
ClutterActor *red;
ClutterActor *green;
ClutterActor *blue;
+
State *state = g_new0 (State, 1);
/* seed random number generator */
srand ((unsigned int) time (NULL));
-if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
+ if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
return 1;
state->animator = clutter_animator_new ();
@@ -87,32 +90,32 @@ if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
G_CALLBACK (clutter_main_quit),
NULL);
- state->group = clutter_group_new ();
+ state->group = clutter_actor_new ();
+ clutter_actor_add_child (state->stage, state->group);
- red = clutter_rectangle_new_with_color (&red_color);
+ red = clutter_actor_new ();
+ clutter_actor_set_background_color (red, &red_color);
clutter_actor_set_size (red, 50, 50);
clutter_actor_set_position (red, 50, 50);
+ clutter_actor_add_child (state->group, red);
- green = clutter_rectangle_new_with_color (&green_color);
+ green = clutter_actor_new ();
+ clutter_actor_set_background_color (green, &green_color);
clutter_actor_set_size (green, 50, 50);
clutter_actor_set_position (green, 50, 150);
+ clutter_actor_add_child (state->group, green);
- blue = clutter_rectangle_new_with_color (&blue_color);
+ blue = clutter_actor_new ();
+ clutter_actor_set_background_color (blue, &blue_color);
clutter_actor_set_size (blue, 50, 50);
clutter_actor_set_position (blue, 50, 250);
+ clutter_actor_add_child (state->group, blue);
g_signal_connect (state->stage,
"key-press-event",
G_CALLBACK (move_actors),
state);
- clutter_container_add (CLUTTER_CONTAINER (state->group),
- red,
- green,
- blue,
- NULL);
- clutter_container_add_actor (CLUTTER_CONTAINER (state->stage), state->group);
-
clutter_actor_show (state->stage);
clutter_main ();
diff --git a/doc/cookbook/examples/cb-button.c b/doc/cookbook/examples/cb-button.c
index e02416c..6f1f0b9 100644
--- a/doc/cookbook/examples/cb-button.c
+++ b/doc/cookbook/examples/cb-button.c
@@ -326,8 +326,7 @@ cb_button_init (CbButton *self)
priv->child = clutter_box_new (layout);
/* set the parent of the ClutterBox to this instance */
- clutter_actor_set_parent (priv->child,
- CLUTTER_ACTOR (self));
+ clutter_actor_add_child (CLUTTER_ACTOR (self), priv->child);
/* add text label to the button; see the ClutterText API docs
* for more information about available properties
@@ -337,8 +336,7 @@ cb_button_init (CbButton *self)
"ellipsize", PANGO_ELLIPSIZE_END,
NULL);
- clutter_container_add_actor (CLUTTER_CONTAINER (priv->child),
- priv->label);
+ clutter_actor_add_child (priv->child, priv->label);
/* add a ClutterClickAction on this actor, so we can proxy its
* "clicked" signal into a signal from this actor
diff --git a/doc/cookbook/examples/events-buttons-click.c b/doc/cookbook/examples/events-buttons-click.c
index f94bc79..07479d4 100644
--- a/doc/cookbook/examples/events-buttons-click.c
+++ b/doc/cookbook/examples/events-buttons-click.c
@@ -2,15 +2,15 @@
#include <clutter/clutter.h>
static const ClutterColor stage_color = { 0x33, 0x33, 0x55, 0xff };
-static const ClutterColor red_color = { 0xff, 0x00, 0x00, 0xff };
-static const ClutterColor blue_color = { 0x00, 0x00, 0xff, 0xff };
void
clicked_cb (ClutterClickAction *action,
ClutterActor *actor,
gpointer user_data)
{
- g_debug ("Button %d clicked", clutter_click_action_get_button (action));
+ g_print ("Pointer button %d clicked on actor %s\n",
+ clutter_click_action_get_button (action),
+ clutter_actor_get_name (actor));
}
int
@@ -31,15 +31,21 @@ main (int argc,
clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
- actor1 = clutter_rectangle_new_with_color (&red_color);
+ actor1 = clutter_actor_new ();
+ clutter_actor_set_name (actor1, "Red Button");
+ clutter_actor_set_background_color (actor1, CLUTTER_COLOR_Red);
clutter_actor_set_size (actor1, 100, 100);
clutter_actor_set_reactive (actor1, TRUE);
clutter_actor_set_position (actor1, 50, 150);
+ clutter_actor_add_child (stage, actor1);
- actor2 = clutter_rectangle_new_with_color (&blue_color);
+ actor2 = clutter_actor_new ();
+ clutter_actor_set_name (actor2, "Blue Button");
+ clutter_actor_set_background_color (actor2, CLUTTER_COLOR_Blue);
clutter_actor_set_size (actor2, 100, 100);
clutter_actor_set_position (actor2, 250, 150);
clutter_actor_set_reactive (actor2, TRUE);
+ clutter_actor_add_child (stage, actor2);
action1 = clutter_click_action_new ();
clutter_actor_add_action (actor1, action1);
@@ -47,8 +53,6 @@ main (int argc,
action2 = clutter_click_action_new ();
clutter_actor_add_action (actor2, action2);
- clutter_container_add (CLUTTER_CONTAINER (stage), actor1, actor2, NULL);
-
g_signal_connect (action1,
"clicked",
G_CALLBACK (clicked_cb),
diff --git a/doc/cookbook/examples/events-mouse-scroll.c b/doc/cookbook/examples/events-mouse-scroll.c
index 07cc0cb..e491c14 100644
--- a/doc/cookbook/examples/events-mouse-scroll.c
+++ b/doc/cookbook/examples/events-mouse-scroll.c
@@ -96,7 +96,7 @@ main (int argc, char *argv[])
NULL);
/* the viewport which the box is scrolled within */
- viewport = clutter_group_new ();
+ viewport = clutter_actor_new ();
/* viewport is shorter than the stage */
clutter_actor_set_size (viewport, STAGE_WIDTH, STAGE_HEIGHT * 0.5);
@@ -111,10 +111,10 @@ main (int argc, char *argv[])
clutter_actor_set_clip_to_allocation (viewport, TRUE);
/* put the texture inside the viewport */
- clutter_container_add_actor (CLUTTER_CONTAINER (viewport), texture);
+ clutter_actor_add_child (viewport, texture);
/* add the viewport to the stage */
- clutter_container_add_actor (CLUTTER_CONTAINER (stage), viewport);
+ clutter_actor_add_child (stage, viewport);
g_signal_connect (viewport,
"scroll-event",
diff --git a/doc/cookbook/examples/layouts-bind-constraint-allocation.c b/doc/cookbook/examples/layouts-bind-constraint-allocation.c
index a487331..2bc690e 100644
--- a/doc/cookbook/examples/layouts-bind-constraint-allocation.c
+++ b/doc/cookbook/examples/layouts-bind-constraint-allocation.c
@@ -4,8 +4,6 @@
#define OVERLAY_FACTOR 1.1
static const ClutterColor stage_color = { 0x33, 0x33, 0x55, 0xff };
-static const ClutterColor red = { 0xff, 0x00, 0x00, 0xff };
-static const ClutterColor blue = { 0x00, 0x00, 0xff, 0x66 };
void
allocation_changed_cb (ClutterActor *actor,
@@ -43,18 +41,22 @@ main (int argc, char *argv[])
clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
- actor = clutter_rectangle_new_with_color (&red);
+ actor = clutter_actor_new ();
+ clutter_actor_set_background_color (actor, CLUTTER_COLOR_Red);
clutter_actor_set_size (actor, 100, 100);
clutter_actor_set_position (actor, 150, 150);
+ clutter_actor_add_child (stage, actor);
- overlay = clutter_rectangle_new_with_color (&blue);
+ overlay = clutter_actor_new ();
+ clutter_actor_set_background_color (overlay, CLUTTER_COLOR_Blue);
+ clutter_actor_set_opacity (overlay, 128);
g_signal_connect (actor,
"allocation-changed",
G_CALLBACK (allocation_changed_cb),
overlay);
- clutter_container_add (CLUTTER_CONTAINER (stage), actor, overlay, NULL);
+ clutter_actor_add_child (stage, overlay);
clutter_actor_animate (actor, CLUTTER_LINEAR, 2000,
"width", 300.0,
diff --git a/doc/cookbook/examples/layouts-box.c b/doc/cookbook/examples/layouts-box.c
index 9b2b40b..cef41ed 100644
--- a/doc/cookbook/examples/layouts-box.c
+++ b/doc/cookbook/examples/layouts-box.c
@@ -35,18 +35,20 @@ main (int argc,
/* put 5px of spacing between actors */
clutter_box_layout_set_spacing (CLUTTER_BOX_LAYOUT (box_layout), 5);
- /* actors are packed into this box; we set its width, but
+ /* actors are packed into this actor; we set its width, but
* allow its height to be determined by the children it contains
*/
- box = clutter_box_new (box_layout);
- clutter_box_set_color (CLUTTER_BOX (box), &box_color);
+ box = clutter_actor_new ();
+ clutter_actor_set_layout_manager (box, box_layout);
+ clutter_actor_set_background_color (box, CLUTTER_COLOR_White);
clutter_actor_set_position (box, 100, 50);
clutter_actor_set_width (box, 200);
/* pack an actor into the layout and set all layout properties on it
* at the same time
*/
- yellow = clutter_rectangle_new_with_color (&yellow_color);
+ yellow = clutter_actor_new ();
+ clutter_actor_set_background_color (yellow, CLUTTER_COLOR_Yellow);
clutter_actor_set_size (yellow, 100, 100);
clutter_box_layout_pack (CLUTTER_BOX_LAYOUT (box_layout),
@@ -57,28 +59,27 @@ main (int argc,
CLUTTER_BOX_ALIGNMENT_START, /* x-align */
CLUTTER_BOX_ALIGNMENT_START); /* y-align */
- /* pack an actor into the box and set layout properties at the
- * same time; note this is more concise if you mostly want to
- * use the default properties for the layout
- */
- red = clutter_rectangle_new_with_color (&red_color);
- clutter_actor_set_size (red, 100, 100);
-
- clutter_box_pack (CLUTTER_BOX (box),
- red,
- "x-fill", TRUE,
- NULL);
-
/* add an actor to the box as a container and set layout properties
* afterwards; the latter is useful if you want to change properties on
* actors already inside a layout, but note that you have to
* pass the function both the layout AND the container
*/
- blue = clutter_rectangle_new_with_color (&blue_color);
- clutter_actor_set_size (blue, 100, 100);
+ red = clutter_actor_new ();
+ clutter_actor_set_background_color (red, CLUTTER_COLOR_Red);
+ clutter_actor_set_size (red, 100, 100);
- clutter_container_add_actor (CLUTTER_CONTAINER (box), blue);
+ clutter_actor_add_child (box, red);
+ clutter_layout_manager_child_set (box_layout,
+ CLUTTER_CONTAINER (box),
+ red,
+ "x-fill", TRUE,
+ NULL);
+
+ blue = clutter_actor_new ();
+ clutter_actor_set_background_color (blue, CLUTTER_COLOR_Blue);
+ clutter_actor_set_size (blue, 100, 100);
+ clutter_actor_add_child (box, blue);
clutter_layout_manager_child_set (box_layout,
CLUTTER_CONTAINER (box),
blue,
@@ -86,7 +87,7 @@ main (int argc,
NULL);
/* put the box on the stage */
- clutter_container_add_actor (CLUTTER_CONTAINER (stage), box);
+ clutter_actor_add_child (stage, box);
clutter_actor_show (stage);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]