blob: 0cd22544da8e1cfaa4ecd337d5f956e158da7ecc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#include "cru/platform/gui/sdl/InputMethod.h"
#include "SDL3/SDL_events.h"
#include "cru/platform/gui/sdl/Base.h"
#include "cru/platform/gui/sdl/Window.h"
#include <SDL3/SDL_keyboard.h>
namespace cru::platform::gui::sdl {
SdlInputMethodContext::SdlInputMethodContext(SdlWindow* window)
: window_(window) {}
bool SdlInputMethodContext::ShouldManuallyDrawCompositionText() {
return false;
}
void SdlInputMethodContext::EnableIME() {
if (auto sdl_window = window_->GetSdlWindow()) {
CheckSdlReturn(SDL_StartTextInput(sdl_window));
}
}
void SdlInputMethodContext::DisableIME() {
if (auto sdl_window = window_->GetSdlWindow()) {
CheckSdlReturn(SDL_StopTextInput(sdl_window));
}
}
void SdlInputMethodContext::CompleteComposition() { CancelComposition(); }
void SdlInputMethodContext::CancelComposition() {
if (auto sdl_window = window_->GetSdlWindow()) {
CheckSdlReturn(SDL_ClearComposition(sdl_window));
}
}
CompositionText SdlInputMethodContext::GetCompositionText() { return {}; }
void SdlInputMethodContext::SetCandidateWindowPosition(const Point& point) {
if (auto sdl_window = window_->GetSdlWindow()) {
SDL_Rect rect{static_cast<int>(point.x), static_cast<int>(point.y), 1, 1};
CheckSdlReturn(SDL_SetTextInputArea(sdl_window, &rect, 0));
}
}
namespace {
std::optional<SDL_WindowID> GetEventWindowId(const SDL_Event& event) {
switch (event.type) {
case SDL_EVENT_TEXT_INPUT:
return event.text.windowID;
default:
return std::nullopt;
}
}
} // namespace
bool SdlInputMethodContext::HandleEvent(const SDL_Event* event) {
if (window_->GetSdlWindowId() != GetEventWindowId(*event)) return false;
if (event->type == SDL_EVENT_TEXT_INPUT) {
std::string text(event->text.text);
TextEvent_.Raise(text);
return true;
}
return false;
}
} // namespace cru::platform::gui::sdl
|