199 Commits

Author SHA1 Message Date
7cae89fb4b Add some missing calls to midend_redraw().
I've just noticed that the GTK game window was not being redrawn when
changing between puzzle modes that don't involve a window resize - by
selecting a preset from the Type menu (e.g. changing between different
12x12 settings in Flood) or via the Custom menu.

It looks as if the bug was introduced in commit 8dfe5cec3, which
suggests that it was a side effect of the switch from
gtk_window_resize_to_geometry to plain gtk_window_resize. My guess is
that the implementation of the former function inside GTK might have
happened to trigger an unconditional window resize, while the latter
took the shortcut of doing nothing if the window was already the right
size; hence, resize_fe() would have been reliably generating a redraw
event without me having to ask for one, but now it doesn't, so I have
to trigger one myself any time I've just called resize_fe.
2016-12-27 16:19:19 +00:00
8dfe5cec31 Stop using deprecated GTK 3 geometry-based functions.
Now we work out for ourselves how the drawing-area size relates to the
overall window size, by adding on the height of fe->menubar and/or
fe->statusbar.
2016-12-03 08:49:29 +00:00
7000b0c70a Implement align_label for GTK 3.[14,16).
gtk_misc_set_alignment was deprecated in GTK 3.14. But my replacement
code using gtk_label_set_{x,y}align doesn't work there, because that
function wasn't introduced until GTK 3.16, so there are two minor
versions in the middle where a third strategy is needed.

(That middle strategy doesn't permit arbitrary float alignments, but
that's OK, bceause we only actually use multiples of 0.5.)
2015-12-06 16:00:10 +00:00
b33b83429f Fix GTK puzzle resizing, *again*.
Jonas Kölker points out that commit a800ff16b (which fixed a bug in
the previous attempt) left in another bug: if the puzzle size was
changed while the window was maximised, the system would fail to
recompute the tile size and would redraw completely wrongly.

So it's not optional after all to run midend_size(), even if the
drawing area size hasn't changed. I've reverted that code to be
unconditional, and now only the refresh of the Cairo-side backing
store system is conditionalised - and that's conditionalised on
changes to either the size of the actual window _or_ the size of the
contained pixmap. (The latter should defend against redraw failure in
the case where the puzzle aspect ratio changes, so that neither the
window size nor the tile size changes but a recentre is still needed.)

I _think_ this now fixes all the cases of resizing: this time I've
tested making an unmaximised puzzle window bigger or smaller, and
within a maximised window, forcing the puzzle to scale up, scale down,
or change its aspect ratio without changing its tile size. All work,
on GTK2 and GTK3, and yet we still don't get the visible flicker on
status line updates that was the reason I started fiddling with this
code in the first place.

(We _do_ still call configure_area on every update of the status line,
at least under GTK3; that's going to cause a forced full redraw on
every timer tick in Mines, which is wasteful of CPU, so it would still
be nice to find a better way of identifying the cases in which no
resizing at all was necessary and we could avoid renewing the game
drawstate. But the current code at least doesn't have any display
_errors_ that I know of, which is an improvement on its previous
state.)
2015-10-18 14:55:01 +01:00
96b6f55ec8 Fix two memory leaks in GTK frontend.
- The file selector for loading and saving gets a g_free().
 - The handling of saving (menu_save_event) gets an sfree().
 - It's also slightly restructured to prevent future errors.
 - menu_load_event was already structured to prevent this error.
 - The OLD_FILESEL code seems to not need a g_free().
2015-10-18 11:02:12 +01:00
d0500732f7 In GTK frontend, bind mouse8/mouse9 to undo/redo.
These button codes are generated by the back/forward button pair on
the sides of some mice, and web browsers treat these as the back and
forward actions in the page history.
2015-10-14 21:22:44 +01:00
11b14a5f44 GTK 3 cleanup: stop using GtkDialog for config boxes.
It's becoming annoying to keep working within the increasing
restrictions on GtkDialog, in particular the fact that not only do we
have to let it have complete control of the button area, but also it's
not clear whether we can intercept a press of the 'OK' button and
display an error message rather than ending the dialog.

So, as I did in PuTTY, I'm resorting to using an ordinary GtkWindow
with controls I laid out myself.
2015-10-04 20:10:41 +01:00
27fe1c9c49 GTK 3 cleanup: use GtkAboutDialog for the About box.
This is again easier than faffing about doing it manually, and as an
added bonus, we get to put the largest of our icons in the box as a
logo :-)
2015-10-04 19:57:25 +01:00
a94dbd27d0 GTK 3 cleanup: use GtkMessageDialog for message_box().
This is a lot easier than faffing about setting up a dialog box
ourself, and also avoids direct access to GtkDialog's action area
(deprecated in GTK 3.16).
2015-10-04 19:56:39 +01:00
2afbcdcc3c GTK 3.16 deprecation: stop using gtk_misc_set_alignment.
The new equivalent is gtk_label_set_{x,y}align. But we can't use that
in all GTK 3 builds, because it's very new.
2015-10-04 19:33:44 +01:00
a800ff16bb Fix switching to a larger puzzle size under GTK 2.
Commit 8b491946e had a bug: configure_area stopped doing most of its
work if the new size already matched fe->w and fe->h, but in fact the
GTK2 resize_fe() _already_ set up fe->w and fe->h for the new size. I
managed not to notice, because I checked it all worked on GTK 3 but
only tested resizing to a _smaller_ puzzle on GTK 2. Ahem.

