Add more Window events
This commit is contained in:
@@ -83,7 +83,12 @@ class Application extends Module {
|
||||
TouchEventManager.onTouchEnd.add (onTouchEnd);
|
||||
|
||||
Window.onWindowActivate.add (onWindowActivate);
|
||||
Window.onWindowClose.add (onWindowClose);
|
||||
Window.onWindowDeactivate.add (onWindowDeactivate);
|
||||
Window.onWindowFocusIn.add (onWindowFocusIn);
|
||||
Window.onWindowFocusOut.add (onWindowFocusOut);
|
||||
Window.onWindowMove.add (onWindowMove);
|
||||
Window.onWindowResize.add (onWindowResize);
|
||||
|
||||
var window = new Window (config);
|
||||
var renderer = new Renderer (window);
|
||||
@@ -165,7 +170,12 @@ class Application extends Module {
|
||||
public function onTouchMove (x:Float, y:Float, id:Int):Void {}
|
||||
public function onTouchStart (x:Float, y:Float, id:Int):Void {}
|
||||
public function onWindowActivate ():Void {}
|
||||
public function onWindowDeactivate ():Void { }
|
||||
public function onWindowClose ():Void {}
|
||||
public function onWindowDeactivate ():Void {}
|
||||
public function onWindowFocusIn ():Void {}
|
||||
public function onWindowFocusOut ():Void {}
|
||||
public function onWindowMove (x:Float, y:Float):Void {}
|
||||
public function onWindowResize (width:Float, height:Float):Void {}
|
||||
|
||||
|
||||
public function render (context:RenderContext):Void {
|
||||
|
||||
@@ -24,7 +24,12 @@ class Window {
|
||||
|
||||
|
||||
public static var onWindowActivate = new Event<Void->Void> ();
|
||||
public static var onWindowClose = new Event<Void->Void> ();
|
||||
public static var onWindowDeactivate = new Event<Void->Void> ();
|
||||
public static var onWindowFocusIn = new Event<Void->Void> ();
|
||||
public static var onWindowFocusOut = new Event<Void->Void> ();
|
||||
public static var onWindowMove = new Event<Float->Float->Void> ();
|
||||
public static var onWindowResize = new Event<Float->Float->Void> ();
|
||||
|
||||
private static var eventInfo = new WindowEventInfo ();
|
||||
private static var registered:Bool;
|
||||
@@ -34,6 +39,8 @@ class Window {
|
||||
public var fullscreen:Bool;
|
||||
public var height:Int;
|
||||
public var width:Int;
|
||||
public var x:Int;
|
||||
public var y:Int;
|
||||
|
||||
#if js
|
||||
public var canvas:CanvasElement;
|
||||
@@ -213,7 +220,7 @@ class Window {
|
||||
}
|
||||
|
||||
|
||||
private static function dispatch ():Void {
|
||||
private function dispatch ():Void {
|
||||
|
||||
switch (eventInfo.type) {
|
||||
|
||||
@@ -221,10 +228,36 @@ class Window {
|
||||
|
||||
onWindowActivate.dispatch ();
|
||||
|
||||
case WINDOW_CLOSE:
|
||||
|
||||
onWindowClose.dispatch ();
|
||||
|
||||
case WINDOW_DEACTIVATE:
|
||||
|
||||
onWindowDeactivate.dispatch ();
|
||||
|
||||
case WINDOW_FOCUS_IN:
|
||||
|
||||
onWindowFocusIn.dispatch ();
|
||||
|
||||
case WINDOW_FOCUS_OUT:
|
||||
|
||||
onWindowFocusOut.dispatch ();
|
||||
|
||||
case WINDOW_MOVE:
|
||||
|
||||
x = eventInfo.x;
|
||||
y = eventInfo.y;
|
||||
|
||||
onWindowMove.dispatch (eventInfo.x, eventInfo.y);
|
||||
|
||||
case WINDOW_RESIZE:
|
||||
|
||||
width = eventInfo.width;
|
||||
height = eventInfo.height;
|
||||
|
||||
onWindowResize.dispatch (eventInfo.width, eventInfo.height);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -262,19 +295,27 @@ class Window {
|
||||
private class WindowEventInfo {
|
||||
|
||||
|
||||
public var height:Int;
|
||||
public var type:WindowEventType;
|
||||
public var width:Int;
|
||||
public var x:Int;
|
||||
public var y:Int;
|
||||
|
||||
|
||||
public function new (type:WindowEventType = null) {
|
||||
public function new (type:WindowEventType = null, width:Int = 0, height:Int = 0, x:Int = 0, y:Int = 0) {
|
||||
|
||||
this.type = type;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function clone ():WindowEventInfo {
|
||||
|
||||
return new WindowEventInfo (type);
|
||||
return new WindowEventInfo (type, width, height, x, y);
|
||||
|
||||
}
|
||||
|
||||
@@ -302,6 +343,11 @@ private class WindowEventInfo {
|
||||
@:enum private abstract WindowEventType(Int) {
|
||||
|
||||
var WINDOW_ACTIVATE = 0;
|
||||
var WINDOW_DEACTIVATE = 1;
|
||||
var WINDOW_CLOSE = 1;
|
||||
var WINDOW_DEACTIVATE = 2;
|
||||
var WINDOW_FOCUS_IN = 3;
|
||||
var WINDOW_FOCUS_OUT = 4;
|
||||
var WINDOW_MOVE = 5;
|
||||
var WINDOW_RESIZE = 6;
|
||||
|
||||
}
|
||||
@@ -11,7 +11,12 @@ namespace lime {
|
||||
enum WindowEventType {
|
||||
|
||||
WINDOW_ACTIVATE,
|
||||
WINDOW_DEACTIVATE
|
||||
WINDOW_CLOSE,
|
||||
WINDOW_DEACTIVATE,
|
||||
WINDOW_FOCUS_IN,
|
||||
WINDOW_FOCUS_OUT,
|
||||
WINDOW_MOVE,
|
||||
WINDOW_RESIZE
|
||||
|
||||
};
|
||||
|
||||
@@ -27,7 +32,11 @@ namespace lime {
|
||||
|
||||
static void Dispatch (WindowEvent* event);
|
||||
|
||||
int height;
|
||||
WindowEventType type;
|
||||
int width;
|
||||
int x;
|
||||
int y;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -162,6 +162,10 @@ namespace lime {
|
||||
|
||||
case SDL_WINDOWEVENT_SHOWN:
|
||||
case SDL_WINDOWEVENT_HIDDEN:
|
||||
case SDL_WINDOWEVENT_SIZE_CHANGED:
|
||||
case SDL_WINDOWEVENT_FOCUS_GAINED:
|
||||
case SDL_WINDOWEVENT_FOCUS_LOST:
|
||||
case SDL_WINDOWEVENT_MOVED:
|
||||
|
||||
ProcessWindowEvent (event);
|
||||
break;
|
||||
@@ -171,11 +175,9 @@ namespace lime {
|
||||
RenderEvent::Dispatch (&renderEvent);
|
||||
break;
|
||||
|
||||
case SDL_WINDOWEVENT_SIZE_CHANGED: /*resize*/ break;
|
||||
case SDL_WINDOWEVENT_FOCUS_GAINED: /*focus in*/ break;
|
||||
case SDL_WINDOWEVENT_FOCUS_LOST: /*focus out*/ break;
|
||||
case SDL_WINDOWEVENT_CLOSE:
|
||||
|
||||
ProcessWindowEvent (event);
|
||||
active = false;
|
||||
break;
|
||||
|
||||
@@ -261,7 +263,24 @@ namespace lime {
|
||||
switch (event->window.event) {
|
||||
|
||||
case SDL_WINDOWEVENT_SHOWN: windowEvent.type = WINDOW_ACTIVATE; break;
|
||||
case SDL_WINDOWEVENT_CLOSE: windowEvent.type = WINDOW_CLOSE; break;
|
||||
case SDL_WINDOWEVENT_HIDDEN: windowEvent.type = WINDOW_DEACTIVATE; break;
|
||||
case SDL_WINDOWEVENT_FOCUS_GAINED: windowEvent.type = WINDOW_FOCUS_IN; break;
|
||||
case SDL_WINDOWEVENT_FOCUS_LOST: windowEvent.type = WINDOW_FOCUS_OUT; break;
|
||||
|
||||
case SDL_WINDOWEVENT_MOVED:
|
||||
|
||||
windowEvent.type = WINDOW_MOVE;
|
||||
windowEvent.x = event->window.data1;
|
||||
windowEvent.y = event->window.data2;
|
||||
break;
|
||||
|
||||
case SDL_WINDOWEVENT_SIZE_CHANGED:
|
||||
|
||||
windowEvent.type = WINDOW_RESIZE;
|
||||
windowEvent.width = event->window.data1;
|
||||
windowEvent.height = event->window.data2;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,12 @@ namespace lime {
|
||||
|
||||
value object = (MouseEvent::eventObject ? MouseEvent::eventObject->get () : alloc_empty_object ());
|
||||
|
||||
alloc_field (object, id_button, alloc_int (event->button));
|
||||
if (event->type != MOUSE_WHEEL) {
|
||||
|
||||
alloc_field (object, id_button, alloc_int (event->button));
|
||||
|
||||
}
|
||||
|
||||
alloc_field (object, id_type, alloc_int (event->type));
|
||||
alloc_field (object, id_x, alloc_float (event->x));
|
||||
alloc_field (object, id_y, alloc_float (event->y));
|
||||
|
||||
@@ -8,13 +8,21 @@ namespace lime {
|
||||
AutoGCRoot* WindowEvent::callback = 0;
|
||||
AutoGCRoot* WindowEvent::eventObject = 0;
|
||||
|
||||
static int id_height;
|
||||
static int id_type;
|
||||
static int id_width;
|
||||
static int id_x;
|
||||
static int id_y;
|
||||
static bool init = false;
|
||||
|
||||
|
||||
WindowEvent::WindowEvent () {
|
||||
|
||||
type = WINDOW_ACTIVATE;
|
||||
width = 0;
|
||||
height = 0;
|
||||
x = 0;
|
||||
y = 0;
|
||||
|
||||
}
|
||||
|
||||
@@ -25,7 +33,11 @@ namespace lime {
|
||||
|
||||
if (!init) {
|
||||
|
||||
id_height = val_id ("height");
|
||||
id_type = val_id ("type");
|
||||
id_width = val_id ("width");
|
||||
id_x = val_id ("x");
|
||||
id_y = val_id ("y");
|
||||
init = true;
|
||||
|
||||
}
|
||||
@@ -34,6 +46,22 @@ namespace lime {
|
||||
|
||||
alloc_field (object, id_type, alloc_int (event->type));
|
||||
|
||||
switch (event->type) {
|
||||
|
||||
case WINDOW_MOVE:
|
||||
|
||||
alloc_field (object, id_x, alloc_int (event->x));
|
||||
alloc_field (object, id_y, alloc_int (event->y));
|
||||
break;
|
||||
|
||||
case WINDOW_RESIZE:
|
||||
|
||||
alloc_field (object, id_width, alloc_int (event->width));
|
||||
alloc_field (object, id_height, alloc_int (event->height));
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
val_call0 (WindowEvent::callback->get ());
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user