GunChleoc has proposed merging lp:~widelands-dev/widelands/arrow-keys-map-movement into lp:widelands.
Commit message: Fixes for keyboard map movement - Stop minimized windows from handling key presses. - Handle map movement by key at the proper place. Requested reviews: Widelands Developers (widelands-dev) Related bugs: Bug #1772076 in widelands: "Minimized chat window still handles some keys" https://bugs.launchpad.net/widelands/+bug/1772076 For more details, see: https://code.launchpad.net/~widelands-dev/widelands/arrow-keys-map-movement/+merge/370687 -- Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/arrow-keys-map-movement into lp:widelands.
=== modified file 'src/ui_basic/panel.cc' --- src/ui_basic/panel.cc 2019-06-01 08:18:58 +0000 +++ src/ui_basic/panel.cc 2019-07-27 11:28:41 +0000 @@ -57,7 +57,7 @@ last_child_(nullptr), mousein_child_(nullptr), focus_(nullptr), - flags_(pf_handle_mouse | pf_thinks | pf_visible), + flags_(pf_handle_mouse | pf_thinks | pf_visible | pf_handle_keypresses), x_(nx), y_(ny), w_(nw), @@ -912,6 +912,10 @@ return true; } + if (!handles_keypresses()) { + return false; + } + // If we handle text, it does not matter if we handled this key // or not, it should not propagate. if (handle_key(down, code) || handles_textinput()) { === modified file 'src/ui_basic/panel.h' --- src/ui_basic/panel.h 2019-06-01 08:18:58 +0000 +++ src/ui_basic/panel.h 2019-07-27 11:28:41 +0000 @@ -79,6 +79,8 @@ pf_layout_toplevel = 512, /// whether widget wants to receive unicode textinput messages pf_handle_textinput = 1024, + /// whether widget and its parents will handle any key presses + pf_handle_keypresses = 2048, }; Panel(Panel* const nparent, @@ -303,6 +305,15 @@ flags_ |= pf_handle_textinput; } + // This panel will never receive keypresses (do_key) or textinput (do_textinput). + void set_handle_keypresses(bool const on) { + if (on) { + flags_ |= pf_handle_keypresses; + } else { + flags_ &= ~pf_handle_keypresses; + } + } + // Defines if think() should be called repeatedly. This is true on construction. void set_thinks(bool yes); @@ -325,6 +336,14 @@ bool handles_mouse() const { return (flags_ & pf_handle_mouse) != 0; } + + bool handles_keypresses() const { + if (get_parent() != nullptr && !get_parent()->handles_keypresses()) { + return false; + } + return (flags_ & pf_handle_keypresses) != 0; + } + bool handles_textinput() const { return (flags_ & pf_handle_textinput) != 0; } === modified file 'src/ui_basic/window.cc' --- src/ui_basic/window.cc 2019-05-26 17:21:15 +0000 +++ src/ui_basic/window.cc 2019-07-27 11:28:41 +0000 @@ -431,6 +431,7 @@ set_inner_size(get_inner_w(), oldh_); update_desired_size(); move_inside_parent(); + set_handle_keypresses(true); } void Window::minimize() { assert(!is_minimal_); @@ -446,6 +447,7 @@ set_border(get_lborder(), get_rborder(), get_tborder(), 0); set_size(get_w(), TP_B_PIXMAP_THICKNESS); set_pos(Vector2i(x, y)); // If on border, this feels more natural + set_handle_keypresses(false); } /** === modified file 'src/wui/interactive_base.cc' --- src/wui/interactive_base.cc 2019-05-29 15:43:40 +0000 +++ src/wui/interactive_base.cc 2019-07-27 11:28:41 +0000 @@ -510,27 +510,6 @@ =============== */ void InteractiveBase::think() { - // If one of the arrow keys is pressed, scroll here - const uint32_t scrollval = 10; - - if (keyboard_free() && Panel::allow_user_input()) { - if (get_key_state(SDL_SCANCODE_UP) || - (get_key_state(SDL_SCANCODE_KP_8) && (SDL_GetModState() ^ KMOD_NUM))) { - map_view_.pan_by(Vector2i(0, -scrollval)); - } - if (get_key_state(SDL_SCANCODE_DOWN) || - (get_key_state(SDL_SCANCODE_KP_2) && (SDL_GetModState() ^ KMOD_NUM))) { - map_view_.pan_by(Vector2i(0, scrollval)); - } - if (get_key_state(SDL_SCANCODE_LEFT) || - (get_key_state(SDL_SCANCODE_KP_4) && (SDL_GetModState() ^ KMOD_NUM))) { - map_view_.pan_by(Vector2i(-scrollval, 0)); - } - if (get_key_state(SDL_SCANCODE_RIGHT) || - (get_key_state(SDL_SCANCODE_KP_6) && (SDL_GetModState() ^ KMOD_NUM))) { - map_view_.pan_by(Vector2i(scrollval, 0)); - } - } egbase().think(); // Call game logic here. The game advances. // Cleanup found port spaces if the ship sailed on or was destroyed @@ -1011,8 +990,12 @@ } bool InteractiveBase::handle_key(bool const down, SDL_Keysym const code) { - if (quick_navigation_.handle_key(down, code)) + if (quick_navigation_.handle_key(down, code)) { return true; + } + + // If one of the arrow keys is pressed, scroll here + constexpr uint32_t kScrollDistance = 10; if (down) { switch (code.sym) { @@ -1050,6 +1033,40 @@ } } return true; + // Scroll the map + case SDLK_KP_8: + if (SDL_GetModState() & KMOD_NUM) { + break; + } + FALLS_THROUGH; + case SDLK_UP: + map_view_.pan_by(Vector2i(0, -kScrollDistance)); + return true; + case SDLK_KP_2: + if (SDL_GetModState() & KMOD_NUM) { + break; + } + FALLS_THROUGH; + case SDLK_DOWN: + map_view_.pan_by(Vector2i(0, kScrollDistance)); + return true; + case SDLK_KP_4: + if (SDL_GetModState() & KMOD_NUM) { + break; + } + FALLS_THROUGH; + case SDLK_LEFT: + map_view_.pan_by(Vector2i(-kScrollDistance, 0)); + return true; + case SDLK_KP_6: + if (SDL_GetModState() & KMOD_NUM) { + break; + } + FALLS_THROUGH; + case SDLK_RIGHT: + map_view_.pan_by(Vector2i(kScrollDistance, 0)); + return true; + #ifndef NDEBUG // only in debug builds case SDLK_F6: GameChatMenu::create_script_console(
_______________________________________________ Mailing list: https://launchpad.net/~widelands-dev Post to : widelands-dev@lists.launchpad.net Unsubscribe : https://launchpad.net/~widelands-dev More help : https://help.launchpad.net/ListHelp