diff --git a/legacy/project/src/ExternalInterface.cpp b/legacy/project/src/ExternalInterface.cpp index 6c9472fc8..789b15200 100644 --- a/legacy/project/src/ExternalInterface.cpp +++ b/legacy/project/src/ExternalInterface.cpp @@ -2,6 +2,7 @@ #ifdef HX_WINDOWS #include +#include #include #endif @@ -568,7 +569,12 @@ namespace nme { #endif - value lime_window_notify () { + value lime_window_alert (value type, value title, value message) { + + #ifdef NME_SDL2 + + SDL_Window* sdlWindow = SDL_GL_GetCurrentWindow (); + if (!sdlWindow) return alloc_null (); #ifdef HX_WINDOWS @@ -578,7 +584,7 @@ namespace nme { SDL_SysWMinfo info; SDL_VERSION (&info.version); - SDL_GetWindowWMInfo (SDL_GL_GetCurrentWindow (), &info); + SDL_GetWindowWMInfo (sdlWindow, &info); FLASHWINFO fi; fi.cbSize = sizeof (FLASHWINFO); @@ -590,12 +596,41 @@ namespace nme { #endif + if (!val_is_null (title) && !val_is_null (message)) { + + int flags = 0; + + switch (val_int (type)) { + + case 1: + + flags = SDL_MESSAGEBOX_WARNING; + break; + + case 2: + + flags = SDL_MESSAGEBOX_ERROR; + break; + + default: + + flags = SDL_MESSAGEBOX_INFORMATION; + break; + + } + + SDL_ShowSimpleMessageBox (flags, val_string (title), val_string (message), sdlWindow); + + } + + #endif + return alloc_null (); } - DEFINE_PRIM (lime_window_notify, 0); + DEFINE_PRIM (lime_window_alert, 3); } diff --git a/lime/_backend/flash/FlashWindow.hx b/lime/_backend/flash/FlashWindow.hx index 950a2bb14..52cd9e83f 100644 --- a/lime/_backend/flash/FlashWindow.hx +++ b/lime/_backend/flash/FlashWindow.hx @@ -9,6 +9,7 @@ import lime.graphics.Image; import lime.system.Display; import lime.system.System; import lime.ui.Window; +import lime.ui.WindowAlertType; @:access(lime.app.Application) @:access(lime.ui.Window) @@ -28,6 +29,13 @@ class FlashWindow { } + public function alert (type:WindowAlertType, title:String, message:String):Void { + + + + } + + public function close ():Void { parent.application.removeWindow (parent); @@ -70,13 +78,6 @@ class FlashWindow { - } - - - public function notify ():Void { - - - } diff --git a/lime/_backend/html5/HTML5Window.hx b/lime/_backend/html5/HTML5Window.hx index aa3c6dc9d..10b67553f 100644 --- a/lime/_backend/html5/HTML5Window.hx +++ b/lime/_backend/html5/HTML5Window.hx @@ -21,6 +21,7 @@ import lime.system.Display; import lime.system.System; import lime.ui.Touch; import lime.ui.Window; +import lime.ui.WindowAlertType; #if (haxe_ver < 3.2) typedef FocusEvent = js.html.Event; @@ -67,6 +68,17 @@ class HTML5Window { } + public function alert (type:WindowAlertType, title:String, message:String):Void { + + if (message != null) { + + Browser.alert (message); + + } + + } + + public function close ():Void { parent.application.removeWindow (parent); @@ -520,13 +532,6 @@ class HTML5Window { - } - - - public function notify ():Void { - - - } diff --git a/lime/_backend/native/NativeWindow.hx b/lime/_backend/native/NativeWindow.hx index 1d6dfbe3b..265f78c6f 100644 --- a/lime/_backend/native/NativeWindow.hx +++ b/lime/_backend/native/NativeWindow.hx @@ -8,6 +8,7 @@ import lime.math.Vector2; import lime.system.Display; import lime.system.System; import lime.ui.Window; +import lime.ui.WindowAlertType; #if !macro @:build(lime.system.CFFI.build()) @@ -32,6 +33,25 @@ class NativeWindow { } + public function alert (type:WindowAlertType, title:String, message:String):Void { + + if (handle != null) { + + var nativeType = switch (type) { + + case WARN: 1; + case ERROR: 2; + default: 0; + + } + + lime_window_alert (handle, nativeType, title, message); + + } + + } + + public function close ():Void { if (handle != null) { @@ -154,17 +174,6 @@ class NativeWindow { } - public function notify ():Void { - - if (handle != null) { - - lime_window_notify (handle); - - } - - } - - public function resize (width:Int, height:Int):Void { if (handle != null) { @@ -245,6 +254,7 @@ class NativeWindow { } + @:cffi private static function lime_window_alert (handle:Float, type:Int, title:String, message:String):Void; @:cffi private static function lime_window_close (handle:Float):Void; @:cffi private static function lime_window_create (application:Float, width:Int, height:Int, flags:Int, title:String):Float; @:cffi private static function lime_window_focus (handle:Float):Void; @@ -255,7 +265,6 @@ class NativeWindow { @:cffi private static function lime_window_get_x (handle:Float):Int; @:cffi private static function lime_window_get_y (handle:Float):Int; @:cffi private static function lime_window_move (handle:Float, x:Int, y:Int):Void; - @:cffi private static function lime_window_notify (handle:Float):Void; @:cffi private static function lime_window_resize (handle:Float, width:Int, height:Int):Void; @:cffi private static function lime_window_set_enable_text_events (handle:Float, enabled:Bool):Void; @:cffi private static function lime_window_set_fullscreen (handle:Float, fullscreen:Bool):Bool; diff --git a/lime/ui/Window.hx b/lime/ui/Window.hx index b23be4a19..fc13dd2a9 100644 --- a/lime/ui/Window.hx +++ b/lime/ui/Window.hx @@ -93,6 +93,15 @@ class Window { } + public function alert (type:WindowAlertType = null, title:String = null, message:String = null):Void { + + if (type == null) type = WindowAlertType.INFO; + + backend.alert (type, title, message); + + } + + public function close ():Void { backend.close (); @@ -247,13 +256,6 @@ class Window { } - public function notify ():Void { - - backend.notify (); - - } - - public function resize (width:Int, height:Int):Void { backend.resize (width, height); diff --git a/lime/ui/WindowAlertType.hx b/lime/ui/WindowAlertType.hx new file mode 100644 index 000000000..34bedb8ed --- /dev/null +++ b/lime/ui/WindowAlertType.hx @@ -0,0 +1,10 @@ +package lime.ui; + + +enum WindowAlertType { + + INFO; + WARN; + ERROR; + +} \ No newline at end of file diff --git a/project/include/ui/Window.h b/project/include/ui/Window.h index efb1d5e5a..8a0f77e9b 100644 --- a/project/include/ui/Window.h +++ b/project/include/ui/Window.h @@ -19,6 +19,7 @@ namespace lime { public: + virtual void Alert (int type, const char* title, const char* message) = 0; virtual void Close () = 0; virtual void Focus () = 0; virtual bool GetEnableTextEvents () = 0; @@ -28,7 +29,6 @@ namespace lime { virtual int GetX () = 0; virtual int GetY () = 0; virtual void Move (int x, int y) = 0; - virtual void Notify () = 0; virtual void Resize (int width, int height) = 0; virtual void SetEnableTextEvents (bool enable) = 0; virtual bool SetFullscreen (bool fullscreen) = 0; diff --git a/project/src/ExternalInterface.cpp b/project/src/ExternalInterface.cpp index d833de010..dffb6b7be 100644 --- a/project/src/ExternalInterface.cpp +++ b/project/src/ExternalInterface.cpp @@ -1075,6 +1075,14 @@ namespace lime { } + void lime_window_alert (double window, int type, HxString title, HxString message) { + + Window* targetWindow = (Window*)(intptr_t)window; + targetWindow->Alert (type, title.__s, message.__s); + + } + + void lime_window_close (double window) { Window* targetWindow = (Window*)(intptr_t)window; @@ -1163,14 +1171,6 @@ namespace lime { } - void lime_window_notify (double window) { - - Window* targetWindow = (Window*)(intptr_t)window; - targetWindow->Notify (); - - } - - void lime_window_resize (double window, int width, int height) { Window* targetWindow = (Window*)(intptr_t)window; @@ -1304,6 +1304,7 @@ namespace lime { DEFINE_PRIME2v (lime_text_layout_set_language); DEFINE_PRIME2v (lime_text_layout_set_script); DEFINE_PRIME2v (lime_touch_event_manager_register); + DEFINE_PRIME4v (lime_window_alert); DEFINE_PRIME1v (lime_window_close); DEFINE_PRIME5 (lime_window_create); DEFINE_PRIME2v (lime_window_event_manager_register); @@ -1315,7 +1316,6 @@ namespace lime { DEFINE_PRIME1 (lime_window_get_x); DEFINE_PRIME1 (lime_window_get_y); DEFINE_PRIME3v (lime_window_move); - DEFINE_PRIME1v (lime_window_notify); DEFINE_PRIME3v (lime_window_resize); DEFINE_PRIME2v (lime_window_set_enable_text_events); DEFINE_PRIME2 (lime_window_set_fullscreen); diff --git a/project/src/backend/sdl/SDLWindow.cpp b/project/src/backend/sdl/SDLWindow.cpp index 769e2de9e..cbbc2375e 100644 --- a/project/src/backend/sdl/SDLWindow.cpp +++ b/project/src/backend/sdl/SDLWindow.cpp @@ -105,6 +105,58 @@ namespace lime { } + void SDLWindow::Alert (int type, const char* title, const char* message) { + + #ifdef HX_WINDOWS + + int count = 0; + int speed = 0; + bool stopOnForeground = true; + + SDL_SysWMinfo info; + SDL_VERSION (&info.version); + SDL_GetWindowWMInfo (sdlWindow, &info); + + FLASHWINFO fi; + fi.cbSize = sizeof (FLASHWINFO); + fi.hwnd = info.info.win.window; + fi.dwFlags = stopOnForeground ? FLASHW_ALL | FLASHW_TIMERNOFG : FLASHW_ALL | FLASHW_TIMER; + fi.uCount = count; + fi.dwTimeout = speed; + FlashWindowEx (&fi); + + #endif + + if (title && message) { + + int flags = 0; + + switch (type) { + + case 1: + + flags = SDL_MESSAGEBOX_WARNING; + break; + + case 2: + + flags = SDL_MESSAGEBOX_ERROR; + break; + + default: + + flags = SDL_MESSAGEBOX_INFORMATION; + break; + + } + + SDL_ShowSimpleMessageBox (flags, title, message, sdlWindow); + + } + + } + + void SDLWindow::Close () { if (sdlWindow) { @@ -192,31 +244,6 @@ namespace lime { } - void SDLWindow::Notify () { - - #ifdef HX_WINDOWS - - int count = 0; - int speed = 0; - bool stopOnForeground = true; - - SDL_SysWMinfo info; - SDL_VERSION (&info.version); - SDL_GetWindowWMInfo (sdlWindow, &info); - - FLASHWINFO fi; - fi.cbSize = sizeof(FLASHWINFO); - fi.hwnd = info.info.win.window; - fi.dwFlags = stopOnForeground ? FLASHW_ALL | FLASHW_TIMERNOFG : FLASHW_ALL | FLASHW_TIMER; - fi.uCount = count; - fi.dwTimeout = speed; - FlashWindowEx (&fi); - - #endif - - } - - void SDLWindow::Resize (int width, int height) { SDL_SetWindowSize (sdlWindow, width, height); diff --git a/project/src/backend/sdl/SDLWindow.h b/project/src/backend/sdl/SDLWindow.h index 24d1e6e06..36b9765bd 100644 --- a/project/src/backend/sdl/SDLWindow.h +++ b/project/src/backend/sdl/SDLWindow.h @@ -17,6 +17,7 @@ namespace lime { SDLWindow (Application* application, int width, int height, int flags, const char* title); ~SDLWindow (); + virtual void Alert (int type, const char* title, const char* message); virtual void Close (); virtual void Focus (); virtual bool GetEnableTextEvents (); @@ -26,7 +27,6 @@ namespace lime { virtual int GetX (); virtual int GetY (); virtual void Move (int x, int y); - virtual void Notify (); virtual void Resize (int width, int height); virtual void SetEnableTextEvents (bool enabled); virtual bool SetFullscreen (bool fullscreen);