8bb01fdbe31ff6ab0df6d5001bfe196d2f7bf5c9
2 * gtk.c: GTK front end for my puzzle collection.
13 /* ----------------------------------------------------------------------
14 * Error reporting functions used elsewhere.
17 void fatal(char *fmt
, ...)
21 fprintf(stderr
, "fatal error: ");
24 vfprintf(stderr
, fmt
, ap
);
27 fprintf(stderr
, "\n");
31 /* ----------------------------------------------------------------------
32 * GTK front end to puzzles.
36 * This structure holds all the data relevant to a single window.
37 * In principle this would allow us to open multiple independent
38 * puzzle windows, although I can't currently see any real point in
39 * doing so. I'm just coding cleanly because there's no
40 * particularly good reason not to.
48 static void destroy(GtkWidget
*widget
, gpointer data
)
53 gint
key_event(GtkWidget
*widget
, GdkEventKey
*event
, gpointer data
)
55 struct window_data
*wdata
= (struct window_data
*)data
;
59 if (!midend_process_key(wdata
->me
, 0, 0, event
->keyval
))
60 gtk_widget_destroy(wdata
->window
);
65 gint
button_event(GtkWidget
*widget
, GdkEventButton
*event
, gpointer data
)
67 struct window_data
*wdata
= (struct window_data
*)data
;
74 static struct window_data
*new_window(void)
76 struct window_data
*wdata
;
79 wdata
= snew(struct window_data
);
81 wdata
->me
= midend_new();
82 midend_new_game(wdata
->me
, NULL
);
84 wdata
->window
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
86 wdata
->area
= gtk_drawing_area_new();
87 midend_size(wdata
->me
, &x
, &y
);
88 gtk_drawing_area_size(GTK_DRAWING_AREA(wdata
->area
), x
, y
);
90 gtk_container_add(GTK_CONTAINER(wdata
->window
), wdata
->area
);
91 gtk_widget_show(wdata
->area
);
93 gtk_signal_connect(GTK_OBJECT(wdata
->window
), "destroy",
94 GTK_SIGNAL_FUNC(destroy
), wdata
);
95 gtk_signal_connect(GTK_OBJECT(wdata
->window
), "key_press_event",
96 GTK_SIGNAL_FUNC(key_event
), wdata
);
97 gtk_signal_connect(GTK_OBJECT(wdata
->area
), "button_press_event",
98 GTK_SIGNAL_FUNC(button_event
), wdata
);
99 gtk_widget_show(wdata
->window
);
103 int main(int argc
, char **argv
)
105 gtk_init(&argc
, &argv
);