Skip to content

Commit 71bb40a

Browse files
daipomashie
authored andcommitted
Add API: SetPreeditCallback
This is for GLFW3 Preedit Callback: glfwSetPreeditCallback
1 parent b432aa2 commit 71bb40a

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

src/platforms/rcore_desktop_glfw.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ static void WindowContentScaleCallback(GLFWwindow *window, float scalex, float s
118118
// Input callbacks events
119119
static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods); // GLFW3 Keyboard Callback, runs on key pressed
120120
static void CharCallback(GLFWwindow *window, unsigned int codepoint); // GLFW3 Char Callback, runs on key pressed (get codepoint value)
121+
static void PreeditCallbackInner(GLFWwindow *window, int preeditLength, unsigned int *preeditString, int blockCount, int *blockSizes, int focusedBlock, int caret); // GLFW3 Preedit Callback
121122
static void MouseButtonCallback(GLFWwindow *window, int button, int action, int mods); // GLFW3 Mouse Button Callback, runs on mouse button pressed
122123
static void MouseCursorPosCallback(GLFWwindow *window, double x, double y); // GLFW3 Cursor Position Callback, runs on mouse move
123124
static void MouseScrollCallback(GLFWwindow *window, double xoffset, double yoffset); // GLFW3 Scrolling Callback, runs on mouse wheel
@@ -1598,6 +1599,7 @@ int InitPlatform(void)
15981599
// Set input callback events
15991600
glfwSetKeyCallback(platform.handle, KeyCallback);
16001601
glfwSetCharCallback(platform.handle, CharCallback);
1602+
glfwSetPreeditCallback(platform.handle, PreeditCallbackInner);
16011603
glfwSetMouseButtonCallback(platform.handle, MouseButtonCallback);
16021604
glfwSetCursorPosCallback(platform.handle, MouseCursorPosCallback); // Track mouse position changes
16031605
glfwSetScrollCallback(platform.handle, MouseScrollCallback);
@@ -1782,6 +1784,13 @@ static void CharCallback(GLFWwindow *window, unsigned int codepoint)
17821784
}
17831785
}
17841786

1787+
// GLFW3 Preedit Callback
1788+
static void PreeditCallbackInner(GLFWwindow *window, int preeditLength, unsigned int *preeditString, int blockCount, int *blockSizes, int focusedBlock, int caret)
1789+
{
1790+
if (!CORE.Input.Keyboard.preeditCallback) return;
1791+
CORE.Input.Keyboard.preeditCallback(preeditLength, (int *)preeditString, blockCount, blockSizes, focusedBlock, caret);
1792+
}
1793+
17851794
// GLFW3 Mouse Button Callback, runs on mouse button pressed
17861795
static void MouseButtonCallback(GLFWwindow *window, int button, int action, int mods)
17871796
{

src/platforms/rcore_web.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ static void WindowContentScaleCallback(GLFWwindow *window, float scalex, float s
122122
// Input callbacks events
123123
static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods); // GLFW3 Keyboard Callback, runs on key pressed
124124
static void CharCallback(GLFWwindow *window, unsigned int key); // GLFW3 Char Key Callback, runs on key pressed (get char value)
125+
static void PreeditCallbackInner(GLFWwindow *window, int preeditLength, unsigned int *preeditString, int blockCount, int *blockSizes, int focusedBlock, int caret); // GLFW3 Preedit Callback
125126
static void MouseButtonCallback(GLFWwindow *window, int button, int action, int mods); // GLFW3 Mouse Button Callback, runs on mouse button pressed
126127
static void MouseCursorPosCallback(GLFWwindow *window, double x, double y); // GLFW3 Cursor Position Callback, runs on mouse move
127128
static void MouseScrollCallback(GLFWwindow *window, double xoffset, double yoffset); // GLFW3 Srolling Callback, runs on mouse wheel
@@ -1219,6 +1220,7 @@ int InitPlatform(void)
12191220
// Set input callback events
12201221
glfwSetKeyCallback(platform.handle, KeyCallback);
12211222
glfwSetCharCallback(platform.handle, CharCallback);
1223+
glfwSetPreeditCallback(platform.handle, PreeditCallbackInner);
12221224
glfwSetMouseButtonCallback(platform.handle, MouseButtonCallback);
12231225
glfwSetCursorPosCallback(platform.handle, MouseCursorPosCallback); // Track mouse position changes
12241226
glfwSetScrollCallback(platform.handle, MouseScrollCallback);
@@ -1453,6 +1455,13 @@ static void CharCallback(GLFWwindow *window, unsigned int key)
14531455
}
14541456
}
14551457

1458+
// GLFW3 Preedit Callback
1459+
static void PreeditCallbackInner(GLFWwindow *window, int preeditLength, unsigned int *preeditString, int blockCount, int *blockSizes, int focusedBlock, int caret)
1460+
{
1461+
if (!CORE.Input.Keyboard.preeditCallback) return;
1462+
CORE.Input.Keyboard.preeditCallback(preeditLength, (int *)preeditString, blockCount, blockSizes, focusedBlock, caret);
1463+
}
1464+
14561465
// GLFW3 Mouse Button Callback, runs on mouse button pressed
14571466
static void MouseButtonCallback(GLFWwindow *window, int button, int action, int mods)
14581467
{

src/raylib.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,6 +1152,14 @@ RLAPI void PlayAutomationEvent(AutomationEvent event);
11521152
//------------------------------------------------------------------------------------
11531153
// Input Handling Functions (Module: core)
11541154
//------------------------------------------------------------------------------------
1155+
// Callback for preedit text.
1156+
// preeditLength: The length of preedit text
1157+
// preeditString: The preedit text (unicode)
1158+
// blockCount: The number of all converting blocks
1159+
// blockSizes: The size of each converting block
1160+
// focusedBlock: The index of the current converting block
1161+
// caret: The index of the caret in preeditString
1162+
typedef void (*PreeditCallback)(int preeditLength, int *preeditString, int blockCount, int *blockSizes, int focusedBlock, int caret);
11551163

11561164
// Input-related functions: keyboard
11571165
RLAPI bool IsKeyPressed(int key); // Check if a key has been pressed once
@@ -1162,6 +1170,7 @@ RLAPI bool IsKeyUp(int key); // Check if a key
11621170
RLAPI int GetKeyPressed(void); // Get key pressed (keycode), call it multiple times for keys queued, returns 0 when the queue is empty
11631171
RLAPI int GetCharPressed(void); // Get char pressed (unicode), call it multiple times for chars queued, returns 0 when the queue is empty
11641172
RLAPI void SetExitKey(int key); // Set a custom key to exit program (default is ESC)
1173+
RLAPI void SetPreeditCallback(PreeditCallback callback); // Set a callback for preedit
11651174

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

src/rcore.c

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

309+
PreeditCallback preeditCallback; // Preedit callback
310+
309311
} Keyboard;
310312
struct {
311313
Vector2 offset; // Mouse offset
@@ -2863,6 +2865,12 @@ int GetCharPressed(void)
28632865
return value;
28642866
}
28652867

2868+
// Set a callback for preedit
2869+
void SetPreeditCallback(PreeditCallback callback)
2870+
{
2871+
CORE.Input.Keyboard.preeditCallback = callback;
2872+
}
2873+
28662874
// Set a custom key to exit program
28672875
// NOTE: default exitKey is set to ESCAPE
28682876
void SetExitKey(int key)

0 commit comments

Comments
 (0)