File: gameboard.h

package info (click to toggle)
gplanarity 17906-7
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 732 kB
  • sloc: ansic: 8,776; makefile: 131; perl: 17; sed: 2
file content (341 lines) | stat: -rw-r--r-- 10,339 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
/*
 *
 *  gPlanarity: 
 *     The geeky little puzzle game with a big noodly crunch!
 *    
 *     gPlanarity copyright (C) 2005 Monty <monty@xiph.org>
 *     Original Flash game by John Tantalo <john.tantalo@case.edu>
 *     Original game concept by Mary Radcliffe
 *
 *  gPlanarity is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *   
 *  gPlanarity is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *   
 *  You should have received a copy of the GNU General Public License
 *  along with Postfish; see the file COPYING.  If not, write to the
 *  Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * 
 */

#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <time.h>

#include "nls.h"

#define V_RADIUS 8
#define V_LINE 2
#define V_LINE_COLOR         0, 0, 0
#define V_FILL_IDLE_COLOR   .2,.2, 1
#define V_FILL_LIT_COLOR     1, 1, 1
#define V_FILL_ADJ_COLOR     1,.2,.2

#define E_LINE 1.5
#define E_LINE_F_COLOR       0, 0, 0, 1
#define E_LINE_B_COLOR      .5,.5,.5, 1
#define SELECTBOX_COLOR     .2,.8,.8,.3

#define INTERSECTION_COLOR  1,.1,.1,.8
#define INTERSECTION_RADIUS 10
#define INTERSECTION_LINE_WIDTH 2

#define RESET_DELTA 2
#define SCALE_DELTA 8

#define B_LINE 1
#define B_BORDER 6.5
#define B_RADIUS 20
#define B_HUMP 130
#define B_COLOR         .1,.1,.7,.1
#define B_LINE_COLOR     0, 0,.7,.3
#define TEXT_COLOR      .0,.0,.7,.6
#define HIGH_COLOR      .7,.0,.0,.6

#define SCOREHEIGHT 50

#define ICON_WIDTH  160
#define ICON_HEIGHT 120

#define FADE_FRAMES 50
#define FADE_ANIM_INTERVAL 100

G_BEGIN_DECLS

#define GAMEBOARD_TYPE            (gameboard_get_type ())
#define GAMEBOARD(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMEBOARD_TYPE, Gameboard))
#define GAMEBOARD_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GAMEBOARD_TYPE, GameboardClass))
#define IS_GAMEBOARD(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMEBOARD_TYPE))
#define IS_GAMEBOARD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMEBOARD_TYPE))

typedef struct _Gameboard       Gameboard;
typedef struct _GameboardClass  GameboardClass;

typedef struct fade_list{
  vertex *v;
  struct fade_list *next;
} fade_list;

typedef struct {
  fade_list *head;
  int count;
  gint fade_timer;
} fade_state;

#define NUMBUTTONS 11

typedef struct {
  int position; // 0 inactive
                // 1 left
                // 2 center
                // 3 right
                // negative indicates active but undeployed
  int x_target;
  int x;

  int y_target;
  int y_inactive;
  int y_active;
  int y;
  int sweepdeploy;

  int alphad;
  double alpha;

  cairo_surface_t *idle;
  cairo_surface_t *lit;

  char *rollovertext;
  cairo_text_extents_t ex;

  int rollover;
  int press;

  void (*callback)();
} buttonstate;

typedef struct {
  buttonstate states[NUMBUTTONS];
  int buttons_ready;
  int allclear; // short-circuit hint
  int sweeper;
  int sweeperd;
  buttonstate *grabbed;
} buttongroup;

typedef struct {
  int num;
  double alpha;
  cairo_surface_t *icon;

  int x;
  int y;
  int w;
  int h;

} dialog_level_oneicon;

