mirror of https://github.com/bjornbytes/lovr.git
Start textinput event;
This commit is contained in:
parent
682633d98b
commit
c24317d982
|
@ -14,6 +14,7 @@ StringEntry EventTypes[] = {
|
||||||
[EVENT_RESIZE] = ENTRY("resize"),
|
[EVENT_RESIZE] = ENTRY("resize"),
|
||||||
[EVENT_KEYPRESSED] = ENTRY("keypressed"),
|
[EVENT_KEYPRESSED] = ENTRY("keypressed"),
|
||||||
[EVENT_KEYRELEASED] = ENTRY("keyreleased"),
|
[EVENT_KEYRELEASED] = ENTRY("keyreleased"),
|
||||||
|
[EVENT_TEXTINPUT] = ENTRY("textinput"),
|
||||||
#ifdef LOVR_ENABLE_THREAD
|
#ifdef LOVR_ENABLE_THREAD
|
||||||
[EVENT_THREAD_ERROR] = ENTRY("threaderror"),
|
[EVENT_THREAD_ERROR] = ENTRY("threaderror"),
|
||||||
#endif
|
#endif
|
||||||
|
@ -140,6 +141,10 @@ static int nextEvent(lua_State* L) {
|
||||||
lua_pushinteger(L, event.data.key.scancode);
|
lua_pushinteger(L, event.data.key.scancode);
|
||||||
return 3;
|
return 3;
|
||||||
|
|
||||||
|
case EVENT_TEXTINPUT:
|
||||||
|
lua_pushinteger(L, event.data.text.codepoint);
|
||||||
|
return 2;
|
||||||
|
|
||||||
#ifdef LOVR_ENABLE_THREAD
|
#ifdef LOVR_ENABLE_THREAD
|
||||||
case EVENT_THREAD_ERROR:
|
case EVENT_THREAD_ERROR:
|
||||||
luax_pushtype(L, Thread, event.data.thread.thread);
|
luax_pushtype(L, Thread, event.data.thread.thread);
|
||||||
|
|
|
@ -55,6 +55,7 @@ typedef void (*windowFocusCallback)(bool focused);
|
||||||
typedef void (*windowResizeCallback)(int width, int height);
|
typedef void (*windowResizeCallback)(int width, int height);
|
||||||
typedef void (*mouseButtonCallback)(MouseButton button, ButtonAction action);
|
typedef void (*mouseButtonCallback)(MouseButton button, ButtonAction action);
|
||||||
typedef void (*keyboardCallback)(ButtonAction action, KeyCode key, uint32_t scancode, bool repeat);
|
typedef void (*keyboardCallback)(ButtonAction action, KeyCode key, uint32_t scancode, bool repeat);
|
||||||
|
typedef void (*textCallback)(uint32_t codepoint);
|
||||||
|
|
||||||
bool lovrPlatformInit(void);
|
bool lovrPlatformInit(void);
|
||||||
void lovrPlatformDestroy(void);
|
void lovrPlatformDestroy(void);
|
||||||
|
@ -81,6 +82,7 @@ void lovrPlatformOnWindowFocus(windowFocusCallback callback);
|
||||||
void lovrPlatformOnWindowResize(windowResizeCallback callback);
|
void lovrPlatformOnWindowResize(windowResizeCallback callback);
|
||||||
void lovrPlatformOnMouseButton(mouseButtonCallback callback);
|
void lovrPlatformOnMouseButton(mouseButtonCallback callback);
|
||||||
void lovrPlatformOnKeyboardEvent(keyboardCallback callback);
|
void lovrPlatformOnKeyboardEvent(keyboardCallback callback);
|
||||||
|
void lovrPlatformOnTextEvent(textCallback callback);
|
||||||
void lovrPlatformGetMousePosition(double* x, double* y);
|
void lovrPlatformGetMousePosition(double* x, double* y);
|
||||||
void lovrPlatformSetMouseMode(MouseMode mode);
|
void lovrPlatformSetMouseMode(MouseMode mode);
|
||||||
bool lovrPlatformIsMouseDown(MouseButton button);
|
bool lovrPlatformIsMouseDown(MouseButton button);
|
||||||
|
|
|
@ -17,6 +17,7 @@ static struct {
|
||||||
windowResizeCallback onWindowResize;
|
windowResizeCallback onWindowResize;
|
||||||
mouseButtonCallback onMouseButton;
|
mouseButtonCallback onMouseButton;
|
||||||
keyboardCallback onKeyboardEvent;
|
keyboardCallback onKeyboardEvent;
|
||||||
|
textCallback onTextEvent;
|
||||||
} glfwState;
|
} glfwState;
|
||||||
|
|
||||||
static void onError(int code, const char* description) {
|
static void onError(int code, const char* description) {
|
||||||
|
@ -74,6 +75,12 @@ static void onKeyboardEvent(GLFWwindow* window, int k, int scancode, int a, int
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void onTextEvent(GLFWwindow* window, unsigned int codepoint) {
|
||||||
|
if (glfwState.onTextEvent) {
|
||||||
|
glfwState.onTextEvent(codepoint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int convertMouseButton(MouseButton button) {
|
static int convertMouseButton(MouseButton button) {
|
||||||
switch (button) {
|
switch (button) {
|
||||||
case MOUSE_LEFT: return GLFW_MOUSE_BUTTON_LEFT;
|
case MOUSE_LEFT: return GLFW_MOUSE_BUTTON_LEFT;
|
||||||
|
@ -161,6 +168,7 @@ bool lovrPlatformCreateWindow(WindowFlags* flags) {
|
||||||
glfwSetWindowSizeCallback(glfwState.window, onWindowResize);
|
glfwSetWindowSizeCallback(glfwState.window, onWindowResize);
|
||||||
glfwSetMouseButtonCallback(glfwState.window, onMouseButton);
|
glfwSetMouseButtonCallback(glfwState.window, onMouseButton);
|
||||||
glfwSetKeyCallback(glfwState.window, onKeyboardEvent);
|
glfwSetKeyCallback(glfwState.window, onKeyboardEvent);
|
||||||
|
glfwSetCharCallback(glfwState.window, onTextEvent);
|
||||||
lovrPlatformSetSwapInterval(flags->vsync);
|
lovrPlatformSetSwapInterval(flags->vsync);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -223,6 +231,10 @@ void lovrPlatformOnKeyboardEvent(keyboardCallback callback) {
|
||||||
glfwState.onKeyboardEvent = callback;
|
glfwState.onKeyboardEvent = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void lovrPlatformOnTextEvent(textCallback callback) {
|
||||||
|
glfwState.onTextEvent = callback;
|
||||||
|
}
|
||||||
|
|
||||||
void lovrPlatformGetMousePosition(double* x, double* y) {
|
void lovrPlatformGetMousePosition(double* x, double* y) {
|
||||||
if (glfwState.window) {
|
if (glfwState.window) {
|
||||||
glfwGetCursorPos(glfwState.window, x, y);
|
glfwGetCursorPos(glfwState.window, x, y);
|
||||||
|
|
|
@ -22,6 +22,13 @@ static void onKeyboardEvent(ButtonAction action, KeyCode key, uint32_t scancode,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void onTextEvent(uint32_t codepoint) {
|
||||||
|
lovrEventPush((Event) {
|
||||||
|
.type = EVENT_TEXTINPUT,
|
||||||
|
.data.text.codepoint = codepoint
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void lovrVariantDestroy(Variant* variant) {
|
void lovrVariantDestroy(Variant* variant) {
|
||||||
switch (variant->type) {
|
switch (variant->type) {
|
||||||
case TYPE_STRING: free(variant->value.string); return;
|
case TYPE_STRING: free(variant->value.string); return;
|
||||||
|
@ -34,6 +41,7 @@ bool lovrEventInit() {
|
||||||
if (state.initialized) return false;
|
if (state.initialized) return false;
|
||||||
arr_init(&state.events);
|
arr_init(&state.events);
|
||||||
lovrPlatformOnKeyboardEvent(onKeyboardEvent);
|
lovrPlatformOnKeyboardEvent(onKeyboardEvent);
|
||||||
|
lovrPlatformOnTextEvent(onTextEvent);
|
||||||
return state.initialized = true;
|
return state.initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,6 +61,7 @@ void lovrEventDestroy() {
|
||||||
}
|
}
|
||||||
arr_free(&state.events);
|
arr_free(&state.events);
|
||||||
lovrPlatformOnKeyboardEvent(NULL);
|
lovrPlatformOnKeyboardEvent(NULL);
|
||||||
|
lovrPlatformOnTextEvent(NULL);
|
||||||
memset(&state, 0, sizeof(state));
|
memset(&state, 0, sizeof(state));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ typedef enum {
|
||||||
EVENT_RESIZE,
|
EVENT_RESIZE,
|
||||||
EVENT_KEYPRESSED,
|
EVENT_KEYPRESSED,
|
||||||
EVENT_KEYRELEASED,
|
EVENT_KEYRELEASED,
|
||||||
|
EVENT_TEXTINPUT,
|
||||||
EVENT_CUSTOM,
|
EVENT_CUSTOM,
|
||||||
#ifdef LOVR_ENABLE_THREAD
|
#ifdef LOVR_ENABLE_THREAD
|
||||||
EVENT_THREAD_ERROR,
|
EVENT_THREAD_ERROR,
|
||||||
|
@ -63,6 +64,11 @@ typedef struct {
|
||||||
bool repeat;
|
bool repeat;
|
||||||
} KeyEvent;
|
} KeyEvent;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char utf8[4];
|
||||||
|
uint32_t codepoint;
|
||||||
|
} TextEvent;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
struct Thread* thread;
|
struct Thread* thread;
|
||||||
char* error;
|
char* error;
|
||||||
|
@ -79,6 +85,7 @@ typedef union {
|
||||||
BoolEvent boolean;
|
BoolEvent boolean;
|
||||||
ResizeEvent resize;
|
ResizeEvent resize;
|
||||||
KeyEvent key;
|
KeyEvent key;
|
||||||
|
TextEvent text;
|
||||||
ThreadEvent thread;
|
ThreadEvent thread;
|
||||||
CustomEvent custom;
|
CustomEvent custom;
|
||||||
} EventData;
|
} EventData;
|
||||||
|
|
Loading…
Reference in New Issue