[atomix/wip/gtk3-port] Ported goal view canvas to plain GTK widgets
- From: Robert Roth <robertroth src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [atomix/wip/gtk3-port] Ported goal view canvas to plain GTK widgets
- Date: Sun, 11 Jan 2015 01:09:20 +0000 (UTC)
commit 4e42785b4a67eead5405931ee3ec44f2562e09ef
Author: Robert Roth <robert roth off gmail com>
Date: Sun Jan 11 03:09:06 2015 +0200
Ported goal view canvas to plain GTK widgets
src/goal-view.c | 78 +++++++++++++++++++++++++-----------------------------
src/goal-view.h | 4 +-
src/main.c | 17 ++++++++++-
src/main.h | 2 +-
4 files changed, 54 insertions(+), 47 deletions(-)
---
diff --git a/src/goal-view.c b/src/goal-view.c
index 87d9b51..9798b28 100644
--- a/src/goal-view.c
+++ b/src/goal-view.c
@@ -18,27 +18,21 @@
*/
#include "goal-view.h"
-#include "canvas_helper.h"
-static GnomeCanvas *goal_canvas;
+static GtkFixed *goal_fixed;
static Theme *goal_theme;
-static GnomeCanvasGroup *item_group;
#define SCALE_FACTOR 0.7
-static GnomeCanvasItem *create_small_item (GnomeCanvasGroup *group,
- gdouble x, gdouble y, Tile *tile);
+static GtkImage *create_small_item (gdouble x, gdouble y, Tile *tile);
static void render_view (Goal *goal);
-void goal_view_init (Theme *theme, GnomeCanvas *canvas)
+void goal_view_init (Theme *theme, GtkFixed *fixed)
{
g_return_if_fail (IS_THEME (theme));
- g_return_if_fail (GNOME_IS_CANVAS (canvas));
+ g_return_if_fail (GTK_IS_FIXED (fixed));
- set_background_color (GTK_WIDGET (canvas),
- theme_get_background_color (theme));
-
- goal_canvas = canvas;
+ goal_fixed = fixed;
goal_theme = theme;
}
@@ -52,7 +46,7 @@ void goal_view_render (Goal *goal)
static void render_view (Goal *goal)
{
- GnomeCanvasItem *item;
+ GtkImage *item;
PlayField *pf;
gint row, col;
gdouble x;
@@ -63,20 +57,19 @@ static void render_view (Goal *goal)
gint width, height;
g_return_if_fail (IS_GOAL (goal));
- g_return_if_fail (GNOME_IS_CANVAS (goal_canvas));
+ g_return_if_fail (GTK_IS_FIXED (goal_fixed));
g_return_if_fail (IS_THEME (goal_theme));
- if (item_group == NULL)
- item_group = create_group (goal_canvas, NULL);
-
theme_get_tile_size (goal_theme, &tile_width, &tile_height);
pf = goal_get_playfield (goal);
for (row = 0; row < playfield_get_n_rows (pf); row++)
{
+ printf ("Row at %d\n", row);
for (col = 0; col < playfield_get_n_cols (pf); col++)
{
+ printf ("Column at %d\n", col);
tile = playfield_get_tile (pf, row, col);
if (!tile)
continue;
@@ -88,7 +81,8 @@ static void render_view (Goal *goal)
case TILE_TYPE_ATOM:
x = col * tile_width * SCALE_FACTOR;
y = row * tile_height * SCALE_FACTOR;
- item = create_small_item (item_group, x, y, tile);
+ item = create_small_item (x, y, tile);
+ printf ("Atom at %d, %d\n", row, col);
break;
@@ -100,29 +94,25 @@ static void render_view (Goal *goal)
g_object_unref (tile);
}
}
- set_background_color (GTK_WIDGET (goal_canvas),
- theme_get_background_color (goal_theme));
-
- width = tile_width * playfield_get_n_cols (pf) * SCALE_FACTOR;
- height = tile_height * playfield_get_n_rows (pf) * SCALE_FACTOR;
- gnome_canvas_set_scroll_region (goal_canvas, 0, 0, width, height);
g_object_unref (pf);
}
+static void remove_child (GtkWidget *widget, gpointer data)
+{
+ gtk_container_remove (GTK_CONTAINER (goal_fixed), widget);
+}
+
void goal_view_clear (void)
{
- if (item_group)
- gtk_object_destroy (GTK_OBJECT (item_group));
- item_group = NULL;
+ gtk_container_forall (GTK_CONTAINER (goal_fixed), remove_child, NULL);
}
-static GnomeCanvasItem *create_small_item (GnomeCanvasGroup *group,
- gdouble x, gdouble y, Tile *tile)
+static GtkImage *create_small_item (gdouble x, gdouble y, Tile *tile)
{
GdkPixbuf *pixbuf = NULL;
GdkPixbuf *small_pb = NULL;
- GnomeCanvasItem *item = NULL;
+ GtkWidget *item = NULL;
g_return_val_if_fail (IS_TILE (tile), NULL);
@@ -134,19 +124,23 @@ static GnomeCanvasItem *create_small_item (GnomeCanvasGroup *group,
gdk_pixbuf_get_height (pixbuf) *
SCALE_FACTOR, GDK_INTERP_BILINEAR);
- item = gnome_canvas_item_new (group,
- gnome_canvas_pixbuf_get_type (),
- "pixbuf", small_pb,
- "x", x,
- "x_in_pixels", TRUE,
- "y", y,
- "y_in_pixels", TRUE,
- "width",
- (gdouble) (gdk_pixbuf_get_width (small_pb)),
- "height",
- (gdouble) (gdk_pixbuf_get_height (small_pb)),
- "anchor", GTK_ANCHOR_NW, NULL);
+ item = gtk_image_new_from_pixbuf (small_pb);
+ gtk_widget_show (item);
+ gtk_fixed_put (goal_fixed, item, x, y);
+
+// item = gnome_canvas_item_new (group,
+// gnome_canvas_pixbuf_get_type (),
+// "pixbuf", small_pb,
+// "x", x,
+// "x_in_pixels", TRUE,
+// "y", y,
+// "y_in_pixels", TRUE,
+// "width",
+// (gdouble) (gdk_pixbuf_get_width (small_pb)),
+// "height",
+// (gdouble) (gdk_pixbuf_get_height (small_pb)),
+// "anchor", GTK_ANCHOR_NW, NULL);
g_object_unref (pixbuf);
- return GNOME_CANVAS_ITEM (item);
+ return GTK_IMAGE (item);
}
diff --git a/src/goal-view.h b/src/goal-view.h
index aa96b7d..2248597 100644
--- a/src/goal-view.h
+++ b/src/goal-view.h
@@ -20,12 +20,12 @@
#ifndef _ATOMIX_GOAL_VIEW_H_
#define _ATOMIX_GOAL_VIEW_H_
-#include <libgnomecanvas/libgnomecanvas.h>
+#include <gtk/gtk.h>
#include "theme.h"
#include "goal.h"
-void goal_view_init (Theme * theme, GnomeCanvas * canvas);
+void goal_view_init (Theme * theme, GtkFixed * fixed);
void goal_view_render (Goal * goal);
diff --git a/src/main.c b/src/main.c
index 9d37a69..2c298ae 100644
--- a/src/main.c
+++ b/src/main.c
@@ -408,7 +408,7 @@ static void game_init ()
board_init (app->theme, GNOME_CANVAS (app->ca_matrix));
/* init goal */
- goal_view_init (app->theme, GNOME_CANVAS (app->ca_goal));
+ goal_view_init (app->theme, GTK_FIXED (app->fi_goal));
/* update user visible information */
app->state = GAME_STATE_NOT_RUNNING;
@@ -603,6 +603,19 @@ static GtkWidget *create_canvas_widget (GtkWidget **canvas)
return frame;
}
+static GtkWidget *create_goal_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 void add_statistics_table_entry (GtkWidget *table, gint row,
gchar *label_str, gboolean is_clock,
GtkWidget **return_widget)
@@ -639,7 +652,7 @@ static GtkWidget *create_mainwin_content (AtomixApp *app)
/* create canvas widgets */
pf = create_canvas_widget (&app->ca_matrix);
- goal = create_canvas_widget (&app->ca_goal);
+ goal = create_goal_widget (&app->fi_goal);
gtk_widget_set_size_request (GTK_WIDGET (goal), 180, 50);
/* add playfield canvas to left side */
diff --git a/src/main.h b/src/main.h
index 4d44183..ff01fd2 100644
--- a/src/main.h
+++ b/src/main.h
@@ -41,7 +41,7 @@ typedef struct
GtkWidget *mainwin;
GtkUIManager *ui_manager;
GtkWidget *ca_matrix;
- GtkWidget *ca_goal;
+ GtkWidget *fi_goal;
GtkWidget *lb_level;
GtkWidget *lb_name;
GtkWidget *lb_formula;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]