minor: KeyCode -> Keycode

This commit is contained in:
y5nw 2024-12-13 17:50:58 +01:00
parent 1e0dfe098d
commit c91d4edbef
5 changed files with 15 additions and 15 deletions

View File

@ -347,19 +347,19 @@ public:
// not implement this. // not implement this.
//! Get the scancode of the corresponding keycode. //! Get the scancode of the corresponding keycode.
virtual u32 getScancodeFromKey(const KeyCode &key) const virtual u32 getScancodeFromKey(const Keycode &key) const
{ {
if (const auto *keycode = std::get_if<EKEY_CODE>(&key)) if (const auto *keycode = std::get_if<EKEY_CODE>(&key))
// treat KEY_UNKNOWN and KEY_KEY_CODES_COUNT as the same and return 0. // treat KEY_UNKNOWN and KEY_KEY_CODES_COUNT as the same and return 0.
return KeyCode::isValid(*keycode) ? *keycode : 0; return Keycode::isValid(*keycode) ? *keycode : 0;
const auto keychar = std::get<wchar_t>(key); const auto keychar = std::get<wchar_t>(key);
return keychar == 0 ? 0 : KEY_KEY_CODES_COUNT + keychar; return keychar == 0 ? 0 : KEY_KEY_CODES_COUNT + keychar;
} }
//! Get the keycode of the corresponding scancode. //! Get the keycode of the corresponding scancode.
virtual KeyCode getKeyFromScancode(const u32 scancode) const virtual Keycode getKeyFromScancode(const u32 scancode) const
{ {
KeyCode key; Keycode key;
if (scancode < KEY_KEY_CODES_COUNT) if (scancode < KEY_KEY_CODES_COUNT)
key.emplace<EKEY_CODE>((EKEY_CODE)scancode); key.emplace<EKEY_CODE>((EKEY_CODE)scancode);
else else

View File

@ -183,12 +183,12 @@ enum EKEY_CODE
KEY_KEY_CODES_COUNT = 0x100 // this is not a key, but the amount of keycodes there are. KEY_KEY_CODES_COUNT = 0x100 // this is not a key, but the amount of keycodes there are.
}; };
class KeyCode : public std::variant<EKEY_CODE, wchar_t> { class Keycode : public std::variant<EKEY_CODE, wchar_t> {
using super = std::variant<EKEY_CODE, wchar_t>; using super = std::variant<EKEY_CODE, wchar_t>;
public: public:
KeyCode() : KeyCode(KEY_KEY_CODES_COUNT, L'\0') {} Keycode() : Keycode(KEY_KEY_CODES_COUNT, L'\0') {}
KeyCode(EKEY_CODE code, wchar_t ch) Keycode(EKEY_CODE code, wchar_t ch)
{ {
emplace(code, ch); emplace(code, ch);
} }

View File

@ -220,7 +220,7 @@ int CIrrDeviceSDL::findCharToPassToIrrlicht(uint32_t sdlKey, EKEY_CODE irrlichtK
} }
} }
u32 CIrrDeviceSDL::getScancodeFromKey(const KeyCode &key) const u32 CIrrDeviceSDL::getScancodeFromKey(const Keycode &key) const
{ {
u32 keynum = 0; u32 keynum = 0;
if (const auto *keycode = std::get_if<EKEY_CODE>(&key)) { if (const auto *keycode = std::get_if<EKEY_CODE>(&key)) {
@ -236,13 +236,13 @@ u32 CIrrDeviceSDL::getScancodeFromKey(const KeyCode &key) const
return SDL_GetScancodeFromKey(keynum); return SDL_GetScancodeFromKey(keynum);
} }
KeyCode CIrrDeviceSDL::getKeyFromScancode(const u32 scancode) const Keycode CIrrDeviceSDL::getKeyFromScancode(const u32 scancode) const
{ {
auto keycode = SDL_GetKeyFromScancode((SDL_Scancode)scancode); auto keycode = SDL_GetKeyFromScancode((SDL_Scancode)scancode);
const auto &keyentry = KeyMap.find(keycode); const auto &keyentry = KeyMap.find(keycode);
auto irrcode = keyentry != KeyMap.end() ? keyentry->second : KEY_UNKNOWN; auto irrcode = keyentry != KeyMap.end() ? keyentry->second : KEY_UNKNOWN;
auto keychar = findCharToPassToIrrlicht(keycode, irrcode, false); auto keychar = findCharToPassToIrrlicht(keycode, irrcode, false);
return KeyCode(irrcode, keychar); return Keycode(irrcode, keychar);
} }
void CIrrDeviceSDL::resetReceiveTextInputEvents() void CIrrDeviceSDL::resetReceiveTextInputEvents()
@ -858,7 +858,7 @@ bool CIrrDeviceSDL::run()
const auto &entry = KeyMap.find(keysym); const auto &entry = KeyMap.find(keysym);
auto key = entry == KeyMap.end() ? KEY_UNKNOWN : entry->second; auto key = entry == KeyMap.end() ? KEY_UNKNOWN : entry->second;
if (!KeyCode::isValid(key)) if (!Keycode::isValid(key))
os::Printer::log("keycode not mapped", core::stringc(keysym), ELL_DEBUG); os::Printer::log("keycode not mapped", core::stringc(keysym), ELL_DEBUG);
// Make sure to only input special characters if something is in focus, as SDL_TEXTINPUT handles normal unicode already // Make sure to only input special characters if something is in focus, as SDL_TEXTINPUT handles normal unicode already

View File

@ -288,8 +288,8 @@ private:
// Return the Char that should be sent to Irrlicht for the given key (either the one passed in or 0). // Return the Char that should be sent to Irrlicht for the given key (either the one passed in or 0).
static int findCharToPassToIrrlicht(uint32_t sdlKey, EKEY_CODE irrlichtKey, bool numlock); static int findCharToPassToIrrlicht(uint32_t sdlKey, EKEY_CODE irrlichtKey, bool numlock);
virtual u32 getScancodeFromKey(const KeyCode &key) const override; virtual u32 getScancodeFromKey(const Keycode &key) const override;
virtual KeyCode getKeyFromScancode(const u32 scancode) const override; virtual Keycode getKeyFromScancode(const u32 scancode) const override;
// Check if a text box is in focus. Enable or disable SDL_TEXTINPUT events only if in focus. // Check if a text box is in focus. Enable or disable SDL_TEXTINPUT events only if in focus.
void resetReceiveTextInputEvents(); void resetReceiveTextInputEvents();

View File

@ -261,7 +261,7 @@ static const table_key &lookup_keyname(std::string_view name)
static const table_key &lookup_keykey(irr::EKEY_CODE key) static const table_key &lookup_keykey(irr::EKEY_CODE key)
{ {
if (!KeyCode::isValid(key)) if (!Keycode::isValid(key))
return invalid_key; return invalid_key;
for (const auto &table_key : table) { for (const auto &table_key : table) {
@ -285,7 +285,7 @@ KeyPress::KeyPress(std::string_view name)
if (loadFromScancode(name)) if (loadFromScancode(name))
return; return;
const auto &key = lookup_keyname(name); const auto &key = lookup_keyname(name);
KeyCode keycode(key.Key, key.Char); Keycode keycode(key.Key, key.Char);
scancode = RenderingEngine::get_raw_device()->getScancodeFromKey(keycode); scancode = RenderingEngine::get_raw_device()->getScancodeFromKey(keycode);
} }