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
){
61 cairo_surface_create_similar (cairo_get_target (g
->wc
),
62 CAIRO_CONTENT_COLOR_ALPHA
,
65 cairo_t
*c
= cairo_create(ret
);
67 cairo_set_line_width(c
,V_LINE
);
68 cairo_arc(c
,V_RADIUS
+V_LINE
,V_RADIUS
+V_LINE
,V_RADIUS
,0,2*M_PI
);
69 cairo_set_source_rgb(c
,V_FILL_IDLE_COLOR
);
70 cairo_fill_preserve(c
);
71 cairo_set_source_rgb(c
,V_LINE_COLOR
);
79 cairo_surface_t
*cache_vertex_sel(Gameboard
*g
){
81 cairo_surface_create_similar (cairo_get_target (g
->wc
),
82 CAIRO_CONTENT_COLOR_ALPHA
,
85 cairo_t
*c
= cairo_create(ret
);
87 cairo_set_line_width(c
,V_LINE
);
88 cairo_arc(c
,V_RADIUS
+V_LINE
,V_RADIUS
+V_LINE
,V_RADIUS
,0,2*M_PI
);
89 cairo_set_source_rgb(c
,V_FILL_LIT_COLOR
);
90 cairo_fill_preserve(c
);
91 cairo_set_source_rgb(c
,V_LINE_COLOR
);
93 cairo_arc(c
,V_RADIUS
+V_LINE
,V_RADIUS
+V_LINE
,V_RADIUS
*.5,0,2*M_PI
);
94 cairo_set_source_rgb(c
,V_FILL_IDLE_COLOR
);
102 cairo_surface_t
*cache_vertex_grabbed(Gameboard
*g
){
103 cairo_surface_t
*ret
=
104 cairo_surface_create_similar (cairo_get_target (g
->wc
),
105 CAIRO_CONTENT_COLOR_ALPHA
,
107 (V_RADIUS
+V_LINE
)*2);
108 cairo_t
*c
= cairo_create(ret
);
110 cairo_set_line_width(c
,V_LINE
);
111 cairo_arc(c
,V_RADIUS
+V_LINE
,V_RADIUS
+V_LINE
,V_RADIUS
,0,2*M_PI
);
112 cairo_set_source_rgb(c
,V_FILL_LIT_COLOR
);
113 cairo_fill_preserve(c
);
114 cairo_set_source_rgb(c
,V_LINE_COLOR
);
116 cairo_arc(c
,V_RADIUS
+V_LINE
,V_RADIUS
+V_LINE
,V_RADIUS
*.5,0,2*M_PI
);
117 cairo_set_source_rgb(c
,V_FILL_ADJ_COLOR
);
124 // vertex under mouse rollover
125 cairo_surface_t
*cache_vertex_lit(Gameboard
*g
){
126 cairo_surface_t
*ret
=
127 cairo_surface_create_similar (cairo_get_target (g
->wc
),
128 CAIRO_CONTENT_COLOR_ALPHA
,
130 (V_RADIUS
+V_LINE
)*2);
131 cairo_t
*c
= cairo_create(ret
);
133 cairo_set_line_width(c
,V_LINE
);
134 cairo_arc(c
,V_RADIUS
+V_LINE
,V_RADIUS
+V_LINE
,V_RADIUS
,0,2*M_PI
);
135 cairo_set_source_rgb(c
,V_FILL_LIT_COLOR
);
136 cairo_fill_preserve(c
);
137 cairo_set_source_rgb(c
,V_LINE_COLOR
);
144 // verticies attached to grabbed vertex
145 cairo_surface_t
*cache_vertex_attached(Gameboard
*g
){
146 cairo_surface_t
*ret
=
147 cairo_surface_create_similar (cairo_get_target (g
->wc
),
148 CAIRO_CONTENT_COLOR_ALPHA
,
150 (V_RADIUS
+V_LINE
)*2);
151 cairo_t
*c
= cairo_create(ret
);
153 cairo_set_line_width(c
,V_LINE
);
154 cairo_arc(c
,V_RADIUS
+V_LINE
,V_RADIUS
+V_LINE
,V_RADIUS
,0,2*M_PI
);
155 cairo_set_source_rgb(c
,V_FILL_ADJ_COLOR
);
156 cairo_fill_preserve(c
);
157 cairo_set_source_rgb(c
,V_LINE_COLOR
);
164 // vertex being dragged in a group
165 cairo_surface_t
*cache_vertex_ghost(Gameboard
*g
){
166 cairo_surface_t
*ret
=
167 cairo_surface_create_similar (cairo_get_target (g
->wc
),
168 CAIRO_CONTENT_COLOR_ALPHA
,
170 (V_RADIUS
+V_LINE
)*2);
171 cairo_t
*c
= cairo_create(ret
);
173 cairo_set_line_width(c
,V_LINE
);
174 cairo_arc(c
,V_RADIUS
+V_LINE
,V_RADIUS
+V_LINE
,V_RADIUS
,0,2*M_PI
);
175 cairo_set_source_rgb(c
,V_FILL_LIT_COLOR
);
176 cairo_fill_preserve(c
);
177 cairo_set_source_rgb(c
,V_LINE_COLOR
);
179 cairo_arc(c
,V_RADIUS
+V_LINE
,V_RADIUS
+V_LINE
,V_RADIUS
*.5,0,2*M_PI
);
180 cairo_set_source_rgb(c
,V_FILL_ADJ_COLOR
);
188 /* region invalidation operations; do exposes efficiently! **********/
190 // invalidate the box around a single offset vertex
191 void invalidate_vertex_off(GtkWidget
*widget
,
192 vertex
*v
, int dx
, int dy
){
195 r
.x
= v
->x
- V_RADIUS
- V_LINE
+ dx
;
196 r
.y
= v
->y
- V_RADIUS
- V_LINE
+ dy
;
197 r
.width
= (V_RADIUS
+ V_LINE
)*2;
198 r
.height
= (V_RADIUS
+ V_LINE
)*2;
200 gdk_window_invalidate_rect (widget
->window
, &r
, FALSE
);
204 // invalidate the box around a single vertex
205 void invalidate_vertex(Gameboard
*g
, vertex
*v
){
206 invalidate_vertex_off(&g
->w
,v
,0,0);
209 // invalidate a vertex and any other attached verticies
210 void invalidate_attached(GtkWidget
*widget
, vertex
*v
){
212 edge_list
*el
=v
->edges
;
215 if(e
->A
!= v
)invalidate_vertex(GAMEBOARD(widget
),e
->A
);
216 if(e
->B
!= v
)invalidate_vertex(GAMEBOARD(widget
),e
->B
);
219 invalidate_vertex(GAMEBOARD(widget
),v
);