~ubuntu-branches/ubuntu/precise/pingus/precise

« back to all changes in this revision

Viewing changes to src/ActionButton.cc

  • Committer: Bazaar Package Importer
  • Author(s): Raphael Goulais
  • Date: 2004-08-09 10:26:00 UTC
  • mfrom: (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040809102600-lg2q9lfars0q1p42
Tags: 0.6.0-8
Applied patch from Andreas Jochens (Closes: #263992)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//  $Id: ActionButton.cc,v 1.27 2002/01/15 22:32:05 grumbel Exp $
2
 
//
3
 
//  Pingus - A free Lemmings clone
4
 
//  Copyright (C) 1999 Ingo Ruhnke <grumbel@gmx.de>
5
 
//
6
 
//  This program is free software; you can redistribute it and/or
7
 
//  modify it under the terms of the GNU General Public License
8
 
//  as published by the Free Software Foundation; either version 2
9
 
//  of the License, or (at your option) any later version.
10
 
// 
11
 
//  This program is distributed in the hope that it will be useful,
12
 
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
//  GNU General Public License for more details.
15
 
//
16
 
//  You should have received a copy of the GNU General Public License
17
 
//  along with this program; if not, write to the Free Software
18
 
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
 
 
20
 
#include <cstdio>
21
 
 
22
 
#include "algo.hh"
23
 
#include "globals.hh"
24
 
#include "PingusResource.hh"
25
 
#include "ActionButton.hh"
26
 
 
27
 
Button::Button()
28
 
{
29
 
}
30
 
 
31
 
Button::~Button()
32
 
{
33
 
}
34
 
 
35
 
EventButton::EventButton(int x, int y, std::string str)
36
 
{
37
 
  surface = PingusResource::load_surface(str, "global");
38
 
  x_pos = x;
39
 
  y_pos = y;
40
 
}
41
 
 
42
 
EventButton::~EventButton() {}
43
 
 
44
 
void
45
 
EventButton::draw()
46
 
{
47
 
  if (mouse_over(CL_Vector() /* FIXME */))
48
 
    {
49
 
      CL_Display::fill_rect(x_pos, y_pos, 
50
 
                            x_pos + surface.get_width(), y_pos + surface.get_height(),
51
 
                            1.0, 1.0, 1.0, 1.0);
52
 
    }
53
 
  surface.put_screen(x_pos, y_pos);
54
 
}
55
 
 
56
 
bool
57
 
EventButton::mouse_over(const CL_Vector& pos)
58
 
{
59
 
  if (pos.x > x_pos && pos.x < x_pos + int(surface.get_width())
60
 
      && pos.y > y_pos && pos.y < y_pos + int(surface.get_height()))
61
 
    {
62
 
      return true;
63
 
    }
64
 
  else 
65
 
    {
66
 
      return false;
67
 
    }
68
 
}
69
 
 
70
 
ActionButton::ActionButton() {}
71
 
ActionButton::~ActionButton() {}
72
 
 
73
 
void
74
 
ActionButton::init(int x, int y, std::string str, int owner_id)
75
 
{
76
 
  //  make_action = func;
77
 
  x_pos = x;
78
 
  y_pos = y;
79
 
  name = str;
80
 
 
81
 
  if (name == "digger" || name == "bomber" 
82
 
      || name == "floater" || name == "blocker")
83
 
    {
84
 
      is_multi_direct = false;
85
 
    }
86
 
  else
87
 
    {
88
 
      is_multi_direct = true;
89
 
    }
90
 
 
91
 
  /*
92
 
  font = PingusResource::load_font("Fonts/courier_small", "fonts");
93
 
  font_h = PingusResource::load_font("Fonts/smallfont","fonts");
94
 
  font_b = PingusResource::load_font("Fonts/pingus","fonts");
95
 
  */
96
 
 
97
 
  font = PingusResource::load_font("Fonts/pingus_small", "fonts");
98
 
  font_h = PingusResource::load_font("Fonts/pingus_small","fonts");
99
 
  font_b = PingusResource::load_font("Fonts/pingus","fonts");
100
 
 
101
 
  if (str != "empty") 
102
 
    {
103
 
      surface   = PingusResource::load_surface("Pingus/" + str + to_string(owner_id),
104
 
                                               "pingus");
105
 
      if (is_multi_direct)
106
 
        {
107
 
          action_c.set_size(surface.get_num_frames()/2);
108
 
        }
109
 
      else
110
 
        {
111
 
          action_c.set_size(surface.get_num_frames());
112
 
        }
113
 
 
114
 
      action_c.set_speed(50);
115
 
    }
116
 
}
117
 
 
118
 
bool
119
 
ActionButton::is_pressed()
120
 
{
121
 
  return false;
122
 
}
123
 
 
124
 
void
125
 
ActionButton::update(float delta)
126
 
{
127
 
  ++action_c;
128
 
}
129
 
 
130
 
std::string
131
 
ActionButton::get_action_name()
132
 
{
133
 
  return name;
134
 
}
135
 
 
136
 
void
137
 
ActionButton::set_action_holder(ActionHolder* h)
138
 
{
139
 
  action_holder = h;
140
 
}
141
 
 
142
 
VerticalActionButton::VerticalActionButton(int x, int y, std::string str, int owner_id)
143
 
  : background (PingusResource::load_surface("buttons/buttonbackground", "core")),
144
 
    backgroundhl (PingusResource::load_surface("buttons/buttonbackgroundhl", "core"))
145
 
{
146
 
  init(x, y, str, owner_id);
147
 
}
148
 
 
149
 
VerticalActionButton::~VerticalActionButton() {}
150
 
 
151
 
bool
152
 
VerticalActionButton::mouse_over(const CL_Vector& pos)
153
 
{
154
 
  if (pos.x > x_pos && pos.x < x_pos + 60
155
 
      && pos.y > y_pos && pos.y <= y_pos + 35) 
156
 
    {
157
 
      return true;
158
 
    } 
159
 
  else 
160
 
    {
161
 
      return false;
162
 
    }
163
 
}
164
 
 
165
 
void
166
 
VerticalActionButton::draw()
167
 
{
168
 
  std::string str;
169
 
  // FIXME: This could need some optimization, throwing strings all
170
 
  // FIXME: around, doesn't look like a good idea. 
171
 
  available = action_holder->get_available(name);
172
 
 
173
 
  if (unlimited_actions) {
174
 
    str = "oo";
175
 
  } else {
176
 
    str = to_string(available);
177
 
  }
178
 
 
179
 
  if (pressed) 
180
 
    {
181
 
      if (fast_mode) {
182
 
        CL_Display::fill_rect(x_pos, y_pos, x_pos + 60, y_pos + 35 ,
183
 
                              1.0, 1.0, 1.0, 1.0);
184
 
      } else {
185
 
        //CL_Display::fill_rect(x_pos, y_pos, x_pos + 60, y_pos + 35 ,
186
 
        //1.0, 1.0, 1.0, 0.5);
187
 
        backgroundhl.put_screen (x_pos, y_pos);
188
 
      }
189
 
      font_h->print_center(x_pos + 46, y_pos + 10, str.c_str ());
190
 
    }
191
 
  else
192
 
    {
193
 
      action_c = 0;
194
 
 
195
 
      if (fast_mode) {
196
 
        // do nothing
197
 
      } else {
198
 
        background.put_screen (x_pos, y_pos);
199
 
      }
200
 
      font->print_center(x_pos + 46, y_pos + 10, str.c_str ());
201
 
    }
202
 
 
203
 
  // print the action name next to the button, when mouse pointer is on
204
 
  // the button.
205
 
  if(action_help 
206
 
     && CL_Mouse::get_x() > x_pos && CL_Mouse::get_x() < x_pos + 60
207
 
     && CL_Mouse::get_y() < y_pos + 35 && CL_Mouse::get_y() > y_pos) 
208
 
  {
209
 
        font_b->print_left (x_pos + 65, y_pos, name.c_str());
210
 
  }
211
 
 
212
 
  surface.put_screen(x_pos + 20 - surface.get_width ()/2,
213
 
                     y_pos + 17 - surface.get_height ()/2,
214
 
                     action_c);
215
 
}
216
 
 
217
 
ArmageddonButton::ArmageddonButton(int x, int y)
218
 
{
219
 
  surface = PingusResource::load_surface("buttons/armageddon_anim", "core");
220
 
 
221
 
  background = PingusResource::load_surface("buttons/hbuttonbgb", "core");
222
 
  backgroundhl = PingusResource::load_surface("buttons/hbuttonbg", "core");
223
 
 
224
 
  counter.set_size(surface.get_num_frames());
225
 
  counter = 0;
226
 
  x_pos = x;
227
 
  y_pos = y;
228
 
  pressed = false;
229
 
}
230
 
 
231
 
ArmageddonButton::~ArmageddonButton() {}
232
 
 
233
 
void
234
 
ArmageddonButton::draw()
235
 
{
236
 
  if (pressed)
237
 
    {
238
 
      backgroundhl.put_screen (x_pos, y_pos);
239
 
      surface.put_screen(x_pos, y_pos, ++counter);
240
 
    } 
241
 
  else 
242
 
    {
243
 
      background.put_screen (x_pos, y_pos);
244
 
      surface.put_screen(x_pos, y_pos, 7);
245
 
    }
246
 
}
247
 
 
248
 
bool
249
 
ArmageddonButton::mouse_over(const CL_Vector& pos)
250
 
{
251
 
  if (pos.x > x_pos && pos.x < x_pos + int(surface.get_width())
252
 
      && pos.y > y_pos && pos.y < y_pos + int(surface.get_height()))
253
 
    {
254
 
      return true;
255
 
    } else  {
256
 
      return false;
257
 
    } 
258
 
}
259
 
 
260
 
ForwardButton::ForwardButton(int x, int y)
261
 
{
262
 
  surface = PingusResource::load_surface("buttons/fast_forward", "core");
263
 
  background = PingusResource::load_surface("buttons/hbuttonbgb", "core");
264
 
  backgroundhl = PingusResource::load_surface("buttons/hbuttonbg", "core");
265
 
 
266
 
  x_pos = x;
267
 
  y_pos = y;
268
 
}
269
 
 
270
 
ForwardButton::~ForwardButton() {}
271
 
 
272
 
void
273
 
ForwardButton::draw()
274
 
{
275
 
  if (server->get_fast_forward())
276
 
    backgroundhl.put_screen (x_pos, y_pos);
277
 
  else
278
 
    background.put_screen (x_pos, y_pos);
279
 
  
280
 
  surface.put_screen(x_pos, y_pos);
281
 
}
282
 
 
283
 
bool
284
 
ForwardButton::mouse_over(const CL_Vector& pos)
285
 
{
286
 
  if (pos.x > x_pos && pos.x < x_pos + int(surface.get_width())
287
 
      && pos.y > y_pos && pos.y < y_pos + int(surface.get_height()))
288
 
    {
289
 
      return true;
290
 
    } else  {
291
 
      return false;
292
 
    } 
293
 
}
294
 
 
295
 
PauseButton::PauseButton(int x, int y)
296
 
{
297
 
  surface = PingusResource::load_surface("buttons/pause", "core");
298
 
 
299
 
  background = PingusResource::load_surface("buttons/hbuttonbgb", "core");
300
 
  backgroundhl = PingusResource::load_surface("buttons/hbuttonbg", "core");
301
 
 
302
 
  x_pos = x;
303
 
  y_pos = y;
304
 
}
305
 
 
306
 
PauseButton::~PauseButton() {}
307
 
 
308
 
void
309
 
PauseButton::draw()
310
 
{
311
 
  if (server->get_pause()) 
312
 
    backgroundhl.put_screen (x_pos, y_pos);
313
 
  else
314
 
    background.put_screen (x_pos, y_pos);
315
 
  
316
 
  surface.put_screen(x_pos, y_pos);
317
 
}
318
 
 
319
 
bool
320
 
PauseButton::mouse_over(const CL_Vector& pos)
321
 
{
322
 
  if (pos.x > x_pos && pos.x < x_pos + int(surface.get_width())
323
 
      && pos.y > y_pos && pos.y < y_pos + int(surface.get_height()))
324
 
    {
325
 
      return true;
326
 
    } else  {
327
 
      return false;
328
 
    } 
329
 
}
330
 
 
331
 
/* EOF */