[gnome-games/gnibbles-clutter] Using g_object_set_property instead of ClutterScript to set special actor
- From: Guillaume Béland <guillaubel src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-games/gnibbles-clutter] Using g_object_set_property instead of ClutterScript to set special actor
- Date: Tue, 26 May 2009 16:53:24 -0400 (EDT)
commit 5d55f7fddad697b6bee95c5074b616b7368f9e6c
Author: Guillaume Beland <guillaume beland gmail com>
Date: Tue May 26 15:02:49 2009 -0400
Using g_object_set_property instead of ClutterScript to set special actor
properties
---
gnibbles/board.c | 42 +++++++---------------------
gnibbles/main.c | 8 +++---
gnibbles/worm-clutter.c | 67 +++++++++++++---------------------------------
3 files changed, 34 insertions(+), 83 deletions(-)
diff --git a/gnibbles/board.c b/gnibbles/board.c
index 0372f93..310f840 100644
--- a/gnibbles/board.c
+++ b/gnibbles/board.c
@@ -111,6 +111,9 @@ GnibblesBoard *
gnibbles_board_new (gint t_w, gint t_h)
{
ClutterColor stage_color = {0x00,0x00,0x00,0xff};
+ gchar *filename;
+ const char *dirname;
+ GValue val = {0,};
GnibblesBoard *board = g_new (GnibblesBoard, 1);
board->width = t_w;
@@ -133,47 +136,24 @@ gnibbles_board_new (gint t_w, gint t_h)
clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), FALSE);
clutter_actor_show (stage);
- gchar *filename;
- const char *dirname;
-
dirname = games_runtime_get_directory (GAMES_RUNTIME_GAME_PIXMAP_DIRECTORY);
filename = g_build_filename (dirname, "wall-small-empty.svg", NULL);
- /* Using ClutterScript to set special texture property such as "repeat-x",
- * "repeat-y" and "keep-aspect-ratio" */
- gchar texture_script[200];
-
- g_sprintf (texture_script, "["
- " {"
- " \"id\" : \"surface\","
- " \"type\" : \"ClutterTexture\","
- " \"filename\" : \"%s\","
- " \"x\" : 0,"
- " \"y\" : 0,"
- " \"width\" : %d,"
- " \"height\" : %d,"
- " \"keep-aspect-ratio\" : true,"
- " \"visible\" : true,"
- " \"repeat-x\" : true,"
- " \"repeat-y\" : true"
- " }"
- "]",
- filename,
- properties->tilesize,
- properties->tilesize);
-
- ClutterScript *script = clutter_script_new ();
-
- clutter_script_load_from_data (script, texture_script, -1, NULL);
- clutter_script_get_objects (script, "surface", &(board->surface), NULL);
+ board->surface = clutter_texture_new_from_file (filename, NULL);
+
+ g_value_init (&val, G_TYPE_BOOLEAN);
+ g_value_set_boolean ( &val, TRUE);
+
+ g_object_set_property (G_OBJECT (board->surface), "repeat-y", &val);
+ g_object_set_property (G_OBJECT (board->surface), "repeat-x", &val);
+ clutter_actor_set_position (CLUTTER_ACTOR (board->surface), 0, 0);
clutter_actor_set_size (CLUTTER_ACTOR (board->surface),
properties->tilesize * BOARDWIDTH,
properties->tilesize * BOARDHEIGHT);
clutter_container_add_actor (CLUTTER_CONTAINER (stage), board->surface);
clutter_actor_show (board->surface);
- g_object_unref (script);
return board;
}
diff --git a/gnibbles/main.c b/gnibbles/main.c
index 7f1233e..eb94779 100644
--- a/gnibbles/main.c
+++ b/gnibbles/main.c
@@ -225,8 +225,8 @@ load_pixmap ()
g_object_unref (worm_pixmaps[i]);
worm_pixmaps[i] = load_pixmap_file (worm_files[i],
- 2 * properties->tilesize,
- 2 * properties->tilesize);
+ properties->tilesize,
+ properties->tilesize);
}
}
@@ -1315,10 +1315,10 @@ main (int argc, char **argv)
gtk_action_set_visible (new_game_action, !ggz_network_mode);
gtk_action_set_visible (player_list_action, ggz_network_mode);
- load_pixmap ();
-
// clutter fun
gtk_clutter_init (&argc, &argv);
+
+ load_pixmap ();
GnibblesBoard *board = gnibbles_board_new (BOARDWIDTH, BOARDHEIGHT);
setup_window_clutter (board);
diff --git a/gnibbles/worm-clutter.c b/gnibbles/worm-clutter.c
index 17b4ac1..9b36a84 100644
--- a/gnibbles/worm-clutter.c
+++ b/gnibbles/worm-clutter.c
@@ -49,7 +49,7 @@ gnibbles_cworm_new (guint number, gint x_s, gint y_s)
worm->xstart = x_s;
worm->ystart = y_s;
- gnibbles_cworm_add_straight_actor (worm, SLENGTH);
+ gnibbles_cworm_add_straight_actor (worm, 30);
return worm;
}
@@ -57,60 +57,31 @@ gnibbles_cworm_new (guint number, gint x_s, gint y_s)
void
gnibbles_cworm_add_straight_actor (GnibblesCWorm *worm, gint size)
{
- ClutterScript *script = NULL;
ClutterActor *actor = NULL;
+ GValue val = {0,};
- gchar worm_script[300];
+ actor = gtk_clutter_texture_new_from_pixbuf (worm_pixmaps[0]);
- if (worm->direction == WORMRIGHT || worm->direction == WORMLEFT) {
- g_sprintf (worm_script, "["
- " {"
- " \"id\" : \"worm\","
- " \"type\" : \"ClutterTexture\","
- " \"x\" : %d,"
- " \"y\" : %d,"
- " \"width\" : %d,"
- " \"height\" : %d,"
- " \"keep-aspect-ratio\" : true,"
- " \"visible\" : true,"
- " \"repeat-x\" : true,"
- " \"repeat-y\" : false,"
- " }"
- "]",
- worm->xstart,
- worm->ystart,
- size * (2 * properties->tilesize),
- 2 * properties->tilesize);
+ g_value_init (&val, G_TYPE_BOOLEAN);
+ g_value_set_boolean ( &val, TRUE);
- } else if (worm->direction == WORMDOWN || worm->direction == WORMUP) {
- g_sprintf (worm_script, "["
- " {"
- " \"id\" : \"worm\","
- " \"type\" : \"ClutterTexture\","
- " \"x\" : %d,"
- " \"y\" : %d,"
- " \"width\" : %d,"
- " \"height\" : %d,"
- " \"keep-aspect-ratio\" : true,"
- " \"visible\" : true,"
- " \"repeat-x\" : false,"
- " \"repeat-y\" : true,"
- " }"
- "]",
- worm->xstart,
- worm->ystart,
- 2 * properties->tilesize,
- size * (2 * properties->tilesize));
+ clutter_actor_set_position (CLUTTER_ACTOR (actor),
+ worm->xstart,
+ worm->ystart);
+ g_object_set_property (G_OBJECT (actor), "keep-aspect-ratio", &val);
+ if (worm->direction == WORMRIGHT || worm->direction == WORMLEFT) {
+ clutter_actor_set_size (CLUTTER_ACTOR (actor),
+ properties->tilesize * size,
+ properties->tilesize);
+ g_object_set_property (G_OBJECT (actor), "repeat-x", &val);
+ } else if (worm->direction == WORMDOWN || worm->direction == WORMUP) {
+ clutter_actor_set_size (CLUTTER_ACTOR (actor),
+ properties->tilesize,
+ properties->tilesize * size);
+ g_object_set_property (G_OBJECT (actor), "repeat-y", &val);
}
- script = clutter_script_new ();
-
- clutter_script_load_from_data (script, worm_script, -1, NULL);
- clutter_script_get_objects (script, "worm", &actor, NULL);
-
- gtk_clutter_texture_set_from_pixbuf (CLUTTER_TEXTURE (actor), worm_pixmaps[0]);
-
clutter_container_add_actor (CLUTTER_CONTAINER (worm->actors), actor);
if (!worm->inverse)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]