Skip to content

Commit

Permalink
GUI2/Menu Button: allow changing selections with the scrollwheel (closes
Browse files Browse the repository at this point in the history
 #3251)'

The changelog entry is under 1.14.3+dev since this is going to be backported.
  • Loading branch information
Vultraz committed Jun 16, 2018
1 parent d523362 commit 880152e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 7 deletions.
1 change: 1 addition & 0 deletions changelog.md
Expand Up @@ -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.
Expand Down
49 changes: 42 additions & 7 deletions src/gui/widgets/menu_button.cpp
Expand Up @@ -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));
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_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)
Expand Down Expand Up @@ -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());
Expand Down
4 changes: 4 additions & 0 deletions src/gui/widgets/menu_button.hpp
Expand Up @@ -129,6 +129,10 @@ class menu_button : public styled_widget, public selectable_item
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 ---------{
Expand Down

0 comments on commit 880152e

Please sign in to comment.