Fix IME positioning with SDL2
This commit is contained in:
@@ -24,6 +24,7 @@
|
|||||||
#include "../fileio_func.h"
|
#include "../fileio_func.h"
|
||||||
#include "../framerate_type.h"
|
#include "../framerate_type.h"
|
||||||
#include "../window_func.h"
|
#include "../window_func.h"
|
||||||
|
#include "../window_gui.h"
|
||||||
#include "sdl2_v.h"
|
#include "sdl2_v.h"
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
@@ -361,14 +362,32 @@ bool VideoDriver_SDL::ClaimMousePointer()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void SetTextInputRect()
|
||||||
|
{
|
||||||
|
SDL_Rect winrect;
|
||||||
|
Point pt = _focused_window->GetCaretPosition();
|
||||||
|
winrect.x = _focused_window->left + pt.x;
|
||||||
|
winrect.y = _focused_window->top + pt.y;
|
||||||
|
winrect.w = 1;
|
||||||
|
winrect.h = FONT_HEIGHT_NORMAL;
|
||||||
|
SDL_SetTextInputRect(&winrect);
|
||||||
|
}
|
||||||
|
|
||||||
void VideoDriver_SDL::EditBoxGainedFocus()
|
void VideoDriver_SDL::EditBoxGainedFocus()
|
||||||
{
|
{
|
||||||
SDL_StartTextInput();
|
if (!this->edit_box_focused) {
|
||||||
|
SDL_StartTextInput();
|
||||||
|
this->edit_box_focused = true;
|
||||||
|
}
|
||||||
|
SetTextInputRect();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VideoDriver_SDL::EditBoxLostFocus()
|
void VideoDriver_SDL::EditBoxLostFocus()
|
||||||
{
|
{
|
||||||
SDL_StopTextInput();
|
if (this->edit_box_focused) {
|
||||||
|
SDL_StopTextInput();
|
||||||
|
this->edit_box_focused = false;
|
||||||
|
}
|
||||||
/* Clear any marked string from the current edit box. */
|
/* Clear any marked string from the current edit box. */
|
||||||
HandleTextInput(nullptr, true);
|
HandleTextInput(nullptr, true);
|
||||||
}
|
}
|
||||||
@@ -592,6 +611,7 @@ int VideoDriver_SDL::PollEvent()
|
|||||||
if (EditBoxInGlobalFocus()) {
|
if (EditBoxInGlobalFocus()) {
|
||||||
HandleTextInput(nullptr, true);
|
HandleTextInput(nullptr, true);
|
||||||
HandleTextInput(ev.text.text);
|
HandleTextInput(ev.text.text);
|
||||||
|
SetTextInputRect();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
WChar character;
|
WChar character;
|
||||||
|
@@ -45,6 +45,8 @@ public:
|
|||||||
private:
|
private:
|
||||||
int PollEvent();
|
int PollEvent();
|
||||||
bool CreateMainSurface(uint w, uint h, bool resize);
|
bool CreateMainSurface(uint w, uint h, bool resize);
|
||||||
|
|
||||||
|
bool edit_box_focused;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Factory for the SDL video driver. */
|
/** Factory for the SDL video driver. */
|
||||||
|
Reference in New Issue
Block a user