188 Commits

Author SHA1 Message Date
a7431c0b7c New infrastructure feature. Games are now permitted to be
_conditionally_ able to format the current puzzle as text to be sent
to the clipboard. For instance, if a game were to support playing on
a square grid and on other kinds of grid such as hexagonal, then it
might reasonably feel that only the former could be sensibly
rendered in ASCII art; so it can now arrange for the "Copy" menu
item to be greyed out depending on the game_params.

To do this I've introduced a new backend function
(can_format_as_text_now()), and renamed the existing static backend
field "can_format_as_text" to "can_format_as_text_ever". The latter
will cause compile errors for anyone maintaining a third-party front
end; if any such person is reading this, I apologise to them for the
inconvenience, but I did do it deliberately so that they'd know to
update their front end.

As yet, no checked-in game actually uses this feature; all current
games can still either copy always or copy never.

[originally from svn r8161]
2008-09-06 09:27:56 +00:00
ae6c738127 New feature in midend.c which allows us to ask for the number of the
currently selected preset, if any. I've used this in the GTK front
end to have the Type menu mark the currently selected menu item.
(After considerable beating of GTK with sticks, I might add. Grr.)
Currently the same UI feature is not yet supported on Windows or
MacOS, but I hope to do those too at some point if it's feasible.

[originally from svn r7980]
2008-04-08 16:25:39 +00:00
c1b0c1d091 Ben Hutchings' patch to allow Gtk windows to be shrunk as well as grown
(from Debian bug#379452).
Tested on Gtk 2. I've been unable to find a Gtk+-1.2 installation on which
Puzzles compiles, so not tested there.

[originally from svn r7367]
2007-03-03 22:39:17 +00:00
d916cd7ff9 Refactoring patch from Ben Hutchings: move all the Gtk resize code into one
place. (From Debian bug#379452)

[originally from svn r7366]
2007-03-03 22:05:05 +00:00
7c59e7259f In Windows/Gtk front-ends, consistently use the ellipsis convention for naming
menu items which bring up dialogs.

[originally from svn r7058]
2007-01-04 19:24:43 +00:00
14ed4e9b1e Phil Bordelon's patch yesterday should have initialised the GError
to NULL.

[originally from svn r7052]
2007-01-03 09:51:42 +00:00
7848918bac Phil Bordelon points out that my invocation of gdk_pixbuf_save()
isn't quite right.

[originally from svn r7050]
2007-01-02 19:45:19 +00:00
fc59e33845 Make errors in option parsing actually _do_ something in interactive mode.
[originally from svn r7039]
2006-12-30 00:26:16 +00:00
197c2ebc12 Aha, this seems to be a more sensible way of getting screenshots:
instead of having the puzzle binary export its window ID to a script
which then runs xwd, we can use the gdk-pixbuf library to have the
puzzle binary _itself_ read its own internal pixmap and save it
straight to a PNG. How handy. And faster, and less timing-sensitive.

[originally from svn r7022]
2006-12-27 15:21:55 +00:00
61b983ae3a Support for run-time icons in the GTK puzzles. This involved another
mkfiles.pl change (I don't seem to be planning ahead very well this
week), this time to provide a list of fallback options for an object
file. That way, I have a no-icon.c which quietly replaces
icons/foo-icon.c if the latter doesn't exist, and so again people
checking straight out from Subversion shouldn't have trouble.

[originally from svn r7021]
2006-12-27 15:10:59 +00:00
d55ad9fc42 New mechanism for automatic generation of the puzzle screenshots on
the web, which I hope will also end up being extended to generate
both Windows and X icons for each individual puzzle. The mechanism
is: for each puzzle there's a save file in the `icons' subdirectory
showing a game state which I think is a decent illustration of the
puzzle, and then there's a nasty set of scripts which runs each
puzzle binary, loads that save file, grabs a screenshot using xwd,
and munges it into shape.

In order to support this I've added two new options (--redo and
--windowid) to all the GTK puzzles, which I don't expect ever to be
used outside the icons makefile. I've also added two more options
(--load and --id) which force a GTK puzzle to treat its command-line
option as a save file or as a game ID respectively (the previous
behaviour was always to guess, and sometimes it guessed wrong).

[originally from svn r7014]
2006-12-26 16:47:28 +00:00
cfcd8cf8c5 Since r6711, puzzles built with Gtk 1.2 would take double actions when a menu
accelerator key (N/U/R/Q) was pressed -- once for the menu accelerator, and
once more in key_event().
This workaround, while unlovely, should at least not break in future (since the
things it relies on are unlikely to change).

[originally from svn r6745]
[r6711 == 077aa510c78f3273bd0d4ca4f1ca14780822ebf9]
2006-06-26 22:01:51 +00:00
d952a3b6ff Trivial patch from Ben Hutchings to support resizable windows under
GTK. All the infrastructure in the midend and beyond was already
there; it was just a matter of enabling it!

[originally from svn r6712]
2006-05-20 12:06:41 +00:00
077aa510c7 Ben Hutchings's patch to add display of key accelerators in the Game
menu.

[originally from svn r6711]
2006-05-20 12:01:55 +00:00
240b6cab8c Cleanup: relieve frontends of the duty to call
midend_rewrite_statusbar() and check the result against the last
string returned. This is now done centrally in drawing.c, and the
front end status bar function need only do what it says on the tin.

While I'm modifying the prototype of drawing_init(), I've also
renamed it drawing_new() for the same reason as random_new() (it
_allocates_ a drawing object, rather than just initialising one
passed in).

[originally from svn r6420]
2005-10-22 17:23:55 +00:00
669bb81f08 New puzzle: `Tents'. Requires a potentially shared algorithms module
maxflow.c. Also in this checkin, fixes to the OS X and GTK back ends
to get ALIGN_VNORMAL right. This is the first time I've used it! :-)

[originally from svn r6390]
2005-10-13 18:30:24 +00:00
948c33c5a9 Backspace and Delete keys now function like Space in Solo.
[originally from svn r6237]
2005-08-29 11:12:05 +00:00
8f46a30e69 There seems to be some odd behaviour when GTK is asked to draw an
outline polygon with a clipping rectangle active. I don't know or
care whether this is GTK or my X server or what, but I'm working
around it by drawing the lines myself, which seems to sort it out.

[originally from svn r6227]
2005-08-28 13:52:58 +00:00
d558bb240a Don't report an error when loading a saved game from the command
line unless there really _is_ an error!

[originally from svn r6203]
2005-08-23 12:49:21 +00:00
af59dcf685 Substantial infrastructure upheaval. I've separated the drawing API
as seen by the back ends from the one implemented by the front end,
and shoved a piece of middleware (drawing.c) in between to permit
interchange of multiple kinds of the latter. I've also added a
number of functions to the drawing API to permit printing as well as
on-screen drawing, and retired print.py in favour of integrated
printing done by means of that API.

The immediate visible change is that print.py is dead, and each
puzzle now does its own printing: where you would previously have
typed `print.py solo 2x3', you now type `solo --print 2x3' and it
should work in much the same way.

Advantages of the new mechanism available right now:
 - Map is now printable, because the new print function can make use
   of the output from the existing game ID decoder rather than me
   having to replicate all those fiddly algorithms in Python.
 - the new print functions can cope with non-initial game states,
   which means each puzzle supporting --print also supports
   --with-solutions.
 - there's also a --scale option permitting users to adjust the size
   of the printed puzzles.

Advantages which will be available at some point:
 - the new API should permit me to implement native printing
   mechanisms on Windows and OS X.

[originally from svn r6190]
2005-08-18 17:50:14 +00:00
4da39de282 (GTK only so far) Allow the argument passed to a game binary to be
either a game ID or a save file name. (The former takes priority,
because you can usually find a synonym for the latter, such as by
prepending `./' or `$PWD/'.)

[originally from svn r6135]
2005-07-24 10:05:11 +00:00
f3c95109c7 Add a `full' parameter to validate_params(), analogous to the one in
encode_params(). This is necessary for cases where generation-time parameters
that are normally omitted from descriptive IDs can place restrictions on other
parameters; in particular, when the default value of a relevant generation-time
parameter is not the one used to generate the descriptive ID, validation could
reject self-generated IDs (e.g., Net `5x2w:56182ae7c2', and some cases in
`Pegs').

[originally from svn r6068]
2005-07-05 21:27:19 +00:00
64e114cce1 draw_polygon() and draw_circle() have always had a portability
constraint: because some front ends interpret `draw filled shape' to
mean `including its boundary' while others interpret it to mean `not
including its boundary' (and X seems to vacillate between the two
opinions as it moves around the shape!), you MUST NOT draw a filled
shape only. You can fill in one colour and outline in another, you
can fill or outline in the same colour, or you can just outline, but
just filling is a no-no.

This leads to a _lot_ of double calls to these functions, so I've
changed the interface. draw_circle() and draw_polygon() now each
take two colour arguments, a fill colour (which can be -1 for none)
and an outline colour (which must be valid). This should simplify
code in the game back ends, while also reducing the possibility for
coding error.

[originally from svn r6047]
2005-07-03 09:35:29 +00:00
6f47baddf9 Load and Save are now supported on all three desktop platforms, and
documented. (This means the GTK temporary dependency on an
environment variable is now gone.)

[originally from svn r6042]
2005-06-30 18:00:37 +00:00
7011028b17 Actually implemented the serialise/deserialise functions in
midend.c. Also I've added an experimental front end in gtk.c only:
`Save' and `Load' options on the Game menu, which don't even show up
unless you define the magic environment variable
PUZZLES_EXPERIMENTAL_SAVE. Once I'm reasonably confident that the
whole edifice is plausibly stable, I'll take that out and turn it
into a supported feature (and also implement it in OS X and Windows
and write documentation).

[originally from svn r6030]
2005-06-28 17:05:05 +00:00
89fdc09c29 More serialisation changes: the game_aux_info structure has now been
retired, and replaced with a simple string. Most of the games which
use it simply encode the string in the same way that the Solve move
will also be encoded, i.e. solve_game() simply returns
dupstr(aux_info). Again, this is a better approach than writing
separate game_aux_info serialise/deserialise functions because doing
it this way is self-testing (the strings are created and parsed
during the course of any Solve operation at all).

[originally from svn r6029]
2005-06-28 11:14:09 +00:00
7cb29412c1 Fix GTK casts to restore correct compilation on GTK 2.0 after r6022.
[originally from svn r6023]
[r6022 == e1c84c9a4ea9e74c128c28a77ea08336350991e3]
2005-06-26 13:12:34 +00:00
e1c84c9a4e Under Gtk 1.2 (at least on Debian woody), a config or preset change that would
otherwise not cause the window size to change caused it to become very small
indeed. This change from Simon fixes that behaviour; I haven't tested it with
Gtk 2.

[originally from svn r6022]
2005-06-26 12:54:08 +00:00
258293a82a Add debugging support.
[originally from svn r6018]
2005-06-25 17:24:03 +00:00
b909204392 Introduce a front-end function to draw circles.
[originally from svn r5991]
2005-06-23 08:24:52 +00:00
b176767dfa New front end functions to save and restore a region of the puzzle
bitmap. Can be used to implement sprite-like animations: for
example, useful for games that wish to implement a user interface
which involves dragging an object around the playing area.

[originally from svn r5987]
2005-06-22 08:30:31 +00:00
a9d0f9ef35 GDK 2.6, in its doubtless infinite wisdom, has decided that
gdk_font_from_description() will no longer even _try_ to return a
font matching the specified Pango font description; instead it will
return `fixed' no matter what you do. Therefore, I've had to switch
to using Pango proper for Puzzles text rendering, rather than just
using Pango for font selection.

[originally from svn r5936]
2005-06-09 18:29:11 +00:00
8add7421df Chris Emerson points out that gtk_window_resize() isn't in GTK 1.2.
Work around it the same way I did in PuTTY.

[originally from svn r5920]
2005-06-07 20:25:25 +00:00
02035753f8 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]
2005-06-07 17:57:50 +00:00
402408125e Colin Watson suggests that Alt-click (or Option-click) could
usefully be equivalent to right-clicking on platforms other than OS
X; in particular, it's useful if you're running Linux on Apple
hardware such as PowerBook which inherently has only one button. So
here's the fix for GTK, and Windows as well (the latter for
completeness and consistency, not because I can actually think of
any reason somebody might be running Windows on one-button
hardware).

[originally from svn r5907]
2005-06-03 12:27:29 +00:00
ad2ec32e1c Fix various departures from C found by `gcc -ansi -pedantic'. I
haven't checked in Makefile changes to enable this, but I'll at
least fix the specific problems it found when enabled as a one-off.

[originally from svn r5902]
2005-06-02 08:14:14 +00:00
695b6be363 Chris Emerson observed the same status-bar flicker under GTK as I
did under Windows, so here's his patch (blatantly copied from my own
fix in windows.c :-).