typedef struct {

  dialog_level_oneicon level_icons[5];
  int center_x;
  int center_done;
  int level_lit;
  int reset_deployed;
  
  GdkRectangle text1;
  GdkRectangle text2;
  GdkRectangle text3;
  GdkRectangle text4;

  gint icon_timer; // used for buttons and icons
} dialog_level_state;

struct _Gameboard{
  GtkWidget w;

  graph g;

  int pushed_curtain;
  void (*redraw_callback)(Gameboard *g);

  cairo_surface_t *vertex;
  cairo_surface_t *vertex_lit;
  cairo_surface_t *vertex_grabbed;
  cairo_surface_t *vertex_attached;
  cairo_surface_t *vertex_sel;
  cairo_surface_t *vertex_ghost;
  cairo_surface_t *forescore;
  cairo_surface_t *forebutton;
  cairo_surface_t *background;
  cairo_surface_t *foreground;
  cairo_pattern_t *curtainp;
  cairo_surface_t *curtains;

  int delayed_background;
  int first_expose;
  int hide_lines;
  int realtime_background;
  int show_intersections;
  int finish_dialog_active;
  int about_dialog_active;
  int pause_dialog_active;
  int level_dialog_active;

  buttongroup b;
  dialog_level_state d;
  fade_state fade;

  vertex *grabbed_vertex;
  vertex *lit_vertex;
  int group_drag;
  int button_grabbed;
  
  int grabx;
  int graby;
  int dragx;
  int dragy;
  int graboffx;
  int graboffy;
  
  int selection_grab;
  int selection_active;
  int selectionx;
  int selectiony;
  int selectionw;
  int selectionh;

  int checkbutton_deployed;
  int buttonbar_sweeper;
  
  gint button_timer; // used for buttons and icons
  void (*button_callback)(Gameboard *);

  time_t resize_timeout; // watch for ignored resize events
  int    resize_w;       // watch for ignored resize events
  int    resize_h;       // watch for ignored resize events
};

struct _GameboardClass{
  GtkWidgetClass parent_class;
  void (* gameboard) (Gameboard *m);
};

GType          gameboard_get_type        (void);
Gameboard*     gameboard_new             (void);

G_END_DECLS

extern void init_buttons(Gameboard *g);
extern buttonstate *find_button(Gameboard *g,int x,int y);
extern void button_set_state(Gameboard *g, buttonstate *b, int rollover, int press);
extern void rollover_extents(Gameboard *g, buttonstate *b);
extern gboolean animate_button_frame(gpointer ptr);
extern void expose_buttons(Gameboard *g,cairo_t *c, int x,int y,int w,int h);
extern void resize_buttons(Gameboard *g,int oldw,int oldh,int w,int h);
extern void button_clear_state(Gameboard *g);

extern void update_push(Gameboard *g, cairo_t *c);
extern void push_curtain(Gameboard *g,void(*redraw_callback)(Gameboard *g));
extern void pop_curtain(Gameboard *g);

extern void prepare_reenter_game(Gameboard *g);
extern void reenter_game(Gameboard *g);
extern void enter_game(Gameboard *g);
extern void quit_action(Gameboard *g);
extern void finish_action(Gameboard *g);
extern void expand_action(Gameboard *g);
extern void shrink_action(Gameboard *g);
extern void pause_action(Gameboard *g);
extern void about_action(Gameboard *g);
extern void level_action(Gameboard *g);
extern void set_hide_lines(Gameboard *g, int state);
extern void toggle_hide_lines(Gameboard *g);
extern void set_show_intersections(Gameboard *g, int state);
extern void toggle_show_intersections(Gameboard *g);
extern void reset_action(Gameboard *g);
extern int gameboard_write(char *basename, Gameboard *g);
extern int gameboard_read(char *basename, Gameboard *g);

extern void topbox (Gameboard *g,cairo_t *c, double w, double h);
extern void bottombox (Gameboard *g,cairo_t *c, double w, double h);
extern void centerbox (cairo_t *c, int x, int y, double w, double h);
extern void borderbox_path (cairo_t *c, double x, double y, double w, double h);