Now we don't change fe->w and fe->h at all until configure_area is
called. Also, we initialise them to dummy values at setup time, so
that configure_area won't compare the new size with uninitialised
data.
2015-10-03 18:01:18 +01:00
581becc3aa Insert a manual reference in the default status bar text.
To guide developers to the resources they need.

[actual wording tweaked by SGT]
2015-10-03 17:12:20 +01:00
41cc7c868f GTK 3 port: don't turn off drawing area double buffering.
I think I did this in GTK2 on the basis that our server-side cache
pixmap was double-buffering enough for us - any puzzle which erased a
big area with a background rectangle and then redrew over the top of
it would do so only on the off-screen pixmap, and the updates would
only be copied to the visible window after it was all done.

In GTK3, I don't think there's any need - this is all the usual way
things are done anyway, as far as I can see. So I've turned this call
back off, at least until I hear of a reason why I need it again.
2015-10-03 16:07:20 +01:00
1b2e4d525f GTK 3 port: change API functions for widget sizing.
set_usize is deprecated, and get_preferred_size is the GTK 3 thing we
should use in place of size_request.
2015-10-03 16:07:20 +01:00
90b73ebcb7 GTK 3 port: use GtkBox directly, not GtkHBox and GtkVBox.
I've done this by #defining the old names in terms of the new ones,
because the old ones are still more concise!
2015-10-03 16:07:19 +01:00
2fb189cc36 GTK 3 port: be prepared not to use GtkStock.
GTK 3 has deprecated it in favour of just making you specify fixed
strings as button labels, which seems like a step backwards to me but
there we go.
2015-10-03 16:07:19 +01:00
88b38f5168 GTK 3 port: use GdkRGBA for the window background colour.
Suits our internal API better, anyway, with RGB components being
floats ranging from 0 to 1.
2015-10-03 16:07:19 +01:00
d6210656b8 GTK 3 port: stop getting default bg colour from the window style.
GTK3 window styles don't reliably provide one, so we have to fall back
to just making one up.
2015-10-03 16:07:19 +01:00
4e1cc65701 GTK 3 port: condition out the complicated window resize code.
In GTK 2, we had a big pile of horrible code to deal with the fact
that it's very hard to open a window in such a way as to make it easy
to resize smaller as well as bigger.

Essentially, we'd open the window with the drawing area's minimum size
request set to the desired _initial_ window size; then we'd wait until
GTK had finished creating other window components (menu bar, status
line) and the window's size allocation had settled down, and finally
reduce the size request to the real minimum size so that now the
window was resizable in both directions. This also involved some
deliberate checking of the Ubuntu Unity GTK extension which steals the
menu bar and put it elsewhere (see commit 8f8333a35), to avoid us
waiting forever for a menu bar that wasn't going to show up.

