Add WindowEvent

This commit is contained in:
Joshua Granick
2014-06-09 12:30:20 -07:00
parent 565c124c9f
commit 0f6adf39d7
10 changed files with 281 additions and 66 deletions

View File

@@ -14,6 +14,7 @@
#include <ui/KeyEvent.h>
#include <ui/MouseEvent.h>
#include <ui/TouchEvent.h>
#include <ui/WindowEvent.h>
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_exec, 1);
DEFINE_PRIM (lime_key_event_manager_register, 2);
@@ -113,6 +123,7 @@ namespace lime {
DEFINE_PRIM (lime_renderer_create, 1);
DEFINE_PRIM (lime_touch_event_manager_register, 2);
DEFINE_PRIM (lime_window_create, 1);
DEFINE_PRIM (lime_window_event_manager_register, 2);
}

View File

@@ -43,6 +43,9 @@ namespace lime {
}
windowEvent.type = WINDOW_DEACTIVATE;
WindowEvent::Dispatch (&windowEvent);
SDL_Quit ();
return 0;
@@ -54,71 +57,6 @@ namespace lime {
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_JOYBALLMOTION:
case SDL_JOYBUTTONDOWN:
@@ -130,6 +68,49 @@ namespace lime {
//joy
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 () {
return new SDLApplication ();

View File

@@ -7,6 +7,7 @@
#include <ui/KeyEvent.h>
#include <ui/MouseEvent.h>
#include <ui/TouchEvent.h>
#include <ui/WindowEvent.h>
namespace lime {
@@ -27,11 +28,13 @@ namespace lime {
void ProcessKeyEvent (SDL_Event* event);
void ProcessMouseEvent (SDL_Event* event);
void ProcessTouchEvent (SDL_Event* event);
void ProcessWindowEvent (SDL_Event* event);
bool active;
KeyEvent keyEvent;
MouseEvent mouseEvent;
TouchEvent touchEvent;
WindowEvent windowEvent;
};

View 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);
}
}
}