mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-01 17:38:41 +00:00
SDL: Use scancodes for keybindings (#14964)
Co-authored-by: Lars Müller <34514239+appgurueu@users.noreply.github.com> Co-authored-by: sfan5 <sfan5@live.de> Co-authored-by: SmallJoker <SmallJoker@users.noreply.github.com>
This commit is contained in:
parent
e0378737b7
commit
cc65c8bd70
13 changed files with 509 additions and 369 deletions
|
@ -16,6 +16,7 @@
|
|||
#include "IrrCompileConfig.h"
|
||||
#include "position2d.h"
|
||||
#include "SColor.h" // video::ECOLOR_FORMAT
|
||||
#include <variant>
|
||||
|
||||
namespace irr
|
||||
{
|
||||
|
@ -342,6 +343,27 @@ public:
|
|||
{
|
||||
return video::isDriverSupported(driver);
|
||||
}
|
||||
|
||||
//! Get the corresponding scancode for the keycode.
|
||||
/**
|
||||
\param key The keycode to convert.
|
||||
\return The implementation-dependent scancode for the key (represented by the u32 component) or, if a scancode is not
|
||||
available, the corresponding Irrlicht keycode (represented by the EKEY_CODE component).
|
||||
*/
|
||||
virtual std::variant<u32, EKEY_CODE> getScancodeFromKey(const Keycode &key) const {
|
||||
if (auto pv = std::get_if<EKEY_CODE>(&key))
|
||||
return *pv;
|
||||
return (u32)std::get<wchar_t>(key);
|
||||
}
|
||||
|
||||
//! Get the corresponding keycode for the scancode.
|
||||
/**
|
||||
\param scancode The implementation-dependent scancode for the key.
|
||||
\return The corresponding keycode.
|
||||
*/
|
||||
virtual Keycode getKeyFromScancode(const u32 scancode) const {
|
||||
return Keycode(KEY_UNKNOWN, (wchar_t)scancode);
|
||||
}
|
||||
};
|
||||
|
||||
} // end namespace irr
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// For conditions of distribution and use, see copyright notice in irrlicht.h
|
||||
|
||||
#pragma once
|
||||
#include <variant>
|
||||
|
||||
namespace irr
|
||||
{
|
||||
|
@ -182,4 +183,30 @@ enum EKEY_CODE
|
|||
KEY_KEY_CODES_COUNT = 0x100 // this is not a key, but the amount of keycodes there are.
|
||||
};
|
||||
|
||||
// A Keycode is either a character produced by the key or one of Irrlicht's codes (EKEY_CODE)
|
||||
class Keycode : public std::variant<EKEY_CODE, wchar_t> {
|
||||
using super = std::variant<EKEY_CODE, wchar_t>;
|
||||
public:
|
||||
Keycode() : Keycode(KEY_KEY_CODES_COUNT, L'\0') {}
|
||||
|
||||
Keycode(EKEY_CODE code, wchar_t ch)
|
||||
{
|
||||
emplace(code, ch);
|
||||
}
|
||||
|
||||
using super::emplace;
|
||||
void emplace(EKEY_CODE code, wchar_t ch)
|
||||
{
|
||||
if (isValid(code))
|
||||
emplace<EKEY_CODE>(code);
|
||||
else
|
||||
emplace<wchar_t>(ch);
|
||||
}
|
||||
|
||||
static bool isValid(EKEY_CODE code)
|
||||
{
|
||||
return code > 0 && code < KEY_KEY_CODES_COUNT;
|
||||
}
|
||||
};
|
||||
|
||||
} // end namespace irr
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue