aboutsummaryrefslogtreecommitdiff
path: root/gtk.c
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2005-06-07 17:57:50 +0000
committerSimon Tatham <anakin@pobox.com>2005-06-07 17:57:50 +0000
commit02035753f817173a6861d1fc4bec437508cec42d (patch)
treece9bd77bcb19939150b2ffc7b53e2cd599016dd8 /gtk.c
parent69f7e7f8f5890946f4625fc071eb3f8313b17238 (diff)
downloadpuzzles-02035753f817173a6861d1fc4bec437508cec42d.zip
puzzles-02035753f817173a6861d1fc4bec437508cec42d.tar.gz
puzzles-02035753f817173a6861d1fc4bec437508cec42d.tar.bz2
puzzles-02035753f817173a6861d1fc4bec437508cec42d.tar.xz
All the games in this collection have always defined their graphics
in terms of a constant TILE_SIZE (or equivalent). Here's a surprisingly small patch which switches this constant into a run-time variable. The only observable behaviour change should be on Windows, which physically does not permit the creation of windows larger than the screen; if you try to create a puzzle (Net makes this plausible) large enough to encounter this restriction, the Windows front end should automatically re-adjust the puzzle's tile size so that it does fit within the available space. On GTK, I haven't done this, on the grounds that X _does_ permit windows larger than the screen, and many X window managers already provide the means to navigate around such a window. Gareth said he'd rather navigate around a huge Net window than have it shrunk to fit on one screen. I'm uncertain that this makes sense for all puzzles - Pattern in particular strikes me as something that might be better off shrunk to fit - so I may have to change policy later or make it configurable. On OS X, I also haven't done automatic shrinkage to fit on one screen, largely because I didn't have the courage to address the question of multiple monitors and what that means for the entire concept :-) [originally from svn r5913]
Diffstat (limited to 'gtk.c')
-rw-r--r--gtk.c65
1 files changed, 53 insertions, 12 deletions
diff --git a/gtk.c b/gtk.c
index 7483a98..91d44d6 100644
--- a/gtk.c
+++ b/gtk.c
@@ -79,6 +79,8 @@ struct frontend {
void *paste_data;
int paste_data_len;
char *laststatus;
+ int pw, ph; /* pixmap size (w, h are area size) */
+ int ox, oy; /* offset of pixmap in drawing area */
};
void get_random_seed(void **randseed, int *randseedsize)
@@ -311,7 +313,7 @@ void end_draw(frontend *fe)
fe->area->style->fg_gc[GTK_WIDGET_STATE(fe->area)],
fe->pixmap,
fe->bbox_l, fe->bbox_u,
- fe->bbox_l, fe->bbox_u,
+ fe->ox + fe->bbox_l, fe->oy + fe->bbox_u,
fe->bbox_r - fe->bbox_l, fe->bbox_d - fe->bbox_u);
}
}
@@ -397,7 +399,8 @@ static gint button_event(GtkWidget *widget, GdkEventButton *event,
if (event->type == GDK_BUTTON_RELEASE)
button += LEFT_RELEASE - LEFT_BUTTON;
- if (!midend_process_key(fe->me, event->x, event->y, button))
+ if (!midend_process_key(fe->me, event->x - fe->ox,
+ event->y - fe->oy, button))
gtk_widget_destroy(fe->window);
return TRUE;
@@ -421,7 +424,8 @@ static gint motion_event(GtkWidget *widget, GdkEventMotion *event,
else
return FALSE; /* don't even know what button! */
- if (!midend_process_key(fe->me, event->x, event->y, button))
+ if (!midend_process_key(fe->me, event->x - fe->ox,
+ event->y - fe->oy, button))
gtk_widget_destroy(fe->window);
return TRUE;
@@ -436,7 +440,7 @@ static gint expose_area(GtkWidget *widget, GdkEventExpose *event,
gdk_draw_pixmap(widget->window,
widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
fe->pixmap,
- event->area.x, event->area.y,
+ event->area.x - fe->ox, event->area.y - fe->oy,
event->area.x, event->area.y,
event->area.width, event->area.height);
}
@@ -463,15 +467,24 @@ static gint configure_area(GtkWidget *widget,
{
frontend *fe = (frontend *)data;
GdkGC *gc;
+ int x, y;
if (fe->pixmap)
gdk_pixmap_unref(fe->pixmap);
- fe->pixmap = gdk_pixmap_new(widget->window, fe->w, fe->h, -1);
+ x = fe->w = event->width;
+ y = fe->h = event->height;
+ midend_size(fe->me, &x, &y, TRUE);
+ fe->pw = x;
+ fe->ph = y;
+ fe->ox = (fe->w - fe->pw) / 2;
+ fe->oy = (fe->h - fe->ph) / 2;
+
+ fe->pixmap = gdk_pixmap_new(widget->window, fe->pw, fe->ph, -1);
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->w, fe->h);
+ gdk_draw_rectangle(fe->pixmap, gc, 1, 0, 0, fe->pw, fe->ph);
gdk_gc_unref(gc);
midend_force_redraw(fe->me);
@@ -816,6 +829,29 @@ static void menu_key_event(GtkMenuItem *menuitem, gpointer data)
gtk_widget_destroy(fe->window);
}
+static void get_size(frontend *fe, int *px, int *py)
+{
+ int x, y;
+
+ /*
+ * Currently I don't want to make the GTK port scale large
+ * puzzles to fit on the screen. This is because X does permit
+ * extremely large windows and many window managers provide a
+ * means of navigating round them, and the users I consulted
+ * before deciding said that they'd rather have enormous puzzle
+ * windows spanning multiple screen pages than have them
+ * shrunk. I could change my mind later or introduce
+ * configurability; this would be the place to do so, by
+ * replacing the initial values of x and y with the screen
+ * dimensions.
+ */
+ x = INT_MAX;
+ y = INT_MAX;
+ midend_size(fe->me, &x, &y, FALSE);
+ *px = x;
+ *py = y;
+}
+
static void menu_preset_event(GtkMenuItem *menuitem, gpointer data)
{
frontend *fe = (frontend *)data;
@@ -825,10 +861,11 @@ static void menu_preset_event(GtkMenuItem *menuitem, gpointer data)
midend_set_params(fe->me, params);
midend_new_game(fe->me);
- midend_size(fe->me, &x, &y);
- gtk_drawing_area_size(GTK_DRAWING_AREA(fe->area), x, y);
+ get_size(fe, &x, &y);
fe->w = x;
fe->h = y;
+ gtk_drawing_area_size(GTK_DRAWING_AREA(fe->area), x, y);
+ gtk_window_resize(GTK_WINDOW(fe->window), 1, 1);
}
GdkAtom compound_text_atom, utf8_string_atom;
@@ -969,10 +1006,11 @@ static void menu_config_event(GtkMenuItem *menuitem, gpointer data)
return;
midend_new_game(fe->me);
- midend_size(fe->me, &x, &y);
- gtk_drawing_area_size(GTK_DRAWING_AREA(fe->area), x, y);
+ get_size(fe, &x, &y);
fe->w = x;
fe->h = y;
+ gtk_drawing_area_size(GTK_DRAWING_AREA(fe->area), x, y);
+ gtk_window_resize(GTK_WINDOW(fe->window), 1, 1);
}
static void menu_about_event(GtkMenuItem *menuitem, gpointer data)
@@ -1201,12 +1239,12 @@ static frontend *new_window(char *game_id, char **error)
fe->statusbar = NULL;
fe->area = gtk_drawing_area_new();
- midend_size(fe->me, &x, &y);
+ get_size(fe, &x, &y);
gtk_drawing_area_size(GTK_DRAWING_AREA(fe->area), x, y);
fe->w = x;
fe->h = y;
- gtk_box_pack_end(vbox, fe->area, FALSE, FALSE, 0);
+ gtk_box_pack_end(vbox, fe->area, TRUE, TRUE, 0);
fe->pixmap = NULL;
fe->fonts = NULL;
@@ -1246,6 +1284,9 @@ static frontend *new_window(char *game_id, char **error)
gtk_widget_show(fe->area);
gtk_widget_show(fe->window);
+ gdk_window_set_background(fe->area->window, &fe->colours[0]);
+ gdk_window_set_background(fe->window->window, &fe->colours[0]);
+
return fe;
}