mirror of https://github.com/OpenTTD/OpenTTD
In particular this fixes handling of the shift keypull/7827/head
parent
1dba06656d
commit
a15ace0f5b
|
@ -23,6 +23,7 @@
|
||||||
#include "../core/math_func.hpp"
|
#include "../core/math_func.hpp"
|
||||||
#include "../fileio_func.h"
|
#include "../fileio_func.h"
|
||||||
#include "../framerate_type.h"
|
#include "../framerate_type.h"
|
||||||
|
#include "../window_func.h"
|
||||||
#include "sdl2_v.h"
|
#include "sdl2_v.h"
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
@ -354,6 +355,29 @@ bool VideoDriver_SDL::ClaimMousePointer()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is called to indicate that an edit box has gained focus, text input mode should be enabled.
|
||||||
|
*/
|
||||||
|
void VideoDriver_SDL::EditBoxGainedFocus()
|
||||||
|
{
|
||||||
|
if (!this->edit_box_focused) {
|
||||||
|
SDL_StartTextInput();
|
||||||
|
this->edit_box_focused = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is called to indicate that an edit box has lost focus, text input mode should be disabled.
|
||||||
|
*/
|
||||||
|
void VideoDriver_SDL::EditBoxLostFocus()
|
||||||
|
{
|
||||||
|
if (this->edit_box_focused) {
|
||||||
|
SDL_StopTextInput();
|
||||||
|
this->edit_box_focused = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
struct VkMapping {
|
struct VkMapping {
|
||||||
SDL_Keycode vk_from;
|
SDL_Keycode vk_from;
|
||||||
byte vk_count;
|
byte vk_count;
|
||||||
|
@ -444,7 +468,6 @@ static uint ConvertSdlKeyIntoMy(SDL_Keysym *sym, WChar *character)
|
||||||
|
|
||||||
/* The mod keys have no character. Prevent '?' */
|
/* The mod keys have no character. Prevent '?' */
|
||||||
if (sym->mod & KMOD_GUI ||
|
if (sym->mod & KMOD_GUI ||
|
||||||
sym->mod & KMOD_SHIFT ||
|
|
||||||
sym->mod & KMOD_CTRL ||
|
sym->mod & KMOD_CTRL ||
|
||||||
sym->mod & KMOD_ALT ||
|
sym->mod & KMOD_ALT ||
|
||||||
unprintable) {
|
unprintable) {
|
||||||
|
@ -550,7 +573,8 @@ int VideoDriver_SDL::PollEvent()
|
||||||
uint keycode = ConvertSdlKeyIntoMy(&ev.key.keysym, &character);
|
uint keycode = ConvertSdlKeyIntoMy(&ev.key.keysym, &character);
|
||||||
// Only handle non-text keys here. Text is handled in
|
// Only handle non-text keys here. Text is handled in
|
||||||
// SDL_TEXTINPUT below.
|
// SDL_TEXTINPUT below.
|
||||||
if (keycode == WKC_DELETE ||
|
if (!this->edit_box_focused ||
|
||||||
|
keycode == WKC_DELETE ||
|
||||||
keycode == WKC_NUM_ENTER ||
|
keycode == WKC_NUM_ENTER ||
|
||||||
keycode == WKC_LEFT ||
|
keycode == WKC_LEFT ||
|
||||||
keycode == WKC_RIGHT ||
|
keycode == WKC_RIGHT ||
|
||||||
|
@ -559,7 +583,6 @@ int VideoDriver_SDL::PollEvent()
|
||||||
keycode == WKC_HOME ||
|
keycode == WKC_HOME ||
|
||||||
keycode == WKC_END ||
|
keycode == WKC_END ||
|
||||||
keycode & WKC_META ||
|
keycode & WKC_META ||
|
||||||
keycode & WKC_SHIFT ||
|
|
||||||
keycode & WKC_CTRL ||
|
keycode & WKC_CTRL ||
|
||||||
keycode & WKC_ALT ||
|
keycode & WKC_ALT ||
|
||||||
(keycode >= WKC_F1 && keycode <= WKC_F12) ||
|
(keycode >= WKC_F1 && keycode <= WKC_F12) ||
|
||||||
|
@ -570,12 +593,17 @@ int VideoDriver_SDL::PollEvent()
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_TEXTINPUT: {
|
case SDL_TEXTINPUT: {
|
||||||
WChar character;
|
if (!this->edit_box_focused) break;
|
||||||
SDL_Keycode kc = SDL_GetKeyFromName(ev.text.text);
|
SDL_Keycode kc = SDL_GetKeyFromName(ev.text.text);
|
||||||
uint keycode = ConvertSdlKeycodeIntoMy(kc);
|
uint keycode = ConvertSdlKeycodeIntoMy(kc);
|
||||||
|
|
||||||
Utf8Decode(&character, ev.text.text);
|
if (keycode == WKC_BACKQUOTE && FocusedWindowIsConsole()) {
|
||||||
HandleKeypress(keycode, character);
|
WChar character;
|
||||||
|
Utf8Decode(&character, ev.text.text);
|
||||||
|
HandleKeypress(keycode, character);
|
||||||
|
} else {
|
||||||
|
HandleTextInput(ev.text.text);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SDL_WINDOWEVENT: {
|
case SDL_WINDOWEVENT: {
|
||||||
|
@ -628,6 +656,9 @@ const char *VideoDriver_SDL::Start(const char * const *parm)
|
||||||
|
|
||||||
_draw_threaded = GetDriverParam(parm, "no_threads") == nullptr && GetDriverParam(parm, "no_thread") == nullptr;
|
_draw_threaded = GetDriverParam(parm, "no_threads") == nullptr && GetDriverParam(parm, "no_thread") == nullptr;
|
||||||
|
|
||||||
|
SDL_StopTextInput();
|
||||||
|
this->edit_box_focused = false;
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,10 +37,19 @@ public:
|
||||||
|
|
||||||
bool ClaimMousePointer() override;
|
bool ClaimMousePointer() override;
|
||||||
|
|
||||||
|
void EditBoxGainedFocus() override;
|
||||||
|
|
||||||
|
void EditBoxLostFocus() override;
|
||||||
|
|
||||||
const char *GetName() const override { return "sdl"; }
|
const char *GetName() const override { return "sdl"; }
|
||||||
private:
|
private:
|
||||||
int PollEvent();
|
int PollEvent();
|
||||||
bool CreateMainSurface(uint w, uint h, bool resize);
|
bool CreateMainSurface(uint w, uint h, bool resize);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is true to indicate that keyboard input is in text input mode, and SDL_TEXTINPUT events are enabled.
|
||||||
|
*/
|
||||||
|
bool edit_box_focused;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Factory for the SDL video driver. */
|
/** Factory for the SDL video driver. */
|
||||||
|
|
Loading…
Reference in New Issue