Added keyboard handlers for the slider.

The arrow keys can now be used in the slider (patch #1639).
This commit is contained in:
Mark de Wever 2010-04-27 19:46:45 +00:00
parent d67503e1c3
commit b868499ccd
4 changed files with 88 additions and 9 deletions

View file

@ -51,6 +51,7 @@ Version 1.9.0-svn:
* Added a new attack dialog, available for testing with --new-widgets
* Patch #1645: Fixed a bug sending keyboard events to deactivated controls
* Deprecated the resize flag for gui2 image, use the resize_mode instead
* Patch #1639: Added handlers for keyboard (arrow keys) to move gui2 sliders
* WML Engine:
* Deprecated [set_variable]'s random key, use rand instead
* Renamed [unit][status] healable to unhealable so it can default to 'no'

View file

@ -962,6 +962,11 @@
[entry]
name = "Miguel Zapico (elricz)"
[/entry]
[entry]
name = "Nathan Partlan (Greywhind)"
email = "greywhind_AT_users.sourceforge.net"
wikiuser = "Greywhind"
[/entry]
[entry]
name = "Pablo J. Urbano Santos (Lord Ork)"
wikiuser = "Lord Ork"

View file

@ -21,6 +21,7 @@
#include "gui/auxiliary/log.hpp"
#include "gui/auxiliary/widget_definition/slider.hpp"
#include "gui/auxiliary/window_builder/slider.hpp"
#include "gui/widgets/window.hpp"
#include "gui/widgets/settings.hpp"
#include "sound.hpp"
@ -44,6 +45,21 @@ static int distance(const int a, const int b)
return result;
}
tslider::tslider():
tscrollbar_(),
best_slider_length_(0),
minimum_value_(0),
minimum_value_label_(),
maximum_value_label_(),
value_labels_()
{
connect_signal<event::SDL_KEY_DOWN>(boost::bind(
&tslider::signal_handler_sdl_key_down, this, _2, _3, _5, _6, _7));
connect_signal<event::LEFT_BUTTON_UP>(boost::bind(
&tslider::signal_handler_left_button_up, this, _2, _3));
}
tpoint tslider::calculate_best_size() const
{
log_scope2(log_gui_layout, LOG_SCOPE_HEADER);
@ -226,5 +242,51 @@ const std::string& tslider::get_control_type() const
return type;
}
void tslider::handle_key_decrease(bool& handled)
{
DBG_GUI_E << LOG_HEADER << '\n';
handled = true;
scroll(tscrollbar_::ITEM_BACKWARDS);
}
void tslider::handle_key_increase(bool& handled)
{
DBG_GUI_E << LOG_HEADER << '\n';
handled = true;
scroll(tscrollbar_::ITEM_FORWARD);
}
void tslider::signal_handler_sdl_key_down(const event::tevent event
, bool& handled
, const SDLKey key
, SDLMod modifier
, const Uint16 unicode)
{
DBG_GUI_E << LOG_HEADER << ' ' << event << ".\n";
if (key == SDLK_DOWN || key == SDLK_LEFT) {
handle_key_decrease(handled);
} else if (key == SDLK_UP || key == SDLK_RIGHT) {
handle_key_increase(handled);
} else {
// Do nothing. Ignore other keys.
}
}
void tslider::signal_handler_left_button_up(
const event::tevent event, bool& handled)
{
DBG_GUI_E << LOG_HEADER << ' ' << event << ".\n";
get_window()->keyboard_capture(this);
handled = true;
}
} // namespace gui2

View file

@ -25,15 +25,7 @@ class tslider : public tscrollbar_, public tinteger_selector_
{
public:
tslider() :
tscrollbar_(),
best_slider_length_(0),
minimum_value_(0),
minimum_value_label_(),
maximum_value_label_(),
value_labels_()
{
}
tslider();
/***** ***** ***** ***** layout functions ***** ***** ***** *****/
@ -87,6 +79,7 @@ public:
* the result of get_value().
*/
t_string get_value_label() const;
protected:
/** Inherited from tscrollbar. */
@ -155,6 +148,24 @@ private:
/** Inherited from tcontrol. */
const std::string& get_control_type() const;
/**
* Handlers for keyboard input
*/
void handle_key_decrease(bool& handled);
void handle_key_increase(bool& handled);
/**
* Signal handlers:
*/
void signal_handler_sdl_key_down(const event::tevent event
, bool& handled
, const SDLKey key);
// In this subclass, only used to grab keyboard focus -
// see tscrollbar class for more handling of this event.
void signal_handler_left_button_up(
const event::tevent event, bool& handled);
};
} // namespace gui2