chiark / gitweb /
Beginnings of a GTK framework. (And I do mean _beginnings_; it opens
authorSimon Tatham <anakin@pobox.com>
Sun, 25 Apr 2004 14:45:22 +0000 (14:45 +0000)
committerSimon Tatham <anakin@pobox.com>
Sun, 25 Apr 2004 14:45:22 +0000 (14:45 +0000)
a window and that's about it.)

[originally from svn r4139]

gtk.c
net.c

diff --git a/gtk.c b/gtk.c
index 365d11d844793a1cb23bd2d717c9ee5389700162..1d5ffdc631df5397f9d1cddd3556cc2e5019fe36 100644 (file)
--- a/gtk.c
+++ b/gtk.c
@@ -6,8 +6,14 @@
 #include <stdlib.h>
 #include <stdarg.h>
 
+#include <gtk/gtk.h>
+
 #include "puzzles.h"
 
+/* ----------------------------------------------------------------------
+ * Error reporting functions used elsewhere.
+ */
+
 void fatal(char *fmt, ...)
 {
     va_list ap;
@@ -21,3 +27,45 @@ void fatal(char *fmt, ...)
     fprintf(stderr, "\n");
     exit(1);
 }
+
+/* ----------------------------------------------------------------------
+ * GTK front end to puzzles.
+ */
+
+/*
+ * This structure holds all the data relevant to a single window.
+ * In principle this would allow us to open multiple independent
+ * puzzle windows, although I can't currently see any real point in
+ * doing so. I'm just coding cleanly because there's no
+ * particularly good reason not to.
+ */
+struct window_data {
+    GtkWidget *window;
+};
+
+static void destroy(GtkWidget *widget, gpointer data)
+{
+    gtk_main_quit();
+}
+
+static struct window_data *new_window(void)
+{
+    struct window_data *wdata;
+
+    wdata = snew(struct window_data);
+
+    wdata->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+    gtk_signal_connect(GTK_OBJECT(wdata->window), "destroy",
+                      GTK_SIGNAL_FUNC(destroy), wdata);
+    gtk_widget_show(wdata->window);
+    return wdata;
+}
+
+int main(int argc, char **argv)
+{
+    gtk_init(&argc, &argv);
+    (void) new_window();
+    gtk_main();
+
+    return 0;
+}
diff --git a/net.c b/net.c
index 4984364346e3e46b9b8452f218be4fa3005b64d5..a5fe8c0d698c10fcc7f134b4d805de46f7efd2ae 100644 (file)
--- a/net.c
+++ b/net.c
@@ -586,7 +586,11 @@ game_state *make_move(game_state *state, int x, int y, int button)
  * Routines for drawing the game position on the screen.
  */
 
-#ifndef TESTMODE                      /* FIXME: should be #ifdef */
+/* ----------------------------------------------------------------------
+ * Test code.
+ */
+
+#ifdef TESTMODE
 
 int main(void)
 {