Swap code/variable declaration to be pre-C99 compliant.
[xiph/unicode.git] / planarity / gameboard_draw_edge.c
blob3951b24633096c08e240ddecdaae7594f085ad38
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 #define _GNU_SOURCE
28 #include <gtk/gtk.h>
29 #include <gtk/gtkmain.h>
30 #include <gdk/gdk.h>
31 #include <gdk/gdkx.h>
32 #include <stdlib.h>
33 #include <math.h>
34 #include <string.h>
36 #include "graph.h"
37 #include "gameboard.h"
40 /******** draw edges ********************************************/
42 void setup_background_edge(cairo_t *c){
43 cairo_set_line_width(c,E_LINE);
44 cairo_set_source_rgba(c,E_LINE_B_COLOR);
47 void setup_foreground_edge(cairo_t *c){
48 cairo_set_line_width(c,E_LINE);
49 cairo_set_source_rgba(c,E_LINE_F_COLOR);
52 void draw_edge(cairo_t *c,edge *e){
53 cairo_move_to(c,e->A->x,e->A->y);
54 cairo_line_to(c,e->B->x,e->B->y);
57 void finish_edge(cairo_t *c){
58 cairo_stroke(c);
61 void draw_edges(cairo_t *c, vertex *v, int offx, int offy){
62 if(v){
63 edge_list *el=v->edges;
64 while (el){
65 edge *e=el->edge;
67 if(e->A->grabbed==0 || e->B->grabbed==0 || v==e->A){
68 if(e->A->grabbed)
69 cairo_move_to(c,e->A->x+offx,e->A->y+offy);
70 else
71 cairo_move_to(c,e->A->x,e->A->y);
73 if(e->B->grabbed)
74 cairo_line_to(c,e->B->x+offx,e->B->y+offy);
75 else
76 cairo_line_to(c,e->B->x,e->B->y);
78 el=el->next;
83 /* invalidate edge region for efficient expose *******************/
85 void invalidate_edges(GtkWidget *widget, vertex *v, int offx, int offy){
86 GdkRectangle r;
88 if(v){
89 edge_list *el=v->edges;
90 while (el){
91 edge *e=el->edge;
93 if(e->A->grabbed==0 || e->B->grabbed==0 || v==e->A){
94 int Ax = e->A->x + (e->A->grabbed?offx:0);
95 int Ay = e->A->y + (e->A->grabbed?offy:0);
96 int Bx = e->B->x + (e->B->grabbed?offx:0);
97 int By = e->B->y + (e->B->grabbed?offy:0);
99 r.x = min(Ax,Bx) - E_LINE;
100 r.y = min(Ay,By) - E_LINE;
101 r.width = labs(Bx - Ax) + 1 + E_LINE*2;
102 r.height = labs(By - Ay) + 1 + E_LINE*2;
104 gdk_window_invalidate_rect (widget->window, &r, FALSE);
106 el=el->next;