diff options
| author | Ray <[email protected]> | 2023-12-23 12:04:19 +0100 |
|---|---|---|
| committer | Ray <[email protected]> | 2023-12-23 12:04:19 +0100 |
| commit | efe3510a9a2863afc48c50d38679c0d2ef1929d4 (patch) | |
| tree | 2a344e774336a3a8ffcd84638a27a4a9dc1863ec /src | |
| parent | 1792bce2924d2cfed9f63aa855dc56be449334f2 (diff) | |
| download | raylib-efe3510a9a2863afc48c50d38679c0d2ef1929d4.tar.gz raylib-efe3510a9a2863afc48c50d38679c0d2ef1929d4.zip | |
REVIEWED: SDL text input to Unicode codepoints #3650
REVIEWED: GLFW naming conventions to reflect codepoints reading
Diffstat (limited to 'src')
| -rw-r--r-- | src/platforms/rcore_desktop.c | 10 | ||||
| -rw-r--r-- | src/platforms/rcore_desktop_sdl.c | 12 |
2 files changed, 13 insertions, 9 deletions
diff --git a/src/platforms/rcore_desktop.c b/src/platforms/rcore_desktop.c index 0dfcacd8..2bbb3f2b 100644 --- a/src/platforms/rcore_desktop.c +++ b/src/platforms/rcore_desktop.c @@ -126,7 +126,7 @@ static void WindowDropCallback(GLFWwindow *window, int count, const char **paths // Input callbacks events static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods); // GLFW3 Keyboard Callback, runs on key pressed -static void CharCallback(GLFWwindow *window, unsigned int key); // GLFW3 Char Key Callback, runs on key pressed (get char value) +static void CharCallback(GLFWwindow *window, unsigned int codepoint); // GLFW3 Char Callback, runs on key pressed (get codepoint value) static void MouseButtonCallback(GLFWwindow *window, int button, int action, int mods); // GLFW3 Mouse Button Callback, runs on mouse button pressed static void MouseCursorPosCallback(GLFWwindow *window, double x, double y); // GLFW3 Cursor Position Callback, runs on mouse move static void MouseScrollCallback(GLFWwindow *window, double xoffset, double yoffset); // GLFW3 Scrolling Callback, runs on mouse wheel @@ -1714,10 +1714,10 @@ static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, i if ((key == CORE.Input.Keyboard.exitKey) && (action == GLFW_PRESS)) glfwSetWindowShouldClose(platform.handle, GLFW_TRUE); } -// GLFW3 Char Key Callback, runs on key down (gets equivalent unicode char value) -static void CharCallback(GLFWwindow *window, unsigned int key) +// GLFW3 Char Callback, get unicode codepoint value +static void CharCallback(GLFWwindow *window, unsigned int codepoint) { - //TRACELOG(LOG_DEBUG, "Char Callback: KEY:%i(%c)", key, key); + //TRACELOG(LOG_DEBUG, "Char Callback: Codepoint: %i", codepoint); // NOTE: Registers any key down considering OS keyboard layout but // does not detect action events, those should be managed by user... @@ -1728,7 +1728,7 @@ static void CharCallback(GLFWwindow *window, unsigned int key) if (CORE.Input.Keyboard.charPressedQueueCount < MAX_CHAR_PRESSED_QUEUE) { // Add character to the queue - CORE.Input.Keyboard.charPressedQueue[CORE.Input.Keyboard.charPressedQueueCount] = key; + CORE.Input.Keyboard.charPressedQueue[CORE.Input.Keyboard.charPressedQueueCount] = codepoint; CORE.Input.Keyboard.charPressedQueueCount++; } } diff --git a/src/platforms/rcore_desktop_sdl.c b/src/platforms/rcore_desktop_sdl.c index e1e6e4c9..1e55cbac 100644 --- a/src/platforms/rcore_desktop_sdl.c +++ b/src/platforms/rcore_desktop_sdl.c @@ -1111,19 +1111,23 @@ void PollInputEvents(void) case SDL_TEXTINPUT: { + // NOTE: event.text.text data comes an UTF-8 text sequence but we register codepoints (int) + + int codepointSize = 0; + // Check if there is space available in the key queue if (CORE.Input.Keyboard.keyPressedQueueCount < MAX_KEY_PRESSED_QUEUE) { - // Add character to the queue - CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount] = event.text.text[0]; + // Add character (key) to the queue + CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount] = GetCodepointNext(event.text.text, &codepointSize); CORE.Input.Keyboard.keyPressedQueueCount++; } // Check if there is space available in the queue if (CORE.Input.Keyboard.charPressedQueueCount < MAX_CHAR_PRESSED_QUEUE) { - // Add character to the queue - CORE.Input.Keyboard.charPressedQueue[CORE.Input.Keyboard.charPressedQueueCount] = event.text.text[0]; + // Add character (codepoint) to the queue + CORE.Input.Keyboard.charPressedQueue[CORE.Input.Keyboard.charPressedQueueCount] = GetCodepointNext(event.text.text, &codepointSize); CORE.Input.Keyboard.charPressedQueueCount++; } } break; |
