From f58c53f8f15e9fa9989072ea8e9a6d1a2d234d18 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Wed, 6 May 2015 20:06:13 -0700 Subject: [PATCH 01/12] Include Cairo by default --- include.xml | 2 +- project/Build.xml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include.xml b/include.xml index e81a21dd5..f1dc110e7 100644 --- a/include.xml +++ b/include.xml @@ -51,7 +51,7 @@ - + diff --git a/project/Build.xml b/project/Build.xml index 95704e535..9991f66b9 100644 --- a/project/Build.xml +++ b/project/Build.xml @@ -9,7 +9,7 @@ - + @@ -18,7 +18,7 @@ - + From 5fcd702027e3b61f1256bd31d35e45dcca9e73ce Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Wed, 6 May 2015 20:18:30 -0700 Subject: [PATCH 02/12] Minor update --- project/lib/cairo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/lib/cairo b/project/lib/cairo index e889c8218..888742ef6 160000 --- a/project/lib/cairo +++ b/project/lib/cairo @@ -1 +1 @@ -Subproject commit e889c82181cd7bae0332a86862ec422d827e82b6 +Subproject commit 888742ef63cd54df6d1d167ef136a50da8770282 From 979d5fd1e4ae67c40da28be2cfba0e9cf9e15798 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Wed, 6 May 2015 20:33:00 -0700 Subject: [PATCH 03/12] Minor update --- project/lib/cairo | 2 +- project/lib/pixman | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/project/lib/cairo b/project/lib/cairo index 888742ef6..eb462ba87 160000 --- a/project/lib/cairo +++ b/project/lib/cairo @@ -1 +1 @@ -Subproject commit 888742ef63cd54df6d1d167ef136a50da8770282 +Subproject commit eb462ba875ed3572cf6e83769bc240614f3e183c diff --git a/project/lib/pixman b/project/lib/pixman index d0404ae11..d42fc0b90 160000 --- a/project/lib/pixman +++ b/project/lib/pixman @@ -1 +1 @@ -Subproject commit d0404ae1135602ae60f3ff7e11b0543d395a71c9 +Subproject commit d42fc0b903c7736b057a6daca7a22dc83db69aab From a28e2673196e6edf2f12688597e0737fc6da9f04 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Thu, 7 May 2015 08:59:25 -0700 Subject: [PATCH 04/12] Update for JS error message --- js/Boot.hx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/js/Boot.hx b/js/Boot.hx index 381fecd49..1db6fcb54 100644 --- a/js/Boot.hx +++ b/js/Boot.hx @@ -24,11 +24,12 @@ package js; private class HaxeError extends js.Error { var val:Dynamic; - - public function new(val:Dynamic) { + + public function new(val:Dynamic) untyped { super(); - this.val = untyped __define_feature__("js.Boot.HaxeError", val); - untyped if (js.Error.captureStackTrace) js.Error.captureStackTrace(this, HaxeError); + this.val = __define_feature__("js.Boot.HaxeError", val); + this.message = String(val); + if (js.Error.captureStackTrace) js.Error.captureStackTrace(this, HaxeError); } } From 4deb21be8c26c9a4378c5b12f47f70faadcd723b Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Thu, 7 May 2015 13:16:36 -0700 Subject: [PATCH 05/12] Fix static build (thanks JeriX) --- include.xml | 2 +- project/Build.xml | 2 +- project/src/ExternalInterface.cpp | 2 +- templates/cpp/static/BuildMain.xml | 2 +- templates/cpp/static/Main.cpp | 6 ++++++ 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/include.xml b/include.xml index f1dc110e7..0f18dcbae 100644 --- a/include.xml +++ b/include.xml @@ -41,7 +41,7 @@ - + diff --git a/project/Build.xml b/project/Build.xml index 9991f66b9..805a92a13 100644 --- a/project/Build.xml +++ b/project/Build.xml @@ -176,7 +176,7 @@ - + diff --git a/project/src/ExternalInterface.cpp b/project/src/ExternalInterface.cpp index 913dd9f87..99f7e719a 100644 --- a/project/src/ExternalInterface.cpp +++ b/project/src/ExternalInterface.cpp @@ -488,7 +488,7 @@ namespace lime { value lime_image_data_util_fill_rect (value image, value rect, value color) { Image _image = Image (image); - Rectangle _rect = Rectangle (rect); + Rectangle _rect = Rectangle (rect); ImageDataUtil::FillRect (&_image, &_rect, val_number (color)); return alloc_null (); diff --git a/templates/cpp/static/BuildMain.xml b/templates/cpp/static/BuildMain.xml index 6771bd076..cbb4c534a 100644 --- a/templates/cpp/static/BuildMain.xml +++ b/templates/cpp/static/BuildMain.xml @@ -78,7 +78,7 @@ - + diff --git a/templates/cpp/static/Main.cpp b/templates/cpp/static/Main.cpp index 5a92451a7..dc71655b3 100644 --- a/templates/cpp/static/Main.cpp +++ b/templates/cpp/static/Main.cpp @@ -7,6 +7,9 @@ extern "C" const char *hxRunLibrary (); extern "C" void hxcpp_set_top_of_stack (); +extern "C" int zlib_register_prims (); +extern "C" int lime_cairo_register_prims (); +extern "C" int lime_openal_register_prims (); ::foreach ndlls::::if (registerStatics):: extern "C" int ::nameSafe::_register_prims ();::end::::end:: @@ -19,6 +22,9 @@ extern "C" int main(int argc, char *argv[]) { hxcpp_set_top_of_stack (); + zlib_register_prims (); + lime_cairo_register_prims (); + lime_openal_register_prims (); ::foreach ndlls::::if (registerStatics):: ::nameSafe::_register_prims ();::end::::end:: From bc0a475c8b648e249ec614ab78d7220b17b8b97f Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Thu, 7 May 2015 13:21:30 -0700 Subject: [PATCH 06/12] Update licenses --- LICENSE.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/LICENSE.md b/LICENSE.md index d5a4c0d15..9c494ec6f 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -25,6 +25,9 @@ THE SOFTWARE. ------- +This product bundles cairo 1.14.2, which is available under an +"MPL 1.1" license. For details, see [project/lib/cairo/](project/lib). + This product bundles libcurl 7.37.1, which is available under an "MIT/X derivate" license. For details, see [project/lib/curl/](project/lib). @@ -47,6 +50,9 @@ an OpenAL-Soft derivative for Android under [project/lib/openal-android/](projec _OpenAL-Soft is only included in dynamically-linked builds, it is excluded from Lime static builds in order to preserve Lime's permissive nature._ +This product bundles pixman 0.32.6, which is available under an +"MIT" license. For details, see [project/lib/pixman/](project/lib). + This product bundles libpng 1.6.12, which is available under a "zlib" (BSD-style) license. For details, see [project/lib/png/](project/lib). From f1c88a86e5edbb23ce26ae9ad308d5ce8a560717 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Thu, 7 May 2015 14:13:56 -0700 Subject: [PATCH 07/12] Fix possible OpenAL crash on Neko --- project/src/audio/openal/OpenALBindings.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/project/src/audio/openal/OpenALBindings.cpp b/project/src/audio/openal/OpenALBindings.cpp index 088670efb..0a1efc851 100644 --- a/project/src/audio/openal/OpenALBindings.cpp +++ b/project/src/audio/openal/OpenALBindings.cpp @@ -29,7 +29,7 @@ namespace lime { value lime_al_buffer3f (value buffer, value param, value value1, value value2, value value3) { - alBuffer3f (val_int (buffer), val_int (param), val_float (value1), val_float (value2), val_float (value3)); + alBuffer3f (val_int (buffer), val_int (param), val_number (value1), val_number (value2), val_number (value3)); return alloc_null (); } @@ -45,7 +45,7 @@ namespace lime { value lime_al_bufferf (value buffer, value param, value value) { - alBufferf (val_int (buffer), val_int (param), val_float (value)); + alBufferf (val_int (buffer), val_int (param), val_number (value)); return alloc_null (); } @@ -169,7 +169,7 @@ namespace lime { value lime_al_distance_model (value distanceModel) { - alDistanceModel (val_float (distanceModel)); + alDistanceModel (val_number (distanceModel)); return alloc_null (); } @@ -177,7 +177,7 @@ namespace lime { value lime_al_doppler_factor (value factor) { - alDopplerFactor (val_float (factor)); + alDopplerFactor (val_number (factor)); return alloc_null (); } @@ -185,7 +185,7 @@ namespace lime { value lime_al_doppler_velocity (value velocity) { - alDopplerVelocity (val_float (velocity)); + alDopplerVelocity (val_number (velocity)); return alloc_null (); } @@ -688,7 +688,7 @@ namespace lime { value lime_al_listener3f (value param, value value1, value value2, value value3) { - alListener3f (val_int (param), val_float (value1), val_float (value2), val_float (value3)); + alListener3f (val_int (param), val_number (value1), val_number (value2), val_number (value3)); return alloc_null (); } @@ -704,7 +704,7 @@ namespace lime { value lime_al_listenerf (value param, value value1) { - alListenerf (val_int (param), val_float (value1)); + alListenerf (val_int (param), val_number (value1)); return alloc_null (); } @@ -878,7 +878,7 @@ namespace lime { value lime_al_source3f (value source, value param, value value1, value value2, value value3) { - alSource3f (val_int (source), val_int (param), val_float (value1), val_float (value2), val_float (value3)); + alSource3f (val_int (source), val_int (param), val_number (value1), val_number (value2), val_number (value3)); return alloc_null (); } @@ -894,7 +894,7 @@ namespace lime { value lime_al_sourcef (value source, value param, value value) { - alSourcef (val_int (source), val_int (param), val_float (value)); + alSourcef (val_int (source), val_int (param), val_number (value)); return alloc_null (); } @@ -940,7 +940,7 @@ namespace lime { value lime_al_speed_of_sound (value speed) { - alSpeedOfSound (val_float (speed)); + alSpeedOfSound (val_number (speed)); return alloc_null (); } From b1a77a57b14f27c4d926974f9628699a23a30416 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Thu, 7 May 2015 15:16:36 -0700 Subject: [PATCH 08/12] Add AudioSource.dispose for now --- lime/audio/AudioSource.hx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lime/audio/AudioSource.hx b/lime/audio/AudioSource.hx index b0c27fdb1..b85e707ee 100644 --- a/lime/audio/AudioSource.hx +++ b/lime/audio/AudioSource.hx @@ -59,6 +59,25 @@ class AudioSource { } + public function dispose ():Void { + + switch (AudioManager.context) { + + case OPENAL (alc, al): + + if (id != 0) { + + al.deleteSource (id); + + } + + default: + + } + + } + + private function init ():Void { switch (AudioManager.context) { From 2d3f51d2a4413069b221269da3e084c9b905caa6 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Tue, 12 May 2015 07:11:21 -0700 Subject: [PATCH 09/12] Initial support for text input/edit events --- lime/_backend/flash/FlashApplication.hx | 6 +++ lime/_backend/flash/FlashWindow.hx | 15 ++++++ lime/_backend/html5/HTML5Application.hx | 6 +++ lime/_backend/html5/HTML5Window.hx | 15 ++++++ lime/_backend/native/NativeApplication.hx | 60 ++++++++++++++++++++++ lime/_backend/native/NativeWindow.hx | 28 ++++++++++ lime/app/Application.hx | 24 +++++++++ lime/app/IModule.hx | 16 ++++++ lime/app/Module.hx | 16 ++++++ lime/ui/Window.hx | 17 ++++++ project/Build.xml | 1 + project/include/ui/TextEvent.h | 41 +++++++++++++++ project/include/ui/Window.h | 2 + project/src/ExternalInterface.cpp | 30 +++++++++++ project/src/backend/sdl/SDLApplication.cpp | 36 +++++++++++++ project/src/backend/sdl/SDLApplication.h | 3 ++ project/src/backend/sdl/SDLWindow.cpp | 22 ++++++++ project/src/backend/sdl/SDLWindow.h | 2 + project/src/ui/TextEvent.cpp | 59 +++++++++++++++++++++ 19 files changed, 399 insertions(+) create mode 100644 project/include/ui/TextEvent.h create mode 100644 project/src/ui/TextEvent.cpp diff --git a/lime/_backend/flash/FlashApplication.hx b/lime/_backend/flash/FlashApplication.hx index 7488b6795..23c46bb1b 100644 --- a/lime/_backend/flash/FlashApplication.hx +++ b/lime/_backend/flash/FlashApplication.hx @@ -163,6 +163,12 @@ class FlashApplication { parent.window.onKeyDown.dispatch (keyCode, modifier); + if (parent.window.enableTextEvents) { + + parent.window.onTextInput.dispatch (String.fromCharCode (event.charCode)); + + } + } else { parent.window.onKeyUp.dispatch (keyCode, modifier); diff --git a/lime/_backend/flash/FlashWindow.hx b/lime/_backend/flash/FlashWindow.hx index c35ff4f06..4e5a28146 100644 --- a/lime/_backend/flash/FlashWindow.hx +++ b/lime/_backend/flash/FlashWindow.hx @@ -12,6 +12,7 @@ import lime.ui.Window; class FlashWindow { + private var enableTextEvents:Bool; private var parent:Window; @@ -37,6 +38,13 @@ class FlashWindow { } + public function getEnableTextEvents ():Bool { + + return enableTextEvents; + + } + + public function move (x:Int, y:Int):Void { @@ -51,6 +59,13 @@ class FlashWindow { } + public function setEnableTextEvents (value:Bool):Bool { + + return enableTextEvents = value; + + } + + public function setFullscreen (value:Bool):Bool { return value; diff --git a/lime/_backend/html5/HTML5Application.hx b/lime/_backend/html5/HTML5Application.hx index 0af060c6e..7eda98583 100644 --- a/lime/_backend/html5/HTML5Application.hx +++ b/lime/_backend/html5/HTML5Application.hx @@ -169,6 +169,12 @@ class HTML5Application { parent.window.onKeyDown.dispatch (keyCode, modifier); + if (parent.window.enableTextEvents) { + + parent.window.onTextInput.dispatch (String.fromCharCode (event.keyCode)); + + } + } else { parent.window.onKeyUp.dispatch (keyCode, modifier); diff --git a/lime/_backend/html5/HTML5Window.hx b/lime/_backend/html5/HTML5Window.hx index 6cae8c737..3ebde5693 100644 --- a/lime/_backend/html5/HTML5Window.hx +++ b/lime/_backend/html5/HTML5Window.hx @@ -26,6 +26,7 @@ class HTML5Window { public var stats:Dynamic; #end + private var enableTextEvents:Bool; private var parent:Window; private var setHeight:Int; private var setWidth:Int; @@ -166,6 +167,13 @@ class HTML5Window { } + public function getEnableTextEvents ():Bool { + + return enableTextEvents; + + } + + private function handleMouseEvent (event:MouseEvent):Void { var x = 0.0; @@ -380,6 +388,13 @@ class HTML5Window { } + public function setEnableTextEvents (value:Bool):Bool { + + return enableTextEvents = value; + + } + + public function setFullscreen (value:Bool):Bool { return false; diff --git a/lime/_backend/native/NativeApplication.hx b/lime/_backend/native/NativeApplication.hx index a8803d9a3..f51e5c656 100644 --- a/lime/_backend/native/NativeApplication.hx +++ b/lime/_backend/native/NativeApplication.hx @@ -27,6 +27,7 @@ class NativeApplication { private var keyEventInfo = new KeyEventInfo (); private var mouseEventInfo = new MouseEventInfo (); private var renderEventInfo = new RenderEventInfo (RENDER); + private var textEventInfo = new TextEventInfo (); private var touchEventInfo = new TouchEventInfo (); private var updateEventInfo = new UpdateEventInfo (); private var windowEventInfo = new WindowEventInfo (); @@ -70,6 +71,7 @@ class NativeApplication { lime_key_event_manager_register (handleKeyEvent, keyEventInfo); lime_mouse_event_manager_register (handleMouseEvent, mouseEventInfo); lime_render_event_manager_register (handleRenderEvent, renderEventInfo); + lime_text_event_manager_register (handleTextEvent, textEventInfo); lime_touch_event_manager_register (handleTouchEvent, touchEventInfo); lime_update_event_manager_register (handleUpdateEvent, updateEventInfo); lime_window_event_manager_register (handleWindowEvent, windowEventInfo); @@ -239,6 +241,25 @@ class NativeApplication { } + private function handleTextEvent ():Void { + + switch (textEventInfo.type) { + + case TEXT_INPUT: + + parent.window.onTextInput.dispatch (textEventInfo.text); + + case TEXT_EDIT: + + parent.window.onTextEdit.dispatch (textEventInfo.text, textEventInfo.start, textEventInfo.length); + + default: + + } + + } + + private function handleTouchEvent ():Void { if (parent.window != null) { @@ -394,6 +415,7 @@ class NativeApplication { private static var lime_key_event_manager_register = System.load ("lime", "lime_key_event_manager_register", 2); private static var lime_mouse_event_manager_register = System.load ("lime", "lime_mouse_event_manager_register", 2); private static var lime_render_event_manager_register = System.load ("lime", "lime_render_event_manager_register", 2); + private static var lime_text_event_manager_register = System.load ("lime", "lime_text_event_manager_register", 2); private static var lime_touch_event_manager_register = System.load ("lime", "lime_touch_event_manager_register", 2); private static var lime_update_event_manager_register = System.load ("lime", "lime_update_event_manager_register", 2); private static var lime_window_event_manager_register = System.load ("lime", "lime_window_event_manager_register", 2); @@ -557,6 +579,44 @@ private class RenderEventInfo { } +private class TextEventInfo { + + + public var id:Int; + public var length:Int; + public var start:Int; + public var text:String; + public var type:TextEventType; + + + public function new (type:TextEventType = null, text:String = "", start:Int = 0, length:Int = 0) { + + this.type = type; + this.text = text; + this.start = start; + this.length = length; + + } + + + public function clone ():TextEventInfo { + + return new TextEventInfo (type, text, start, length); + + } + + +} + + +@:enum private abstract TextEventType(Int) { + + var TEXT_INPUT = 0; + var TEXT_EDIT = 1; + +} + + private class TouchEventInfo { diff --git a/lime/_backend/native/NativeWindow.hx b/lime/_backend/native/NativeWindow.hx index 72182d52b..e898e6d2c 100644 --- a/lime/_backend/native/NativeWindow.hx +++ b/lime/_backend/native/NativeWindow.hx @@ -89,6 +89,19 @@ class NativeWindow { } + public function getEnableTextEvents ():Bool { + + if (handle != null) { + + return lime_window_get_enable_text_events (handle); + + } + + return false; + + } + + public function move (x:Int, y:Int):Void { if (handle != null) { @@ -111,6 +124,19 @@ class NativeWindow { } + public function setEnableTextEvents (value:Bool):Bool { + + if (handle != null) { + + return lime_window_set_enable_text_events (handle, value); + + } + + return value; + + } + + public function setFullscreen (value:Bool):Bool { if (handle != null) { @@ -156,12 +182,14 @@ class NativeWindow { private static var lime_window_close = System.load ("lime", "lime_window_close", 1); private static var lime_window_create = System.load ("lime", "lime_window_create", 5); + private static var lime_window_get_enable_text_events = System.load ("lime", "lime_window_get_enable_text_events", 1); private static var lime_window_get_height = System.load ("lime", "lime_window_get_height", 1); private static var lime_window_get_width = System.load ("lime", "lime_window_get_width", 1); private static var lime_window_get_x = System.load ("lime", "lime_window_get_x", 1); private static var lime_window_get_y = System.load ("lime", "lime_window_get_y", 1); private static var lime_window_move = System.load ("lime", "lime_window_move", 3); private static var lime_window_resize = System.load ("lime", "lime_window_resize", 3); + private static var lime_window_set_enable_text_events = System.load ("lime", "lime_window_set_enable_text_events", 2); private static var lime_window_set_fullscreen = System.load ("lime", "lime_window_set_fullscreen", 2); private static var lime_window_set_icon = System.load ("lime", "lime_window_set_icon", 2); private static var lime_window_set_minimized = System.load ("lime", "lime_window_set_minimized", 2); diff --git a/lime/app/Application.hx b/lime/app/Application.hx index 9fa4dad85..69e592424 100644 --- a/lime/app/Application.hx +++ b/lime/app/Application.hx @@ -113,6 +113,8 @@ class Application extends Module { window.onMouseMoveRelative.add (onMouseMoveRelative); window.onMouseUp.add (onMouseUp); window.onMouseWheel.add (onMouseWheel); + window.onTextEdit.add (onTextEdit); + window.onTextInput.add (onTextInput); window.onTouchStart.add (onTouchStart); window.onTouchMove.add (onTouchMove); window.onTouchEnd.add (onTouchEnd); @@ -329,6 +331,28 @@ class Application extends Module { } + public override function onTextEdit (text:String, start:Int, length:Int):Void { + + for (module in modules) { + + module.onTextEdit (text, start, length); + + } + + } + + + public override function onTextInput (text:String):Void { + + for (module in modules) { + + module.onTextInput (text); + + } + + } + + public override function onTouchEnd (x:Float, y:Float, id:Int):Void { for (module in modules) { diff --git a/lime/app/IModule.hx b/lime/app/IModule.hx index 4627999ae..9710ea21c 100644 --- a/lime/app/IModule.hx +++ b/lime/app/IModule.hx @@ -133,6 +133,22 @@ interface IModule { public function onRenderContextRestored (context:RenderContext):Void; + /** + * Called when a text edit event is fired + * @param text The current replacement text + * @param start The starting index for the edit + * @param length The length of the edit + */ + public function onTextEdit (text:String, start:Int, length:Int):Void; + + + /** + * Called when a text input event is fired + * @param text The current input text + */ + public function onTextInput (text:String):Void; + + /** * Called when a touch end event is fired * @param x The current x coordinate of the touch point diff --git a/lime/app/Module.hx b/lime/app/Module.hx index 88b469fad..516ac5b1d 100644 --- a/lime/app/Module.hx +++ b/lime/app/Module.hx @@ -108,6 +108,22 @@ class Module implements IModule { public function onRenderContextRestored (context:RenderContext):Void { } + /** + * Called when a text edit event is fired + * @param text The current replacement text + * @param start The starting index for the edit + * @param length The length of the edit + */ + public function onTextEdit (text:String, start:Int, length:Int):Void { } + + + /** + * Called when a text input event is fired + * @param text The current input text + */ + public function onTextInput (text:String):Void { } + + /** * Called when a touch end event is fired * @param x The current x coordinate of the touch point diff --git a/lime/ui/Window.hx b/lime/ui/Window.hx index 637d01871..2dd7b32d1 100644 --- a/lime/ui/Window.hx +++ b/lime/ui/Window.hx @@ -13,6 +13,7 @@ class Window { public var currentRenderer:Renderer; public var config:Config; + public var enableTextEvents (get, set):Bool; public var fullscreen (get, set):Bool; public var height (get, set):Int; public var minimized (get, set):Bool; @@ -28,6 +29,8 @@ class Window { public var onMouseMoveRelative = new EventFloat->Void> (); public var onMouseUp = new EventFloat->Int->Void> (); public var onMouseWheel = new EventFloat->Void> (); + public var onTextEdit = new EventInt->Int->Void> (); + public var onTextInput = new EventVoid> (); public var onTouchEnd = new EventFloat->Int->Void> (); public var onTouchMove = new EventFloat->Int->Void> (); public var onTouchStart = new EventFloat->Int->Void> (); @@ -141,6 +144,20 @@ class Window { + @:noCompletion private inline function get_enableTextEvents ():Bool { + + return backend.getEnableTextEvents (); + + } + + + @:noCompletion private inline function set_enableTextEvents (value:Bool):Bool { + + return backend.setEnableTextEvents (value); + + } + + @:noCompletion private inline function get_fullscreen ():Bool { return __fullscreen; diff --git a/project/Build.xml b/project/Build.xml index 805a92a13..d56b804e1 100644 --- a/project/Build.xml +++ b/project/Build.xml @@ -194,6 +194,7 @@ + diff --git a/project/include/ui/TextEvent.h b/project/include/ui/TextEvent.h new file mode 100644 index 000000000..4ea3d2251 --- /dev/null +++ b/project/include/ui/TextEvent.h @@ -0,0 +1,41 @@ +#ifndef LIME_UI_TEXT_EVENT_H +#define LIME_UI_TEXT_EVENT_H + + +#include + + +namespace lime { + + + enum TextEventType { + + TEXT_INPUT, + TEXT_EDIT + + }; + + + class TextEvent { + + public: + + static AutoGCRoot* callback; + static AutoGCRoot* eventObject; + + TextEvent (); + + static void Dispatch (TextEvent* event); + + long length; + long start; + char text[32]; + TextEventType type; + + }; + + +} + + +#endif \ No newline at end of file diff --git a/project/include/ui/Window.h b/project/include/ui/Window.h index e58d27420..78c983288 100644 --- a/project/include/ui/Window.h +++ b/project/include/ui/Window.h @@ -19,12 +19,14 @@ namespace lime { public: virtual void Close () = 0; + virtual bool GetEnableTextEvents () = 0; virtual int GetHeight () = 0; virtual int GetWidth () = 0; virtual int GetX () = 0; virtual int GetY () = 0; virtual void Move (int x, int y) = 0; virtual void Resize (int width, int height) = 0; + virtual void SetEnableTextEvents (bool enable) = 0; virtual bool SetFullscreen (bool fullscreen) = 0; virtual void SetIcon (ImageBuffer *imageBuffer) = 0; virtual bool SetMinimized (bool minimized) = 0; diff --git a/project/src/ExternalInterface.cpp b/project/src/ExternalInterface.cpp index 99f7e719a..f253ad9be 100644 --- a/project/src/ExternalInterface.cpp +++ b/project/src/ExternalInterface.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -763,6 +764,15 @@ namespace lime { } + value lime_text_event_manager_register (value callback, value eventObject) { + + TextEvent::callback = new AutoGCRoot (callback); + TextEvent::eventObject = new AutoGCRoot (eventObject); + return alloc_null (); + + } + + void lime_text_layout_destroy (value textHandle) { #ifdef LIME_HARFBUZZ @@ -885,6 +895,14 @@ namespace lime { } + value lime_window_get_enable_text_events (value window) { + + Window* targetWindow = (Window*)(intptr_t)val_float (window); + return alloc_bool (targetWindow->GetEnableTextEvents ()); + + } + + value lime_window_get_height (value window) { Window* targetWindow = (Window*)(intptr_t)val_float (window); @@ -935,6 +953,15 @@ namespace lime { } + value lime_window_set_enable_text_events (value window, value enabled) { + + Window* targetWindow = (Window*)(intptr_t)val_float (window); + targetWindow->SetEnableTextEvents (val_bool (enabled)); + return alloc_null (); + + } + + value lime_window_set_fullscreen (value window, value fullscreen) { Window* targetWindow = (Window*)(intptr_t)val_float (window); @@ -1018,6 +1045,7 @@ namespace lime { DEFINE_PRIM (lime_render_event_manager_register, 2); DEFINE_PRIM (lime_system_get_directory, 3); DEFINE_PRIM (lime_system_get_timer, 0); + DEFINE_PRIM (lime_text_event_manager_register, 2); DEFINE_PRIM (lime_text_layout_create, 3); DEFINE_PRIM (lime_text_layout_position, 5); DEFINE_PRIM (lime_text_layout_set_direction, 2); @@ -1028,12 +1056,14 @@ namespace lime { DEFINE_PRIM (lime_window_close, 1); DEFINE_PRIM (lime_window_create, 5); DEFINE_PRIM (lime_window_event_manager_register, 2); + DEFINE_PRIM (lime_window_get_enable_text_events, 1); DEFINE_PRIM (lime_window_get_height, 1); DEFINE_PRIM (lime_window_get_width, 1); DEFINE_PRIM (lime_window_get_x, 1); DEFINE_PRIM (lime_window_get_y, 1); DEFINE_PRIM (lime_window_move, 3); DEFINE_PRIM (lime_window_resize, 3); + DEFINE_PRIM (lime_window_set_enable_text_events, 2); DEFINE_PRIM (lime_window_set_fullscreen, 2); DEFINE_PRIM (lime_window_set_icon, 2); DEFINE_PRIM (lime_window_set_minimized, 2); diff --git a/project/src/backend/sdl/SDLApplication.cpp b/project/src/backend/sdl/SDLApplication.cpp index 25a153bb7..38a765aae 100644 --- a/project/src/backend/sdl/SDLApplication.cpp +++ b/project/src/backend/sdl/SDLApplication.cpp @@ -41,6 +41,7 @@ namespace lime { KeyEvent keyEvent; MouseEvent mouseEvent; RenderEvent renderEvent; + TextEvent textEvent; TouchEvent touchEvent; UpdateEvent updateEvent; WindowEvent windowEvent; @@ -145,6 +146,12 @@ namespace lime { ProcessMouseEvent (event); break; + case SDL_TEXTINPUT: + case SDL_TEXTEDITING: + + ProcessTextEvent (event); + break; + case SDL_WINDOWEVENT: switch (event->window.event) { @@ -337,6 +344,35 @@ namespace lime { } + void SDLApplication::ProcessTextEvent (SDL_Event* event) { + + if (TextEvent::callback) { + + switch (event->type) { + + case SDL_TEXTINPUT: + + textEvent.type = TEXT_INPUT; + break; + + case SDL_TEXTEDITING: + + textEvent.type = TEXT_EDIT; + textEvent.start = event->edit.start; + textEvent.length = event->edit.length; + break; + + } + + strcpy (textEvent.text, event->text.text); + + TextEvent::Dispatch (&textEvent); + + } + + } + + void SDLApplication::ProcessTouchEvent (SDL_Event* event) { diff --git a/project/src/backend/sdl/SDLApplication.h b/project/src/backend/sdl/SDLApplication.h index 9770cc171..de48a7e0f 100644 --- a/project/src/backend/sdl/SDLApplication.h +++ b/project/src/backend/sdl/SDLApplication.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include "SDLWindow.h" @@ -37,6 +38,7 @@ namespace lime { void ProcessGamepadEvent (SDL_Event* event); void ProcessKeyEvent (SDL_Event* event); void ProcessMouseEvent (SDL_Event* event); + void ProcessTextEvent (SDL_Event* event); void ProcessTouchEvent (SDL_Event* event); void ProcessWindowEvent (SDL_Event* event); @@ -54,6 +56,7 @@ namespace lime { MouseEvent mouseEvent; double nextUpdate; RenderEvent renderEvent; + TextEvent textEvent; TouchEvent touchEvent; UpdateEvent updateEvent; WindowEvent windowEvent; diff --git a/project/src/backend/sdl/SDLWindow.cpp b/project/src/backend/sdl/SDLWindow.cpp index ab6a7ca10..eea27001e 100644 --- a/project/src/backend/sdl/SDLWindow.cpp +++ b/project/src/backend/sdl/SDLWindow.cpp @@ -115,6 +115,13 @@ namespace lime { } + bool SDLWindow::GetEnableTextEvents () { + + return SDL_IsTextInputActive (); + + } + + int SDLWindow::GetHeight () { int width; @@ -177,6 +184,21 @@ namespace lime { } + void SDLWindow::SetEnableTextEvents (bool enabled) { + + if (enabled) { + + SDL_StartTextInput (); + + } else { + + SDL_StopTextInput (); + + } + + } + + bool SDLWindow::SetFullscreen (bool fullscreen) { if (fullscreen) { diff --git a/project/src/backend/sdl/SDLWindow.h b/project/src/backend/sdl/SDLWindow.h index f26d580c6..4342166df 100644 --- a/project/src/backend/sdl/SDLWindow.h +++ b/project/src/backend/sdl/SDLWindow.h @@ -18,12 +18,14 @@ namespace lime { ~SDLWindow (); virtual void Close (); + virtual bool GetEnableTextEvents (); virtual int GetHeight (); virtual int GetWidth (); virtual int GetX (); virtual int GetY (); virtual void Move (int x, int y); virtual void Resize (int width, int height); + virtual void SetEnableTextEvents (bool enabled); virtual bool SetFullscreen (bool fullscreen); virtual void SetIcon (ImageBuffer *imageBuffer); virtual bool SetMinimized (bool minimized); diff --git a/project/src/ui/TextEvent.cpp b/project/src/ui/TextEvent.cpp new file mode 100644 index 000000000..a90aac52f --- /dev/null +++ b/project/src/ui/TextEvent.cpp @@ -0,0 +1,59 @@ +#include +#include + + +namespace lime { + + + AutoGCRoot* TextEvent::callback = 0; + AutoGCRoot* TextEvent::eventObject = 0; + + static int id_length; + static int id_start; + static int id_text; + static int id_type; + static bool init = false; + + + TextEvent::TextEvent () { + + length = 0; + start = 0; + + } + + + void TextEvent::Dispatch (TextEvent* event) { + + if (TextEvent::callback) { + + if (!init) { + + id_length = val_id ("length"); + id_start = val_id ("start"); + id_text = val_id ("text"); + id_type = val_id ("type"); + init = true; + + } + + value object = (TextEvent::eventObject ? TextEvent::eventObject->get () : alloc_empty_object ()); + + if (event->type != TEXT_INPUT) { + + alloc_field (object, id_length, alloc_int (event->length)); + alloc_field (object, id_start, alloc_int (event->start)); + + } + + alloc_field (object, id_text, alloc_string (event->text)); + alloc_field (object, id_type, alloc_int (event->type)); + + val_call0 (TextEvent::callback->get ()); + + } + + } + + +} \ No newline at end of file From 6304548e44a05155bbaaef871293e1e3e40b1dd2 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Tue, 12 May 2015 12:20:34 -0700 Subject: [PATCH 10/12] Update to 2.4.0 --- haxelib.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/haxelib.json b/haxelib.json index dd81bb5d8..4d1d9c654 100644 --- a/haxelib.json +++ b/haxelib.json @@ -4,7 +4,7 @@ "license": "MIT", "tags": [], "description": "A flexible lightweight layer for Haxe cross-platform developers", - "version": "2.3.3", - "releasenote": "AudioSource improvements, other fixes", + "version": "2.4.0", + "releasenote": "Added Cairo, text input and mouse focus events, other improvements", "contributors": [ "singmajesty" ] } From 99209ac51b6b73f0801b56e13e17036d5dafabe9 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Tue, 12 May 2015 12:20:42 -0700 Subject: [PATCH 11/12] Update CHANGELOG --- CHANGELOG.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 308bab168..875f311e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,19 @@ +2.4.0 (05/12/2015) +------------------ + +* Added Cairo render context and bindings +* Added support for software windows, using Cairo not OpenGL +* Added text input/edit events +* Added onEnter/onLeave events for Window mouse focus +* Added Image getColorBoundsRect +* Added build support for ANGLE +* Removed prevent default for HTML5 arrow and space keys +* Improved Image copyPixels with merge alpha +* Fixed static build support +* Fixed a case where fonts might not be embedded +* Fixed occasional crash with OpenAL on Neko + + 2.3.3 (04/21/2015) ------------------ From ca97897f39b6e5e138d0a2e53f891e4a4fd8f722 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Tue, 12 May 2015 12:30:34 -0700 Subject: [PATCH 12/12] Sync files --- haxe/CallStack.hx | 89 +++++++++++++++++++++++-------------------- haxe/Timer.hx | 9 +---- haxe/crypto/Hmac.hx | 8 +++- haxe/crypto/Sha256.hx | 3 ++ js/Boot.hx | 7 +--- 5 files changed, 62 insertions(+), 54 deletions(-) diff --git a/haxe/CallStack.hx b/haxe/CallStack.hx index 168a3838b..ae931b7ab 100644 --- a/haxe/CallStack.hx +++ b/haxe/CallStack.hx @@ -36,6 +36,40 @@ enum StackItem { Get informations about the call stack. **/ class CallStack { + #if js + static var lastException:js.Error; + + static function getStack(e:js.Error):Array { + if (e == null) return []; + // https://code.google.com/p/v8/wiki/JavaScriptStackTraceApi + var oldValue = (untyped Error).prepareStackTrace; + (untyped Error).prepareStackTrace = function (error, callsites :Array) { + var stack = []; + for (site in callsites) { + if (wrapCallSite != null) site = wrapCallSite(site); + var method = null; + var fullName :String = site.getFunctionName(); + if (fullName != null) { + var idx = fullName.lastIndexOf("."); + if (idx >= 0) { + var className = fullName.substr(0, idx); + var methodName = fullName.substr(idx+1); + method = Method(className, methodName); + } + } + stack.push(FilePos(method, site.getFileName(), site.getLineNumber())); + } + return stack; + } + var a = makeStack(e.stack); + (untyped Error).prepareStackTrace = oldValue; + return a; + } + + // support for source-map-support module + @:noCompletion + public static var wrapCallSite:Dynamic->Dynamic; + #end /** Return the call stack elements, or an empty array if not available. @@ -45,45 +79,24 @@ class CallStack { var a = makeStack(untyped __dollar__callstack()); a.shift(); // remove Stack.callStack() return a; - #elseif flash9 + #elseif flash var a = makeStack( new flash.errors.Error().getStackTrace() ); a.shift(); // remove Stack.callStack() return a; - #elseif flash - return makeStack("$s"); #elseif php return makeStack("%s"); #elseif cpp var s:Array = untyped __global__.__hxcpp_get_call_stack(true); return makeStack(s); #elseif js - // https://code.google.com/p/v8/wiki/JavaScriptStackTraceApi - var oldValue = (untyped Error).prepareStackTrace; - (untyped Error).prepareStackTrace = function (error, callsites :Array) { - var stack = []; - for (site in callsites) { - var method = null; - var fullName :String = site.getFunctionName(); - if (fullName != null) { - var idx = fullName.lastIndexOf("."); - if (idx >= 0) { - var className = fullName.substr(0, idx); - var methodName = fullName.substr(idx+1); - method = Method(className, methodName); - } - } - stack.push(FilePos(method, site.getFileName(), site.getLineNumber())); - } - return stack; - } try { - throw untyped __new__("Error"); + throw new js.Error(); } catch( e : Dynamic ) { - var a = makeStack(e.stack); - if( a != null ) a.shift(); // remove Stack.callStack() - (untyped Error).prepareStackTrace = oldValue; + var a = getStack(e); + a.shift(); // remove Stack.callStack() return a; } + #elseif java var stack = []; for ( el in java.lang.Thread.currentThread().getStackTrace() ) { @@ -129,7 +142,7 @@ class CallStack { return makeStack(untyped __dollar__excstack()); #elseif as3 return new Array(); - #elseif flash9 + #elseif flash var err : flash.errors.Error = untyped flash.Boot.lastError; if( err == null ) return new Array(); var a = makeStack( err.getStackTrace() ); @@ -143,8 +156,6 @@ class CallStack { i--; } return a; - #elseif flash - return makeStack("$e"); #elseif php return makeStack("%e"); #elseif cpp @@ -182,6 +193,8 @@ class CallStack { stack.push(FilePos(null, elem._1, elem._2)); } return stack; + #elseif js + return untyped __define_feature__("haxe.CallStack.exceptionStack", getStack(lastException)); #else return []; // Unsupported #end @@ -245,7 +258,7 @@ class CallStack { a.unshift(FilePos(null,new String(untyped x[0]),untyped x[1])); } return a; - #elseif flash9 + #elseif flash var a = new Array(); var r = ~/at ([^\/]+?)\$?(\/[^\(]+)?\(\)(\[(.*?):([0-9]+)\])?/; var rlambda = ~/^MethodInfo-([0-9]+)$/g; @@ -266,14 +279,6 @@ class CallStack { s = r.matchedRight(); } return a; - #elseif flash - var a : Array = untyped __eval__(s); - var m = new Array(); - for( i in 0...a.length - if(s == "$s") 2 else 0 ) { - var d = a[i].split("::"); - m.unshift(Method(d[0],d[1])); - } - return m; #elseif php if (!untyped __call__("isset", __var__("GLOBALS", s))) return []; @@ -298,10 +303,12 @@ class CallStack { } return m; #elseif js - if ((untyped __js__("typeof"))(s) == "string") { + if (s == null) { + return []; + } else if ((untyped __js__("typeof"))(s) == "string") { // Return the raw lines in browsers that don't support prepareStackTrace var stack : Array = s.split("\n"); - if( stack[0] == "Error" ) stack.shift(); + if( stack[0] == "Error" ) stack.shift(); var m = []; var rie10 = ~/^ at ([A-Za-z0-9_. ]+) \(([^)]+):([0-9]+):([0-9]+)\)$/; for( line in stack ) { @@ -312,7 +319,7 @@ class CallStack { var line = Std.parseInt(rie10.matched(3)); m.push(FilePos( meth == "Anonymous function" ? LocalFunction() : meth == "Global code" ? null : Method(path.join("."),meth), file, line )); } else - m.push(Module(line)); // A little weird, but better than nothing + m.push(Module(StringTools.trim(line))); // A little weird, but better than nothing } return m; } else { diff --git a/haxe/Timer.hx b/haxe/Timer.hx index 4062c9d00..788bf2fef 100644 --- a/haxe/Timer.hx +++ b/haxe/Timer.hx @@ -62,12 +62,9 @@ class Timer { The accuracy of this may be platform-dependent. **/ public function new( time_ms : Int ){ - #if flash9 + #if flash var me = this; id = untyped __global__["flash.utils.setInterval"](function() { me.run(); },time_ms); - #elseif flash - var me = this; - id = untyped _global["setInterval"](function() { me.run(); },time_ms); #elseif js var me = this; id = untyped setInterval(function() me.run(),time_ms); @@ -89,10 +86,8 @@ class Timer { #if (flash || js) if( id == null ) return; - #if flash9 + #if flash untyped __global__["flash.utils.clearInterval"](id); - #elseif flash - untyped _global["clearInterval"](id); #elseif js untyped clearInterval(id); #end diff --git a/haxe/crypto/Hmac.hx b/haxe/crypto/Hmac.hx index 2afc65ec2..9a83f59e2 100644 --- a/haxe/crypto/Hmac.hx +++ b/haxe/crypto/Hmac.hx @@ -21,12 +21,18 @@ */ package haxe.crypto; +/** + Hash methods for Hmac calculation. +*/ enum HashMethod { MD5; SHA1; SHA256; } +/** + Calculates a Hmac of the given Bytes using a HashMethod. +*/ class Hmac { var method : HashMethod; @@ -82,4 +88,4 @@ class Hmac { return doHash(Ko.getBytes()); } -} \ No newline at end of file +} diff --git a/haxe/crypto/Sha256.hx b/haxe/crypto/Sha256.hx index 868bbe523..17292d573 100644 --- a/haxe/crypto/Sha256.hx +++ b/haxe/crypto/Sha256.hx @@ -21,6 +21,9 @@ */ package haxe.crypto; +/** + Creates a Sha256 of a String. +*/ class Sha256 { public static function encode( s:String ) : String { diff --git a/js/Boot.hx b/js/Boot.hx index 1db6fcb54..ef349f969 100644 --- a/js/Boot.hx +++ b/js/Boot.hx @@ -246,12 +246,9 @@ class Boot { return __nativeClassName(o) != null; } - // resolve native JS class (with window or global): + // resolve native JS class in the global scope: static function __resolveNativeClass(name:String) untyped { - if (__js__("typeof window") != "undefined") - return window[name]; - else - return global[name]; + return untyped Function('return typeof $name != "undefined" ? $name : null')(); } }