[gnome-games/gnibbles-clutter] Removed the GtkClutterEmbed from GnibblesBoard and replaced it with a



commit 1f41d482fffdd3d267fdf7fe10e2b44137cab5e6
Author: Guillaume Beland <guillaume beland gmail com>
Date:   Mon Jul 20 23:40:57 2009 -0400

    Removed the GtkClutterEmbed from GnibblesBoard and replaced it with a
    ClutterStage

 gnibbles/board.c        |   25 +++++++------------------
 gnibbles/board.h        |    5 ++---
 gnibbles/bonus.c        |    3 +--
 gnibbles/gnibbles.c     |    4 +---
 gnibbles/main.c         |   27 ++++++++++++++-------------
 gnibbles/warp.c         |    3 +--
 gnibbles/worm-clutter.c |   41 +++++++++++++++++++++++++++++++++--------
 7 files changed, 59 insertions(+), 49 deletions(-)
---
diff --git a/gnibbles/board.c b/gnibbles/board.c
index 10148fe..de0c28a 100644
--- a/gnibbles/board.c
+++ b/gnibbles/board.c
@@ -40,7 +40,7 @@ extern GnibblesProperties *properties;
 extern GdkPixbuf *wall_pixmaps[];
 
 GnibblesBoard *
-gnibbles_board_new (gint t_w, gint t_h) 
+gnibbles_board_new (ClutterActor *stage) 
 {
   ClutterColor stage_color = {0x00,0x00,0x00,0xff};
   gchar *filename;
@@ -48,15 +48,12 @@ gnibbles_board_new (gint t_w, gint t_h)
   GValue val = {0,};
 
   GnibblesBoard *board = g_new (GnibblesBoard, 1);
-  board->width = t_w;
-  board->height = t_h;
+  board->width = BOARDWIDTH;
+  board->height = BOARDHEIGHT;
   board->level = NULL;
   board->surface = NULL;
-  board->clutter_widget = gtk_clutter_embed_new ();
+  board->stage = stage;
 
-  ClutterActor *stage;
-
-  stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (board->clutter_widget));
   clutter_stage_set_color (CLUTTER_STAGE(stage), &stage_color);
 
   clutter_stage_set_user_resizable (CLUTTER_STAGE(stage), FALSE); 
@@ -87,12 +84,6 @@ gnibbles_board_new (gint t_w, gint t_h)
   return board;
 }
 
-ClutterActor *
-gnibbles_board_get_stage (GnibblesBoard *board) 
-{
-  return gtk_clutter_embed_get_stage(GTK_CLUTTER_EMBED(board->clutter_widget));
-}
-
 void 
 gnibbles_board_load_level (GnibblesBoard *board, GnibblesLevel *level) 
 {
@@ -167,9 +158,8 @@ gnibbles_board_load_level (GnibblesBoard *board, GnibblesLevel *level)
     }
   }
 
