From 472bf272a79d1461578eab2e9eba28f467a0c38b Mon Sep 17 00:00:00 2001 From: Hugh Sanderson Date: Thu, 12 Dec 2024 22:29:48 +0800 Subject: [PATCH] Call SDL3 start/stop text input. --- project/include/Display.h | 1 + project/include/TextField.h | 1 + project/src/common/TextField.cpp | 10 ++++++++++ project/src/sdl2/SDL2Stage.cpp | 10 ++++++++++ 4 files changed, 22 insertions(+) diff --git a/project/include/Display.h b/project/include/Display.h index 90919ebdb..90eede2ec 100644 --- a/project/include/Display.h +++ b/project/include/Display.h @@ -472,6 +472,7 @@ class Stage : public DisplayObjectContainer virtual void setTitle(const std::string &) { } virtual std::string getTitle() { return ""; } + virtual void setTextInput(bool enable) { } DisplayObject *GetFocusObject() { return mFocusObject; } diff --git a/project/include/TextField.h b/project/include/TextField.h index 9d2150c74..db1428455 100644 --- a/project/include/TextField.h +++ b/project/include/TextField.h @@ -212,6 +212,7 @@ class TextField : public DisplayObject bool IsCacheDirty(); void SyncSelection(); void Focus(); + void Unfocus(); void setCaretIndex(int inIndex); diff --git a/project/src/common/TextField.cpp b/project/src/common/TextField.cpp index 7b0b11268..cd926e990 100644 --- a/project/src/common/TextField.cpp +++ b/project/src/common/TextField.cpp @@ -600,9 +600,19 @@ void TextField::setSelection(int inStartIndex, int inEndIndex) SyncSelection(); } +void TextField::Unfocus() +{ + Stage *stage = getStage(); + if (stage) + stage->setTextInput(false); +} + void TextField::Focus() { + Stage *stage = getStage(); + if (stage) + stage->setTextInput(true); #if defined(IPHONE) || defined (ANDROID) || defined(WEBOS) || defined(BLACKBERRY) || defined(TIZEN) if (needsSoftKeyboard) { diff --git a/project/src/sdl2/SDL2Stage.cpp b/project/src/sdl2/SDL2Stage.cpp index 82f756d11..d6316a1ec 100644 --- a/project/src/sdl2/SDL2Stage.cpp +++ b/project/src/sdl2/SDL2Stage.cpp @@ -681,6 +681,16 @@ class SDLStage : public Stage SDL_SetWindowFullscreen(mSDLWindow, FullscreenMode); #endif } + + void setTextInput(bool enable) + { + #ifdef NME_SDL3 + if (enable) + SDL_StartTextInput(mSDLWindow); + else + SDL_StopTextInput(mSDLWindow); + #endif + } void SetScreenMode(ScreenMode m)