chiark / gitweb /
Assorted char * -> const char * API changes.
[sgt-puzzles.git] / puzzles.h
1 /*
2  * puzzles.h: header file for my puzzle collection
3  */
4
5 #ifndef PUZZLES_PUZZLES_H
6 #define PUZZLES_PUZZLES_H
7
8 #include <stdio.h>  /* for FILE */
9 #include <stdlib.h> /* for size_t */
10 #include <limits.h> /* for UINT_MAX */
11
12 #ifndef TRUE
13 #define TRUE 1
14 #endif
15 #ifndef FALSE
16 #define FALSE 0
17 #endif
18
19 #define PI 3.141592653589793238462643383279502884197169399
20
21 #define lenof(array) ( sizeof(array) / sizeof(*(array)) )
22
23 #define STR_INT(x) #x
24 #define STR(x) STR_INT(x)
25
26 /* NB not perfect because they evaluate arguments multiple times. */
27 #ifndef max
28 #define max(x,y) ( (x)>(y) ? (x) : (y) )
29 #endif /* max */
30 #ifndef min
31 #define min(x,y) ( (x)<(y) ? (x) : (y) )
32 #endif /* min */
33
34 enum {
35     LEFT_BUTTON = 0x0200,
36     MIDDLE_BUTTON,
37     RIGHT_BUTTON,
38     LEFT_DRAG,
39     MIDDLE_DRAG,
40     RIGHT_DRAG,
41     LEFT_RELEASE,
42     MIDDLE_RELEASE,
43     RIGHT_RELEASE,
44     CURSOR_UP,
45     CURSOR_DOWN,
46     CURSOR_LEFT,
47     CURSOR_RIGHT,
48     CURSOR_SELECT,
49     CURSOR_SELECT2,
50     /* UI_* are special keystrokes generated by front ends in response
51      * to menu actions, never passed to back ends */
52     UI_LOWER_BOUND,
53     UI_QUIT,
54     UI_NEWGAME,
55     UI_SOLVE,
56     UI_UNDO,
57     UI_REDO,
58     UI_UPPER_BOUND,
59     
60     /* made smaller because of 'limited range of datatype' errors. */
61     MOD_CTRL       = 0x1000,
62     MOD_SHFT       = 0x2000,
63     MOD_NUM_KEYPAD = 0x4000,
64     MOD_MASK       = 0x7000 /* mask for all modifiers */
65 };
66
67 #define IS_MOUSE_DOWN(m) ( (unsigned)((m) - LEFT_BUTTON) <= \
68                                (unsigned)(RIGHT_BUTTON - LEFT_BUTTON))
69 #define IS_MOUSE_DRAG(m) ( (unsigned)((m) - LEFT_DRAG) <= \
70                                (unsigned)(RIGHT_DRAG - LEFT_DRAG))
71 #define IS_MOUSE_RELEASE(m) ( (unsigned)((m) - LEFT_RELEASE) <= \
72                                (unsigned)(RIGHT_RELEASE - LEFT_RELEASE))
73 #define IS_CURSOR_MOVE(m) ( (m) == CURSOR_UP || (m) == CURSOR_DOWN || \
74                             (m) == CURSOR_RIGHT || (m) == CURSOR_LEFT )
75 #define IS_CURSOR_SELECT(m) ( (m) == CURSOR_SELECT || (m) == CURSOR_SELECT2)
76 #define IS_UI_FAKE_KEY(m) ( (m) > UI_LOWER_BOUND && (m) < UI_UPPER_BOUND )
77
78 /*
79  * Flags in the back end's `flags' word.
80  */
81 /* Bit flags indicating mouse button priorities */
82 #define BUTTON_BEATS(x,y) ( 1 << (((x)-LEFT_BUTTON)*3+(y)-LEFT_BUTTON) )
83 /* Flag indicating that Solve operations should be animated */
84 #define SOLVE_ANIMATES ( 1 << 9 )
85 /* Pocket PC: Game requires right mouse button emulation */
86 #define REQUIRE_RBUTTON ( 1 << 10 )
87 /* Pocket PC: Game requires numeric input */
88 #define REQUIRE_NUMPAD ( 1 << 11 )
89 /* end of `flags' word definitions */
90
91 #ifdef _WIN32_WCE
92   /* Pocket PC devices have small, portrait screen that requires more vivid colours */
93   #define SMALL_SCREEN
94   #define PORTRAIT_SCREEN
95   #define VIVID_COLOURS
96   #define STYLUS_BASED
97 #endif
98
99 #define IGNOREARG(x) ( (x) = (x) )
100
101 typedef struct frontend frontend;
102 typedef struct config_item config_item;
103 typedef struct midend midend;
104 typedef struct random_state random_state;
105 typedef struct game_params game_params;
106 typedef struct game_state game_state;
107 typedef struct game_ui game_ui;
108 typedef struct game_drawstate game_drawstate;
109 typedef struct game game;
110 typedef struct blitter blitter;
111 typedef struct document document;
112 typedef struct drawing_api drawing_api;
113 typedef struct drawing drawing;
114 typedef struct psdata psdata;
115
116 #define ALIGN_VNORMAL 0x000
117 #define ALIGN_VCENTRE 0x100
118
119 #define ALIGN_HLEFT   0x000
120 #define ALIGN_HCENTRE 0x001
121 #define ALIGN_HRIGHT  0x002
122
123 #define FONT_FIXED    0
124 #define FONT_VARIABLE 1
125
126 /* For printing colours */
127 #define HATCH_SLASH     1
128 #define HATCH_BACKSLASH 2
129 #define HATCH_HORIZ     3
130 #define HATCH_VERT      4
131 #define HATCH_PLUS      5
132 #define HATCH_X         6
133
134 /*
135  * Structure used to pass configuration data between frontend and
136  * game
137  */
138 enum { C_STRING, C_CHOICES, C_BOOLEAN, C_END };
139 struct config_item {
140     /* Not dynamically allocated */
141     const char *name;
142     /* Value from the above C_* enum */
143     int type;
144     union {
145         struct { /* if type == C_STRING */
146             /* Always dynamically allocated and non-NULL */
147             char *sval;
148         } string;
149         struct { /* if type == C_CHOICES */
150             /*
151              * choicenames is non-NULL, not dynamically allocated, and
152              * contains a set of option strings separated by a
153              * delimiter. The delimiter is also the first character in
154              * the string, so for example ":Foo:Bar:Baz" gives three
155              * options `Foo', `Bar' and `Baz'.
156              */
157             const char *choicenames;
158             /*
159              * Indicates the chosen index from the options in
160              * choicenames. In the above example, 0==Foo, 1==Bar and
161              * 2==Baz.
162              */
163             int selected;
164         } choices;
165         struct {
166             /* just TRUE or FALSE */
167             int bval;
168         } boolean;
169     } u;
170 };
171
172 /*
173  * Structure used to communicate the presets menu from midend to
174  * frontend. In principle, it's also used to pass the same information
175  * from game to midend, though games that don't specify a menu
176  * hierarchy (i.e. most of them) will use the simpler fetch_preset()
177  * function to return an unstructured list.
178  *
179  * A tree of these structures always belongs to the midend, and only
180  * the midend should ever need to free it. The front end should treat
181  * them as read-only.
182  */
183 struct preset_menu_entry {
184     char *title;
185     /* Exactly one of the next two fields is NULL, depending on
186      * whether this entry is a submenu title or an actual preset */
187     game_params *params;
188     struct preset_menu *submenu;
189     /* Every preset menu entry has a number allocated by the mid-end,
190      * so that midend_which_preset() can return a value that
191      * identifies an entry anywhere in the menu hierarchy. The values
192      * will be allocated reasonably densely from 1 upwards (so it's
193      * reasonable for the front end to use them as array indices if it
194      * needs to store GUI state per menu entry), but no other
195      * guarantee is given about their ordering.
196      *
197      * Entries containing submenus have ids too - not only the actual
198      * presets are numbered. */
199     int id;
200 };
201 struct preset_menu {
202     int n_entries;             /* number of entries actually in use */
203     int entries_size;          /* space currently allocated in this array */
204     struct preset_menu_entry *entries;
205 };
206 /* For games which do want to directly return a tree of these, here
207  * are convenience routines (in midend.c) for constructing one. These
208  * assume that 'title' and 'encoded_params' are already dynamically
209  * allocated by the caller; the resulting preset_menu tree takes
210  * ownership of them. */
211 struct preset_menu *preset_menu_new(void);
212 struct preset_menu *preset_menu_add_submenu(struct preset_menu *parent,
213                                             char *title);
214 void preset_menu_add_preset(struct preset_menu *menu,
215                             char *title, game_params *params);
216 /* Helper routine front ends can use for one of the ways they might
217  * want to organise their preset menu usage */
218 game_params *preset_menu_lookup_by_id(struct preset_menu *menu, int id);
219
220 /*
221  * Platform routines
222  */
223
224 /* We can't use #ifdef DEBUG, because Cygwin defines it by default. */
225 #ifdef DEBUGGING
226 #define debug(x) (debug_printf x)
227 void debug_printf(const char *fmt, ...);
228 #else
229 #define debug(x)
230 #endif
231
232 void fatal(const char *fmt, ...);
233 void frontend_default_colour(frontend *fe, float *output);
234 void deactivate_timer(frontend *fe);
235 void activate_timer(frontend *fe);
236 void get_random_seed(void **randseed, int *randseedsize);
237
238 /*
239  * drawing.c
240  */
241 drawing *drawing_new(const drawing_api *api, midend *me, void *handle);
242 void drawing_free(drawing *dr);
243 void draw_text(drawing *dr, int x, int y, int fonttype, int fontsize,
244                int align, int colour, const char *text);
245 void draw_rect(drawing *dr, int x, int y, int w, int h, int colour);
246 void draw_line(drawing *dr, int x1, int y1, int x2, int y2, int colour);
247 void draw_polygon(drawing *dr, int *coords, int npoints,
248                   int fillcolour, int outlinecolour);
249 void draw_circle(drawing *dr, int cx, int cy, int radius,
250                  int fillcolour, int outlinecolour);
251 void draw_thick_line(drawing *dr, float thickness,
252                      float x1, float y1, float x2, float y2, int colour);
253 void clip(drawing *dr, int x, int y, int w, int h);
254 void unclip(drawing *dr);
255 void start_draw(drawing *dr);
256 void draw_update(drawing *dr, int x, int y, int w, int h);
257 void end_draw(drawing *dr);
258 char *text_fallback(drawing *dr, const char *const *strings, int nstrings);
259 void status_bar(drawing *dr, const char *text);
260 blitter *blitter_new(drawing *dr, int w, int h);
261 void blitter_free(drawing *dr, blitter *bl);
262 /* save puts the portion of the current display with top-left corner
263  * (x,y) to the blitter. load puts it back again to the specified
264  * coords, or else wherever it was saved from
265  * (if x = y = BLITTER_FROMSAVED). */
266 void blitter_save(drawing *dr, blitter *bl, int x, int y);
267 #define BLITTER_FROMSAVED (-1)
268 void blitter_load(drawing *dr, blitter *bl, int x, int y);
269 void print_begin_doc(drawing *dr, int pages);
270 void print_begin_page(drawing *dr, int number);
271 void print_begin_puzzle(drawing *dr, float xm, float xc,
272                         float ym, float yc, int pw, int ph, float wmm,
273                         float scale);
274 void print_end_puzzle(drawing *dr);
275 void print_end_page(drawing *dr, int number);
276 void print_end_doc(drawing *dr);
277 void print_get_colour(drawing *dr, int colour, int printing_in_colour,
278                       int *hatch, float *r, float *g, float *b);
279 int print_mono_colour(drawing *dr, int grey); /* 0==black, 1==white */
280 int print_grey_colour(drawing *dr, float grey);
281 int print_hatched_colour(drawing *dr, int hatch);
282 int print_rgb_mono_colour(drawing *dr, float r, float g, float b, int mono);
283 int print_rgb_grey_colour(drawing *dr, float r, float g, float b, float grey);
284 int print_rgb_hatched_colour(drawing *dr, float r, float g, float b,
285                              int hatch);
286 void print_line_width(drawing *dr, int width);
287 void print_line_dotted(drawing *dr, int dotted);
288
289 /*
290  * midend.c
291  */
292 midend *midend_new(frontend *fe, const game *ourgame,
293                    const drawing_api *drapi, void *drhandle);
294 void midend_free(midend *me);
295 const game *midend_which_game(midend *me);
296 void midend_set_params(midend *me, game_params *params);
297 game_params *midend_get_params(midend *me);
298 void midend_size(midend *me, int *x, int *y, int user_size);
299 void midend_reset_tilesize(midend *me);
300 void midend_new_game(midend *me);
301 void midend_restart_game(midend *me);
302 void midend_stop_anim(midend *me);
303 int midend_process_key(midend *me, int x, int y, int button);
304 void midend_force_redraw(midend *me);
305 void midend_redraw(midend *me);
306 float *midend_colours(midend *me, int *ncolours);
307 void midend_freeze_timer(midend *me, float tprop);
308 void midend_timer(midend *me, float tplus);
309 struct preset_menu *midend_get_presets(midend *me, int *id_limit);
310 int midend_which_preset(midend *me);
311 int midend_wants_statusbar(midend *me);
312 enum { CFG_SETTINGS, CFG_SEED, CFG_DESC, CFG_FRONTEND_SPECIFIC };
313 config_item *midend_get_config(midend *me, int which, char **wintitle);
314 const char *midend_set_config(midend *me, int which, config_item *cfg);
315 const char *midend_game_id(midend *me, const char *id);
316 char *midend_get_game_id(midend *me);
317 char *midend_get_random_seed(midend *me);
318 int midend_can_format_as_text_now(midend *me);
319 char *midend_text_format(midend *me);
320 const char *midend_solve(midend *me);
321 int midend_status(midend *me);
322 int midend_can_undo(midend *me);
323 int midend_can_redo(midend *me);
324 void midend_supersede_game_desc(midend *me, const char *desc,
325                                 const char *privdesc);
326 char *midend_rewrite_statusbar(midend *me, const char *text);
327 void midend_serialise(midend *me,
328                       void (*write)(void *ctx, void *buf, int len),
329                       void *wctx);
330 const char *midend_deserialise(midend *me,
331                                int (*read)(void *ctx, void *buf, int len),
332                                void *rctx);
333 const char *identify_game(char **name,
334                           int (*read)(void *ctx, void *buf, int len),
335                           void *rctx);
336 void midend_request_id_changes(midend *me, void (*notify)(void *), void *ctx);
337 /* Printing functions supplied by the mid-end */
338 const char *midend_print_puzzle(midend *me, document *doc, int with_soln);
339 int midend_tilesize(midend *me);
340
341 /*
342  * malloc.c
343  */
344 void *smalloc(size_t size);
345 void *srealloc(void *p, size_t size);
346 void sfree(void *p);
347 char *dupstr(const char *s);
348 #define snew(type) \
349     ( (type *) smalloc (sizeof (type)) )
350 #define snewn(number, type) \
351     ( (type *) smalloc ((number) * sizeof (type)) )
352 #define sresize(array, number, type) \
353     ( (type *) srealloc ((array), (number) * sizeof (type)) )
354
355 /*
356  * misc.c
357  */
358 void free_cfg(config_item *cfg);
359 void obfuscate_bitmap(unsigned char *bmp, int bits, int decode);
360
361 /* allocates output each time. len is always in bytes of binary data.
362  * May assert (or just go wrong) if lengths are unchecked. */
363 char *bin2hex(const unsigned char *in, int inlen);
364 unsigned char *hex2bin(const char *in, int outlen);
365
366 /* Sets (and possibly dims) background from frontend default colour,
367  * and auto-generates highlight and lowlight colours too. */
368 void game_mkhighlight(frontend *fe, float *ret,
369                       int background, int highlight, int lowlight);
370 /* As above, but starts from a provided background colour rather
371  * than the frontend default. */
372 void game_mkhighlight_specific(frontend *fe, float *ret,
373                                int background, int highlight, int lowlight);
374
375 /* Randomly shuffles an array of items. */
376 void shuffle(void *array, int nelts, int eltsize, random_state *rs);
377
378 /* Draw a rectangle outline, using the drawing API's draw_line. */
379 void draw_rect_outline(drawing *dr, int x, int y, int w, int h,
380                        int colour);
381
382 /* Draw a set of rectangle corners (e.g. for a cursor display). */
383 void draw_rect_corners(drawing *dr, int cx, int cy, int r, int col);
384
385 void move_cursor(int button, int *x, int *y, int maxw, int maxh, int wrap);
386
387 /* Used in netslide.c and sixteen.c for cursor movement around edge. */
388 int c2pos(int w, int h, int cx, int cy);
389 int c2diff(int w, int h, int cx, int cy, int button);
390 void pos2c(int w, int h, int pos, int *cx, int *cy);
391
392 /* Draws text with an 'outline' formed by offsetting the text
393  * by one pixel; useful for highlighting. Outline is omitted if -1. */
394 void draw_text_outline(drawing *dr, int x, int y, int fonttype,
395                        int fontsize, int align,
396                        int text_colour, int outline_colour, const char *text);
397
398 /* Copies text left-justified with spaces. Length of string must be
399  * less than buffer size. */
400 void copy_left_justified(char *buf, size_t sz, const char *str);
401
402 /*
403  * dsf.c
404  */
405 int *snew_dsf(int size);
406
407 void print_dsf(int *dsf, int size);
408
409 /* Return the canonical element of the equivalence class containing element
410  * val.  If 'inverse' is non-NULL, this function will put into it a flag
411  * indicating whether the canonical element is inverse to val. */
412 int edsf_canonify(int *dsf, int val, int *inverse);
413 int dsf_canonify(int *dsf, int val);
414 int dsf_size(int *dsf, int val);
415
416 /* Allow the caller to specify that two elements should be in the same
417  * equivalence class.  If 'inverse' is TRUE, the elements are actually opposite
418  * to one another in some sense.  This function will fail an assertion if the
419  * caller gives it self-contradictory data, ie if two elements are claimed to
420  * be both opposite and non-opposite. */
421 void edsf_merge(int *dsf, int v1, int v2, int inverse);
422 void dsf_merge(int *dsf, int v1, int v2);
423 void dsf_init(int *dsf, int len);
424
425 /*
426  * tdq.c
427  */
428
429 /*
430  * Data structure implementing a 'to-do queue', a simple
431  * de-duplicating to-do list mechanism.
432  *
433  * Specification: a tdq is a queue which can hold integers from 0 to
434  * n-1, where n was some constant specified at tdq creation time. No
435  * integer may appear in the queue's current contents more than once;
436  * an attempt to add an already-present integer again will do nothing,
437  * so that that integer is removed from the queue at the position
438  * where it was _first_ inserted. The add and remove operations take
439  * constant time.
440  *
441  * The idea is that you might use this in applications like solvers:
442  * keep a tdq listing the indices of grid squares that you currently
443  * need to process in some way. Whenever you modify a square in a way
444  * that will require you to re-scan its neighbours, add them to the
445  * list with tdq_add; meanwhile you're constantly taking elements off
446  * the list when you need another square to process. In solvers where
447  * deductions are mostly localised, this should prevent repeated
448  * O(N^2) loops over the whole grid looking for something to do. (But
449  * if only _most_ of the deductions are localised, then you should
450  * respond to an empty to-do list by re-adding everything using
451  * tdq_fill, so _then_ you rescan the whole grid looking for newly
452  * enabled non-local deductions. Only if you've done that and emptied
453  * the list again finding nothing new to do are you actually done.)
454  */
455 typedef struct tdq tdq;
456 tdq *tdq_new(int n);
457 void tdq_free(tdq *tdq);
458 void tdq_add(tdq *tdq, int k);
459 int tdq_remove(tdq *tdq);        /* returns -1 if nothing available */
460 void tdq_fill(tdq *tdq);         /* add everything to the tdq at once */
461
462 /*
463  * laydomino.c
464  */
465 int *domino_layout(int w, int h, random_state *rs);
466 void domino_layout_prealloc(int w, int h, random_state *rs,
467                             int *grid, int *grid2, int *list);
468 /*
469  * version.c
470  */
471 extern char ver[];
472
473 /*
474  * random.c
475  */
476 random_state *random_new(const char *seed, int len);
477 random_state *random_copy(random_state *tocopy);
478 unsigned long random_bits(random_state *state, int bits);
479 unsigned long random_upto(random_state *state, unsigned long limit);
480 void random_free(random_state *state);
481 char *random_state_encode(random_state *state);
482 random_state *random_state_decode(const char *input);
483 /* random.c also exports SHA, which occasionally comes in useful. */
484 #if __STDC_VERSION__ >= 199901L
485 #include <stdint.h>
486 typedef uint32_t uint32;
487 #elif UINT_MAX >= 4294967295L
488 typedef unsigned int uint32;
489 #else
490 typedef unsigned long uint32;
491 #endif
492 typedef struct {
493     uint32 h[5];
494     unsigned char block[64];
495     int blkused;
496     uint32 lenhi, lenlo;
497 } SHA_State;
498 void SHA_Init(SHA_State *s);
499 void SHA_Bytes(SHA_State *s, const void *p, int len);
500 void SHA_Final(SHA_State *s, unsigned char *output);
501 void SHA_Simple(const void *p, int len, unsigned char *output);
502
503 /*
504  * printing.c
505  */
506 document *document_new(int pw, int ph, float userscale);
507 void document_free(document *doc);
508 void document_add_puzzle(document *doc, const game *game, game_params *par,
509                          game_state *st, game_state *st2);
510 void document_print(document *doc, drawing *dr);
511
512 /*
513  * ps.c
514  */
515 psdata *ps_init(FILE *outfile, int colour);
516 void ps_free(psdata *ps);
517 drawing *ps_drawing_api(psdata *ps);
518
519 /*
520  * combi.c: provides a structure and functions for iterating over
521  * combinations (i.e. choosing r things out of n).
522  */
523 typedef struct _combi_ctx {
524   int r, n, nleft, total;
525   int *a;
526 } combi_ctx;
527
528 combi_ctx *new_combi(int r, int n);
529 void reset_combi(combi_ctx *combi);
530 combi_ctx *next_combi(combi_ctx *combi); /* returns NULL for end */
531 void free_combi(combi_ctx *combi);
532
533 /*
534  * divvy.c
535  */
536 /* divides w*h rectangle into pieces of size k. Returns w*h dsf. */
537 int *divvy_rectangle(int w, int h, int k, random_state *rs);
538
539 /*
540  * findloop.c
541  */
542 struct findloopstate;
543 struct findloopstate *findloop_new_state(int nvertices);
544 void findloop_free_state(struct findloopstate *);
545 /*
546  * Callback provided by the client code to enumerate the graph
547  * vertices joined directly to a given vertex.
548  *
549  * Semantics: if vertex >= 0, return one of its neighbours; if vertex
550  * < 0, return a previously unmentioned neighbour of whatever vertex
551  * was last passed as input. Write to 'ctx' as necessary to store
552  * state. In either case, return < 0 if no such vertex can be found.
553  */
554 typedef int (*neighbour_fn_t)(int vertex, void *ctx);
555 /*
556  * Actual function to find loops. 'ctx' will be passed unchanged to
557  * the 'neighbour' function to query graph edges. Returns FALSE if no
558  * loop was found, or TRUE if one was.
559  */
560 int findloop_run(struct findloopstate *state, int nvertices,
561                  neighbour_fn_t neighbour, void *ctx);
562 /*
563  * Query whether an edge is part of a loop, in the output of
564  * find_loops.
565  *
566  * Due to the internal storage format, if you pass u,v which are not
567  * connected at all, the output will be TRUE. (The algorithm actually
568  * stores an exhaustive list of *non*-loop edges, because there are
569  * fewer of those, so really it's querying whether the edge is on that
570  * list.)
571  */
572 int findloop_is_loop_edge(struct findloopstate *state, int u, int v);
573
574 /*
575  * Data structure containing the function calls and data specific
576  * to a particular game. This is enclosed in a data structure so
577  * that a particular platform can choose, if it wishes, to compile
578  * all the games into a single combined executable rather than
579  * having lots of little ones.
580  */
581 struct game {
582     const char *name;
583     const char *winhelp_topic, *htmlhelp_topic;
584     game_params *(*default_params)(void);
585     int (*fetch_preset)(int i, char **name, game_params **params);
586     struct preset_menu *(*preset_menu)(void);
587     void (*decode_params)(game_params *, char const *string);
588     char *(*encode_params)(const game_params *, int full);
589     void (*free_params)(game_params *params);
590     game_params *(*dup_params)(const game_params *params);
591     int can_configure;
592     config_item *(*configure)(const game_params *params);
593     game_params *(*custom_params)(const config_item *cfg);
594     const char *(*validate_params)(const game_params *params, int full);
595     char *(*new_desc)(const game_params *params, random_state *rs,
596                       char **aux, int interactive);
597     const char *(*validate_desc)(const game_params *params, const char *desc);
598     game_state *(*new_game)(midend *me, const game_params *params,
599                             const char *desc);
600     game_state *(*dup_game)(const game_state *state);
601     void (*free_game)(game_state *state);
602     int can_solve;
603     char *(*solve)(const game_state *orig, const game_state *curr,
604                    const char *aux, const char **error);
605     int can_format_as_text_ever;
606     int (*can_format_as_text_now)(const game_params *params);
607     char *(*text_format)(const game_state *state);
608     game_ui *(*new_ui)(const game_state *state);
609     void (*free_ui)(game_ui *ui);
610     char *(*encode_ui)(const game_ui *ui);
611     void (*decode_ui)(game_ui *ui, const char *encoding);
612     void (*changed_state)(game_ui *ui, const game_state *oldstate,
613                           const game_state *newstate);
614     char *(*interpret_move)(const game_state *state, game_ui *ui,
615                             const game_drawstate *ds, int x, int y, int button);
616     game_state *(*execute_move)(const game_state *state, const char *move);
617     int preferred_tilesize;
618     void (*compute_size)(const game_params *params, int tilesize,
619                          int *x, int *y);
620     void (*set_size)(drawing *dr, game_drawstate *ds,
621                      const game_params *params, int tilesize);
622     float *(*colours)(frontend *fe, int *ncolours);
623     game_drawstate *(*new_drawstate)(drawing *dr, const game_state *state);
624     void (*free_drawstate)(drawing *dr, game_drawstate *ds);
625     void (*redraw)(drawing *dr, game_drawstate *ds, const game_state *oldstate,
626                    const game_state *newstate, int dir, const game_ui *ui,
627                    float anim_time, float flash_time);
628     float (*anim_length)(const game_state *oldstate,
629                          const game_state *newstate, int dir, game_ui *ui);
630     float (*flash_length)(const game_state *oldstate,
631                           const game_state *newstate, int dir, game_ui *ui);
632     int (*status)(const game_state *state);
633     int can_print, can_print_in_colour;
634     void (*print_size)(const game_params *params, float *x, float *y);
635     void (*print)(drawing *dr, const game_state *state, int tilesize);
636     int wants_statusbar;
637     int is_timed;
638     int (*timing_state)(const game_state *state, game_ui *ui);
639     int flags;
640 };
641
642 /*
643  * Data structure containing the drawing API implemented by the
644  * front end and also by cross-platform printing modules such as
645  * PostScript.
646  */
647 struct drawing_api {
648     void (*draw_text)(void *handle, int x, int y, int fonttype, int fontsize,
649                       int align, int colour, const char *text);
650     void (*draw_rect)(void *handle, int x, int y, int w, int h, int colour);
651     void (*draw_line)(void *handle, int x1, int y1, int x2, int y2,
652                       int colour);
653     void (*draw_polygon)(void *handle, int *coords, int npoints,
654                          int fillcolour, int outlinecolour);
655     void (*draw_circle)(void *handle, int cx, int cy, int radius,
656                         int fillcolour, int outlinecolour);
657     void (*draw_update)(void *handle, int x, int y, int w, int h);
658     void (*clip)(void *handle, int x, int y, int w, int h);
659     void (*unclip)(void *handle);
660     void (*start_draw)(void *handle);
661     void (*end_draw)(void *handle);
662     void (*status_bar)(void *handle, const char *text);
663     blitter *(*blitter_new)(void *handle, int w, int h);
664     void (*blitter_free)(void *handle, blitter *bl);
665     void (*blitter_save)(void *handle, blitter *bl, int x, int y);
666     void (*blitter_load)(void *handle, blitter *bl, int x, int y);
667     void (*begin_doc)(void *handle, int pages);
668     void (*begin_page)(void *handle, int number);
669     void (*begin_puzzle)(void *handle, float xm, float xc,
670                          float ym, float yc, int pw, int ph, float wmm);
671     void (*end_puzzle)(void *handle);
672     void (*end_page)(void *handle, int number);
673     void (*end_doc)(void *handle);
674     void (*line_width)(void *handle, float width);
675     void (*line_dotted)(void *handle, int dotted);
676     char *(*text_fallback)(void *handle, const char *const *strings,
677                            int nstrings);
678     void (*draw_thick_line)(void *handle, float thickness,
679                             float x1, float y1, float x2, float y2,
680                             int colour);
681 };
682
683 /*
684  * For one-game-at-a-time platforms, there's a single structure
685  * like the above, under a fixed name. For all-at-once platforms,
686  * there's a list of all available puzzles in array form.
687  */
688 #ifdef COMBINED
689 extern const game *gamelist[];
690 extern const int gamecount;
691 #else
692 extern const game thegame;
693 #endif
694
695 /*
696  * Special string value to return from interpret_move in the case
697  * where the game UI has been updated but no actual move is being
698  * appended to the undo chain. Must be declared as a non-const char,
699  * but should never actually be modified by anyone.
700  */
701 extern char UI_UPDATE[];
702
703 /* A little bit of help to lazy developers */
704 #define DEFAULT_STATUSBAR_TEXT "Use status_bar() to fill this in."
705
706 #endif /* PUZZLES_PUZZLES_H */