Fix #2657: inability to scroll diagonally with keyboard

Regression from commit ecc0dca665.

Scrolling diagonally requires holding two keys. Now when a key press event
is considered a key press only if there hasn't been a key release in
between, the second key press is no longer considered a key press.

As a workaround, simply activate scrolling on key event even if the event
isn't considered a key press.
This commit is contained in:
Jyrki Vesterinen 2018-03-15 19:33:32 +02:00
parent bba1dc264b
commit 75b50979b6
6 changed files with 25 additions and 16 deletions

View file

@ -584,7 +584,7 @@ hotkey::ACTION_STATE editor_controller::get_action_state(hotkey::HOTKEY_COMMAND
}
}
bool editor_controller::do_execute_command(const hotkey::hotkey_command& cmd, int index, bool press)
bool editor_controller::do_execute_command(const hotkey::hotkey_command& cmd, int index, bool press, bool release)
{
hotkey::HOTKEY_COMMAND command = cmd.id;
SCOPE_ED;
@ -592,7 +592,7 @@ bool editor_controller::do_execute_command(const hotkey::hotkey_command& cmd, in
// nothing here handles release; fall through to base implementation
if (!press) {
return hotkey::command_executor::do_execute_command(cmd, index, press);
return hotkey::command_executor::do_execute_command(cmd, index, press, release);
}
switch (command) {
@ -988,7 +988,7 @@ bool editor_controller::do_execute_command(const hotkey::hotkey_command& cmd, in
return true;
}
default:
return hotkey::command_executor::do_execute_command(cmd, index, press);
return hotkey::command_executor::do_execute_command(cmd, index, press, release);
}
}

View file

@ -108,7 +108,7 @@ class editor_controller : public controller_base,
hotkey::ACTION_STATE get_action_state(hotkey::HOTKEY_COMMAND command, int index) const override;
/** command_executor override */
bool do_execute_command(const hotkey::hotkey_command& command, int index = -1, bool press=true) override;
bool do_execute_command(const hotkey::hotkey_command& command, int index = -1, bool press = true, bool release = false) override;
/** controller_base override */
void show_menu(const std::vector<config>& items_arg, int xloc, int yloc, bool context_menu, display& disp) override;

View file

@ -84,10 +84,10 @@ namespace hotkey {
static void event_execute(const SDL_Event& event, command_executor* executor);
bool command_executor::do_execute_command(const hotkey_command& cmd, int /*index*/, bool press)
bool command_executor::do_execute_command(const hotkey_command& cmd, int /*index*/, bool press, bool release)
{
// hotkey release handling
if (!press) {
if (release) {
switch(cmd.id) {
// release a scroll key, un-apply scrolling in the given direction
case HOTKEY_SCROLL_UP:
@ -109,20 +109,28 @@ bool command_executor::do_execute_command(const hotkey_command& cmd, int /*inde
return true;
}
// hotkey press handling
// handling of hotkeys which activate even on hold events
switch(cmd.id) {
case HOTKEY_SCROLL_UP:
scroll_up(true);
break;
return true;
case HOTKEY_SCROLL_DOWN:
scroll_down(true);
break;
return true;
case HOTKEY_SCROLL_LEFT:
scroll_left(true);
break;
return true;
case HOTKEY_SCROLL_RIGHT:
scroll_right(true);
break;
return true;
}
if(!press) {
return false; // nothing else handles hotkey hold events
}
// hotkey press handling
switch(cmd.id) {
case HOTKEY_CYCLE_UNITS:
cycle_units();
break;
@ -561,6 +569,7 @@ void command_executor::execute_command(const SDL_Event& event, int index)
!press_event_sent_;
bool press = keypress ||
(event.type == SDL_JOYBUTTONDOWN || event.type == SDL_MOUSEBUTTONDOWN);
bool release = event.type == SDL_KEYUP;
if(press) {
LOG_HK << "sending press event (keypress = " <<
std::boolalpha << keypress << std::noboolalpha << ")\n";
@ -570,7 +579,7 @@ void command_executor::execute_command(const SDL_Event& event, int index)
}
if (!can_execute_command(command, index)
|| do_execute_command(command, index, press)) {
|| do_execute_command(command, index, press, release)) {
return;
}

View file

@ -147,7 +147,7 @@ public:
}
protected:
virtual bool do_execute_command(const hotkey_command& command, int index=-1, bool press=true);
virtual bool do_execute_command(const hotkey_command& command, int index=-1, bool press=true, bool release=false);
private:
bool press_event_sent_ = false;

View file

@ -237,7 +237,7 @@ void play_controller::hotkey_handler::scroll_right(bool on)
play_controller_.set_scroll_right(on);
}
bool play_controller::hotkey_handler::do_execute_command(const hotkey::hotkey_command& cmd, int index, bool press)
bool play_controller::hotkey_handler::do_execute_command(const hotkey::hotkey_command& cmd, int index, bool press, bool release)
{
hotkey::HOTKEY_COMMAND command = cmd.id;
if(index >= 0) {
@ -259,7 +259,7 @@ bool play_controller::hotkey_handler::do_execute_command(const hotkey::hotkey_co
return gamestate().get_wml_menu_items().fire_item(name, hex, gamestate().gamedata_, gamestate(), gamestate().board_.units_, !press);
}
return command_executor::do_execute_command(cmd, index, press);
return command_executor::do_execute_command(cmd, index, press, release);
}
bool play_controller::hotkey_handler::can_execute_command(const hotkey::hotkey_command& cmd, int index) const

View file

@ -123,7 +123,7 @@ public:
virtual hotkey::ACTION_STATE get_action_state(hotkey::HOTKEY_COMMAND command, int index) const override;
/** Check if a command can be executed. */
virtual bool can_execute_command(const hotkey::hotkey_command& command, int index=-1) const override;
virtual bool do_execute_command(const hotkey::hotkey_command& command, int index=-1, bool press=true) override;
virtual bool do_execute_command(const hotkey::hotkey_command& command, int index=-1, bool press=true, bool release=false) override;
void show_menu(const std::vector<config>& items_arg, int xloc, int yloc, bool context_menu, display& disp) override;
/**