From afbac6d35f3131f8f962f7f1c3d695ff5232b123 Mon Sep 17 00:00:00 2001 From: Josh Tynjala Date: Fri, 12 Sep 2025 12:24:38 -0700 Subject: [PATCH 1/2] some more API docs --- src/lime/ui/KeyCode.hx | 8 ++++++++ src/lime/ui/ScanCode.hx | 8 ++++++++ src/lime/ui/Window.hx | 43 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) diff --git a/src/lime/ui/KeyCode.hx b/src/lime/ui/KeyCode.hx index 1843e6d4f..54f0c3ddd 100644 --- a/src/lime/ui/KeyCode.hx +++ b/src/lime/ui/KeyCode.hx @@ -2,6 +2,14 @@ package lime.ui; import lime._internal.backend.native.NativeCFFI; +/** + Used by keyboard event listeners to identify which key was pressed + down or released. + + @see `lime.ui.Window.onKeyDown` + @see `lime.ui.Window.onKeyUp` + @see `lime.ui.ScanCode` +**/ @:access(lime._internal.backend.native.NativeCFFI) #if (haxe_ver >= 4.0) enum #else @:enum #end abstract KeyCode(Int) from Int to Int from UInt to UInt { diff --git a/src/lime/ui/ScanCode.hx b/src/lime/ui/ScanCode.hx index 52cca0a5d..1d115499e 100644 --- a/src/lime/ui/ScanCode.hx +++ b/src/lime/ui/ScanCode.hx @@ -2,6 +2,14 @@ package lime.ui; import lime._internal.backend.native.NativeCFFI; +/** + May be used to identify the scan code associated with the `KeyCode` passed + to keyboard event listeners. + + @see `lime.ui.Window.onKeyDown` + @see `lime.ui.Window.onKeyUp` + @see `lime.ui.KeyCode` +**/ @:access(lime._internal.backend.native.NativeCFFI) @:access(lime.ui.KeyCode) #if (haxe_ver >= 4.0) enum #else @:enum #end abstract ScanCode(Int) from Int to Int from UInt to UInt diff --git a/src/lime/ui/Window.hx b/src/lime/ui/Window.hx index 64810eba3..7c6bf088f 100644 --- a/src/lime/ui/Window.hx +++ b/src/lime/ui/Window.hx @@ -67,25 +67,68 @@ class Window public var onFocusOut(default, null) = new EventVoid>(); public var onFullscreen(default, null) = new EventVoid>(); public var onHide(default, null) = new EventVoid>(); + + /** + Fired when the user presses a key down when this window has focus. + **/ public var onKeyDown(default, null) = new EventKeyModifier->Void>(); + + /** + Fired when the user releases a key that was down. + **/ public var onKeyUp(default, null) = new EventKeyModifier->Void>(); + public var onLeave(default, null) = new EventVoid>(); + + /** + Fired when the window is maximized. + **/ public var onMaximize(default, null) = new EventVoid>(); + + /** + Fired when the window is minimized. + **/ public var onMinimize(default, null) = new EventVoid>(); + + /** + Fired when the user pressed a mouse button down. + **/ public var onMouseDown(default, null) = new EventFloat->MouseButton->Void>(); + + /** + Fired when the mouse is moved over the window. + **/ public var onMouseMove(default, null) = new EventFloat->Void>(); public var onMouseMoveRelative(default, null) = new EventFloat->Void>(); + + /** + Fired when the user releases a mouse button that was pressed down. + **/ public var onMouseUp(default, null) = new EventFloat->Int->Void>(); + + /** + Fired when the user interacts with the mouse wheel. + **/ public var onMouseWheel(default, null) = new EventFloat->MouseWheelMode->Void>(); + + /** + Fired when the window is moved to a new position. + **/ public var onMove(default, null) = new EventFloat->Void>(); public var onRender(default, null) = new EventVoid>(); public var onRenderContextLost(default, null) = new EventVoid>(); public var onRenderContextRestored(default, null) = new EventVoid>(); + + /** + Fired when the window is resized with new dimensions. + **/ public var onResize(default, null) = new EventInt->Void>(); + public var onRestore(default, null) = new EventVoid>(); public var onShow(default, null) = new EventVoid>(); public var onTextEdit(default, null) = new EventInt->Int->Void>(); public var onTextInput(default, null) = new EventVoid>(); + public var opacity(get, set):Float; public var parameters:Dynamic; public var resizable(get, set):Bool; From 05591ebdb0ca830c5b7cd6b175c2e7e7662fa804 Mon Sep 17 00:00:00 2001 From: Josh Tynjala Date: Fri, 12 Sep 2025 15:57:44 -0700 Subject: [PATCH 2/2] NativeCFFI: fix key_code_to_scan_code and key_code_from_scan_code They were using float values, but they should have been int values instead. The numeric type conversion was causing some kind of data loss that resulted in wrong values being returned in some cases. In particular, arrow keys. --- project/src/ExternalInterface.cpp | 12 ++++++------ src/lime/_internal/backend/native/NativeCFFI.hx | 16 ++++++++-------- src/lime/ui/KeyCode.hx | 4 ++-- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/project/src/ExternalInterface.cpp b/project/src/ExternalInterface.cpp index 1718f4aa0..93ac90a07 100644 --- a/project/src/ExternalInterface.cpp +++ b/project/src/ExternalInterface.cpp @@ -2427,28 +2427,28 @@ namespace lime { } - float lime_key_code_from_scan_code (float scanCode) { + int lime_key_code_from_scan_code (int scanCode) { return KeyCode::FromScanCode (scanCode); } - HL_PRIM float HL_NAME(hl_key_code_from_scan_code) (float scanCode) { + HL_PRIM int HL_NAME(hl_key_code_from_scan_code) (int scanCode) { return KeyCode::FromScanCode (scanCode); } - float lime_key_code_to_scan_code (float keyCode) { + int lime_key_code_to_scan_code (int keyCode) { return KeyCode::ToScanCode (keyCode); } - HL_PRIM float HL_NAME(hl_key_code_to_scan_code) (float keyCode) { + HL_PRIM int HL_NAME(hl_key_code_to_scan_code) (int keyCode) { return KeyCode::ToScanCode (keyCode); @@ -4197,8 +4197,8 @@ namespace lime { DEFINE_HL_PRIM (_I32, hl_joystick_get_num_hats, _I32); DEFINE_HL_PRIM (_TIMAGEBUFFER, hl_jpeg_decode_bytes, _TBYTES _BOOL _TIMAGEBUFFER); DEFINE_HL_PRIM (_TIMAGEBUFFER, hl_jpeg_decode_file, _STRING _BOOL _TIMAGEBUFFER); - DEFINE_HL_PRIM (_F32, hl_key_code_from_scan_code, _F32); - DEFINE_HL_PRIM (_F32, hl_key_code_to_scan_code, _F32); + DEFINE_HL_PRIM (_I32, hl_key_code_from_scan_code, _I32); + DEFINE_HL_PRIM (_I32, hl_key_code_to_scan_code, _I32); DEFINE_HL_PRIM (_VOID, hl_key_event_manager_register, _FUN (_VOID, _NO_ARG) _TKEY_EVENT); DEFINE_HL_PRIM (_BYTES, hl_locale_get_system_locale, _NO_ARG); DEFINE_HL_PRIM (_TBYTES, hl_lzma_compress, _TBYTES _TBYTES); diff --git a/src/lime/_internal/backend/native/NativeCFFI.hx b/src/lime/_internal/backend/native/NativeCFFI.hx index dd3403c8c..4efefb98a 100644 --- a/src/lime/_internal/backend/native/NativeCFFI.hx +++ b/src/lime/_internal/backend/native/NativeCFFI.hx @@ -219,9 +219,9 @@ class NativeCFFI @:cffi private static function lime_jpeg_decode_file(path:String, decodeData:Bool, buffer:Dynamic):Dynamic; - @:cffi private static function lime_key_code_from_scan_code(scanCode:Float32):Float32; + @:cffi private static function lime_key_code_from_scan_code(scanCode:Int):Int; - @:cffi private static function lime_key_code_to_scan_code(keyCode:Float32):Float32; + @:cffi private static function lime_key_code_to_scan_code(keyCode:Int):Int; @:cffi private static function lime_key_event_manager_register(callback:Dynamic, eventObject:Dynamic):Void; @@ -499,10 +499,10 @@ class NativeCFFI "lime_jpeg_decode_bytes", "oboo", false)); private static var lime_jpeg_decode_file = new cpp.CallableBool->cpp.Object->cpp.Object>(cpp.Prime._loadPrime("lime", "lime_jpeg_decode_file", "sboo", false)); - private static var lime_key_code_from_scan_code = new cpp.Callablecpp.Float32>(cpp.Prime._loadPrime("lime", "lime_key_code_from_scan_code", - "ff", false)); - private static var lime_key_code_to_scan_code = new cpp.Callablecpp.Float32>(cpp.Prime._loadPrime("lime", "lime_key_code_to_scan_code", - "ff", false)); + private static var lime_key_code_from_scan_code = new cpp.CallableInt>(cpp.Prime._loadPrime("lime", "lime_key_code_from_scan_code", + "ii", false)); + private static var lime_key_code_to_scan_code = new cpp.CallableInt>(cpp.Prime._loadPrime("lime", "lime_key_code_to_scan_code", + "ii", false)); private static var lime_key_event_manager_register = new cpp.Callablecpp.Object->cpp.Void>(cpp.Prime._loadPrime("lime", "lime_key_event_manager_register", "oov", false)); private static var lime_lzma_compress = new cpp.Callablecpp.Object->cpp.Object>(cpp.Prime._loadPrime("lime", "lime_lzma_compress", "ooo", @@ -1121,12 +1121,12 @@ class NativeCFFI return null; } - @:hlNative("lime", "hl_key_code_from_scan_code") private static function lime_key_code_from_scan_code(scanCode:hl.F32):hl.F32 + @:hlNative("lime", "hl_key_code_from_scan_code") private static function lime_key_code_from_scan_code(scanCode:Int):Int { return 0; } - @:hlNative("lime", "hl_key_code_to_scan_code") private static function lime_key_code_to_scan_code(keyCode:hl.F32):hl.F32 + @:hlNative("lime", "hl_key_code_to_scan_code") private static function lime_key_code_to_scan_code(keyCode:Int):Int { return 0; } diff --git a/src/lime/ui/KeyCode.hx b/src/lime/ui/KeyCode.hx index 54f0c3ddd..36bdedf7d 100644 --- a/src/lime/ui/KeyCode.hx +++ b/src/lime/ui/KeyCode.hx @@ -254,7 +254,7 @@ import lime._internal.backend.native.NativeCFFI; { #if (lime_cffi && !macro) var code:Int = scanCode; - return Std.int(NativeCFFI.lime_key_code_from_scan_code(code)); + return NativeCFFI.lime_key_code_from_scan_code(code); #else return KeyCode.UNKNOWN; #end @@ -264,7 +264,7 @@ import lime._internal.backend.native.NativeCFFI; { #if (lime_cffi && !macro) var code:Int = keyCode; - return Std.int(NativeCFFI.lime_key_code_to_scan_code(code)); + return NativeCFFI.lime_key_code_to_scan_code(code); #else return ScanCode.UNKNOWN; #end