[gnome-games] Loading pixmaps in main.c



commit 5e6a2b14e1b408980339fa8f94fb3e2f798bf93b
Author: Guillaume Beland <guillaubel svn gnome org>
Date:   Sun May 24 19:12:53 2009 -0400

    Loading pixmaps in main.c
    
    I still have an annoying segfault if I try to delete pixmaps related functions
    in board.c. I'm clueless about this one since I don't even use the code i'm
    removing and it segfault if it's not there.

 glchess/src/lib/game.py |  812 -----------------------------------------------
 glchess/src/lib/uci.py  |  185 -----------
 gnibbles/board.c        |  173 +++++-----
 gnibbles/main.c         |  111 +++++++-
 gnibbles/worm-clutter.c |    8 +-
 5 files changed, 201 insertions(+), 1088 deletions(-)
---
diff --git a/gnibbles/board.c b/gnibbles/board.c
index e676a6d..f851760 100644
--- a/gnibbles/board.c
+++ b/gnibbles/board.c
@@ -35,18 +35,77 @@
 #include "properties.h"
 #include "board.h"
 
-static GdkPixbuf*  load_pixmap_file (const gchar * pixmap,
-			                                      gint xsize, gint ysize);
-static void load_pixmap ();
+extern GnibblesProperties *properties;
+
+extern GdkPixbuf *wall_pixmaps[];
 
-GdkPixbuf *wall_pixmaps[19] = { NULL, NULL, NULL, NULL, NULL,
+GdkPixbuf *walls_pixmaps[19] = { NULL, NULL, NULL, NULL, NULL,
   NULL, NULL, NULL, NULL, NULL,
   NULL, NULL, NULL, NULL, NULL,
   NULL, NULL, NULL, NULL
 };
 
-extern GnibblesProperties *properties;
+static GdkPixbuf *
+board_load_pixmap_file (const gchar * pixmap, gint xsize, gint ysize)
+{
+  GdkPixbuf *image;
+  gchar *filename;
+  const char *dirname;
+
+  dirname = games_runtime_get_directory (GAMES_RUNTIME_GAME_PIXMAP_DIRECTORY);
+  filename = g_build_filename (dirname, pixmap, NULL);
+
+  if (!filename) {
+    char *message =
+      g_strdup_printf (_("Nibbles couldn't find pixmap file:\n%s\n\n"
+			 "Please check your Nibbles installation"), pixmap);
+    //gnibbles_error (window, message;
+    g_free(message);
+  }
 
+  image = gdk_pixbuf_new_from_file_at_size (filename, xsize, ysize, NULL);
+  g_free (filename);
+
+  return image;
+}
+
+static void 
+board_load_pixmap ()
+{
+
+  gchar *small_files[] = {
+    "snake-red.svg",
+    "snake-green.svg",
+    "snake-blue.svg",
+    "snake-yellow.svg",
+    "snake-cyan.svg",
+    "snake-magenta.svg",
+    "snake-grey.svg",
+    "wall-empty.svg",
+    "wall-straight-up.svg",
+    "wall-straight-side.svg",
+    "wall-corner-bottom-left.svg",
+    "wall-corner-bottom-right.svg",
+    "wall-corner-top-left.svg",
+    "wall-corner-top-right.svg",
+    "wall-tee-up.svg",
+    "wall-tee-right.svg",
+    "wall-tee-left.svg",
+    "wall-tee-down.svg",
+    "wall-cross.svg"
+  };
+
+  int i;
+
+  for (i = 0; i < 19; i++) {
+    if (walls_pixmaps[i])
+      g_object_unref (walls_pixmaps[i]);
+      
+    walls_pixmaps[i] = board_load_pixmap_file (small_files[i],
+		  		                              4 * properties->tilesize,
+                           						  4 * properties->tilesize);
+  }
+}
 
 GnibblesBoard *
 gnibbles_board_new (gint t_w, gint t_h) 
@@ -57,12 +116,12 @@ gnibbles_board_new (gint t_w, gint t_h)
   board->width = t_w;
   board->height = t_h;
   board->level = NULL;
-  board->surface =NULL;
+  board->surface = NULL;
   board->clutter_widget = gtk_clutter_embed_new ();
 
   ClutterActor *stage;
 
-  load_pixmap ();
+  board_load_pixmap ();
 
   stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (board->clutter_widget));
   clutter_stage_set_color (CLUTTER_STAGE(stage), &stage_color);
@@ -130,61 +189,61 @@ gnibbles_board_load_level (GnibblesBoard *board, GnibblesLevel *level)
   gint i,j;
   gint x_pos, y_pos;
   ClutterActor *tmp;  
-  gboolean wall = TRUE;
+  gboolean is_wall = TRUE;
 
   if (board->level)
     g_object_unref (board->level);
 
   board->level = clutter_group_new ();
 
-  /* Load walls onto the surface*/
+  /* Load wall_pixmaps onto the surface*/
   for (i = 0; i < BOARDHEIGHT; i++) {
     y_pos = i * properties->tilesize;
     for (j = 0; j < BOARDWIDTH; j++) {
-      wall = TRUE;
+      is_wall = TRUE;
       switch (level->walls[j][i]) {
         case 'a': // empty space
-          wall = FALSE;
+          is_wall = FALSE;
           break; // break right away
         case 'b': // straight up
-          tmp = gtk_clutter_texture_new_from_pixbuf (wall_pixmaps[1]);
+          tmp = gtk_clutter_texture_new_from_pixbuf (wall_pixmaps[0]);
           break;
         case 'c': // straight side
-          tmp = gtk_clutter_texture_new_from_pixbuf (wall_pixmaps[2]);
+          tmp = gtk_clutter_texture_new_from_pixbuf (wall_pixmaps[1]);
           break;
         case 'd': // corner bottom left
-          tmp = gtk_clutter_texture_new_from_pixbuf (wall_pixmaps[3]);
+          tmp = gtk_clutter_texture_new_from_pixbuf (wall_pixmaps[2]);
           break;
         case 'e': // corner bottom right
-          tmp = gtk_clutter_texture_new_from_pixbuf (wall_pixmaps[4]);
+          tmp = gtk_clutter_texture_new_from_pixbuf (wall_pixmaps[3]);
           break;
-        case 'f': // corner up left
-          tmp = gtk_clutter_texture_new_from_pixbuf (wall_pixmaps[5]);
+          case 'f': // corner up left
+          tmp = gtk_clutter_texture_new_from_pixbuf (wall_pixmaps[4]);
           break;
         case 'g': // corner up right
-          tmp = gtk_clutter_texture_new_from_pixbuf (wall_pixmaps[6]);
+          tmp = gtk_clutter_texture_new_from_pixbuf (wall_pixmaps[5]);
           break;
         case 'h': // tee up
-          tmp = gtk_clutter_texture_new_from_pixbuf (wall_pixmaps[7]);
+          tmp = gtk_clutter_texture_new_from_pixbuf (wall_pixmaps[6]);
           break;
         case 'i': // tee right
-          tmp = gtk_clutter_texture_new_from_pixbuf (wall_pixmaps[8]);
+          tmp = gtk_clutter_texture_new_from_pixbuf (wall_pixmaps[7]);
           break;
         case 'j': // tee left
-          tmp = gtk_clutter_texture_new_from_pixbuf (wall_pixmaps[9]);
+          tmp = gtk_clutter_texture_new_from_pixbuf (wall_pixmaps[8]);
           break;
         case 'k': // tee down
-          tmp = gtk_clutter_texture_new_from_pixbuf (wall_pixmaps[10]);
+          tmp = gtk_clutter_texture_new_from_pixbuf (wall_pixmaps[9]);
           break;
         case 'l': // cross
-          tmp = gtk_clutter_texture_new_from_pixbuf (wall_pixmaps[11]);
+          tmp = gtk_clutter_texture_new_from_pixbuf (wall_pixmaps[10]);
           break;
         default:
-          wall = FALSE;
+          is_wall = FALSE;
           break;
       }
 
-      if (wall == TRUE) {
+      if (is_wall) {
         x_pos = j * properties->tilesize;
 
         clutter_actor_set_size (CLUTTER_ACTOR(tmp),
@@ -236,67 +295,3 @@ gnibbles_board_resize (GnibblesBoard *board, gint newtile)
     clutter_actor_set_size (tmp ,newtile, newtile);
   }
 }
-
-static void 
-load_pixmap ()
-{
-
-  gchar *small_files[] = {
-    "wall-empty.svg",
-    "wall-straight-up.svg",
-    "wall-straight-side.svg",
-    "wall-corner-bottom-left.svg",
-    "wall-corner-bottom-right.svg",
-    "wall-corner-top-left.svg",
-    "wall-corner-top-right.svg",
-    "wall-tee-up.svg",
-    "wall-tee-right.svg",
-    "wall-tee-left.svg",
-    "wall-tee-down.svg",
-    "wall-cross.svg",
-    "snake-red.svg",
-    "snake-green.svg",
-    "snake-blue.svg",
-    "snake-yellow.svg",
-    "snake-cyan.svg",
-    "snake-magenta.svg",
-    "snake-grey.svg"
-  };
-
-  int i;
-
-  for (i = 0; i < 19; i++) {
-    if (wall_pixmaps[i])
-      g_object_unref (wall_pixmaps[i]);
-      
-    wall_pixmaps[i] = load_pixmap_file (small_files[i],
-		  		                              4 * properties->tilesize,
-                           						  4 * properties->tilesize);
-  }
-}
-
-static GdkPixbuf *
-load_pixmap_file (const gchar * pixmap, gint xsize, gint ysize)
-{
-  GdkPixbuf *image;
-  gchar *filename;
-  const char *dirname;
-
-  dirname = games_runtime_get_directory (GAMES_RUNTIME_GAME_PIXMAP_DIRECTORY);
-  filename = g_build_filename (dirname, pixmap, NULL);
-
-  if (!filename) {
-    char *message =
-      g_strdup_printf (_("Nibbles couldn't find pixmap file:\n%s\n\n"
-			 "Please check your Nibbles installation"), pixmap);
-    //gnibbles_error (window, message;
-    g_free(message);
-  }
-
-  image = gdk_pixbuf_new_from_file_at_size (filename, xsize, ysize, NULL);
-  g_free (filename);
-
-  return image;
-}
-
-
diff --git a/gnibbles/main.c b/gnibbles/main.c
index ff286da..6489221 100644
--- a/gnibbles/main.c
+++ b/gnibbles/main.c
@@ -50,6 +50,7 @@
 #include <clutter/clutter.h>
 
 #include "board.h"
+#include "worm-clutter.h"
 
 #ifdef GGZ_CLIENT
 #include <libgames-support/games-dlg-chat.h>
@@ -87,6 +88,19 @@ GnibblesProperties *properties;
 
 GnibblesScoreboard *scoreboard;
 
+GdkPixbuf *wall_pixmaps[11] = { NULL, NULL, NULL, NULL, NULL,
+  NULL, NULL, NULL, NULL, NULL,
+  NULL
+};
+
+GdkPixbuf *worm_pixmaps[7] = { NULL, NULL, NULL, NULL, NULL,
+  NULL, NULL
+};
+
+GdkPixbuf *boni_pixmaps[9] = { NULL, NULL, NULL, NULL, NULL,
+  NULL, NULL, NULL, NULL
+};
+
 extern GnibblesBoni *boni;
 
 gchar board[BOARDWIDTH][BOARDHEIGHT];
@@ -124,6 +138,98 @@ static GtkAction *scores_action;
 static GtkAction *fullscreen_action;
 static GtkAction *leave_fullscreen_action;
 
+static GdkPixbuf *
+load_pixmap_file (const gchar * pixmap, gint xsize, gint ysize)
+{
+  GdkPixbuf *image;
+  gchar *filename;
+  const char *dirname;
+
+  dirname = games_runtime_get_directory (GAMES_RUNTIME_GAME_PIXMAP_DIRECTORY);
+  filename = g_build_filename (dirname, pixmap, NULL);
+
+  if (!filename) {
+    char *message =
+      g_strdup_printf (_("Nibbles couldn't find pixmap file:\n%s\n\n"
+			 "Please check your Nibbles installation"), pixmap);
+    //gnibbles_error (window, message;
+    g_free(message);
+  }
+
+  image = gdk_pixbuf_new_from_file_at_size (filename, xsize, ysize, NULL);
+  g_free (filename);
+
+  return image;
+}
+
+static void 
+load_pixmap ()
+{
+  gchar *bonus_files[] = {
+    "blank.svg",
+    "diamond.svg",
+    "bonus1.svg",
+    "bonus2.svg",
+    "life.svg",
+    "bonus3.svg",
+    "bonus4.svg",
+    "bonus5.svg",
+    "questionmark.svg"
+  };
+
+  gchar *small_files[] = {
+    "wall-straight-up.svg",
+    "wall-straight-side.svg",
+    "wall-corner-bottom-left.svg",
+    "wall-corner-bottom-right.svg",
+    "wall-corner-top-left.svg",
+    "wall-corner-top-right.svg",
+    "wall-tee-up.svg",
+    "wall-tee-right.svg",
+    "wall-tee-left.svg",
+    "wall-tee-down.svg",
+    "wall-cross.svg"
+  };
+  
+  gchar *worm_files[] = {
+    "snake-red.svg",
+    "snake-green.svg",
+    "snake-blue.svg",
+    "snake-yellow.svg",
+    "snake-cyan.svg",
+    "snake-magenta.svg",
+    "snake-grey.svg"
+  };
+
+  int i;
+
+  for (i = 0; i < 9; i++) {
+    if (boni_pixmaps[i])
+      g_object_unref (boni_pixmaps[i]);
+    boni_pixmaps[i] = load_pixmap_file (bonus_files[i],
+						  4 * properties->tilesize,
+						  4 * properties->tilesize);
+  }
+
+  for (i = 0; i < 11; i++) {
+    if (wall_pixmaps[i])
+      g_object_unref (wall_pixmaps[i]);
+      
+    wall_pixmaps[i] = load_pixmap_file (small_files[i],
+		  		                              4 * properties->tilesize,
+                           						  4 * properties->tilesize);
+  }
+
+  for (i = 0; i < 7; i++) {
+    if (worm_pixmaps[i])
+      g_object_unref (worm_pixmaps[i]);
+
+    worm_pixmaps[i] = load_pixmap_file (worm_files[i],
+                                        4 * properties->tilesize,
+                                        4 * properties->tilesize);
+  }
+}
+
 static void
 hide_cursor (void)
 {
@@ -1218,13 +1324,16 @@ 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);
   GnibblesBoard *board = gnibbles_board_new (BOARDWIDTH, BOARDHEIGHT);
   setup_window_clutter (board);
   
-  gnibbles_board_load_level (board, gnibbles_level_new (1));
+  gnibbles_board_load_level (board, gnibbles_level_new (16));
+
+  //GnibblesCWorm *cworm = gnibbles_cworm_new (1,10,10);
 
   //render_logo_clutter (board);
 
diff --git a/gnibbles/worm-clutter.c b/gnibbles/worm-clutter.c
index 3328f04..22283f6 100644
--- a/gnibbles/worm-clutter.c
+++ b/gnibbles/worm-clutter.c
@@ -19,13 +19,19 @@
  *   along with this program; if not, write to the Free Software
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
-
+#include <config.h>
+#include <glib/gi18n.h>
+#include <gdk/gdk.h>
+#include <stdlib.h>
+#include <libgames-support/games-runtime.h>
+
+#include "main.h"
+#include "gnibbles.h"
 #include "properties.h"
 #include "worm-clutter.h"
 
 extern GnibblesProperties *properties;
 
-
 GnibblesCWorm*
 gnibbles_cworm_new (guint number, gint x_s, gint y_s)
 {



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