Add window enter and leave events (mouse focus)

This commit is contained in:
Joshua Granick
2015-04-24 02:18:06 -07:00
parent aefc15ee20
commit 632f0e695d
9 changed files with 104 additions and 8 deletions

View File

@@ -25,6 +25,7 @@ class FlashApplication {
private var cacheTime:Int;
private var mouseLeft:Bool;
private var parent:Application;
@@ -138,6 +139,7 @@ class FlashApplication {
Lib.current.stage.addEventListener (Event.DEACTIVATE, handleWindowEvent);
Lib.current.stage.addEventListener (FocusEvent.FOCUS_IN, handleWindowEvent);
Lib.current.stage.addEventListener (FocusEvent.FOCUS_OUT, handleWindowEvent);
Lib.current.stage.addEventListener (Event.MOUSE_LEAVE, handleWindowEvent);
Lib.current.stage.addEventListener (Event.RESIZE, handleWindowEvent);
cacheTime = Lib.getTimer ();
@@ -192,6 +194,13 @@ class FlashApplication {
case "mouseMove":
if (mouseLeft) {
mouseLeft = false;
parent.window.onWindowEnter.dispatch ();
}
parent.window.onMouseMove.dispatch (event.stageX, event.stageY);
case "mouseUp", "middleMouseUp", "rightMouseUp":
@@ -280,6 +289,11 @@ class FlashApplication {
parent.window.onWindowFocusOut.dispatch ();
case Event.MOUSE_LEAVE:
mouseLeft = true;
parent.window.onWindowLeave.dispatch ();
default:
parent.window.width = Lib.current.stage.stageWidth;

View File

@@ -140,7 +140,7 @@ class HTML5Window {
}
var events = [ "mousedown", "mousemove", "mouseup", "wheel" ];
var events = [ "mousedown", "mouseenter", "mouseleave", "mousemove", "mouseup", "wheel" ];
for (event in events) {
@@ -210,6 +210,14 @@ class HTML5Window {
parent.onMouseDown.dispatch (x, y, event.button);
case "mouseenter":
parent.onWindowEnter.dispatch ();
case "mouseleave":
parent.onWindowLeave.dispatch ();
case "mouseup":
parent.onMouseUp.dispatch (x, y, event.button);

View File

@@ -287,6 +287,10 @@ class NativeApplication {
parent.window.onWindowDeactivate.dispatch ();
case WINDOW_ENTER:
parent.window.onWindowEnter.dispatch ();
case WINDOW_FOCUS_IN:
parent.window.onWindowFocusIn.dispatch ();
@@ -295,6 +299,10 @@ class NativeApplication {
parent.window.onWindowFocusOut.dispatch ();
case WINDOW_LEAVE:
parent.window.onWindowLeave.dispatch ();
case WINDOW_MINIMIZE:
parent.window.__minimized = true;
@@ -650,11 +658,13 @@ private class WindowEventInfo {
var WINDOW_ACTIVATE = 0;
var WINDOW_CLOSE = 1;
var WINDOW_DEACTIVATE = 2;
var WINDOW_FOCUS_IN = 3;
var WINDOW_FOCUS_OUT = 4;
var WINDOW_MINIMIZE = 5;
var WINDOW_MOVE = 6;
var WINDOW_RESIZE = 7;
var WINDOW_RESTORE = 8;
var WINDOW_ENTER = 3;
var WINDOW_FOCUS_IN = 4;
var WINDOW_FOCUS_OUT = 5;
var WINDOW_LEAVE = 6;
var WINDOW_MINIMIZE = 7;
var WINDOW_MOVE = 8;
var WINDOW_RESIZE = 9;
var WINDOW_RESTORE = 10;
}

View File

@@ -119,9 +119,11 @@ class Application extends Module {
window.onWindowActivate.add (onWindowActivate);
window.onWindowClose.add (onWindowClose);
window.onWindowDeactivate.add (onWindowDeactivate);
window.onWindowEnter.add (onWindowEnter);
window.onWindowFocusIn.add (onWindowFocusIn);
window.onWindowFocusOut.add (onWindowFocusOut);
window.onWindowFullscreen.add (onWindowFullscreen);
window.onWindowLeave.add (onWindowLeave);
window.onWindowMinimize.add (onWindowMinimize);
window.onWindowMove.add (onWindowMove);
window.onWindowResize.add (onWindowResize);
@@ -393,6 +395,17 @@ class Application extends Module {
}
public override function onWindowEnter ():Void {
for (module in modules) {
module.onWindowEnter ();
}
}
public override function onWindowFocusIn ():Void {
for (module in modules) {
@@ -426,6 +439,17 @@ class Application extends Module {
}
public override function onWindowLeave ():Void {
for (module in modules) {
module.onWindowLeave ();
}
}
public override function onWindowMinimize ():Void {
for (module in modules) {

View File

@@ -178,6 +178,12 @@ interface IModule {
public function onWindowDeactivate ():Void;
/**
* Called when a window enter event is fired
*/
public function onWindowEnter ():Void;
/**
* Called when a window focus in event is fired
*/
@@ -196,6 +202,12 @@ interface IModule {
public function onWindowFullscreen ():Void;
/**
* Called when a window leave event is fired
*/
public function onWindowLeave ():Void;
/**
* Called when a window move event is fired
* @param x The x position of the window

View File

@@ -153,6 +153,12 @@ class Module implements IModule {
public function onWindowDeactivate ():Void { }
/**
* Called when a window enter event is fired
*/
public function onWindowEnter ():Void { }
/**
* Called when a window focus in event is fired
*/
@@ -165,7 +171,21 @@ class Module implements IModule {
public function onWindowFocusOut ():Void { }
/**
* Called when a window fullscreen event is fired
*/
public function onWindowFullscreen ():Void { }
/**
* Called when a mouse leave event is fired
*/
public function onWindowLeave ():Void { }
/**
* Called when a window minimize event is fired
*/
public function onWindowMinimize ():Void { }

View File

@@ -34,9 +34,11 @@ class Window {
public var onWindowActivate = new Event<Void->Void> ();
public var onWindowClose = new Event<Void->Void> ();
public var onWindowDeactivate = new Event<Void->Void> ();
public var onWindowEnter = new Event<Void->Void> ();
public var onWindowFocusIn = new Event<Void->Void> ();
public var onWindowFocusOut = new Event<Void->Void> ();
public var onWindowFullscreen = new Event<Void->Void> ();
public var onWindowLeave = new Event<Void->Void> ();
public var onWindowMinimize = new Event<Void->Void> ();
public var onWindowMove = new Event<Float->Float->Void> ();
public var onWindowResize = new Event<Int->Int->Void> ();

View File

@@ -13,12 +13,14 @@ namespace lime {
WINDOW_ACTIVATE,
WINDOW_CLOSE,
WINDOW_DEACTIVATE,
WINDOW_ENTER,
WINDOW_FOCUS_IN,
WINDOW_FOCUS_OUT,
WINDOW_LEAVE,
WINDOW_MINIMIZE,
WINDOW_MOVE,
WINDOW_RESIZE,
WINDOW_RESTORE
WINDOW_RESTORE,
};

View File

@@ -149,6 +149,8 @@ namespace lime {
switch (event->window.event) {
case SDL_WINDOWEVENT_ENTER:
case SDL_WINDOWEVENT_LEAVE:
case SDL_WINDOWEVENT_SHOWN:
case SDL_WINDOWEVENT_HIDDEN:
case SDL_WINDOWEVENT_FOCUS_GAINED:
@@ -351,8 +353,10 @@ namespace lime {
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_ENTER: windowEvent.type = WINDOW_ENTER; 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_LEAVE: windowEvent.type = WINDOW_LEAVE; break;
case SDL_WINDOWEVENT_MINIMIZED: windowEvent.type = WINDOW_MINIMIZE; break;
case SDL_WINDOWEVENT_MOVED: