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
|
/*
*
* 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.
*
*
*/
#define _GNU_SOURCE
#include <gtk/gtk.h>
#include <gtk/gtkmain.h>
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "graph.h"
#include "gameboard.h"
#include "main.h"
static void draw_intersection(cairo_t *c,double x, double y){
cairo_move_to(c,x-INTERSECTION_RADIUS,y);
cairo_rel_line_to(c,INTERSECTION_RADIUS,-INTERSECTION_RADIUS);
cairo_rel_line_to(c,INTERSECTION_RADIUS,INTERSECTION_RADIUS);
cairo_rel_line_to(c,-INTERSECTION_RADIUS,INTERSECTION_RADIUS);
cairo_close_path(c);
}
static void draw_many_intersection(Gameboard *g,cairo_t *c){
int x2 = g->g.width/2;
int y2 = g->g.height/2;
int r = INTERSECTION_RADIUS*10;
cairo_set_source_rgba (c, INTERSECTION_COLOR);
cairo_set_line_width(c, INTERSECTION_LINE_WIDTH*10);
cairo_move_to(c,x2-r,y2-r/4);
cairo_rel_line_to(c,r,-r);
cairo_rel_line_to(c,r,r);
cairo_rel_line_to(c,-r,r);
cairo_close_path(c);
cairo_stroke(c);
set_font(c, 30., 34., 0,1);
render_bordertext_centered(c,_("rather many, really"),x2,y2+r/4);
}
void draw_intersections(Gameboard *b, graph *g, cairo_t *c,
int x,int y,int w,int h){
double xx=x-(INTERSECTION_LINE_WIDTH*.5 + INTERSECTION_RADIUS);
double x2=w+x+(INTERSECTION_LINE_WIDTH + INTERSECTION_RADIUS*2);
double yy=y-(INTERSECTION_LINE_WIDTH*.5 + INTERSECTION_RADIUS);
double y2=h+y+(INTERSECTION_LINE_WIDTH + INTERSECTION_RADIUS*2);
if(g->active_intersections > 1000){
// don't draw them all; potential for accidental CPU sink.
draw_many_intersection(b,c);
}else{
cairo_set_source_rgba (c, INTERSECTION_COLOR);
cairo_set_line_width(c, INTERSECTION_LINE_WIDTH);
// walk the intersection list of all edges; draw if paired is a higher pointer
edge *e=g->edges;
while(e){
intersection *i = e->i.next;
while(i){
if(i->paired > i){
double ix=i->x, iy=i->y;
if(ix >= xx && ix <= x2 && iy >= yy && iy <= y2)
draw_intersection(c,ix,iy);
}
cairo_stroke(c); /* incremental stroke! It's easy to run
the path longer than the X server
allows. */
i=i->next;
}
e=e->next;
}
}
}
|