From a9e0c2ed940f679e92438896b8d3e58426b205f1 Mon Sep 17 00:00:00 2001 From: Viachaslau Tratsiak Date: Tue, 2 Dec 2014 14:57:52 +0300 Subject: [PATCH 01/28] Fix font preloading for Safari on OsX Safari on OsX reports some strange offsetWidth immediately after changing fontFamily, but before font actually loaded, and if you want to pre-cache font metrics on application start, you will get wrong values. Specifying correct css font family stack seems to fix this issue. --- lime/app/Preloader.hx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lime/app/Preloader.hx b/lime/app/Preloader.hx index 0744073da..d547a4226 100644 --- a/lime/app/Preloader.hx +++ b/lime/app/Preloader.hx @@ -142,7 +142,7 @@ class Preloader #if flash extends Sprite #end { Browser.document.body.appendChild (node); var width = node.offsetWidth; - style.fontFamily = "'" + font + "'"; + style.fontFamily = "'" + font + "', sans-serif"; var interval:Null = null; var found = false; @@ -301,4 +301,4 @@ class Preloader #if flash extends Sprite #end { #end -} \ No newline at end of file +} From 01a1c6ca3a06ca69aeaacc3b5bf4561ffe6139b0 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Sun, 28 Dec 2014 11:05:24 -0800 Subject: [PATCH 02/28] Fix compile warnings on CURL binding --- project/lib/curl | 2 +- project/src/net/curl/CURLBindings.cpp | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/project/lib/curl b/project/lib/curl index 8c8f49f2a..b5b913c01 160000 --- a/project/lib/curl +++ b/project/lib/curl @@ -1 +1 @@ -Subproject commit 8c8f49f2af04bb89bc887d553ab4e693bd1d781c +Subproject commit b5b913c01427297d87da69d34ddbbc06a6591697 diff --git a/project/src/net/curl/CURLBindings.cpp b/project/src/net/curl/CURLBindings.cpp index ccee50e94..8f05e6896 100644 --- a/project/src/net/curl/CURLBindings.cpp +++ b/project/src/net/curl/CURLBindings.cpp @@ -105,6 +105,12 @@ namespace lime { // todo break; + case CURLINFO_NONE: + case CURLINFO_LASTONE: + + // ignore + break; + } @@ -468,7 +474,7 @@ namespace lime { } case CURLOPT_HTTPHEADER: - + { struct curl_slist *chunk = NULL; int size = val_array_size (parameter); @@ -480,6 +486,11 @@ namespace lime { code = curl_easy_setopt (curl, type, chunk); break; + } + + default: + + break; } From 05162a2d0552b72717cf6f842474a4b4ae52d58f Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Sun, 28 Dec 2014 11:05:35 -0800 Subject: [PATCH 03/28] Add initial window.setIcon support --- lime/ui/Window.hx | 10 ++++++++++ project/include/ui/Window.h | 2 ++ project/src/ExternalInterface.cpp | 11 +++++++++++ project/src/backend/sdl/SDLWindow.cpp | 9 +++++++++ project/src/backend/sdl/SDLWindow.h | 2 ++ 5 files changed, 34 insertions(+) diff --git a/lime/ui/Window.hx b/lime/ui/Window.hx index cad16aa6a..d49954bb3 100644 --- a/lime/ui/Window.hx +++ b/lime/ui/Window.hx @@ -448,11 +448,21 @@ class Window { } + public function setIcon (buffer:ImageBuffer):Void { + + #if (cpp || neko || nodejs) + lime_window_set_icon (handle, buffer); + #end + + } + + #if (cpp || neko || nodejs) private static var lime_window_create = System.load ("lime", "lime_window_create", 5); private static var lime_window_event_manager_register = System.load ("lime", "lime_window_event_manager_register", 2); 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_icon = System.load ("lime", "lime_window_resize", 2); #end diff --git a/project/include/ui/Window.h b/project/include/ui/Window.h index b154ef3db..3d862b5a7 100644 --- a/project/include/ui/Window.h +++ b/project/include/ui/Window.h @@ -7,6 +7,7 @@ #endif #include +#include namespace lime { @@ -19,6 +20,7 @@ namespace lime { virtual void Move (int x, int y) = 0; virtual void Resize (int width, int height) = 0; + virtual void SetIcon (ImageBuffer *imageBuffer) = 0; Application* currentApplication; int flags; diff --git a/project/src/ExternalInterface.cpp b/project/src/ExternalInterface.cpp index bee40c6e8..68d3eb2ef 100644 --- a/project/src/ExternalInterface.cpp +++ b/project/src/ExternalInterface.cpp @@ -462,6 +462,16 @@ namespace lime { } + value lime_window_set_icon (value window, value buffer) { + + Window* targetWindow = (Window*)(intptr_t)val_float (window); + ImageBuffer imageBuffer = ImageBuffer (buffer); + targetWindow->SetIcon (&imageBuffer); + return alloc_null (); + + } + + DEFINE_PRIM (lime_application_create, 1); DEFINE_PRIM (lime_application_exec, 1); DEFINE_PRIM (lime_application_init, 1); @@ -494,6 +504,7 @@ namespace lime { DEFINE_PRIM (lime_window_event_manager_register, 2); DEFINE_PRIM (lime_window_move, 3); DEFINE_PRIM (lime_window_resize, 3); + DEFINE_PRIM (lime_window_set_icon, 2); } diff --git a/project/src/backend/sdl/SDLWindow.cpp b/project/src/backend/sdl/SDLWindow.cpp index 33d7cf95e..2385ac010 100644 --- a/project/src/backend/sdl/SDLWindow.cpp +++ b/project/src/backend/sdl/SDLWindow.cpp @@ -53,6 +53,15 @@ namespace lime { } + void SDLWindow::SetIcon (ImageBuffer *imageBuffer) { + + SDL_Surface *surface = SDL_CreateRGBSurfaceFrom (imageBuffer->data->Bytes (), imageBuffer->width, imageBuffer->height, imageBuffer->bpp, imageBuffer->width * imageBuffer->bpp, 0x0f00, 0x00f0, 0x000f, 0xf000); + SDL_SetWindowIcon (sdlWindow, surface); + SDL_FreeSurface (surface); + + } + + Window* CreateWindow (Application* application, int width, int height, int flags, const char* title) { return new SDLWindow (application, width, height, flags, title); diff --git a/project/src/backend/sdl/SDLWindow.h b/project/src/backend/sdl/SDLWindow.h index 871df4535..c12d00288 100644 --- a/project/src/backend/sdl/SDLWindow.h +++ b/project/src/backend/sdl/SDLWindow.h @@ -3,6 +3,7 @@ #include +#include #include @@ -18,6 +19,7 @@ namespace lime { virtual void Move (int x, int y); virtual void Resize (int width, int height); + virtual void SetIcon (ImageBuffer *imageBuffer); SDL_Window* sdlWindow; From 353e2d9000f582973629e1e4c189a6bb5a47ac87 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Sun, 28 Dec 2014 11:14:45 -0800 Subject: [PATCH 04/28] Compile fix --- lime/ui/Window.hx | 1 + 1 file changed, 1 insertion(+) diff --git a/lime/ui/Window.hx b/lime/ui/Window.hx index d49954bb3..8b805279c 100644 --- a/lime/ui/Window.hx +++ b/lime/ui/Window.hx @@ -4,6 +4,7 @@ package lime.ui; import lime.app.Application; import lime.app.Config; import lime.app.Event; +import lime.graphics.ImageBuffer; import lime.graphics.Renderer; import lime.system.System; From a12a27582e3e5e1d8346d8cb09c18a57f3f70ada Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Sun, 28 Dec 2014 11:54:10 -0800 Subject: [PATCH 05/28] Confirm window.setIcon on Windows --- lime/ui/Window.hx | 14 ++++++++++---- project/src/backend/sdl/SDLApplication.cpp | 2 +- project/src/backend/sdl/SDLWindow.cpp | 11 ++++++++--- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/lime/ui/Window.hx b/lime/ui/Window.hx index 8b805279c..f7ae73e8d 100644 --- a/lime/ui/Window.hx +++ b/lime/ui/Window.hx @@ -4,7 +4,7 @@ package lime.ui; import lime.app.Application; import lime.app.Config; import lime.app.Event; -import lime.graphics.ImageBuffer; +import lime.graphics.Image; import lime.graphics.Renderer; import lime.system.System; @@ -449,10 +449,16 @@ class Window { } - public function setIcon (buffer:ImageBuffer):Void { + public function setIcon (image:Image):Void { + + if (image == null) { + + return; + + } #if (cpp || neko || nodejs) - lime_window_set_icon (handle, buffer); + lime_window_set_icon (handle, image.buffer); #end } @@ -463,7 +469,7 @@ class Window { private static var lime_window_event_manager_register = System.load ("lime", "lime_window_event_manager_register", 2); 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_icon = System.load ("lime", "lime_window_resize", 2); + private static var lime_window_set_icon = System.load ("lime", "lime_window_set_icon", 2); #end diff --git a/project/src/backend/sdl/SDLApplication.cpp b/project/src/backend/sdl/SDLApplication.cpp index 1c8852c89..1d78bc50d 100644 --- a/project/src/backend/sdl/SDLApplication.cpp +++ b/project/src/backend/sdl/SDLApplication.cpp @@ -307,7 +307,7 @@ namespace lime { SDL_Event event; event.type = -1; - + if (active && (firstTime || SDL_WaitEvent (&event))) { firstTime = false; diff --git a/project/src/backend/sdl/SDLWindow.cpp b/project/src/backend/sdl/SDLWindow.cpp index 2385ac010..d7b4edc6b 100644 --- a/project/src/backend/sdl/SDLWindow.cpp +++ b/project/src/backend/sdl/SDLWindow.cpp @@ -55,9 +55,14 @@ namespace lime { void SDLWindow::SetIcon (ImageBuffer *imageBuffer) { - SDL_Surface *surface = SDL_CreateRGBSurfaceFrom (imageBuffer->data->Bytes (), imageBuffer->width, imageBuffer->height, imageBuffer->bpp, imageBuffer->width * imageBuffer->bpp, 0x0f00, 0x00f0, 0x000f, 0xf000); - SDL_SetWindowIcon (sdlWindow, surface); - SDL_FreeSurface (surface); + SDL_Surface *surface = SDL_CreateRGBSurfaceFrom (imageBuffer->data->Bytes (), imageBuffer->width, imageBuffer->height, imageBuffer->bpp * 8, imageBuffer->width * imageBuffer->bpp, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000); + + if (surface) { + + SDL_SetWindowIcon (sdlWindow, surface); + SDL_FreeSurface (surface); + + } } From 896efe77c0dead9674e83f278b1ae34a893187de Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Sun, 28 Dec 2014 13:23:12 -0800 Subject: [PATCH 06/28] Automatically load icon on Windows --- lime/app/Application.hx | 11 +++++++++++ project/src/backend/sdl/SDLWindow.cpp | 2 +- tools/platforms/WindowsPlatform.hx | 7 +++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lime/app/Application.hx b/lime/app/Application.hx index 898ddd9d6..e605cb00f 100644 --- a/lime/app/Application.hx +++ b/lime/app/Application.hx @@ -13,6 +13,8 @@ import flash.Lib; #elseif java import org.lwjgl.opengl.GL11; import org.lwjgl.system.glfw.GLFW; +#elseif windows +import sys.FileSystem; #end @@ -133,6 +135,15 @@ class Application extends Module { addWindow (window); + #if windows + if (FileSystem.exists ("icon.png")) { + + var image = Image.fromFile ("icon.png"); + window.setIcon (image); + + } + #end + } diff --git a/project/src/backend/sdl/SDLWindow.cpp b/project/src/backend/sdl/SDLWindow.cpp index d7b4edc6b..509022695 100644 --- a/project/src/backend/sdl/SDLWindow.cpp +++ b/project/src/backend/sdl/SDLWindow.cpp @@ -55,7 +55,7 @@ namespace lime { void SDLWindow::SetIcon (ImageBuffer *imageBuffer) { - SDL_Surface *surface = SDL_CreateRGBSurfaceFrom (imageBuffer->data->Bytes (), imageBuffer->width, imageBuffer->height, imageBuffer->bpp * 8, imageBuffer->width * imageBuffer->bpp, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000); + SDL_Surface *surface = SDL_CreateRGBSurfaceFrom (imageBuffer->data->Bytes (), imageBuffer->width, imageBuffer->height, imageBuffer->bpp * 8, imageBuffer->width * imageBuffer->bpp, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000); if (surface) { diff --git a/tools/platforms/WindowsPlatform.hx b/tools/platforms/WindowsPlatform.hx index 115c2f329..e7fa42e70 100644 --- a/tools/platforms/WindowsPlatform.hx +++ b/tools/platforms/WindowsPlatform.hx @@ -12,6 +12,7 @@ import helpers.NodeJSHelper; import helpers.PathHelper; import helpers.PlatformHelper; import helpers.ProcessHelper; +import project.Asset; import project.AssetType; import project.Haxelib; import project.HXProject; @@ -92,6 +93,8 @@ class WindowsPlatform extends PlatformTarget { } + IconHelper.createIcon (project.icons, 32, 32, PathHelper.combine (applicationDirectory, "icon.png")); + if (targetType == "neko") { ProcessHelper.runCommand ("", "haxe", [ hxml ]); @@ -134,14 +137,14 @@ class WindowsPlatform extends PlatformTarget { } - var iconPath = PathHelper.combine (applicationDirectory, "icon.ico"); + /*var iconPath = PathHelper.combine (applicationDirectory, "icon.ico"); if (IconHelper.createWindowsIcon (project.icons, iconPath)) { var templates = [ PathHelper.getHaxelib (new Haxelib ("lime")) + "/templates" ].concat (project.templatePaths); ProcessHelper.runCommand ("", PathHelper.findTemplate (templates, "bin/ReplaceVistaIcon.exe"), [ executablePath, iconPath ], true, true); - } + }*/ } From 1c0b067185e84d0454ed1c2d34b706bf899bd530 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Sun, 28 Dec 2014 13:24:13 -0800 Subject: [PATCH 07/28] Implement SDL2 SetIcon in Lime legacy --- legacy/project/include/Utils.h | 4 ++-- legacy/project/src/common/ExternalInterface.cpp | 2 +- legacy/project/src/directfb/DirectFBStage.cpp | 2 +- legacy/project/src/empty/Stage.cpp | 2 +- legacy/project/src/sdl/SDLStage.cpp | 2 +- legacy/project/src/sdl2/SDL2Stage.cpp | 12 +++++++++++- legacy/project/src/tizen/TizenStage.cpp | 2 +- legacy/project/src/winrt/WinRTStage.cpp | 2 +- 8 files changed, 19 insertions(+), 9 deletions(-) diff --git a/legacy/project/include/Utils.h b/legacy/project/include/Utils.h index 2ea32d5c1..b1917d89e 100644 --- a/legacy/project/include/Utils.h +++ b/legacy/project/include/Utils.h @@ -194,8 +194,6 @@ typedef std::wstring WString; WString IntToWide(int value); WString ColorToWide(int value); -void SetIcon( const char *path ); - int GetDeviceOrientation(); int GetNormalOrientation(); double CapabilitiesGetPixelAspectRatio (); @@ -255,6 +253,8 @@ extern int gFixedOrientation; #endif +void SetIcon( const OSChar *path ); + std::string GetExeName(); diff --git a/legacy/project/src/common/ExternalInterface.cpp b/legacy/project/src/common/ExternalInterface.cpp index 08332a0bf..2556720aa 100644 --- a/legacy/project/src/common/ExternalInterface.cpp +++ b/legacy/project/src/common/ExternalInterface.cpp @@ -928,7 +928,7 @@ DEFINE_PRIM(nme_get_unique_device_identifier,0); value nme_set_icon( value path ) { //printf( "setting icon\n" ); #if defined( HX_WINDOWS ) || defined( HX_MACOS ) - SetIcon( val_string( path ) ); + SetIcon( val_os_string( path ) ); #endif return alloc_null(); } diff --git a/legacy/project/src/directfb/DirectFBStage.cpp b/legacy/project/src/directfb/DirectFBStage.cpp index e0bbc86ea..cefbe677d 100644 --- a/legacy/project/src/directfb/DirectFBStage.cpp +++ b/legacy/project/src/directfb/DirectFBStage.cpp @@ -370,7 +370,7 @@ void CreateMainFrame(FrameCreationCallback inOnFrame, int inWidth, int inHeight, } -void SetIcon(const char *path) +void SetIcon(const OSChar *path) { } diff --git a/legacy/project/src/empty/Stage.cpp b/legacy/project/src/empty/Stage.cpp index b08f8e26f..35cb79324 100644 --- a/legacy/project/src/empty/Stage.cpp +++ b/legacy/project/src/empty/Stage.cpp @@ -17,7 +17,7 @@ void CreateMainFrame(nme::FrameCreationCallback inOnFrame,int inWidth,int inHeig bool sgDead = false; -void SetIcon( const char *path ) { } +void SetIcon( const OSChar *path ) { } QuickVec *CapabilitiesGetScreenResolutions() { diff --git a/legacy/project/src/sdl/SDLStage.cpp b/legacy/project/src/sdl/SDLStage.cpp index d232ce042..9c92e9de2 100644 --- a/legacy/project/src/sdl/SDLStage.cpp +++ b/legacy/project/src/sdl/SDLStage.cpp @@ -1343,7 +1343,7 @@ void CreateMainFrame(FrameCreationCallback inOnFrame,int inWidth,int inHeight, bool sgDead = false; -void SetIcon( const char *path ) { +void SetIcon( const OSChar *path ) { #ifndef EMSCRIPTEN initSDL(); diff --git a/legacy/project/src/sdl2/SDL2Stage.cpp b/legacy/project/src/sdl2/SDL2Stage.cpp index cfeca5431..bc536b5f6 100644 --- a/legacy/project/src/sdl2/SDL2Stage.cpp +++ b/legacy/project/src/sdl2/SDL2Stage.cpp @@ -1591,9 +1591,19 @@ void CreateMainFrame(FrameCreationCallback inOnFrame, int inWidth, int inHeight, bool sgDead = false; -void SetIcon(const char *path) +void SetIcon(const OSChar *path) { + Surface *surface = Surface::Load(path); + if (surface) + { + SDL_Surface *sdlSurface = SDL_CreateRGBSurfaceFrom ((void *)surface->GetBase(), surface->Width(), surface->Height(), 32, surface->GetStride(), 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000); + + SDL_SetWindowIcon(sgSDLFrame->mStage->mSDLWindow, sdlSurface); + + surface->DecRef(); + SDL_FreeSurface (sdlSurface); + } } diff --git a/legacy/project/src/tizen/TizenStage.cpp b/legacy/project/src/tizen/TizenStage.cpp index 87cd13f6f..340d91b8b 100644 --- a/legacy/project/src/tizen/TizenStage.cpp +++ b/legacy/project/src/tizen/TizenStage.cpp @@ -213,7 +213,7 @@ namespace nme { } - void SetIcon (const char *path) {} + void SetIcon (const OSChar *path) {} } diff --git a/legacy/project/src/winrt/WinRTStage.cpp b/legacy/project/src/winrt/WinRTStage.cpp index dabe61b2c..7650e70f3 100644 --- a/legacy/project/src/winrt/WinRTStage.cpp +++ b/legacy/project/src/winrt/WinRTStage.cpp @@ -710,7 +710,7 @@ void CreateMainFrame(nme::FrameCreationCallback inOnFrame,int inWidth,int inHeig bool sgDead = false; -void SetIcon( const char *path ) { } +void SetIcon( const OSChar *path ) { } QuickVec *CapabilitiesGetScreenResolutions() { From 61216f14f76141ebf0fb5a597a2f6b3b343b2934 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Sun, 28 Dec 2014 13:29:36 -0800 Subject: [PATCH 08/28] Restore Windows Explorer icon --- tools/platforms/WindowsPlatform.hx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/platforms/WindowsPlatform.hx b/tools/platforms/WindowsPlatform.hx index e7fa42e70..8dfaeaa3b 100644 --- a/tools/platforms/WindowsPlatform.hx +++ b/tools/platforms/WindowsPlatform.hx @@ -137,14 +137,14 @@ class WindowsPlatform extends PlatformTarget { } - /*var iconPath = PathHelper.combine (applicationDirectory, "icon.ico"); + var iconPath = PathHelper.combine (applicationDirectory, "icon.ico"); if (IconHelper.createWindowsIcon (project.icons, iconPath)) { var templates = [ PathHelper.getHaxelib (new Haxelib ("lime")) + "/templates" ].concat (project.templatePaths); ProcessHelper.runCommand ("", PathHelper.findTemplate (templates, "bin/ReplaceVistaIcon.exe"), [ executablePath, iconPath ], true, true); - }*/ + } } From f018f49e8a78cc94b71b78ce234241dfb7ea1328 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Sun, 28 Dec 2014 14:33:48 -0800 Subject: [PATCH 09/28] Validate haxelib when checking version --- tools/CommandLineTools.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/CommandLineTools.hx b/tools/CommandLineTools.hx index 3bece1f85..61c6954b8 100644 --- a/tools/CommandLineTools.hx +++ b/tools/CommandLineTools.hx @@ -1032,7 +1032,7 @@ class CommandLineTools { } - var json = Json.parse (File.getContent (PathHelper.getHaxelib (haxelib) + "/haxelib.json")); + var json = Json.parse (File.getContent (PathHelper.getHaxelib (haxelib, true) + "/haxelib.json")); return json.version; } From 95df09575f54765b4c0a85776b7dbd1941075540 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Mon, 29 Dec 2014 11:45:01 -0800 Subject: [PATCH 10/28] Add support for mouse hide/show/cursor on HTML5, initially --- lime/ui/Mouse.hx | 107 +++++++++++++++++++++++++++++++++++++++++ lime/ui/MouseCursor.hx | 13 +++++ 2 files changed, 120 insertions(+) create mode 100644 lime/ui/Mouse.hx create mode 100644 lime/ui/MouseCursor.hx diff --git a/lime/ui/Mouse.hx b/lime/ui/Mouse.hx new file mode 100644 index 000000000..8d976c755 --- /dev/null +++ b/lime/ui/Mouse.hx @@ -0,0 +1,107 @@ +package lime.ui; + + +import lime.app.Application; + +@:access(lime.app.Application) + + +class Mouse { + + + public static var cursor (get, set):MouseCursor; + + + private static var __cursor:MouseCursor; + private static var __hidden:Bool; + + + public static function hide ():Void { + + if (!__hidden) { + + #if (js && html5) + + for (window in Application.__instance.windows) { + + window.element.style.cursor = "none"; + + } + + #end + + __hidden = true; + + } + + } + + + public static function show ():Void { + + if (__hidden) { + + #if (js && html5) + + var cacheValue = __cursor; + __cursor = null; + cursor = cacheValue; + + #end + + __hidden = false; + + } + + } + + + + + // Get & Set Methods + + + + + private static function get_cursor ():MouseCursor { + + if (__cursor == null) return DEFAULT; + return __cursor; + + } + + + private static function set_cursor (value:MouseCursor):MouseCursor { + + if (__cursor != value) { + + if (!__hidden) { + + #if (js && html5) + + for (window in Application.__instance.windows) { + + window.element.style.cursor = switch (value) { + + case POINTER: "pointer"; + case TEXT: "text"; + default: "default"; + + } + + } + + #end + + } + + __cursor = value; + + } + + return __cursor; + + } + + +} \ No newline at end of file diff --git a/lime/ui/MouseCursor.hx b/lime/ui/MouseCursor.hx new file mode 100644 index 000000000..21ef509a9 --- /dev/null +++ b/lime/ui/MouseCursor.hx @@ -0,0 +1,13 @@ +package lime.ui; + + +enum MouseCursor { + + + DEFAULT; + POINTER; + TEXT; + CUSTOM; + + +} \ No newline at end of file From f1d08f096f3ba35022dd0924aa1c6c636db1e27b Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Mon, 29 Dec 2014 12:28:14 -0800 Subject: [PATCH 11/28] Add Lime mouse cursor support on SDL2 --- lime/ui/Mouse.hx | 37 +++++++++++++ project/Build.xml | 1 + project/include/ui/Mouse.h | 27 ++++++++++ project/include/ui/MouseCursor.h | 21 ++++++++ project/src/ExternalInterface.cpp | 29 +++++++++++ project/src/backend/sdl/SDLMouse.cpp | 77 ++++++++++++++++++++++++++++ project/src/backend/sdl/SDLMouse.h | 27 ++++++++++ 7 files changed, 219 insertions(+) create mode 100644 project/include/ui/Mouse.h create mode 100644 project/include/ui/MouseCursor.h create mode 100644 project/src/backend/sdl/SDLMouse.cpp create mode 100644 project/src/backend/sdl/SDLMouse.h diff --git a/lime/ui/Mouse.hx b/lime/ui/Mouse.hx index 8d976c755..8682a78e2 100644 --- a/lime/ui/Mouse.hx +++ b/lime/ui/Mouse.hx @@ -2,6 +2,7 @@ package lime.ui; import lime.app.Application; +import lime.system.System; @:access(lime.app.Application) @@ -28,6 +29,10 @@ class Mouse { } + #elseif (cpp || neko || nodejs) + + lime_mouse_hide (); + #end __hidden = true; @@ -47,6 +52,10 @@ class Mouse { __cursor = null; cursor = cacheValue; + #elseif (cpp || neko || nodejs) + + lime_mouse_show (); + #end __hidden = false; @@ -91,6 +100,18 @@ class Mouse { } + #elseif (cpp || neko || nodejs) + + var type = switch (value) { + + case POINTER: MouseCursorType.POINTER; + case TEXT: MouseCursorType.TEXT; + default: MouseCursorType.DEFAULT; + + } + + lime_mouse_set_cursor (type); + #end } @@ -104,4 +125,20 @@ class Mouse { } + #if (cpp || neko || nodejs) + private static var lime_mouse_hide = System.load ("lime", "lime_mouse_hide", 0); + private static var lime_mouse_set_cursor = System.load ("lime", "lime_mouse_set_cursor", 1); + private static var lime_mouse_show = System.load ("lime", "lime_mouse_show", 0); + #end + + +} + + +@:enum private abstract MouseCursorType(Int) { + + var DEFAULT = 0; + var POINTER = 1; + var TEXT = 2; + } \ No newline at end of file diff --git a/project/Build.xml b/project/Build.xml index dcaca2103..6bee43798 100644 --- a/project/Build.xml +++ b/project/Build.xml @@ -132,6 +132,7 @@ + diff --git a/project/include/ui/Mouse.h b/project/include/ui/Mouse.h new file mode 100644 index 000000000..f444b6b89 --- /dev/null +++ b/project/include/ui/Mouse.h @@ -0,0 +1,27 @@ +#ifndef LIME_UI_MOUSE_H +#define LIME_UI_MOUSE_H + + +#include + + +namespace lime { + + + class Mouse { + + public: + + static MouseCursor currentCursor; + + static void Hide (); + static void SetCursor (MouseCursor cursor); + static void Show (); + + }; + + +} + + +#endif \ No newline at end of file diff --git a/project/include/ui/MouseCursor.h b/project/include/ui/MouseCursor.h new file mode 100644 index 000000000..e8f93d7d8 --- /dev/null +++ b/project/include/ui/MouseCursor.h @@ -0,0 +1,21 @@ +#ifndef LIME_UI_MOUSE_CURSOR_H +#define LIME_UI_MOUSE_CURSOR_H + + +namespace lime { + + + enum MouseCursor { + + DEFAULT, + POINTER, + TEXT, + CUSTOM + + }; + + +} + + +#endif \ No newline at end of file diff --git a/project/src/ExternalInterface.cpp b/project/src/ExternalInterface.cpp index 68d3eb2ef..5b20108a0 100644 --- a/project/src/ExternalInterface.cpp +++ b/project/src/ExternalInterface.cpp @@ -24,6 +24,8 @@ #include #include #include +#include +#include #include #include #include @@ -329,6 +331,30 @@ namespace lime { } + value lime_mouse_hide () { + + Mouse::Hide (); + return alloc_null (); + + } + + + value lime_mouse_set_cursor (value cursor) { + + Mouse::SetCursor ((MouseCursor)val_int (cursor)); + return alloc_null (); + + } + + + value lime_mouse_show () { + + Mouse::Show (); + return alloc_null (); + + } + + value lime_neko_execute (value module) { #ifdef LIME_NEKO @@ -490,6 +516,9 @@ namespace lime { DEFINE_PRIM (lime_key_event_manager_register, 2); DEFINE_PRIM (lime_lzma_encode, 1); DEFINE_PRIM (lime_lzma_decode, 1); + DEFINE_PRIM (lime_mouse_hide, 0); + DEFINE_PRIM (lime_mouse_set_cursor, 1); + DEFINE_PRIM (lime_mouse_show, 0); DEFINE_PRIM (lime_mouse_event_manager_register, 2); DEFINE_PRIM (lime_neko_execute, 1); DEFINE_PRIM (lime_renderer_create, 1); diff --git a/project/src/backend/sdl/SDLMouse.cpp b/project/src/backend/sdl/SDLMouse.cpp new file mode 100644 index 000000000..b8f9536d3 --- /dev/null +++ b/project/src/backend/sdl/SDLMouse.cpp @@ -0,0 +1,77 @@ +#include "SDLMouse.h" + + +namespace lime { + + + MouseCursor Mouse::currentCursor = DEFAULT; + SDL_Cursor* SDLMouse::defaultCursor = 0; + SDL_Cursor* SDLMouse::pointerCursor = 0; + SDL_Cursor* SDLMouse::textCursor = 0; + + + void Mouse::Hide () { + + SDL_ShowCursor (SDL_DISABLE); + + } + + + void Mouse::SetCursor (MouseCursor cursor) { + + if (cursor != Mouse::currentCursor) { + + switch (cursor) { + + case POINTER: + + if (!SDLMouse::pointerCursor) { + + SDLMouse::pointerCursor = SDL_CreateSystemCursor (SDL_SYSTEM_CURSOR_HAND); + + } + + SDL_SetCursor (SDLMouse::pointerCursor); + break; + + case TEXT: + + if (!SDLMouse::textCursor) { + + SDLMouse::textCursor = SDL_CreateSystemCursor (SDL_SYSTEM_CURSOR_IBEAM); + + } + + SDL_SetCursor (SDLMouse::textCursor); + break; + + default: + + if (!SDLMouse::defaultCursor) { + + SDLMouse::defaultCursor = SDL_CreateSystemCursor (SDL_SYSTEM_CURSOR_ARROW); + + } + + SDL_SetCursor (SDLMouse::defaultCursor); + break; + + } + + Mouse::currentCursor = cursor; + + } + + + + } + + + void Mouse::Show () { + + SDL_ShowCursor (SDL_ENABLE); + + } + + +} \ No newline at end of file diff --git a/project/src/backend/sdl/SDLMouse.h b/project/src/backend/sdl/SDLMouse.h new file mode 100644 index 000000000..a294d0c7f --- /dev/null +++ b/project/src/backend/sdl/SDLMouse.h @@ -0,0 +1,27 @@ +#ifndef LIME_SDL_MOUSE_H +#define LIME_SDL_MOUSE_H + + +#include +#include +#include + + +namespace lime { + + + class SDLMouse { + + public: + + static SDL_Cursor* defaultCursor; + static SDL_Cursor* pointerCursor; + static SDL_Cursor* textCursor; + + }; + + +} + + +#endif \ No newline at end of file From ed34459738b8a72982d3095f46efa31b0a8dd716 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Mon, 29 Dec 2014 13:41:13 -0800 Subject: [PATCH 12/28] Add more mouse cursor types --- lime/ui/Mouse.hx | 51 ++++++++++--- lime/ui/MouseCursor.hx | 11 ++- project/include/ui/MouseCursor.h | 15 +++- project/src/backend/sdl/SDLMouse.cpp | 109 +++++++++++++++++++++++++-- project/src/backend/sdl/SDLMouse.h | 10 ++- 5 files changed, 171 insertions(+), 25 deletions(-) diff --git a/lime/ui/Mouse.hx b/lime/ui/Mouse.hx index 8682a78e2..02e124b15 100644 --- a/lime/ui/Mouse.hx +++ b/lime/ui/Mouse.hx @@ -21,6 +21,8 @@ class Mouse { if (!__hidden) { + __hidden = true; + #if (js && html5) for (window in Application.__instance.windows) { @@ -35,8 +37,6 @@ class Mouse { #end - __hidden = true; - } } @@ -46,6 +46,8 @@ class Mouse { if (__hidden) { + __hidden = false; + #if (js && html5) var cacheValue = __cursor; @@ -58,8 +60,6 @@ class Mouse { #end - __hidden = false; - } } @@ -92,9 +92,18 @@ class Mouse { window.element.style.cursor = switch (value) { + case ARROW: "default"; + case CROSSHAIR: "crosshair"; + case MOVE: "move"; case POINTER: "pointer"; + case RESIZE_NESW: "nesw-resize"; + case RESIZE_NS: "ns-resize"; + case RESIZE_NWSE: "nwse-resize"; + case RESIZE_WE: "ew-resize"; case TEXT: "text"; - default: "default"; + case WAIT: "wait"; + case WAIT_ARROW: "wait"; + default: "auto"; } @@ -102,11 +111,20 @@ class Mouse { #elseif (cpp || neko || nodejs) - var type = switch (value) { + var type:MouseCursorType = switch (value) { - case POINTER: MouseCursorType.POINTER; - case TEXT: MouseCursorType.TEXT; - default: MouseCursorType.DEFAULT; + case ARROW: ARROW; + case CROSSHAIR: CROSSHAIR; + case MOVE: MOVE; + case POINTER: POINTER; + case RESIZE_NESW: RESIZE_NESW; + case RESIZE_NS: RESIZE_NS; + case RESIZE_NWSE: RESIZE_NWSE; + case RESIZE_WE: RESIZE_WE; + case TEXT: TEXT; + case WAIT: WAIT; + case WAIT_ARROW: WAIT_ARROW; + default: DEFAULT; } @@ -137,8 +155,17 @@ class Mouse { @:enum private abstract MouseCursorType(Int) { - var DEFAULT = 0; - var POINTER = 1; - var TEXT = 2; + var ARROW = 0; + var CROSSHAIR = 1; + var DEFAULT = 2; + var MOVE = 3; + var POINTER = 4; + var RESIZE_NESW = 5; + var RESIZE_NS = 6; + var RESIZE_NWSE = 7; + var RESIZE_WE = 8; + var TEXT = 9; + var WAIT = 10; + var WAIT_ARROW = 11; } \ No newline at end of file diff --git a/lime/ui/MouseCursor.hx b/lime/ui/MouseCursor.hx index 21ef509a9..8d07f8803 100644 --- a/lime/ui/MouseCursor.hx +++ b/lime/ui/MouseCursor.hx @@ -3,11 +3,18 @@ package lime.ui; enum MouseCursor { - + ARROW; + CROSSHAIR; DEFAULT; + MOVE; POINTER; + RESIZE_NESW; + RESIZE_NS; + RESIZE_NWSE; + RESIZE_WE; TEXT; + WAIT; + WAIT_ARROW; CUSTOM; - } \ No newline at end of file diff --git a/project/include/ui/MouseCursor.h b/project/include/ui/MouseCursor.h index e8f93d7d8..5194f025d 100644 --- a/project/include/ui/MouseCursor.h +++ b/project/include/ui/MouseCursor.h @@ -7,9 +7,18 @@ namespace lime { enum MouseCursor { - DEFAULT, - POINTER, - TEXT, + ARROW, + CROSSHAIR, + DEFAULT, + MOVE, + POINTER, + RESIZE_NESW, + RESIZE_NS, + RESIZE_NWSE, + RESIZE_WE, + TEXT, + WAIT, + WAIT_ARROW, CUSTOM }; diff --git a/project/src/backend/sdl/SDLMouse.cpp b/project/src/backend/sdl/SDLMouse.cpp index b8f9536d3..0c11d7be1 100644 --- a/project/src/backend/sdl/SDLMouse.cpp +++ b/project/src/backend/sdl/SDLMouse.cpp @@ -5,9 +5,18 @@ namespace lime { MouseCursor Mouse::currentCursor = DEFAULT; - SDL_Cursor* SDLMouse::defaultCursor = 0; + + SDL_Cursor* SDLMouse::arrowCursor = 0; + SDL_Cursor* SDLMouse::crosshairCursor = 0; + SDL_Cursor* SDLMouse::moveCursor = 0; SDL_Cursor* SDLMouse::pointerCursor = 0; + SDL_Cursor* SDLMouse::resizeNESWCursor = 0; + SDL_Cursor* SDLMouse::resizeNSCursor = 0; + SDL_Cursor* SDLMouse::resizeNWSECursor = 0; + SDL_Cursor* SDLMouse::resizeWECursor = 0; SDL_Cursor* SDLMouse::textCursor = 0; + SDL_Cursor* SDLMouse::waitCursor = 0; + SDL_Cursor* SDLMouse::waitArrowCursor = 0; void Mouse::Hide () { @@ -23,6 +32,28 @@ namespace lime { switch (cursor) { + case CROSSHAIR: + + if (!SDLMouse::crosshairCursor) { + + SDLMouse::crosshairCursor = SDL_CreateSystemCursor (SDL_SYSTEM_CURSOR_CROSSHAIR); + + } + + SDL_SetCursor (SDLMouse::crosshairCursor); + break; + + case MOVE: + + if (!SDLMouse::moveCursor) { + + SDLMouse::moveCursor = SDL_CreateSystemCursor (SDL_SYSTEM_CURSOR_SIZEALL); + + } + + SDL_SetCursor (SDLMouse::moveCursor); + break; + case POINTER: if (!SDLMouse::pointerCursor) { @@ -34,6 +65,50 @@ namespace lime { SDL_SetCursor (SDLMouse::pointerCursor); break; + case RESIZE_NESW: + + if (!SDLMouse::resizeNESWCursor) { + + SDLMouse::resizeNESWCursor = SDL_CreateSystemCursor (SDL_SYSTEM_CURSOR_SIZENESW); + + } + + SDL_SetCursor (SDLMouse::resizeNESWCursor); + break; + + case RESIZE_NS: + + if (!SDLMouse::resizeNSCursor) { + + SDLMouse::resizeNSCursor = SDL_CreateSystemCursor (SDL_SYSTEM_CURSOR_SIZENS); + + } + + SDL_SetCursor (SDLMouse::resizeNSCursor); + break; + + case RESIZE_NWSE: + + if (!SDLMouse::resizeNWSECursor) { + + SDLMouse::resizeNWSECursor = SDL_CreateSystemCursor (SDL_SYSTEM_CURSOR_SIZENWSE); + + } + + SDL_SetCursor (SDLMouse::resizeNWSECursor); + break; + + case RESIZE_WE: + + if (!SDLMouse::resizeWECursor) { + + SDLMouse::resizeWECursor = SDL_CreateSystemCursor (SDL_SYSTEM_CURSOR_SIZEWE); + + } + + SDL_SetCursor (SDLMouse::resizeWECursor); + break; + case TEXT: if (!SDLMouse::textCursor) { @@ -45,15 +120,37 @@ namespace lime { SDL_SetCursor (SDLMouse::textCursor); break; - default: + case WAIT: - if (!SDLMouse::defaultCursor) { + if (!SDLMouse::waitCursor) { - SDLMouse::defaultCursor = SDL_CreateSystemCursor (SDL_SYSTEM_CURSOR_ARROW); + SDLMouse::waitCursor = SDL_CreateSystemCursor (SDL_SYSTEM_CURSOR_WAIT); } - SDL_SetCursor (SDLMouse::defaultCursor); + SDL_SetCursor (SDLMouse::waitCursor); + break; + + case WAIT_ARROW: + + if (!SDLMouse::waitArrowCursor) { + + SDLMouse::waitArrowCursor = SDL_CreateSystemCursor (SDL_SYSTEM_CURSOR_WAITARROW); + + } + + SDL_SetCursor (SDLMouse::waitArrowCursor); + break; + + default: + + if (!SDLMouse::arrowCursor) { + + SDLMouse::arrowCursor = SDL_CreateSystemCursor (SDL_SYSTEM_CURSOR_ARROW); + + } + + SDL_SetCursor (SDLMouse::arrowCursor); break; } @@ -62,8 +159,6 @@ namespace lime { } - - } diff --git a/project/src/backend/sdl/SDLMouse.h b/project/src/backend/sdl/SDLMouse.h index a294d0c7f..8ab457941 100644 --- a/project/src/backend/sdl/SDLMouse.h +++ b/project/src/backend/sdl/SDLMouse.h @@ -14,9 +14,17 @@ namespace lime { public: - static SDL_Cursor* defaultCursor; + static SDL_Cursor* arrowCursor; + static SDL_Cursor* crosshairCursor; + static SDL_Cursor* moveCursor; static SDL_Cursor* pointerCursor; + static SDL_Cursor* resizeNESWCursor; + static SDL_Cursor* resizeNSCursor; + static SDL_Cursor* resizeNWSECursor; + static SDL_Cursor* resizeWECursor; static SDL_Cursor* textCursor; + static SDL_Cursor* waitCursor; + static SDL_Cursor* waitArrowCursor; }; From d64c14a0fc81d452cba0958d5c1dd17568f0abcf Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Mon, 29 Dec 2014 13:54:11 -0800 Subject: [PATCH 13/28] Implement cursor on Flash --- lime/ui/Mouse.hx | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/lime/ui/Mouse.hx b/lime/ui/Mouse.hx index 02e124b15..ba4c7a59e 100644 --- a/lime/ui/Mouse.hx +++ b/lime/ui/Mouse.hx @@ -4,6 +4,11 @@ package lime.ui; import lime.app.Application; import lime.system.System; +#if flash +import flash.ui.Mouse in FlashMouse; +import flash.ui.MouseCursor in FlashMouseCursor; +#end + @:access(lime.app.Application) @@ -35,6 +40,10 @@ class Mouse { lime_mouse_hide (); + #elseif flash + + FlashMouse.hide (); + #end } @@ -58,6 +67,10 @@ class Mouse { lime_mouse_show (); + #elseif flash + + FlashMouse.show (); + #end } @@ -130,6 +143,25 @@ class Mouse { lime_mouse_set_cursor (type); + #elseif flash + + FlashMouse.cursor = switch (value) { + + case ARROW: FlashMouseCursor.ARROW; + case CROSSHAIR: FlashMouseCursor.ARROW; + case MOVE: FlashMouseCursor.HAND; + case POINTER: FlashMouseCursor.BUTTON; + case RESIZE_NESW: FlashMouseCursor.HAND; + case RESIZE_NS: FlashMouseCursor.HAND; + case RESIZE_NWSE: FlashMouseCursor.HAND; + case RESIZE_WE: FlashMouseCursor.HAND; + case TEXT: FlashMouseCursor.IBEAM; + case WAIT: FlashMouseCursor.ARROW; + case WAIT_ARROW: FlashMouseCursor.ARROW; + default: FlashMouseCursor.AUTO; + + } + #end } From 4c8122b00206c3045657ca59430b7dddc6de0ceb Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Mon, 29 Dec 2014 14:09:11 -0800 Subject: [PATCH 14/28] Disable Lime right-click mouse event in Flash when using OpenFL, by default. This preserves the context menu --- lime/ui/MouseEventManager.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lime/ui/MouseEventManager.hx b/lime/ui/MouseEventManager.hx index 867e4362f..81ddad7a3 100644 --- a/lime/ui/MouseEventManager.hx +++ b/lime/ui/MouseEventManager.hx @@ -181,7 +181,7 @@ class MouseEventManager { #elseif flash - var events = [ "mouseDown", "mouseMove", "mouseUp", "mouseWheel", "middleMouseDown", "middleMouseMove", "middleMouseUp", "rightMouseDown", "rightMouseMove", "rightMouseUp" ]; + var events = [ "mouseDown", "mouseMove", "mouseUp", "mouseWheel", "middleMouseDown", "middleMouseMove", "middleMouseUp" #if ((!openfl && !disable_flash_right_click) || enable_flash_right_click) , "rightMouseDown", "rightMouseMove", "rightMouseUp" #end ]; for (event in events) { From c422dba7f0ad6397b55d02797c11beb79ebe180c Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Mon, 29 Dec 2014 21:14:33 -0800 Subject: [PATCH 15/28] Some code cleanup --- lime/app/Application.hx | 206 +++++++++++---------- lime/app/Preloader.hx | 114 ++++++------ lime/audio/AudioBuffer.hx | 48 ++--- lime/audio/AudioManager.hx | 37 ++-- lime/audio/AudioSource.hx | 34 ++-- lime/graphics/Image.hx | 340 ++++++++++++++++++----------------- lime/graphics/ImageBuffer.hx | 40 +++-- lime/graphics/Renderer.hx | 125 +++++++------ lime/system/System.hx | 78 ++++---- lime/ui/KeyEventManager.hx | 291 +++++++++++++++--------------- lime/ui/Mouse.hx | 153 ++++++++-------- lime/ui/MouseEventManager.hx | 191 ++++++++++---------- lime/ui/TouchEventManager.hx | 151 ++++++++-------- lime/ui/Window.hx | 260 ++++++++++++++------------- 14 files changed, 1099 insertions(+), 969 deletions(-) diff --git a/lime/app/Application.hx b/lime/app/Application.hx index e605cb00f..3fecdac25 100644 --- a/lime/app/Application.hx +++ b/lime/app/Application.hx @@ -59,7 +59,9 @@ class Application extends Module { AudioManager.init (); #if (cpp || neko || nodejs) - lime_update_event_manager_register (__dispatch, __eventInfo); + + lime_update_event_manager_register (__dispatch, __eventInfo); + #end } @@ -91,9 +93,13 @@ class Application extends Module { this.config = config; #if (cpp || neko || nodejs) - __handle = lime_application_create (null); + + __handle = lime_application_create (null); + #elseif java - GLFW.glfwInit (); + + GLFW.glfwInit (); + #end KeyEventManager.create (); @@ -130,18 +136,22 @@ class Application extends Module { window.height = config.height; #if (js && html5) - window.element = config.element; + + window.element = config.element; + #end addWindow (window); #if windows - if (FileSystem.exists ("icon.png")) { - var image = Image.fromFile ("icon.png"); - window.setIcon (image); + if (FileSystem.exists ("icon.png")) { + + var image = Image.fromFile ("icon.png"); + window.setIcon (image); + + } - } #end } @@ -156,114 +166,107 @@ class Application extends Module { public function exec ():Int { #if nodejs - - lime_application_init (__handle); - - var prevTime = untyped __js__ ('Date.now ()'); - var eventLoop = function () { - var active = lime_application_update (__handle); + lime_application_init (__handle); - if (!active) { + var prevTime = untyped __js__ ('Date.now ()'); + var eventLoop = function () { - var result = lime_application_quit (__handle); - __cleanup (); - Sys.exit (result); + var active = lime_application_update (__handle); + + if (!active) { + + var result = lime_application_quit (__handle); + __cleanup (); + Sys.exit (result); + + } + + var time = untyped __js__ ('Date.now ()'); + if (time - prevTime <= 16) { + + untyped setTimeout (eventLoop, 0); + + } + else { + + untyped setImmediate (eventLoop); + + } + + prevTime = time; } - var time = untyped __js__ ('Date.now ()'); - if (time - prevTime <= 16) { - - untyped setTimeout (eventLoop, 0); - - } - else { - - untyped setImmediate (eventLoop); - - } + untyped setImmediate (eventLoop); - prevTime = time; - - } - - untyped setImmediate (eventLoop); - #elseif (cpp || neko) - - lime_application_init (__handle); - - while (lime_application_update (__handle)) {} - - var result = lime_application_quit (__handle); - __cleanup (); - - return result; - + + lime_application_init (__handle); + + while (lime_application_update (__handle)) {} + + var result = lime_application_quit (__handle); + __cleanup (); + + return result; + #elseif (js && html5) - - untyped __js__ (" - var lastTime = 0; - var vendors = ['ms', 'moz', 'webkit', 'o']; - for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { - window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame']; - window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame'] - || window[vendors[x]+'CancelRequestAnimationFrame']; - } - if (!window.requestAnimationFrame) - window.requestAnimationFrame = function(callback, element) { - var currTime = new Date().getTime(); - var timeToCall = Math.max(0, 16 - (currTime - lastTime)); - var id = window.setTimeout(function() { callback(currTime + timeToCall); }, - timeToCall); - lastTime = currTime + timeToCall; - return id; - }; + untyped __js__ (" + var lastTime = 0; + var vendors = ['ms', 'moz', 'webkit', 'o']; + for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { + window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame']; + window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame'] + || window[vendors[x]+'CancelRequestAnimationFrame']; + } + + if (!window.requestAnimationFrame) + window.requestAnimationFrame = function(callback, element) { + var currTime = new Date().getTime(); + var timeToCall = Math.max(0, 16 - (currTime - lastTime)); + var id = window.setTimeout(function() { callback(currTime + timeToCall); }, + timeToCall); + lastTime = currTime + timeToCall; + return id; + }; + + if (!window.cancelAnimationFrame) + window.cancelAnimationFrame = function(id) { + clearTimeout(id); + }; + + window.requestAnimFrame = window.requestAnimationFrame; + "); - if (!window.cancelAnimationFrame) - window.cancelAnimationFrame = function(id) { - clearTimeout(id); - }; + __triggerFrame (); - window.requestAnimFrame = window.requestAnimationFrame; - "); - - __triggerFrame (); - #elseif flash - - Lib.current.stage.addEventListener (flash.events.Event.ENTER_FRAME, __triggerFrame); - - #elseif java - - if (window != null) { - while (GLFW.glfwWindowShouldClose (window.handle) == GL11.GL_FALSE) { + Lib.current.stage.addEventListener (flash.events.Event.ENTER_FRAME, __triggerFrame); + + #elseif java + + if (window != null) { - __triggerFrame (); - - GLFW.glfwSwapBuffers (window.handle); - GLFW.glfwPollEvents (); + while (GLFW.glfwWindowShouldClose (window.handle) == GL11.GL_FALSE) { + + __triggerFrame (); + + GLFW.glfwSwapBuffers (window.handle); + GLFW.glfwPollEvents (); + + } } - } - #end return 0; } - #if (cpp || neko || nodejs) - @:noCompletion private function __cleanup():Void { - - AudioManager.shutdown(); - - } - #end /** * The init() method is called once before the first render() @@ -437,10 +440,23 @@ class Application extends Module { } + @:noCompletion private function __cleanup():Void { + + #if (cpp || neko || nodejs) + + AudioManager.shutdown(); + + #end + + } + + @:noCompletion private static function __dispatch ():Void { #if (js && stats) - __instance.window.stats.begin (); + + __instance.window.stats.begin (); + #end __instance.update (__eventInfo.deltaTime); @@ -457,7 +473,9 @@ class Application extends Module { Renderer.render (); #if (js && html5) - Browser.window.requestAnimationFrame (cast __triggerFrame); + + Browser.window.requestAnimationFrame (cast __triggerFrame); + #end } diff --git a/lime/app/Preloader.hx b/lime/app/Preloader.hx index 0744073da..25a9b33b2 100644 --- a/lime/app/Preloader.hx +++ b/lime/app/Preloader.hx @@ -34,7 +34,9 @@ class Preloader #if flash extends Sprite #end { public function new () { #if flash - super (); + + super (); + #end } @@ -43,19 +45,23 @@ class Preloader #if flash extends Sprite #end { public function create (config:Config):Void { #if flash - Lib.current.stage.align = flash.display.StageAlign.TOP_LEFT; - Lib.current.stage.scaleMode = flash.display.StageScaleMode.NO_SCALE; - - Lib.current.addChild (this); - - Lib.current.loaderInfo.addEventListener (Event.COMPLETE, loaderInfo_onComplete); - Lib.current.loaderInfo.addEventListener (Event.INIT, loaderInfo_onInit); - Lib.current.loaderInfo.addEventListener (ProgressEvent.PROGRESS, loaderInfo_onProgress); - Lib.current.addEventListener (Event.ENTER_FRAME, current_onEnter); + + Lib.current.stage.align = flash.display.StageAlign.TOP_LEFT; + Lib.current.stage.scaleMode = flash.display.StageScaleMode.NO_SCALE; + + Lib.current.addChild (this); + + Lib.current.loaderInfo.addEventListener (Event.COMPLETE, loaderInfo_onComplete); + Lib.current.loaderInfo.addEventListener (Event.INIT, loaderInfo_onInit); + Lib.current.loaderInfo.addEventListener (ProgressEvent.PROGRESS, loaderInfo_onProgress); + Lib.current.addEventListener (Event.ENTER_FRAME, current_onEnter); + #end #if (!flash && !html5) - start (); + + start (); + #end } @@ -64,61 +70,61 @@ class Preloader #if flash extends Sprite #end { public function load (urls:Array, types:Array):Void { #if (js && html5) - - var url = null; - - for (i in 0...urls.length) { - url = urls[i]; + var url = null; - switch (types[i]) { + for (i in 0...urls.length) { - case IMAGE: + url = urls[i]; + + switch (types[i]) { - var image = new Image (); - images.set (url, image); - image.onload = image_onLoad; - image.src = url; - total++; - - case BINARY: + case IMAGE: + + var image = new Image (); + images.set (url, image); + image.onload = image_onLoad; + image.src = url; + total++; - var loader = new URLLoader (); - loader.dataFormat = BINARY; - loaders.set (url, loader); - total++; - - case TEXT: + case BINARY: + + var loader = new URLLoader (); + loader.dataFormat = BINARY; + loaders.set (url, loader); + total++; - var loader = new URLLoader (); - loaders.set (url, loader); - total++; - - case FONT: + case TEXT: + + var loader = new URLLoader (); + loaders.set (url, loader); + total++; - total++; - loadFont (url); - - default: + case FONT: + + total++; + loadFont (url); + + default: + + } } - } - - for (url in loaders.keys ()) { + for (url in loaders.keys ()) { + + var loader = loaders.get (url); + loader.onComplete.add (loader_onComplete); + loader.load (new URLRequest (url)); + + } - var loader = loaders.get (url); - loader.onComplete.add (loader_onComplete); - loader.load (new URLRequest (url)); + if (total == 0) { + + start (); + + } - } - - if (total == 0) { - - start (); - - } - #end } diff --git a/lime/audio/AudioBuffer.hx b/lime/audio/AudioBuffer.hx index 5d23926b8..b6af8f56d 100644 --- a/lime/audio/AudioBuffer.hx +++ b/lime/audio/AudioBuffer.hx @@ -48,20 +48,20 @@ class AudioBuffer { public static function fromBytes (bytes:ByteArray):AudioBuffer { #if (cpp || neko || nodejs) - - var data = lime_audio_load (bytes); - - if (data != null) { - var audioBuffer = new AudioBuffer (); - audioBuffer.bitsPerSample = data.bitsPerSample; - audioBuffer.channels = data.channels; - audioBuffer.data = data.data; - audioBuffer.sampleRate = data.sampleRate; - return audioBuffer; + var data = lime_audio_load (bytes); + + if (data != null) { + + var audioBuffer = new AudioBuffer (); + audioBuffer.bitsPerSample = data.bitsPerSample; + audioBuffer.channels = data.channels; + audioBuffer.data = data.data; + audioBuffer.sampleRate = data.sampleRate; + return audioBuffer; + + } - } - #end return null; @@ -72,20 +72,20 @@ class AudioBuffer { public static function fromFile (path:String):AudioBuffer { #if (cpp || neko || nodejs) - - var data = lime_audio_load (path); - - if (data != null) { - var audioBuffer = new AudioBuffer (); - audioBuffer.bitsPerSample = data.bitsPerSample; - audioBuffer.channels = data.channels; - audioBuffer.data = data.data; - audioBuffer.sampleRate = data.sampleRate; - return audioBuffer; + var data = lime_audio_load (path); + + if (data != null) { + + var audioBuffer = new AudioBuffer (); + audioBuffer.bitsPerSample = data.bitsPerSample; + audioBuffer.channels = data.channels; + audioBuffer.data = data.data; + audioBuffer.sampleRate = data.sampleRate; + return audioBuffer; + + } - } - #end return null; diff --git a/lime/audio/AudioManager.hx b/lime/audio/AudioManager.hx index aab70271e..c9049dbef 100644 --- a/lime/audio/AudioManager.hx +++ b/lime/audio/AudioManager.hx @@ -22,26 +22,31 @@ class AudioManager { if (context == null) { #if (js && html5) - try { - untyped __js__ ("window.AudioContext = window.AudioContext || window.webkitAudioContext;"); - AudioManager.context = WEB (cast untyped __js__ ("new AudioContext ()")); + try { + + untyped __js__ ("window.AudioContext = window.AudioContext || window.webkitAudioContext;"); + AudioManager.context = WEB (cast untyped __js__ ("new AudioContext ()")); + + } catch (e:Dynamic) { + + AudioManager.context = HTML5 (new HTML5AudioContext ()); + + } - } catch (e:Dynamic) { - - AudioManager.context = HTML5 (new HTML5AudioContext ()); - - } #elseif flash - AudioManager.context = FLASH (new FlashAudioContext ()); + + AudioManager.context = FLASH (new FlashAudioContext ()); + #else - AudioManager.context = OPENAL (new ALCAudioContext (), new ALAudioContext ()); - - var device = ALC.openDevice (); - var ctx = ALC.createContext (device); - ALC.makeContextCurrent (ctx); - ALC.processContext (ctx); - + + AudioManager.context = OPENAL (new ALCAudioContext (), new ALAudioContext ()); + + var device = ALC.openDevice (); + var ctx = ALC.createContext (device); + ALC.makeContextCurrent (ctx); + ALC.processContext (ctx); + #end } else { diff --git a/lime/audio/AudioSource.hx b/lime/audio/AudioSource.hx index 1b78836b4..9b6ed636a 100644 --- a/lime/audio/AudioSource.hx +++ b/lime/audio/AudioSource.hx @@ -97,10 +97,14 @@ class AudioSource { #if html5 #elseif flash - if (channel != null) channel.stop (); - var channel = buffer.src.play (pauseTime / 1000); + + if (channel != null) channel.stop (); + var channel = buffer.src.play (pauseTime / 1000); + #else - AL.sourcePlay (id); + + AL.sourcePlay (id); + #end } @@ -110,14 +114,18 @@ class AudioSource { #if html5 #elseif flash - if (channel != null) { - pauseTime = Std.int (channel.position * 1000); - channel.stop (); + if (channel != null) { + + pauseTime = Std.int (channel.position * 1000); + channel.stop (); + + } - } #else - AL.sourcePause (id); + + AL.sourcePause (id); + #end } @@ -127,10 +135,14 @@ class AudioSource { #if html5 #elseif flash - pauseTime = 0; - if (channel != null) channel.stop (); + + pauseTime = 0; + if (channel != null) channel.stop (); + #else - AL.sourceStop (id); + + AL.sourceStop (id); + #end } diff --git a/lime/graphics/Image.hx b/lime/graphics/Image.hx index 7dedbd685..74baee406 100644 --- a/lime/graphics/Image.hx +++ b/lime/graphics/Image.hx @@ -295,40 +295,40 @@ class Image { #if java #elseif (sys && (!disable_cffi || !format)) - - return lime_image_encode (buffer, 0, quality); - + + return lime_image_encode (buffer, 0, quality); + #elseif !js - - try { - var bytes = Bytes.alloc (width * height * 4 + height); - var sourceBytes = buffer.data.getByteBuffer (); - var sourceIndex:Int, index:Int; - - for (y in 0...height) { + try { - sourceIndex = y * width * 4; - index = y * width * 4 + y; + var bytes = Bytes.alloc (width * height * 4 + height); + var sourceBytes = buffer.data.getByteBuffer (); + var sourceIndex:Int, index:Int; - bytes.set (index, 0); - bytes.blit (index + 1, sourceBytes, sourceIndex, width * 4); + for (y in 0...height) { + + sourceIndex = y * width * 4; + index = y * width * 4 + y; + + bytes.set (index, 0); + bytes.blit (index + 1, sourceBytes, sourceIndex, width * 4); + + } - } + var data = new List (); + data.add (CHeader ({ width: width, height: height, colbits: 8, color: ColTrue (true), interlaced: false })); + data.add (CData (Deflate.run (bytes))); + data.add (CEnd); + + var output = new BytesOutput (); + var png = new Writer (output); + png.write (data); + + return ByteArray.fromBytes (output.getBytes ()); + + } catch (e:Dynamic) {} - var data = new List (); - data.add (CHeader ({ width: width, height: height, colbits: 8, color: ColTrue (true), interlaced: false })); - data.add (CData (Deflate.run (bytes))); - data.add (CEnd); - - var output = new BytesOutput (); - var png = new Writer (output); - png.write (data); - - return ByteArray.fromBytes (output.getBytes ()); - - } catch (e:Dynamic) {} - #end case "jpg", "jpeg": @@ -336,9 +336,9 @@ class Image { #if java #elseif (sys && (!disable_cffi || !format)) - - return lime_image_encode (buffer, 1, quality); - + + return lime_image_encode (buffer, 1, quality); + #end default: @@ -689,23 +689,27 @@ class Image { private static function __base64Encode (bytes:ByteArray):String { #if (js && html5) - var extension = switch (bytes.length % 3) { - case 1: "=="; - case 2: "="; - default: ""; + var extension = switch (bytes.length % 3) { + + case 1: "=="; + case 2: "="; + default: ""; + + } - } - - if (__base64Encoder == null) { + if (__base64Encoder == null) { + + __base64Encoder = new BaseCode (Bytes.ofString (__base64Chars)); + + } - __base64Encoder = new BaseCode (Bytes.ofString (__base64Chars)); + return __base64Encoder.encodeBytes (Bytes.ofData (cast bytes.byteView)).toString () + extension; - } - - return __base64Encoder.encodeBytes (Bytes.ofData (cast bytes.byteView)).toString () + extension; #else - return ""; + + return ""; + #end } @@ -787,49 +791,49 @@ class Image { private function __fromBytes (bytes:ByteArray, onload:Image -> Void):Void { #if (js && html5) - - var type = ""; - - if (__isPNG (bytes)) { - type = "image/png"; + var type = ""; - } else if (__isJPG (bytes)) { - - type = "image/jpeg"; - - } else if (__isGIF (bytes)) { - - type = "image/gif"; - - } else { - - throw "Image tried to read a PNG/JPG ByteArray, but found an invalid header."; - - } - - __fromBase64 (__base64Encode (bytes), type, onload); - - #elseif (cpp || neko || nodejs) - - var data = lime_image_load (bytes); - - if (data != null) { - - __fromImageBuffer (new ImageBuffer (new UInt8Array (data.data), data.width, data.height, data.bpp)); - - if (onload != null) { + if (__isPNG (bytes)) { - onload (this); + type = "image/png"; + + } else if (__isJPG (bytes)) { + + type = "image/jpeg"; + + } else if (__isGIF (bytes)) { + + type = "image/gif"; + + } else { + + throw "Image tried to read a PNG/JPG ByteArray, but found an invalid header."; + + } + + __fromBase64 (__base64Encode (bytes), type, onload); + + #elseif (cpp || neko || nodejs) + + var data = lime_image_load (bytes); + + if (data != null) { + + __fromImageBuffer (new ImageBuffer (new UInt8Array (data.data), data.width, data.height, data.bpp)); + + if (onload != null) { + + onload (this); + + } } - } - #else - - throw "ImageBuffer.loadFromBytes not supported on this target"; - + + throw "ImageBuffer.loadFromBytes not supported on this target"; + #end } @@ -838,108 +842,108 @@ class Image { private function __fromFile (path:String, onload:Image -> Void, onerror:Void -> Void):Void { #if (js && html5) - - var image = new JSImage (); - - image.onload = function (_) { - buffer = new ImageBuffer (null, image.width, image.height); - buffer.__srcImage = cast image; + var image = new JSImage (); + + image.onload = function (_) { + + buffer = new ImageBuffer (null, image.width, image.height); + buffer.__srcImage = cast image; - width = image.width; - height = image.height; - - if (onload != null) { + width = image.width; + height = image.height; - onload (this); + if (onload != null) { + + onload (this); + + } } - } - - image.onerror = function (_) { - - if (onerror != null) { + image.onerror = function (_) { - onerror (); + if (onerror != null) { + + onerror (); + + } } - } - - image.src = path; - - // Another IE9 bug: loading 20+ images fails unless this line is added. - // (issue #1019768) - if (image.complete) { } - + image.src = path; + + // Another IE9 bug: loading 20+ images fails unless this line is added. + // (issue #1019768) + if (image.complete) { } + #elseif (cpp || neko || nodejs || java) - - var buffer = null; - - #if (sys && (!disable_cffi || !format) && !java) - - var data = lime_image_load (path); - if (data != null) { - var ba:ByteArray = cast(data.data, ByteArray); - #if nodejs - var u8a = ba.byteView; - #else - var u8a = new UInt8Array(ba); + + var buffer = null; + + #if (sys && (!disable_cffi || !format) && !java) + + var data = lime_image_load (path); + if (data != null) { + var ba:ByteArray = cast(data.data, ByteArray); + #if nodejs + var u8a = ba.byteView; + #else + var u8a = new UInt8Array(ba); + #end + buffer = new ImageBuffer (u8a, data.width, data.height, data.bpp); + } + + #elseif format + + try { + + var bytes = File.getBytes (path); + var input = new BytesInput (bytes, 0, bytes.length); + var png = new Reader (input).read (); + var data = Tools.extract32 (png); + var header = Tools.getHeader (png); + + var data = new UInt8Array (ByteArray.fromBytes (Bytes.ofData (data.getData ()))); + var length = header.width * header.height; + var b, g, r, a; + + for (i in 0...length) { + + var b = data[i * 4]; + var g = data[i * 4 + 1]; + var r = data[i * 4 + 2]; + var a = data[i * 4 + 3]; + + data[i * 4] = r; + data[i * 4 + 1] = g; + data[i * 4 + 2] = b; + data[i * 4 + 3] = a; + + } + + buffer = new ImageBuffer (data, header.width, header.height); + + } catch (e:Dynamic) {} + #end - buffer = new ImageBuffer (u8a, data.width, data.height, data.bpp); - } - - #elseif format - - try { - var bytes = File.getBytes (path); - var input = new BytesInput (bytes, 0, bytes.length); - var png = new Reader (input).read (); - var data = Tools.extract32 (png); - var header = Tools.getHeader (png); - - var data = new UInt8Array (ByteArray.fromBytes (Bytes.ofData (data.getData ()))); - var length = header.width * header.height; - var b, g, r, a; - - for (i in 0...length) { + if (buffer != null) { - var b = data[i * 4]; - var g = data[i * 4 + 1]; - var r = data[i * 4 + 2]; - var a = data[i * 4 + 3]; + __fromImageBuffer (buffer); - data[i * 4] = r; - data[i * 4 + 1] = g; - data[i * 4 + 2] = b; - data[i * 4 + 3] = a; + if (onload != null) { + + onload (this); + + } } - buffer = new ImageBuffer (data, header.width, header.height); - - } catch (e:Dynamic) {} - - #end - - if (buffer != null) { - - __fromImageBuffer (buffer); - - if (onload != null) { - - onload (this); - - } - - } - #else - - throw "ImageBuffer.loadFromFile not supported on this target"; - + + throw "ImageBuffer.loadFromFile not supported on this target"; + #end } @@ -1011,11 +1015,15 @@ class Image { if (buffer.data == null && buffer.width > 0 && buffer.height > 0) { #if (js && html5) - ImageCanvasUtil.convertToCanvas (this); - ImageCanvasUtil.createImageData (this); + + ImageCanvasUtil.convertToCanvas (this); + ImageCanvasUtil.createImageData (this); + #elseif flash - var pixels = buffer.__srcBitmapData.getPixels (buffer.__srcBitmapData.rect); - buffer.data = new UInt8Array (pixels); + + var pixels = buffer.__srcBitmapData.getPixels (buffer.__srcBitmapData.rect); + buffer.data = new UInt8Array (pixels); + #end } diff --git a/lime/graphics/ImageBuffer.hx b/lime/graphics/ImageBuffer.hx index 01dc198b4..8787f1ed7 100644 --- a/lime/graphics/ImageBuffer.hx +++ b/lime/graphics/ImageBuffer.hx @@ -66,12 +66,18 @@ class ImageBuffer { private function get_src ():Dynamic { #if (js && html5) - if (__srcImage != null) return __srcImage; - return __srcCanvas; + + if (__srcImage != null) return __srcImage; + return __srcCanvas; + #elseif flash - return __srcBitmapData; + + return __srcBitmapData; + #else - return __srcCustom; + + return __srcCustom; + #end } @@ -80,20 +86,26 @@ class ImageBuffer { private function set_src (value:Dynamic):Dynamic { #if (js && html5) - if (Std.is (value, HTMLImage)) { - __srcImage = cast value; + if (Std.is (value, HTMLImage)) { + + __srcImage = cast value; + + } else if (Std.is (value, CanvasElement)) { + + __srcCanvas = cast value; + __srcContext = cast __srcCanvas.getContext ("2d"); + + } - } else if (Std.is (value, CanvasElement)) { - - __srcCanvas = cast value; - __srcContext = cast __srcCanvas.getContext ("2d"); - - } #elseif flash - __srcBitmapData = cast value; + + __srcBitmapData = cast value; + #else - __srcCustom = value; + + __srcCustom = value; + #end return value; diff --git a/lime/graphics/Renderer.hx b/lime/graphics/Renderer.hx index 8573358e0..c12d92b36 100644 --- a/lime/graphics/Renderer.hx +++ b/lime/graphics/Renderer.hx @@ -50,31 +50,31 @@ class Renderer { public function create ():Void { #if (cpp || neko || nodejs) - - handle = lime_renderer_create (window.handle); - + + handle = lime_renderer_create (window.handle); + #elseif java - - GLFW.glfwMakeContextCurrent (window.handle); - GLContext.createFromCurrent (); - + + GLFW.glfwMakeContextCurrent (window.handle); + GLContext.createFromCurrent (); + #end createContext (); #if (js && html5) - - switch (context) { - case OPENGL (_): + switch (context) { - window.canvas.addEventListener ("webglcontextlost", handleCanvasEvent, false); - window.canvas.addEventListener ("webglcontextrestored", handleCanvasEvent, false); + case OPENGL (_): + + window.canvas.addEventListener ("webglcontextlost", handleCanvasEvent, false); + window.canvas.addEventListener ("webglcontextrestored", handleCanvasEvent, false); + + default: + + } - default: - - } - #end if (!registered) { @@ -93,61 +93,61 @@ class Renderer { private function createContext ():Void { #if (js && html5) - - if (window.div != null) { - context = DOM (window.div); - - } else if (window.canvas != null) { - - #if canvas - - var webgl = null; - - #else - - var options = { - alpha: true, - antialias: window.config.antialiasing > 0, - depth: window.config.depthBuffer, - premultipliedAlpha: true, - stencil: window.config.stencilBuffer, - preserveDrawingBuffer: false - }; - - var webgl:RenderingContext = cast window.canvas.getContextWebGL(options); - - #end - - if (webgl == null) { + if (window.div != null) { - context = CANVAS (cast window.canvas.getContext ("2d")); + context = DOM (window.div); - } else { + } else if (window.canvas != null) { - #if debug - webgl = untyped WebGLDebugUtils.makeDebugContext (webgl); - #end + #if canvas + + var webgl = null; - GL.context = webgl; - #if (js && html5) - context = OPENGL (cast GL.context); #else - context = OPENGL (new GLRenderContext ()); + + var options = { + alpha: true, + antialias: window.config.antialiasing > 0, + depth: window.config.depthBuffer, + premultipliedAlpha: true, + stencil: window.config.stencilBuffer, + preserveDrawingBuffer: false + }; + + var webgl:RenderingContext = cast window.canvas.getContextWebGL(options); + #end + if (webgl == null) { + + context = CANVAS (cast window.canvas.getContext ("2d")); + + } else { + + #if debug + webgl = untyped WebGLDebugUtils.makeDebugContext (webgl); + #end + + GL.context = webgl; + #if (js && html5) + context = OPENGL (cast GL.context); + #else + context = OPENGL (new GLRenderContext ()); + #end + + } + } - } - #elseif (cpp || neko || nodejs || java) - - context = OPENGL (new GLRenderContext ()); - + + context = OPENGL (new GLRenderContext ()); + #elseif flash - - context = FLASH (Lib.current); - + + context = FLASH (Lib.current); + #end } @@ -244,6 +244,13 @@ class Renderer { } + + + // Native Methods + + + + #if (cpp || neko || nodejs) private static var lime_render_event_manager_register = System.load ("lime", "lime_render_event_manager_register", 2); private static var lime_renderer_create = System.load ("lime", "lime_renderer_create", 1); diff --git a/lime/system/System.hx b/lime/system/System.hx index 9c085b10f..786f27466 100644 --- a/lime/system/System.hx +++ b/lime/system/System.hx @@ -88,41 +88,41 @@ class System { static private function findHaxeLib (library:String):String { #if (sys && !html5) - - try { - var proc = new Process ("haxelib", [ "path", library ]); - - if (proc != null) { + try { - var stream = proc.stdout; + var proc = new Process ("haxelib", [ "path", library ]); - try { + if (proc != null) { - while (true) { + var stream = proc.stdout; + + try { - var s = stream.readLine (); - - if (s.substr (0, 1) != "-") { + while (true) { - stream.close (); - proc.close (); - loaderTrace ("Found haxelib " + s); - return s; + var s = stream.readLine (); + + if (s.substr (0, 1) != "-") { + + stream.close (); + proc.close (); + loaderTrace ("Found haxelib " + s); + return s; + + } } - } + } catch(e:Dynamic) { } - } catch(e:Dynamic) { } + stream.close (); + proc.close (); + + } - stream.close (); - proc.close (); - - } + } catch (e:Dynamic) { } - } catch (e:Dynamic) { } - #end return ""; @@ -252,14 +252,22 @@ class System { private static function sysName ():String { #if (sys && !html5) - #if cpp - var sys_string = cpp.Lib.load ("std", "sys_string", 0); - return sys_string (); + + #if cpp + + var sys_string = cpp.Lib.load ("std", "sys_string", 0); + return sys_string (); + + #else + + return Sys.systemName (); + + #end + #else - return Sys.systemName (); - #end - #else - return null; + + return null; + #end } @@ -307,10 +315,14 @@ class System { #if (sys && !html5) #if cpp - var get_env = cpp.Lib.load ("std", "get_env", 1); - var debug = (get_env ("OPENFL_LOAD_DEBUG") != null); + + var get_env = cpp.Lib.load ("std", "get_env", 1); + var debug = (get_env ("OPENFL_LOAD_DEBUG") != null); + #else - var debug = (Sys.getEnv ("OPENFL_LOAD_DEBUG") !=null); + + var debug = (Sys.getEnv ("OPENFL_LOAD_DEBUG") !=null); + #end if (debug) { diff --git a/lime/ui/KeyEventManager.hx b/lime/ui/KeyEventManager.hx index 0d58f5603..9db02bac7 100644 --- a/lime/ui/KeyEventManager.hx +++ b/lime/ui/KeyEventManager.hx @@ -29,19 +29,19 @@ class KeyEventManager { eventInfo = new KeyEventInfo (); #if (js && html5) - - Browser.window.addEventListener ("keydown", handleEvent, false); - Browser.window.addEventListener ("keyup", handleEvent, false); - + + Browser.window.addEventListener ("keydown", handleEvent, false); + Browser.window.addEventListener ("keyup", handleEvent, false); + #elseif flash - - Lib.current.stage.addEventListener (flash.events.KeyboardEvent.KEY_DOWN, handleEvent); - Lib.current.stage.addEventListener (flash.events.KeyboardEvent.KEY_UP, handleEvent); - + + Lib.current.stage.addEventListener (flash.events.KeyboardEvent.KEY_DOWN, handleEvent); + Lib.current.stage.addEventListener (flash.events.KeyboardEvent.KEY_UP, handleEvent); + #elseif (cpp || neko || nodejs) - - lime_key_event_manager_register (handleEvent, eventInfo); - + + lime_key_event_manager_register (handleEvent, eventInfo); + #end } @@ -50,98 +50,102 @@ class KeyEventManager { private static function convertKeyCode (keyCode:Int):KeyCode { #if (js && html5) - if (keyCode >= 65 && keyCode <= 90) { - return cast keyCode + 32; + if (keyCode >= 65 && keyCode <= 90) { + + return cast keyCode + 32; + + } - } - - switch (keyCode) { + switch (keyCode) { + + case 16: return KeyCode.LEFT_SHIFT; + case 17: return KeyCode.LEFT_CTRL; + case 18: return KeyCode.LEFT_ALT; + case 20: return KeyCode.CAPS_LOCK; + case 144: return KeyCode.NUM_LOCK; + case 37: return KeyCode.LEFT; + case 38: return KeyCode.UP; + case 39: return KeyCode.RIGHT; + case 40: return KeyCode.DOWN; + case 45: return KeyCode.INSERT; + case 46: return KeyCode.DELETE; + case 36: return KeyCode.HOME; + case 35: return KeyCode.END; + case 33: return KeyCode.PAGE_UP; + case 34: return KeyCode.PAGE_DOWN; + case 112: return KeyCode.F1; + case 113: return KeyCode.F2; + case 114: return KeyCode.F3; + case 115: return KeyCode.F4; + case 116: return KeyCode.F5; + case 117: return KeyCode.F6; + case 118: return KeyCode.F7; + case 119: return KeyCode.F8; + case 120: return KeyCode.F9; + case 121: return KeyCode.F10; + case 122: return KeyCode.F11; + case 123: return KeyCode.F12; + + } - case 16: return KeyCode.LEFT_SHIFT; - case 17: return KeyCode.LEFT_CTRL; - case 18: return KeyCode.LEFT_ALT; - case 20: return KeyCode.CAPS_LOCK; - case 144: return KeyCode.NUM_LOCK; - case 37: return KeyCode.LEFT; - case 38: return KeyCode.UP; - case 39: return KeyCode.RIGHT; - case 40: return KeyCode.DOWN; - case 45: return KeyCode.INSERT; - case 46: return KeyCode.DELETE; - case 36: return KeyCode.HOME; - case 35: return KeyCode.END; - case 33: return KeyCode.PAGE_UP; - case 34: return KeyCode.PAGE_DOWN; - case 112: return KeyCode.F1; - case 113: return KeyCode.F2; - case 114: return KeyCode.F3; - case 115: return KeyCode.F4; - case 116: return KeyCode.F5; - case 117: return KeyCode.F6; - case 118: return KeyCode.F7; - case 119: return KeyCode.F8; - case 120: return KeyCode.F9; - case 121: return KeyCode.F10; - case 122: return KeyCode.F11; - case 123: return KeyCode.F12; - - } #elseif flash - if (keyCode >= 65 && keyCode <= 90) { - return cast keyCode + 32; + if (keyCode >= 65 && keyCode <= 90) { + + return cast keyCode + 32; + + } - } - - switch (keyCode) { + switch (keyCode) { + + case 16: return KeyCode.LEFT_SHIFT; + case 17: return KeyCode.LEFT_CTRL; + case 18: return KeyCode.LEFT_ALT; + case 20: return KeyCode.CAPS_LOCK; + case 33: return KeyCode.PAGE_UP; + case 34: return KeyCode.PAGE_DOWN; + case 35: return KeyCode.END; + case 36: return KeyCode.HOME; + case 37: return KeyCode.LEFT; + case 38: return KeyCode.UP; + case 39: return KeyCode.RIGHT; + case 40: return KeyCode.DOWN; + case 45: return KeyCode.INSERT; + case 46: return KeyCode.DELETE; + case 96: return KeyCode.NUMPAD_0; + case 97: return KeyCode.NUMPAD_1; + case 98: return KeyCode.NUMPAD_2; + case 99: return KeyCode.NUMPAD_3; + case 100: return KeyCode.NUMPAD_4; + case 101: return KeyCode.NUMPAD_5; + case 102: return KeyCode.NUMPAD_6; + case 103: return KeyCode.NUMPAD_7; + case 104: return KeyCode.NUMPAD_8; + case 105: return KeyCode.NUMPAD_9; + case 106: return KeyCode.NUMPAD_MULTIPLY; + case 107: return KeyCode.NUMPAD_PLUS; + case 109: return KeyCode.NUMPAD_MINUS; + case 110: return KeyCode.NUMPAD_PERIOD; + case 111: return KeyCode.NUMPAD_DIVIDE; + case 112: return KeyCode.F1; + case 113: return KeyCode.F2; + case 114: return KeyCode.F3; + case 115: return KeyCode.F4; + case 116: return KeyCode.F5; + case 117: return KeyCode.F6; + case 118: return KeyCode.F7; + case 119: return KeyCode.F8; + case 120: return KeyCode.F9; + case 121: return KeyCode.F10; + case 122: return KeyCode.F11; + case 123: return KeyCode.F12; + case 144: return KeyCode.NUM_LOCK; + case 219: return KeyCode.LEFT_BRACKET; + case 221: return KeyCode.RIGHT_BRACKET; + + } - case 16: return KeyCode.LEFT_SHIFT; - case 17: return KeyCode.LEFT_CTRL; - case 18: return KeyCode.LEFT_ALT; - case 20: return KeyCode.CAPS_LOCK; - case 33: return KeyCode.PAGE_UP; - case 34: return KeyCode.PAGE_DOWN; - case 35: return KeyCode.END; - case 36: return KeyCode.HOME; - case 37: return KeyCode.LEFT; - case 38: return KeyCode.UP; - case 39: return KeyCode.RIGHT; - case 40: return KeyCode.DOWN; - case 45: return KeyCode.INSERT; - case 46: return KeyCode.DELETE; - case 96: return KeyCode.NUMPAD_0; - case 97: return KeyCode.NUMPAD_1; - case 98: return KeyCode.NUMPAD_2; - case 99: return KeyCode.NUMPAD_3; - case 100: return KeyCode.NUMPAD_4; - case 101: return KeyCode.NUMPAD_5; - case 102: return KeyCode.NUMPAD_6; - case 103: return KeyCode.NUMPAD_7; - case 104: return KeyCode.NUMPAD_8; - case 105: return KeyCode.NUMPAD_9; - case 106: return KeyCode.NUMPAD_MULTIPLY; - case 107: return KeyCode.NUMPAD_PLUS; - case 109: return KeyCode.NUMPAD_MINUS; - case 110: return KeyCode.NUMPAD_PERIOD; - case 111: return KeyCode.NUMPAD_DIVIDE; - case 112: return KeyCode.F1; - case 113: return KeyCode.F2; - case 114: return KeyCode.F3; - case 115: return KeyCode.F4; - case 116: return KeyCode.F5; - case 117: return KeyCode.F6; - case 118: return KeyCode.F7; - case 119: return KeyCode.F8; - case 120: return KeyCode.F9; - case 121: return KeyCode.F10; - case 122: return KeyCode.F11; - case 123: return KeyCode.F12; - case 144: return KeyCode.NUM_LOCK; - case 219: return KeyCode.LEFT_BRACKET; - case 221: return KeyCode.RIGHT_BRACKET; - - } #end return cast keyCode; @@ -152,45 +156,45 @@ class KeyEventManager { private static function handleEvent (#if (js && html5) event:js.html.KeyboardEvent #elseif flash event:flash.events.KeyboardEvent #elseif java _window, key, scancode, action, mods #end):Void { #if (js && html5) - - // space and arrow keys - switch (event.keyCode) { - case 32, 37, 38, 39, 40: event.preventDefault (); + // space and arrow keys + switch (event.keyCode) { + + case 32, 37, 38, 39, 40: event.preventDefault (); + + } + + //keyEvent.code = event.code; + eventInfo.keyCode = cast convertKeyCode (event.keyCode != null ? event.keyCode : event.which); + //keyEvent.key = keyEvent.code; + //keyEvent.code = Keyboard.__convertMozillaCode (keyEvent.code); + + //keyEvent.location = untyped (event).location != null ? untyped (event).location : event.keyLocation; + + //keyEvent.ctrlKey = event.ctrlKey; + //keyEvent.altKey = event.altKey; + //keyEvent.shiftKey = event.shiftKey; + //keyEvent.metaKey = event.metaKey; + + eventInfo.type = (event.type == "keydown" ? KEY_DOWN : KEY_UP); - } - - //keyEvent.code = event.code; - eventInfo.keyCode = cast convertKeyCode (event.keyCode != null ? event.keyCode : event.which); - //keyEvent.key = keyEvent.code; - //keyEvent.code = Keyboard.__convertMozillaCode (keyEvent.code); - - //keyEvent.location = untyped (event).location != null ? untyped (event).location : event.keyLocation; - - //keyEvent.ctrlKey = event.ctrlKey; - //keyEvent.altKey = event.altKey; - //keyEvent.shiftKey = event.shiftKey; - //keyEvent.metaKey = event.metaKey; - - eventInfo.type = (event.type == "keydown" ? KEY_DOWN : KEY_UP); - #elseif flash - - eventInfo.keyCode = cast convertKeyCode (event.keyCode); - //keyEvent.key = event.charCode; - - //keyEvent.ctrlKey = event.ctrlKey; - //keyEvent.altKey = event.altKey; - //keyEvent.shiftKey = event.shiftKey; - //keyEvent.metaKey = event.commandKey; - - eventInfo.type = (event.type == flash.events.KeyboardEvent.KEY_DOWN ? KEY_DOWN : KEY_UP); - + + eventInfo.keyCode = cast convertKeyCode (event.keyCode); + //keyEvent.key = event.charCode; + + //keyEvent.ctrlKey = event.ctrlKey; + //keyEvent.altKey = event.altKey; + //keyEvent.shiftKey = event.shiftKey; + //keyEvent.metaKey = event.commandKey; + + eventInfo.type = (event.type == flash.events.KeyboardEvent.KEY_DOWN ? KEY_DOWN : KEY_UP); + #elseif java - - eventInfo.keyCode = cast convertKeyCode (key); - eventInfo.type == (action == GLFW.GLFW_RELEASE ? KEY_UP : KEY_DOWN); - + + eventInfo.keyCode = cast convertKeyCode (key); + eventInfo.type == (action == GLFW.GLFW_RELEASE ? KEY_UP : KEY_DOWN); + #end switch (eventInfo.type) { @@ -211,20 +215,27 @@ class KeyEventManager { private static function registerWindow (_window:Window):Void { #if java - - /*GLFW.glfwSetKeyCallback (_window.handle, keyfun = new GLFW.GLFWkeyfun() { - @Override - public void invoke(long window, int key, int scancode, int action, int mods) { - if ( key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE ) - glfwSetWindowShouldClose(window, GL_TRUE); // We will detect this in our rendering loop - } - }));*/ - + + /*GLFW.glfwSetKeyCallback (_window.handle, keyfun = new GLFW.GLFWkeyfun() { + @Override + public void invoke(long window, int key, int scancode, int action, int mods) { + if ( key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE ) + glfwSetWindowShouldClose(window, GL_TRUE); // We will detect this in our rendering loop + } + }));*/ + #end } + + + // Native Methods + + + + #if (cpp || neko || nodejs) private static var lime_key_event_manager_register = System.load ("lime", "lime_key_event_manager_register", 2); #end diff --git a/lime/ui/Mouse.hx b/lime/ui/Mouse.hx index ba4c7a59e..b58c68e7f 100644 --- a/lime/ui/Mouse.hx +++ b/lime/ui/Mouse.hx @@ -29,21 +29,21 @@ class Mouse { __hidden = true; #if (js && html5) - - for (window in Application.__instance.windows) { - window.element.style.cursor = "none"; + for (window in Application.__instance.windows) { + + window.element.style.cursor = "none"; + + } - } - #elseif (cpp || neko || nodejs) - - lime_mouse_hide (); - + + lime_mouse_hide (); + #elseif flash - - FlashMouse.hide (); - + + FlashMouse.hide (); + #end } @@ -58,19 +58,19 @@ class Mouse { __hidden = false; #if (js && html5) - - var cacheValue = __cursor; - __cursor = null; - cursor = cacheValue; - + + var cacheValue = __cursor; + __cursor = null; + cursor = cacheValue; + #elseif (cpp || neko || nodejs) - - lime_mouse_show (); - + + lime_mouse_show (); + #elseif flash - - FlashMouse.show (); - + + FlashMouse.show (); + #end } @@ -100,68 +100,68 @@ class Mouse { if (!__hidden) { #if (js && html5) - - for (window in Application.__instance.windows) { - window.element.style.cursor = switch (value) { + for (window in Application.__instance.windows) { - case ARROW: "default"; - case CROSSHAIR: "crosshair"; - case MOVE: "move"; - case POINTER: "pointer"; - case RESIZE_NESW: "nesw-resize"; - case RESIZE_NS: "ns-resize"; - case RESIZE_NWSE: "nwse-resize"; - case RESIZE_WE: "ew-resize"; - case TEXT: "text"; - case WAIT: "wait"; - case WAIT_ARROW: "wait"; - default: "auto"; + window.element.style.cursor = switch (value) { + + case ARROW: "default"; + case CROSSHAIR: "crosshair"; + case MOVE: "move"; + case POINTER: "pointer"; + case RESIZE_NESW: "nesw-resize"; + case RESIZE_NS: "ns-resize"; + case RESIZE_NWSE: "nwse-resize"; + case RESIZE_WE: "ew-resize"; + case TEXT: "text"; + case WAIT: "wait"; + case WAIT_ARROW: "wait"; + default: "auto"; + + } } - } - #elseif (cpp || neko || nodejs) - - var type:MouseCursorType = switch (value) { - case ARROW: ARROW; - case CROSSHAIR: CROSSHAIR; - case MOVE: MOVE; - case POINTER: POINTER; - case RESIZE_NESW: RESIZE_NESW; - case RESIZE_NS: RESIZE_NS; - case RESIZE_NWSE: RESIZE_NWSE; - case RESIZE_WE: RESIZE_WE; - case TEXT: TEXT; - case WAIT: WAIT; - case WAIT_ARROW: WAIT_ARROW; - default: DEFAULT; + var type:MouseCursorType = switch (value) { + + case ARROW: ARROW; + case CROSSHAIR: CROSSHAIR; + case MOVE: MOVE; + case POINTER: POINTER; + case RESIZE_NESW: RESIZE_NESW; + case RESIZE_NS: RESIZE_NS; + case RESIZE_NWSE: RESIZE_NWSE; + case RESIZE_WE: RESIZE_WE; + case TEXT: TEXT; + case WAIT: WAIT; + case WAIT_ARROW: WAIT_ARROW; + default: DEFAULT; + + } + + lime_mouse_set_cursor (type); - } - - lime_mouse_set_cursor (type); - #elseif flash - - FlashMouse.cursor = switch (value) { - case ARROW: FlashMouseCursor.ARROW; - case CROSSHAIR: FlashMouseCursor.ARROW; - case MOVE: FlashMouseCursor.HAND; - case POINTER: FlashMouseCursor.BUTTON; - case RESIZE_NESW: FlashMouseCursor.HAND; - case RESIZE_NS: FlashMouseCursor.HAND; - case RESIZE_NWSE: FlashMouseCursor.HAND; - case RESIZE_WE: FlashMouseCursor.HAND; - case TEXT: FlashMouseCursor.IBEAM; - case WAIT: FlashMouseCursor.ARROW; - case WAIT_ARROW: FlashMouseCursor.ARROW; - default: FlashMouseCursor.AUTO; + FlashMouse.cursor = switch (value) { + + case ARROW: FlashMouseCursor.ARROW; + case CROSSHAIR: FlashMouseCursor.ARROW; + case MOVE: FlashMouseCursor.HAND; + case POINTER: FlashMouseCursor.BUTTON; + case RESIZE_NESW: FlashMouseCursor.HAND; + case RESIZE_NS: FlashMouseCursor.HAND; + case RESIZE_NWSE: FlashMouseCursor.HAND; + case RESIZE_WE: FlashMouseCursor.HAND; + case TEXT: FlashMouseCursor.IBEAM; + case WAIT: FlashMouseCursor.ARROW; + case WAIT_ARROW: FlashMouseCursor.ARROW; + default: FlashMouseCursor.AUTO; + + } - } - #end } @@ -175,6 +175,13 @@ class Mouse { } + + + // Native Methods + + + + #if (cpp || neko || nodejs) private static var lime_mouse_hide = System.load ("lime", "lime_mouse_hide", 0); private static var lime_mouse_set_cursor = System.load ("lime", "lime_mouse_set_cursor", 1); diff --git a/lime/ui/MouseEventManager.hx b/lime/ui/MouseEventManager.hx index 81ddad7a3..6188e63b3 100644 --- a/lime/ui/MouseEventManager.hx +++ b/lime/ui/MouseEventManager.hx @@ -34,7 +34,9 @@ class MouseEventManager { eventInfo = new MouseEventInfo (); #if (cpp || neko || nodejs) - lime_mouse_event_manager_register (handleEvent, eventInfo); + + lime_mouse_event_manager_register (handleEvent, eventInfo); + #end } @@ -43,92 +45,92 @@ class MouseEventManager { private static function handleEvent (#if (js && html5) event:js.html.MouseEvent #elseif flash event:flash.events.MouseEvent #end):Void { #if (js && html5) - - eventInfo.type = switch (event.type) { - case "mousedown": MOUSE_DOWN; - case "mouseup": MOUSE_UP; - case "mousemove": MOUSE_MOVE; - //case "click": MouseEvent.CLICK; - //case "dblclick": MouseEvent.DOUBLE_CLICK; - case "wheel": MOUSE_WHEEL; - default: null; - - } - - if (eventInfo.type != MOUSE_WHEEL) { - - if (window != null && window.element != null) { + eventInfo.type = switch (event.type) { - if (window.canvas != null) { + case "mousedown": MOUSE_DOWN; + case "mouseup": MOUSE_UP; + case "mousemove": MOUSE_MOVE; + //case "click": MouseEvent.CLICK; + //case "dblclick": MouseEvent.DOUBLE_CLICK; + case "wheel": MOUSE_WHEEL; + default: null; + + } + + if (eventInfo.type != MOUSE_WHEEL) { + + if (window != null && window.element != null) { - var rect = window.canvas.getBoundingClientRect (); - eventInfo.x = (event.clientX - rect.left) * (window.width / rect.width); - eventInfo.y = (event.clientY - rect.top) * (window.height / rect.height); - - } else if (window.div != null) { - - var rect = window.div.getBoundingClientRect (); - //eventInfo.x = (event.clientX - rect.left) * (window.div.style.width / rect.width); - eventInfo.x = (event.clientX - rect.left); - //eventInfo.y = (event.clientY - rect.top) * (window.div.style.height / rect.height); - eventInfo.y = (event.clientY - rect.top); + if (window.canvas != null) { + + var rect = window.canvas.getBoundingClientRect (); + eventInfo.x = (event.clientX - rect.left) * (window.width / rect.width); + eventInfo.y = (event.clientY - rect.top) * (window.height / rect.height); + + } else if (window.div != null) { + + var rect = window.div.getBoundingClientRect (); + //eventInfo.x = (event.clientX - rect.left) * (window.div.style.width / rect.width); + eventInfo.x = (event.clientX - rect.left); + //eventInfo.y = (event.clientY - rect.top) * (window.div.style.height / rect.height); + eventInfo.y = (event.clientY - rect.top); + + } else { + + var rect = window.element.getBoundingClientRect (); + eventInfo.x = (event.clientX - rect.left) * (window.width / rect.width); + eventInfo.y = (event.clientY - rect.top) * (window.height / rect.height); + + } } else { - var rect = window.element.getBoundingClientRect (); - eventInfo.x = (event.clientX - rect.left) * (window.width / rect.width); - eventInfo.y = (event.clientY - rect.top) * (window.height / rect.height); + eventInfo.x = event.clientX; + eventInfo.y = event.clientY; } } else { - eventInfo.x = event.clientX; - eventInfo.y = event.clientY; + eventInfo.x = untyped event.deltaX; + eventInfo.y = untyped event.deltaY; } - } else { + eventInfo.button = event.button; - eventInfo.x = untyped event.deltaX; - eventInfo.y = untyped event.deltaY; - - } - - eventInfo.button = event.button; - #elseif flash - - eventInfo.type = switch (event.type) { - case "mouseDown", "middleMouseDown", "rightMouseDown": MOUSE_DOWN; - case "mouseMove", "middleMouseMove", "rightMouseMove": MOUSE_MOVE; - case "mouseUp", "middleMouseUp", "rightMouseUp": MOUSE_UP; - default: MOUSE_WHEEL; + eventInfo.type = switch (event.type) { + + case "mouseDown", "middleMouseDown", "rightMouseDown": MOUSE_DOWN; + case "mouseMove", "middleMouseMove", "rightMouseMove": MOUSE_MOVE; + case "mouseUp", "middleMouseUp", "rightMouseUp": MOUSE_UP; + default: MOUSE_WHEEL; + + } - } - - if (eventInfo.type != MOUSE_WHEEL) { + if (eventInfo.type != MOUSE_WHEEL) { + + eventInfo.x = event.stageX; + eventInfo.y = event.stageY; + + } else { + + eventInfo.x = 0; + eventInfo.y = event.delta; + + } - eventInfo.x = event.stageX; - eventInfo.y = event.stageY; + eventInfo.button = switch (event.type) { + + case "middleMouseDown", "middleMouseMove", "middleMouseUp": 1; + case "rightMouseDown", "rightMouseMove", "rightMouseUp": 2; + default: 0; + + } - } else { - - eventInfo.x = 0; - eventInfo.y = event.delta; - - } - - eventInfo.button = switch (event.type) { - - case "middleMouseDown", "middleMouseMove", "middleMouseUp": 1; - case "rightMouseDown", "rightMouseMove", "rightMouseUp": 2; - default: 0; - - } - #end switch (eventInfo.type) { @@ -159,41 +161,48 @@ class MouseEventManager { private static function registerWindow (_window:Window):Void { #if (js && html5) - - var events = [ "mousedown", "mousemove", "mouseup", "wheel" ]; - - for (event in events) { - _window.element.addEventListener (event, handleEvent, true); + var events = [ "mousedown", "mousemove", "mouseup", "wheel" ]; - } - - MouseEventManager.window = _window; - - // Disable image drag on Firefox - Browser.document.addEventListener ("dragstart", function (e) { - if (e.target.nodeName.toLowerCase () == "img") { - e.preventDefault (); - return false; + for (event in events) { + + _window.element.addEventListener (event, handleEvent, true); + } - return true; - }, false); - + + MouseEventManager.window = _window; + + // Disable image drag on Firefox + Browser.document.addEventListener ("dragstart", function (e) { + if (e.target.nodeName.toLowerCase () == "img") { + e.preventDefault (); + return false; + } + return true; + }, false); + #elseif flash - - var events = [ "mouseDown", "mouseMove", "mouseUp", "mouseWheel", "middleMouseDown", "middleMouseMove", "middleMouseUp" #if ((!openfl && !disable_flash_right_click) || enable_flash_right_click) , "rightMouseDown", "rightMouseMove", "rightMouseUp" #end ]; - - for (event in events) { - Lib.current.stage.addEventListener (event, handleEvent); + var events = [ "mouseDown", "mouseMove", "mouseUp", "mouseWheel", "middleMouseDown", "middleMouseMove", "middleMouseUp" #if ((!openfl && !disable_flash_right_click) || enable_flash_right_click) , "rightMouseDown", "rightMouseMove", "rightMouseUp" #end ]; + + for (event in events) { + + Lib.current.stage.addEventListener (event, handleEvent); + + } - } - #end } + + + // Native Methods + + + + #if (cpp || neko || nodejs) private static var lime_mouse_event_manager_register = System.load ("lime", "lime_mouse_event_manager_register", 2); #end diff --git a/lime/ui/TouchEventManager.hx b/lime/ui/TouchEventManager.hx index 70638b99b..17acb24b8 100644 --- a/lime/ui/TouchEventManager.hx +++ b/lime/ui/TouchEventManager.hx @@ -30,7 +30,9 @@ import flash.Lib; eventInfo = new TouchEventInfo (); #if (cpp || neko || nodejs) - lime_touch_event_manager_register (handleEvent, eventInfo); + + lime_touch_event_manager_register (handleEvent, eventInfo); + #end } @@ -39,75 +41,75 @@ import flash.Lib; private static function handleEvent (#if (js && html5) event:js.html.TouchEvent #elseif flash event:flash.events.TouchEvent #end):Void { #if (js && html5) - - event.preventDefault (); - - //var rect = __canvas.getBoundingClientRect (); - - //touchEvent.id = event.changedTouches[0].identifier; - //eventInfo.x = event.pageX; - //eventInfo.y = event.pageY; - - eventInfo.type = switch (event.type) { - case "touchstart": TOUCH_START; - case "touchmove": TOUCH_MOVE; - case "touchend": TOUCH_END; - default: null; + event.preventDefault (); - } - - var touch = event.changedTouches[0]; - - eventInfo.id = touch.identifier; - - if (window != null && window.element != null) { + //var rect = __canvas.getBoundingClientRect (); - if (window.canvas != null) { + //touchEvent.id = event.changedTouches[0].identifier; + //eventInfo.x = event.pageX; + //eventInfo.y = event.pageY; + + eventInfo.type = switch (event.type) { - var rect = window.canvas.getBoundingClientRect (); - eventInfo.x = (touch.clientX - rect.left) * (window.width / rect.width); - eventInfo.y = (touch.clientY - rect.top) * (window.height / rect.height); - - } else if (window.div != null) { - - var rect = window.div.getBoundingClientRect (); - //eventInfo.x = (event.clientX - rect.left) * (window.div.style.width / rect.width); - eventInfo.x = (touch.clientX - rect.left); - //eventInfo.y = (event.clientY - rect.top) * (window.div.style.height / rect.height); - eventInfo.y = (touch.clientY - rect.top); - - } else { - - var rect = window.element.getBoundingClientRect (); - eventInfo.x = (touch.clientX - rect.left) * (window.width / rect.width); - eventInfo.y = (touch.clientY - rect.top) * (window.height / rect.height); + case "touchstart": TOUCH_START; + case "touchmove": TOUCH_MOVE; + case "touchend": TOUCH_END; + default: null; } + var touch = event.changedTouches[0]; + + eventInfo.id = touch.identifier; + + if (window != null && window.element != null) { + + if (window.canvas != null) { + + var rect = window.canvas.getBoundingClientRect (); + eventInfo.x = (touch.clientX - rect.left) * (window.width / rect.width); + eventInfo.y = (touch.clientY - rect.top) * (window.height / rect.height); + + } else if (window.div != null) { + + var rect = window.div.getBoundingClientRect (); + //eventInfo.x = (event.clientX - rect.left) * (window.div.style.width / rect.width); + eventInfo.x = (touch.clientX - rect.left); + //eventInfo.y = (event.clientY - rect.top) * (window.div.style.height / rect.height); + eventInfo.y = (touch.clientY - rect.top); + + } else { + + var rect = window.element.getBoundingClientRect (); + eventInfo.x = (touch.clientX - rect.left) * (window.width / rect.width); + eventInfo.y = (touch.clientY - rect.top) * (window.height / rect.height); + + } + + + } else { + + eventInfo.x = touch.clientX; + eventInfo.y = touch.clientY; + + } - } else { - - eventInfo.x = touch.clientX; - eventInfo.y = touch.clientY; - - } - #elseif flash - - //touchEvent.id = event.touchPointID; - eventInfo.x = event.stageX; - eventInfo.y = event.stageY; - - eventInfo.type = switch (event.type) { - case flash.events.TouchEvent.TOUCH_BEGIN: TOUCH_START; - case flash.events.TouchEvent.TOUCH_MOVE: TOUCH_MOVE; - default: TOUCH_END; + //touchEvent.id = event.touchPointID; + eventInfo.x = event.stageX; + eventInfo.y = event.stageY; + + eventInfo.type = switch (event.type) { + + case flash.events.TouchEvent.TOUCH_BEGIN: TOUCH_START; + case flash.events.TouchEvent.TOUCH_MOVE: TOUCH_MOVE; + default: TOUCH_END; + + } - } - #end switch (eventInfo.type) { @@ -132,25 +134,32 @@ import flash.Lib; private static function registerWindow (window:Window):Void { #if (js && html5) - - window.element.addEventListener ("touchstart", handleEvent, true); - window.element.addEventListener ("touchmove", handleEvent, true); - window.element.addEventListener ("touchend", handleEvent, true); - - TouchEventManager.window = window; - + + window.element.addEventListener ("touchstart", handleEvent, true); + window.element.addEventListener ("touchmove", handleEvent, true); + window.element.addEventListener ("touchend", handleEvent, true); + + TouchEventManager.window = window; + #elseif flash - - Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT; - Lib.current.stage.addEventListener (flash.events.TouchEvent.TOUCH_BEGIN, handleEvent); - Lib.current.stage.addEventListener (flash.events.TouchEvent.TOUCH_MOVE, handleEvent); - Lib.current.stage.addEventListener (flash.events.TouchEvent.TOUCH_END, handleEvent); - + + Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT; + Lib.current.stage.addEventListener (flash.events.TouchEvent.TOUCH_BEGIN, handleEvent); + Lib.current.stage.addEventListener (flash.events.TouchEvent.TOUCH_MOVE, handleEvent); + Lib.current.stage.addEventListener (flash.events.TouchEvent.TOUCH_END, handleEvent); + #end } + + + // Native Methods + + + + #if (cpp || neko || nodejs) private static var lime_touch_event_manager_register = System.load ("lime", "lime_touch_event_manager_register", 2); #end diff --git a/lime/ui/Window.hx b/lime/ui/Window.hx index f7ae73e8d..ac9e0d863 100644 --- a/lime/ui/Window.hx +++ b/lime/ui/Window.hx @@ -72,7 +72,9 @@ class Window { registered = true; #if (cpp || neko || nodejs) - lime_window_event_manager_register (dispatch, eventInfo); + + lime_window_event_manager_register (dispatch, eventInfo); + #end } @@ -86,137 +88,139 @@ class Window { setHeight = height; #if (js && html5) - - if (Std.is (element, CanvasElement)) { - canvas = cast element; - - } else { - - #if dom - div = cast Browser.document.createElement ("div"); - #else - canvas = cast Browser.document.createElement ("canvas"); - #end - - } - - if (canvas != null) { - - var style = canvas.style; - style.setProperty ("-webkit-transform", "translateZ(0)", null); - style.setProperty ("transform", "translateZ(0)", null); - - } else if (div != null) { - - var style = div.style; - style.setProperty ("-webkit-transform", "translate3D(0,0,0)", null); - style.setProperty ("transform", "translate3D(0,0,0)", null); - //style.setProperty ("-webkit-transform-style", "preserve-3d", null); - //style.setProperty ("transform-style", "preserve-3d", null); - style.position = "relative"; - style.overflow = "hidden"; - style.setProperty ("-webkit-user-select", "none", null); - style.setProperty ("-moz-user-select", "none", null); - style.setProperty ("-ms-user-select", "none", null); - style.setProperty ("-o-user-select", "none", null); - - } - - if (width == 0 && height == 0) { - - if (element != null) { + if (Std.is (element, CanvasElement)) { - width = element.clientWidth; - height = element.clientHeight; + canvas = cast element; } else { - width = Browser.window.innerWidth; - height = Browser.window.innerHeight; + #if dom + div = cast Browser.document.createElement ("div"); + #else + canvas = cast Browser.document.createElement ("canvas"); + #end } - fullscreen = true; - - } - - if (canvas != null) { - - canvas.width = width; - canvas.height = height; - - } else { - - div.style.width = width + "px"; - div.style.height = height + "px"; - - } - - handleDOMResize (); - - if (element != null) { - if (canvas != null) { - if (element != cast canvas) { - - element.appendChild (canvas); - - } + var style = canvas.style; + style.setProperty ("-webkit-transform", "translateZ(0)", null); + style.setProperty ("transform", "translateZ(0)", null); - } else { + } else if (div != null) { - element.appendChild (div); + var style = div.style; + style.setProperty ("-webkit-transform", "translate3D(0,0,0)", null); + style.setProperty ("transform", "translate3D(0,0,0)", null); + //style.setProperty ("-webkit-transform-style", "preserve-3d", null); + //style.setProperty ("transform-style", "preserve-3d", null); + style.position = "relative"; + style.overflow = "hidden"; + style.setProperty ("-webkit-user-select", "none", null); + style.setProperty ("-moz-user-select", "none", null); + style.setProperty ("-ms-user-select", "none", null); + style.setProperty ("-o-user-select", "none", null); } - } - - #if stats - stats = untyped __js__("new Stats ()"); - stats.domElement.style.position = "absolute"; - stats.domElement.style.top = "0px"; - Browser.document.body.appendChild (stats.domElement); - #end - + if (width == 0 && height == 0) { + + if (element != null) { + + width = element.clientWidth; + height = element.clientHeight; + + } else { + + width = Browser.window.innerWidth; + height = Browser.window.innerHeight; + + } + + fullscreen = true; + + } + + if (canvas != null) { + + canvas.width = width; + canvas.height = height; + + } else { + + div.style.width = width + "px"; + div.style.height = height + "px"; + + } + + handleDOMResize (); + + if (element != null) { + + if (canvas != null) { + + if (element != cast canvas) { + + element.appendChild (canvas); + + } + + } else { + + element.appendChild (div); + + } + + } + + #if stats + + stats = untyped __js__("new Stats ()"); + stats.domElement.style.position = "absolute"; + stats.domElement.style.top = "0px"; + Browser.document.body.appendChild (stats.domElement); + + #end + #elseif (cpp || neko || nodejs) - - var flags = 0; - - if (config.antialiasing >= 4) { - flags |= cast WindowFlags.WINDOW_FLAG_HW_AA_HIRES; + var flags = 0; - } else if (config.antialiasing >= 2) { + if (config.antialiasing >= 4) { + + flags |= cast WindowFlags.WINDOW_FLAG_HW_AA_HIRES; + + } else if (config.antialiasing >= 2) { + + flags |= cast WindowFlags.WINDOW_FLAG_HW_AA; + + } - flags |= cast WindowFlags.WINDOW_FLAG_HW_AA; + if (config.borderless) flags |= cast WindowFlags.WINDOW_FLAG_BORDERLESS; + if (config.depthBuffer) flags |= cast WindowFlags.WINDOW_FLAG_DEPTH_BUFFER; + if (config.fullscreen) flags |= cast WindowFlags.WINDOW_FLAG_FULLSCREEN; + if (config.resizable) flags |= cast WindowFlags.WINDOW_FLAG_RESIZABLE; + if (config.stencilBuffer) flags |= cast WindowFlags.WINDOW_FLAG_STENCIL_BUFFER; + if (config.vsync) flags |= cast WindowFlags.WINDOW_FLAG_VSYNC; + + handle = lime_window_create (application.__handle, width, height, flags, config.title); - } - - if (config.borderless) flags |= cast WindowFlags.WINDOW_FLAG_BORDERLESS; - if (config.depthBuffer) flags |= cast WindowFlags.WINDOW_FLAG_DEPTH_BUFFER; - if (config.fullscreen) flags |= cast WindowFlags.WINDOW_FLAG_FULLSCREEN; - if (config.resizable) flags |= cast WindowFlags.WINDOW_FLAG_RESIZABLE; - if (config.stencilBuffer) flags |= cast WindowFlags.WINDOW_FLAG_STENCIL_BUFFER; - if (config.vsync) flags |= cast WindowFlags.WINDOW_FLAG_VSYNC; - - handle = lime_window_create (application.__handle, width, height, flags, config.title); - #elseif java - - GLFW.glfwWindowHint (GLFW.GLFW_SAMPLES, config.antialiasing); - - if (config.borderless) GLFW.glfwWindowHint (GLFW.GLFW_DECORATED, GL11.GL_TRUE); - if (!config.depthBuffer) GLFW.glfwWindowHint (GLFW.GLFW_DEPTH_BITS, 0); - //if (config.fullscreen) GLFW.glfwWindowHint (GLFW.GLFW_DECORATED, GL11.GL_TRUE); - if (!config.resizable) GLFW.glfwWindowHint (GLFW.GLFW_RESIZABLE, GL11.GL_FALSE); - if (!config.stencilBuffer) GLFW.glfwWindowHint (GLFW.GLFW_STENCIL_BITS, 0); - - handle = GLFW.glfwCreateWindow (width, height, config.title, null, null); - - if (config.vsync) GLFW.glfwSwapInterval (1); - + + GLFW.glfwWindowHint (GLFW.GLFW_SAMPLES, config.antialiasing); + + if (config.borderless) GLFW.glfwWindowHint (GLFW.GLFW_DECORATED, GL11.GL_TRUE); + if (!config.depthBuffer) GLFW.glfwWindowHint (GLFW.GLFW_DEPTH_BITS, 0); + //if (config.fullscreen) GLFW.glfwWindowHint (GLFW.GLFW_DECORATED, GL11.GL_TRUE); + if (!config.resizable) GLFW.glfwWindowHint (GLFW.GLFW_RESIZABLE, GL11.GL_FALSE); + if (!config.stencilBuffer) GLFW.glfwWindowHint (GLFW.GLFW_STENCIL_BITS, 0); + + handle = GLFW.glfwCreateWindow (width, height, config.title, null, null); + + if (config.vsync) GLFW.glfwSwapInterval (1); + #end KeyEventManager.registerWindow (this); @@ -224,16 +228,20 @@ class Window { TouchEventManager.registerWindow (this); #if (js && html5) - Browser.window.addEventListener ("focus", handleDOMEvent, false); - Browser.window.addEventListener ("blur", handleDOMEvent, false); - Browser.window.addEventListener ("resize", handleDOMEvent, false); - Browser.window.addEventListener ("beforeunload", handleDOMEvent, false); + + Browser.window.addEventListener ("focus", handleDOMEvent, false); + Browser.window.addEventListener ("blur", handleDOMEvent, false); + Browser.window.addEventListener ("resize", handleDOMEvent, false); + Browser.window.addEventListener ("beforeunload", handleDOMEvent, false); + #elseif flash - Lib.current.stage.addEventListener (flash.events.Event.ACTIVATE, handleFlashEvent); - Lib.current.stage.addEventListener (flash.events.Event.DEACTIVATE, handleFlashEvent); - Lib.current.stage.addEventListener (flash.events.FocusEvent.FOCUS_IN, handleFlashEvent); - Lib.current.stage.addEventListener (flash.events.FocusEvent.FOCUS_OUT, handleFlashEvent); - Lib.current.stage.addEventListener (flash.events.Event.RESIZE, handleFlashEvent); + + Lib.current.stage.addEventListener (flash.events.Event.ACTIVATE, handleFlashEvent); + Lib.current.stage.addEventListener (flash.events.Event.DEACTIVATE, handleFlashEvent); + Lib.current.stage.addEventListener (flash.events.FocusEvent.FOCUS_IN, handleFlashEvent); + Lib.current.stage.addEventListener (flash.events.FocusEvent.FOCUS_OUT, handleFlashEvent); + Lib.current.stage.addEventListener (flash.events.Event.RESIZE, handleFlashEvent); + #end if (currentRenderer != null) { @@ -431,7 +439,9 @@ class Window { public function move (x:Int, y:Int):Void { #if (cpp || neko || nodejs) - lime_window_move (handle, x, y); + + lime_window_move (handle, x, y); + #end } @@ -443,7 +453,9 @@ class Window { setHeight = height; #if (cpp || neko || nodejs) - lime_window_resize (handle, width, height); + + lime_window_resize (handle, width, height); + #end } @@ -458,7 +470,9 @@ class Window { } #if (cpp || neko || nodejs) - lime_window_set_icon (handle, image.buffer); + + lime_window_set_icon (handle, image.buffer); + #end } From 0d0c52eff79b3bba9aaf473249176e9396dad4b3 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Tue, 30 Dec 2014 11:01:13 -0800 Subject: [PATCH 16/28] Use proper fontName for embedded OpenFL/HTML5 fonts (closes #280) --- templates/haxe/DefaultAssetLibrary.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/haxe/DefaultAssetLibrary.hx b/templates/haxe/DefaultAssetLibrary.hx index ed0d574ec..7998f4c6c 100644 --- a/templates/haxe/DefaultAssetLibrary.hx +++ b/templates/haxe/DefaultAssetLibrary.hx @@ -652,7 +652,7 @@ class DefaultAssetLibrary extends AssetLibrary { #elseif html5 #if openfl -::foreach assets::::if (type == "font")::@:keep #if display private #end class __ASSET__::flatName:: extends openfl.text.Font { public function new () { super (); fontName = "::id::"; } } ::end:: +::foreach assets::::if (type == "font")::@:keep #if display private #end class __ASSET__::flatName:: extends openfl.text.Font { public function new () { super (); fontName = "::fontName::"; } } ::end:: ::end:: #end From 86f7bb88415c22f56e27a9f62aa96f6bb8ab6b45 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Tue, 30 Dec 2014 11:47:41 -0800 Subject: [PATCH 17/28] Ignore dummy HXCPP config ANT_HOME and JAVA_HOME values --- tools/CommandLineTools.hx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tools/CommandLineTools.hx b/tools/CommandLineTools.hx index 61c6954b8..a35f19d33 100644 --- a/tools/CommandLineTools.hx +++ b/tools/CommandLineTools.hx @@ -1145,7 +1145,21 @@ class CommandLineTools { if (define == define.toUpperCase ()) { - Sys.putEnv (define, config.defines.get (define)); + switch (define) { + + case "ANT_HOME", "JAVA_HOME": + + if (FileSystem.exists (config.defines.get (define))) { + + Sys.putEnv (define, config.defines.get (define)); + + } + + default: + + Sys.putEnv (define, config.defines.get (define)); + + } } From 17dce6cb57529f522f886b463961830f842e91ab Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Tue, 30 Dec 2014 12:04:22 -0800 Subject: [PATCH 18/28] Use runCommand instead of runProcess for the node web server --- tools/helpers/HTML5Helper.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/helpers/HTML5Helper.hx b/tools/helpers/HTML5Helper.hx index 91a241af7..9e60442fc 100644 --- a/tools/helpers/HTML5Helper.hx +++ b/tools/helpers/HTML5Helper.hx @@ -139,7 +139,7 @@ class HTML5Helper { } - ProcessHelper.runProcess ("", node, args); + ProcessHelper.runCommand ("", node, args); } From 954ab3a32cff6a13c30e8cc9a117a1c4b17629c9 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Tue, 30 Dec 2014 12:40:03 -0800 Subject: [PATCH 19/28] Improve use of Node http-server --- templates/bin/node/http-server/http-server | 38 ++++++++++++++++----- templates/bin/node/http-server/package.json | 2 +- tools/helpers/HTML5Helper.hx | 6 ++-- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/templates/bin/node/http-server/http-server b/templates/bin/node/http-server/http-server index f6b2cab81..2c073630c 100755 --- a/templates/bin/node/http-server/http-server +++ b/templates/bin/node/http-server/http-server @@ -2,9 +2,11 @@ var colors = require('colors'), httpServer = require('./http-server.js'), - argv = require('optimist').argv, portfinder = require('portfinder'), - opener = require('opener'); + opener = require('opener'), + argv = require('optimist') + .boolean('cors') + .argv; if (argv.h || argv.help) { console.log([ @@ -19,8 +21,13 @@ if (argv.h || argv.help) { " -s --silent Suppress log messages from output", " --cors Enable CORS via the 'Access-Control-Allow-Origin' header", " -o Open browser window after staring the server", - " -c Set cache time (in seconds). e.g. -c10 for 10 seconds.", + " -c Cache time (max-age) in seconds [3600], e.g. -c10 for 10 seconds.", " To disable caching, use -c-1.", + "", + " -S --ssl Enable https.", + " -C --cert Path to ssl cert file (default: cert.pem).", + " -K --key Path to ssl key file (default: key.pem).", + "", " -h --help Print this list and exit." ].join('\n')); process.exit(); @@ -29,6 +36,7 @@ if (argv.h || argv.help) { var port = argv.p || parseInt(process.env.PORT, 10), host = argv.a || '0.0.0.0', log = (argv.s || argv.silent) ? (function () {}) : console.log, + ssl = !!argv.S || !!argv.ssl, requestLogger; if (!argv.s && !argv.silent) { @@ -58,19 +66,31 @@ function listen(port) { }; if (argv.cors) { - options.headers = { 'Access-Control-Allow-Origin': '*' }; + options.headers = { + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept' + }; + } + + if (ssl) { + options.https = { + cert: argv.C || argv.cert || 'cert.pem', + key: argv.K || argv.key || 'key.pem' + }; } var server = httpServer.createServer(options); server.listen(port, host, function() { + var uri = [ssl ? 'https' : 'http', '://', host, ':', port].join(''); log('Starting up http-server, serving '.yellow + server.root.cyan - + ' on port: '.yellow - + port.toString().cyan); - log('Hit CTRL-C to stop the server'); + + ((ssl) ? ' through'.yellow + ' https'.cyan : '') + + ' on: '.yellow + + uri.cyan); + log('Hit CTRL-C to stop the server'); if (argv.o) { - opener('http://127.0.0.1:' + port.toString()); + opener(uri); } }); } @@ -83,4 +103,4 @@ if (process.platform !== 'win32') { log('http-server stopped.'.red); process.exit(); }); -} +} \ No newline at end of file diff --git a/templates/bin/node/http-server/package.json b/templates/bin/node/http-server/package.json index 8ad9ea3f9..61f42f4fd 100755 --- a/templates/bin/node/http-server/package.json +++ b/templates/bin/node/http-server/package.json @@ -1,6 +1,6 @@ { "name": "http-server", - "version": "0.6.1", + "version": "0.7.4", "author": "Nodejitsu ", "description": "a simple zero-configuration command-line http server", "main": "./lib/http-server", diff --git a/tools/helpers/HTML5Helper.hx b/tools/helpers/HTML5Helper.hx index 9e60442fc..68def0b11 100644 --- a/tools/helpers/HTML5Helper.hx +++ b/tools/helpers/HTML5Helper.hx @@ -124,14 +124,14 @@ class HTML5Helper { LogHelper.info ("", " - \x1b[1mStarting local web server:\x1b[0m http://localhost:" + port); - Thread.create (function () { + /*Thread.create (function () { Sys.sleep (0.5); ProcessHelper.openURL ("http://localhost:" + port); - }); + });*/ - var args = [ server, path, "-p", Std.string (port), "-c-1" ]; + var args = [ server, path, "-p", Std.string (port), "-c-1", "-o", "-a", "localhost", "--cors" ]; if (!LogHelper.verbose) { From 8151f10c35664796708d0d2ad25cbd11ba3772fe Mon Sep 17 00:00:00 2001 From: cbatson Date: Wed, 31 Dec 2014 09:19:32 -0800 Subject: [PATCH 20/28] Borrow fixed orientation handling from NME so that on iOS orientation can be configured before the stage is created. See also https://github.com/haxenme/nme/commit/b7698f25d30d45d13c780f33567973772cca01f6. Stage.shouldRotateInterface() cannot be used to indicate initial orientation preference on iOS, because it is not called unless the stage has been instantiated, and UIStageViewController.supportedInterfaceOrientations() is called before the stage is created. --- legacy/project/src/iPhone/UIStageView.mm | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/legacy/project/src/iPhone/UIStageView.mm b/legacy/project/src/iPhone/UIStageView.mm index a37105722..ae5023b65 100644 --- a/legacy/project/src/iPhone/UIStageView.mm +++ b/legacy/project/src/iPhone/UIStageView.mm @@ -3052,7 +3052,29 @@ public: - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if (gFixedOrientation >= 0) - return interfaceOrientation == gFixedOrientation; + { + enum { + OrientationPortrait = 1, + OrientationPortraitUpsideDown = 2, + OrientationLandscapeRight = 3, + OrientationLandscapeLeft = 4, + OrientationFaceUp = 5, + OrientationFaceDown = 6, + OrientationPortraitAny = 7, + OrientationLandscapeAny = 8, + OrientationAny = 9, + }; + + if (interfaceOrientation == gFixedOrientation) + return true; + if (gFixedOrientation==OrientationAny) + return true; + if (gFixedOrientation==OrientationPortraitAny) + return interfaceOrientation==OrientationPortrait || interfaceOrientation==OrientationPortraitUpsideDown; + if (gFixedOrientation==OrientationLandscapeAny) + return interfaceOrientation==OrientationLandscapeLeft || interfaceOrientation==OrientationLandscapeRight; + return false; + } Event evt(etShouldRotate); evt.value = interfaceOrientation; sgMainView->mStage->OnEvent(evt); From 974d5b774440ef2df15b18574617898b32608d3b Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Wed, 31 Dec 2014 13:56:52 -0800 Subject: [PATCH 21/28] Fix getPixels --- lime/graphics/utils/ImageDataUtil.hx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lime/graphics/utils/ImageDataUtil.hx b/lime/graphics/utils/ImageDataUtil.hx index 5f0c407b5..092c27348 100644 --- a/lime/graphics/utils/ImageDataUtil.hx +++ b/lime/graphics/utils/ImageDataUtil.hx @@ -409,17 +409,23 @@ class ImageDataUtil { var srcRowOffset = srcStride - Std.int (4 * rect.width); var srcRowEnd = Std.int (4 * (rect.x + rect.width)); - var length = Std.int (4 * rect.width * rect.height); + var length = Std.int (rect.width * rect.height); #if js - byteArray.length = length; + byteArray.length = length * 4; #end for (i in 0...length) { #if flash byteArray.writeUnsignedInt (srcData[srcPosition++]); + byteArray.writeUnsignedInt (srcData[srcPosition++]); + byteArray.writeUnsignedInt (srcData[srcPosition++]); + byteArray.writeUnsignedInt (srcData[srcPosition++]); #else - byteArray.__set (i, srcData[srcPosition++]); + byteArray.__set (i * 4 + 1, srcData[srcPosition++]); + byteArray.__set (i * 4 + 2, srcData[srcPosition++]); + byteArray.__set (i * 4 + 3, srcData[srcPosition++]); + byteArray.__set (i * 4, srcData[srcPosition++]); #end if ((srcPosition % srcStride) > srcRowEnd) { From 4cec0df3156296e8465d04ce8296beb97c8f2d63 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Wed, 31 Dec 2014 13:57:00 -0800 Subject: [PATCH 22/28] Minor cleanup --- lime/ui/TouchEventManager.hx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lime/ui/TouchEventManager.hx b/lime/ui/TouchEventManager.hx index 17acb24b8..f4df69756 100644 --- a/lime/ui/TouchEventManager.hx +++ b/lime/ui/TouchEventManager.hx @@ -10,8 +10,10 @@ import flash.ui.MultitouchInputMode; import flash.Lib; #end +@:allow(lime.ui.Window) -@:allow(lime.ui.Window) class TouchEventManager { + +class TouchEventManager { public static var onTouchEnd = new EventFloat->Int->Void> (); From e53da6cd01ae5b863deb617e8bdf1d2925361344 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Wed, 31 Dec 2014 17:11:52 -0800 Subject: [PATCH 23/28] Update CHANGELOG --- CHANGELOG.md | 115 +++++++++++++++++++++++++++++---------------------- 1 file changed, 65 insertions(+), 50 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e443755b4..e848acf99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ -2.0.3 -===== +2.0.4 (12/31/2014) +------------------ + +* Added system mouse cursor support in lime.ui.Mouse +* Added hide/show cursor support in lime.ui.Mouse +* Improved the behavior of the embedded web server +* Fixed the behavior of Image.getPixels +* Fixed embedded font support for OpenFL HTML5 +* Fixed handling of dummy ANT_HOME or JAVA_HOME HXCPP values +* Improved default context menu behavior on Flash/OpenFL +* Improved fixed orientation support on iOS (legacy) + + +2.0.3 (12/27/2014) +------------------ * Improved linking of OpenAL for Android * Added support for cached `` processing @@ -7,8 +20,8 @@ * Fixed minor issues with "lime rebuild tools" -2.0.2 -===== +2.0.2 (12/21/2014) +------------------ * Added ARMV7S, ARM64 and X86_64 support for iOS * Added unofficial Java support @@ -29,8 +42,8 @@ * Fixed TextField leading (legacy) -2.0.1 -===== +2.0.1 (12/04/2014) +------------------ * Added GL.isContextLost * Added Renderer onRenderContextLost/onRenderContextRestored @@ -39,8 +52,8 @@ * Fixed HTML5 touch event coordinates -2.0.0 -===== +2.0.0 (11/20/2014) +------------------ * Improved the "lime rebuild" command * Added a "-dryrun" flag to help test the tools @@ -53,8 +66,8 @@ * Fixed GraphicsPath on Neko (legacy) -2.0.0-beta -========== +2.0.0-beta (11/13/2014) +----------------------- * Merged the Lime "legacy" codebase * Initial steps towards Lime node.js support @@ -66,16 +79,16 @@ * Other minor fixes -2.0.0-alpha.8 -============= +2.0.0-alpha.8 (11/08/2014) +-------------------------- * Guarded certain CFFI calls * Fixed discovery of Java install on OS X * Omitting Android force downgrade on old devices -2.0.0-alpha.7 -============= +2.0.0-alpha.7 (11/01/2014) +-------------------------- * Improved handling of haxelib library versions * Add patched haxe.CallStack to fix C++ stack order @@ -85,8 +98,8 @@ * Added the force downgrade argument when installing on Android -2.0.0-alpha.6 -============= +2.0.0-alpha.6 (10/28/2014) +-------------------------- * Added initial support for cubic bezier font outlines * Added better OpenFL ASCII color on Mac @@ -95,8 +108,8 @@ * Fixed loading of type BINARY files as TEXT -2.0.0-alpha.5 -============= +2.0.0-alpha.5 (10/23/2014) +-------------------------- * Added patched Haxe Boot class, to fix Std.is on Safari * Added support for the "openfl" command @@ -105,16 +118,16 @@ * Minor fixes -2.0.0-alpha.4 -============= +2.0.0-alpha.4 (10/21/2014) +-------------------------- * Improved parsing of HXML when compiling for the Flash target * Improved the `` data system * Enabled splash screen generation for iOS again -2.0.0-alpha.3 -============= +2.0.0-alpha.3 (10/20/2014) +-------------------------- * Fixed handling of HXML with comments when targeting Flash * Added initial support for ".bundle" asset folders @@ -127,8 +140,8 @@ * Added Tilesheet TILE_RECT support (legacy) -2.0.0-alpha.2 -============= +2.0.0-alpha.2 (10/16/2014) +-------------------------- * Added Lime "legacy" binaries for OpenFL v2 native support * Merged the Aether tools into Lime @@ -153,8 +166,9 @@ * Fixed null data in URLLoader on Neko (legacy) * Added a dead zone filter for joystick events (legacy) -2.0.0-alpha -=========== + +2.0.0-alpha (10/14/2014) +------------------------ * Created an all-new Lime API * The core architecture is built around Application, Window and Renderer @@ -174,19 +188,19 @@ * Many other tool improvements -1.0.1 -===== +1.0.1 (06/24/2014) +------------------ * Fixed BlackBerry support * Fixed a memory leak when using LZMA decoding -1.0.0 -===== +1.0.0 (05/29/2014) +----------------- -0.9.9 -===== +0.9.9 (05/28/2014) +----------------- * Fixed ACTIVATE/DEACTIVATE for Windows on minimize/restore * Fixed Mac fullscreen handling @@ -194,8 +208,8 @@ * Added "-nocolor" option -0.9.8 -===== +0.9.8 (05/27/2014) +------------------ * Fixed issues with Android JNI * Fixed a GPU texture issue on iOS @@ -207,8 +221,8 @@ * Other minor fixes -0.9.7 -===== +0.9.7 (04/22/2014) +------------------ * Merged Lime with NME for code collaboration * Fixed software rendering path @@ -224,8 +238,8 @@ * Fixed color order for PNG encoding -0.9.6 -===== +0.9.6 (03/18/2014) +------------------ * Fixed Android library instantiation order * Fixed Android onKeyUp event @@ -236,8 +250,9 @@ * Improved support for looping audio * Minor fixes -0.9.5 -===== + +0.9.5 (03/04/2014) +------------------ * Improvements to Lime wrapper * Fixed cURL to support larger header sizes @@ -262,15 +277,15 @@ * Updated for automated builds: http://openfl.org/builds/lime -0.9.4 -===== +0.9.4 (01/27/2014) +------------------ * Fixed support for 8-bit PNG images with alpha * Fixed software fallback for certain older cards -0.9.3 -===== +0.9.3 (01/22/2014) +------------------ * Improved the Android extension API * Improved OpenAL audio panning behavior @@ -278,23 +293,23 @@ * Fixed GL drawArrays issue on desktop -0.9.2 -===== +0.9.2 (12/31/2013) +------------------ * Fixed Tizen storage directory * Fixed support for Emscripten -0.9.1 -===== +0.9.1 (12/18/2013) +------------------ * Lime wrapper improvements * Improved performance when loading OGG samples in memory * Added support for the Tizen emulator -0.9.0 -===== +0.9.0 (12/10/2013) +------------------ * Added Tizen support * Initial wrapper implementation From ed9ed7d4d210388075754f8027ec7e4dec340d54 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Wed, 31 Dec 2014 17:12:04 -0800 Subject: [PATCH 24/28] Update to 2.0.4 --- haxelib.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/haxelib.json b/haxelib.json index dfe95b0e4..fc1ee5b0d 100644 --- a/haxelib.json +++ b/haxelib.json @@ -4,8 +4,8 @@ "license": "MIT", "tags": [], "description": "A flexible lightweight layer for Haxe cross-platform developers", - "version": "2.0.3", - "releasenote": "Build improvements", + "version": "2.0.4", + "releasenote": "Added system cursor support, updated web server, other fixes", "contributors": [ "singmajesty" ], "dependencies": {} } From 8b308dc64c9cb9d8c9a9da1b86d4eaa6b2e38fd2 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Wed, 31 Dec 2014 21:33:04 -0800 Subject: [PATCH 25/28] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e848acf99..ee4bc976c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * Improved the behavior of the embedded web server * Fixed the behavior of Image.getPixels * Fixed embedded font support for OpenFL HTML5 +* Fixed the Windows application icon * Fixed handling of dummy ANT_HOME or JAVA_HOME HXCPP values * Improved default context menu behavior on Flash/OpenFL * Improved fixed orientation support on iOS (legacy) From 971bfd12884b517eaed73d6522512d4ae8fa2340 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Fri, 2 Jan 2015 06:32:40 -0800 Subject: [PATCH 26/28] Update LICENSE.md --- LICENSE.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/LICENSE.md b/LICENSE.md index 699f839f5..1e3f9cd3e 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -3,7 +3,7 @@ License The MIT License (MIT) -Copyright (c) 2013-2014 OpenFL contributors +Copyright (c) 2013-2015 OpenFL contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -27,8 +27,8 @@ THE SOFTWARE. Portions of other MIT-license projects are also used, including content that is - Copyright (c) 2007-2014 NME contributors - Copyright (c) 2014 snow contributors + Copyright (c) 2007-2015 NME contributors + Copyright (c) 2014-2015 snow contributors ------- From 938c5e78262a815e59c98d4a1c434cd671781222 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Fri, 2 Jan 2015 07:11:31 -0800 Subject: [PATCH 27/28] Allow key code to cast to and from Int without a 'cast' declaration --- lime/ui/KeyCode.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lime/ui/KeyCode.hx b/lime/ui/KeyCode.hx index 52a00d571..b8744a7bc 100644 --- a/lime/ui/KeyCode.hx +++ b/lime/ui/KeyCode.hx @@ -1,7 +1,7 @@ package lime.ui; -@:enum abstract KeyCode(Int) { +@:enum abstract KeyCode(Int) from Int to Int { var UNKNOWN = 0x00; From 394dde821bc58f622948593e325ed351a9074e36 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Sat, 3 Jan 2015 02:11:34 -0800 Subject: [PATCH 28/28] Fix color order --- tools/helpers/IconHelper.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/helpers/IconHelper.hx b/tools/helpers/IconHelper.hx index 12d4163b5..947c12e07 100644 --- a/tools/helpers/IconHelper.hx +++ b/tools/helpers/IconHelper.hx @@ -208,10 +208,10 @@ class IconHelper { for (i in 0...size) { + var a = bits.readByte (); var r = bits.readByte (); var g = bits.readByte (); var b = bits.readByte (); - var a = bits.readByte (); ico.writeByte (b); ico.writeByte (g); ico.writeByte (r);