File: gameboard_logic_buttonbar.c

package info (click to toggle)
gplanarity 17906-7
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 732 kB
  • sloc: ansic: 8,776; makefile: 131; perl: 17; sed: 2
file content (178 lines) | stat: -rw-r--r-- 5,345 bytes parent folder | download | duplicates (5)
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
/*
 *
 *  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 "nls.h"
#include "graph.h"
#include "timer.h"
#include "gameboard.h"
#include "gameboard_draw_button.h"
#include "gameboard_logic_buttonbar.h"
#include "dialog_finish.h"
#include "dialog_pause.h"
#include "dialog_level.h"

/************************ the lower button bar *********************/

/* initialize the rather weird little animation engine */
void setup_buttonbar(Gameboard *g){
  
  buttonstate *states=g->b.states;
  int xcount=BUTTONBAR_BORDER;
  int dcount=0;
  int i;
  int w=g->g.width;
  int h=g->g.height;

  states[0].rollovertext=_("exit gPlanarity");
  states[1].rollovertext=_("level selection menu");
  states[2].rollovertext=_("reset board");
  states[3].rollovertext=_("pause");
  states[4].rollovertext=_("help / about");
  states[5].rollovertext=_("expand");
  states[6].rollovertext=_("shrink");
  states[7].rollovertext=_("hide/show lines");
  states[8].rollovertext=_("mark intersections");
  states[9].rollovertext=_("click when finished!");

  states[0].callback = quit_action;
  states[1].callback = level_action;
  states[2].callback = reset_action;
  states[3].callback = pause_action;
  states[4].callback = about_action;
  states[5].callback = expand_action;
  states[6].callback = shrink_action;
  states[7].callback = toggle_hide_lines;
  states[8].callback = toggle_show_intersections;
  states[9].callback = finish_action;

  for(i=0;i<NUMBUTTONS;i++)
    states[i].position=0;

  states[0].position = 1; //left;
  states[1].position = 1; //left;
  states[2].position = 1; //left;
  states[3].position = 1; //left;
  states[4].position = 1; //left;
  states[5].position = 3; //right
  states[6].position = 3; //right
  states[7].position = 3; //right
  states[8].position = 3; //right
  states[9].position = 3; //right

  for(i=0;i<NUMBUTTONS;i++){
    buttonstate *b=states+i;
    if(b->position == 1){

      b->x = b->x_target = xcount;
      b->y_active = h - BUTTONBAR_Y_FROM_BOTTOM;
      b->y = b->y_target = b->y_inactive = h - BUTTONBAR_Y_FROM_BOTTOM + BUTTON_EXPOSE;
      b->sweepdeploy = dcount;
      xcount += BUTTONBAR_SPACING;
      dcount += SWEEP_DELTA;
      rollover_extents(g,states+i);
    }
  }
  
  xcount = w-BUTTONBAR_BORDER;
  dcount = 0;
  for(i=NUMBUTTONS-1;i>=0;i--){
    buttonstate *b=states+i;
    if(b->position == 3){

      b->x = b->x_target = xcount;
      b->y_active = h - BUTTONBAR_Y_FROM_BOTTOM;
      b->y = b->y_target = b->y_inactive = h - BUTTONBAR_Y_FROM_BOTTOM + BUTTON_EXPOSE;
      b->sweepdeploy = dcount;
      
      if(i!=9 || g->checkbutton_deployed){ // special-case the checkbutton
	xcount -= BUTTONBAR_SPACING;
	dcount += SWEEP_DELTA;
      }else{
	states[9].position = -3; //deactivate it for the deploy
      }
      rollover_extents(g,states+i);
    }
  }
}

/* effects animated 'rollout' of buttons when level begins */
void deploy_buttonbar(Gameboard *g){
  if(!g->b.buttons_ready ){
    if(g->g.active_intersections <= g->g.objective)
      g->checkbutton_deployed=1;
    else
      g->checkbutton_deployed=0;
    setup_buttonbar(g);
    deploy_buttons(g,0);
  }
  
}

/* effects animated rollout of 'check' button */
void deploy_check(Gameboard *g){
  buttonstate *states=g->b.states;
  if(g->b.buttons_ready && !g->checkbutton_deployed){
    int i;
    for(i=5;i<9;i++){
      states[i].x_target-=BUTTONBAR_SPACING;
      states[i].sweepdeploy += SWEEP_DELTA;
    }

    states[9].position = 3; //activate it
    states[9].y_target = states[9].y_active;
    states[i].sweepdeploy = 0;

    if(g->button_timer!=0)
      g_source_remove(g->button_timer);
    g->button_callback=0;
    g->button_timer = g_timeout_add(BUTTON_ANIM_INTERVAL, animate_button_frame, (gpointer)g);
    g->checkbutton_deployed=1;
  }
}

/* effects animated rollback of 'check' button */
void undeploy_check(Gameboard *g){
  buttonstate *states=g->b.states;
  if(g->checkbutton_deployed){
    int i;
    for(i=5;i<9;i++){
      states[i].x_target+=BUTTONBAR_SPACING;
      states[i].sweepdeploy -= SWEEP_DELTA;
    }
    states[9].y_target=states[9].y_inactive;

    if(g->button_timer!=0)
      g_source_remove(g->button_timer);
    g->button_callback=0;
    g->button_timer = g_timeout_add(BUTTON_ANIM_INTERVAL, animate_button_frame, (gpointer)g);
    g->checkbutton_deployed=0;
  }
}