Add resize event; lovr.resize callback;

This commit is contained in:
bjorn 2020-05-02 13:05:21 -06:00
parent b035f8e4dc
commit c0d73ab541
3 changed files with 14 additions and 0 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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) {