*/
struct frontend {
GtkWidget *window;
+ GtkAccelGroup *accelgroup;
GtkWidget *area;
GtkWidget *statusbar;
guint statusctx;
if (!fe->pixmap)
return TRUE;
+#if !GTK_CHECK_VERSION(2,0,0)
+ /* Gtk 1.2 passes a key event to this function even if it's also
+ * defined as an accelerator.
+ * Gtk 2 doesn't do this, and this function appears not to exist there. */
+ if (fe->accelgroup &&
+ gtk_accel_group_get_entry(fe->accelgroup,
+ event->keyval, event->state))
+ return TRUE;
+#endif
+
if (event->keyval == GDK_Up)
keyval = shift | ctrl | CURSOR_UP;
else if (event->keyval == GDK_KP_Up || event->keyval == GDK_KP_8)
gc = gdk_gc_new(fe->area->window);
gdk_gc_set_foreground(gc, &fe->colours[0]);
gdk_draw_rectangle(fe->pixmap, gc, 1, 0, 0, fe->pw, fe->ph);
+ gdk_draw_rectangle(widget->window, gc, 1, 0, 0,
+ event->width, event->height);
gdk_gc_unref(gc);
midend_force_redraw(fe->me);
char *text, int key)
{
GtkWidget *menuitem = gtk_menu_item_new_with_label(text);
+ int keyqual;
gtk_container_add(cont, menuitem);
gtk_object_set_data(GTK_OBJECT(menuitem), "user-data",
GINT_TO_POINTER(key));
gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
GTK_SIGNAL_FUNC(menu_key_event), fe);
+ switch (key & ~0x1F) {
+ case 0x00:
+ key += 0x60;
+ keyqual = GDK_CONTROL_MASK;
+ break;
+ case 0x40:
+ key += 0x20;
+ keyqual = GDK_SHIFT_MASK;
+ break;
+ default:
+ keyqual = 0;
+ break;
+ }
+ gtk_widget_add_accelerator(menuitem,
+ "activate", fe->accelgroup,
+ key, keyqual,
+ GTK_ACCEL_VISIBLE);
gtk_widget_show(menuitem);
return menuitem;
}
gtk_widget_show(menuitem);
}
-static frontend *new_window(char *arg, char **error)
+enum { ARG_EITHER, ARG_SAVE, ARG_ID }; /* for argtype */
+
+static frontend *new_window(char *arg, int argtype, char **error)
{
frontend *fe;
GtkBox *vbox;
if (arg) {
char *err;
+ FILE *fp;
errbuf[0] = '\0';
- /*
- * Try treating the argument as a game ID.
- */
- err = midend_game_id(fe->me, arg);
- if (!err) {
- /*
- * It's a valid game ID.
- */
- midend_new_game(fe->me);
- } else {
- FILE *fp = fopen(arg, "r");
+ switch (argtype) {
+ case ARG_ID:
+ err = midend_game_id(fe->me, arg);
+ if (!err)
+ midend_new_game(fe->me);
+ else
+ sprintf(errbuf, "Invalid game ID: %.800s", err);
+ break;
+ case ARG_SAVE:
+ fp = fopen(arg, "r");
if (!fp) {
- sprintf(errbuf, "Supplied argument is neither a game ID (%.400s)"
- " nor a save file (%.400s)", err, strerror(errno));
+ sprintf(errbuf, "Error opening file: %.800s", strerror(errno));
} else {
err = midend_deserialise(fe->me, savefile_read, fp);
if (err)
- sprintf(errbuf, "%.800s", err);
+ sprintf(errbuf, "Invalid save file: %.800s", err);
fclose(fp);
}
- }
+ break;
+ default /*case ARG_EITHER*/:
+ /*
+ * First try treating the argument as a game ID.
+ */
+ err = midend_game_id(fe->me, arg);
+ if (!err) {
+ /*
+ * It's a valid game ID.
+ */
+ midend_new_game(fe->me);
+ } else {
+ FILE *fp = fopen(arg, "r");
+ if (!fp) {
+ sprintf(errbuf, "Supplied argument is neither a game ID (%.400s)"
+ " nor a save file (%.400s)", err, strerror(errno));
+ } else {
+ err = midend_deserialise(fe->me, savefile_read, fp);
+ if (err)
+ sprintf(errbuf, "%.800s", err);
+ fclose(fp);
+ }
+ }
+ break;
+ }
if (*errbuf) {
*error = dupstr(errbuf);
midend_free(fe->me);
fe->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(fe->window), thegame.name);
-#if 0
- gtk_window_set_resizable(GTK_WINDOW(fe->window), FALSE);
-#else
- gtk_window_set_policy(GTK_WINDOW(fe->window), FALSE, FALSE, TRUE);
-#endif
+
vbox = GTK_BOX(gtk_vbox_new(FALSE, 0));
gtk_container_add(GTK_CONTAINER(fe->window), GTK_WIDGET(vbox));
gtk_widget_show(GTK_WIDGET(vbox));
+ fe->accelgroup = gtk_accel_group_new();
+ gtk_window_add_accel_group(GTK_WINDOW(fe->window), fe->accelgroup);
+
menubar = gtk_menu_bar_new();
gtk_box_pack_start(vbox, menubar, FALSE, FALSE, 0);
gtk_widget_show(menubar);
gtk_widget_show(menuitem);
add_menu_separator(GTK_CONTAINER(menu));
add_menu_item_with_key(fe, GTK_CONTAINER(menu), "Undo", 'u');
- add_menu_item_with_key(fe, GTK_CONTAINER(menu), "Redo", '\x12');
+ add_menu_item_with_key(fe, GTK_CONTAINER(menu), "Redo", 'r');
if (thegame.can_format_as_text) {
add_menu_separator(GTK_CONTAINER(menu));
menuitem = gtk_menu_item_new_with_label("Copy");
int ngenerate = 0, print = FALSE, px = 1, py = 1;
int soln = FALSE, colour = FALSE;
float scale = 1.0F;
+ float redo_proportion = 0.0F;
char *arg = NULL;
+ int argtype = ARG_EITHER;
+ int output_window_id = FALSE;
int doing_opts = TRUE;
int ac = argc;
char **av = argv;
pname);
return 1;
}
+ } else if (doing_opts && !strcmp(p, "--redo")) {
+ /*
+ * This is an internal option which I don't expect
+ * users to have any particular use for. The effect of
+ * --redo is that once the game has been loaded and
+ * initialised, the next move in the redo chain is
+ * replayed, and the game screen is redrawn part way
+ * through the making of the move. This is only
+ * meaningful if there _is_ a next move in the redo
+ * chain, which means in turn that this option is only
+ * useful if you're also passing a save file on the
+ * command line.
+ *
+ * This option is used by the script which generates
+ * the puzzle icons and website screenshots, and I
+ * don't imagine it's useful for anything else.
+ * (Unless, I suppose, users don't like my screenshots
+ * and want to generate their own in the same way for
+ * some repackaged version of the puzzles.)
+ */
+ if (--ac > 0) {
+ redo_proportion = atof(*++av);
+ } else {
+ fprintf(stderr, "%s: no argument supplied to '--redo'\n",
+ pname);
+ return 1;
+ }
+ } else if (doing_opts && !strcmp(p, "--windowid")) {
+ /*
+ * Another internal option for the icon building
+ * script. This causes the window ID of the central
+ * drawing area (i.e. not including the menu bar or
+ * status bar) to be printed on standard output once
+ * the window has been drawn.
+ */
+ output_window_id = TRUE;
} else if (doing_opts && (!strcmp(p, "--with-solutions") ||
!strcmp(p, "--with-solution") ||
!strcmp(p, "--with-solns") ||
return 1;
}
colour = TRUE;
+ } else if (doing_opts && !strcmp(p, "--load")) {
+ argtype = ARG_SAVE;
+ } else if (doing_opts && !strcmp(p, "--game")) {
+ argtype = ARG_ID;
} else if (doing_opts && !strcmp(p, "--")) {
doing_opts = FALSE;
} else if (!doing_opts || p[0] != '-') {
return 0;
} else {
+ frontend *fe;
gtk_init(&argc, &argv);
- if (!new_window(argc > 1 ? argv[1] : NULL, &error)) {
+ fe = new_window(arg, argtype, &error);
+
+ if (!fe) {
fprintf(stderr, "%s: %s\n", pname, error);
return 1;
}
+ if (output_window_id) {
+ /*
+ * Some puzzles will not redraw their entire area if
+ * given a partially completed animation, which means
+ * we must redraw now and _then_ redraw again after
+ * freezing the move timer.
+ */
+ midend_force_redraw(fe->me);
+ }
+
+ if (redo_proportion) {
+ /* Start a redo. */
+ midend_process_key(fe->me, 0, 0, 'r');
+ /* And freeze the timer at the specified position. */
+ midend_freeze_timer(fe->me, redo_proportion);
+ }
+
+ if (output_window_id) {
+ midend_redraw(fe->me);
+ printf("%p\n", (void *)GDK_WINDOW_XWINDOW(fe->area->window));
+ fflush(stdout);
+ }
+
gtk_main();
}