GUI2/Menu Button: allow changing selections with the scrollwheel (closes #3251)'

The changelog entry is under 1.14.3+dev since this is going to be backported.
This commit is contained in:
Charles Dang 2018-06-16 13:43:42 +11:00
parent d5233620e4
commit 880152e9f0
3 changed files with 48 additions and 8 deletions

View file

@ -4,6 +4,7 @@
* Fixed missing prisoners and loss of recallable units in 'Captured'.
### User interface
* Improved the layout of the Statistics dialog.
* Allow changing dropdown menu selections with the scrollwheel (FR #3251).
### Graphics
* Tweaked the Ruffian's attack animation timing.
* New attack animation for the Peasant.

View file

@ -48,16 +48,27 @@ menu_button::menu_button(const implementation::builder_menu_button& builder)
values_.emplace_back(::config {"label", this->get_label()});
connect_signal<event::MOUSE_ENTER>(
std::bind(&menu_button::signal_handler_mouse_enter, this, _2, _3));
connect_signal<event::MOUSE_LEAVE>(
std::bind(&menu_button::signal_handler_mouse_leave, this, _2, _3));
std::bind(&menu_button::signal_handler_mouse_enter, this, _2, _3));
connect_signal<event::MOUSE_LEAVE>(
std::bind(&menu_button::signal_handler_mouse_leave, this, _2, _3));
connect_signal<event::LEFT_BUTTON_DOWN>(
std::bind(&menu_button::signal_handler_left_button_down, this, _2, _3));
connect_signal<event::LEFT_BUTTON_DOWN>(std::bind(
&menu_button::signal_handler_left_button_down, this, _2, _3));
connect_signal<event::LEFT_BUTTON_UP>(
std::bind(&menu_button::signal_handler_left_button_up, this, _2, _3));
connect_signal<event::LEFT_BUTTON_CLICK>(std::bind(
&menu_button::signal_handler_left_button_click, this, _2, _3));
std::bind(&menu_button::signal_handler_left_button_up, this, _2, _3));
connect_signal<event::LEFT_BUTTON_CLICK>(
std::bind(&menu_button::signal_handler_left_button_click, this, _2, _3));
connect_signal<event::SDL_WHEEL_UP>(
std::bind(&menu_button::signal_handler_sdl_wheel_up, this, _2, _3),
event::dispatcher::back_post_child);
connect_signal<event::SDL_WHEEL_DOWN>(
std::bind(&menu_button::signal_handler_sdl_wheel_down, this, _2, _3),
event::dispatcher::back_post_child);
}
void menu_button::set_active(const bool active)
@ -148,6 +159,30 @@ void menu_button::signal_handler_left_button_click(const event::ui_event event,
handled = true;
}
void menu_button::signal_handler_sdl_wheel_up(const event::ui_event event, bool& handled)
{
DBG_GUI_E << LOG_HEADER << ' ' << event << ".\n";
// TODO: should values wrap?
if(selected_ > 0) {
set_selected(selected_ - 1);
}
handled = true;
}
void menu_button::signal_handler_sdl_wheel_down(const event::ui_event event, bool& handled)
{
DBG_GUI_E << LOG_HEADER << ' ' << event << ".\n";
// TODO: should values wrap?
if(selected_ < values_.size() - 1) {
set_selected(selected_ + 1);
}
handled = true;
}
void menu_button::set_values(const std::vector<::config>& values, int selected)
{
assert(static_cast<size_t>(selected) < values.size());

View file

@ -129,6 +129,10 @@ private:
void signal_handler_left_button_up(const event::ui_event event, bool& handled);
void signal_handler_left_button_click(const event::ui_event event, bool& handled);
void signal_handler_sdl_wheel_up(const event::ui_event event, bool& handled);
void signal_handler_sdl_wheel_down(const event::ui_event event, bool& handled);
};
// }---------- DEFINITION ---------{