[hitori] Port to GTK+ 3



commit e5a751639ccb7ddf4b499eecc9169cfbd3435dfe
Author: Philip Withnall <philip tecnocode co uk>
Date:   Thu Oct 28 17:46:57 2010 +0100

    Port to GTK+ 3
    
    This bumps the dependency on GTK+ to 3 unconditionally, and does a basic
    port of the interface drawing code to it.

 configure.ac    |    2 +-
 data/hitori.ui  |    2 +-
 src/interface.c |   39 ++++++++++++++++++++++++---------------
 3 files changed, 26 insertions(+), 17 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index f6017fe..b41bf95 100644
--- a/configure.ac
+++ b/configure.ac
@@ -31,7 +31,7 @@ GNOME_DOC_INIT
 
 # Dependencies
 AC_CHECK_FUNCS([floor])
-PKG_CHECK_MODULES([GENERAL],[glib-2.0 gtk+-2.0 >= 2.13 gmodule-2.0 cairo >= 1.4])
+PKG_CHECK_MODULES([GENERAL],[glib-2.0 gtk+-3.0 gmodule-2.0 cairo >= 1.4])
 
 # Output!
 AC_CONFIG_FILES([
diff --git a/data/hitori.ui b/data/hitori.ui
index fed554a..aebdf41 100644
--- a/data/hitori.ui
+++ b/data/hitori.ui
@@ -181,7 +181,7 @@
 						<property name="width-request">400</property>
 						<property name="height-request">400</property>
 						<property name="events">GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-						<signal name="expose-event" handler="hitori_expose_cb"/>
+						<signal name="draw" handler="hitori_draw_cb"/>
 						<signal name="button-release-event" handler="hitori_button_release_cb"/>
 					</object>
 				</child>
diff --git a/src/interface.c b/src/interface.c
index 774d7c8..8b52569 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -34,7 +34,7 @@
 #define HINT_INTERVAL 500
 
 /* Declarations for GtkBuilder */
-gboolean hitori_expose_cb (GtkWidget *drawing_area, GdkEventExpose *event, Hitori *hitori);
+gboolean hitori_draw_cb (GtkWidget *drawing_area, cairo_t *cr, Hitori *hitori);
 gboolean hitori_button_release_cb (GtkWidget *drawing_area, GdkEventButton *event, Hitori *hitori);
 void hitori_destroy_cb (GtkWindow *window, Hitori *hitori);
 void hitori_new_game_cb (GtkAction *action, Hitori *hitori);
@@ -111,7 +111,8 @@ hitori_draw_board (Hitori *hitori, cairo_t *cr, gboolean check_win)
 		has_won = TRUE;
 	}
 
-	gdk_drawable_get_size (GDK_DRAWABLE (gtk_widget_get_window (hitori->drawing_area)), &area_width, &area_height);
+	area_width = gdk_window_get_width (gtk_widget_get_window (hitori->drawing_area));
+	area_height = gdk_window_get_height (gtk_widget_get_window (hitori->drawing_area));
 	style = gtk_widget_get_style (hitori->drawing_area);
 
 	/* Clamp the width/height to the minimum */
@@ -247,26 +248,32 @@ void
 hitori_draw_board_simple (Hitori *hitori, gboolean check_win, gboolean clear_first)
 {
 	cairo_t *cr;
+	GdkWindow *window;
 
-	if (clear_first)
-		gdk_window_clear (gtk_widget_get_window (hitori->drawing_area));
+	window = gtk_widget_get_window (hitori->drawing_area);
+	cr = gdk_cairo_create (GDK_DRAWABLE (window));
+
+	if (clear_first) {
+		gint width, height;
+		GtkStyle *style;
+
+		width = gdk_window_get_width (window);
+		height = gdk_window_get_height (window);
+		style = gtk_widget_get_style (hitori->drawing_area);
+
+		cairo_set_source (cr, style->background[GTK_STATE_NORMAL]);
+		cairo_rectangle (cr, 0.0, 0.0, width, height);
+		cairo_paint (cr);
+	}
 
-	cr = gdk_cairo_create (GDK_DRAWABLE (gtk_widget_get_window (hitori->drawing_area)));
 	hitori_draw_board (hitori, cr, check_win);
 	cairo_destroy (cr);
 }
 
 gboolean
-hitori_expose_cb (GtkWidget *drawing_area, GdkEventExpose *event, Hitori *hitori)
+hitori_draw_cb (GtkWidget *drawing_area, cairo_t *cr, Hitori *hitori)
 {
-	cairo_t *cr;
-
-	cr = gdk_cairo_create (GDK_DRAWABLE (gtk_widget_get_window (hitori->drawing_area)));
-	cairo_rectangle (cr, event->area.x, event->area.y,
-				event->area.width, event->area.height);
-	cairo_clip (cr);
 	hitori_draw_board (hitori, cr, FALSE);
-	cairo_destroy (cr);
 
 	return FALSE;
 }
@@ -283,7 +290,8 @@ hitori_button_release_cb (GtkWidget *drawing_area, GdkEventButton *event, Hitori
 	if (hitori->processing_events == FALSE)
 		return FALSE;
 
-	gdk_drawable_get_size (GDK_DRAWABLE (gtk_widget_get_window (hitori->drawing_area)), &width, &height);
+	width = gdk_window_get_width (gtk_widget_get_window (hitori->drawing_area));
+	height = gdk_window_get_height (gtk_widget_get_window (hitori->drawing_area));
 
 	/* Clamp the width/height to the minimum */
 	if (height < width)
@@ -370,7 +378,8 @@ hitori_update_hint (Hitori *hitori)
 		g_debug ("Updating hint status to %u.", hitori->hint_status);
 
 	/* Calculate the area to redraw (just the hinted cell, hopefully) */
-	gdk_drawable_get_size (GDK_DRAWABLE (gtk_widget_get_window (hitori->drawing_area)), &area_width, &area_height);
+	area_width = gdk_window_get_width (gtk_widget_get_window (hitori->drawing_area));
+	area_height = gdk_window_get_height (gtk_widget_get_window (hitori->drawing_area));
 
 	/* Clamp the width/height to the minimum */
 	if (area_height < area_width) {



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