[originally from svn r5891]
2005-06-01 06:54:14 +00:00
412344ff9a Fix a couple of robustness issues.
[originally from svn r5873]
2005-05-31 08:56:33 +00:00
2698fc9e9e GTK misfires timers at inconvenient moments, sometimes causing a new
puzzle of a different size to be redrawn before the pixmap is
resized, and since backends never redraw already-drawn stuff this is
a problem. Was biting me when I entered a Mines game ID of a
different size than the current settings into the Specific box.

[originally from svn r5872]
2005-05-31 08:50:42 +00:00
e4328b9081 Added an `interactive' flag to new_game_desc(), which toggles Mines
between on the one hand generating indeterminate game descriptions
awaiting the initial click, and on the other hand generating
concrete ones which have had their initial click. This makes `mines
--generate' do something useful.

[originally from svn r5869]
2005-05-30 18:41:40 +00:00
90560462c4 First cut at a game timer. Yet another backend function which
indicates whether a particular game state should have the timer
going (for Mines the initial indeterminate state does not have this
property, and neither does a dead or won state); a midend function
that optionally (on request from the game) prepends a timer to the
front of the status bar text; some complicated midend timing code.

It's not great. It's ugly; it's probably slightly inaccurate; it's
got no provision for anyone but the game author decreeing whether a
game is timed or not. But Mines can't be taken seriously without a
timer, so it's a start.

