From 81d682d355dfeaeb74c40d907283a1c7d7e66258 Mon Sep 17 00:00:00 2001 From: Josh Tynjala Date: Thu, 9 Jun 2022 14:14:05 -0700 Subject: [PATCH] Window: add new setTextInputRect() method to optionally specify the location of the input when textInputEnabled is set to true On native, this uses SDL_SetTextInputRect --- project/include/ui/Window.h | 1 + project/src/ExternalInterface.cpp | 19 +++++++++++++++++++ project/src/backend/sdl/SDLWindow.cpp | 17 +++++++++++++++++ project/src/backend/sdl/SDLWindow.h | 1 + .../_internal/backend/flash/FlashWindow.hx | 6 ++++++ .../_internal/backend/html5/HTML5Window.hx | 6 ++++++ .../_internal/backend/native/NativeCFFI.hx | 8 ++++++++ .../_internal/backend/native/NativeWindow.hx | 12 ++++++++++++ src/lime/ui/Window.hx | 5 +++++ 9 files changed, 75 insertions(+) diff --git a/project/include/ui/Window.h b/project/include/ui/Window.h index 579f0b3c4..81e454f10 100644 --- a/project/include/ui/Window.h +++ b/project/include/ui/Window.h @@ -57,6 +57,7 @@ namespace lime { virtual void SetMouseLock (bool mouseLock) = 0; virtual bool SetResizable (bool resizable) = 0; virtual void SetTextInputEnabled (bool enable) = 0; + virtual void SetTextInputRect (Rectangle *rect) = 0; virtual const char* SetTitle (const char* title) = 0; virtual void WarpMouse (int x, int y) = 0; diff --git a/project/src/ExternalInterface.cpp b/project/src/ExternalInterface.cpp index 05969826e..08195e7eb 100644 --- a/project/src/ExternalInterface.cpp +++ b/project/src/ExternalInterface.cpp @@ -3668,6 +3668,23 @@ namespace lime { } + void lime_window_set_text_input_rect (value window, value rect) { + + Window* targetWindow = (Window*)val_data (window); + Rectangle _rect = Rectangle (rect); + targetWindow->SetTextInputRect (&_rect); + + } + + + HL_PRIM void HL_NAME(hl_window_set_text_input_rect) (HL_CFFIPointer* window, Rectangle* rect) { + + Window* targetWindow = (Window*)window->ptr; + targetWindow->SetTextInputRect (rect); + + } + + value lime_window_set_title (value window, HxString title) { Window* targetWindow = (Window*)val_data (window); @@ -3931,6 +3948,7 @@ namespace lime { DEFINE_PRIME2v (lime_window_set_mouse_lock); DEFINE_PRIME2 (lime_window_set_resizable); DEFINE_PRIME2v (lime_window_set_text_input_enabled); + DEFINE_PRIME2v (lime_window_set_text_input_rect); DEFINE_PRIME2 (lime_window_set_title); DEFINE_PRIME3v (lime_window_warp_mouse); DEFINE_PRIME2 (lime_zlib_compress); @@ -4114,6 +4132,7 @@ namespace lime { DEFINE_HL_PRIM (_VOID, hl_window_set_mouse_lock, _TCFFIPOINTER _BOOL); DEFINE_HL_PRIM (_BOOL, hl_window_set_resizable, _TCFFIPOINTER _BOOL); DEFINE_HL_PRIM (_VOID, hl_window_set_text_input_enabled, _TCFFIPOINTER _BOOL); + DEFINE_HL_PRIM (_VOID, hl_window_set_text_input_rect, _TCFFIPOINTER _TRECTANGLE); DEFINE_HL_PRIM (_STRING, hl_window_set_title, _TCFFIPOINTER _STRING); DEFINE_HL_PRIM (_VOID, hl_window_warp_mouse, _TCFFIPOINTER _I32 _I32); DEFINE_HL_PRIM (_TBYTES, hl_zlib_compress, _TBYTES _TBYTES); diff --git a/project/src/backend/sdl/SDLWindow.cpp b/project/src/backend/sdl/SDLWindow.cpp index 3f842e34c..2c54ec997 100644 --- a/project/src/backend/sdl/SDLWindow.cpp +++ b/project/src/backend/sdl/SDLWindow.cpp @@ -1050,6 +1050,23 @@ namespace lime { } + void SDLWindow::SetTextInputRect (Rectangle * rect) { + + SDL_Rect bounds = { 0, 0, 0, 0 }; + + if (rect) { + + bounds.x = rect->x; + bounds.y = rect->y; + bounds.w = rect->width; + bounds.h = rect->height; + + } + + SDL_SetTextInputRect(&bounds); + } + + const char* SDLWindow::SetTitle (const char* title) { SDL_SetWindowTitle (sdlWindow, title); diff --git a/project/src/backend/sdl/SDLWindow.h b/project/src/backend/sdl/SDLWindow.h index f18c713a9..c3769ef18 100644 --- a/project/src/backend/sdl/SDLWindow.h +++ b/project/src/backend/sdl/SDLWindow.h @@ -51,6 +51,7 @@ namespace lime { virtual void SetMouseLock (bool mouseLock); virtual bool SetResizable (bool resizable); virtual void SetTextInputEnabled (bool enabled); + virtual void SetTextInputRect (Rectangle *rect); virtual const char* SetTitle (const char* title); virtual void WarpMouse (int x, int y); diff --git a/src/lime/_internal/backend/flash/FlashWindow.hx b/src/lime/_internal/backend/flash/FlashWindow.hx index b106648fa..f61fe3d73 100644 --- a/src/lime/_internal/backend/flash/FlashWindow.hx +++ b/src/lime/_internal/backend/flash/FlashWindow.hx @@ -47,6 +47,7 @@ class FlashWindow private var mouseLeft:Bool; private var parent:Window; private var textInputEnabled:Bool; + private var textInputRect:Rectangle; private var unusedTouchesPool = new List(); public function new(parent:Window) @@ -622,6 +623,11 @@ class FlashWindow return textInputEnabled = value; } + public function setTextInputRect(value:Rectangle):Rectangle + { + return textInputRect = value; + } + public function setTitle(value:String):String { return value; diff --git a/src/lime/_internal/backend/html5/HTML5Window.hx b/src/lime/_internal/backend/html5/HTML5Window.hx index 376216bad..c938bd193 100644 --- a/src/lime/_internal/backend/html5/HTML5Window.hx +++ b/src/lime/_internal/backend/html5/HTML5Window.hx @@ -73,6 +73,7 @@ class HTML5Window private var setHeight:Int; private var setWidth:Int; private var textInputEnabled:Bool; + private var textInputRect:Rectangle; private var unusedTouchesPool = new List(); public function new(parent:Window) @@ -1165,6 +1166,11 @@ class HTML5Window return textInputEnabled = value; } + public function setTextInputRect(value:Rectangle):Rectangle + { + return textInputRect = value; + } + private var inputing = false; public function handleCompositionstartEvent(e):Void diff --git a/src/lime/_internal/backend/native/NativeCFFI.hx b/src/lime/_internal/backend/native/NativeCFFI.hx index 774ab6a27..a3da6319b 100644 --- a/src/lime/_internal/backend/native/NativeCFFI.hx +++ b/src/lime/_internal/backend/native/NativeCFFI.hx @@ -341,6 +341,8 @@ class NativeCFFI @:cffi private static function lime_window_set_text_input_enabled(handle:Dynamic, enabled:Bool):Void; + @:cffi private static function lime_window_set_text_input_rect(handle:Dynamic, rect:Dynamic):Void; + @:cffi private static function lime_window_set_title(handle:Dynamic, title:String):Dynamic; @:cffi private static function lime_window_warp_mouse(handle:Dynamic, x:Int, y:Int):Void; @@ -593,6 +595,8 @@ class NativeCFFI false)); private static var lime_window_set_text_input_enabled = new cpp.CallableBool->cpp.Void>(cpp.Prime._loadPrime("lime", "lime_window_set_text_input_enabled", "obv", false)); + private static var lime_window_set_text_input_rect = new cpp.Callablecpp.Object->cpp.Void>(cpp.Prime._loadPrime("lime", + "lime_window_set_text_input_rect", "oov", false)); private static var lime_window_set_title = new cpp.CallableString->cpp.Object>(cpp.Prime._loadPrime("lime", "lime_window_set_title", "oso", false)); private static var lime_window_warp_mouse = new cpp.CallableInt->Int->cpp.Object>(cpp.Prime._loadPrime("lime", "lime_window_warp_mouse", @@ -747,6 +751,7 @@ class NativeCFFI private static var lime_window_set_mouse_lock = CFFI.load("lime", "lime_window_set_mouse_lock", 2); private static var lime_window_set_resizable = CFFI.load("lime", "lime_window_set_resizable", 2); private static var lime_window_set_text_input_enabled = CFFI.load("lime", "lime_window_set_text_input_enabled", 2); + private static var lime_window_set_text_input_rect = CFFI.load("lime", "lime_window_set_text_input_rect", 2); private static var lime_window_set_title = CFFI.load("lime", "lime_window_set_title", 2); private static var lime_window_warp_mouse = CFFI.load("lime", "lime_window_warp_mouse", 3); private static var lime_window_event_manager_register = CFFI.load("lime", "lime_window_event_manager_register", 2); @@ -1342,6 +1347,9 @@ class NativeCFFI @:hlNative("lime", "hl_window_set_text_input_enabled") private static function lime_window_set_text_input_enabled(handle:CFFIPointer, enabled:Bool):Void {} + @:hlNative("lime", "hl_window_set_text_input_rect") private static function lime_window_set_text_input_rect(handle:CFFIPointer, + rect:Rectangle):Void {} + @:hlNative("lime", "hl_window_set_title") private static function lime_window_set_title(handle:CFFIPointer, title:String):String { return null; diff --git a/src/lime/_internal/backend/native/NativeWindow.hx b/src/lime/_internal/backend/native/NativeWindow.hx index d3c67b88f..15a01b05c 100644 --- a/src/lime/_internal/backend/native/NativeWindow.hx +++ b/src/lime/_internal/backend/native/NativeWindow.hx @@ -546,6 +546,18 @@ class NativeWindow return value; } + public function setTextInputRect(value:Rectangle):Rectangle + { + if (handle != null) + { + #if (!macro && lime_cffi) + NativeCFFI.lime_window_set_text_input_rect(handle, value); + #end + } + + return value; + } + public function setFrameRate(value:Float):Float { // TODO: Support multiple independent frame rates per window diff --git a/src/lime/ui/Window.hx b/src/lime/ui/Window.hx index b3d35b3cf..1cdc8dd73 100644 --- a/src/lime/ui/Window.hx +++ b/src/lime/ui/Window.hx @@ -544,6 +544,11 @@ class Window return __backend.setTextInputEnabled(value); } + public function setTextInputRect(value:Rectangle):Rectangle + { + return __backend.setTextInputRect(value); + } + @:noCompletion private inline function get_title():String { return __title;