Add window.id, add native EXIT event, filter window-based events and send to correct window instance
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <hx/CFFI.h>
|
||||
#include <app/Application.h>
|
||||
#include <app/UpdateEvent.h>
|
||||
#include <app/ApplicationEvent.h>
|
||||
#include <audio/format/OGG.h>
|
||||
#include <audio/format/WAV.h>
|
||||
#include <audio/AudioBuffer.h>
|
||||
@@ -51,6 +51,15 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
value lime_application_event_manager_register (value callback, value eventObject) {
|
||||
|
||||
ApplicationEvent::callback = new AutoGCRoot (callback);
|
||||
ApplicationEvent::eventObject = new AutoGCRoot (eventObject);
|
||||
return alloc_null ();
|
||||
|
||||
}
|
||||
|
||||
|
||||
value lime_application_exec (value application) {
|
||||
|
||||
Application* app = (Application*)(intptr_t)val_float (application);
|
||||
@@ -1065,15 +1074,6 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
value lime_update_event_manager_register (value callback, value eventObject) {
|
||||
|
||||
UpdateEvent::callback = new AutoGCRoot (callback);
|
||||
UpdateEvent::eventObject = new AutoGCRoot (eventObject);
|
||||
return alloc_null ();
|
||||
|
||||
}
|
||||
|
||||
|
||||
value lime_window_close (value window) {
|
||||
|
||||
Window* targetWindow = (Window*)(intptr_t)val_float (window);
|
||||
@@ -1116,6 +1116,14 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
value lime_window_get_id (value window) {
|
||||
|
||||
Window* targetWindow = (Window*)(intptr_t)val_float (window);
|
||||
return alloc_int ((int32_t)targetWindow->GetID ());
|
||||
|
||||
}
|
||||
|
||||
|
||||
value lime_window_get_width (value window) {
|
||||
|
||||
Window* targetWindow = (Window*)(intptr_t)val_float (window);
|
||||
@@ -1202,6 +1210,7 @@ namespace lime {
|
||||
|
||||
|
||||
DEFINE_PRIM (lime_application_create, 1);
|
||||
DEFINE_PRIM (lime_application_event_manager_register, 2);
|
||||
DEFINE_PRIM (lime_application_exec, 1);
|
||||
DEFINE_PRIM (lime_application_init, 1);
|
||||
DEFINE_PRIM (lime_application_quit, 1);
|
||||
@@ -1279,12 +1288,12 @@ namespace lime {
|
||||
DEFINE_PRIM (lime_text_layout_set_language, 2);
|
||||
DEFINE_PRIM (lime_text_layout_set_script, 2);
|
||||
DEFINE_PRIM (lime_touch_event_manager_register, 2);
|
||||
DEFINE_PRIM (lime_update_event_manager_register, 2);
|
||||
DEFINE_PRIM (lime_window_close, 1);
|
||||
DEFINE_PRIM (lime_window_create, 5);
|
||||
DEFINE_PRIM (lime_window_event_manager_register, 2);
|
||||
DEFINE_PRIM (lime_window_get_enable_text_events, 1);
|
||||
DEFINE_PRIM (lime_window_get_height, 1);
|
||||
DEFINE_PRIM (lime_window_get_id, 1);
|
||||
DEFINE_PRIM (lime_window_get_width, 1);
|
||||
DEFINE_PRIM (lime_window_get_x, 1);
|
||||
DEFINE_PRIM (lime_window_get_y, 1);
|
||||
|
||||
48
project/src/app/ApplicationEvent.cpp
Normal file
48
project/src/app/ApplicationEvent.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
#include <hx/CFFI.h>
|
||||
#include <app/ApplicationEvent.h>
|
||||
|
||||
|
||||
namespace lime {
|
||||
|
||||
|
||||
AutoGCRoot* ApplicationEvent::callback = 0;
|
||||
AutoGCRoot* ApplicationEvent::eventObject = 0;
|
||||
|
||||
static int id_deltaTime;
|
||||
static int id_type;
|
||||
static bool init = false;
|
||||
|
||||
|
||||
ApplicationEvent::ApplicationEvent () {
|
||||
|
||||
deltaTime = 0;
|
||||
type = UPDATE;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ApplicationEvent::Dispatch (ApplicationEvent* event) {
|
||||
|
||||
if (ApplicationEvent::callback) {
|
||||
|
||||
if (!init) {
|
||||
|
||||
id_deltaTime = val_id ("deltaTime");
|
||||
id_type = val_id ("type");
|
||||
init = true;
|
||||
|
||||
}
|
||||
|
||||
value object = (ApplicationEvent::eventObject ? ApplicationEvent::eventObject->get () : alloc_empty_object ());
|
||||
|
||||
alloc_field (object, id_deltaTime, alloc_int (event->deltaTime));
|
||||
alloc_field (object, id_type, alloc_int (event->type));
|
||||
|
||||
val_call0 (ApplicationEvent::callback->get ());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
#include <hx/CFFI.h>
|
||||
#include <app/UpdateEvent.h>
|
||||
|
||||
|
||||
namespace lime {
|
||||
|
||||
|
||||
AutoGCRoot* UpdateEvent::callback = 0;
|
||||
AutoGCRoot* UpdateEvent::eventObject = 0;
|
||||
|
||||
static int id_deltaTime;
|
||||
//static int id_type;
|
||||
static bool init = false;
|
||||
|
||||
|
||||
UpdateEvent::UpdateEvent () {
|
||||
|
||||
deltaTime = 0;
|
||||
type = UPDATE;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void UpdateEvent::Dispatch (UpdateEvent* event) {
|
||||
|
||||
if (UpdateEvent::callback) {
|
||||
|
||||
if (!init) {
|
||||
|
||||
id_deltaTime = val_id ("deltaTime");
|
||||
//id_type = val_id ("type");
|
||||
init = true;
|
||||
|
||||
}
|
||||
|
||||
value object = (UpdateEvent::eventObject ? UpdateEvent::eventObject->get () : alloc_empty_object ());
|
||||
|
||||
alloc_field (object, id_deltaTime, alloc_int (event->deltaTime));
|
||||
//alloc_field (object, id_type, alloc_int (event->type));
|
||||
|
||||
val_call0 (UpdateEvent::callback->get ());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -40,13 +40,13 @@ namespace lime {
|
||||
lastUpdate = 0;
|
||||
nextUpdate = 0;
|
||||
|
||||
ApplicationEvent applicationEvent;
|
||||
GamepadEvent gamepadEvent;
|
||||
KeyEvent keyEvent;
|
||||
MouseEvent mouseEvent;
|
||||
RenderEvent renderEvent;
|
||||
TextEvent textEvent;
|
||||
TouchEvent touchEvent;
|
||||
UpdateEvent updateEvent;
|
||||
WindowEvent windowEvent;
|
||||
|
||||
#ifdef HX_MACOS
|
||||
@@ -102,7 +102,8 @@ namespace lime {
|
||||
case SDL_USEREVENT:
|
||||
|
||||
currentUpdate = SDL_GetTicks ();
|
||||
updateEvent.deltaTime = currentUpdate - lastUpdate;
|
||||
applicationEvent.type = UPDATE;
|
||||
applicationEvent.deltaTime = currentUpdate - lastUpdate;
|
||||
lastUpdate = currentUpdate;
|
||||
|
||||
while (nextUpdate <= currentUpdate) {
|
||||
@@ -111,7 +112,7 @@ namespace lime {
|
||||
|
||||
}
|
||||
|
||||
UpdateEvent::Dispatch (&updateEvent);
|
||||
ApplicationEvent::Dispatch (&applicationEvent);
|
||||
RenderEvent::Dispatch (&renderEvent);
|
||||
break;
|
||||
|
||||
@@ -240,25 +241,24 @@ namespace lime {
|
||||
|
||||
case SDL_CONTROLLERAXISMOTION:
|
||||
|
||||
if (gamepadsAxisMap[event->caxis.which].empty()) {
|
||||
if (gamepadsAxisMap[event->caxis.which].empty ()) {
|
||||
|
||||
gamepadsAxisMap[event->caxis.which][event->caxis.axis] = event->caxis.value;
|
||||
|
||||
} else if (gamepadsAxisMap[event->caxis.which][event->caxis.axis] == event->caxis.value) {
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
else if (gamepadsAxisMap[event->caxis.which][event->caxis.axis] == event->caxis.value) {
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
|
||||
gamepadEvent.type = AXIS_MOVE;
|
||||
gamepadEvent.axis = event->caxis.axis;
|
||||
gamepadEvent.id = event->caxis.which;
|
||||
|
||||
if (event->caxis.value > -analogAxisDeadZone && event->caxis.value < analogAxisDeadZone) {
|
||||
|
||||
if (gamepadsAxisMap[event->caxis.which][event->caxis.axis] != 0) {
|
||||
|
||||
if (gamepadsAxisMap[event->caxis.which][event->caxis.axis] != 0) {
|
||||
|
||||
gamepadsAxisMap[event->caxis.which][event->caxis.axis] = 0;
|
||||
gamepadEvent.axisValue = 0;
|
||||
GamepadEvent::Dispatch (&gamepadEvent);
|
||||
@@ -385,6 +385,7 @@ namespace lime {
|
||||
|
||||
}
|
||||
|
||||
mouseEvent.windowID = event->button.windowID;
|
||||
MouseEvent::Dispatch (&mouseEvent);
|
||||
|
||||
}
|
||||
@@ -413,7 +414,7 @@ namespace lime {
|
||||
}
|
||||
|
||||
strcpy (textEvent.text, event->text.text);
|
||||
|
||||
textEvent.windowID = event->text.windowID;
|
||||
TextEvent::Dispatch (&textEvent);
|
||||
|
||||
}
|
||||
@@ -453,6 +454,7 @@ namespace lime {
|
||||
|
||||
}
|
||||
|
||||
//touchEvent.windowID = event->tfinger.windowID;
|
||||
TouchEvent::Dispatch (&touchEvent);
|
||||
|
||||
}
|
||||
@@ -493,6 +495,7 @@ namespace lime {
|
||||
|
||||
}
|
||||
|
||||
windowEvent.windowID = event->window.windowID;
|
||||
WindowEvent::Dispatch (&windowEvent);
|
||||
|
||||
}
|
||||
@@ -502,8 +505,8 @@ namespace lime {
|
||||
|
||||
int SDLApplication::Quit () {
|
||||
|
||||
windowEvent.type = WINDOW_DEACTIVATE;
|
||||
WindowEvent::Dispatch (&windowEvent);
|
||||
applicationEvent.type = EXIT;
|
||||
ApplicationEvent::Dispatch (&applicationEvent);
|
||||
|
||||
SDL_Quit ();
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#include <SDL.h>
|
||||
#include <app/Application.h>
|
||||
#include <app/UpdateEvent.h>
|
||||
#include <app/ApplicationEvent.h>
|
||||
#include <graphics/RenderEvent.h>
|
||||
#include <ui/GamepadEvent.h>
|
||||
#include <ui/KeyEvent.h>
|
||||
@@ -49,6 +49,7 @@ namespace lime {
|
||||
static SDLApplication* currentApplication;
|
||||
|
||||
bool active;
|
||||
ApplicationEvent applicationEvent;
|
||||
Uint32 currentUpdate;
|
||||
double framePeriod;
|
||||
GamepadEvent gamepadEvent;
|
||||
@@ -59,7 +60,6 @@ namespace lime {
|
||||
RenderEvent renderEvent;
|
||||
TextEvent textEvent;
|
||||
TouchEvent touchEvent;
|
||||
UpdateEvent updateEvent;
|
||||
WindowEvent windowEvent;
|
||||
|
||||
};
|
||||
|
||||
@@ -135,6 +135,13 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
uint32_t SDLWindow::GetID () {
|
||||
|
||||
return SDL_GetWindowID (sdlWindow);
|
||||
|
||||
}
|
||||
|
||||
|
||||
int SDLWindow::GetWidth () {
|
||||
|
||||
int width;
|
||||
|
||||
@@ -20,6 +20,7 @@ namespace lime {
|
||||
virtual void Close ();
|
||||
virtual bool GetEnableTextEvents ();
|
||||
virtual int GetHeight ();
|
||||
virtual uint32_t GetID ();
|
||||
virtual int GetWidth ();
|
||||
virtual int GetX ();
|
||||
virtual int GetY ();
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace lime {
|
||||
static int id_movementX;
|
||||
static int id_movementY;
|
||||
static int id_type;
|
||||
static int id_windowID;
|
||||
static int id_x;
|
||||
static int id_y;
|
||||
static bool init = false;
|
||||
@@ -21,6 +22,7 @@ namespace lime {
|
||||
|
||||
button = 0;
|
||||
type = MOUSE_DOWN;
|
||||
windowID = 0;
|
||||
x = 0.0;
|
||||
y = 0.0;
|
||||
movementX = 0.0;
|
||||
@@ -39,6 +41,7 @@ namespace lime {
|
||||
id_movementX = val_id ("movementX");
|
||||
id_movementY = val_id ("movementY");
|
||||
id_type = val_id ("type");
|
||||
id_windowID = val_id ("windowID");
|
||||
id_x = val_id ("x");
|
||||
id_y = val_id ("y");
|
||||
init = true;
|
||||
@@ -56,6 +59,7 @@ namespace lime {
|
||||
alloc_field (object, id_movementX, alloc_float (event->movementX));
|
||||
alloc_field (object, id_movementY, alloc_float (event->movementY));
|
||||
alloc_field (object, id_type, alloc_int (event->type));
|
||||
alloc_field (object, id_windowID, alloc_int (event->windowID));
|
||||
alloc_field (object, id_x, alloc_float (event->x));
|
||||
alloc_field (object, id_y, alloc_float (event->y));
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace lime {
|
||||
static int id_start;
|
||||
static int id_text;
|
||||
static int id_type;
|
||||
static int id_windowID;
|
||||
static bool init = false;
|
||||
|
||||
|
||||
@@ -19,6 +20,7 @@ namespace lime {
|
||||
|
||||
length = 0;
|
||||
start = 0;
|
||||
windowID = 0;
|
||||
|
||||
}
|
||||
|
||||
@@ -33,6 +35,7 @@ namespace lime {
|
||||
id_start = val_id ("start");
|
||||
id_text = val_id ("text");
|
||||
id_type = val_id ("type");
|
||||
id_windowID = val_id ("windowID");
|
||||
init = true;
|
||||
|
||||
}
|
||||
@@ -48,6 +51,7 @@ namespace lime {
|
||||
|
||||
alloc_field (object, id_text, alloc_string (event->text));
|
||||
alloc_field (object, id_type, alloc_int (event->type));
|
||||
alloc_field (object, id_windowID, alloc_int (event->windowID));
|
||||
|
||||
val_call0 (TextEvent::callback->get ());
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace lime {
|
||||
|
||||
static int id_id;
|
||||
static int id_type;
|
||||
static int id_windowID;
|
||||
static int id_x;
|
||||
static int id_y;
|
||||
static bool init = false;
|
||||
@@ -19,6 +20,7 @@ namespace lime {
|
||||
|
||||
id = 0;
|
||||
type = TOUCH_START;
|
||||
windowID = 0;
|
||||
x = 0;
|
||||
y = 0;
|
||||
|
||||
@@ -33,6 +35,7 @@ namespace lime {
|
||||
|
||||
id_id = val_id ("id");
|
||||
id_type = val_id ("type");
|
||||
id_windowID = val_id ("windowID");
|
||||
id_x = val_id ("x");
|
||||
id_y = val_id ("y");
|
||||
init = true;
|
||||
@@ -43,6 +46,7 @@ namespace lime {
|
||||
|
||||
alloc_field (object, id_id, alloc_int (event->id));
|
||||
alloc_field (object, id_type, alloc_int (event->type));
|
||||
alloc_field (object, id_windowID, alloc_int (event->windowID));
|
||||
alloc_field (object, id_x, alloc_float (event->x));
|
||||
alloc_field (object, id_y, alloc_float (event->y));
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace lime {
|
||||
static int id_height;
|
||||
static int id_type;
|
||||
static int id_width;
|
||||
static int id_windowID;
|
||||
static int id_x;
|
||||
static int id_y;
|
||||
static bool init = false;
|
||||
@@ -22,8 +23,9 @@ namespace lime {
|
||||
|
||||
width = 0;
|
||||
height = 0;
|
||||
windowID = 0;
|
||||
x = 0;
|
||||
y = 0;
|
||||
y = 0;
|
||||
|
||||
}
|
||||
|
||||
@@ -37,6 +39,7 @@ namespace lime {
|
||||
id_height = val_id ("height");
|
||||
id_type = val_id ("type");
|
||||
id_width = val_id ("width");
|
||||
id_windowID = val_id ("windowID");
|
||||
id_x = val_id ("x");
|
||||
id_y = val_id ("y");
|
||||
init = true;
|
||||
@@ -46,6 +49,7 @@ namespace lime {
|
||||
value object = (WindowEvent::eventObject ? WindowEvent::eventObject->get () : alloc_empty_object ());
|
||||
|
||||
alloc_field (object, id_type, alloc_int (event->type));
|
||||
alloc_field (object, id_windowID, alloc_int (event->windowID));
|
||||
|
||||
switch (event->type) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user