-  ClutterActor *stage = gnibbles_board_get_stage (board);
-  clutter_container_add_actor (CLUTTER_CONTAINER (stage), board->level);
-  clutter_actor_raise (board->level,board->surface);
+  clutter_container_add_actor (CLUTTER_CONTAINER (board->stage), board->level);
+  clutter_actor_raise (board->level, board->surface);
 
   clutter_actor_set_opacity (board->level, 0);
   clutter_actor_animate (board->level, CLUTTER_EASE_IN_QUAD, 410,
@@ -192,9 +182,8 @@ gnibbles_board_resize (GnibblesBoard *board, gint newtile)
   int count;
 
   ClutterActor *tmp;
-  ClutterActor *stage = gnibbles_board_get_stage (board);
 
-  clutter_actor_set_size (stage, 
+  clutter_actor_set_size (board->stage, 
                           BOARDWIDTH * newtile,
                           BOARDHEIGHT * newtile);
   clutter_actor_set_size (board->surface,
diff --git a/gnibbles/board.h b/gnibbles/board.h
index 3907244..9ed8461 100644
--- a/gnibbles/board.h
+++ b/gnibbles/board.h
@@ -31,13 +31,12 @@
 typedef struct {
   gint width;
   gint height;
-  GtkWidget *clutter_widget;
+  ClutterActor *stage;
   ClutterActor *surface;
   ClutterActor *level;
 } GnibblesBoard;
 
-GnibblesBoard* gnibbles_board_new (gint t_w, gint t_h);
-ClutterActor* gnibbles_board_get_stage (GnibblesBoard *board);
+GnibblesBoard* gnibbles_board_new (ClutterActor *stage);
 void gnibbles_board_load_level (GnibblesBoard *board, GnibblesLevel *level);
 void gnibbles_board_resize (GnibblesBoard *board, gint newtile);
 
diff --git a/gnibbles/bonus.c b/gnibbles/bonus.c
index de83c64..210ec35 100644
--- a/gnibbles/bonus.c
+++ b/gnibbles/bonus.c
@@ -61,8 +61,7 @@ gnibbles_bonus_draw (GnibblesBonus *bonus)
   clutter_actor_set_position (CLUTTER_ACTOR (bonus->actor),
                               bonus->x * properties->tilesize,
                               bonus->y * properties->tilesize);
-  ClutterActor *stage = gnibbles_board_get_stage (board);
-  clutter_container_add_actor (CLUTTER_CONTAINER (stage), bonus->actor);
+  clutter_container_add_actor (CLUTTER_CONTAINER (board->stage), bonus->actor);
   clutter_actor_set_opacity (bonus->actor, 0);
   clutter_actor_animate (bonus->actor, CLUTTER_EASE_IN_QUAD, 410,
                          "opacity", 0xff,
diff --git a/gnibbles/gnibbles.c b/gnibbles/gnibbles.c
index 17bb0e2..be481bd 100644
--- a/gnibbles/gnibbles.c
+++ b/gnibbles/gnibbles.c
@@ -202,11 +202,9 @@ gnibbles_init ()
 	                 colorval_name (properties->wormprops[i]->color));
   }
 
-  ClutterActor *stage = gnibbles_board_get_stage (board);
-
   for (i = 0; i < properties->numworms; i++) {
     if (worms[i]) {
-      clutter_container_add_actor (CLUTTER_CONTAINER (stage), worms[i]->actors);
+      clutter_container_add_actor (CLUTTER_CONTAINER (board->stage), worms[i]->actors);
       clutter_actor_raise_top (worms[i]->actors);
       gnibbles_worm_show (worms[i]);
     }
diff --git a/gnibbles/main.c b/gnibbles/main.c
index 99824e8..f91e930 100644
--- a/gnibbles/main.c
+++ b/gnibbles/main.c
@@ -90,6 +90,8 @@ GnibblesLevel *level;
 
 GnibblesScoreboard *scoreboard;
 
+GtkWidget *clutter_widget;
+
 extern GnibblesWorm *worms[];
 extern GnibblesBoni *boni;
 
@@ -126,8 +128,7 @@ static ClutterActor *logo;
 static void
 hide_cursor (void)
 {
-  ClutterActor *stage = gnibbles_board_get_stage (board);
-  clutter_stage_hide_cursor (CLUTTER_STAGE (stage));
+  clutter_stage_hide_cursor (CLUTTER_STAGE (board->stage));
 }
 
 static void
@@ -182,8 +183,7 @@ window_state_cb (GtkWidget * widget, GdkEventWindowState * event)
 static void
 show_cursor (void)
 {
-  ClutterActor *stage = gnibbles_board_get_stage (board);
-  clutter_stage_show_cursor (CLUTTER_STAGE (stage));
+  clutter_stage_show_cursor (CLUTTER_STAGE (board->stage));
 }
 
 gint
@@ -327,7 +327,7 @@ new_game_2_cb (GtkWidget * widget, gpointer data)
 {
   if (!paused) {
     if (!keyboard_id)
-      keyboard_id = g_signal_connect (G_OBJECT (gnibbles_board_get_stage (board)),
+      keyboard_id = g_signal_connect (G_OBJECT (board->stage),
 				                              "key-press-event",
                         				      G_CALLBACK (key_press_cb), NULL);
 #ifdef GGZ_CLIENT
@@ -798,10 +798,14 @@ setup_window ()
   GtkWidget *main_vbox;
   GtkWidget *packing;
   GtkWidget *menubar;
+
   GtkUIManager *ui_manager;
   GtkAccelGroup *accel_group;
 
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+  clutter_widget = gtk_clutter_embed_new ();
+  board = gnibbles_board_new (gtk_clutter_embed_get_stage (
+                              GTK_CLUTTER_EMBED (clutter_widget)));
   gtk_window_set_title (GTK_WINDOW (window), _("Nibbles"));
 
   gtk_window_set_default_size (GTK_WINDOW (window), 
@@ -837,13 +841,13 @@ setup_window ()
   gtk_widget_show (packing);
 
 
-  gtk_container_add (GTK_CONTAINER (packing), board->clutter_widget);
+  gtk_container_add (GTK_CONTAINER (packing), clutter_widget);
 #ifdef GGZ_CLIENT
   chat = create_chat_widget ();
   gtk_box_pack_start (GTK_BOX (vbox), chat, FALSE, TRUE, 0);
 #endif
 
-  g_signal_connect (G_OBJECT (board->clutter_widget), "configure_event",
+  g_signal_connect (G_OBJECT (clutter_widget), "configure_event",
 		    G_CALLBACK (configure_event_cb), NULL);
 
   g_signal_connect (G_OBJECT (window), "focus_out_event",
@@ -876,10 +880,9 @@ render_logo (void)
   ClutterActor *desc;
   ClutterColor actor_color = {0xff,0xff,0xff,0xff};
 
-  ClutterActor *stage = gnibbles_board_get_stage (board);
   logo = clutter_group_new ();
 
-  clutter_actor_get_size (CLUTTER_ACTOR (stage), &width, &height);
+  clutter_actor_get_size (CLUTTER_ACTOR (board->stage), &width, &height);
  
   if (!logo_pixmap)
     gnibbles_load_logo ();
@@ -904,7 +907,7 @@ render_logo (void)
                          CLUTTER_ACTOR (desc),
                          NULL);
   
-  clutter_container_add_actor (CLUTTER_CONTAINER (stage), 
+  clutter_container_add_actor (CLUTTER_CONTAINER (board->stage), 
                          CLUTTER_ACTOR (logo));
 }
 
@@ -965,11 +968,9 @@ main (int argc, char **argv)
 
   games_conf_initialise ("Gnibbles");
   properties = gnibbles_properties_new (); 
-
+  setup_window ();
   gnibbles_load_pixmap (properties->tilesize);
 
-  board = gnibbles_board_new (BOARDWIDTH, BOARDHEIGHT);
-  setup_window ();
   gnibbles_load_logo ();
 
 #ifdef GGZ_CLIENT
diff --git a/gnibbles/warp.c b/gnibbles/warp.c
index daeedac..f689f84 100644
--- a/gnibbles/warp.c
+++ b/gnibbles/warp.c
@@ -57,8 +57,7 @@ gnibbles_warp_draw (GnibblesWarp *warp)
   clutter_actor_set_position (CLUTTER_ACTOR (warp->actor),
                               properties->tilesize * warp->x,
                               properties->tilesize * warp->y);
-  ClutterActor *stage = gnibbles_board_get_stage (board);
-  clutter_container_add_actor (CLUTTER_CONTAINER (stage), warp->actor);
+  clutter_container_add_actor (CLUTTER_CONTAINER (board->stage), warp->actor);
   clutter_actor_set_opacity (warp->actor, 0);
   clutter_actor_animate (warp->actor, CLUTTER_EASE_IN_QUAD, 410,
                          "opacity", 0xff,
diff --git a/gnibbles/worm-clutter.c b/gnibbles/worm-clutter.c
index 63a5206..cb2f503 100644
--- a/gnibbles/worm-clutter.c
+++ b/gnibbles/worm-clutter.c
@@ -592,7 +592,10 @@ gnibbles_worm_move_straight_worm (GnibblesWorm *worm)
       level->walls[worm->xhead][worm->yhead] = WORMCHAR;
       worm->xhead++;
       level->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
-      worm->xtail++;
+      if (worm->xtail == BOARDWIDTH)
+        worm->xtail = 0;
+      else 
+         worm->xtail++;
       break;
     case WORMDOWN:
       clutter_actor_set_position (CLUTTER_ACTOR (head), 
@@ -600,7 +603,10 @@ gnibbles_worm_move_straight_worm (GnibblesWorm *worm)
       level->walls[worm->xhead][worm->yhead] = WORMCHAR;
       worm->yhead++;
       level->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
-      worm->ytail++;
+      if (worm->ytail == BOARDHEIGHT)
+        worm->ytail = 0;
+      else
+        worm->ytail++;
       break;
     case WORMLEFT:
       clutter_actor_set_position (CLUTTER_ACTOR (head), 
@@ -608,7 +614,10 @@ gnibbles_worm_move_straight_worm (GnibblesWorm *worm)
       level->walls[worm->xhead][worm->yhead] = WORMCHAR;
       worm->xhead--;
       level->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
-      worm->xtail--;
+      if (worm->xtail == 0)
+        worm->xtail = BOARDWIDTH;
+      else
+        worm->xtail--;
       break;
     case WORMUP:
       clutter_actor_set_position (CLUTTER_ACTOR (head), 
@@ -616,7 +625,10 @@ gnibbles_worm_move_straight_worm (GnibblesWorm *worm)
       level->walls[worm->xhead][worm->yhead] = WORMCHAR;
       worm->yhead--;
       level->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
-      worm->ytail--;
+      if (worm->ytail == 0)
+        worm->ytail = BOARDHEIGHT;
+      else
+        worm->ytail--;
       break;
     default:
       break;
@@ -733,8 +745,12 @@ gnibbles_worm_move_tail (GnibblesWorm *worm)
                                 properties->tilesize);
         clutter_actor_set_position (CLUTTER_ACTOR (tail), 
                                     x + properties->tilesize, y);
+
         level->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
-        worm->xtail++;
+        if (worm->xtail == BOARDWIDTH) 
+          worm->xtail = 0;
+        else 
+          worm->xtail++;
         break;
       case WORMDOWN:
         clutter_actor_set_size (CLUTTER_ACTOR (tail), 
@@ -743,21 +759,30 @@ gnibbles_worm_move_tail (GnibblesWorm *worm)
         clutter_actor_set_position (CLUTTER_ACTOR (tail), 
                                     x, y + properties->tilesize);
         level->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
-        worm->ytail++;
+        if (worm->ytail == BOARDHEIGHT)
+          worm->ytail = 0;
+        else
+          worm->ytail++;
         break;
       case WORMLEFT:
         clutter_actor_set_size (CLUTTER_ACTOR (tail), 
                                 size, 
                                 properties->tilesize);
         level->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
-        worm->xtail--;
+        if (worm->xtail == 0)
+          worm->xtail = BOARDWIDTH;
+        else
+          worm->xtail--;
         break;
       case WORMUP:
         clutter_actor_set_size (CLUTTER_ACTOR (tail), 
                                 properties->tilesize, 
                                 size);
         level->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
-        worm->ytail--;
+        if (worm->ytail == 0)
+          worm->ytail = BOARDHEIGHT;
+        else
+          worm->ytail--;
         break;
       default:
         break;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]