Skip to content

Commit 12f9251

Browse files
committedJul 2, 2024
Backends: SDL3: Update for API changes: SDLK_x renames and SDLK_KP_x removals (#7761, #7762)
Also updated function signature in SDL2 backend to match and because it is expected we will use that data (as per #7672)
1 parent 84cc72f commit 12f9251

File tree

3 files changed

+56
-47
lines changed

3 files changed

+56
-47
lines changed
 

‎backends/imgui_impl_sdl2.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,9 @@ static void ImGui_ImplSDL2_SetPlatformImeData(ImGuiViewport*, ImGuiPlatformImeDa
163163
}
164164
}
165165

166-
static ImGuiKey ImGui_ImplSDL2_KeycodeToImGuiKey(int keycode)
166+
static ImGuiKey ImGui_ImplSDL2_KeyEventToImGuiKey(SDL_Keycode keycode, SDL_Scancode scancode)
167167
{
168+
IM_UNUSED(scancode);
168169
switch (keycode)
169170
{
170171
case SDLK_TAB: return ImGuiKey_Tab;
@@ -361,7 +362,7 @@ bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event)
361362
case SDL_KEYUP:
362363
{
363364
ImGui_ImplSDL2_UpdateKeyModifiers((SDL_Keymod)event->key.keysym.mod);
364-
ImGuiKey key = ImGui_ImplSDL2_KeycodeToImGuiKey(event->key.keysym.sym);
365+
ImGuiKey key = ImGui_ImplSDL2_KeyEventToImGuiKey(event->key.keysym.sym, event->key.keysym.scancode);
365366
io.AddKeyEvent(key, (event->type == SDL_KEYDOWN));
366367
io.SetKeyEventNativeData(key, event->key.keysym.sym, event->key.keysym.scancode, event->key.keysym.scancode); // To support legacy indexing (<1.87 user code). Legacy backend uses SDLK_*** as indices to IsKeyXXX() functions.
367368
return true;

‎backends/imgui_impl_sdl3.cpp

+51-45
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
// CHANGELOG
2424
// (minor and older changes stripped away, please see git history for details)
25+
// 2024-07-02: Update for SDL3 api changes: SDLK_x renames and SDLK_KP_x removals (#7761, #7762).
2526
// 2024-07-01: Update for SDL3 api changes: SDL_SetTextInputRect() changed to SDL_SetTextInputArea().
2627
// 2024-06-26: Update for SDL3 api changes: SDL_StartTextInput()/SDL_StopTextInput()/SDL_SetTextInputRect() functions signatures.
2728
// 2024-06-24: Update for SDL3 api changes: SDL_EVENT_KEY_DOWN/SDL_EVENT_KEY_UP contents.
@@ -146,8 +147,29 @@ static void ImGui_ImplSDL3_SetPlatformImeData(ImGuiViewport* viewport, ImGuiPlat
146147
}
147148
}
148149

149-
static ImGuiKey ImGui_ImplSDL3_KeycodeToImGuiKey(int keycode)
150+
static ImGuiKey ImGui_ImplSDL3_KeyEventToImGuiKey(SDL_Keycode keycode, SDL_Scancode scancode)
150151
{
152+
// Keypad doesn't have individual key values in SDL3
153+
switch (scancode)
154+
{
155+
case SDL_SCANCODE_KP_0: return ImGuiKey_Keypad0;
156+
case SDL_SCANCODE_KP_1: return ImGuiKey_Keypad1;
157+
case SDL_SCANCODE_KP_2: return ImGuiKey_Keypad2;
158+
case SDL_SCANCODE_KP_3: return ImGuiKey_Keypad3;
159+
case SDL_SCANCODE_KP_4: return ImGuiKey_Keypad4;
160+
case SDL_SCANCODE_KP_5: return ImGuiKey_Keypad5;
161+
case SDL_SCANCODE_KP_6: return ImGuiKey_Keypad6;
162+
case SDL_SCANCODE_KP_7: return ImGuiKey_Keypad7;
163+
case SDL_SCANCODE_KP_8: return ImGuiKey_Keypad8;
164+
case SDL_SCANCODE_KP_9: return ImGuiKey_Keypad9;
165+
case SDL_SCANCODE_KP_PERIOD: return ImGuiKey_KeypadDecimal;
166+
case SDL_SCANCODE_KP_DIVIDE: return ImGuiKey_KeypadDivide;
167+
case SDL_SCANCODE_KP_MULTIPLY: return ImGuiKey_KeypadMultiply;
168+
case SDL_SCANCODE_KP_MINUS: return ImGuiKey_KeypadSubtract;
169+
case SDL_SCANCODE_KP_PLUS: return ImGuiKey_KeypadAdd;
170+
case SDL_SCANCODE_KP_ENTER: return ImGuiKey_KeypadEnter;
171+
case SDL_SCANCODE_KP_EQUALS: return ImGuiKey_KeypadEqual;
172+
}
151173
switch (keycode)
152174
{
153175
case SDLK_TAB: return ImGuiKey_Tab;
@@ -181,23 +203,6 @@ static ImGuiKey ImGui_ImplSDL3_KeycodeToImGuiKey(int keycode)
181203
case SDLK_NUMLOCKCLEAR: return ImGuiKey_NumLock;
182204
case SDLK_PRINTSCREEN: return ImGuiKey_PrintScreen;
183205
case SDLK_PAUSE: return ImGuiKey_Pause;
184-
case SDLK_KP_0: return ImGuiKey_Keypad0;
185-
case SDLK_KP_1: return ImGuiKey_Keypad1;
186-
case SDLK_KP_2: return ImGuiKey_Keypad2;
187-
case SDLK_KP_3: return ImGuiKey_Keypad3;
188-
case SDLK_KP_4: return ImGuiKey_Keypad4;
189-
case SDLK_KP_5: return ImGuiKey_Keypad5;
190-
case SDLK_KP_6: return ImGuiKey_Keypad6;
191-
case SDLK_KP_7: return ImGuiKey_Keypad7;
192-
case SDLK_KP_8: return ImGuiKey_Keypad8;
193-
case SDLK_KP_9: return ImGuiKey_Keypad9;
194-
case SDLK_KP_PERIOD: return ImGuiKey_KeypadDecimal;
195-
case SDLK_KP_DIVIDE: return ImGuiKey_KeypadDivide;
196-
case SDLK_KP_MULTIPLY: return ImGuiKey_KeypadMultiply;
197-
case SDLK_KP_MINUS: return ImGuiKey_KeypadSubtract;
198-
case SDLK_KP_PLUS: return ImGuiKey_KeypadAdd;
199-
case SDLK_KP_ENTER: return ImGuiKey_KeypadEnter;
200-
case SDLK_KP_EQUALS: return ImGuiKey_KeypadEqual;
201206
case SDLK_LCTRL: return ImGuiKey_LeftCtrl;
202207
case SDLK_LSHIFT: return ImGuiKey_LeftShift;
203208
case SDLK_LALT: return ImGuiKey_LeftAlt;
@@ -217,32 +222,32 @@ static ImGuiKey ImGui_ImplSDL3_KeycodeToImGuiKey(int keycode)
217222
case SDLK_7: return ImGuiKey_7;
218223
case SDLK_8: return ImGuiKey_8;
219224
case SDLK_9: return ImGuiKey_9;
220-
case SDLK_a: return ImGuiKey_A;
221-
case SDLK_b: return ImGuiKey_B;
222-
case SDLK_c: return ImGuiKey_C;
223-
case SDLK_d: return ImGuiKey_D;
224-
case SDLK_e: return ImGuiKey_E;
225-
case SDLK_f: return ImGuiKey_F;
226-
case SDLK_g: return ImGuiKey_G;
227-
case SDLK_h: return ImGuiKey_H;
228-
case SDLK_i: return ImGuiKey_I;
229-
case SDLK_j: return ImGuiKey_J;
230-
case SDLK_k: return ImGuiKey_K;
231-
case SDLK_l: return ImGuiKey_L;
232-
case SDLK_m: return ImGuiKey_M;
233-
case SDLK_n: return ImGuiKey_N;
234-
case SDLK_o: return ImGuiKey_O;
235-
case SDLK_p: return ImGuiKey_P;
236-
case SDLK_q: return ImGuiKey_Q;
237-
case SDLK_r: return ImGuiKey_R;
238-
case SDLK_s: return ImGuiKey_S;
239-
case SDLK_t: return ImGuiKey_T;
240-
case SDLK_u: return ImGuiKey_U;
241-
case SDLK_v: return ImGuiKey_V;
242-
case SDLK_w: return ImGuiKey_W;
243-
case SDLK_x: return ImGuiKey_X;
244-
case SDLK_y: return ImGuiKey_Y;
245-
case SDLK_z: return ImGuiKey_Z;
225+
case SDLK_A: return ImGuiKey_A;
226+
case SDLK_B: return ImGuiKey_B;
227+
case SDLK_C: return ImGuiKey_C;
228+
case SDLK_D: return ImGuiKey_D;
229+
case SDLK_E: return ImGuiKey_E;
230+
case SDLK_F: return ImGuiKey_F;
231+
case SDLK_G: return ImGuiKey_G;
232+
case SDLK_H: return ImGuiKey_H;
233+
case SDLK_I: return ImGuiKey_I;
234+
case SDLK_J: return ImGuiKey_J;
235+
case SDLK_K: return ImGuiKey_K;
236+
case SDLK_L: return ImGuiKey_L;
237+
case SDLK_M: return ImGuiKey_M;
238+
case SDLK_N: return ImGuiKey_N;
239+
case SDLK_O: return ImGuiKey_O;
240+
case SDLK_P: return ImGuiKey_P;
241+
case SDLK_Q: return ImGuiKey_Q;
242+
case SDLK_R: return ImGuiKey_R;
243+
case SDLK_S: return ImGuiKey_S;
244+
case SDLK_T: return ImGuiKey_T;
245+
case SDLK_U: return ImGuiKey_U;
246+
case SDLK_V: return ImGuiKey_V;
247+
case SDLK_W: return ImGuiKey_W;
248+
case SDLK_X: return ImGuiKey_X;
249+
case SDLK_Y: return ImGuiKey_Y;
250+
case SDLK_Z: return ImGuiKey_Z;
246251
case SDLK_F1: return ImGuiKey_F1;
247252
case SDLK_F2: return ImGuiKey_F2;
248253
case SDLK_F3: return ImGuiKey_F3;
@@ -338,8 +343,9 @@ bool ImGui_ImplSDL3_ProcessEvent(const SDL_Event* event)
338343
case SDL_EVENT_KEY_DOWN:
339344
case SDL_EVENT_KEY_UP:
340345
{
346+
//IMGUI_DEBUG_LOG("SDL_EVENT_KEY_%d: key=%d, scancode=%d, mod=%X\n", (event->type == SDL_EVENT_KEY_DOWN) ? "DOWN" : "UP", event->key.key, event->key.scancode, event->key.mod);
341347
ImGui_ImplSDL3_UpdateKeyModifiers((SDL_Keymod)event->key.mod);
342-
ImGuiKey key = ImGui_ImplSDL3_KeycodeToImGuiKey(event->key.key);
348+
ImGuiKey key = ImGui_ImplSDL3_KeyEventToImGuiKey(event->key.key, event->key.scancode);
343349
io.AddKeyEvent(key, (event->type == SDL_EVENT_KEY_DOWN));
344350
io.SetKeyEventNativeData(key, event->key.key, event->key.scancode, event->key.scancode); // To support legacy indexing (<1.87 user code). Legacy backend uses SDLK_*** as indices to IsKeyXXX() functions.
345351
return true;

‎docs/CHANGELOG.txt

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ Breaking changes:
4343

4444
Other changes:
4545

46+
- Backends: SDL3: Update for API changes: SDLK_x renames and SDLK_KP_x removals (#7761, #7762)
47+
4648

4749
-----------------------------------------------------------------------
4850
VERSION 1.90.9 (Released 2024-07-01)

0 commit comments

Comments
 (0)
Please sign in to comment.