extern void setup_buttonbar(Gameboard *g);
extern void deploy_buttonbar(Gameboard *g);
extern void deploy_check(Gameboard *g);
extern void undeploy_check(Gameboard *g);

extern void update_draw(Gameboard *g);
extern void update_full(Gameboard *g);
extern void expose_full(Gameboard *g);
extern void update_full_delayed(Gameboard *g);
extern void update_add_vertex(Gameboard *g, vertex *v);
extern void update_add_selgroup(Gameboard *g);
extern void gameboard_draw(Gameboard *g, int x, int y, int w, int h);
extern void draw_foreground(Gameboard *g,cairo_t *c,
			    int x,int y,int width,int height);
extern void draw_intersections(Gameboard *b,graph *g,cairo_t *c,
			       int x,int y,int w,int h);

extern void draw_score(Gameboard *g);
extern void update_score(Gameboard *g);

extern void draw_vertex(cairo_t *c,vertex *v,cairo_surface_t *s);
extern void draw_vertex_with_alpha(cairo_t *c,vertex *v,cairo_surface_t *s,float alpha);
extern cairo_surface_t *cache_vertex(Gameboard *g);
extern cairo_surface_t *cache_vertex_sel(Gameboard *g);
extern cairo_surface_t *cache_vertex_grabbed(Gameboard *g);
extern cairo_surface_t *cache_vertex_lit(Gameboard *g);
extern cairo_surface_t *cache_vertex_attached(Gameboard *g);
extern cairo_surface_t *cache_vertex_ghost(Gameboard *g);
extern void invalidate_vertex_off(GtkWidget *widget, vertex *v, int dx, int dy);
extern void invalidate_vertex(Gameboard *g, vertex *v);
extern void invalidate_attached(GtkWidget *widget, vertex *v);
extern void invalidate_edges(GtkWidget *widget, vertex *v, int offx, int offy);
extern void draw_selection_rectangle(Gameboard *g,cairo_t *c);
extern void invalidate_selection(GtkWidget *widget);
extern void invalidate_verticies_selection(GtkWidget *widget);

extern void cache_curtain(Gameboard *g);
extern void draw_curtain(Gameboard *g);
extern void draw_buttonbar_box (Gameboard *g);

extern gint mouse_motion(GtkWidget *widget,GdkEventMotion *event);
extern gboolean mouse_press (GtkWidget *widget,GdkEventButton *event);
extern gboolean mouse_release (GtkWidget *widget,GdkEventButton *event);

extern void setup_background_edge(cairo_t *c);
extern void setup_foreground_edge(cairo_t *c);
extern void draw_edge(cairo_t *c,edge *e);
extern void draw_edges(cairo_t *c, vertex *v, int offx, int offy);
extern void finish_edge(cairo_t *c);

extern cairo_surface_t *gameboard_read_icon(char *filename, char *ext,Gameboard *b);
extern int gameboard_write_icon(char *filename, char *ext,Gameboard *b, graph *g,
				int lines, int intersections);
extern int gameboard_icon_exists(char *filename, char *ext);

extern void deploy_buttons(Gameboard *g, void (*callback)(Gameboard *));
extern void undeploy_buttons(Gameboard *g, void (*callback)(Gameboard *));

extern GdkRectangle render_text_centered(cairo_t *c, char *s, int x, int y);
extern GdkRectangle render_border_centered(cairo_t *c, char *s, int x, int y);
extern GdkRectangle render_bordertext_centered(cairo_t *c, char *s, int x, int y);

extern void gameboard_size_allocate (GtkWidget     *widget,
				     GtkAllocation *allocation);

extern void fade_cancel(Gameboard *g);
extern void fade_attached(Gameboard *g,vertex *v);
extern void fade_grabbed(Gameboard *g);
extern void fade_marked(Gameboard *g);