[originally from svn r5866]
2005-05-30 16:15:34 +00:00
865e8ad6ca Add origin-shifting (Shift+cursors) and source-shifting (Ctrl+cursors) to Net.
(Adding modifier+cursors handling has had minor knock-on effects on the other
puzzles, so that they can continue to ignore modifiers.)

(An unfortunate side effect of this is some artifacts in exterior barrier
drawing; notably, a disconnected corner can now appear at the corner of the
grid under some circumstances. I haven't found a satisfactory way round
this yet.)

[originally from svn r5844]
2005-05-26 13:40:38 +00:00
80aa8bafb1 I'm sick of `--generate' giving the same answers if you run it twice
in one second. Switched the Unix get_random_seed() to using
gettimeofday() rather than time().

[originally from svn r5837]
2005-05-23 11:15:39 +00:00
916ad91298 The GTK `--generate' option didn't validate the game parameters. It
does now.

[originally from svn r5836]
2005-05-23 11:13:39 +00:00
cf9e6e81eb --version.
[originally from svn r5806]
2005-05-18 17:27:16 +00:00
90e42d4cde Move the colour configuration into midend.c so that it becomes
cross-platform, and rename the environment variables so that they
follow the puzzle name. Should allow a static environment
configuration for each puzzle. Also introduced a <game>_PRESETS
variable for people whose favourite configuration isn't on the Type
menu by default.

[originally from svn r5801]
2005-05-18 09:04:47 +00:00
0e197efe44 After much thought, I've decided that `Restart' on r is not a
particularly useful keypress, particularly given how easy it is to
confuse it with `Redo'. So both r and ^R are now Redo, and Restart
is relegated to being a menu-only option.

[originally from svn r5796]
2005-05-17 17:20:08 +00:00
b77d727eb4 Just for Gareth: a means of overriding individual game colour
settings using environment variables. GTK frontend only, because
this is an unsupported (and unprincipled) hack.

[originally from svn r5792]
2005-05-17 11:47:33 +00:00
2534ec5d69 The game IDs for Net (and Netslide) have always been random seeds
rather than literal grid descriptions, which has always faintly
annoyed me because it makes it impossible to type in a grid from
another source. However, Gareth pointed out that short random-seed
game descriptions are useful, because you can read one out to
someone else without having to master the technology of cross-
machine cut and paste, or you can have two people enter the same
random seed simultaneously in order to race against each other to
complete the same puzzle. So both types of game ID seem to have
their uses.

Therefore, here's a reorganisation of the whole game ID concept.
There are now two types of game ID: one has a parameter string then
a hash then a piece of arbitrary random seed text, and the other has
a parameter string then a colon then a literal game description. For
most games, the latter is identical to the game IDs that were
previously valid; for Net and Netslide, old game IDs must be
translated into new ones by turning the colon into a hash, and
there's a new descriptive game ID format.

Random seed IDs are not guaranteed to be portable between software
versions (this is a major reason why I added version reporting
yesterday). Descriptive game IDs have a longer lifespan.

As an added bonus, I've removed the sections of documentation
dealing with game parameter encodings not shown in the game ID
(Rectangles expansion factor, Solo symmetry and difficulty settings
etc), because _all_ parameters must be specified in a random seed ID
and therefore users can easily find out the appropriate parameter
string for any settings they have configured.

[originally from svn r5788]
2005-05-16 18:57:09 +00:00
c05b4697a8 Introduce a versioning mechanism, and an `About' box in all front
ends. Versioning will be done solely by Subversion revision number,
since development on these puzzles is very incremental and gradual
and there don't tend to be obvious points to place numbered
releases.

[originally from svn r5781]
2005-05-15 10:31:11 +00:00