[milepost] changes to event system that allows using events with payloads (eg file paths) across threads

This commit is contained in:
Martin Fouilleul 2023-04-19 16:19:13 +02:00
parent 81ead1ba91
commit eb09d73fa8
2 changed files with 16 additions and 16 deletions

@ -1 +1 @@
Subproject commit ab150f94f2a9232d47f8a34213dc92dc23438c7f Subproject commit bb6b68ad73b89e0481c3c684e65ac5b10ee1732c

View File

@ -348,15 +348,15 @@ void* orca_runloop(void* user)
while(!mp_should_quit()) while(!mp_should_quit())
{ {
mp_event event = {0}; mp_event* event = 0;
while(mp_next_event(&event)) while((event = mp_next_event(mem_scratch())) != 0)
{ {
if(app->debugOverlay.show) if(app->debugOverlay.show)
{ {
ui_process_event(event); ui_process_event(event);
} }
switch(event.type) switch(event->type)
{ {
case MP_EVENT_WINDOW_CLOSE: case MP_EVENT_WINDOW_CLOSE:
{ {
@ -365,13 +365,13 @@ void* orca_runloop(void* user)
case MP_EVENT_WINDOW_RESIZE: case MP_EVENT_WINDOW_RESIZE:
{ {
mp_rect frame = {0, 0, event.frame.rect.w, event.frame.rect.h}; mp_rect frame = {0, 0, event->frame.rect.w, event->frame.rect.h};
mg_surface_set_frame(app->surface, frame); mg_surface_set_frame(app->surface, frame);
if(eventHandlers[G_EVENT_FRAME_RESIZE]) if(eventHandlers[G_EVENT_FRAME_RESIZE])
{ {
u32 width = (u32)event.frame.rect.w; u32 width = (u32)event->frame.rect.w;
u32 height = (u32)event.frame.rect.h; u32 height = (u32)event->frame.rect.h;
const void* args[2] = {&width, &height}; const void* args[2] = {&width, &height};
m3_Call(eventHandlers[G_EVENT_FRAME_RESIZE], 2, args); m3_Call(eventHandlers[G_EVENT_FRAME_RESIZE], 2, args);
} }
@ -379,11 +379,11 @@ void* orca_runloop(void* user)
case MP_EVENT_MOUSE_BUTTON: case MP_EVENT_MOUSE_BUTTON:
{ {
if(event.key.action == MP_KEY_PRESS) if(event->key.action == MP_KEY_PRESS)
{ {
if(eventHandlers[G_EVENT_MOUSE_DOWN]) if(eventHandlers[G_EVENT_MOUSE_DOWN])
{ {
int key = event.key.code; int key = event->key.code;
const void* args[1] = {&key}; const void* args[1] = {&key};
m3_Call(eventHandlers[G_EVENT_MOUSE_DOWN], 1, args); m3_Call(eventHandlers[G_EVENT_MOUSE_DOWN], 1, args);
} }
@ -392,7 +392,7 @@ void* orca_runloop(void* user)
{ {
if(eventHandlers[G_EVENT_MOUSE_UP]) if(eventHandlers[G_EVENT_MOUSE_UP])
{ {
int key = event.key.code; int key = event->key.code;
const void* args[1] = {&key}; const void* args[1] = {&key};
m3_Call(eventHandlers[G_EVENT_MOUSE_UP], 1, args); m3_Call(eventHandlers[G_EVENT_MOUSE_UP], 1, args);
} }
@ -403,31 +403,31 @@ void* orca_runloop(void* user)
{ {
if(eventHandlers[G_EVENT_MOUSE_MOVE]) if(eventHandlers[G_EVENT_MOUSE_MOVE])
{ {
const void* args[4] = {&event.move.x, &event.move.y, &event.move.deltaX, &event.move.deltaY}; const void* args[4] = {&event->move.x, &event->move.y, &event->move.deltaX, &event->move.deltaY};
m3_Call(eventHandlers[G_EVENT_MOUSE_MOVE], 4, args); m3_Call(eventHandlers[G_EVENT_MOUSE_MOVE], 4, args);
} }
} break; } break;
case MP_EVENT_KEYBOARD_KEY: case MP_EVENT_KEYBOARD_KEY:
{ {
if(event.key.action == MP_KEY_PRESS) if(event->key.action == MP_KEY_PRESS)
{ {
if(event.key.code == MP_KEY_D && (event.key.mods & (MP_KEYMOD_SHIFT | MP_KEYMOD_CMD))) if(event->key.code == MP_KEY_D && (event->key.mods & (MP_KEYMOD_SHIFT | MP_KEYMOD_CMD)))
{ {
debug_overlay_toogle(&app->debugOverlay); debug_overlay_toogle(&app->debugOverlay);
} }
if(eventHandlers[G_EVENT_KEY_DOWN]) if(eventHandlers[G_EVENT_KEY_DOWN])
{ {
const void* args[1] = {&event.key.code}; const void* args[1] = {&event->key.code};
m3_Call(eventHandlers[G_EVENT_KEY_DOWN], 1, args); m3_Call(eventHandlers[G_EVENT_KEY_DOWN], 1, args);
} }
} }
else if(event.key.action == MP_KEY_RELEASE) else if(event->key.action == MP_KEY_RELEASE)
{ {
if(eventHandlers[G_EVENT_KEY_UP]) if(eventHandlers[G_EVENT_KEY_UP])
{ {
const void* args[1] = {&event.key.code}; const void* args[1] = {&event->key.code};
m3_Call(eventHandlers[G_EVENT_KEY_UP], 1, args); m3_Call(eventHandlers[G_EVENT_KEY_UP], 1, args);
} }
} }