Cache view scroll shortcuts

This commit is contained in:
Ted John 2021-01-20 17:40:29 +00:00
parent 2b3e7b98b8
commit 80662d72a4
2 changed files with 18 additions and 9 deletions

View file

@ -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;

View file

@ -53,6 +53,11 @@ namespace OpenRCT2::Ui
uint32_t _mouseState;
std::vector<uint8_t> _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;