Name window.notify back to window.alert and unify with simple message box support

This commit is contained in:
Joshua Granick
2015-09-02 09:53:03 -07:00
parent b199e7ac7d
commit dc919adccc
10 changed files with 161 additions and 72 deletions

View File

@@ -2,6 +2,7 @@
#ifdef HX_WINDOWS
#include <SDL_syswm.h>
#include <SDL.h>
#include <Windows.h>
#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);
}

View File

@@ -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 {
}

View File

@@ -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 {
}

View File

@@ -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;

View File

@@ -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);

View File

@@ -0,0 +1,10 @@
package lime.ui;
enum WindowAlertType {
INFO;
WARN;
ERROR;
}

View File

@@ -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;

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);