But in GTK3, this has all become actually sensible! All we now have to
do is to set the window's geometry hints to indicate the drawing area
itself as the base widget (probably a good plan anyway), and then we
can set the initial size using gtk_window_set_default_geometry() and
resize it later using gtk_window_resize_to_geometry(). So now we can
completely condition out all of the previous horrors, and consider
them to be legacy GTK2 compatibility code only. Phew.
2015-10-03 16:07:18 +01:00
37232c3c30 GTK 3 port: provide a 'draw' handler.
This is what GTK 3 uses in place of 'expose_event'. Also I've arranged
here for my internal USE_CAIRO_WITHOUT_PIXMAP setting to be enabled in
GTK3, as well as in GTK2 with deprecated functions disabled.
2015-10-03 16:07:04 +01:00
62c6312982 GTK 3 port: use GtkGrid as an alternative to GtkTable.
This also involves setting some "hexpand" properties on the widgets
contained in the GtkGrid, to achieve effects which GtkTable did by
setting flags in gtk_table_attach.
2015-10-03 16:07:04 +01:00
64d0a70e13 GTK 3 prep: use g_timeout_add, not gtk_timeout_add. 2015-10-03 16:07:04 +01:00
3d0d54e3b4 GTK 3 prep: use GTK instead of GDK window-icon functions.
We now build cleanly with -DGDK_DISABLE_DEPRECATED.
2015-10-03 16:07:04 +01:00
fd7882fb45 GTK 3 prep: make the server-side backing pixmap optional.
When GDK_DISABLE_DEPRECATED is defined, we now don't have fe->pixmap;
instead we just maintain our client-side window contents in fe->image,
and draw from there directly to the window in the expose handler.
2015-10-03 16:07:04 +01:00
07906104a2 GTK 3 prep: use gtk_radio_menu_item_get_group().
Replaces the previous deprecated spelling. We now build cleanly with
-DGTK_DISABLE_DEPRECATED.
2015-10-03 16:07:04 +01:00
2c1b00086d GTK 3 prep: use GtkComboBox for drop-down lists.
The previous GtkOptionMenu was long since deprecated.
2015-10-03 16:07:04 +01:00
71c7bcd981 GTK 3 prep: use the glib names for base object types. 2015-10-03 16:07:04 +01:00
0dc2fd1ea3 GTK 3 prep: use GTK_KEY_* constants. 2015-10-03 16:07:04 +01:00
238cd9dc83 GTK 3 prep: use accessors instead of direct field access.
We now build cleanly with -DGSEAL_ENABLE.
2015-10-03 16:07:04 +01:00
7242dcc4ef Fix packing direction of config boxes.
We were packing the GtkTable into the dialog's content area using
gtk_box_pack_end, which had the slightly silly effect that resizing
the config box vertically would keep all the controls aligned to the
_bottom_ rather than the top.
2015-10-03 16:07:04 +01:00
8b491946ef Don't refresh backing store on a no-op configure event.
Sometimes, we can get a "configure_area" event telling us that the
drawing area has changed size to the same size it already was. This
can happen when we change puzzle presets in a way that doesn't change
the size, and also sometimes seems to happen as a side effect of
changing the text in the status line.

In that situation, it's a waste of effort - and can cause visible
on-screen flicker - to throw away the window's backing image and
pixmap and regenerate them from scratch. So now we detect a non-resize
and avoid doing all that.

The only thing we retain unconditionally in configure_area is the
midend_force_redraw, because that's the place where a puzzle redraw is
forced when changing presets or loading a new game.
2015-10-03 16:07:01 +01:00
8f8333a351 Fix puzzle window resize behaviour on Unity.
Unity hijacks the menu bar and prevents it from appearing in the main
puzzle window. And we wait for the menu bar to appear before reducing
the puzzle drawing area's size request. These two behaviours go
together badly.

Fixed by detecting the extra GTK property that the Unity patches
invented, and using that to know whether to expect the menu bar to
show up at all.
2015-01-04 18:11:28 +00:00
f806528a30 Remove another erroneous GINT_TO_POINTER.
This one shouldn't have been there at all - it had a pointer argument
already, not an int.
2014-11-29 10:39:00 +00:00
69ab4b2205 Fix a GINT_TO_POINTER that was back to front.
Spotted by clang, which I just tried building this codebase with out
of curiosity.
2014-11-29 10:24:05 +00:00
120f6de605 Introduce some extra testing and benchmarking command-line options to
the GTK front end, plus a 'make test' target in the GTK makefile which
uses them to automatically generate 100 puzzles for each game at each
preset configuration, test-run them back through the solver without
their aux_info to ensure that can cope, and produce an HTML box plot
of game generation times for each preset.

As part of this work I've removed the TESTSOLVE mechanism from r9549,
since the new --test-solve option does the same thing better (in that
when something goes wrong it prints the random seed that caused the
problem).

[originally from svn r9825]
[r9549 == 5a095b8a08fa9f087b93c86aea0fa027138b028d]
2013-04-11 12:51:06 +00:00
261a784d1e Actually do what the comment says at the top of main() regarding not
bombing out due to an option that we don't recognise but GTK will.
Somehow my basically workable plan had been completely nullified by
putting the error check in the wrong place.

[originally from svn r9733]
2012-12-28 11:22:13 +00:00
e17bf4abec Fix overnight build failure last night, by making the new call to
gtk_widget_get_allocation conditional on GTK being new enough to have
that function.

I'm assuming until someone proves otherwise that if it isn't that new,
then it also isn't one of the versions of GTK which exhibit the bug
which that call was working around (since gtk_widget_get_allocation
came in 2.18, and the problem seems to have arisen since 2.20).

