Add WindowEvent
This commit is contained in:
@@ -4,16 +4,19 @@ package lime.app;
|
|||||||
import lime.ui.IKeyEventListener;
|
import lime.ui.IKeyEventListener;
|
||||||
import lime.ui.IMouseEventListener;
|
import lime.ui.IMouseEventListener;
|
||||||
import lime.ui.ITouchEventListener;
|
import lime.ui.ITouchEventListener;
|
||||||
|
import lime.ui.IWindowEventListener;
|
||||||
import lime.ui.KeyEventManager;
|
import lime.ui.KeyEventManager;
|
||||||
import lime.ui.KeyEvent;
|
import lime.ui.KeyEvent;
|
||||||
import lime.ui.MouseEventManager;
|
import lime.ui.MouseEventManager;
|
||||||
import lime.ui.MouseEvent;
|
import lime.ui.MouseEvent;
|
||||||
import lime.ui.TouchEventManager;
|
import lime.ui.TouchEventManager;
|
||||||
import lime.ui.TouchEvent;
|
import lime.ui.TouchEvent;
|
||||||
|
import lime.ui.WindowEventManager;
|
||||||
|
import lime.ui.WindowEvent;
|
||||||
import lime.system.System;
|
import lime.system.System;
|
||||||
|
|
||||||
|
|
||||||
class Application implements IKeyEventListener implements IMouseEventListener implements ITouchEventListener {
|
class Application implements IKeyEventListener implements IMouseEventListener implements ITouchEventListener implements IWindowEventListener {
|
||||||
|
|
||||||
|
|
||||||
public var handle:Dynamic;
|
public var handle:Dynamic;
|
||||||
@@ -35,10 +38,12 @@ class Application implements IKeyEventListener implements IMouseEventListener im
|
|||||||
new KeyEventManager ();
|
new KeyEventManager ();
|
||||||
new MouseEventManager ();
|
new MouseEventManager ();
|
||||||
new TouchEventManager ();
|
new TouchEventManager ();
|
||||||
|
new WindowEventManager ();
|
||||||
|
|
||||||
KeyEventManager.addEventListener (this);
|
KeyEventManager.addEventListener (this);
|
||||||
MouseEventManager.addEventListener (this);
|
MouseEventManager.addEventListener (this);
|
||||||
TouchEventManager.addEventListener (this);
|
TouchEventManager.addEventListener (this);
|
||||||
|
WindowEventManager.addEventListener (this);
|
||||||
|
|
||||||
var window = new Window (this);
|
var window = new Window (this);
|
||||||
var renderer = new Renderer (window);
|
var renderer = new Renderer (window);
|
||||||
@@ -63,6 +68,8 @@ class Application implements IKeyEventListener implements IMouseEventListener im
|
|||||||
public function onTouchEnd (event:TouchEvent):Void {}
|
public function onTouchEnd (event:TouchEvent):Void {}
|
||||||
public function onTouchMove (event:TouchEvent):Void {}
|
public function onTouchMove (event:TouchEvent):Void {}
|
||||||
public function onTouchStart (event:TouchEvent):Void {}
|
public function onTouchStart (event:TouchEvent):Void {}
|
||||||
|
public function onWindowActivate (event:WindowEvent):Void {}
|
||||||
|
public function onWindowDeactivate (event:WindowEvent):Void {}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
11
lime/ui/IWindowEventListener.hx
Normal file
11
lime/ui/IWindowEventListener.hx
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package lime.ui;
|
||||||
|
|
||||||
|
|
||||||
|
interface IWindowEventListener {
|
||||||
|
|
||||||
|
|
||||||
|
function onWindowActivate (event:WindowEvent):Void;
|
||||||
|
function onWindowDeactivate (event:WindowEvent):Void;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
32
lime/ui/WindowEvent.hx
Normal file
32
lime/ui/WindowEvent.hx
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
package lime.ui;
|
||||||
|
|
||||||
|
|
||||||
|
class WindowEvent {
|
||||||
|
|
||||||
|
|
||||||
|
public var type:WindowEventType;
|
||||||
|
|
||||||
|
|
||||||
|
public function new (type:WindowEventType = null) {
|
||||||
|
|
||||||
|
this.type = type;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function clone ():WindowEvent {
|
||||||
|
|
||||||
|
return new WindowEvent (type);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@:enum abstract WindowEventType(Int) {
|
||||||
|
|
||||||
|
var WINDOW_ACTIVATE = 0;
|
||||||
|
var WINDOW_DEACTIVATE = 1;
|
||||||
|
|
||||||
|
}
|
||||||
70
lime/ui/WindowEventManager.hx
Normal file
70
lime/ui/WindowEventManager.hx
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
package lime.ui;
|
||||||
|
|
||||||
|
|
||||||
|
import lime.system.System;
|
||||||
|
|
||||||
|
|
||||||
|
class WindowEventManager {
|
||||||
|
|
||||||
|
|
||||||
|
private static var instance:WindowEventManager;
|
||||||
|
|
||||||
|
private var listeners:Array<IWindowEventListener>;
|
||||||
|
|
||||||
|
|
||||||
|
public function new () {
|
||||||
|
|
||||||
|
listeners = new Array ();
|
||||||
|
instance = this;
|
||||||
|
|
||||||
|
#if (cpp || neko)
|
||||||
|
lime_window_event_manager_register (handleEvent, new WindowEvent ());
|
||||||
|
#end
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static function addEventListener (listener:IWindowEventListener):Void {
|
||||||
|
|
||||||
|
if (instance != null) {
|
||||||
|
|
||||||
|
instance.listeners.push (listener);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private function handleEvent (event:WindowEvent):Void {
|
||||||
|
|
||||||
|
var event = event.clone ();
|
||||||
|
|
||||||
|
switch (event.type) {
|
||||||
|
|
||||||
|
case WINDOW_ACTIVATE:
|
||||||
|
|
||||||
|
for (listener in listeners) {
|
||||||
|
|
||||||
|
listener.onWindowActivate (event);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
case WINDOW_DEACTIVATE:
|
||||||
|
|
||||||
|
for (listener in listeners) {
|
||||||
|
|
||||||
|
listener.onWindowDeactivate (event);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if (cpp || neko)
|
||||||
|
private static var lime_window_event_manager_register = System.load ("lime", "lime_window_event_manager_register", 2);
|
||||||
|
#end
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -51,6 +51,7 @@
|
|||||||
<file name="src/ui/KeyEvent.cpp" />
|
<file name="src/ui/KeyEvent.cpp" />
|
||||||
<file name="src/ui/MouseEvent.cpp" />
|
<file name="src/ui/MouseEvent.cpp" />
|
||||||
<file name="src/ui/TouchEvent.cpp" />
|
<file name="src/ui/TouchEvent.cpp" />
|
||||||
|
<file name="src/ui/WindowEvent.cpp" />
|
||||||
<file name="src/utils/ByteArray.cpp" />
|
<file name="src/utils/ByteArray.cpp" />
|
||||||
|
|
||||||
</files>
|
</files>
|
||||||
|
|||||||
38
project/include/ui/WindowEvent.h
Normal file
38
project/include/ui/WindowEvent.h
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
#ifndef LIME_UI_WINDOW_EVENT_H
|
||||||
|
#define LIME_UI_WINDOW_EVENT_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <hx/CFFI.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace lime {
|
||||||
|
|
||||||
|
|
||||||
|
enum WindowEventType {
|
||||||
|
|
||||||
|
WINDOW_ACTIVATE,
|
||||||
|
WINDOW_DEACTIVATE
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class WindowEvent {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
static AutoGCRoot* callback;
|
||||||
|
static AutoGCRoot* eventObject;
|
||||||
|
|
||||||
|
WindowEvent ();
|
||||||
|
|
||||||
|
static void Dispatch (WindowEvent* event);
|
||||||
|
|
||||||
|
WindowEventType type;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -14,6 +14,7 @@
|
|||||||
#include <ui/KeyEvent.h>
|
#include <ui/KeyEvent.h>
|
||||||
#include <ui/MouseEvent.h>
|
#include <ui/MouseEvent.h>
|
||||||
#include <ui/TouchEvent.h>
|
#include <ui/TouchEvent.h>
|
||||||
|
#include <ui/WindowEvent.h>
|
||||||
|
|
||||||
|
|
||||||
namespace lime {
|
namespace lime {
|
||||||
@@ -104,6 +105,15 @@ namespace lime {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
value lime_window_event_manager_register (value callback, value eventObject) {
|
||||||
|
|
||||||
|
WindowEvent::callback = new AutoGCRoot (callback);
|
||||||
|
WindowEvent::eventObject = new AutoGCRoot (eventObject);
|
||||||
|
return alloc_null ();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
DEFINE_PRIM (lime_application_create, 0);
|
DEFINE_PRIM (lime_application_create, 0);
|
||||||
DEFINE_PRIM (lime_application_exec, 1);
|
DEFINE_PRIM (lime_application_exec, 1);
|
||||||
DEFINE_PRIM (lime_key_event_manager_register, 2);
|
DEFINE_PRIM (lime_key_event_manager_register, 2);
|
||||||
@@ -113,6 +123,7 @@ namespace lime {
|
|||||||
DEFINE_PRIM (lime_renderer_create, 1);
|
DEFINE_PRIM (lime_renderer_create, 1);
|
||||||
DEFINE_PRIM (lime_touch_event_manager_register, 2);
|
DEFINE_PRIM (lime_touch_event_manager_register, 2);
|
||||||
DEFINE_PRIM (lime_window_create, 1);
|
DEFINE_PRIM (lime_window_create, 1);
|
||||||
|
DEFINE_PRIM (lime_window_event_manager_register, 2);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,9 @@ namespace lime {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
windowEvent.type = WINDOW_DEACTIVATE;
|
||||||
|
WindowEvent::Dispatch (&windowEvent);
|
||||||
|
|
||||||
SDL_Quit ();
|
SDL_Quit ();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -54,71 +57,6 @@ namespace lime {
|
|||||||
|
|
||||||
switch (event->type) {
|
switch (event->type) {
|
||||||
|
|
||||||
case SDL_QUIT:
|
|
||||||
|
|
||||||
//quit
|
|
||||||
active = false;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_WINDOWEVENT:
|
|
||||||
|
|
||||||
switch (event->window.event) {
|
|
||||||
|
|
||||||
case SDL_WINDOWEVENT_SHOWN:
|
|
||||||
|
|
||||||
//activate
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_WINDOWEVENT_HIDDEN:
|
|
||||||
|
|
||||||
//deactivate
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_WINDOWEVENT_EXPOSED:
|
|
||||||
|
|
||||||
//poll
|
|
||||||
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:
|
|
||||||
|
|
||||||
active = false;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
case SDL_MOUSEMOTION:
|
|
||||||
case SDL_MOUSEBUTTONDOWN:
|
|
||||||
case SDL_MOUSEBUTTONUP:
|
|
||||||
case SDL_MOUSEWHEEL:
|
|
||||||
|
|
||||||
ProcessMouseEvent (event);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_KEYDOWN:
|
|
||||||
case SDL_KEYUP:
|
|
||||||
|
|
||||||
ProcessKeyEvent (event);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_JOYAXISMOTION:
|
case SDL_JOYAXISMOTION:
|
||||||
case SDL_JOYBALLMOTION:
|
case SDL_JOYBALLMOTION:
|
||||||
case SDL_JOYBUTTONDOWN:
|
case SDL_JOYBUTTONDOWN:
|
||||||
@@ -130,6 +68,49 @@ namespace lime {
|
|||||||
//joy
|
//joy
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SDL_KEYDOWN:
|
||||||
|
case SDL_KEYUP:
|
||||||
|
|
||||||
|
ProcessKeyEvent (event);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDL_MOUSEMOTION:
|
||||||
|
case SDL_MOUSEBUTTONDOWN:
|
||||||
|
case SDL_MOUSEBUTTONUP:
|
||||||
|
case SDL_MOUSEWHEEL:
|
||||||
|
|
||||||
|
ProcessMouseEvent (event);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDL_WINDOWEVENT:
|
||||||
|
|
||||||
|
switch (event->window.event) {
|
||||||
|
|
||||||
|
case SDL_WINDOWEVENT_SHOWN:
|
||||||
|
case SDL_WINDOWEVENT_HIDDEN:
|
||||||
|
|
||||||
|
ProcessWindowEvent (event);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDL_WINDOWEVENT_EXPOSED: /*poll*/ 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:
|
||||||
|
|
||||||
|
active = false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDL_QUIT:
|
||||||
|
|
||||||
|
//quit
|
||||||
|
active = false;
|
||||||
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -186,6 +167,24 @@ namespace lime {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SDLApplication::ProcessWindowEvent (SDL_Event* event) {
|
||||||
|
|
||||||
|
if (WindowEvent::callback) {
|
||||||
|
|
||||||
|
switch (event->window.event) {
|
||||||
|
|
||||||
|
case SDL_WINDOWEVENT_SHOWN: windowEvent.type = WINDOW_ACTIVATE; break;
|
||||||
|
case SDL_WINDOWEVENT_HIDDEN: windowEvent.type = WINDOW_DEACTIVATE; break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowEvent::Dispatch (&windowEvent);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Application* CreateApplication () {
|
Application* CreateApplication () {
|
||||||
|
|
||||||
return new SDLApplication ();
|
return new SDLApplication ();
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include <ui/KeyEvent.h>
|
#include <ui/KeyEvent.h>
|
||||||
#include <ui/MouseEvent.h>
|
#include <ui/MouseEvent.h>
|
||||||
#include <ui/TouchEvent.h>
|
#include <ui/TouchEvent.h>
|
||||||
|
#include <ui/WindowEvent.h>
|
||||||
|
|
||||||
|
|
||||||
namespace lime {
|
namespace lime {
|
||||||
@@ -27,11 +28,13 @@ namespace lime {
|
|||||||
void ProcessKeyEvent (SDL_Event* event);
|
void ProcessKeyEvent (SDL_Event* event);
|
||||||
void ProcessMouseEvent (SDL_Event* event);
|
void ProcessMouseEvent (SDL_Event* event);
|
||||||
void ProcessTouchEvent (SDL_Event* event);
|
void ProcessTouchEvent (SDL_Event* event);
|
||||||
|
void ProcessWindowEvent (SDL_Event* event);
|
||||||
|
|
||||||
bool active;
|
bool active;
|
||||||
KeyEvent keyEvent;
|
KeyEvent keyEvent;
|
||||||
MouseEvent mouseEvent;
|
MouseEvent mouseEvent;
|
||||||
TouchEvent touchEvent;
|
TouchEvent touchEvent;
|
||||||
|
WindowEvent windowEvent;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
43
project/src/ui/WindowEvent.cpp
Normal file
43
project/src/ui/WindowEvent.cpp
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
#include <hx/CFFI.h>
|
||||||
|
#include <ui/WindowEvent.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace lime {
|
||||||
|
|
||||||
|
|
||||||
|
AutoGCRoot* WindowEvent::callback = 0;
|
||||||
|
AutoGCRoot* WindowEvent::eventObject = 0;
|
||||||
|
|
||||||
|
static int id_type;
|
||||||
|
static bool init = false;
|
||||||
|
|
||||||
|
|
||||||
|
WindowEvent::WindowEvent () {
|
||||||
|
|
||||||
|
type = WINDOW_ACTIVATE;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void WindowEvent::Dispatch (WindowEvent* event) {
|
||||||
|
|
||||||
|
if (WindowEvent::callback) {
|
||||||
|
|
||||||
|
if (!init) {
|
||||||
|
|
||||||
|
id_type = val_id ("type");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
value object = (WindowEvent::eventObject ? WindowEvent::eventObject->get () : alloc_empty_object ());
|
||||||
|
|
||||||
|
alloc_field (object, id_type, alloc_int (event->type));
|
||||||
|
|
||||||
|
val_call1 (WindowEvent::callback->get (), object);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user