[atomix/wip/gtk3-port] Board: background ported



commit 0dd0e0eb097b922367000b580f6615b7d6014d5d
Author: Robert Roth <robert roth off gmail com>
Date:   Sun Jan 11 16:39:59 2015 +0200

    Board: background ported

 src/Makefile.am |    2 +-
 src/board.h     |    2 -
 src/board_gtk.c |  141 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/board_gtk.h |   49 +++++++++++++++++++
 src/main.c      |   46 ++++++++++++------
 src/main.h      |    2 +-
 6 files changed, 222 insertions(+), 20 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 521aa0f..4f563d9 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -16,7 +16,7 @@ noinst_PROGRAMS = pf-test
 
 atomix_SOURCES = \
        main.c main.h \
-       board.c board.h \
+       board_gtk.c board_gtk.h \
        undo.c undo.h \
        goal.c goal.h \
        goal-view.c goal-view.h \
diff --git a/src/board.h b/src/board.h
index 1943d70..32065a3 100644
--- a/src/board.h
+++ b/src/board.h
@@ -39,8 +39,6 @@ void board_hide (void);
 
 void board_show (void);
 
-void board_show_normal_cursor (void);
-
 gboolean board_undo_move (void);
 
 void board_show_logo (gboolean visible);
diff --git a/src/board_gtk.c b/src/board_gtk.c
new file mode 100644
index 0000000..e08c4c7
--- /dev/null
+++ b/src/board_gtk.c
@@ -0,0 +1,141 @@
+/* Atomix -- a little puzzle game about atoms and molecules.
+ * Copyright (C) 1999 Jens Finke
+ * Copyright (C) 2005 Guilherme de S. Pastore
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "board_gtk.h"
+
+static GtkFixed *board_canvas = NULL;
+static Theme *board_theme = NULL;
+
+#define BGR_FLOOR_ROWS 15
+#define BGR_FLOOR_COLS 15
+
+static void create_background_floor (void)
+{
+  int row, col;
+  Tile *tile;
+  GQuark quark;
+  int tile_width, tile_height;
+  double x, y;
+  GdkPixbuf *pixbuf = NULL;
+  GtkWidget *item;
+  int ca_width, ca_height;
+  int width, height;
+  GtkAllocation allocation;
+
+  quark = g_quark_from_static_string ("floor");
+  theme_get_tile_size (board_theme, &tile_width, &tile_height);
+
+  tile = tile_new (TILE_TYPE_FLOOR);
+  tile_set_base_id (tile, quark);
+  pixbuf = theme_get_tile_image (board_theme, tile);
+  g_object_unref (tile);
+
+  for (row = 0; row < BGR_FLOOR_ROWS; row++)
+    for (col = 0; col < BGR_FLOOR_COLS; col++)
+      {
+       x = col * tile_width;
+       y = row * tile_height;
+
+    item = gtk_image_new_from_pixbuf (pixbuf);
+    gtk_fixed_put (GTK_FIXED (board_canvas), item, x, y);
+       //item = gnome_canvas_item_new (level_items->floor,
+       //                            gnome_canvas_pixbuf_get_type (),
+       //                            "pixbuf", pixbuf, "x", x, "x_in_pixels",
+       //                            TRUE, "y", y, "y_in_pixels", TRUE,
+       //                            "width",
+       //                            (double) gdk_pixbuf_get_width (pixbuf),
+       //                            "height",
+       //                            (double) gdk_pixbuf_get_height (pixbuf),
+       //                            "anchor", GTK_ANCHOR_NW, NULL);
+      }
+
+  g_object_unref (pixbuf);
+
+  /* center the whole thing */
+  gtk_widget_get_allocation (GTK_WIDGET (board_canvas), &allocation);
+  ca_width = allocation.width;
+  ca_height = allocation.height;
+
+  width = tile_width * BGR_FLOOR_COLS;
+  height = tile_height * BGR_FLOOR_ROWS;
+
+  if (width > ca_width)
+    {
+      x = (width / 2) - (ca_width / 2);
+      width = ca_width;
+    }
+  else
+    x = 0;
+
+  if (height > ca_height)
+    {
+      y = (height / 2) - (ca_height / 2);
+      height = ca_height;
+    }
+  else
+    y = 0;
+}
+
+void board_gtk_init (Theme * theme, gpointer canvas)
+{
+  board_theme = theme;
+  board_canvas = canvas;
+
+  create_background_floor ();
+  gtk_widget_show_all (GTK_WIDGET(board_canvas));
+}
+
+void board_gtk_init_level (PlayField * env, PlayField * sce, Goal * goal)
+{
+}
+
+void board_gtk_destroy (void)
+{
+}
+
+void board_gtk_clear (void)
+{
+}
+
+void board_gtk_print (void)
+{
+}
+
+void board_gtk_hide (void)
+{
+}
+
+void board_gtk_show (void)
+{
+}
+
+gboolean board_gtk_undo_move (void)
+{
+    return FALSE;
+}
+
+void board_gtk_show_logo (gboolean visible)
+{
+}
+
+void board_gtk_handle_key_event (GObject * canvas, GdkEventKey * event,
+                            gpointer data)
+{
+}
+
diff --git a/src/board_gtk.h b/src/board_gtk.h
new file mode 100644
index 0000000..64630d6
--- /dev/null
+++ b/src/board_gtk.h
@@ -0,0 +1,49 @@
+/* Atomix -- a little puzzle game about atoms and molecules.
+ * Copyright (C) 1999 Jens Finke
+ * Copyright (C) 2005 Guilherme de S. Pastore
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef _ATOMIX_BOARD_GTK_H_
+#define _ATOMIX_BOARD_GTK_H_
+
+#include <gtk/gtk.h>
+#include "theme.h"
+#include "playfield.h"
+#include "goal.h"
+
+void board_gtk_init (Theme * theme, gpointer canvas);
+
+void board_gtk_init_level (PlayField * env, PlayField * sce, Goal * goal);
+
+void board_gtk_destroy (void);
+
+void board_gtk_clear (void);
+
+void board_gtk_print (void);
+
+void board_gtk_hide (void);
+
+void board_gtk_show (void);
+
+gboolean board_gtk_undo_move (void);
+
+void board_gtk_show_logo (gboolean visible);
+
+void board_gtk_handle_key_event (GObject * canvas, GdkEventKey * event,
+                            gpointer data);
+
+#endif /* _ATOMIX_BOARD_GTK_H_ */
diff --git a/src/main.c b/src/main.c
index 2ae0b20..4ec7371 100644
--- a/src/main.c
+++ b/src/main.c
@@ -26,7 +26,7 @@
 #include <unistd.h>
 #include <errno.h>
 
