Jacob Nevins wrote: > Ben Hutchings writes: > > I think what should happen when you change the type is that the puzzle > > compares the current window size with the desired window size and > > requests a resize only if the current size is too small. Does that seem > > reasonable? > > I don't think that's quite right; if a puzzle is (say) 3x3, but the user > then changes to 2x2, this would expand the 2x2 puzzle to fill the space > used by the 3x3 one. > > I think a better approach would be for the internal 'tilesize' parameter > to be remembered across game grid size changes, so that the individual > game features stay at the user's requested size. > > The attached patch against the upstream version illustrates this, but it > needs some work; as it stands, if the tile size is enlarged and then a > new game grid size is selected, the tile size cannot be reduced again.
There's a simpler way to do that:
--- midend.c (revision 314)
+++ midend.c (working copy)
@@ -264,6 +264,8 @@
*/
me->tilesize = min;
+ if (expand)
+ me->preferred_tilesize = me->tilesize;
midend_size_new_drawstate(me);
*x = me->winwidth;
*y = me->winheight;
-- END --
(It might be appropriate to rename the 'expand' parameter too.)
> (This no-shrinking policy applies to the unpatched upstream version too;
> perhaps it shouldn't?)
This isn't a deliberate policy. The problem is that Gtk widgets do not
have a preferred size setting distinct from their minimum size ('size
request'), so the calculated preferred size of the drawing area becomes
its minimum. (Actually that may not be true in Gtk 1.2, but this code
has to work on Gtk 2.0 as well.)
It is possible to work around this by reducing the drawing area's size
request after calculating the window's size request. First, I want to
combine the multiple copies of the resizing code:
--- gtk.c (revision 280)
+++ gtk.c (working copy)
@@ -1102,26 +1102,32 @@
gdk_window_resize(GTK_WIDGET(win)->window, x, y)
#endif
-static void menu_preset_event(GtkMenuItem *menuitem, gpointer data)
+static void resize_fe(frontend *fe)
{
- frontend *fe = (frontend *)data;
- game_params *params =
- (game_params *)gtk_object_get_data(GTK_OBJECT(menuitem), "user-data");
int x, y;
- midend_set_params(fe->me, params);
- midend_new_game(fe->me);
get_size(fe, &x, &y);
fe->w = x;
fe->h = y;
gtk_drawing_area_size(GTK_DRAWING_AREA(fe->area), x, y);
{
GtkRequisition req;
gtk_widget_size_request(GTK_WIDGET(fe->window), &req);
gtk_window_resize(GTK_WINDOW(fe->window), req.width, req.height);
}
}
+static void menu_preset_event(GtkMenuItem *menuitem, gpointer data)
+{
+ frontend *fe = (frontend *)data;
+ game_params *params =
+ (game_params *)gtk_object_get_data(GTK_OBJECT(menuitem), "user-data");
+
+ midend_set_params(fe->me, params);
+ midend_new_game(fe->me);
+ resize_fe(fe);
+}
+
GdkAtom compound_text_atom, utf8_string_atom;
int paste_initialised = FALSE;
@@ -1294,7 +1320,6 @@
{
frontend *fe = (frontend *)data;
char *name, *err;
- int x, y;
name = file_selector(fe, "Enter name of saved game file to load", FALSE);
@@ -1316,16 +1341,7 @@
return;
}
- get_size(fe, &x, &y);
- fe->w = x;
- fe->h = y;
- gtk_drawing_area_size(GTK_DRAWING_AREA(fe->area), x, y);
- {
- GtkRequisition req;
- gtk_widget_size_request(GTK_WIDGET(fe->window), &req);
- gtk_window_resize(GTK_WINDOW(fe->window), req.width, req.height);
- }
-
+ resize_fe(fe);
}
}
@@ -1352,21 +1368,12 @@
frontend *fe = (frontend *)data;
int which = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(menuitem),
"user-data"));
- int x, y;
if (!get_config(fe, which))
return;
midend_new_game(fe->me);
- get_size(fe, &x, &y);
- fe->w = x;
- fe->h = y;
- gtk_drawing_area_size(GTK_DRAWING_AREA(fe->area), x, y);
- {
- GtkRequisition req;
- gtk_widget_size_request(GTK_WIDGET(fe->window), &req);
- gtk_window_resize(GTK_WINDOW(fe->window), req.width, req.height);
- }
+ resize_fe(fe);
}
#ifdef USE_GNOME_HELP
-- END --
Then the change to allow shrinking is quite simple:
--- gtk.c (working copy)
+++ gtk.c (working copy)
@@ -1115,6 +1115,12 @@
gtk_widget_size_request(GTK_WIDGET(fe->window), &req);
gtk_window_resize(GTK_WINDOW(fe->window), req.width, req.height);
}
+ /*
+ * Now that we've established the preferred size of the window,
+ * reduce the drawing area's size request so the user can shrink
+ * the window.
+ */
+ gtk_drawing_area_size(GTK_DRAWING_AREA(fe->area), 1, 1);
}
static void menu_preset_event(GtkMenuItem *menuitem, gpointer data)
@@ -1728,6 +1734,13 @@
gtk_widget_show(fe->area);
gtk_widget_show(fe->window);
+ /*
+ * Now that we've established the preferred size of the window,
+ * reduce the drawing area's size request so the user can shrink
+ * the window.
+ */
+ gtk_drawing_area_size(GTK_DRAWING_AREA(fe->area), 1, 1);
+
gdk_window_set_background(fe->area->window, &fe->colours[0]);
gdk_window_set_background(fe->window->window, &fe->colours[0]);
-- END --
Comments?
Ben.
--
Ben Hutchings -- [EMAIL PROTECTED] shortened to [EMAIL PROTECTED]
If you've signed my GPG key, please send a signature on and to the new uid.
Editing code like this is akin to sticking plasters on the bleeding stump
of a severed limb. - me, 29 June 1999
signature.asc
Description: This is a digitally signed message part

