242 |
//---------------------------------------- |
//---------------------------------------- |
243 |
// Button implementation |
// Button implementation |
244 |
//---------------------------------------- |
//---------------------------------------- |
245 |
|
Button::Button() |
246 |
|
: m_activep (false) |
247 |
|
{} |
248 |
|
|
249 |
|
void |
250 |
|
Button::activate() |
251 |
|
{ |
252 |
|
sound::PlaySound("menuswitch"); |
253 |
|
m_activep = true; |
254 |
|
redraw(); |
255 |
|
} |
256 |
|
|
257 |
|
void |
258 |
|
Button::deactivate() |
259 |
|
{ |
260 |
|
m_activep = false; |
261 |
|
redraw(); |
262 |
|
} |
263 |
|
|
264 |
void |
void |
265 |
Button::draw(px::GC &gc, const px::Rect &r) |
Button::draw(px::GC &gc, const px::Rect &r) |
266 |
{ |
{ |
267 |
const int borderw = 4; |
const int borderw = 4; |
268 |
|
|
269 |
px::Surface *s = enigma::GetImage (highlighted ? "buttonhl" : "button"); |
px::Surface *s = enigma::GetImage (m_activep ? "buttonhl" : "button"); |
270 |
|
|
271 |
if (s) { // Ugly, but hey, it works |
if (s) { // Ugly, but hey, it works |
272 |
set_color (gc, 0,0,0); |
set_color (gc, 0,0,0); |
333 |
//---------------------------------------- |
//---------------------------------------- |
334 |
|
|
335 |
PushButton::PushButton() |
PushButton::PushButton() |
336 |
: pressed(false) |
: m_pressedp (false) |
337 |
{} |
{} |
338 |
|
|
339 |
bool |
bool |
340 |
PushButton::on_event(const SDL_Event &e) |
PushButton::on_event(const SDL_Event &e) |
341 |
{ |
{ |
342 |
bool was_pressed = pressed; |
bool was_pressed = m_pressedp; |
343 |
|
|
344 |
switch (e.type) { |
switch (e.type) { |
345 |
case SDL_KEYDOWN: |
case SDL_KEYDOWN: |
346 |
if (e.key.keysym.sym != SDLK_RETURN && |
if (e.key.keysym.sym != SDLK_RETURN && |
347 |
e.key.keysym.sym != SDLK_SPACE) break; |
e.key.keysym.sym != SDLK_SPACE) break; |
348 |
// fall-through |
// fall-through |
349 |
case SDL_MOUSEBUTTONDOWN: |
case SDL_MOUSEBUTTONDOWN: |
350 |
pressed = true; |
m_pressedp = true; |
351 |
break; |
break; |
352 |
|
|
353 |
case SDL_KEYUP: |
case SDL_KEYUP: |
354 |
if (e.key.keysym.sym != SDLK_RETURN && |
if (e.key.keysym.sym != SDLK_RETURN && |
355 |
e.key.keysym.sym != SDLK_SPACE) break; |
e.key.keysym.sym != SDLK_SPACE) break; |
356 |
// fall-through |
// fall-through |
357 |
case SDL_MOUSEBUTTONUP: |
case SDL_MOUSEBUTTONUP: |
358 |
pressed = false; |
m_pressedp = false; |
359 |
break; |
break; |
360 |
} |
} |
361 |
|
|
362 |
bool changed = (was_pressed != pressed); |
bool changed = (was_pressed != m_pressedp); |
363 |
if (changed) { |
if (changed) { |
364 |
redraw(); |
redraw(); |
365 |
if (!pressed) { |
if (!m_pressedp) { |
366 |
sound::PlaySound("menuok"); |
sound::PlaySound("menuok"); |
367 |
invoke_listener(); |
invoke_listener(); |
368 |
} |
} |
374 |
void |
void |
375 |
PushButton::deactivate() |
PushButton::deactivate() |
376 |
{ |
{ |
377 |
pressed=false; |
m_pressedp = false; |
378 |
redraw(); |
redraw(); |
379 |
Button::deactivate(); |
Button::deactivate(); |
380 |
} |
} |
580 |
} |
} |
581 |
|
|
582 |
void |
void |
583 |
Menu::switch_active_widget(Widget *to_activate) { |
Menu::switch_active_widget(Widget *to_activate) |
584 |
|
{ |
585 |
if (to_activate != active_widget) { |
if (to_activate != active_widget) { |
586 |
if (active_widget) |
if (active_widget) |
587 |
active_widget->deactivate(); |
active_widget->deactivate(); |
588 |
|
|
589 |
if (to_activate) { |
if (to_activate) { |
|
sound::PlaySound("menuswitch"); |
|
590 |
to_activate->activate(); |
to_activate->activate(); |
591 |
} |
} |
592 |
|
|