Skip to content

Commit 05591eb

Browse files
committed
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.
1 parent afbac6d commit 05591eb

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

project/src/ExternalInterface.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2427,28 +2427,28 @@ namespace lime {
24272427
}
24282428

24292429

2430-
float lime_key_code_from_scan_code (float scanCode) {
2430+
int lime_key_code_from_scan_code (int scanCode) {
24312431

24322432
return KeyCode::FromScanCode (scanCode);
24332433

24342434
}
24352435

24362436

2437-
HL_PRIM float HL_NAME(hl_key_code_from_scan_code) (float scanCode) {
2437+
HL_PRIM int HL_NAME(hl_key_code_from_scan_code) (int scanCode) {
24382438

24392439
return KeyCode::FromScanCode (scanCode);
24402440

24412441
}
24422442

24432443

2444-
float lime_key_code_to_scan_code (float keyCode) {
2444+
int lime_key_code_to_scan_code (int keyCode) {
24452445

24462446
return KeyCode::ToScanCode (keyCode);
24472447

24482448
}
24492449

24502450

2451-
HL_PRIM float HL_NAME(hl_key_code_to_scan_code) (float keyCode) {
2451+
HL_PRIM int HL_NAME(hl_key_code_to_scan_code) (int keyCode) {
24522452

24532453
return KeyCode::ToScanCode (keyCode);
24542454

@@ -4197,8 +4197,8 @@ namespace lime {
41974197
DEFINE_HL_PRIM (_I32, hl_joystick_get_num_hats, _I32);
41984198
DEFINE_HL_PRIM (_TIMAGEBUFFER, hl_jpeg_decode_bytes, _TBYTES _BOOL _TIMAGEBUFFER);
41994199
DEFINE_HL_PRIM (_TIMAGEBUFFER, hl_jpeg_decode_file, _STRING _BOOL _TIMAGEBUFFER);
4200-
DEFINE_HL_PRIM (_F32, hl_key_code_from_scan_code, _F32);
4201-
DEFINE_HL_PRIM (_F32, hl_key_code_to_scan_code, _F32);
4200+
DEFINE_HL_PRIM (_I32, hl_key_code_from_scan_code, _I32);
4201+
DEFINE_HL_PRIM (_I32, hl_key_code_to_scan_code, _I32);
42024202
DEFINE_HL_PRIM (_VOID, hl_key_event_manager_register, _FUN (_VOID, _NO_ARG) _TKEY_EVENT);
42034203
DEFINE_HL_PRIM (_BYTES, hl_locale_get_system_locale, _NO_ARG);
42044204
DEFINE_HL_PRIM (_TBYTES, hl_lzma_compress, _TBYTES _TBYTES);

src/lime/_internal/backend/native/NativeCFFI.hx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,9 @@ class NativeCFFI
219219

220220
@:cffi private static function lime_jpeg_decode_file(path:String, decodeData:Bool, buffer:Dynamic):Dynamic;
221221

222-
@:cffi private static function lime_key_code_from_scan_code(scanCode:Float32):Float32;
222+
@:cffi private static function lime_key_code_from_scan_code(scanCode:Int):Int;
223223

224-
@:cffi private static function lime_key_code_to_scan_code(keyCode:Float32):Float32;
224+
@:cffi private static function lime_key_code_to_scan_code(keyCode:Int):Int;
225225

226226
@:cffi private static function lime_key_event_manager_register(callback:Dynamic, eventObject:Dynamic):Void;
227227

@@ -499,10 +499,10 @@ class NativeCFFI
499499
"lime_jpeg_decode_bytes", "oboo", false));
500500
private static var lime_jpeg_decode_file = new cpp.Callable<String->Bool->cpp.Object->cpp.Object>(cpp.Prime._loadPrime("lime", "lime_jpeg_decode_file",
501501
"sboo", false));
502-
private static var lime_key_code_from_scan_code = new cpp.Callable<cpp.Float32->cpp.Float32>(cpp.Prime._loadPrime("lime", "lime_key_code_from_scan_code",
503-
"ff", false));
504-
private static var lime_key_code_to_scan_code = new cpp.Callable<cpp.Float32->cpp.Float32>(cpp.Prime._loadPrime("lime", "lime_key_code_to_scan_code",
505-
"ff", false));
502+
private static var lime_key_code_from_scan_code = new cpp.Callable<Int->Int>(cpp.Prime._loadPrime("lime", "lime_key_code_from_scan_code",
503+
"ii", false));
504+
private static var lime_key_code_to_scan_code = new cpp.Callable<Int->Int>(cpp.Prime._loadPrime("lime", "lime_key_code_to_scan_code",
505+
"ii", false));
506506
private static var lime_key_event_manager_register = new cpp.Callable<cpp.Object->cpp.Object->cpp.Void>(cpp.Prime._loadPrime("lime",
507507
"lime_key_event_manager_register", "oov", false));
508508
private static var lime_lzma_compress = new cpp.Callable<cpp.Object->cpp.Object->cpp.Object>(cpp.Prime._loadPrime("lime", "lime_lzma_compress", "ooo",
@@ -1121,12 +1121,12 @@ class NativeCFFI
11211121
return null;
11221122
}
11231123

1124-
@:hlNative("lime", "hl_key_code_from_scan_code") private static function lime_key_code_from_scan_code(scanCode:hl.F32):hl.F32
1124+
@:hlNative("lime", "hl_key_code_from_scan_code") private static function lime_key_code_from_scan_code(scanCode:Int):Int
11251125
{
11261126
return 0;
11271127
}
11281128

1129-
@:hlNative("lime", "hl_key_code_to_scan_code") private static function lime_key_code_to_scan_code(keyCode:hl.F32):hl.F32
1129+
@:hlNative("lime", "hl_key_code_to_scan_code") private static function lime_key_code_to_scan_code(keyCode:Int):Int
11301130
{
11311131
return 0;
11321132
}

src/lime/ui/KeyCode.hx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ import lime._internal.backend.native.NativeCFFI;
254254
{
255255
#if (lime_cffi && !macro)
256256
var code:Int = scanCode;
257-
return Std.int(NativeCFFI.lime_key_code_from_scan_code(code));
257+
return NativeCFFI.lime_key_code_from_scan_code(code);
258258
#else
259259
return KeyCode.UNKNOWN;
260260
#end
@@ -264,7 +264,7 @@ import lime._internal.backend.native.NativeCFFI;
264264
{
265265
#if (lime_cffi && !macro)
266266
var code:Int = keyCode;
267-
return Std.int(NativeCFFI.lime_key_code_to_scan_code(code));
267+
return NativeCFFI.lime_key_code_to_scan_code(code);
268268
#else
269269
return ScanCode.UNKNOWN;
270270
#end

0 commit comments

Comments
 (0)