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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
|
/*
*
* 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.
*
*
*/
#include <math.h>
#include <string.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include "graph.h"
#include "timer.h"
#include "gameboard.h"
#include "gameboard_draw_button.h"
#include "dialog_pause.h"
#include "main.h"
static void unpause_post (Gameboard *g){
// back to buttonbar activity!
pop_curtain(g);
deploy_buttonbar(g);
unpause_timer();
g->about_dialog_active=0;
g->pause_dialog_active=0;
}
static void unpause_quit (Gameboard *g){
gtk_main_quit();
}
static void local_unpause (Gameboard *g){
undeploy_buttons(g,unpause_post);
}
static void local_quit (Gameboard *g){
undeploy_buttons(g,unpause_quit);
}
/* initialize the rather weird little animation engine */
static void setup_pause_buttons(Gameboard *g,int bw, int bh){
int i;
int w=g->g.width;
int h=g->g.height;
buttonstate *states=g->b.states;
states[0].rollovertext=_("exit gPlanarity");
states[10].rollovertext=_("resume game!");
states[0].callback = local_quit;
states[10].callback = local_unpause;
for(i=0;i<NUMBUTTONS;i++)
states[i].position=0;
states[0].position = 2; //center;
states[10].position = 2; //center;
{
buttonstate *b=states;
b->x = b->x_target = w/2 - bw/2 + PAUSE_BUTTON_BORDER;
b->y_active = h/2 + bh/2 - PAUSE_BUTTON_Y;
b->y = b->y_target = b->y_inactive = b->y_active + BUTTON_EXPOSE;
b->sweepdeploy = 0;
}
{
buttonstate *b=states+10;
b->x = b->x_target = w/2 + bw/2 - PAUSE_BUTTON_BORDER;
b->y_active = h/2 + bh/2 - PAUSE_BUTTON_Y;
b->y = b->y_target = b->y_inactive = b->y_active + BUTTON_EXPOSE;
b->sweepdeploy = SWEEP_DELTA;
}
for(i=0;i<NUMBUTTONS;i++)
if(states[i].position)
rollover_extents(g,states+i);
}
static void draw_pausebox(Gameboard *g){
int w= g->g.width;
int h= g->g.height;
cairo_t *c = cairo_create(g->background);
borderbox_path(c,
w/2 - PAUSEBOX_WIDTH/2,
h/2 - PAUSEBOX_HEIGHT/2,
PAUSEBOX_WIDTH,
PAUSEBOX_HEIGHT);
cairo_set_source_rgb(c,1,1,1);
cairo_fill(c);
centerbox(c,
w/2 - PAUSEBOX_WIDTH/2,
h/2 - PAUSEBOX_HEIGHT/2,
PAUSEBOX_WIDTH,
SCOREHEIGHT);
centerbox(c,
w/2 - PAUSEBOX_WIDTH/2 ,
h/2 + PAUSEBOX_HEIGHT/2 - SCOREHEIGHT,
PAUSEBOX_WIDTH,
SCOREHEIGHT);
{
char *time = get_timer_string();
set_font(c,18,18,0,1);
cairo_set_source_rgba (c, TEXT_COLOR);
render_text_centered(c,_("Game Paused"), w/2,h/2-PAUSEBOX_HEIGHT/2+SCOREHEIGHT/2);
set_font(c,18,18,0,0);
render_bordertext_centered(c,_("Time Elapsed:"), w/2,h/2-30);
render_bordertext_centered(c,time, w/2,h/2);
}
cairo_destroy(c);
}
void pause_dialog(Gameboard *g){
g->pause_dialog_active=1;
// set up new buttons
setup_pause_buttons(g,PAUSEBOX_WIDTH, PAUSEBOX_HEIGHT);
// draw pausebox
push_curtain(g,draw_pausebox);
// deploy new buttons
deploy_buttons(g,0);
}
// the 'about' box is nearly identical, including the fact it pauses the game.
// we just piggyback it here
static void draw_aboutbox(Gameboard *g){
int w= g->g.width;
int h= g->g.height;
cairo_t *c = cairo_create(g->background);
borderbox_path(c,
w/2 - ABOUTBOX_WIDTH/2,
h/2 - ABOUTBOX_HEIGHT/2,
ABOUTBOX_WIDTH,
ABOUTBOX_HEIGHT);
cairo_set_source_rgb(c,1,1,1);
cairo_fill(c);
centerbox(c,
w/2 - ABOUTBOX_WIDTH/2,
h/2 - ABOUTBOX_HEIGHT/2,
ABOUTBOX_WIDTH,
SCOREHEIGHT);
centerbox(c,
w/2 - ABOUTBOX_WIDTH/2 ,
h/2 + ABOUTBOX_HEIGHT/2 - SCOREHEIGHT,
ABOUTBOX_WIDTH,
SCOREHEIGHT);
{
int y = h/2-ABOUTBOX_HEIGHT/2+SCOREHEIGHT/2;
set_font(c,18,18,0,1);
cairo_set_source_rgba (c, TEXT_COLOR);
render_text_centered(c,_("gPlanarity"), w/2,y);
set_font(c,18,18,0,0);
y+=45;
render_bordertext_centered(c,_("Untangle the mess!"), w/2,y);
y+=30;
set_font(c,13,13,0,0);
render_bordertext_centered(c,_("Drag vertices to eliminate crossed lines."), w/2,y); y+=16;
render_bordertext_centered(c,_("The objective may be a complete solution or"), w/2,y); y+=16;
render_bordertext_centered(c,_("getting as close as possible to solving an"), w/2,y); y+=16;
render_bordertext_centered(c,_("unsolvable puzzle. Work quickly and"), w/2,y); y+=16;
render_bordertext_centered(c,_("exceed the objective for bonus points!"), w/2,y); y+=16;
y+=16;
cairo_move_to (c, w/2-100,y);
cairo_line_to (c, w/2+100,y);
cairo_stroke(c);
y+=32;
set_font(c,12,13,0,0);
render_bordertext_centered(c,_("gPlanarity written by Monty <monty@xiph.org>"),w/2,y);y+=17;
render_bordertext_centered(c,_("as a demonstration of Gtk+/Cairo"),w/2,y);y+=32;
render_bordertext_centered(c,_("Original Flash version of Planarity by"),w/2,y);y+=17;
render_bordertext_centered(c,_("John Tantalo <john.tantalo@case.edu>"),w/2,y);y+=32;
render_bordertext_centered(c,_("Original game concept by Mary Radcliffe"),w/2,y);y+=17;
y = h/2+ABOUTBOX_HEIGHT/2-SCOREHEIGHT/2;
set_font(c,10,11,0,1);
render_text_centered(c,version, w/2,y);
}
cairo_destroy(c);
}
void about_dialog(Gameboard *g){
g->about_dialog_active=1;
// set up new buttons
setup_pause_buttons(g,ABOUTBOX_WIDTH,ABOUTBOX_HEIGHT);
// draw about box
push_curtain(g,draw_aboutbox);
// deploy new buttons
deploy_buttons(g,0);
}
|