-#include "board.h"
+#include "board_gtk.h"
 #include "playfield.h"
 #include "main.h"
 #include "goal.h"
@@ -179,7 +179,7 @@ static void controller_handle_action (GameAction action)
 
        case GAME_ACTION_PAUSE:
          clock_stop (CLOCK (app->clock));
-         board_hide ();
+         board_gtk_hide ();
          app->state = GAME_STATE_PAUSED;
          break;
 
@@ -220,7 +220,7 @@ static void controller_handle_action (GameAction action)
        case GAME_ACTION_UNDO:
          g_assert (app->state != GAME_STATE_RUNNING_UNMOVED);
 
-         board_undo_move ();
+         board_gtk_undo_move ();
          break;
 
        default:
@@ -232,7 +232,7 @@ static void controller_handle_action (GameAction action)
       if (action == GAME_ACTION_CONTINUE)
        {
          clock_start (CLOCK(app->clock));
-         board_show ();
+         board_gtk_show ();
          app->state = (undo_exists())?GAME_STATE_RUNNING:GAME_STATE_RUNNING_UNMOVED;
        }
       break;
@@ -247,7 +247,7 @@ static void controller_handle_action (GameAction action)
 
 static void set_game_not_running_state (void)
 {
-  board_show_logo (TRUE);
+  board_gtk_show_logo (TRUE);
 
   if (app->level)
     g_object_unref (app->level);
@@ -310,8 +310,8 @@ static void setup_level (void)
   /* init board */
   env_pf = level_get_environment (app->level);
   sce_pf = level_get_scenario (app->level);
-  board_show_logo (FALSE);
-  board_init_level (env_pf, sce_pf, app->goal);
+  board_gtk_show_logo (FALSE);
+  board_gtk_init_level (env_pf, sce_pf, app->goal);
 
   /* init goal */
   goal_view_render (app->goal);
@@ -326,7 +326,7 @@ static void setup_level (void)
 
 static void level_cleanup_view (void)
 {
-  board_clear ();
+  board_gtk_clear ();
   goal_view_clear ();
 
   clock_stop (CLOCK(app->clock));
@@ -345,7 +345,7 @@ static void atomix_exit (void)
       set_game_not_running_state ();
     }
 
-  board_destroy ();
+  board_gtk_destroy ();
 
   if (app->level)
     g_object_unref (app->level);
@@ -370,7 +370,7 @@ static gboolean on_key_press_event (GObject *widget, GdkEventKey *event,
 {
   if ((app->state == GAME_STATE_RUNNING) || (app->state == GAME_STATE_RUNNING_UNMOVED))
     {
-      board_handle_key_event (NULL, event, NULL);
+      board_gtk_handle_key_event (NULL, event, NULL);
     }
 
   return TRUE;
@@ -398,7 +398,7 @@ static void game_init ()
   clock_set_seconds (CLOCK(app->clock), 0);
 
   /* init the board */
-  board_init (app->theme, GNOME_CANVAS (app->ca_matrix));
+  board_gtk_init (app->theme, GTK_FIXED (app->fi_matrix));
 
   /* init goal */
   goal_view_init (app->theme, GTK_FIXED (app->fi_goal));
@@ -408,7 +408,7 @@ static void game_init ()
   update_menu_item_state ();
   update_statistics ();
 
-  gtk_widget_grab_focus (GTK_WIDGET (app->ca_matrix));
+  gtk_widget_grab_focus (GTK_WIDGET (app->fi_matrix));
 }
 
 void game_level_finished (void)
@@ -583,7 +583,7 @@ void update_menu_item_state (void)
              GUI creation  functions 
 
 -------------------------------------------------------------- */
-static GtkWidget *create_canvas_widget (GtkWidget **canvas)
+/*static GtkWidget *create_canvas_widget (GtkWidget **canvas)
 {
   GtkWidget *frame;
 
@@ -594,6 +594,19 @@ static GtkWidget *create_canvas_widget (GtkWidget **canvas)
   gtk_container_add (GTK_CONTAINER (frame), GTK_WIDGET (*canvas));
 
   return frame;
+}*/
+
+static GtkWidget *create_board_widget (GtkWidget **fixed)
+{
+  GtkWidget *frame;
+
+  *fixed = gtk_fixed_new ();
+
+  frame = gtk_frame_new (NULL);
+  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
+  gtk_container_add (GTK_CONTAINER (frame), GTK_WIDGET (*fixed));
+
+  return frame;
 }
 
 static GtkWidget *create_goal_widget (GtkWidget **fixed)
@@ -644,7 +657,7 @@ static GtkWidget *create_mainwin_content (AtomixApp *app)
   GtkWidget *table;
 
   /* create canvas widgets */
-  pf = create_canvas_widget (&app->ca_matrix);
+  pf = create_board_widget (&app->fi_matrix);
   goal = create_goal_widget (&app->fi_goal);
   gtk_widget_set_size_request (GTK_WIDGET (goal), 180, 50);
 
@@ -652,7 +665,7 @@ static GtkWidget *create_mainwin_content (AtomixApp *app)
   hbox = gtk_hbox_new (FALSE, 6);
   gtk_container_set_border_width (GTK_CONTAINER (hbox), 6);
   gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (pf), TRUE, TRUE, 0);
-  g_signal_connect (G_OBJECT (app->ca_matrix), "key_press_event",
+  g_signal_connect (G_OBJECT (app->fi_matrix), "key_press_event",
                    G_CALLBACK (on_key_press_event), app);
 
   /* create right window side */
@@ -796,7 +809,8 @@ int main (int argc, char *argv[])
 
   game_init ();
 
-  gtk_widget_set_size_request (GTK_WIDGET (app->mainwin), 660, 480);
+  gtk_widget_set_size_request (GTK_WIDGET (app->mainwin), 678, 520);
+  gtk_window_set_resizable (GTK_WINDOW (app->mainwin), FALSE);
   gtk_widget_show (app->mainwin);
 
   gtk_main ();
diff --git a/src/main.h b/src/main.h
index 3978ae7..9e2cb8b 100644
--- a/src/main.h
+++ b/src/main.h
@@ -39,7 +39,7 @@ typedef struct
 {
   GtkWidget *mainwin;
   GtkUIManager *ui_manager;
-  GtkWidget *ca_matrix;
+  GtkWidget *fi_matrix;
   GtkWidget *fi_goal;
   GtkWidget *lb_level;
   GtkWidget *lb_name;


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