diff --git a/src/openrct2-ui/input/InputManager.cpp b/src/openrct2-ui/input/InputManager.cpp index e3d9174dd5..dd881c24cb 100644 --- a/src/openrct2-ui/input/InputManager.cpp +++ b/src/openrct2-ui/input/InputManager.cpp @@ -291,18 +291,22 @@ void InputManager::ProcessHoldEvents() auto& shortcutManager = GetShortcutManager(); if (!shortcutManager.IsPendingShortcutChange()) { - ProcessViewScrollEvent(ShortcutId::ScrollUp, { 0, -1 }); - ProcessViewScrollEvent(ShortcutId::ScrollDown, { 0, 1 }); - ProcessViewScrollEvent(ShortcutId::ScrollLeft, { -1, 0 }); - ProcessViewScrollEvent(ShortcutId::ScrollRight, { 1, 0 }); + ProcessViewScrollEvent(ShortcutId::ScrollUp, _scrollUpShortcut, { 0, -1 }); + ProcessViewScrollEvent(ShortcutId::ScrollDown, _scrollDownShortcut, { 0, 1 }); + ProcessViewScrollEvent(ShortcutId::ScrollLeft, _scrollLeftShortcut, { -1, 0 }); + ProcessViewScrollEvent(ShortcutId::ScrollRight, _scrollRightShortcut, { 1, 0 }); } } -void InputManager::ProcessViewScrollEvent(std::string_view shortcutId, const ScreenCoordsXY& delta) +void InputManager::ProcessViewScrollEvent( + std::string_view shortcutId, RegisteredShortcut*& shortcut, const ScreenCoordsXY& delta) { - auto& shortcutManager = GetShortcutManager(); - auto s = shortcutManager.GetShortcut(shortcutId); - if (s != nullptr && GetState(*s)) + if (shortcut == nullptr) + { + auto& shortcutManager = GetShortcutManager(); + shortcut = shortcutManager.GetShortcut(shortcutId); + } + if (shortcut != nullptr && GetState(*shortcut)) { _viewScroll.x += delta.x; _viewScroll.y += delta.y; diff --git a/src/openrct2-ui/input/InputManager.h b/src/openrct2-ui/input/InputManager.h index 1aa81ee225..476a9f718d 100644 --- a/src/openrct2-ui/input/InputManager.h +++ b/src/openrct2-ui/input/InputManager.h @@ -53,6 +53,11 @@ namespace OpenRCT2::Ui uint32_t _mouseState; std::vector _keyboardState; + RegisteredShortcut* _scrollLeftShortcut{}; + RegisteredShortcut* _scrollUpShortcut{}; + RegisteredShortcut* _scrollRightShortcut{}; + RegisteredShortcut* _scrollDownShortcut{}; + void CheckJoysticks(); void HandleViewScrolling(); @@ -62,7 +67,7 @@ namespace OpenRCT2::Ui void ProcessInGameConsole(const InputEvent& e); void ProcessChat(const InputEvent& e); void ProcessHoldEvents(); - void ProcessViewScrollEvent(std::string_view shortcutId, const ScreenCoordsXY& delta); + void ProcessViewScrollEvent(std::string_view shortcutId, RegisteredShortcut*& shortcut, const ScreenCoordsXY& delta); bool GetState(const RegisteredShortcut& shortcut) const; bool GetState(const ShortcutInput& shortcut) const;