[gnome-nibbles] Revert "Removed games-frame and notebook" This reverts commit a0296baad35622cd3349a26f2fad36d0e1e5b1



commit eee6ab506b658a54204bc5052f12d2141ffd3075
Author: Bryan Quigley <bryanquigs src gnome org>
Date:   Thu Jan 23 23:29:45 2014 -0500

    Revert "Removed games-frame and notebook"
    This reverts commit a0296baad35622cd3349a26f2fad36d0e1e5b1d8.

 src/Makefile.am       |    2 +
 src/games-gridframe.c |  278 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/games-gridframe.h |   63 +++++++++++
 src/main.c            |   30 +++---
 4 files changed, 356 insertions(+), 17 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 0fd33bc..d917e79 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -11,6 +11,8 @@ gnome_nibbles_SOURCES = \
        warpmanager.c \
        games-controls.h \
        games-controls.c \
+       games-gridframe.h \
+       games-gridframe.c \
        games-score.h                   \
        games-score.c                   \
        games-scores.c                  \
diff --git a/src/games-gridframe.c b/src/games-gridframe.c
new file mode 100644
index 0000000..968047f
--- /dev/null
+++ b/src/games-gridframe.c
@@ -0,0 +1,278 @@
+/* games-gridframe.c: Create a container that guarantees that the internal
+ *                    allocated space is a fixed multiple of an integer. 
+ *
+ * Copyright 2004 by Callum McKenzie
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/* A lot of this was written by following the sorce for GtkFrame and
+ * GtkAspectFrame. */
+
+#include <config.h>
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+
+#include "games-gridframe.h"
+
+enum {
+  PROP_0,
+  PROP_X_PADDING,
+  PROP_Y_PADDING,
+  PROP_WIDTH,
+  PROP_HEIGHT,
+  PROP_X_ALIGN,
+  PROP_Y_ALIGN
+};
+
+G_DEFINE_TYPE (GamesGridFrame, games_grid_frame,GTK_TYPE_BIN)
+
+struct GamesGridFramePrivate {
+  gint xmult;
+  gint ymult;
+
+  gint xpadding;
+  gint ypadding;
+
+  gfloat xalign;
+  gfloat yalign;
+
+  GtkAllocation old_allocation;
+};
+
+void
+games_grid_frame_set (GamesGridFrame * frame, gint newxmult, gint newymult)
+{
+  if (newxmult > 0)
+    frame->priv->xmult = newxmult;
+  if (newymult > 0)
+    frame->priv->ymult = newymult;
+
+  gtk_widget_queue_resize (GTK_WIDGET (frame));
+}
+
+void
+games_grid_frame_set_padding (GamesGridFrame * frame, gint newxpadding,
+                             gint newypadding)
+{
+  if (newxpadding >= 0)
+    frame->priv->xpadding = newxpadding;
+
+  if (newypadding >= 0)
+    frame->priv->ypadding = newypadding;
+
+  gtk_widget_queue_resize (GTK_WIDGET (frame));
+}
+
+
+void
+games_grid_frame_set_alignment (GamesGridFrame * frame, gfloat xalign,
+                               gfloat yalign)
+{
+  if (xalign < 0.0)
+    xalign = 0.0;
+  else if (xalign > 1.0)
+    xalign = 1.0;
+
+  if (yalign < 0.0)
+    yalign = 0.0;
+  else if (yalign > 1.0)
+    yalign = 1.0;
+
+  frame->priv->xalign = xalign;
+  frame->priv->yalign = yalign;
+
+  gtk_widget_queue_resize (GTK_WIDGET (frame));
+}
+
+static void
+games_grid_frame_set_property (GObject * object, guint prop_id,
+                              const GValue * value, GParamSpec * pspec)
+{
+  GamesGridFrame *frame = GAMES_GRID_FRAME (object);
+
+  switch (prop_id) {
+  case PROP_X_PADDING:
+    games_grid_frame_set_padding (frame, g_value_get_int (value), -1);
+    break;
+  case PROP_Y_PADDING:
+    games_grid_frame_set_padding (frame, -1, g_value_get_int (value));
+    break;
+  case PROP_X_ALIGN:
+    games_grid_frame_set_alignment (frame, g_value_get_float (value),
+                                   frame->priv->yalign);
+    break;
+  case PROP_Y_ALIGN:
+    games_grid_frame_set_alignment (frame, frame->priv->xalign,
+                                   g_value_get_float (value));
+    break;
+  case PROP_WIDTH:
+    games_grid_frame_set (frame, g_value_get_int (value), -1);
+    break;
+  case PROP_HEIGHT:
+    games_grid_frame_set (frame, -1, g_value_get_int (value));
+    break;
+  default:
+    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    break;
+  }
+}
+
+static void
+games_grid_frame_get_property (GObject * object, guint prop_id,
+                              GValue * value, GParamSpec * pspec)
+{
+  GamesGridFrame *frame = GAMES_GRID_FRAME (object);
+
+  switch (prop_id) {
+  case PROP_X_PADDING:
+    g_value_set_int (value, frame->priv->xpadding);
+    break;
+  case PROP_Y_PADDING:
+    g_value_set_int (value, frame->priv->ypadding);
+    break;
+  case PROP_X_ALIGN:
+    g_value_set_float (value, frame->priv->xalign);
+    break;
+  case PROP_Y_ALIGN:
+    g_value_set_float (value, frame->priv->yalign);
+    break;
+  case PROP_WIDTH:
+    g_value_set_int (value, frame->priv->xmult);
+    break;
+  case PROP_HEIGHT:
+    g_value_set_int (value, frame->priv->ymult);
+    break;
+  default:
+    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    break;
+  }
+}
+
+static void
+games_grid_frame_size_allocate (GtkWidget * widget,
+                               GtkAllocation * allocation)
+{
+  GamesGridFrame *frame = GAMES_GRID_FRAME (widget);
+  GtkWidget *child = gtk_bin_get_child (GTK_BIN (widget));
+  GtkAllocation child_allocation;
+  gint xsize, ysize, size;
+
+  gtk_widget_set_allocation (widget, allocation);
+
+  xsize = MAX (1, (allocation->width - frame->priv->xpadding) / frame->priv->xmult);
+  ysize = MAX (1, (allocation->height - frame->priv->ypadding) / frame->priv->ymult);
+
+  size = MIN (xsize, ysize);
+
+  child_allocation.width = size * frame->priv->xmult + frame->priv->xpadding;
+  child_allocation.height = size * frame->priv->ymult + frame->priv->ypadding;
+
+  child_allocation.x =
+    (allocation->width - child_allocation.width) * frame->priv->xalign +
+    allocation->x;
+  child_allocation.y =
+    (allocation->height - child_allocation.height) * frame->priv->yalign +
+    allocation->y;
+
+  if (gtk_widget_get_mapped (widget) &&
+      (child_allocation.x != frame->priv->old_allocation.x ||
+       child_allocation.y != frame->priv->old_allocation.y ||
+       child_allocation.width != frame->priv->old_allocation.width ||
+       child_allocation.height != frame->priv->old_allocation.height))
+    gdk_window_invalidate_rect (gtk_widget_get_window (widget), allocation, FALSE);
+
+  if (child && gtk_widget_get_visible (child))
+    gtk_widget_size_allocate (child, &child_allocation);
+
+  frame->priv->old_allocation = child_allocation;
+}
+
+static void
+games_grid_frame_class_init (GamesGridFrameClass * class)
+{
+  GObjectClass *object_class;
+  GtkWidgetClass *widget_class;
+
+  object_class = G_OBJECT_CLASS (class);
+  widget_class = GTK_WIDGET_CLASS (class);
+
+  object_class->set_property = games_grid_frame_set_property;
+  object_class->get_property = games_grid_frame_get_property;
+
+  widget_class->size_allocate = games_grid_frame_size_allocate;
+
+  g_type_class_add_private (object_class, sizeof (GamesGridFramePrivate));  
+
+  g_object_class_install_property (object_class, PROP_X_PADDING,
+                                  g_param_spec_int ("x_padding", NULL, NULL,
+                                                    0, G_MAXINT, 0,
+                                                    G_PARAM_READABLE |
+                                                    G_PARAM_WRITABLE));
+  g_object_class_install_property (object_class, PROP_Y_PADDING,
+                                   g_param_spec_int ("y_padding", NULL, NULL,
+                                                    0, G_MAXINT, 0,
+                                                    G_PARAM_READABLE |
+                                                    G_PARAM_WRITABLE));
+  g_object_class_install_property (object_class, PROP_WIDTH,
+                                   g_param_spec_int ("width_multiple",  NULL, NULL,
+                                                    1, G_MAXINT, 1,
+                                                    G_PARAM_READABLE |
+                                                    G_PARAM_WRITABLE));
+  g_object_class_install_property (object_class, PROP_HEIGHT,
+                                   g_param_spec_int ("height_multiple", NULL, NULL,
+                                                    1, G_MAXINT, 1,
+                                                    G_PARAM_READABLE |
+                                                    G_PARAM_WRITABLE));
+  g_object_class_install_property (object_class, PROP_X_ALIGN,
+                                   g_param_spec_float ("xalign",  NULL, NULL,
+                                                      0.0, 1.0, 0.5,
+                                                      G_PARAM_READABLE |
+                                                      G_PARAM_WRITABLE));
+  g_object_class_install_property (object_class, PROP_Y_ALIGN,
+                                   g_param_spec_float ("yalign",  NULL, NULL,
+                                                      0.0, 1.0, 0.5,
+                                                      G_PARAM_READWRITE |
+                                                      G_PARAM_WRITABLE));
+}
+
+static void
+games_grid_frame_init (GamesGridFrame * frame)
+{
+  frame->priv = G_TYPE_INSTANCE_GET_PRIVATE (frame, GAMES_TYPE_GRID_FRAME, GamesGridFramePrivate);
+
+  frame->priv->xmult = 1;
+  frame->priv->ymult = 1;
+
+  frame->priv->xalign = 0.5;
+  frame->priv->yalign = 0.5;
+}
+
+GtkWidget *
+games_grid_frame_new (gint width, gint height)
+{
+  GamesGridFrame *frame;
+
+  frame = g_object_new (GAMES_TYPE_GRID_FRAME, NULL);
+
+  frame->priv->xmult = MAX (width, 1);
+  frame->priv->ymult = MAX (height, 1);
+
+  return GTK_WIDGET (frame);
+}
+
+/* EOF */
diff --git a/src/games-gridframe.h b/src/games-gridframe.h
new file mode 100644
index 0000000..2a8b32c
--- /dev/null
+++ b/src/games-gridframe.h
@@ -0,0 +1,63 @@
+/* games-gridframe.h: Create a container that guarantees that the internal
+ *                    allocated space is a fixed multiple of an integer. 
+ *
+ * Copyright 2004 by Callum McKenzie
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef GAMES_GRID_FRAME_H
+#define GAMES_GRID_FRAME_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GAMES_TYPE_GRID_FRAME            (games_grid_frame_get_type ())
+#define GAMES_GRID_FRAME(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_GRID_FRAME, 
GamesGridFrame))
+#define GAMES_GRID_FRAME_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_GRID_FRAME, 
GamesGridFrameClass))
+#define GAMES_IS_GRID_FRAME(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_GRID_FRAME))
+#define GAMES_IS_GRID_FRAME_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_GRID_FRAME))
+#define GAMES_GRID_FRAME_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_GRID_FRAME))
+
+typedef struct GamesGridFramePrivate GamesGridFramePrivate;
+
+typedef struct {
+  GtkBin bin;
+  /*< private >*/
+  GamesGridFramePrivate *priv;
+} GamesGridFrame;
+
+typedef struct {
+  GtkBinClass parent;
+} GamesGridFrameClass;
+
+GType      games_grid_frame_get_type      (void);
+GtkWidget *games_grid_frame_new           (gint width,
+                                           gint height);
+void       games_grid_frame_set           (GamesGridFrame * frame,
+                                           gint width,
+                                           gint height);
+void       games_grid_frame_set_padding   (GamesGridFrame * frame,
+                                           gint xpadding,
+                                           gint ypadding);
+void       games_grid_frame_set_alignment (GamesGridFrame * frame,
+                                           gfloat xalign,
+                                           gfloat yalign);
+
+G_END_DECLS
+#endif /* GAMES_GRID_FRAME_H */
+/* EOF */
diff --git a/src/main.c b/src/main.c
index f210fa8..1e66f2c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -39,6 +39,7 @@
 #include "preferences.h"
 #include "scoreboard.h"
 #include "warp.h"
