Skip to content

Commit 4be8755

Browse files
committed
Add API: SetPreeditCallback
This is for GLFW3 Preedit Callback: glfwSetPreeditCallback
1 parent 2fd6d7e commit 4be8755

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/raylib.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,14 @@ RLAPI unsigned char *DecodeDataBase64(const unsigned char *data, int *outputSize
10921092
//------------------------------------------------------------------------------------
10931093
// Input Handling Functions (Module: core)
10941094
//------------------------------------------------------------------------------------
1095+
// Callback for preedit text.
1096+
// preeditLength: The length of preedit text
1097+
// preeditString: The preedit text (unicode)
1098+
// blockCount: The number of all converting blocks
1099+
// blockSizes: The size of each converting block
1100+
// focusedBlock: The index of the current converting block
1101+
// caret: The index of the caret in preeditString
1102+
typedef void (*PreeditCallback)(int preeditLength, int *preeditString, int blockCount, int *blockSizes, int focusedBlock, int caret);
10951103

10961104
// Input-related functions: keyboard
10971105
RLAPI bool IsKeyPressed(int key); // Check if a key has been pressed once
@@ -1101,6 +1109,7 @@ RLAPI bool IsKeyUp(int key); // Check if a key
11011109
RLAPI void SetExitKey(int key); // Set a custom key to exit program (default is ESC)
11021110
RLAPI int GetKeyPressed(void); // Get key pressed (keycode), call it multiple times for keys queued, returns 0 when the queue is empty
11031111
RLAPI int GetCharPressed(void); // Get char pressed (unicode), call it multiple times for chars queued, returns 0 when the queue is empty
1112+
RLAPI void SetPreeditCallback(PreeditCallback callback); // Set a callback for preedit
11041113

11051114
// Input-related functions: gamepads
11061115
RLAPI bool IsGamepadAvailable(int gamepad); // Check if a gamepad is available

src/rcore.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,8 @@ typedef struct CoreData {
438438
int charPressedQueue[MAX_CHAR_PRESSED_QUEUE]; // Input characters queue (unicode)
439439
int charPressedQueueCount; // Input characters queue count
440440

441+
PreeditCallback preeditCallback; // Preedit callback
442+
441443
#if defined(PLATFORM_RPI) || defined(PLATFORM_DRM)
442444
int defaultMode; // Default keyboard mode
443445
#if defined(SUPPORT_SSH_KEYBOARD_RPI)
@@ -639,6 +641,7 @@ static void WindowDropCallback(GLFWwindow *window, int count, const char **paths
639641
// Input callbacks events
640642
static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods); // GLFW3 Keyboard Callback, runs on key pressed
641643
static void CharCallback(GLFWwindow *window, unsigned int key); // GLFW3 Char Key Callback, runs on key pressed (get char value)
644+
static void PreeditCallbackInner(GLFWwindow *window, int preeditLength, unsigned int *preeditString, int blockCount, int *blockSizes, int focusedBlock, int caret); // GLFW3 Preedit Callback
642645
static void MouseButtonCallback(GLFWwindow *window, int button, int action, int mods); // GLFW3 Mouse Button Callback, runs on mouse button pressed
643646
static void MouseCursorPosCallback(GLFWwindow *window, double x, double y); // GLFW3 Cursor Position Callback, runs on mouse move
644647
static void MouseScrollCallback(GLFWwindow *window, double xoffset, double yoffset); // GLFW3 Srolling Callback, runs on mouse wheel
@@ -3543,6 +3546,12 @@ int GetCharPressed(void)
35433546
return value;
35443547
}
35453548

3549+
// Set a callback for preedit
3550+
void SetPreeditCallback(PreeditCallback callback)
3551+
{
3552+
CORE.Input.Keyboard.preeditCallback = callback;
3553+
}
3554+
35463555
// Set a custom key to exit program
35473556
// NOTE: default exitKey is ESCAPE
35483557
void SetExitKey(int key)
@@ -4139,6 +4148,7 @@ static bool InitGraphicsDevice(int width, int height)
41394148
// Set input callback events
41404149
glfwSetKeyCallback(CORE.Window.handle, KeyCallback);
41414150
glfwSetCharCallback(CORE.Window.handle, CharCallback);
4151+
glfwSetPreeditCallback(CORE.Window.handle, PreeditCallbackInner);
41424152
glfwSetMouseButtonCallback(CORE.Window.handle, MouseButtonCallback);
41434153
glfwSetCursorPosCallback(CORE.Window.handle, MouseCursorPosCallback); // Track mouse position changes
41444154
glfwSetScrollCallback(CORE.Window.handle, MouseScrollCallback);
@@ -5378,6 +5388,14 @@ static void CharCallback(GLFWwindow *window, unsigned int key)
53785388
}
53795389
}
53805390

5391+
// GLFW3 Preedit Callback
5392+
static void PreeditCallbackInner(GLFWwindow *window, int preeditLength, unsigned int *preeditString, int blockCount, int *blockSizes, int focusedBlock, int caret)
5393+
{
5394+
if (!CORE.Input.Keyboard.preeditCallback) return;
5395+
CORE.Input.Keyboard.preeditCallback(preeditLength, (int *)preeditString, blockCount, blockSizes, focusedBlock, caret);
5396+
}
5397+
5398+
53815399
// GLFW3 Mouse Button Callback, runs on mouse button pressed
53825400
static void MouseButtonCallback(GLFWwindow *window, int button, int action, int mods)
53835401
{

0 commit comments

Comments
 (0)