[originally from svn r9712]
2012-11-21 18:45:07 +00:00
2a2520b8e7 Work around an annoying GTK behaviour I noticed the other day on my
Ubuntu 12.04 machine. What seems to happen is that we set up a window
containing a menu bar, a drawing area and a status bar, and set the
size of the drawing area; then the window is displayed _without_ the
menu bar; then we reduce the drawing area's size request to (1,1) to
let the user resize the window smaller; and now GTK gets round to
constructing the menu bar, and the drawing area helpfully shrinks a
bit to make room for it.

My fix is to set a 'shrink pending' flag instead of shrinking the
drawing area's size request, and defer the actual shrink operation
until the menu bar and status bar are both present.

[originally from svn r9711]
2012-11-20 20:05:27 +00:00
7024735f89 Allow --save to work with --soln, causing saved game files to be
written out with the Solve operation having already been performed.

[originally from svn r9375]
2011-12-28 18:17:30 +00:00
b5cb02b61a Fix bug in error reporting for --save caused by freeing 'realname'
before the error messages wanted to use it.

[originally from svn r9374]
2011-12-28 18:07:46 +00:00
236f965093 Fix bug in --save caused by failure to initialise ctx.error to zero
before later checking to see if an errno code was dumped in it.

[originally from svn r9373]
2011-12-28 18:07:46 +00:00
4d41f0f717 Fixes to r8997: firstly, move the fix out of #ifdef CAIRO so that it
applies to both drawing mechanisms, and secondly, make sure to paint
the spare pieces of window in the _puzzle's_ background colour
rather than the (sometimes slightly different) system default.

[originally from svn r9021]
[r8997 == 26c669a6b2892b97b4a9bc6842f633291951fdbd]
2010-11-06 17:47:46 +00:00
26c669a6b2 Jonas Koelker reports that using the version of GTK currently in
Debian sid (2.20.1), there's a redraw problem when the window has a
different aspect ratio from the puzzle (due to resizing or
maximising): pieces of the window outside the real puzzle rectangle
don't get redrawn when exposed (e.g. by the drop-down menus).

Introduced code to explicitly redraw the whole exposed area,
including the parts that fall outside the pixmap. This makes the
problem go away in my hasty test install of sid, and doesn't seem to
affect the build on lenny.

[originally from svn r8997]
2010-09-14 10:55:06 +00:00
9cd182ffa9 Patch from Mark Wooding to introduce a draw_thick_line() function in
the drawing API, for use by Loopy. It's optional: drawing.c will
construct an acceptable alternative using a filled polygon if the
front end doesn't provide it.

Net and Netslide previously had static functions called
draw_thick_line(), whose claim to the name is less justified and so
they've been renamed.

[originally from svn r8962]
2010-05-29 15:43:46 +00:00
ef6e78c6ac Patch from Mark Wooding to (optionally at compile time) use the
Cairo rendering library in place of GDK, which provides pretty
antialiased graphics much like we get on MacOS. Inertia and Untangle
are perhaps the two games most obviously improved by this.

[originally from svn r8961]
2010-05-29 15:43:42 +00:00
9ce82b0feb Patch from Mark Wooding to disable GTK's internal double buffering,
which I didn't know about, but which is clearly a waste of effort
since we keep our own backing pixmap for the puzzle window.

[originally from svn r8960]
2010-05-29 15:43:41 +00:00
d040a921ba Patch from Mark Wooding to use GTK stock items for standard 'OK',
'Yes' and 'No' buttons, which means they get the standard icons that
go on those button types. Also reorders yes/no boxes so that they're
the GNOME standard way round.

[originally from svn r8959]
2010-05-29 15:43:40 +00:00
5062bee2ec Patch from Debian, to bring the use of the X selection/clipboard in
line with freedesktop.org. (This is relatively simple for Puzzles,
since it only writes to the clipboard and never reads it, so the
question of which selection to use when is most easily dealt with by
always writing to both.)

[originally from svn r8929]
2010-04-25 14:57:19 +00:00
9fbb365684 Introduce, and implement as usefully as I can in all front ends, a
new function in the drawing API which permits the display of text
from outside basic ASCII. A fallback mechanism is provided so that
puzzles can give a list of strings they'd like to display in order
of preference and the system will return the best one it can manage;
puzzles are required to cope with ASCII-only front ends.

[originally from svn r8793]
2009-12-27 10:01:16 +00:00
6d5245d8bf Patch from Frode Austvik to tinker with the GTK interface if
compiling gtk.c with STYLUS_BASED defined: most notably, it provides
a row of numeric 'keys' made of GTK button widgets for puzzles that
want a numeric keypad.

[originally from svn r8783]
2009-12-17 18:12:18 +00:00