+#include "games-gridframe.h"
 #include "games-scores.h"
 
 #include <clutter-gtk/clutter-gtk.h>
@@ -54,6 +55,7 @@ GSettings *settings;
 GSettings *worm_settings[NUMWORMS];
 GtkWidget *window;
 GtkWidget *statusbar;
+GtkWidget *notebook;
 GtkWidget *chat = NULL;
 
 static const GamesScoresCategory scorecats[] = {
@@ -580,12 +582,13 @@ activate (GtkApplication* app,
   GtkBuilder *builder;
 
   window = gtk_application_window_new (app);
+  gtk_window_set_default_size (GTK_WINDOW (window), 800, 600);
 
   g_action_map_add_action_entries (G_ACTION_MAP (app), app_entries, G_N_ELEMENTS (app_entries), app);
 
   builder = gtk_builder_new ();
 
-   gtk_builder_add_from_string (builder,
+  gtk_builder_add_from_string (builder,
                                "<interface>"
                                "  <menu id='app-menu'>"
                                "    <section>"
@@ -634,8 +637,7 @@ activate (GtkApplication* app,
 
   gtk_application_set_app_menu (GTK_APPLICATION (app), G_MENU_MODEL (gtk_builder_get_object (builder, 
"app-menu")));
 
-
-  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
+  
 
   clutter_widget = gtk_clutter_embed_new ();
   stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (clutter_widget));
@@ -645,33 +647,27 @@ activate (GtkApplication* app,
   clutter_actor_set_size (CLUTTER_ACTOR (stage),
                           properties->tilesize * BOARDWIDTH,
                           properties->tilesize * BOARDHEIGHT);
-  //clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), TRUE);
 
-  packing = gtk_aspect_frame_new (NULL,
-                        0.5,
-                        0.5,
-                        1.38,   //between 1.398176292 and 1.388888889
-                        FALSE);
-
-   gtk_container_add( GTK_CONTAINER(packing), clutter_widget); 
-
-  
+  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
 
+  //Games Grid Frame Packing
+  packing = games_grid_frame_new (BOARDWIDTH, BOARDHEIGHT);
+  gtk_container_add (GTK_CONTAINER (packing), clutter_widget);
   gtk_box_pack_start (GTK_BOX (vbox), packing, FALSE, TRUE, 0);
 
+  //Statusbar
   statusbar = gtk_statusbar_new ();
   gtk_box_pack_start (GTK_BOX (vbox), statusbar, FALSE, FALSE, 0);
-  scoreboard = gnibbles_scoreboard_new (statusbar);
 
+  //Actually inits the board/scoreboard
   board = gnibbles_board_new ();
+  scoreboard = gnibbles_scoreboard_new (statusbar);
 
   gtk_container_add (GTK_CONTAINER (window), vbox);
-  gtk_window_set_default_size (GTK_WINDOW (window), 640, 480);
+  gtk_widget_show_all (window);
 
   g_signal_connect (G_OBJECT (clutter_widget), "configure_event",
                     G_CALLBACK (configure_event_cb), NULL);
-
-  gtk_widget_show_all (window);
 }
 
 


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