1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-21 05:53:02 +01:00

Use ScreenCoordsXY for Keyboard shortcuts

This commit is contained in:
Tulio Leao
2019-10-13 08:20:38 -03:00
parent e1a9e6005d
commit 88dfff5f5e
3 changed files with 15 additions and 15 deletions

View File

@@ -81,7 +81,6 @@ static void input_handle_chat(int32_t key)
static void game_handle_key_scroll()
{
rct_window* mainWindow;
int32_t scrollX, scrollY;
mainWindow = window_get_main();
if (mainWindow == nullptr)
@@ -99,16 +98,14 @@ static void game_handle_key_scroll()
if (gChatOpen)
return;
scrollX = 0;
scrollY = 0;
const uint8_t* keysState = context_get_keys_state();
get_keyboard_map_scroll(keysState, &scrollX, &scrollY);
auto scrollCoords = get_keyboard_map_scroll(keysState);
if (scrollX != 0 || scrollY != 0)
if (scrollCoords.x != 0 || scrollCoords.y != 0)
{
window_unfollow_sprite(mainWindow);
}
input_scroll_viewport(scrollX, scrollY);
input_scroll_viewport(scrollCoords.x, scrollCoords.y);
}
static int32_t input_scancode_to_rct_keycode(int32_t sdl_key)

View File

@@ -157,8 +157,9 @@ std::string KeyboardShortcuts::GetShortcutString(int32_t shortcut) const
return std::string(buffer);
}
void KeyboardShortcuts::GetKeyboardMapScroll(const uint8_t* keysState, int32_t* x, int32_t* y) const
ScreenCoordsXY KeyboardShortcuts::GetKeyboardMapScroll(const uint8_t* keysState) const
{
ScreenCoordsXY screenCoords;
for (int32_t shortcutId = SHORTCUT_SCROLL_MAP_UP; shortcutId <= SHORTCUT_SCROLL_MAP_RIGHT; shortcutId++)
{
uint16_t shortcutKey = _keys[shortcutId];
@@ -184,21 +185,22 @@ void KeyboardShortcuts::GetKeyboardMapScroll(const uint8_t* keysState, int32_t*
switch (shortcutId)
{
case SHORTCUT_SCROLL_MAP_UP:
*y = -1;
screenCoords.y = -1;
break;
case SHORTCUT_SCROLL_MAP_LEFT:
*x = -1;
screenCoords.x = -1;
break;
case SHORTCUT_SCROLL_MAP_DOWN:
*y = 1;
screenCoords.y = 1;
break;
case SHORTCUT_SCROLL_MAP_RIGHT:
*x = 1;
screenCoords.x = 1;
break;
default:
break;
}
}
return screenCoords;
}
void keyboard_shortcuts_reset()
@@ -232,9 +234,9 @@ void keyboard_shortcuts_format_string(char* buffer, size_t bufferSize, int32_t s
String::Set(buffer, bufferSize, str.c_str());
}
void get_keyboard_map_scroll(const uint8_t* keysState, int32_t* x, int32_t* y)
ScreenCoordsXY get_keyboard_map_scroll(const uint8_t* keysState)
{
_instance->GetKeyboardMapScroll(keysState, x, y);
return _instance->GetKeyboardMapScroll(keysState);
}
// Default keyboard shortcuts

View File

@@ -11,6 +11,7 @@
#include <memory>
#include <openrct2/common.h>
#include <openrct2/world/Location.hpp>
#define SHIFT 0x100
#define CTRL 0x200
@@ -131,7 +132,7 @@ namespace OpenRCT2
void Set(int32_t key);
int32_t GetFromKey(int32_t key);
void GetKeyboardMapScroll(const uint8_t* keysState, int32_t* x, int32_t* y) const;
ScreenCoordsXY GetKeyboardMapScroll(const uint8_t* keysState) const;
};
} // namespace Input
} // namespace OpenRCT2
@@ -151,4 +152,4 @@ void keyboard_shortcut_handle(int32_t key);
void keyboard_shortcut_handle_command(int32_t shortcutIndex);
void keyboard_shortcut_format_string(char* buffer, size_t size, uint16_t shortcutKey);
void get_keyboard_map_scroll(const uint8_t* keysState, int32_t* x, int32_t* y);
ScreenCoordsXY get_keyboard_map_scroll(const uint8_t* keysState);