From 7d20efa165289db22c7ff620f1c59f422a025820 Mon Sep 17 00:00:00 2001 From: Yuqian Yang Date: Sat, 29 Nov 2025 23:03:02 +0800 Subject: Impl sdl input method context. --- src/platform/gui/sdl/Window.cpp | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) (limited to 'src/platform/gui/sdl/Window.cpp') diff --git a/src/platform/gui/sdl/Window.cpp b/src/platform/gui/sdl/Window.cpp index f4b0422e..a4dea5ad 100644 --- a/src/platform/gui/sdl/Window.cpp +++ b/src/platform/gui/sdl/Window.cpp @@ -8,6 +8,7 @@ #include "cru/platform/gui/sdl/Base.h" #include "cru/platform/gui/sdl/Cursor.h" #include "cru/platform/gui/sdl/Input.h" +#include "cru/platform/gui/sdl/InputMethod.h" #include "cru/platform/gui/sdl/UiApplication.h" #include @@ -25,6 +26,8 @@ SdlWindow::SdlWindow(SdlUiApplication* application) client_rect_(100, 100, 400, 200), parent_(nullptr) { application->RegisterWindow(this); + + input_context_ = std::make_unique(this); } SdlWindow::~SdlWindow() { application_->UnregisterWindow(this); } @@ -182,9 +185,13 @@ std::unique_ptr SdlWindow::BeginPaint() { NotImplemented(); } -IInputMethodContext* SdlWindow::GetInputMethodContext() { NotImplemented(); } +IInputMethodContext* SdlWindow::GetInputMethodContext() { + return input_context_.get(); +} + +SDL_Window* SdlWindow::GetSdlWindow() { return sdl_window_; } -std::optional SdlWindow::GetSdlWindow() { return sdl_window_; } +SDL_WindowID SdlWindow::GetSdlWindowId() { return sdl_window_id_; } SdlUiApplication* SdlWindow::GetSdlUiApplication() { return application_; } @@ -280,9 +287,39 @@ NativeMouseButtonEventArgs ConvertMouseButtonEvent( NativeKeyEventArgs ConvertKeyEvent(const SDL_KeyboardEvent& event) { return {ConvertKeyScanCode(event.scancode), ConvertKeyModifier(event.mod)}; } + +std::optional GetEventWindowId(const SDL_Event& event) { + switch (event.type) { + case SDL_EVENT_WINDOW_MOVED: + case SDL_EVENT_WINDOW_RESIZED: + case SDL_EVENT_WINDOW_SHOWN: + case SDL_EVENT_WINDOW_HIDDEN: + case SDL_EVENT_WINDOW_MINIMIZED: + case SDL_EVENT_WINDOW_FOCUS_GAINED: + case SDL_EVENT_WINDOW_FOCUS_LOST: + case SDL_EVENT_WINDOW_MOUSE_ENTER: + case SDL_EVENT_WINDOW_MOUSE_LEAVE: + case SDL_EVENT_WINDOW_DESTROYED: + return event.window.windowID; + case SDL_EVENT_MOUSE_BUTTON_DOWN: + case SDL_EVENT_MOUSE_BUTTON_UP: + return event.button.windowID; + case SDL_EVENT_MOUSE_WHEEL: + return event.wheel.windowID; + case SDL_EVENT_KEY_DOWN: + case SDL_EVENT_KEY_UP: + return event.key.windowID; + default: + return std::nullopt; + } +} } // namespace bool SdlWindow::HandleEvent(const SDL_Event* event) { + if (input_context_->HandleEvent(event)) return true; + + if (sdl_window_id_ != GetEventWindowId(*event)) return false; + switch (event->type) { case SDL_EVENT_WINDOW_MOVED: { client_rect_.left = event->window.data1; -- cgit v1.2.3