|
@@ -36,6 +36,16 @@ namespace keyboard
|
|
|
namespace sdl
|
|
|
{
|
|
|
|
|
|
+#if SDL_VERSION_ATLEAST(3, 0, 0)
|
|
|
+static SDL_Window *getSDLWindow()
|
|
|
+{
|
|
|
+ auto window = Module::getInstance<window::Window>(Module::M_WINDOW);
|
|
|
+ if (window)
|
|
|
+ return (SDL_Window *) window->getHandle();
|
|
|
+ return nullptr;
|
|
|
+}
|
|
|
+#endif
|
|
|
+
|
|
|
Keyboard::Keyboard()
|
|
|
: love::keyboard::Keyboard("love.keyboard.sdl")
|
|
|
, key_repeat(false)
|
|
@@ -54,14 +64,22 @@ bool Keyboard::hasKeyRepeat() const
|
|
|
|
|
|
bool Keyboard::isDown(const std::vector<Key> &keylist) const
|
|
|
{
|
|
|
+#if SDL_VERSION_ATLEAST(3, 0, 0)
|
|
|
+ const bool *state = SDL_GetKeyboardState(nullptr);
|
|
|
+#else
|
|
|
const Uint8 *state = SDL_GetKeyboardState(nullptr);
|
|
|
+#endif
|
|
|
|
|
|
for (Key key : keylist)
|
|
|
{
|
|
|
SDL_Keycode sdlkey = SDLK_UNKNOWN;
|
|
|
if (getConstant(key, sdlkey))
|
|
|
{
|
|
|
+#if SDL_VERSION_ATLEAST(3, 0, 0)
|
|
|
+ SDL_Scancode scancode = SDL_GetScancodeFromKey(sdlkey, nullptr);
|
|
|
+#else
|
|
|
SDL_Scancode scancode = SDL_GetScancodeFromKey(sdlkey);
|
|
|
+#endif
|
|
|
if (state[scancode])
|
|
|
return true;
|
|
|
}
|
|
@@ -72,7 +90,11 @@ bool Keyboard::isDown(const std::vector<Key> &keylist) const
|
|
|
|
|
|
bool Keyboard::isScancodeDown(const std::vector<Scancode> &scancodelist) const
|
|
|
{
|
|
|
+#if SDL_VERSION_ATLEAST(3, 0, 0)
|
|
|
+ const bool *state = SDL_GetKeyboardState(nullptr);
|
|
|
+#else
|
|
|
const Uint8 *state = SDL_GetKeyboardState(nullptr);
|
|
|
+#endif
|
|
|
|
|
|
for (Scancode scancode : scancodelist)
|
|
|
{
|
|
@@ -122,7 +144,11 @@ Keyboard::Key Keyboard::getKeyFromScancode(Scancode scancode) const
|
|
|
SDL_Scancode sdlscancode = SDL_SCANCODE_UNKNOWN;
|
|
|
scancodes.find(scancode, sdlscancode);
|
|
|
|
|
|
+#if SDL_VERSION_ATLEAST(3, 0, 0)
|
|
|
+ SDL_Keycode sdlkey = SDL_GetKeyFromScancode(sdlscancode, SDL_KMOD_NONE, false);
|
|
|
+#else
|
|
|
SDL_Keycode sdlkey = SDL_GetKeyFromScancode(sdlscancode);
|
|
|
+#endif
|
|
|
|
|
|
Key key = KEY_UNKNOWN;
|
|
|
getConstant(sdlkey, key);
|
|
@@ -136,7 +162,11 @@ Keyboard::Scancode Keyboard::getScancodeFromKey(Key key) const
|
|
|
SDL_Keycode sdlkey = SDLK_UNKNOWN;
|
|
|
if (getConstant(key, sdlkey))
|
|
|
{
|
|
|
+#if SDL_VERSION_ATLEAST(3, 0, 0)
|
|
|
+ SDL_Scancode sdlscancode = SDL_GetScancodeFromKey(sdlkey, nullptr);
|
|
|
+#else
|
|
|
SDL_Scancode sdlscancode = SDL_GetScancodeFromKey(sdlkey);
|
|
|
+#endif
|
|
|
scancodes.find(sdlscancode, scancode);
|
|
|
}
|
|
|
|
|
@@ -145,10 +175,20 @@ Keyboard::Scancode Keyboard::getScancodeFromKey(Key key) const
|
|
|
|
|
|
void Keyboard::setTextInput(bool enable)
|
|
|
{
|
|
|
+#if SDL_VERSION_ATLEAST(3, 0, 0)
|
|
|
+ SDL_Window *window = getSDLWindow();
|
|
|
+ if (window == nullptr)
|
|
|
+ return;
|
|
|
+ if (enable)
|
|
|
+ SDL_StartTextInput(window);
|
|
|
+ else
|
|
|
+ SDL_StopTextInput(window);
|
|
|
+#else
|
|
|
if (enable)
|
|
|
SDL_StartTextInput();
|
|
|
else
|
|
|
SDL_StopTextInput();
|
|
|
+#endif
|
|
|
}
|
|
|
|
|
|
void Keyboard::setTextInput(bool enable, double x, double y, double w, double h)
|
|
@@ -163,7 +203,14 @@ void Keyboard::setTextInput(bool enable, double x, double y, double w, double h)
|
|
|
}
|
|
|
|
|
|
SDL_Rect rect = {(int) x, (int) y, (int) w, (int) h};
|
|
|
+
|
|
|
+#if SDL_VERSION_ATLEAST(3, 0, 0)
|
|
|
+ SDL_Window *sdlwindow = getSDLWindow();
|
|
|
+ if (sdlwindow != nullptr)
|
|
|
+ SDL_SetTextInputArea(sdlwindow, &rect, 0);
|
|
|
+#else
|
|
|
SDL_SetTextInputRect(&rect);
|
|
|
+#endif
|
|
|
|
|
|
setTextInput(enable);
|
|
|
}
|
|
@@ -171,7 +218,10 @@ void Keyboard::setTextInput(bool enable, double x, double y, double w, double h)
|
|
|
bool Keyboard::hasTextInput() const
|
|
|
{
|
|
|
#if SDL_VERSION_ATLEAST(3, 0, 0)
|
|
|
- return SDL_TextInputActive();
|
|
|
+ SDL_Window *window = getSDLWindow();
|
|
|
+ if (window == nullptr)
|
|
|
+ return false;
|
|
|
+ return SDL_TextInputActive(window);
|
|
|
#else
|
|
|
return SDL_IsTextInputActive() != SDL_FALSE;
|
|
|
#endif
|
|
@@ -179,7 +229,11 @@ bool Keyboard::hasTextInput() const
|
|
|
|
|
|
bool Keyboard::hasScreenKeyboard() const
|
|
|
{
|
|
|
+#if SDL_VERSION_ATLEAST(3, 0, 0)
|
|
|
+ return SDL_HasScreenKeyboardSupport();
|
|
|
+#else
|
|
|
return SDL_HasScreenKeyboardSupport() != SDL_FALSE;
|
|
|
+#endif
|
|
|
}
|
|
|
|
|
|
bool Keyboard::getConstant(Key in, SDL_Keycode &out)
|
|
@@ -363,6 +417,14 @@ std::map<Keyboard::Key, SDL_Keycode> Keyboard::keyToSDLKey =
|
|
|
|
|
|
{ KEY_MODE, SDLK_MODE },
|
|
|
|
|
|
+#if SDL_VERSION_ATLEAST(3, 0, 0)
|
|
|
+ { KEY_AUDIONEXT, SDLK_MEDIA_NEXT_TRACK },
|
|
|
+ { KEY_AUDIOPREV, SDLK_MEDIA_PREVIOUS_TRACK },
|
|
|
+ { KEY_AUDIOSTOP, SDLK_MEDIA_STOP },
|
|
|
+ { KEY_AUDIOPLAY, SDLK_MEDIA_PLAY },
|
|
|
+ { KEY_AUDIOMUTE, SDLK_MUTE },
|
|
|
+ { KEY_MEDIASELECT, SDLK_MEDIA_SELECT },
|
|
|
+#else
|
|
|
{ KEY_AUDIONEXT, SDLK_AUDIONEXT },
|
|
|
{ KEY_AUDIOPREV, SDLK_AUDIOPREV },
|
|
|
{ KEY_AUDIOSTOP, SDLK_AUDIOSTOP },
|
|
@@ -373,6 +435,7 @@ std::map<Keyboard::Key, SDL_Keycode> Keyboard::keyToSDLKey =
|
|
|
{ KEY_MAIL, SDLK_MAIL },
|
|
|
{ KEY_CALCULATOR, SDLK_CALCULATOR },
|
|
|
{ KEY_COMPUTER, SDLK_COMPUTER },
|
|
|
+#endif
|
|
|
{ KEY_APP_SEARCH, SDLK_AC_SEARCH },
|
|
|
{ KEY_APP_HOME, SDLK_AC_HOME },
|
|
|
{ KEY_APP_BACK, SDLK_AC_BACK },
|
|
@@ -381,6 +444,9 @@ std::map<Keyboard::Key, SDL_Keycode> Keyboard::keyToSDLKey =
|
|
|
{ KEY_APP_REFRESH, SDLK_AC_REFRESH },
|
|
|
{ KEY_APP_BOOKMARKS, SDLK_AC_BOOKMARKS },
|
|
|
|
|
|
+#if SDL_VERSION_ATLEAST(3, 0, 0)
|
|
|
+ { KEY_EJECT, SDLK_MEDIA_EJECT },
|
|
|
+#else
|
|
|
{ KEY_BRIGHTNESSDOWN, SDLK_BRIGHTNESSDOWN },
|
|
|
{ KEY_BRIGHTNESSUP, SDLK_BRIGHTNESSUP },
|
|
|
{ KEY_DISPLAYSWITCH, SDLK_DISPLAYSWITCH },
|
|
@@ -388,12 +454,17 @@ std::map<Keyboard::Key, SDL_Keycode> Keyboard::keyToSDLKey =
|
|
|
{ KEY_KBDILLUMDOWN, SDLK_KBDILLUMDOWN },
|
|
|
{ KEY_KBDILLUMUP, SDLK_KBDILLUMUP },
|
|
|
{ KEY_EJECT, SDLK_EJECT },
|
|
|
+#endif
|
|
|
{ KEY_SLEEP, SDLK_SLEEP },
|
|
|
};
|
|
|
|
|
|
std::map<SDL_Keycode, Keyboard::Key> Keyboard::sdlKeyToKey;
|
|
|
|
|
|
+#if SDL_VERSION_ATLEAST(3, 0, 0)
|
|
|
+EnumMap<Keyboard::Scancode, SDL_Scancode, SDL_SCANCODE_COUNT>::Entry Keyboard::scancodeEntries[] =
|
|
|
+#else
|
|
|
EnumMap<Keyboard::Scancode, SDL_Scancode, SDL_NUM_SCANCODES>::Entry Keyboard::scancodeEntries[] =
|
|
|
+#endif
|
|
|
{
|
|
|
{SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN},
|
|
|
|
|
@@ -624,6 +695,14 @@ EnumMap<Keyboard::Scancode, SDL_Scancode, SDL_NUM_SCANCODES>::Entry Keyboard::sc
|
|
|
|
|
|
{SCANCODE_MODE, SDL_SCANCODE_MODE},
|
|
|
|
|
|
+#if SDL_VERSION_ATLEAST(3, 0, 0)
|
|
|
+ {SCANCODE_AUDIONEXT, SDL_SCANCODE_MEDIA_NEXT_TRACK},
|
|
|
+ {SCANCODE_AUDIOPREV, SDL_SCANCODE_MEDIA_PREVIOUS_TRACK},
|
|
|
+ {SCANCODE_AUDIOSTOP, SDL_SCANCODE_MEDIA_STOP},
|
|
|
+ {SCANCODE_AUDIOPLAY, SDL_SCANCODE_MEDIA_PLAY},
|
|
|
+ {SCANCODE_AUDIOMUTE, SDL_SCANCODE_MUTE},
|
|
|
+ {SCANCODE_MEDIASELECT, SDL_SCANCODE_MEDIA_SELECT},
|
|
|
+#else
|
|
|
{SCANCODE_AUDIONEXT, SDL_SCANCODE_AUDIONEXT},
|
|
|
{SCANCODE_AUDIOPREV, SDL_SCANCODE_AUDIOPREV},
|
|
|
{SCANCODE_AUDIOSTOP, SDL_SCANCODE_AUDIOSTOP},
|
|
@@ -634,6 +713,7 @@ EnumMap<Keyboard::Scancode, SDL_Scancode, SDL_NUM_SCANCODES>::Entry Keyboard::sc
|
|
|
{SCANCODE_MAIL, SDL_SCANCODE_MAIL},
|
|
|
{SCANCODE_CALCULATOR, SDL_SCANCODE_CALCULATOR},
|
|
|
{SCANCODE_COMPUTER, SDL_SCANCODE_COMPUTER},
|
|
|
+#endif
|
|
|
{SCANCODE_AC_SEARCH, SDL_SCANCODE_AC_SEARCH},
|
|
|
{SCANCODE_AC_HOME, SDL_SCANCODE_AC_HOME},
|
|
|
{SCANCODE_AC_BACK, SDL_SCANCODE_AC_BACK},
|
|
@@ -642,6 +722,10 @@ EnumMap<Keyboard::Scancode, SDL_Scancode, SDL_NUM_SCANCODES>::Entry Keyboard::sc
|
|
|
{SCANCODE_AC_REFRESH, SDL_SCANCODE_AC_REFRESH},
|
|
|
{SCANCODE_AC_BOOKMARKS, SDL_SCANCODE_AC_BOOKMARKS},
|
|
|
|
|
|
+#if SDL_VERSION_ATLEAST(3, 0, 0)
|
|
|
+ {SCANCODE_EJECT, SDL_SCANCODE_MEDIA_EJECT},
|
|
|
+ {SCANCODE_SLEEP, SDL_SCANCODE_SLEEP},
|
|
|
+#else
|
|
|
{SCANCODE_BRIGHTNESSDOWN, SDL_SCANCODE_BRIGHTNESSDOWN},
|
|
|
{SCANCODE_BRIGHTNESSUP, SDL_SCANCODE_BRIGHTNESSUP},
|
|
|
{SCANCODE_DISPLAYSWITCH, SDL_SCANCODE_DISPLAYSWITCH},
|
|
@@ -653,9 +737,14 @@ EnumMap<Keyboard::Scancode, SDL_Scancode, SDL_NUM_SCANCODES>::Entry Keyboard::sc
|
|
|
|
|
|
{SCANCODE_APP1, SDL_SCANCODE_APP1},
|
|
|
{SCANCODE_APP2, SDL_SCANCODE_APP2},
|
|
|
+#endif
|
|
|
};
|
|
|
|
|
|
+#if SDL_VERSION_ATLEAST(3, 0, 0)
|
|
|
+EnumMap<Keyboard::Scancode, SDL_Scancode, SDL_SCANCODE_COUNT> Keyboard::scancodes(Keyboard::scancodeEntries, sizeof(Keyboard::scancodeEntries));
|
|
|
+#else
|
|
|
EnumMap<Keyboard::Scancode, SDL_Scancode, SDL_NUM_SCANCODES> Keyboard::scancodes(Keyboard::scancodeEntries, sizeof(Keyboard::scancodeEntries));
|
|
|
+#endif
|
|
|
|
|
|
} // sdl
|
|
|
} // keyboard
|