From a33414a79f3bc3f59019d9917ac2bcf2587c2185 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Tue, 22 Mar 2016 08:22:56 -0400 Subject: [PATCH 01/13] Correct doc reference to nonexistent function is_keyboard_scroll_active no longer exists, scrolling_ seems to be the equivalent. --- src/controller_base.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controller_base.hpp b/src/controller_base.hpp index 87df5cfe8a0..93dea82a36b 100644 --- a/src/controller_base.hpp +++ b/src/controller_base.hpp @@ -102,7 +102,7 @@ protected: /** * Handle scrolling by keyboard, joystick and moving mouse near map edges - * @see is_keyboard_scroll_active + * @see scrolling_, which is set if the display is being scrolled * @return true when there was any scrolling, false otherwise */ bool handle_scroll(CKey& key, int mousex, int mousey, int mouse_flags, double joystickx, double joysticky); From fa756088735d67395fc7dbe04f89890172bcecf6 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Thu, 24 Mar 2016 22:46:05 -0400 Subject: [PATCH 02/13] Implement hotkey release handling. Hotkeys are now triggered by a key/button release as well as a press. This information is passed along as HOTKEY_EVENT_TYPE, which may be HOTKEY_EVENT_PRESS, HOTKEY_EVENT_RELEASE, or HOTKEY_EVENT_REPEAT (for a held key repeat). Currently this should preserve the previous functionality. Existing hotkeys respond to a press or repeat as they did before and ignore a release. --- src/controller_base.cpp | 5 +++-- src/hotkey/command_executor.cpp | 24 ++++++++++++++++++++---- src/hotkey/command_executor.hpp | 4 ++-- src/hotkey/hotkey_command.hpp | 2 ++ src/hotkey/hotkey_handler.cpp | 4 ++-- src/hotkey/hotkey_handler.hpp | 2 +- 6 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/controller_base.cpp b/src/controller_base.cpp index ffe7ec5fb2f..9dbd829cc0c 100644 --- a/src/controller_base.cpp +++ b/src/controller_base.cpp @@ -61,13 +61,14 @@ void controller_base::handle_event(const SDL_Event& event) process_keydown_event(event); hotkey::key_event(event, get_hotkey_command_executor()); + process_keyup_event(event); } else { process_focus_keydown_event(event); - break; } - // intentionally fall-through + break; case SDL_KEYUP: process_keyup_event(event); + hotkey::key_event(event, get_hotkey_command_executor()); break; case SDL_JOYBUTTONDOWN: process_keydown_event(event); diff --git a/src/hotkey/command_executor.cpp b/src/hotkey/command_executor.cpp index 7d708ae6af6..baf9ebf69a4 100644 --- a/src/hotkey/command_executor.cpp +++ b/src/hotkey/command_executor.cpp @@ -72,8 +72,11 @@ namespace hotkey { static void event_execute(const SDL_Event& event, command_executor* executor); -bool command_executor::execute_command(const hotkey_command& cmd, int /*index*/) +bool command_executor::execute_command(const hotkey_command& cmd, int /*index*/, HOTKEY_EVENT_TYPE type) { + if (type == HOTKEY_EVENT_RELEASE) + return false; // nothing responds to a release yet + switch(cmd.id) { case HOTKEY_CYCLE_UNITS: cycle_units(); @@ -460,6 +463,7 @@ void basic_handler::handle_event(const SDL_Event& event) switch (event.type) { case SDL_KEYDOWN: + case SDL_KEYUP: // If we're in a dialog we only want to handle items that are explicitly // handled by the executor. // If we're not in a dialog we can call the regular key event handler. @@ -470,6 +474,7 @@ void basic_handler::handle_event(const SDL_Event& event) } break; case SDL_JOYBUTTONDOWN: + case SDL_JOYBUTTONUP: if (!gui::in_dialog()) { jbutton_event(event,exec_); } else if (exec_ != nullptr) { @@ -477,6 +482,7 @@ void basic_handler::handle_event(const SDL_Event& event) } break; case SDL_MOUSEBUTTONDOWN: + case SDL_MOUSEBUTTONUP: if (!gui::in_dialog()) { mbutton_event(event,exec_); } else if (exec_ != nullptr) { @@ -515,18 +521,28 @@ static void event_execute( const SDL_Event& event, command_executor* executor) return; } - execute_command(hotkey::get_hotkey_command(hk->get_command()), executor); + HOTKEY_EVENT_TYPE type = HOTKEY_EVENT_PRESS; + if (event.type == SDL_KEYUP || event.type == SDL_JOYBUTTONUP || event.type == SDL_MOUSEBUTTONUP) + type = HOTKEY_EVENT_RELEASE; + else if (event.type == SDL_KEYDOWN && event.key.repeat > 0) + type = HOTKEY_EVENT_REPEAT; + + execute_command(hotkey::get_hotkey_command(hk->get_command()), executor, -1, type); executor->set_button_state(); } -void execute_command(const hotkey_command& command, command_executor* executor, int index) +void execute_command(const hotkey_command& command, command_executor* executor, int index, HOTKEY_EVENT_TYPE type) { if (executor != nullptr) { if (!executor->can_execute_command(command, index) - || executor->execute_command(command, index)) { + || executor->execute_command(command, index, type)) { return; } } + + if (type == HOTKEY_EVENT_RELEASE) + return; // none of the commands here respond to a key release + switch (command.id) { case HOTKEY_MINIMAP_DRAW_TERRAIN: diff --git a/src/hotkey/command_executor.hpp b/src/hotkey/command_executor.hpp index 87257a5f2d3..6b0b1a229d4 100644 --- a/src/hotkey/command_executor.hpp +++ b/src/hotkey/command_executor.hpp @@ -132,7 +132,7 @@ public: void execute_action(const std::vector& items_arg, int xloc, int yloc, bool context_menu, display& gui); virtual bool can_execute_command(const hotkey_command& command, int index=-1) const = 0; - virtual bool execute_command(const hotkey_command& command, int index=-1); + virtual bool execute_command(const hotkey_command& command, int index=-1, HOTKEY_EVENT_TYPE type = HOTKEY_EVENT_PRESS); }; class command_executor_default : public command_executor { @@ -162,7 +162,7 @@ void mbutton_event(const SDL_Event& event, command_executor* executor); //TODO -void execute_command(const hotkey_command& command, command_executor* executor, int index=-1); +void execute_command(const hotkey_command& command, command_executor* executor, int index=-1, HOTKEY_EVENT_TYPE type = HOTKEY_EVENT_PRESS); // Object which will ensure that basic keyboard events like escape // are handled properly for the duration of its lifetime. diff --git a/src/hotkey/hotkey_command.hpp b/src/hotkey/hotkey_command.hpp index 485a651eb74..4df7c857e2f 100644 --- a/src/hotkey/hotkey_command.hpp +++ b/src/hotkey/hotkey_command.hpp @@ -35,6 +35,8 @@ enum scope { SCOPE_COUNT, }; +enum HOTKEY_EVENT_TYPE { HOTKEY_EVENT_PRESS, HOTKEY_EVENT_RELEASE, HOTKEY_EVENT_REPEAT }; + enum HOTKEY_COMMAND { HOTKEY_CYCLE_UNITS, HOTKEY_CYCLE_BACK_UNITS, HOTKEY_UNIT_HOLD_POSITION, diff --git a/src/hotkey/hotkey_handler.cpp b/src/hotkey/hotkey_handler.cpp index 573fc80d173..71a0b381c2c 100644 --- a/src/hotkey/hotkey_handler.cpp +++ b/src/hotkey/hotkey_handler.cpp @@ -218,7 +218,7 @@ void play_controller::hotkey_handler::toggle_accelerated_speed() } } -bool play_controller::hotkey_handler::execute_command(const hotkey::hotkey_command& cmd, int index) +bool play_controller::hotkey_handler::execute_command(const hotkey::hotkey_command& cmd, int index, hotkey::HOTKEY_EVENT_TYPE type) { hotkey::HOTKEY_COMMAND command = cmd.id; if(index >= 0) { @@ -245,7 +245,7 @@ bool play_controller::hotkey_handler::execute_command(const hotkey::hotkey_comma gamestate().get_wml_menu_items().fire_item(name, hex, gamestate().gamedata_, gamestate(), gamestate().board_.units_); /// @todo Shouldn't the function return at this point? } - return command_executor::execute_command(cmd, index); + return command_executor::execute_command(cmd, index, type); } bool play_controller::hotkey_handler::can_execute_command(const hotkey::hotkey_command& cmd, int index) const diff --git a/src/hotkey/hotkey_handler.hpp b/src/hotkey/hotkey_handler.hpp index 2f6ffb114cc..93662594c8e 100644 --- a/src/hotkey/hotkey_handler.hpp +++ b/src/hotkey/hotkey_handler.hpp @@ -125,7 +125,7 @@ public: virtual hotkey::ACTION_STATE get_action_state(hotkey::HOTKEY_COMMAND command, int index) const; /** Check if a command can be executed. */ virtual bool can_execute_command(const hotkey::hotkey_command& command, int index=-1) const; - virtual bool execute_command(const hotkey::hotkey_command& command, int index=-1); + virtual bool execute_command(const hotkey::hotkey_command& command, int index=-1, hotkey::HOTKEY_EVENT_TYPE type = hotkey::HOTKEY_EVENT_PRESS); void show_menu(const std::vector& items_arg, int xloc, int yloc, bool context_menu, display& disp); /** From 0a05828da38658a31d29be9d6196480a1cd95e96 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Thu, 24 Mar 2016 22:49:46 -0400 Subject: [PATCH 03/13] Implement map scrolling with hotkeys. This leverages the new hotkey release support to implement scrolling with hotkeys rather than keyboard polling. This allows users to rebind the scroll keys in the hotkey menu. Previously they were fixed to the arrow keys. --- src/controller_base.cpp | 52 +++++++++++++++++++-------------- src/controller_base.hpp | 6 +++- src/hotkey/command_executor.cpp | 42 ++++++++++++++++++++++++-- src/hotkey/command_executor.hpp | 1 + src/hotkey/hotkey_command.cpp | 4 +++ src/hotkey/hotkey_command.hpp | 3 ++ src/hotkey/hotkey_handler.cpp | 9 ++++++ src/hotkey/hotkey_handler.hpp | 1 + 8 files changed, 93 insertions(+), 25 deletions(-) diff --git a/src/controller_base.cpp b/src/controller_base.cpp index 9dbd829cc0c..b320a3a2187 100644 --- a/src/controller_base.cpp +++ b/src/controller_base.cpp @@ -34,6 +34,8 @@ controller_base::controller_base( : game_config_(game_config) , key_() , scrolling_(false) + , scrollx_(0) + , scrolly_(0) , joystick_manager_() { } @@ -129,11 +131,10 @@ void controller_base::process_keyup_event(const SDL_Event& /*event*/) { //no action by default } -bool controller_base::handle_scroll(CKey& key, int mousex, int mousey, int mouse_flags, double x_axis, double y_axis) +bool controller_base::handle_scroll(int mousex, int mousey, int mouse_flags, double x_axis, double y_axis) { bool mouse_in_window = (SDL_GetAppState() & SDL_APPMOUSEFOCUS) != 0 || preferences::get("scroll_when_mouse_outside", true); - bool keyboard_focus = have_keyboard_focus(); int scroll_speed = preferences::scroll_speed(); int dx = 0, dy = 0; int scroll_threshold = (preferences::mouse_scroll_enabled()) @@ -143,26 +144,24 @@ bool controller_base::handle_scroll(CKey& key, int mousex, int mousey, int mouse scroll_threshold = 0; } } - if ((key[SDLK_UP] && keyboard_focus) || - (mousey < scroll_threshold && mouse_in_window)) - { - dy -= scroll_speed; - } - if ((key[SDLK_DOWN] && keyboard_focus) || - (mousey > get_display().h() - scroll_threshold && mouse_in_window)) - { - dy += scroll_speed; - } - if ((key[SDLK_LEFT] && keyboard_focus) || - (mousex < scroll_threshold && mouse_in_window)) - { - dx -= scroll_speed; - } - if ((key[SDLK_RIGHT] && keyboard_focus) || - (mousex > get_display().w() - scroll_threshold && mouse_in_window)) - { - dx += scroll_speed; + + // scroll with keyboard + dx += scrollx_ * scroll_speed; + dy += scrolly_ * scroll_speed; + + // scroll if mouse is placed near the edge of the screen + if (mouse_in_window) { + if (mousey < scroll_threshold) + dy -= scroll_speed; + if (mousey > get_display().h() - scroll_threshold) + dy += scroll_speed; + if (mousex < scroll_threshold) + dx -= scroll_speed; + if (mousex > get_display().w() - scroll_threshold) + dx += scroll_speed; } + + // scroll with middle-mouse if enabled if ((mouse_flags & SDL_BUTTON_MMASK) != 0 && preferences::middle_click_scrolls()) { const map_location original_loc = get_mouse_handler_base().get_scroll_start(); @@ -186,6 +185,7 @@ bool controller_base::handle_scroll(CKey& key, int mousex, int mousey, int mouse } } + // scroll with joystick dx += round_double( x_axis * scroll_speed); dy += round_double( y_axis * scroll_speed); @@ -239,7 +239,7 @@ void controller_base::play_slice(bool is_delay_enabled) mousey += values.second * 10; SDL_WarpMouse(mousex, mousey); */ - scrolling_ = handle_scroll(key, mousex, mousey, mouse_flags, joystickx, joysticky); + scrolling_ = handle_scroll(mousex, mousey, mouse_flags, joystickx, joysticky); map_location highlighted_hex = get_display().mouseover_hex(); @@ -342,3 +342,11 @@ const config& controller_base::get_theme(const config& game_config, std::string static config empty; return empty; } + +void controller_base::keyboard_scroll(int x, int y) +{ + if (have_keyboard_focus()) { + scrollx_ += x; + scrolly_ += y; + } +} diff --git a/src/controller_base.hpp b/src/controller_base.hpp index 93dea82a36b..2329d9fc144 100644 --- a/src/controller_base.hpp +++ b/src/controller_base.hpp @@ -64,6 +64,8 @@ public: void play_slice(bool is_delay_enabled = true); static const config &get_theme(const config& game_config, std::string theme_name); + + void keyboard_scroll(int x, int y); protected: virtual bool is_browsing() const { return false; } @@ -105,7 +107,7 @@ protected: * @see scrolling_, which is set if the display is being scrolled * @return true when there was any scrolling, false otherwise */ - bool handle_scroll(CKey& key, int mousex, int mousey, int mouse_flags, double joystickx, double joysticky); + bool handle_scroll(int mousex, int mousey, int mouse_flags, double joystickx, double joysticky); /** * Process mouse- and keypress-events from SDL. @@ -141,6 +143,8 @@ protected: const config& game_config_; CKey key_; bool scrolling_; + int scrollx_; + int scrolly_; joystick_manager joystick_manager_; }; diff --git a/src/hotkey/command_executor.cpp b/src/hotkey/command_executor.cpp index baf9ebf69a4..d548de95abb 100644 --- a/src/hotkey/command_executor.cpp +++ b/src/hotkey/command_executor.cpp @@ -74,9 +74,47 @@ static void event_execute(const SDL_Event& event, command_executor* executor); bool command_executor::execute_command(const hotkey_command& cmd, int /*index*/, HOTKEY_EVENT_TYPE type) { - if (type == HOTKEY_EVENT_RELEASE) - return false; // nothing responds to a release yet + if (type == HOTKEY_EVENT_RELEASE) { + switch(cmd.id) { + // release a scroll key, un-apply scrolling in the given direction + case HOTKEY_SCROLL_UP: + keyboard_scroll(0, 1); + break; + case HOTKEY_SCROLL_DOWN: + keyboard_scroll(0, -1); + break; + case HOTKEY_SCROLL_LEFT: + keyboard_scroll(1, 0); + break; + case HOTKEY_SCROLL_RIGHT: + keyboard_scroll(-1, 0); + break; + default: + return false; // nothing else handles a hotkey release + } + return true; + } + + // special handling for scroll keys, which do not handle repeat + if (type == HOTKEY_EVENT_PRESS) { + switch(cmd.id) { + case HOTKEY_SCROLL_UP: + keyboard_scroll(0, -1); + return true; + case HOTKEY_SCROLL_DOWN: + keyboard_scroll(0, 1); + return true; + case HOTKEY_SCROLL_LEFT: + keyboard_scroll(-1, 0); + return true; + case HOTKEY_SCROLL_RIGHT: + keyboard_scroll(1, 0); + return true; + } + } + + // everything following responds to a press or repeat, but not release switch(cmd.id) { case HOTKEY_CYCLE_UNITS: cycle_units(); diff --git a/src/hotkey/command_executor.hpp b/src/hotkey/command_executor.hpp index 6b0b1a229d4..4718f554994 100644 --- a/src/hotkey/command_executor.hpp +++ b/src/hotkey/command_executor.hpp @@ -108,6 +108,7 @@ public: virtual void left_mouse_click() {} virtual void right_mouse_click() {} virtual void toggle_accelerated_speed() {} + virtual void keyboard_scroll(int /*x*/, int /*y*/) {} virtual void lua_console(); virtual void zoom_in() {} virtual void zoom_out() {} diff --git a/src/hotkey/hotkey_command.cpp b/src/hotkey/hotkey_command.cpp index 6d1a4f23b93..0d53957698d 100644 --- a/src/hotkey/hotkey_command.cpp +++ b/src/hotkey/hotkey_command.cpp @@ -35,6 +35,10 @@ namespace { hotkey::hk_scopes scope_main(1 << hotkey::SCOPE_MAIN_MENU); // this contains all static hotkeys hotkey::hotkey_command_temp hotkey_list_[] = { + { hotkey::HOTKEY_SCROLL_UP, "scroll-up", N_("Scroll Up"), false, scope_game | scope_editor, "" }, + { hotkey::HOTKEY_SCROLL_DOWN, "scroll-down", N_("Scroll Down"), false, scope_game | scope_editor, "" }, + { hotkey::HOTKEY_SCROLL_LEFT, "scroll-left", N_("Scroll Left"), false, scope_game | scope_editor, "" }, + { hotkey::HOTKEY_SCROLL_RIGHT, "scroll-right", N_("Scroll Right"), false, scope_game | scope_editor, "" }, { hotkey::HOTKEY_CANCEL, N_("cancel"), N_("Cancel"), false, scope_game | scope_editor | scope_main, "" }, { hotkey::HOTKEY_SELECT_HEX, "selecthex", N_("Select Hex"), false, scope_game, "" }, diff --git a/src/hotkey/hotkey_command.hpp b/src/hotkey/hotkey_command.hpp index 4df7c857e2f..f68f75e74fd 100644 --- a/src/hotkey/hotkey_command.hpp +++ b/src/hotkey/hotkey_command.hpp @@ -67,6 +67,9 @@ enum HOTKEY_COMMAND { HOTKEY_SELECT_HEX, HOTKEY_DESELECT_HEX, HOTKEY_MOVE_ACTION, HOTKEY_SELECT_AND_ACTION, + // Camera movement + HOTKEY_SCROLL_UP, HOTKEY_SCROLL_DOWN, HOTKEY_SCROLL_LEFT, HOTKEY_SCROLL_RIGHT, + // Dialog control HOTKEY_CANCEL, HOTKEY_OKAY, diff --git a/src/hotkey/hotkey_handler.cpp b/src/hotkey/hotkey_handler.cpp index 71a0b381c2c..3607a1bfc99 100644 --- a/src/hotkey/hotkey_handler.cpp +++ b/src/hotkey/hotkey_handler.cpp @@ -218,6 +218,11 @@ void play_controller::hotkey_handler::toggle_accelerated_speed() } } +void play_controller::hotkey_handler::keyboard_scroll(int x, int y) +{ + play_controller_.keyboard_scroll(x, y); +} + bool play_controller::hotkey_handler::execute_command(const hotkey::hotkey_command& cmd, int index, hotkey::HOTKEY_EVENT_TYPE type) { hotkey::HOTKEY_COMMAND command = cmd.id; @@ -302,6 +307,10 @@ bool play_controller::hotkey_handler::can_execute_command(const hotkey::hotkey_c case hotkey::HOTKEY_SAVE_REPLAY: case hotkey::HOTKEY_LABEL_SETTINGS: case hotkey::LUA_CONSOLE: + case hotkey::HOTKEY_SCROLL_UP: + case hotkey::HOTKEY_SCROLL_DOWN: + case hotkey::HOTKEY_SCROLL_LEFT: + case hotkey::HOTKEY_SCROLL_RIGHT: return true; // Commands that have some preconditions: diff --git a/src/hotkey/hotkey_handler.hpp b/src/hotkey/hotkey_handler.hpp index 93662594c8e..e2e24a12d3a 100644 --- a/src/hotkey/hotkey_handler.hpp +++ b/src/hotkey/hotkey_handler.hpp @@ -117,6 +117,7 @@ public: virtual void toggle_grid(); virtual void search(); virtual void toggle_accelerated_speed(); + virtual void keyboard_scroll(int x, int y); virtual void replay_skip_animation() override { return play_controller_.toggle_skipping_replay(); } From f4d2b24a3f9346a02991728c8ba6a6f52a3d8eb0 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Fri, 25 Mar 2016 22:42:56 -0400 Subject: [PATCH 04/13] Add braces to single-line ifs. Code review feedback. --- src/controller_base.cpp | 12 ++++++++---- src/hotkey/command_executor.cpp | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/controller_base.cpp b/src/controller_base.cpp index b320a3a2187..a3f1b93bf3d 100644 --- a/src/controller_base.cpp +++ b/src/controller_base.cpp @@ -151,14 +151,18 @@ bool controller_base::handle_scroll(int mousex, int mousey, int mouse_flags, dou // scroll if mouse is placed near the edge of the screen if (mouse_in_window) { - if (mousey < scroll_threshold) + if (mousey < scroll_threshold) { dy -= scroll_speed; - if (mousey > get_display().h() - scroll_threshold) + } + if (mousey > get_display().h() - scroll_threshold) { dy += scroll_speed; - if (mousex < scroll_threshold) + } + if (mousex < scroll_threshold) { dx -= scroll_speed; - if (mousex > get_display().w() - scroll_threshold) + } + if (mousex > get_display().w() - scroll_threshold) { dx += scroll_speed; + } } // scroll with middle-mouse if enabled diff --git a/src/hotkey/command_executor.cpp b/src/hotkey/command_executor.cpp index d548de95abb..cd3bbb79589 100644 --- a/src/hotkey/command_executor.cpp +++ b/src/hotkey/command_executor.cpp @@ -578,8 +578,9 @@ void execute_command(const hotkey_command& command, command_executor* executor, } } - if (type == HOTKEY_EVENT_RELEASE) + if (type == HOTKEY_EVENT_RELEASE) { return; // none of the commands here respond to a key release + } switch (command.id) { From ae37341ab3b1a58840f4b80b05c2e4a1eb3c1a66 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Sat, 26 Mar 2016 22:53:45 -0400 Subject: [PATCH 05/13] Remove specialized hotkey repeat handling. Don't handle repeat events specially when triggering hotkeys. Replace the HOTKEY_EVENT_TYPE enum with a bool indicating whether the event was a press or a release. Scrolling handles repeats by clamping the scroll between -1 and 1 so repeat events don't accelerate the scroll speed. --- src/controller_base.cpp | 5 ++-- src/hotkey/command_executor.cpp | 53 +++++++++++++-------------------- src/hotkey/command_executor.hpp | 4 +-- src/hotkey/hotkey_command.hpp | 2 -- src/hotkey/hotkey_handler.cpp | 4 +-- src/hotkey/hotkey_handler.hpp | 2 +- 6 files changed, 28 insertions(+), 42 deletions(-) diff --git a/src/controller_base.cpp b/src/controller_base.cpp index a3f1b93bf3d..b583570abf9 100644 --- a/src/controller_base.cpp +++ b/src/controller_base.cpp @@ -350,7 +350,8 @@ const config& controller_base::get_theme(const config& game_config, std::string void controller_base::keyboard_scroll(int x, int y) { if (have_keyboard_focus()) { - scrollx_ += x; - scrolly_ += y; + // clamp between -1 and 1 so key repeats don't accelerate scrolling + scrollx_ = std::min(1, std::max(-1, scrollx_ + x)); + scrolly_ = std::min(1, std::max(-1, scrolly_ + y)); } } diff --git a/src/hotkey/command_executor.cpp b/src/hotkey/command_executor.cpp index cd3bbb79589..a6379feeb5c 100644 --- a/src/hotkey/command_executor.cpp +++ b/src/hotkey/command_executor.cpp @@ -72,9 +72,10 @@ namespace hotkey { static void event_execute(const SDL_Event& event, command_executor* executor); -bool command_executor::execute_command(const hotkey_command& cmd, int /*index*/, HOTKEY_EVENT_TYPE type) +bool command_executor::execute_command(const hotkey_command& cmd, int /*index*/, bool press) { - if (type == HOTKEY_EVENT_RELEASE) { + // hotkey release handling + if (!press) { switch(cmd.id) { // release a scroll key, un-apply scrolling in the given direction case HOTKEY_SCROLL_UP: @@ -96,30 +97,20 @@ bool command_executor::execute_command(const hotkey_command& cmd, int /*index*/ return true; } - // special handling for scroll keys, which do not handle repeat - if (type == HOTKEY_EVENT_PRESS) { - switch(cmd.id) { - case HOTKEY_SCROLL_UP: - keyboard_scroll(0, -1); - return true; - case HOTKEY_SCROLL_DOWN: - keyboard_scroll(0, 1); - return true; - case HOTKEY_SCROLL_LEFT: - keyboard_scroll(-1, 0); - return true; - case HOTKEY_SCROLL_RIGHT: - keyboard_scroll(1, 0); - return true; - } - } - - // everything following responds to a press or repeat, but not release + // hotkey press handling switch(cmd.id) { - case HOTKEY_CYCLE_UNITS: - cycle_units(); + case HOTKEY_SCROLL_UP: + keyboard_scroll(0, -1); + break; + case HOTKEY_SCROLL_DOWN: + keyboard_scroll(0, 1); + break; + case HOTKEY_SCROLL_LEFT: + keyboard_scroll(-1, 0); + break; + case HOTKEY_SCROLL_RIGHT: + keyboard_scroll(1, 0); break; - case HOTKEY_CYCLE_BACK_UNITS: cycle_back_units(); break; case HOTKEY_ENDTURN: @@ -559,26 +550,22 @@ static void event_execute( const SDL_Event& event, command_executor* executor) return; } - HOTKEY_EVENT_TYPE type = HOTKEY_EVENT_PRESS; - if (event.type == SDL_KEYUP || event.type == SDL_JOYBUTTONUP || event.type == SDL_MOUSEBUTTONUP) - type = HOTKEY_EVENT_RELEASE; - else if (event.type == SDL_KEYDOWN && event.key.repeat > 0) - type = HOTKEY_EVENT_REPEAT; + bool press = event.type == SDL_KEYDOWN || event.type == SDL_JOYBUTTONDOWN || event.type == SDL_MOUSEBUTTONDOWN; - execute_command(hotkey::get_hotkey_command(hk->get_command()), executor, -1, type); + execute_command(hotkey::get_hotkey_command(hk->get_command()), executor, -1, press); executor->set_button_state(); } -void execute_command(const hotkey_command& command, command_executor* executor, int index, HOTKEY_EVENT_TYPE type) +void execute_command(const hotkey_command& command, command_executor* executor, int index, bool press) { if (executor != nullptr) { if (!executor->can_execute_command(command, index) - || executor->execute_command(command, index, type)) { + || executor->execute_command(command, index, press)) { return; } } - if (type == HOTKEY_EVENT_RELEASE) { + if (!press) { return; // none of the commands here respond to a key release } diff --git a/src/hotkey/command_executor.hpp b/src/hotkey/command_executor.hpp index 4718f554994..52764786bb3 100644 --- a/src/hotkey/command_executor.hpp +++ b/src/hotkey/command_executor.hpp @@ -133,7 +133,7 @@ public: void execute_action(const std::vector& items_arg, int xloc, int yloc, bool context_menu, display& gui); virtual bool can_execute_command(const hotkey_command& command, int index=-1) const = 0; - virtual bool execute_command(const hotkey_command& command, int index=-1, HOTKEY_EVENT_TYPE type = HOTKEY_EVENT_PRESS); + virtual bool execute_command(const hotkey_command& command, int index=-1, bool press=true); }; class command_executor_default : public command_executor { @@ -163,7 +163,7 @@ void mbutton_event(const SDL_Event& event, command_executor* executor); //TODO -void execute_command(const hotkey_command& command, command_executor* executor, int index=-1, HOTKEY_EVENT_TYPE type = HOTKEY_EVENT_PRESS); +void execute_command(const hotkey_command& command, command_executor* executor, int index=-1, bool press=true); // Object which will ensure that basic keyboard events like escape // are handled properly for the duration of its lifetime. diff --git a/src/hotkey/hotkey_command.hpp b/src/hotkey/hotkey_command.hpp index f68f75e74fd..d9013470261 100644 --- a/src/hotkey/hotkey_command.hpp +++ b/src/hotkey/hotkey_command.hpp @@ -35,8 +35,6 @@ enum scope { SCOPE_COUNT, }; -enum HOTKEY_EVENT_TYPE { HOTKEY_EVENT_PRESS, HOTKEY_EVENT_RELEASE, HOTKEY_EVENT_REPEAT }; - enum HOTKEY_COMMAND { HOTKEY_CYCLE_UNITS, HOTKEY_CYCLE_BACK_UNITS, HOTKEY_UNIT_HOLD_POSITION, diff --git a/src/hotkey/hotkey_handler.cpp b/src/hotkey/hotkey_handler.cpp index 3607a1bfc99..e0b56706805 100644 --- a/src/hotkey/hotkey_handler.cpp +++ b/src/hotkey/hotkey_handler.cpp @@ -223,7 +223,7 @@ void play_controller::hotkey_handler::keyboard_scroll(int x, int y) play_controller_.keyboard_scroll(x, y); } -bool play_controller::hotkey_handler::execute_command(const hotkey::hotkey_command& cmd, int index, hotkey::HOTKEY_EVENT_TYPE type) +bool play_controller::hotkey_handler::execute_command(const hotkey::hotkey_command& cmd, int index, bool press) { hotkey::HOTKEY_COMMAND command = cmd.id; if(index >= 0) { @@ -250,7 +250,7 @@ bool play_controller::hotkey_handler::execute_command(const hotkey::hotkey_comma gamestate().get_wml_menu_items().fire_item(name, hex, gamestate().gamedata_, gamestate(), gamestate().board_.units_); /// @todo Shouldn't the function return at this point? } - return command_executor::execute_command(cmd, index, type); + return command_executor::execute_command(cmd, index, press); } bool play_controller::hotkey_handler::can_execute_command(const hotkey::hotkey_command& cmd, int index) const diff --git a/src/hotkey/hotkey_handler.hpp b/src/hotkey/hotkey_handler.hpp index e2e24a12d3a..ccf5f19c204 100644 --- a/src/hotkey/hotkey_handler.hpp +++ b/src/hotkey/hotkey_handler.hpp @@ -126,7 +126,7 @@ public: virtual hotkey::ACTION_STATE get_action_state(hotkey::HOTKEY_COMMAND command, int index) const; /** Check if a command can be executed. */ virtual bool can_execute_command(const hotkey::hotkey_command& command, int index=-1) const; - virtual bool execute_command(const hotkey::hotkey_command& command, int index=-1, hotkey::HOTKEY_EVENT_TYPE type = hotkey::HOTKEY_EVENT_PRESS); + virtual bool execute_command(const hotkey::hotkey_command& command, int index=-1, bool press=true); void show_menu(const std::vector& items_arg, int xloc, int yloc, bool context_menu, display& disp); /** From 419bf799acfe65ef23585d623246b632ebd17592 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Sun, 27 Mar 2016 22:06:53 -0400 Subject: [PATCH 06/13] Handle scrolling hotkeys in editor. --- src/editor/controller/editor_controller.cpp | 19 +++++++++++++++++-- src/editor/controller/editor_controller.hpp | 5 ++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/editor/controller/editor_controller.cpp b/src/editor/controller/editor_controller.cpp index 6a65b61841e..0ed39664926 100644 --- a/src/editor/controller/editor_controller.cpp +++ b/src/editor/controller/editor_controller.cpp @@ -286,6 +286,10 @@ bool editor_controller::can_execute_command(const hotkey::hotkey_command& cmd, i case HOTKEY_PREFERENCES: case HOTKEY_HELP: case HOTKEY_QUIT_GAME: + case HOTKEY_SCROLL_UP: + case HOTKEY_SCROLL_DOWN: + case HOTKEY_SCROLL_LEFT: + case HOTKEY_SCROLL_RIGHT: return true; //general hotkeys we can always do case hotkey::HOTKEY_UNIT_LIST: @@ -584,12 +588,18 @@ hotkey::ACTION_STATE editor_controller::get_action_state(hotkey::HOTKEY_COMMAND } } -bool editor_controller::execute_command(const hotkey::hotkey_command& cmd, int index) +bool editor_controller::execute_command(const hotkey::hotkey_command& cmd, int index, bool press) { const int zoom_amount = 4; hotkey::HOTKEY_COMMAND command = cmd.id; SCOPE_ED; using namespace hotkey; + + // nothing here handles release; fall through to base implementation + if (!press) { + return hotkey::command_executor::execute_command(cmd, index, press); + } + switch (command) { case HOTKEY_NULL: switch (active_menu_) { @@ -972,7 +982,7 @@ bool editor_controller::execute_command(const hotkey::hotkey_command& cmd, int i gui().invalidate_all(); return true; default: - return hotkey::command_executor::execute_command(cmd, index); + return hotkey::command_executor::execute_command(cmd, index, press); } } @@ -1356,4 +1366,9 @@ hotkey::command_executor * editor_controller::get_hotkey_command_executor() { return this; } +void editor_controller::keyboard_scroll(int x, int y) +{ + controller_base::keyboard_scroll(x, y); +} + } //end namespace editor diff --git a/src/editor/controller/editor_controller.hpp b/src/editor/controller/editor_controller.hpp index ab4cce2a4a7..743c508c634 100644 --- a/src/editor/controller/editor_controller.hpp +++ b/src/editor/controller/editor_controller.hpp @@ -107,7 +107,7 @@ class editor_controller : public controller_base, hotkey::ACTION_STATE get_action_state(hotkey::HOTKEY_COMMAND command, int index) const; /** command_executor override */ - bool execute_command(const hotkey::hotkey_command& command, int index = -1); + bool execute_command(const hotkey::hotkey_command& command, int index = -1, bool press=true); /** controller_base override */ void show_menu(const std::vector& items_arg, int xloc, int yloc, bool context_menu, display& disp); @@ -118,6 +118,9 @@ class editor_controller : public controller_base, /** Show the preferences dialog */ void preferences(); + /** Handle hotkeys to scroll map */ + void keyboard_scroll(int /*x*/, int /*y*/); + /** Grid toggle */ void toggle_grid(); From a58e595705248cb67e4a703d4cab8f72bf821fe4 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Sun, 27 Mar 2016 22:41:47 -0400 Subject: [PATCH 07/13] Add default hotkeys for map scrolling --- data/core/hotkeys.cfg | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/data/core/hotkeys.cfg b/data/core/hotkeys.cfg index a9cc925b2fb..f3a5622ade6 100644 --- a/data/core/hotkeys.cfg +++ b/data/core/hotkeys.cfg @@ -13,6 +13,23 @@ #endif #enddef +[hotkey] + command=scroll-up + key=UP +[/hotkey] +[hotkey] + command=scroll-down + key=DOWN +[/hotkey] +[hotkey] + command=scroll-left + key=LEFT +[/hotkey] +[hotkey] + command=scroll-right + key=RIGHT +[/hotkey] + [hotkey] button=1 command="selectmoveaction" From 4e3d6163360f6ec532436e96e81d37b2c3c200cf Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Mon, 28 Mar 2016 21:57:58 -0400 Subject: [PATCH 08/13] Rename controller_base::keyboard_scroll. Rename to controller_base::apply_keyboard_scroll to avoid confusion with hotkey_handler::keyboard_scroll. keyboard_scroll handles the hotkey press and invokes apply_keyboard_scroll on the controller. --- src/controller_base.cpp | 2 +- src/controller_base.hpp | 2 +- src/editor/controller/editor_controller.cpp | 2 +- src/hotkey/hotkey_handler.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/controller_base.cpp b/src/controller_base.cpp index b583570abf9..2573f7defda 100644 --- a/src/controller_base.cpp +++ b/src/controller_base.cpp @@ -347,7 +347,7 @@ const config& controller_base::get_theme(const config& game_config, std::string return empty; } -void controller_base::keyboard_scroll(int x, int y) +void controller_base::apply_keyboard_scroll(int x, int y) { if (have_keyboard_focus()) { // clamp between -1 and 1 so key repeats don't accelerate scrolling diff --git a/src/controller_base.hpp b/src/controller_base.hpp index 2329d9fc144..afe4540bc45 100644 --- a/src/controller_base.hpp +++ b/src/controller_base.hpp @@ -65,7 +65,7 @@ public: static const config &get_theme(const config& game_config, std::string theme_name); - void keyboard_scroll(int x, int y); + void apply_keyboard_scroll(int x, int y); protected: virtual bool is_browsing() const { return false; } diff --git a/src/editor/controller/editor_controller.cpp b/src/editor/controller/editor_controller.cpp index 0ed39664926..e7d37902c2e 100644 --- a/src/editor/controller/editor_controller.cpp +++ b/src/editor/controller/editor_controller.cpp @@ -1368,7 +1368,7 @@ hotkey::command_executor * editor_controller::get_hotkey_command_executor() { void editor_controller::keyboard_scroll(int x, int y) { - controller_base::keyboard_scroll(x, y); + controller_base::apply_keyboard_scroll(x, y); } } //end namespace editor diff --git a/src/hotkey/hotkey_handler.cpp b/src/hotkey/hotkey_handler.cpp index e0b56706805..294885a6421 100644 --- a/src/hotkey/hotkey_handler.cpp +++ b/src/hotkey/hotkey_handler.cpp @@ -220,7 +220,7 @@ void play_controller::hotkey_handler::toggle_accelerated_speed() void play_controller::hotkey_handler::keyboard_scroll(int x, int y) { - play_controller_.keyboard_scroll(x, y); + play_controller_.apply_keyboard_scroll(x, y); } bool play_controller::hotkey_handler::execute_command(const hotkey::hotkey_command& cmd, int index, bool press) From 355b8ce1b81a84ad0d1a11aac3830f87b1f8381a Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Tue, 29 Mar 2016 23:01:14 -0400 Subject: [PATCH 09/13] Restore cycle_units/cycle_back_units hotkeys. These were accidentally removed while implementing scroll hotkeys. --- src/hotkey/command_executor.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/hotkey/command_executor.cpp b/src/hotkey/command_executor.cpp index a6379feeb5c..1ba01d6cb39 100644 --- a/src/hotkey/command_executor.cpp +++ b/src/hotkey/command_executor.cpp @@ -111,6 +111,10 @@ bool command_executor::execute_command(const hotkey_command& cmd, int /*index*/ case HOTKEY_SCROLL_RIGHT: keyboard_scroll(1, 0); break; + case HOTKEY_CYCLE_UNITS: + cycle_units(); + break; + case HOTKEY_CYCLE_BACK_UNITS: cycle_back_units(); break; case HOTKEY_ENDTURN: From 94e390c067a3535e0a7294e3de3335f16fa2b9f9 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Wed, 30 Mar 2016 21:57:31 -0400 Subject: [PATCH 10/13] Gracefully handle multiple scrolling hotkeys. Track whether each scroll direction is enabled separately. This avoids odd behavior when holding multiple hotkeys for the same scroll direction. For example, holding two hotkeys for right and releasing both will no longer cause the map to begin scrolling left. --- src/controller_base.cpp | 37 +++++++++++++++------ src/controller_base.hpp | 10 ++++-- src/editor/controller/editor_controller.cpp | 19 +++++++++-- src/editor/controller/editor_controller.hpp | 5 ++- src/hotkey/command_executor.cpp | 16 ++++----- src/hotkey/command_executor.hpp | 5 ++- src/hotkey/hotkey_handler.cpp | 19 +++++++++-- src/hotkey/hotkey_handler.hpp | 5 ++- 8 files changed, 88 insertions(+), 28 deletions(-) diff --git a/src/controller_base.cpp b/src/controller_base.cpp index 2573f7defda..aad2865b65b 100644 --- a/src/controller_base.cpp +++ b/src/controller_base.cpp @@ -34,8 +34,10 @@ controller_base::controller_base( : game_config_(game_config) , key_() , scrolling_(false) - , scrollx_(0) - , scrolly_(0) + , scroll_up_(false) + , scroll_down_(false) + , scroll_left_(false) + , scroll_right_(false) , joystick_manager_() { } @@ -145,9 +147,11 @@ bool controller_base::handle_scroll(int mousex, int mousey, int mouse_flags, dou } } - // scroll with keyboard - dx += scrollx_ * scroll_speed; - dy += scrolly_ * scroll_speed; + // apply keyboard scrolling + dy -= scroll_up_ * scroll_speed; + dy += scroll_down_ * scroll_speed; + dx -= scroll_left_ * scroll_speed; + dx += scroll_right_ * scroll_speed; // scroll if mouse is placed near the edge of the screen if (mouse_in_window) { @@ -347,11 +351,22 @@ const config& controller_base::get_theme(const config& game_config, std::string return empty; } -void controller_base::apply_keyboard_scroll(int x, int y) +void controller_base::set_scroll_up(bool on) { - if (have_keyboard_focus()) { - // clamp between -1 and 1 so key repeats don't accelerate scrolling - scrollx_ = std::min(1, std::max(-1, scrollx_ + x)); - scrolly_ = std::min(1, std::max(-1, scrolly_ + y)); - } + scroll_up_ = on; +} + +void controller_base::set_scroll_down(bool on) +{ + scroll_down_ = on; +} + +void controller_base::set_scroll_left(bool on) +{ + scroll_left_ = on; +} + +void controller_base::set_scroll_right(bool on) +{ + scroll_right_ = on; } diff --git a/src/controller_base.hpp b/src/controller_base.hpp index afe4540bc45..8512661ec68 100644 --- a/src/controller_base.hpp +++ b/src/controller_base.hpp @@ -66,6 +66,10 @@ public: static const config &get_theme(const config& game_config, std::string theme_name); void apply_keyboard_scroll(int x, int y); + void set_scroll_up(bool on); + void set_scroll_down(bool on); + void set_scroll_left(bool on); + void set_scroll_right(bool on); protected: virtual bool is_browsing() const { return false; } @@ -143,8 +147,10 @@ protected: const config& game_config_; CKey key_; bool scrolling_; - int scrollx_; - int scrolly_; + bool scroll_up_; + bool scroll_down_; + bool scroll_left_; + bool scroll_right_; joystick_manager joystick_manager_; }; diff --git a/src/editor/controller/editor_controller.cpp b/src/editor/controller/editor_controller.cpp index e7d37902c2e..02210ba648e 100644 --- a/src/editor/controller/editor_controller.cpp +++ b/src/editor/controller/editor_controller.cpp @@ -1366,9 +1366,24 @@ hotkey::command_executor * editor_controller::get_hotkey_command_executor() { return this; } -void editor_controller::keyboard_scroll(int x, int y) +void editor_controller::scroll_up(bool on) { - controller_base::apply_keyboard_scroll(x, y); + controller_base::set_scroll_up(on); +} + +void editor_controller::scroll_down(bool on) +{ + controller_base::set_scroll_down(on); +} + +void editor_controller::scroll_left(bool on) +{ + controller_base::set_scroll_left(on); +} + +void editor_controller::scroll_right(bool on) +{ + controller_base::set_scroll_right(on); } } //end namespace editor diff --git a/src/editor/controller/editor_controller.hpp b/src/editor/controller/editor_controller.hpp index 743c508c634..88411d2b518 100644 --- a/src/editor/controller/editor_controller.hpp +++ b/src/editor/controller/editor_controller.hpp @@ -119,7 +119,10 @@ class editor_controller : public controller_base, void preferences(); /** Handle hotkeys to scroll map */ - void keyboard_scroll(int /*x*/, int /*y*/); + void scroll_up(bool on); + void scroll_down(bool on); + void scroll_left(bool on); + void scroll_right(bool on); /** Grid toggle */ void toggle_grid(); diff --git a/src/hotkey/command_executor.cpp b/src/hotkey/command_executor.cpp index 1ba01d6cb39..982937f56dc 100644 --- a/src/hotkey/command_executor.cpp +++ b/src/hotkey/command_executor.cpp @@ -79,16 +79,16 @@ bool command_executor::execute_command(const hotkey_command& cmd, int /*index*/ switch(cmd.id) { // release a scroll key, un-apply scrolling in the given direction case HOTKEY_SCROLL_UP: - keyboard_scroll(0, 1); + scroll_up(false); break; case HOTKEY_SCROLL_DOWN: - keyboard_scroll(0, -1); + scroll_down(false); break; case HOTKEY_SCROLL_LEFT: - keyboard_scroll(1, 0); + scroll_left(false); break; case HOTKEY_SCROLL_RIGHT: - keyboard_scroll(-1, 0); + scroll_right(false); break; default: return false; // nothing else handles a hotkey release @@ -100,16 +100,16 @@ bool command_executor::execute_command(const hotkey_command& cmd, int /*index*/ // hotkey press handling switch(cmd.id) { case HOTKEY_SCROLL_UP: - keyboard_scroll(0, -1); + scroll_up(true); break; case HOTKEY_SCROLL_DOWN: - keyboard_scroll(0, 1); + scroll_down(true); break; case HOTKEY_SCROLL_LEFT: - keyboard_scroll(-1, 0); + scroll_left(true); break; case HOTKEY_SCROLL_RIGHT: - keyboard_scroll(1, 0); + scroll_right(true); break; case HOTKEY_CYCLE_UNITS: cycle_units(); diff --git a/src/hotkey/command_executor.hpp b/src/hotkey/command_executor.hpp index 52764786bb3..8582e8ef635 100644 --- a/src/hotkey/command_executor.hpp +++ b/src/hotkey/command_executor.hpp @@ -108,7 +108,10 @@ public: virtual void left_mouse_click() {} virtual void right_mouse_click() {} virtual void toggle_accelerated_speed() {} - virtual void keyboard_scroll(int /*x*/, int /*y*/) {} + virtual void scroll_up(bool /*on*/) {} + virtual void scroll_down(bool /*on*/) {} + virtual void scroll_left(bool /*on*/) {} + virtual void scroll_right(bool /*on*/) {} virtual void lua_console(); virtual void zoom_in() {} virtual void zoom_out() {} diff --git a/src/hotkey/hotkey_handler.cpp b/src/hotkey/hotkey_handler.cpp index 294885a6421..689887aa1b3 100644 --- a/src/hotkey/hotkey_handler.cpp +++ b/src/hotkey/hotkey_handler.cpp @@ -218,9 +218,24 @@ void play_controller::hotkey_handler::toggle_accelerated_speed() } } -void play_controller::hotkey_handler::keyboard_scroll(int x, int y) +void play_controller::hotkey_handler::scroll_up(bool on) { - play_controller_.apply_keyboard_scroll(x, y); + play_controller_.set_scroll_up(on); +} + +void play_controller::hotkey_handler::scroll_down(bool on) +{ + play_controller_.set_scroll_down(on); +} + +void play_controller::hotkey_handler::scroll_left(bool on) +{ + play_controller_.set_scroll_left(on); +} + +void play_controller::hotkey_handler::scroll_right(bool on) +{ + play_controller_.set_scroll_right(on); } bool play_controller::hotkey_handler::execute_command(const hotkey::hotkey_command& cmd, int index, bool press) diff --git a/src/hotkey/hotkey_handler.hpp b/src/hotkey/hotkey_handler.hpp index ccf5f19c204..f24d8b8bf86 100644 --- a/src/hotkey/hotkey_handler.hpp +++ b/src/hotkey/hotkey_handler.hpp @@ -117,7 +117,10 @@ public: virtual void toggle_grid(); virtual void search(); virtual void toggle_accelerated_speed(); - virtual void keyboard_scroll(int x, int y); + virtual void scroll_up(bool on); + virtual void scroll_down(bool on); + virtual void scroll_left(bool on); + virtual void scroll_right(bool on); virtual void replay_skip_animation() override { return play_controller_.toggle_skipping_replay(); } From e066075a04f0330effef37c5629754c4271d4640 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Fri, 1 Apr 2016 07:58:39 -0400 Subject: [PATCH 11/13] Cleanup: Replace spaces with tabs --- src/controller_base.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/controller_base.cpp b/src/controller_base.cpp index aad2865b65b..1a9e03d04e5 100644 --- a/src/controller_base.cpp +++ b/src/controller_base.cpp @@ -157,16 +157,16 @@ bool controller_base::handle_scroll(int mousex, int mousey, int mouse_flags, dou if (mouse_in_window) { if (mousey < scroll_threshold) { dy -= scroll_speed; - } + } if (mousey > get_display().h() - scroll_threshold) { dy += scroll_speed; - } + } if (mousex < scroll_threshold) { dx -= scroll_speed; - } + } if (mousex > get_display().w() - scroll_threshold) { dx += scroll_speed; - } + } } // scroll with middle-mouse if enabled From fd8dfd585349b0c488529723cbba2aa9bc20baa7 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Wed, 6 Apr 2016 22:41:48 -0400 Subject: [PATCH 12/13] Changelog: hotkey release and scroll key binding. --- changelog | 2 ++ players_changelog | 2 ++ 2 files changed, 4 insertions(+) diff --git a/changelog b/changelog index f8247708a77..fe73a91440f 100644 --- a/changelog +++ b/changelog @@ -270,6 +270,8 @@ Version 1.13.4+dev: * Miscellaneous and bug fixes: * Resolve translated logo images not being used (bug #24357) * Ported the "hexometer" tool from Bash to Python 3 + * Recognize hotkey release events + * Allow changing keybindings for scrolling the map. Version 1.13.4: * Language and i18n: diff --git a/players_changelog b/players_changelog index aa08524aedb..2633a73a0b4 100644 --- a/players_changelog +++ b/players_changelog @@ -5,6 +5,8 @@ changelog: https://github.com/wesnoth/wesnoth/blob/master/changelog Version 1.13.4+dev: * Language and i18n: * Updated translations: + * Miscellaneous and bug fixes: + * Allow changing keybindings for scrolling the map. Version 1.13.4: * Language and i18n: From 5aecbdbe83344b6e79b62374a79374f54c724710 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Wed, 6 Apr 2016 22:45:30 -0400 Subject: [PATCH 13/13] Add self (rcorre) to contributors --- data/core/about.cfg | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/data/core/about.cfg b/data/core/about.cfg index 600794a3fa9..f69a6a92a8e 100644 --- a/data/core/about.cfg +++ b/data/core/about.cfg @@ -1357,6 +1357,10 @@ [entry] name = "Ryan Henszey" [/entry] + [entry] + name = "Ryan Roden-Corrent (rcorre)" + comment = "Hotkey release and scroll key rebinding" + [/entry] [entry] name = "Sachith Seneviratne (sachith500)" email = "sachith500@gmail.com"