4 * The geeky little puzzle game with a big noodly crunch!
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)
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.
29 #include <gtk/gtkmain.h>
37 #include "gameboard.h"
39 /* draw/cache vertex surfaces; direct surface copies are faster than
40 always redrawing lots of circles */
42 void draw_vertex(cairo_t
*c
,vertex
*v
,cairo_surface_t
*s
){
43 cairo_set_source_surface(c
,
46 v
->y
-V_LINE
-V_RADIUS
);
50 void draw_vertex_with_alpha(cairo_t
*c
,vertex
*v
,cairo_surface_t
*s
,float alpha
){
51 cairo_set_source_surface(c
,
54 v
->y
-V_LINE
-V_RADIUS
);
55 cairo_paint_with_alpha(c
,alpha
);
58 // normal unlit vertex
59 cairo_surface_t
*cache_vertex(Gameboard
*g
){
60 cairo_t
*wc
= gdk_cairo_create(g
->w
.window
);
62 cairo_surface_create_similar (cairo_get_target (wc
),
63 CAIRO_CONTENT_COLOR_ALPHA
,
66 cairo_t
*c
= cairo_create(ret
);
69 cairo_set_line_width(c
,V_LINE
);
70 cairo_arc(c
,V_RADIUS
+V_LINE
,V_RADIUS
+V_LINE
,V_RADIUS
,0,2*M_PI
);
71 cairo_set_source_rgb(c
,V_FILL_IDLE_COLOR
);
72 cairo_fill_preserve(c
);
73 cairo_set_source_rgb(c
,V_LINE_COLOR
);
81 cairo_surface_t
*cache_vertex_sel(Gameboard
*g
){
82 cairo_t
*wc
= gdk_cairo_create(g
->w
.window
);
84 cairo_surface_create_similar (cairo_get_target (wc
),
85 CAIRO_CONTENT_COLOR_ALPHA
,
88 cairo_t
*c
= cairo_create(ret
);
91 cairo_set_line_width(c
,V_LINE
);
92 cairo_arc(c
,V_RADIUS
+V_LINE
,V_RADIUS
+V_LINE
,V_RADIUS
,0,2*M_PI
);
93 cairo_set_source_rgb(c
,V_FILL_LIT_COLOR
);
94 cairo_fill_preserve(c
);
95 cairo_set_source_rgb(c
,V_LINE_COLOR
);
97 cairo_arc(c
,V_RADIUS
+V_LINE
,V_RADIUS
+V_LINE
,V_RADIUS
*.5,0,2*M_PI
);
98 cairo_set_source_rgb(c
,V_FILL_IDLE_COLOR
);
106 cairo_surface_t
*cache_vertex_grabbed(Gameboard
*g
){
107 cairo_t
*wc
= gdk_cairo_create(g
->w
.window
);
108 cairo_surface_t
*ret
=
109 cairo_surface_create_similar (cairo_get_target (wc
),
110 CAIRO_CONTENT_COLOR_ALPHA
,
112 (V_RADIUS
+V_LINE
)*2);
113 cairo_t
*c
= cairo_create(ret
);
116 cairo_set_line_width(c
,V_LINE
);
117 cairo_arc(c
,V_RADIUS
+V_LINE
,V_RADIUS
+V_LINE
,V_RADIUS
,0,2*M_PI
);
118 cairo_set_source_rgb(c
,V_FILL_LIT_COLOR
);
119 cairo_fill_preserve(c
);
120 cairo_set_source_rgb(c
,V_LINE_COLOR
);
122 cairo_arc(c
,V_RADIUS
+V_LINE
,V_RADIUS
+V_LINE
,V_RADIUS
*.5,0,2*M_PI
);
123 cairo_set_source_rgb(c
,V_FILL_ADJ_COLOR
);
130 // vertex under mouse rollover
131 cairo_surface_t
*cache_vertex_lit(Gameboard
*g
){
132 cairo_t
*wc
= gdk_cairo_create(g
->w
.window
);
133 cairo_surface_t
*ret
=
134 cairo_surface_create_similar (cairo_get_target (wc
),
135 CAIRO_CONTENT_COLOR_ALPHA
,
137 (V_RADIUS
+V_LINE
)*2);
138 cairo_t
*c
= cairo_create(ret
);
141 cairo_set_line_width(c
,V_LINE
);
142 cairo_arc(c
,V_RADIUS
+V_LINE
,V_RADIUS
+V_LINE
,V_RADIUS
,0,2*M_PI
);
143 cairo_set_source_rgb(c
,V_FILL_LIT_COLOR
);
144 cairo_fill_preserve(c
);
145 cairo_set_source_rgb(c
,V_LINE_COLOR
);
152 // verticies attached to grabbed vertex
153 cairo_surface_t
*cache_vertex_attached(Gameboard
*g
){
154 cairo_t
*wc
= gdk_cairo_create(g
->w
.window
);
155 cairo_surface_t
*ret
=
156 cairo_surface_create_similar (cairo_get_target (wc
),
157 CAIRO_CONTENT_COLOR_ALPHA
,
159 (V_RADIUS
+V_LINE
)*2);
160 cairo_t
*c
= cairo_create(ret
);
163 cairo_set_line_width(c
,V_LINE
);
164 cairo_arc(c
,V_RADIUS
+V_LINE
,V_RADIUS
+V_LINE
,V_RADIUS
,0,2*M_PI
);
165 cairo_set_source_rgb(c
,V_FILL_ADJ_COLOR
);
166 cairo_fill_preserve(c
);
167 cairo_set_source_rgb(c
,V_LINE_COLOR
);
174 // vertex being dragged in a group
175 cairo_surface_t
*cache_vertex_ghost(Gameboard
*g
){
176 cairo_t
*wc
= gdk_cairo_create(g
->w
.window
);
177 cairo_surface_t
*ret
=
178 cairo_surface_create_similar (cairo_get_target (wc
),
179 CAIRO_CONTENT_COLOR_ALPHA
,
181 (V_RADIUS
+V_LINE
)*2);
182 cairo_t
*c
= cairo_create(ret
);
185 cairo_set_line_width(c
,V_LINE
);
186 cairo_arc(c
,V_RADIUS
+V_LINE
,V_RADIUS
+V_LINE
,V_RADIUS
,0,2*M_PI
);
187 cairo_set_source_rgb(c
,V_FILL_LIT_COLOR
);
188 cairo_fill_preserve(c
);
189 cairo_set_source_rgb(c
,V_LINE_COLOR
);
191 cairo_arc(c
,V_RADIUS
+V_LINE
,V_RADIUS
+V_LINE
,V_RADIUS
*.5,0,2*M_PI
);
192 cairo_set_source_rgb(c
,V_FILL_ADJ_COLOR
);
200 /* region invalidation operations; do exposes efficiently! **********/
202 // invalidate the box around a single offset vertex
203 void invalidate_vertex_off(GtkWidget
*widget
,
204 vertex
*v
, int dx
, int dy
){
207 r
.x
= v
->x
- V_RADIUS
- V_LINE
+ dx
;
208 r
.y
= v
->y
- V_RADIUS
- V_LINE
+ dy
;
209 r
.width
= (V_RADIUS
+ V_LINE
)*2;
210 r
.height
= (V_RADIUS
+ V_LINE
)*2;
212 gdk_window_invalidate_rect (widget
->window
, &r
, FALSE
);
216 // invalidate the box around a single vertex
217 void invalidate_vertex(Gameboard
*g
, vertex
*v
){
218 invalidate_vertex_off(&g
->w
,v
,0,0);
221 // invalidate a vertex and any other attached verticies
222 void invalidate_attached(GtkWidget
*widget
, vertex
*v
){
224 edge_list
*el
=v
->edges
;
227 if(e
->A
!= v
)invalidate_vertex(GAMEBOARD(widget
),e
->A
);
228 if(e
->B
!= v
)invalidate_vertex(GAMEBOARD(widget
),e
->B
);
231 invalidate_vertex(GAMEBOARD(widget
),v
);