diff --git a/src/api/l_event.c b/src/api/l_event.c index 9e5de77b..a1c14c5b 100644 --- a/src/api/l_event.c +++ b/src/api/l_event.c @@ -11,6 +11,7 @@ StringEntry EventTypes[] = { [EVENT_QUIT] = ENTRY("quit"), [EVENT_RESTART] = ENTRY("restart"), [EVENT_FOCUS] = ENTRY("focus"), + [EVENT_RESIZE] = ENTRY("resize"), #ifdef LOVR_ENABLE_THREAD [EVENT_THREAD_ERROR] = ENTRY("threaderror"), #endif @@ -106,6 +107,11 @@ static int nextEvent(lua_State* L) { lua_pushboolean(L, event.data.boolean.value); return 2; + case EVENT_RESIZE: + lua_pushinteger(L, event.data.resize.width); + lua_pushinteger(L, event.data.resize.height); + return 3; + #ifdef LOVR_ENABLE_THREAD case EVENT_THREAD_ERROR: luax_pushtype(L, Thread, event.data.thread.thread); diff --git a/src/modules/event/event.h b/src/modules/event/event.h index bccf62a1..3fe909a4 100644 --- a/src/modules/event/event.h +++ b/src/modules/event/event.h @@ -11,6 +11,7 @@ typedef enum { EVENT_QUIT, EVENT_RESTART, EVENT_FOCUS, + EVENT_RESIZE, EVENT_CUSTOM, #ifdef LOVR_ENABLE_THREAD EVENT_THREAD_ERROR, @@ -49,6 +50,11 @@ typedef struct { bool value; } BoolEvent; +typedef struct { + uint32_t width; + uint32_t height; +} ResizeEvent; + typedef struct { struct Thread* thread; char* error; @@ -63,6 +69,7 @@ typedef struct { typedef union { QuitEvent quit; BoolEvent boolean; + ResizeEvent resize; ThreadEvent thread; CustomEvent custom; } EventData; diff --git a/src/modules/graphics/graphics.c b/src/modules/graphics/graphics.c index 4d0d4cd4..52ed7eda 100644 --- a/src/modules/graphics/graphics.c +++ b/src/modules/graphics/graphics.c @@ -170,6 +170,7 @@ static void onResizeWindow(int width, int height) { state.height = height; lovrCanvasSetWidth(state.defaultCanvas, width); lovrCanvasSetHeight(state.defaultCanvas, height); + lovrEventPush((Event) { .type = EVENT_RESIZE, .data.resize = { width, height } }); } static void* lovrGraphicsMapBuffer(StreamType type, uint32_t count) {