Add Russian translation provided by Валерий Крувялис <valkru@mail.ru>
[xiph-mirror.git] / planarity / gameboard.h
blob6990b7ecb43c9dd8ec1f6ed1f62fb85787f0e101
1 /*
3 * gPlanarity:
4 * The geeky little puzzle game with a big noodly crunch!
5 *
6 * gPlanarity copyright (C) 2005 Monty <monty@xiph.org>
7 * Original Flash game by John Tantalo <john.tantalo@case.edu>
8 * Original game concept by Mary Radcliffe
10 * gPlanarity is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
13 * any later version.
15 * gPlanarity is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with Postfish; see the file COPYING. If not, write to the
22 * Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include <glib.h>
28 #include <glib-object.h>
29 #include <gtk/gtk.h>
30 #include <gdk/gdk.h>
31 #include <time.h>
33 #include "nls.h"
35 #define V_RADIUS 8
36 #define V_LINE 2
37 #define V_LINE_COLOR 0, 0, 0
38 #define V_FILL_IDLE_COLOR .2,.2, 1
39 #define V_FILL_LIT_COLOR 1, 1, 1
40 #define V_FILL_ADJ_COLOR 1,.2,.2
42 #define E_LINE 1.5
43 #define E_LINE_F_COLOR 0, 0, 0, 1
44 #define E_LINE_B_COLOR .5,.5,.5, 1
45 #define SELECTBOX_COLOR .2,.8,.8,.3
47 #define INTERSECTION_COLOR 1,.1,.1,.8
48 #define INTERSECTION_RADIUS 10
49 #define INTERSECTION_LINE_WIDTH 2
51 #define RESET_DELTA 2
52 #define SCALE_DELTA 8
54 #define B_LINE 1
55 #define B_BORDER 6.5
56 #define B_RADIUS 20
57 #define B_HUMP 130
58 #define B_COLOR .1,.1,.7,.1
59 #define B_LINE_COLOR 0, 0,.7,.3
60 #define TEXT_COLOR .0,.0,.7,.6
61 #define HIGH_COLOR .7,.0,.0,.6
63 #define SCOREHEIGHT 50
65 #define ICON_WIDTH 160
66 #define ICON_HEIGHT 120
68 #define FADE_FRAMES 50
69 #define FADE_ANIM_INTERVAL 100
71 G_BEGIN_DECLS
73 #define GAMEBOARD_TYPE (gameboard_get_type ())
74 #define GAMEBOARD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMEBOARD_TYPE, Gameboard))
75 #define GAMEBOARD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMEBOARD_TYPE, GameboardClass))
76 #define IS_GAMEBOARD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMEBOARD_TYPE))
77 #define IS_GAMEBOARD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMEBOARD_TYPE))
79 typedef struct _Gameboard Gameboard;
80 typedef struct _GameboardClass GameboardClass;
82 typedef struct fade_list{
83 vertex *v;
84 struct fade_list *next;
85 } fade_list;
87 typedef struct {
88 fade_list *head;
89 int count;
90 gint fade_timer;
91 } fade_state;
93 #define NUMBUTTONS 11
95 typedef struct {
96 int position; // 0 inactive
97 // 1 left
98 // 2 center
99 // 3 right
100 // negative indicates active but undeployed
101 int x_target;
102 int x;
104 int y_target;
105 int y_inactive;
106 int y_active;
107 int y;
108 int sweepdeploy;
110 int alphad;
111 double alpha;
113 cairo_surface_t *idle;
114 cairo_surface_t *lit;
116 char *rollovertext;
117 cairo_text_extents_t ex;
119 int rollover;
120 int press;
122 void (*callback)();
123 } buttonstate;
125 typedef struct {
126 buttonstate states[NUMBUTTONS];
127 int buttons_ready;
128 int allclear; // short-circuit hint
129 int sweeper;
130 int sweeperd;
131 buttonstate *grabbed;
132 } buttongroup;
134 typedef struct {
135 int num;
136 double alpha;
137 cairo_surface_t *icon;
139 int x;
140 int y;
141 int w;
142 int h;
144 } dialog_level_oneicon;
146 typedef struct {
148 dialog_level_oneicon level_icons[5];
149 int center_x;
150 int center_done;
151 int level_lit;
152 int reset_deployed;
154 GdkRectangle text1;
155 GdkRectangle text2;
156 GdkRectangle text3;
157 GdkRectangle text4;
159 gint icon_timer; // used for buttons and icons
160 } dialog_level_state;
162 struct _Gameboard{
163 GtkWidget w;
165 graph g;
167 int pushed_curtain;
168 void (*redraw_callback)(Gameboard *g);
170 cairo_surface_t *vertex;
171 cairo_surface_t *vertex_lit;
172 cairo_surface_t *vertex_grabbed;
173 cairo_surface_t *vertex_attached;
174 cairo_surface_t *vertex_sel;
175 cairo_surface_t *vertex_ghost;
176 cairo_surface_t *forescore;
177 cairo_surface_t *forebutton;
178 cairo_surface_t *background;
179 cairo_surface_t *foreground;
180 cairo_pattern_t *curtainp;
181 cairo_surface_t *curtains;
183 int delayed_background;
184 int first_expose;
185 int hide_lines;
186 int realtime_background;
187 int show_intersections;
188 int finish_dialog_active;
189 int about_dialog_active;
190 int pause_dialog_active;
191 int level_dialog_active;
193 buttongroup b;
194 dialog_level_state d;
195 fade_state fade;
197 vertex *grabbed_vertex;
198 vertex *lit_vertex;
199 int group_drag;
200 int button_grabbed;
202 int grabx;
203 int graby;
204 int dragx;
205 int dragy;
206 int graboffx;
207 int graboffy;
209 int selection_grab;
210 int selection_active;
211 int selectionx;
212 int selectiony;
213 int selectionw;
214 int selectionh;
216 int checkbutton_deployed;
217 int buttonbar_sweeper;
219 gint button_timer; // used for buttons and icons
220 void (*button_callback)(Gameboard *);
222 time_t resize_timeout; // watch for ignored resize events
223 int resize_w; // watch for ignored resize events
224 int resize_h; // watch for ignored resize events
227 struct _GameboardClass{
228 GtkWidgetClass parent_class;
229 void (* gameboard) (Gameboard *m);
232 GType gameboard_get_type (void);
233 Gameboard* gameboard_new (void);
235 G_END_DECLS
237 extern void init_buttons(Gameboard *g);
238 extern buttonstate *find_button(Gameboard *g,int x,int y);
239 extern void button_set_state(Gameboard *g, buttonstate *b, int rollover, int press);
240 extern void rollover_extents(Gameboard *g, buttonstate *b);
241 extern gboolean animate_button_frame(gpointer ptr);
242 extern void expose_buttons(Gameboard *g,cairo_t *c, int x,int y,int w,int h);
243 extern void resize_buttons(Gameboard *g,int oldw,int oldh,int w,int h);
244 extern void button_clear_state(Gameboard *g);
246 extern void update_push(Gameboard *g, cairo_t *c);
247 extern void push_curtain(Gameboard *g,void(*redraw_callback)(Gameboard *g));
248 extern void pop_curtain(Gameboard *g);
250 extern void prepare_reenter_game(Gameboard *g);
251 extern void reenter_game(Gameboard *g);
252 extern void enter_game(Gameboard *g);
253 extern void quit_action(Gameboard *g);
254 extern void finish_action(Gameboard *g);
255 extern void expand_action(Gameboard *g);
256 extern void shrink_action(Gameboard *g);
257 extern void pause_action(Gameboard *g);
258 extern void about_action(Gameboard *g);
259 extern void level_action(Gameboard *g);
260 extern void set_hide_lines(Gameboard *g, int state);
261 extern void toggle_hide_lines(Gameboard *g);
262 extern void set_show_intersections(Gameboard *g, int state);
263 extern void toggle_show_intersections(Gameboard *g);
264 extern void reset_action(Gameboard *g);
265 extern int gameboard_write(char *basename, Gameboard *g);
266 extern int gameboard_read(char *basename, Gameboard *g);
268 extern void topbox (Gameboard *g,cairo_t *c, double w, double h);
269 extern void bottombox (Gameboard *g,cairo_t *c, double w, double h);
270 extern void centerbox (cairo_t *c, int x, int y, double w, double h);
271 extern void borderbox_path (cairo_t *c, double x, double y, double w, double h);
273 extern void setup_buttonbar(Gameboard *g);
274 extern void deploy_buttonbar(Gameboard *g);
275 extern void deploy_check(Gameboard *g);
276 extern void undeploy_check(Gameboard *g);
278 extern void update_draw(Gameboard *g);
279 extern void update_full(Gameboard *g);
280 extern void expose_full(Gameboard *g);
281 extern void update_full_delayed(Gameboard *g);
282 extern void update_add_vertex(Gameboard *g, vertex *v);
283 extern void update_add_selgroup(Gameboard *g);
284 extern void gameboard_draw(Gameboard *g, int x, int y, int w, int h);
285 extern void draw_foreground(Gameboard *g,cairo_t *c,
286 int x,int y,int width,int height);
287 extern void draw_intersections(Gameboard *b,graph *g,cairo_t *c,
288 int x,int y,int w,int h);
290 extern void draw_score(Gameboard *g);
291 extern void update_score(Gameboard *g);
293 extern void draw_vertex(cairo_t *c,vertex *v,cairo_surface_t *s);
294 extern void draw_vertex_with_alpha(cairo_t *c,vertex *v,cairo_surface_t *s,float alpha);
295 extern cairo_surface_t *cache_vertex(Gameboard *g);
296 extern cairo_surface_t *cache_vertex_sel(Gameboard *g);
297 extern cairo_surface_t *cache_vertex_grabbed(Gameboard *g);
298 extern cairo_surface_t *cache_vertex_lit(Gameboard *g);
299 extern cairo_surface_t *cache_vertex_attached(Gameboard *g);
300 extern cairo_surface_t *cache_vertex_ghost(Gameboard *g);
301 extern void invalidate_vertex_off(GtkWidget *widget, vertex *v, int dx, int dy);
302 extern void invalidate_vertex(Gameboard *g, vertex *v);
303 extern void invalidate_attached(GtkWidget *widget, vertex *v);
304 extern void invalidate_edges(GtkWidget *widget, vertex *v, int offx, int offy);
305 extern void draw_selection_rectangle(Gameboard *g,cairo_t *c);
306 extern void invalidate_selection(GtkWidget *widget);
307 extern void invalidate_verticies_selection(GtkWidget *widget);
309 extern void cache_curtain(Gameboard *g);
310 extern void draw_curtain(Gameboard *g);
311 extern void draw_buttonbar_box (Gameboard *g);
313 extern gint mouse_motion(GtkWidget *widget,GdkEventMotion *event);
314 extern gboolean mouse_press (GtkWidget *widget,GdkEventButton *event);
315 extern gboolean mouse_release (GtkWidget *widget,GdkEventButton *event);
317 extern void setup_background_edge(cairo_t *c);
318 extern void setup_foreground_edge(cairo_t *c);
319 extern void draw_edge(cairo_t *c,edge *e);
320 extern void draw_edges(cairo_t *c, vertex *v, int offx, int offy);
321 extern void finish_edge(cairo_t *c);
323 extern cairo_surface_t *gameboard_read_icon(char *filename, char *ext,Gameboard *b);
324 extern int gameboard_write_icon(char *filename, char *ext,Gameboard *b, graph *g,
325 int lines, int intersections);
326 extern int gameboard_icon_exists(char *filename, char *ext);
328 extern void deploy_buttons(Gameboard *g, void (*callback)(Gameboard *));
329 extern void undeploy_buttons(Gameboard *g, void (*callback)(Gameboard *));
331 extern GdkRectangle render_text_centered(cairo_t *c, char *s, int x, int y);
332 extern GdkRectangle render_border_centered(cairo_t *c, char *s, int x, int y);
333 extern GdkRectangle render_bordertext_centered(cairo_t *c, char *s, int x, int y);
335 extern void gameboard_size_allocate (GtkWidget *widget,
336 GtkAllocation *allocation);
338 extern void fade_cancel(Gameboard *g);
339 extern void fade_attached(Gameboard *g,vertex *v);
340 extern void fade_grabbed(Gameboard *g);
341 extern void fade_marked(Gameboard *g);