From 632f0e695dbc5d8957113d4a14357b1033b501fc Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Fri, 24 Apr 2015 02:18:06 -0700 Subject: [PATCH] Add window enter and leave events (mouse focus) --- lime/_backend/flash/FlashApplication.hx | 14 +++++++++++++ lime/_backend/html5/HTML5Window.hx | 10 ++++++++- lime/_backend/native/NativeApplication.hx | 22 ++++++++++++++------ lime/app/Application.hx | 24 ++++++++++++++++++++++ lime/app/IModule.hx | 12 +++++++++++ lime/app/Module.hx | 20 ++++++++++++++++++ lime/ui/Window.hx | 2 ++ project/include/ui/WindowEvent.h | 4 +++- project/src/backend/sdl/SDLApplication.cpp | 4 ++++ 9 files changed, 104 insertions(+), 8 deletions(-) diff --git a/lime/_backend/flash/FlashApplication.hx b/lime/_backend/flash/FlashApplication.hx index c407442e6..7488b6795 100644 --- a/lime/_backend/flash/FlashApplication.hx +++ b/lime/_backend/flash/FlashApplication.hx @@ -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; diff --git a/lime/_backend/html5/HTML5Window.hx b/lime/_backend/html5/HTML5Window.hx index 101bea46f..6cae8c737 100644 --- a/lime/_backend/html5/HTML5Window.hx +++ b/lime/_backend/html5/HTML5Window.hx @@ -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); diff --git a/lime/_backend/native/NativeApplication.hx b/lime/_backend/native/NativeApplication.hx index 4ab68db87..1b86c4f1e 100644 --- a/lime/_backend/native/NativeApplication.hx +++ b/lime/_backend/native/NativeApplication.hx @@ -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; } \ No newline at end of file diff --git a/lime/app/Application.hx b/lime/app/Application.hx index 90d455be0..9fa4dad85 100644 --- a/lime/app/Application.hx +++ b/lime/app/Application.hx @@ -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) { diff --git a/lime/app/IModule.hx b/lime/app/IModule.hx index 5b26d41f2..4627999ae 100644 --- a/lime/app/IModule.hx +++ b/lime/app/IModule.hx @@ -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 diff --git a/lime/app/Module.hx b/lime/app/Module.hx index 05573667c..88b469fad 100644 --- a/lime/app/Module.hx +++ b/lime/app/Module.hx @@ -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 { } diff --git a/lime/ui/Window.hx b/lime/ui/Window.hx index efb4b3dd0..637d01871 100644 --- a/lime/ui/Window.hx +++ b/lime/ui/Window.hx @@ -34,9 +34,11 @@ class Window { public var onWindowActivate = new EventVoid> (); public var onWindowClose = new EventVoid> (); public var onWindowDeactivate = new EventVoid> (); + public var onWindowEnter = new EventVoid> (); public var onWindowFocusIn = new EventVoid> (); public var onWindowFocusOut = new EventVoid> (); public var onWindowFullscreen = new EventVoid> (); + public var onWindowLeave = new EventVoid> (); public var onWindowMinimize = new EventVoid> (); public var onWindowMove = new EventFloat->Void> (); public var onWindowResize = new EventInt->Void> (); diff --git a/project/include/ui/WindowEvent.h b/project/include/ui/WindowEvent.h index 34ee8db1d..a96b33fcc 100644 --- a/project/include/ui/WindowEvent.h +++ b/project/include/ui/WindowEvent.h @@ -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, }; diff --git a/project/src/backend/sdl/SDLApplication.cpp b/project/src/backend/sdl/SDLApplication.cpp index 3f55c091a..25a153bb7 100644 --- a/project/src/backend/sdl/SDLApplication.cpp +++ b/project/src/backend/sdl/SDLApplication.cpp @@ -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: