diff --git a/project/src/ExternalInterface.cpp b/project/src/ExternalInterface.cpp index 86394cbc0..39ccdcf3d 100644 --- a/project/src/ExternalInterface.cpp +++ b/project/src/ExternalInterface.cpp @@ -2490,28 +2490,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); @@ -4300,8 +4300,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 0f55748db..aae899923 100644 --- a/src/lime/_internal/backend/native/NativeCFFI.hx +++ b/src/lime/_internal/backend/native/NativeCFFI.hx @@ -225,9 +225,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; @@ -515,10 +515,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", @@ -1157,12 +1157,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 1843e6d4f..36bdedf7d 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 { @@ -246,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 @@ -256,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 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 a20c6f560..e43a0fa52 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;