openMSX
imgui_impl_sdl2.cc
Go to the documentation of this file.
1// dear imgui: Platform Backend for SDL2
2// This needs to be used along with a Renderer (e.g. DirectX11, OpenGL3, Vulkan..)
3// (Info: SDL2 is a cross-platform general purpose library for handling windows, inputs, graphics context creation, etc.)
4// (Prefer SDL 2.0.5+ for full feature support.)
5
6// Implemented features:
7// [X] Platform: Clipboard support.
8// [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen.
9// [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy SDL_SCANCODE_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set]
10// [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
11// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
12// [X] Platform: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
13// Issues:
14// [ ] Platform: Multi-viewport: Minimized windows seems to break mouse wheel events (at least under Windows).
15// [ ] Platform: Multi-viewport: ParentViewportID not honored, and so io.ConfigViewportsNoDefaultParent has no effect (minor).
16// [x] Platform: Basic IME support. App needs to call 'SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1");' before SDL_CreateWindow()!.
17
18// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
19// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
20// Learn about Dear ImGui:
21// - FAQ https://dearimgui.com/faq
22// - Getting Started https://dearimgui.com/getting-started
23// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
24// - Introduction, links and more at the top of imgui.cpp
25
26// CHANGELOG
27// (minor and older changes stripped away, please see git history for details)
28// 2024-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
29// 2024-02-14: Inputs: Handle gamepad disconnection. Added ImGui_ImplSDL2_SetGamepadMode().
30// 2023-10-05: Inputs: Added support for extra ImGuiKey values: F13 to F24 function keys, app back/forward keys.
31// 2023-04-06: Inputs: Avoid calling SDL_StartTextInput()/SDL_StopTextInput() as they don't only pertain to IME. It's unclear exactly what their relation is to IME. (#6306)
32// 2023-04-04: Inputs: Added support for io.AddMouseSourceEvent() to discriminate ImGuiMouseSource_Mouse/ImGuiMouseSource_TouchScreen. (#2702)
33// 2023-02-23: Accept SDL_GetPerformanceCounter() not returning a monotonically increasing value. (#6189, #6114, #3644)
34// 2023-02-07: Implement IME handler (io.SetPlatformImeDataFn will call SDL_SetTextInputRect()/SDL_StartTextInput()).
35// 2023-02-07: *BREAKING CHANGE* Renamed this backend file from imgui_impl_sdl.cpp/.h to imgui_impl_sdl2.cpp/.h in prevision for the future release of SDL3.
36// 2023-02-02: Avoid calling SDL_SetCursor() when cursor has not changed, as the function is surprisingly costly on Mac with latest SDL (may be fixed in next SDL version).
37// 2023-02-02: Added support for SDL 2.0.18+ preciseX/preciseY mouse wheel data for smooth scrolling + Scaling X value on Emscripten (bug?). (#4019, #6096)
38// 2023-02-02: Removed SDL_MOUSEWHEEL value clamping, as values seem correct in latest Emscripten. (#4019)
39// 2023-02-01: Flipping SDL_MOUSEWHEEL 'wheel.x' value to match other backends and offer consistent horizontal scrolling direction. (#4019, #6096, #1463)
40// 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11.
41// 2022-09-26: Inputs: Disable SDL 2.0.22 new "auto capture" (SDL_HINT_MOUSE_AUTO_CAPTURE) which prevents drag and drop across windows for multi-viewport support + don't capture when drag and dropping. (#5710)
42// 2022-09-26: Inputs: Renamed ImGuiKey_ModXXX introduced in 1.87 to ImGuiMod_XXX (old names still supported).
43// 2022-03-22: Inputs: Fix mouse position issues when dragging outside of boundaries. SDL_CaptureMouse() erroneously still gives out LEAVE events when hovering OS decorations.
44// 2022-03-22: Inputs: Added support for extra mouse buttons (SDL_BUTTON_X1/SDL_BUTTON_X2).
45// 2022-02-04: Added SDL_Renderer* parameter to ImGui_ImplSDL2_InitForSDLRenderer(), so we can use SDL_GetRendererOutputSize() instead of SDL_GL_GetDrawableSize() when bound to a SDL_Renderer.
46// 2022-01-26: Inputs: replaced short-lived io.AddKeyModsEvent() (added two weeks ago) with io.AddKeyEvent() using ImGuiKey_ModXXX flags. Sorry for the confusion.
47// 2021-01-20: Inputs: calling new io.AddKeyAnalogEvent() for gamepad support, instead of writing directly to io.NavInputs[].
48// 2022-01-17: Inputs: calling new io.AddMousePosEvent(), io.AddMouseButtonEvent(), io.AddMouseWheelEvent() API (1.87+).
49// 2022-01-17: Inputs: always update key mods next and before key event (not in NewFrame) to fix input queue with very low framerates.
50// 2022-01-12: Update mouse inputs using SDL_MOUSEMOTION/SDL_WINDOWEVENT_LEAVE + fallback to provide it when focused but not hovered/captured. More standard and will allow us to pass it to future input queue API.
51// 2022-01-12: Maintain our own copy of MouseButtonsDown mask instead of using ImGui::IsAnyMouseDown() which will be obsoleted.
52// 2022-01-10: Inputs: calling new io.AddKeyEvent(), io.AddKeyModsEvent() + io.SetKeyEventNativeData() API (1.87+). Support for full ImGuiKey range.
53// 2021-08-17: Calling io.AddFocusEvent() on SDL_WINDOWEVENT_FOCUS_GAINED/SDL_WINDOWEVENT_FOCUS_LOST.
54// 2021-07-29: Inputs: MousePos is correctly reported when the host platform window is hovered but not focused (using SDL_GetMouseFocus() + SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, requires SDL 2.0.5+)
55// 2021-06:29: *BREAKING CHANGE* Removed 'SDL_Window* window' parameter to ImGui_ImplSDL2_NewFrame() which was unnecessary.
56// 2021-06-29: Reorganized backend to pull data from a single structure to facilitate usage with multiple-contexts (all g_XXXX access changed to bd->XXXX).
57// 2021-03-22: Rework global mouse pos availability check listing supported platforms explicitly, effectively fixing mouse access on Raspberry Pi. (#2837, #3950)
58// 2020-05-25: Misc: Report a zero display-size when window is minimized, to be consistent with other backends.
59// 2020-02-20: Inputs: Fixed mapping for ImGuiKey_KeyPadEnter (using SDL_SCANCODE_KP_ENTER instead of SDL_SCANCODE_RETURN2).
60// 2019-12-17: Inputs: On Wayland, use SDL_GetMouseState (because there is no global mouse state).
61// 2019-12-05: Inputs: Added support for ImGuiMouseCursor_NotAllowed mouse cursor.
62// 2019-07-21: Inputs: Added mapping for ImGuiKey_KeyPadEnter.
63// 2019-04-23: Inputs: Added support for SDL_GameController (if ImGuiConfigFlags_NavEnableGamepad is set by user application).
64// 2019-03-12: Misc: Preserve DisplayFramebufferScale when main window is minimized.
65// 2018-12-21: Inputs: Workaround for Android/iOS which don't seem to handle focus related calls.
66// 2018-11-30: Misc: Setting up io.BackendPlatformName so it can be displayed in the About Window.
67// 2018-11-14: Changed the signature of ImGui_ImplSDL2_ProcessEvent() to take a 'const SDL_Event*'.
68// 2018-08-01: Inputs: Workaround for Emscripten which doesn't seem to handle focus related calls.
69// 2018-06-29: Inputs: Added support for the ImGuiMouseCursor_Hand cursor.
70// 2018-06-08: Misc: Extracted imgui_impl_sdl.cpp/.h away from the old combined SDL2+OpenGL/Vulkan examples.
71// 2018-06-08: Misc: ImGui_ImplSDL2_InitForOpenGL() now takes a SDL_GLContext parameter.
72// 2018-05-09: Misc: Fixed clipboard paste memory leak (we didn't call SDL_FreeMemory on the data returned by SDL_GetClipboardText).
73// 2018-03-20: Misc: Setup io.BackendFlags ImGuiBackendFlags_HasMouseCursors flag + honor ImGuiConfigFlags_NoMouseCursorChange flag.
74// 2018-02-16: Inputs: Added support for mouse cursors, honoring ImGui::GetMouseCursor() value.
75// 2018-02-06: Misc: Removed call to ImGui::Shutdown() which is not available from 1.60 WIP, user needs to call CreateContext/DestroyContext themselves.
76// 2018-02-06: Inputs: Added mapping for ImGuiKey_Space.
77// 2018-02-05: Misc: Using SDL_GetPerformanceCounter() instead of SDL_GetTicks() to be able to handle very high framerate (1000+ FPS).
78// 2018-02-05: Inputs: Keyboard mapping is using scancodes everywhere instead of a confusing mixture of keycodes and scancodes.
79// 2018-01-20: Inputs: Added Horizontal Mouse Wheel support.
80// 2018-01-19: Inputs: When available (SDL 2.0.4+) using SDL_CaptureMouse() to retrieve coordinates outside of client area when dragging. Otherwise (SDL 2.0.3 and before) testing for SDL_WINDOW_INPUT_FOCUS instead of SDL_WINDOW_MOUSE_FOCUS.
81// 2018-01-18: Inputs: Added mapping for ImGuiKey_Insert.
82// 2017-08-25: Inputs: MousePos set to -FLT_MAX,-FLT_MAX when mouse is unavailable/missing (instead of -1,-1).
83// 2016-10-15: Misc: Added a void* user_data parameter to Clipboard function handlers.
84
85#include "imgui.h"
86#ifndef IMGUI_DISABLE
87#include "imgui_impl_sdl2.h"
88
89// Clang warnings with -Weverything
90#if defined(__clang__)
91#pragma clang diagnostic push
92#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion" // warning: implicit conversion from 'xxx' to 'float' may lose precision
93#endif
94
95// SDL
96// (the multi-viewports feature requires SDL features supported from SDL 2.0.4+. SDL 2.0.5+ is highly recommended)
97#include <SDL.h>
98#include <SDL_syswm.h>
99#if defined(__APPLE__)
100#include <TargetConditionals.h>
101#endif
102
103#if SDL_VERSION_ATLEAST(2,0,4) && !defined(__EMSCRIPTEN__) && !defined(__ANDROID__) && !(defined(__APPLE__) && TARGET_OS_IOS) && !defined(__amigaos4__)
104#define SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE 1
105#else
106#define SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE 0
107#endif
108#define SDL_HAS_WINDOW_ALPHA SDL_VERSION_ATLEAST(2,0,5)
109#define SDL_HAS_ALWAYS_ON_TOP SDL_VERSION_ATLEAST(2,0,5)
110#define SDL_HAS_USABLE_DISPLAY_BOUNDS SDL_VERSION_ATLEAST(2,0,5)
111#define SDL_HAS_PER_MONITOR_DPI SDL_VERSION_ATLEAST(2,0,4)
112#define SDL_HAS_VULKAN SDL_VERSION_ATLEAST(2,0,6)
113#define SDL_HAS_DISPLAY_EVENT SDL_VERSION_ATLEAST(2,0,9)
114#if !SDL_HAS_VULKAN
115static const Uint32 SDL_WINDOW_VULKAN = 0x10000000;
116#endif
117
118// SDL Data
120{
121 SDL_Window* Window;
122 SDL_Renderer* Renderer;
123 Uint64 Time;
127
128 // Mouse handling
131 SDL_Cursor* MouseCursors[ImGuiMouseCursor_COUNT];
132 SDL_Cursor* MouseLastCursor;
135 bool MouseCanReportHoveredViewport; // This is hard to use/unreliable on SDL so we'll set ImGuiBackendFlags_HasMouseHoveredViewport dynamically based on state.
136
137 // Gamepad handling
138 ImVector<SDL_GameController*> Gamepads;
139 ImGui_ImplSDL2_GamepadMode GamepadMode;
141
142 ImGui_ImplSDL2_Data() { memset((void*)this, 0, sizeof(*this)); }
143};
144
145// Backend data stored in io.BackendPlatformUserData to allow support for multiple Dear ImGui contexts
146// It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts.
147// FIXME: multi-context support is not well tested and probably dysfunctional in this backend.
148// FIXME: some shared resources (mouse cursor shape, gamepad) are mishandled when using multi-context.
149static ImGui_ImplSDL2_Data* ImGui_ImplSDL2_GetBackendData()
150{
151 return ImGui::GetCurrentContext() ? (ImGui_ImplSDL2_Data*)ImGui::GetIO().BackendPlatformUserData : nullptr;
152}
153
154// Forward Declarations
155static void ImGui_ImplSDL2_UpdateMonitors();
156static void ImGui_ImplSDL2_InitPlatformInterface(SDL_Window* window, void* sdl_gl_context);
157static void ImGui_ImplSDL2_ShutdownPlatformInterface();
158
159// Functions
160static const char* ImGui_ImplSDL2_GetClipboardText(void*)
161{
162 ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
163 if (bd->ClipboardTextData)
164 SDL_free(bd->ClipboardTextData);
165 bd->ClipboardTextData = SDL_GetClipboardText();
166 return bd->ClipboardTextData;
167}
168
169static void ImGui_ImplSDL2_SetClipboardText(void*, const char* text)
170{
171 SDL_SetClipboardText(text);
172}
173
174// Note: native IME will only display if user calls SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1") _before_ SDL_CreateWindow().
175static void ImGui_ImplSDL2_SetPlatformImeData(ImGuiViewport* viewport, ImGuiPlatformImeData* data)
176{
177 if (data->WantVisible)
178 {
179 SDL_Rect r;
180 r.x = (int)(data->InputPos.x - viewport->Pos.x);
181 r.y = (int)(data->InputPos.y - viewport->Pos.y + data->InputLineHeight);
182 r.w = 1;
183 r.h = (int)data->InputLineHeight;
184 SDL_SetTextInputRect(&r);
185 }
186}
187
188static ImGuiKey ImGui_ImplSDL2_KeycodeToImGuiKey(int keycode)
189{
190 switch (keycode)
191 {
192 case SDLK_TAB: return ImGuiKey_Tab;
193 case SDLK_LEFT: return ImGuiKey_LeftArrow;
194 case SDLK_RIGHT: return ImGuiKey_RightArrow;
195 case SDLK_UP: return ImGuiKey_UpArrow;
196 case SDLK_DOWN: return ImGuiKey_DownArrow;
197 case SDLK_PAGEUP: return ImGuiKey_PageUp;
198 case SDLK_PAGEDOWN: return ImGuiKey_PageDown;
199 case SDLK_HOME: return ImGuiKey_Home;
200 case SDLK_END: return ImGuiKey_End;
201 case SDLK_INSERT: return ImGuiKey_Insert;
202 case SDLK_DELETE: return ImGuiKey_Delete;
203 case SDLK_BACKSPACE: return ImGuiKey_Backspace;
204 case SDLK_SPACE: return ImGuiKey_Space;
205 case SDLK_RETURN: return ImGuiKey_Enter;
206 case SDLK_ESCAPE: return ImGuiKey_Escape;
207 case SDLK_QUOTE: return ImGuiKey_Apostrophe;
208 case SDLK_COMMA: return ImGuiKey_Comma;
209 case SDLK_MINUS: return ImGuiKey_Minus;
210 case SDLK_PERIOD: return ImGuiKey_Period;
211 case SDLK_SLASH: return ImGuiKey_Slash;
212 case SDLK_SEMICOLON: return ImGuiKey_Semicolon;
213 case SDLK_EQUALS: return ImGuiKey_Equal;
214 case SDLK_LEFTBRACKET: return ImGuiKey_LeftBracket;
215 case SDLK_BACKSLASH: return ImGuiKey_Backslash;
216 case SDLK_RIGHTBRACKET: return ImGuiKey_RightBracket;
217 case SDLK_BACKQUOTE: return ImGuiKey_GraveAccent;
218 case SDLK_CAPSLOCK: return ImGuiKey_CapsLock;
219 case SDLK_SCROLLLOCK: return ImGuiKey_ScrollLock;
220 case SDLK_NUMLOCKCLEAR: return ImGuiKey_NumLock;
221 case SDLK_PRINTSCREEN: return ImGuiKey_PrintScreen;
222 case SDLK_PAUSE: return ImGuiKey_Pause;
223 case SDLK_KP_0: return ImGuiKey_Keypad0;
224 case SDLK_KP_1: return ImGuiKey_Keypad1;
225 case SDLK_KP_2: return ImGuiKey_Keypad2;
226 case SDLK_KP_3: return ImGuiKey_Keypad3;
227 case SDLK_KP_4: return ImGuiKey_Keypad4;
228 case SDLK_KP_5: return ImGuiKey_Keypad5;
229 case SDLK_KP_6: return ImGuiKey_Keypad6;
230 case SDLK_KP_7: return ImGuiKey_Keypad7;
231 case SDLK_KP_8: return ImGuiKey_Keypad8;
232 case SDLK_KP_9: return ImGuiKey_Keypad9;
233 case SDLK_KP_PERIOD: return ImGuiKey_KeypadDecimal;
234 case SDLK_KP_DIVIDE: return ImGuiKey_KeypadDivide;
235 case SDLK_KP_MULTIPLY: return ImGuiKey_KeypadMultiply;
236 case SDLK_KP_MINUS: return ImGuiKey_KeypadSubtract;
237 case SDLK_KP_PLUS: return ImGuiKey_KeypadAdd;
238 case SDLK_KP_ENTER: return ImGuiKey_KeypadEnter;
239 case SDLK_KP_EQUALS: return ImGuiKey_KeypadEqual;
240 case SDLK_LCTRL: return ImGuiKey_LeftCtrl;
241 case SDLK_LSHIFT: return ImGuiKey_LeftShift;
242 case SDLK_LALT: return ImGuiKey_LeftAlt;
243 case SDLK_LGUI: return ImGuiKey_LeftSuper;
244 case SDLK_RCTRL: return ImGuiKey_RightCtrl;
245 case SDLK_RSHIFT: return ImGuiKey_RightShift;
246 case SDLK_RALT: return ImGuiKey_RightAlt;
247 case SDLK_RGUI: return ImGuiKey_RightSuper;
248 case SDLK_APPLICATION: return ImGuiKey_Menu;
249 case SDLK_0: return ImGuiKey_0;
250 case SDLK_1: return ImGuiKey_1;
251 case SDLK_2: return ImGuiKey_2;
252 case SDLK_3: return ImGuiKey_3;
253 case SDLK_4: return ImGuiKey_4;
254 case SDLK_5: return ImGuiKey_5;
255 case SDLK_6: return ImGuiKey_6;
256 case SDLK_7: return ImGuiKey_7;
257 case SDLK_8: return ImGuiKey_8;
258 case SDLK_9: return ImGuiKey_9;
259 case SDLK_a: return ImGuiKey_A;
260 case SDLK_b: return ImGuiKey_B;
261 case SDLK_c: return ImGuiKey_C;
262 case SDLK_d: return ImGuiKey_D;
263 case SDLK_e: return ImGuiKey_E;
264 case SDLK_f: return ImGuiKey_F;
265 case SDLK_g: return ImGuiKey_G;
266 case SDLK_h: return ImGuiKey_H;
267 case SDLK_i: return ImGuiKey_I;
268 case SDLK_j: return ImGuiKey_J;
269 case SDLK_k: return ImGuiKey_K;
270 case SDLK_l: return ImGuiKey_L;
271 case SDLK_m: return ImGuiKey_M;
272 case SDLK_n: return ImGuiKey_N;
273 case SDLK_o: return ImGuiKey_O;
274 case SDLK_p: return ImGuiKey_P;
275 case SDLK_q: return ImGuiKey_Q;
276 case SDLK_r: return ImGuiKey_R;
277 case SDLK_s: return ImGuiKey_S;
278 case SDLK_t: return ImGuiKey_T;
279 case SDLK_u: return ImGuiKey_U;
280 case SDLK_v: return ImGuiKey_V;
281 case SDLK_w: return ImGuiKey_W;
282 case SDLK_x: return ImGuiKey_X;
283 case SDLK_y: return ImGuiKey_Y;
284 case SDLK_z: return ImGuiKey_Z;
285 case SDLK_F1: return ImGuiKey_F1;
286 case SDLK_F2: return ImGuiKey_F2;
287 case SDLK_F3: return ImGuiKey_F3;
288 case SDLK_F4: return ImGuiKey_F4;
289 case SDLK_F5: return ImGuiKey_F5;
290 case SDLK_F6: return ImGuiKey_F6;
291 case SDLK_F7: return ImGuiKey_F7;
292 case SDLK_F8: return ImGuiKey_F8;
293 case SDLK_F9: return ImGuiKey_F9;
294 case SDLK_F10: return ImGuiKey_F10;
295 case SDLK_F11: return ImGuiKey_F11;
296 case SDLK_F12: return ImGuiKey_F12;
297 case SDLK_F13: return ImGuiKey_F13;
298 case SDLK_F14: return ImGuiKey_F14;
299 case SDLK_F15: return ImGuiKey_F15;
300 case SDLK_F16: return ImGuiKey_F16;
301 case SDLK_F17: return ImGuiKey_F17;
302 case SDLK_F18: return ImGuiKey_F18;
303 case SDLK_F19: return ImGuiKey_F19;
304 case SDLK_F20: return ImGuiKey_F20;
305 case SDLK_F21: return ImGuiKey_F21;
306 case SDLK_F22: return ImGuiKey_F22;
307 case SDLK_F23: return ImGuiKey_F23;
308 case SDLK_F24: return ImGuiKey_F24;
309 case SDLK_AC_BACK: return ImGuiKey_AppBack;
310 case SDLK_AC_FORWARD: return ImGuiKey_AppForward;
311 }
312 return ImGuiKey_None;
313}
314
315static void ImGui_ImplSDL2_UpdateKeyModifiers(SDL_Keymod sdl_key_mods)
316{
317 ImGuiIO& io = ImGui::GetIO();
318 io.AddKeyEvent(ImGuiMod_Ctrl, (sdl_key_mods & KMOD_CTRL) != 0);
319 io.AddKeyEvent(ImGuiMod_Shift, (sdl_key_mods & KMOD_SHIFT) != 0);
320 io.AddKeyEvent(ImGuiMod_Alt, (sdl_key_mods & KMOD_ALT) != 0);
321 io.AddKeyEvent(ImGuiMod_Super, (sdl_key_mods & KMOD_GUI) != 0);
322}
323
324// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
325// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data.
326// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data.
327// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
328// If you have multiple SDL events and some of them are not meant to be used by dear imgui, you may need to filter events based on their windowID field.
329bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event)
330{
331 ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
332 IM_ASSERT(bd != nullptr && "Context or backend not initialized! Did you call ImGui_ImplSDL2_Init()?");
333 ImGuiIO& io = ImGui::GetIO();
334
335 switch (event->type)
336 {
337 case SDL_MOUSEMOTION:
338 {
339 ImVec2 mouse_pos((float)event->motion.x, (float)event->motion.y);
340 if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
341 {
342 int window_x, window_y;
343 SDL_GetWindowPosition(SDL_GetWindowFromID(event->motion.windowID), &window_x, &window_y);
344 mouse_pos.x += window_x;
345 mouse_pos.y += window_y;
346 }
347 io.AddMouseSourceEvent(event->motion.which == SDL_TOUCH_MOUSEID ? ImGuiMouseSource_TouchScreen : ImGuiMouseSource_Mouse);
348 io.AddMousePosEvent(mouse_pos.x, mouse_pos.y);
349 return true;
350 }
351 case SDL_MOUSEWHEEL:
352 {
353 //IMGUI_DEBUG_LOG("wheel %.2f %.2f, precise %.2f %.2f\n", (float)event->wheel.x, (float)event->wheel.y, event->wheel.preciseX, event->wheel.preciseY);
354#if SDL_VERSION_ATLEAST(2,0,18) // If this fails to compile on Emscripten: update to latest Emscripten!
355 float wheel_x = -event->wheel.preciseX;
356 float wheel_y = event->wheel.preciseY;
357#else
358 float wheel_x = -(float)event->wheel.x;
359 float wheel_y = (float)event->wheel.y;
360#endif
361#ifdef __EMSCRIPTEN__
362 wheel_x /= 100.0f;
363#endif
364 io.AddMouseSourceEvent(event->wheel.which == SDL_TOUCH_MOUSEID ? ImGuiMouseSource_TouchScreen : ImGuiMouseSource_Mouse);
365 io.AddMouseWheelEvent(wheel_x, wheel_y);
366 return true;
367 }
368 case SDL_MOUSEBUTTONDOWN:
369 case SDL_MOUSEBUTTONUP:
370 {
371 int mouse_button = -1;
372 if (event->button.button == SDL_BUTTON_LEFT) { mouse_button = 0; }
373 if (event->button.button == SDL_BUTTON_RIGHT) { mouse_button = 1; }
374 if (event->button.button == SDL_BUTTON_MIDDLE) { mouse_button = 2; }
375 if (event->button.button == SDL_BUTTON_X1) { mouse_button = 3; }
376 if (event->button.button == SDL_BUTTON_X2) { mouse_button = 4; }
377 if (mouse_button == -1)
378 break;
379 io.AddMouseSourceEvent(event->button.which == SDL_TOUCH_MOUSEID ? ImGuiMouseSource_TouchScreen : ImGuiMouseSource_Mouse);
380 io.AddMouseButtonEvent(mouse_button, (event->type == SDL_MOUSEBUTTONDOWN));
381 bd->MouseButtonsDown = (event->type == SDL_MOUSEBUTTONDOWN) ? (bd->MouseButtonsDown | (1 << mouse_button)) : (bd->MouseButtonsDown & ~(1 << mouse_button));
382 return true;
383 }
384 case SDL_TEXTINPUT:
385 {
386 io.AddInputCharactersUTF8(event->text.text);
387 return true;
388 }
389 case SDL_KEYDOWN:
390 case SDL_KEYUP:
391 {
392 ImGui_ImplSDL2_UpdateKeyModifiers((SDL_Keymod)event->key.keysym.mod);
393 ImGuiKey key = ImGui_ImplSDL2_KeycodeToImGuiKey(event->key.keysym.sym);
394 io.AddKeyEvent(key, (event->type == SDL_KEYDOWN));
395 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.
396 return true;
397 }
398#if SDL_HAS_DISPLAY_EVENT
399 case SDL_DISPLAYEVENT:
400 {
401 // 2.0.26 has SDL_DISPLAYEVENT_CONNECTED/SDL_DISPLAYEVENT_DISCONNECTED/SDL_DISPLAYEVENT_ORIENTATION,
402 // so change of DPI/Scaling are not reflected in this event. (SDL3 has it)
403 bd->WantUpdateMonitors = true;
404 return true;
405 }
406#endif
407 case SDL_WINDOWEVENT:
408 {
409 // - When capturing mouse, SDL will send a bunch of conflicting LEAVE/ENTER event on every mouse move, but the final ENTER tends to be right.
410 // - However we won't get a correct LEAVE event for a captured window.
411 // - In some cases, when detaching a window from main viewport SDL may send SDL_WINDOWEVENT_ENTER one frame too late,
412 // causing SDL_WINDOWEVENT_LEAVE on previous frame to interrupt drag operation by clear mouse position. This is why
413 // we delay process the SDL_WINDOWEVENT_LEAVE events by one frame. See issue #5012 for details.
414 Uint8 window_event = event->window.event;
415 if (window_event == SDL_WINDOWEVENT_ENTER)
416 {
417 bd->MouseWindowID = event->window.windowID;
418 bd->MouseLastLeaveFrame = 0;
419 }
420 if (window_event == SDL_WINDOWEVENT_LEAVE)
421 bd->MouseLastLeaveFrame = ImGui::GetFrameCount() + 1;
422 if (window_event == SDL_WINDOWEVENT_FOCUS_GAINED)
423 io.AddFocusEvent(true);
424 else if (window_event == SDL_WINDOWEVENT_FOCUS_LOST)
425 io.AddFocusEvent(false);
426 if (window_event == SDL_WINDOWEVENT_CLOSE || window_event == SDL_WINDOWEVENT_MOVED || window_event == SDL_WINDOWEVENT_RESIZED)
427 if (ImGuiViewport* viewport = ImGui::FindViewportByPlatformHandle((void*)SDL_GetWindowFromID(event->window.windowID)))
428 {
429 if (window_event == SDL_WINDOWEVENT_CLOSE)
430 viewport->PlatformRequestClose = true;
431 if (window_event == SDL_WINDOWEVENT_MOVED)
432 viewport->PlatformRequestMove = true;
433 if (window_event == SDL_WINDOWEVENT_RESIZED)
434 viewport->PlatformRequestResize = true;
435 return true;
436 }
437 return true;
438 }
439 case SDL_CONTROLLERDEVICEADDED:
440 case SDL_CONTROLLERDEVICEREMOVED:
441 {
442 bd->WantUpdateGamepadsList = true;
443 return true;
444 }
445 }
446 return false;
447}
448
449static bool ImGui_ImplSDL2_Init(SDL_Window* window, SDL_Renderer* renderer, void* sdl_gl_context)
450{
451 ImGuiIO& io = ImGui::GetIO();
452 IM_ASSERT(io.BackendPlatformUserData == nullptr && "Already initialized a platform backend!");
453
454 // Check and store if we are on a SDL backend that supports global mouse position
455 // ("wayland" and "rpi" don't support it, but we chose to use a white-list instead of a black-list)
456 bool mouse_can_use_global_state = false;
457#if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE
458 const char* sdl_backend = SDL_GetCurrentVideoDriver();
459 const char* global_mouse_whitelist[] = { "windows", "cocoa", "x11", "DIVE", "VMAN" };
460 for (int n = 0; n < IM_ARRAYSIZE(global_mouse_whitelist); n++)
461 if (strncmp(sdl_backend, global_mouse_whitelist[n], strlen(global_mouse_whitelist[n])) == 0)
462 mouse_can_use_global_state = true;
463#endif
464
465 // Setup backend capabilities flags
467 io.BackendPlatformUserData = (void*)bd;
468 io.BackendPlatformName = "imgui_impl_sdl2";
469 io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional)
470 io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used)
471 if (mouse_can_use_global_state)
472 io.BackendFlags |= ImGuiBackendFlags_PlatformHasViewports; // We can create multi-viewports on the Platform side (optional)
473
474 bd->Window = window;
475 bd->Renderer = renderer;
476
477 // SDL on Linux/OSX doesn't report events for unfocused windows (see https://github.com/ocornut/imgui/issues/4960)
478 // We will use 'MouseCanReportHoveredViewport' to set 'ImGuiBackendFlags_HasMouseHoveredViewport' dynamically each frame.
479 bd->MouseCanUseGlobalState = mouse_can_use_global_state;
480#ifndef __APPLE__
482#else
484#endif
485 bd->WantUpdateMonitors = true;
486
487 io.SetClipboardTextFn = ImGui_ImplSDL2_SetClipboardText;
488 io.GetClipboardTextFn = ImGui_ImplSDL2_GetClipboardText;
489 io.ClipboardUserData = nullptr;
490 io.SetPlatformImeDataFn = ImGui_ImplSDL2_SetPlatformImeData;
491
492 // Gamepad handling
493 bd->GamepadMode = ImGui_ImplSDL2_GamepadMode_AutoFirst;
494 bd->WantUpdateGamepadsList = true;
495
496 // Load mouse cursors
497 bd->MouseCursors[ImGuiMouseCursor_Arrow] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
498 bd->MouseCursors[ImGuiMouseCursor_TextInput] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_IBEAM);
499 bd->MouseCursors[ImGuiMouseCursor_ResizeAll] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEALL);
500 bd->MouseCursors[ImGuiMouseCursor_ResizeNS] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENS);
501 bd->MouseCursors[ImGuiMouseCursor_ResizeEW] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEWE);
502 bd->MouseCursors[ImGuiMouseCursor_ResizeNESW] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENESW);
503 bd->MouseCursors[ImGuiMouseCursor_ResizeNWSE] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENWSE);
504 bd->MouseCursors[ImGuiMouseCursor_Hand] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_HAND);
505 bd->MouseCursors[ImGuiMouseCursor_NotAllowed] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NO);
506
507 // Set platform dependent data in viewport
508 // Our mouse update function expect PlatformHandle to be filled for the main viewport
509 ImGuiViewport* main_viewport = ImGui::GetMainViewport();
510 main_viewport->PlatformHandle = (void*)window;
511 main_viewport->PlatformHandleRaw = nullptr;
512 SDL_SysWMinfo info;
513 SDL_VERSION(&info.version);
514 if (SDL_GetWindowWMInfo(window, &info))
515 {
516#if defined(SDL_VIDEO_DRIVER_WINDOWS)
517 main_viewport->PlatformHandleRaw = (void*)info.info.win.window;
518#elif defined(__APPLE__) && defined(SDL_VIDEO_DRIVER_COCOA)
519 main_viewport->PlatformHandleRaw = (void*)info.info.cocoa.window;
520#endif
521 }
522
523 // From 2.0.5: Set SDL hint to receive mouse click events on window focus, otherwise SDL doesn't emit the event.
524 // Without this, when clicking to gain focus, our widgets wouldn't activate even though they showed as hovered.
525 // (This is unfortunately a global SDL setting, so enabling it might have a side-effect on your application.
526 // It is unlikely to make a difference, but if your app absolutely needs to ignore the initial on-focus click:
527 // you can ignore SDL_MOUSEBUTTONDOWN events coming right after a SDL_WINDOWEVENT_FOCUS_GAINED)
528#ifdef SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH
529 SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1");
530#endif
531
532 // From 2.0.18: Enable native IME.
533 // IMPORTANT: This is used at the time of SDL_CreateWindow() so this will only affects secondary windows, if any.
534 // For the main window to be affected, your application needs to call this manually before calling SDL_CreateWindow().
535#ifdef SDL_HINT_IME_SHOW_UI
536 SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1");
537#endif
538
539 // From 2.0.22: Disable auto-capture, this is preventing drag and drop across multiple windows (see #5710)
540#ifdef SDL_HINT_MOUSE_AUTO_CAPTURE
541 SDL_SetHint(SDL_HINT_MOUSE_AUTO_CAPTURE, "0");
542#endif
543
544 // We need SDL_CaptureMouse(), SDL_GetGlobalMouseState() from SDL 2.0.4+ to support multiple viewports.
545 // We left the call to ImGui_ImplSDL2_InitPlatformInterface() outside of #ifdef to avoid unused-function warnings.
546 if ((io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) && (io.BackendFlags & ImGuiBackendFlags_PlatformHasViewports))
547 ImGui_ImplSDL2_InitPlatformInterface(window, sdl_gl_context);
548
549 return true;
550}
551
552bool ImGui_ImplSDL2_InitForOpenGL(SDL_Window* window, void* sdl_gl_context)
553{
554 return ImGui_ImplSDL2_Init(window, nullptr, sdl_gl_context);
555}
556
557bool ImGui_ImplSDL2_InitForVulkan(SDL_Window* window)
558{
559#if !SDL_HAS_VULKAN
560 IM_ASSERT(0 && "Unsupported");
561#endif
562 if (!ImGui_ImplSDL2_Init(window, nullptr, nullptr))
563 return false;
564 ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
565 bd->UseVulkan = true;
566 return true;
567}
568
569bool ImGui_ImplSDL2_InitForD3D(SDL_Window* window)
570{
571#if !defined(_WIN32)
572 IM_ASSERT(0 && "Unsupported");
573#endif
574 return ImGui_ImplSDL2_Init(window, nullptr, nullptr);
575}
576
577bool ImGui_ImplSDL2_InitForMetal(SDL_Window* window)
578{
579 return ImGui_ImplSDL2_Init(window, nullptr, nullptr);
580}
581
582bool ImGui_ImplSDL2_InitForSDLRenderer(SDL_Window* window, SDL_Renderer* renderer)
583{
584 return ImGui_ImplSDL2_Init(window, renderer, nullptr);
585}
586
587bool ImGui_ImplSDL2_InitForOther(SDL_Window* window)
588{
589 return ImGui_ImplSDL2_Init(window, nullptr, nullptr);
590}
591
592static void ImGui_ImplSDL2_CloseGamepads();
593
595{
596 ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
597 IM_ASSERT(bd != nullptr && "No platform backend to shutdown, or already shutdown?");
598 ImGuiIO& io = ImGui::GetIO();
599
600 ImGui_ImplSDL2_ShutdownPlatformInterface();
601
602 if (bd->ClipboardTextData)
603 SDL_free(bd->ClipboardTextData);
604 for (ImGuiMouseCursor cursor_n = 0; cursor_n < ImGuiMouseCursor_COUNT; cursor_n++)
605 SDL_FreeCursor(bd->MouseCursors[cursor_n]);
606 ImGui_ImplSDL2_CloseGamepads();
607
608 io.BackendPlatformName = nullptr;
609 io.BackendPlatformUserData = nullptr;
610 io.BackendFlags &= ~(ImGuiBackendFlags_HasMouseCursors | ImGuiBackendFlags_HasSetMousePos | ImGuiBackendFlags_HasGamepad | ImGuiBackendFlags_PlatformHasViewports | ImGuiBackendFlags_HasMouseHoveredViewport);
611 IM_DELETE(bd);
612}
613
614// This code is incredibly messy because some of the functions we need for full viewport support are not available in SDL < 2.0.4.
615static void ImGui_ImplSDL2_UpdateMouseData()
616{
617 ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
618 ImGuiIO& io = ImGui::GetIO();
619
620 // We forward mouse input when hovered or captured (via SDL_MOUSEMOTION) or when focused (below)
621#if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE
622 // SDL_CaptureMouse() let the OS know e.g. that our imgui drag outside the SDL window boundaries shouldn't e.g. trigger other operations outside
623 SDL_CaptureMouse((bd->MouseButtonsDown != 0) ? SDL_TRUE : SDL_FALSE);
624 SDL_Window* focused_window = SDL_GetKeyboardFocus();
625 const bool is_app_focused = (focused_window && (bd->Window == focused_window || ImGui::FindViewportByPlatformHandle((void*)focused_window)));
626#else
627 SDL_Window* focused_window = bd->Window;
628 const bool is_app_focused = (SDL_GetWindowFlags(bd->Window) & SDL_WINDOW_INPUT_FOCUS) != 0; // SDL 2.0.3 and non-windowed systems: single-viewport only
629#endif
630
631 if (is_app_focused)
632 {
633 // (Optional) Set OS mouse position from Dear ImGui if requested (rarely used, only when ImGuiConfigFlags_NavEnableSetMousePos is enabled by user)
634 if (io.WantSetMousePos)
635 {
636#if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE
637 if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
638 SDL_WarpMouseGlobal((int)io.MousePos.x, (int)io.MousePos.y);
639 else
640#endif
641 SDL_WarpMouseInWindow(bd->Window, (int)io.MousePos.x, (int)io.MousePos.y);
642 }
643
644 // (Optional) Fallback to provide mouse position when focused (SDL_MOUSEMOTION already provides this when hovered or captured)
645 if (bd->MouseCanUseGlobalState && bd->MouseButtonsDown == 0)
646 {
647 // Single-viewport mode: mouse position in client window coordinates (io.MousePos is (0,0) when the mouse is on the upper-left corner of the app window)
648 // Multi-viewport mode: mouse position in OS absolute coordinates (io.MousePos is (0,0) when the mouse is on the upper-left of the primary monitor)
649 int mouse_x, mouse_y, window_x, window_y;
650 SDL_GetGlobalMouseState(&mouse_x, &mouse_y);
651 if (!(io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable))
652 {
653 SDL_GetWindowPosition(focused_window, &window_x, &window_y);
654 mouse_x -= window_x;
655 mouse_y -= window_y;
656 }
657 io.AddMousePosEvent((float)mouse_x, (float)mouse_y);
658 }
659 }
660
661 // (Optional) When using multiple viewports: call io.AddMouseViewportEvent() with the viewport the OS mouse cursor is hovering.
662 // If ImGuiBackendFlags_HasMouseHoveredViewport is not set by the backend, Dear imGui will ignore this field and infer the information using its flawed heuristic.
663 // - [!] SDL backend does NOT correctly ignore viewports with the _NoInputs flag.
664 // Some backend are not able to handle that correctly. If a backend report an hovered viewport that has the _NoInputs flag (e.g. when dragging a window
665 // for docking, the viewport has the _NoInputs flag in order to allow us to find the viewport under), then Dear ImGui is forced to ignore the value reported
666 // by the backend, and use its flawed heuristic to guess the viewport behind.
667 // - [X] SDL backend correctly reports this regardless of another viewport behind focused and dragged from (we need this to find a useful drag and drop target).
668 if (io.BackendFlags & ImGuiBackendFlags_HasMouseHoveredViewport)
669 {
670 ImGuiID mouse_viewport_id = 0;
671 if (SDL_Window* sdl_mouse_window = SDL_GetWindowFromID(bd->MouseWindowID))
672 if (ImGuiViewport* mouse_viewport = ImGui::FindViewportByPlatformHandle((void*)sdl_mouse_window))
673 mouse_viewport_id = mouse_viewport->ID;
674 io.AddMouseViewportEvent(mouse_viewport_id);
675 }
676}
677
678static void ImGui_ImplSDL2_UpdateMouseCursor()
679{
680 ImGuiIO& io = ImGui::GetIO();
681 if (io.ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange)
682 return;
683 ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
684
685 ImGuiMouseCursor imgui_cursor = ImGui::GetMouseCursor();
686 if (io.MouseDrawCursor || imgui_cursor == ImGuiMouseCursor_None)
687 {
688 // Hide OS mouse cursor if imgui is drawing it or if it wants no cursor
689 SDL_ShowCursor(SDL_FALSE);
690 }
691 else
692 {
693 // Show OS mouse cursor
694 SDL_Cursor* expected_cursor = bd->MouseCursors[imgui_cursor] ? bd->MouseCursors[imgui_cursor] : bd->MouseCursors[ImGuiMouseCursor_Arrow];
695 if (bd->MouseLastCursor != expected_cursor)
696 {
697 SDL_SetCursor(expected_cursor); // SDL function doesn't have an early out (see #6113)
698 bd->MouseLastCursor = expected_cursor;
699 }
700 SDL_ShowCursor(SDL_TRUE);
701 }
702}
703
704static void ImGui_ImplSDL2_CloseGamepads()
705{
706 ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
707 if (bd->GamepadMode != ImGui_ImplSDL2_GamepadMode_Manual)
708 for (SDL_GameController* gamepad : bd->Gamepads)
709 SDL_GameControllerClose(gamepad);
710 bd->Gamepads.resize(0);
711}
712
713void ImGui_ImplSDL2_SetGamepadMode(ImGui_ImplSDL2_GamepadMode mode, struct _SDL_GameController** manual_gamepads_array, int manual_gamepads_count)
714{
715 ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
716 ImGui_ImplSDL2_CloseGamepads();
717 if (mode == ImGui_ImplSDL2_GamepadMode_Manual)
718 {
719 IM_ASSERT(manual_gamepads_array != nullptr && manual_gamepads_count > 0);
720 for (int n = 0; n < manual_gamepads_count; n++)
721 bd->Gamepads.push_back(manual_gamepads_array[n]);
722 }
723 else
724 {
725 IM_ASSERT(manual_gamepads_array == nullptr && manual_gamepads_count <= 0);
726 bd->WantUpdateGamepadsList = true;
727 }
728 bd->GamepadMode = mode;
729}
730
731static void ImGui_ImplSDL2_UpdateGamepadButton(ImGui_ImplSDL2_Data* bd, ImGuiIO& io, ImGuiKey key, SDL_GameControllerButton button_no)
732{
733 bool merged_value = false;
734 for (SDL_GameController* gamepad : bd->Gamepads)
735 merged_value |= SDL_GameControllerGetButton(gamepad, button_no) != 0;
736 io.AddKeyEvent(key, merged_value);
737}
738
739static inline float Saturate(float v) { return v < 0.0f ? 0.0f : v > 1.0f ? 1.0f : v; }
740static void ImGui_ImplSDL2_UpdateGamepadAnalog(ImGui_ImplSDL2_Data* bd, ImGuiIO& io, ImGuiKey key, SDL_GameControllerAxis axis_no, float v0, float v1)
741{
742 float merged_value = 0.0f;
743 for (SDL_GameController* gamepad : bd->Gamepads)
744 {
745 float vn = Saturate((float)(SDL_GameControllerGetAxis(gamepad, axis_no) - v0) / (float)(v1 - v0));
746 if (merged_value < vn)
747 merged_value = vn;
748 }
749 io.AddKeyAnalogEvent(key, merged_value > 0.1f, merged_value);
750}
751
752static void ImGui_ImplSDL2_UpdateGamepads()
753{
754 ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
755 ImGuiIO& io = ImGui::GetIO();
756
757 // Update list of controller(s) to use
758 if (bd->WantUpdateGamepadsList && bd->GamepadMode != ImGui_ImplSDL2_GamepadMode_Manual)
759 {
760 ImGui_ImplSDL2_CloseGamepads();
761 int joystick_count = SDL_NumJoysticks();
762 for (int n = 0; n < joystick_count; n++)
763 if (SDL_IsGameController(n))
764 if (SDL_GameController* gamepad = SDL_GameControllerOpen(n))
765 {
766 bd->Gamepads.push_back(gamepad);
767 if (bd->GamepadMode == ImGui_ImplSDL2_GamepadMode_AutoFirst)
768 break;
769 }
770 bd->WantUpdateGamepadsList = false;
771 }
772
773 // FIXME: Technically feeding gamepad shouldn't depend on this now that they are regular inputs.
774 if ((io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) == 0)
775 return;
776 io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad;
777 if (bd->Gamepads.Size == 0)
778 return;
779 io.BackendFlags |= ImGuiBackendFlags_HasGamepad;
780
781 // Update gamepad inputs
782 const int thumb_dead_zone = 8000; // SDL_gamecontroller.h suggests using this value.
783 ImGui_ImplSDL2_UpdateGamepadButton(bd, io, ImGuiKey_GamepadStart, SDL_CONTROLLER_BUTTON_START);
784 ImGui_ImplSDL2_UpdateGamepadButton(bd, io, ImGuiKey_GamepadBack, SDL_CONTROLLER_BUTTON_BACK);
785 ImGui_ImplSDL2_UpdateGamepadButton(bd, io, ImGuiKey_GamepadFaceLeft, SDL_CONTROLLER_BUTTON_X); // Xbox X, PS Square
786 ImGui_ImplSDL2_UpdateGamepadButton(bd, io, ImGuiKey_GamepadFaceRight, SDL_CONTROLLER_BUTTON_B); // Xbox B, PS Circle
787 ImGui_ImplSDL2_UpdateGamepadButton(bd, io, ImGuiKey_GamepadFaceUp, SDL_CONTROLLER_BUTTON_Y); // Xbox Y, PS Triangle
788 ImGui_ImplSDL2_UpdateGamepadButton(bd, io, ImGuiKey_GamepadFaceDown, SDL_CONTROLLER_BUTTON_A); // Xbox A, PS Cross
789 ImGui_ImplSDL2_UpdateGamepadButton(bd, io, ImGuiKey_GamepadDpadLeft, SDL_CONTROLLER_BUTTON_DPAD_LEFT);
790 ImGui_ImplSDL2_UpdateGamepadButton(bd, io, ImGuiKey_GamepadDpadRight, SDL_CONTROLLER_BUTTON_DPAD_RIGHT);
791 ImGui_ImplSDL2_UpdateGamepadButton(bd, io, ImGuiKey_GamepadDpadUp, SDL_CONTROLLER_BUTTON_DPAD_UP);
792 ImGui_ImplSDL2_UpdateGamepadButton(bd, io, ImGuiKey_GamepadDpadDown, SDL_CONTROLLER_BUTTON_DPAD_DOWN);
793 ImGui_ImplSDL2_UpdateGamepadButton(bd, io, ImGuiKey_GamepadL1, SDL_CONTROLLER_BUTTON_LEFTSHOULDER);
794 ImGui_ImplSDL2_UpdateGamepadButton(bd, io, ImGuiKey_GamepadR1, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER);
795 ImGui_ImplSDL2_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadL2, SDL_CONTROLLER_AXIS_TRIGGERLEFT, 0.0f, 32767);
796 ImGui_ImplSDL2_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadR2, SDL_CONTROLLER_AXIS_TRIGGERRIGHT, 0.0f, 32767);
797 ImGui_ImplSDL2_UpdateGamepadButton(bd, io, ImGuiKey_GamepadL3, SDL_CONTROLLER_BUTTON_LEFTSTICK);
798 ImGui_ImplSDL2_UpdateGamepadButton(bd, io, ImGuiKey_GamepadR3, SDL_CONTROLLER_BUTTON_RIGHTSTICK);
799 ImGui_ImplSDL2_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadLStickLeft, SDL_CONTROLLER_AXIS_LEFTX, -thumb_dead_zone, -32768);
800 ImGui_ImplSDL2_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadLStickRight, SDL_CONTROLLER_AXIS_LEFTX, +thumb_dead_zone, +32767);
801 ImGui_ImplSDL2_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadLStickUp, SDL_CONTROLLER_AXIS_LEFTY, -thumb_dead_zone, -32768);
802 ImGui_ImplSDL2_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadLStickDown, SDL_CONTROLLER_AXIS_LEFTY, +thumb_dead_zone, +32767);
803 ImGui_ImplSDL2_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadRStickLeft, SDL_CONTROLLER_AXIS_RIGHTX, -thumb_dead_zone, -32768);
804 ImGui_ImplSDL2_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadRStickRight, SDL_CONTROLLER_AXIS_RIGHTX, +thumb_dead_zone, +32767);
805 ImGui_ImplSDL2_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadRStickUp, SDL_CONTROLLER_AXIS_RIGHTY, -thumb_dead_zone, -32768);
806 ImGui_ImplSDL2_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadRStickDown, SDL_CONTROLLER_AXIS_RIGHTY, +thumb_dead_zone, +32767);
807}
808
809// FIXME: Note that doesn't update with DPI/Scaling change only as SDL2 doesn't have an event for it (SDL3 has).
810static void ImGui_ImplSDL2_UpdateMonitors()
811{
812 ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
813 ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
814 platform_io.Monitors.resize(0);
815 bd->WantUpdateMonitors = false;
816 int display_count = SDL_GetNumVideoDisplays();
817 for (int n = 0; n < display_count; n++)
818 {
819 // Warning: the validity of monitor DPI information on Windows depends on the application DPI awareness settings, which generally needs to be set in the manifest or at runtime.
820 ImGuiPlatformMonitor monitor;
821 SDL_Rect r;
822 SDL_GetDisplayBounds(n, &r);
823 monitor.MainPos = monitor.WorkPos = ImVec2((float)r.x, (float)r.y);
824 monitor.MainSize = monitor.WorkSize = ImVec2((float)r.w, (float)r.h);
825#if SDL_HAS_USABLE_DISPLAY_BOUNDS
826 SDL_GetDisplayUsableBounds(n, &r);
827 monitor.WorkPos = ImVec2((float)r.x, (float)r.y);
828 monitor.WorkSize = ImVec2((float)r.w, (float)r.h);
829#endif
830#if SDL_HAS_PER_MONITOR_DPI
831 // FIXME-VIEWPORT: On MacOS SDL reports actual monitor DPI scale, ignoring OS configuration. We may want to set
832 // DpiScale to cocoa_window.backingScaleFactor here.
833 float dpi = 0.0f;
834 if (!SDL_GetDisplayDPI(n, &dpi, nullptr, nullptr))
835 monitor.DpiScale = dpi / 96.0f;
836#endif
837 monitor.PlatformHandle = (void*)(intptr_t)n;
838 platform_io.Monitors.push_back(monitor);
839 }
840}
841
843{
844 ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
845 IM_ASSERT(bd != nullptr && "Context or backend not initialized! Did you call ImGui_ImplSDL2_Init()?");
846 ImGuiIO& io = ImGui::GetIO();
847
848 // Setup display size (every frame to accommodate for window resizing)
849 int w, h;
850 int display_w, display_h;
851 SDL_GetWindowSize(bd->Window, &w, &h);
852 if (SDL_GetWindowFlags(bd->Window) & SDL_WINDOW_MINIMIZED)
853 w = h = 0;
854 if (bd->Renderer != nullptr)
855 SDL_GetRendererOutputSize(bd->Renderer, &display_w, &display_h);
856 else
857 SDL_GL_GetDrawableSize(bd->Window, &display_w, &display_h);
858 io.DisplaySize = ImVec2((float)w, (float)h);
859 if (w > 0 && h > 0)
860 io.DisplayFramebufferScale = ImVec2((float)display_w / w, (float)display_h / h);
861
862 // Update monitors
863 if (bd->WantUpdateMonitors)
864 ImGui_ImplSDL2_UpdateMonitors();
865
866 // Setup time step (we don't use SDL_GetTicks() because it is using millisecond resolution)
867 // (Accept SDL_GetPerformanceCounter() not returning a monotonically increasing value. Happens in VMs and Emscripten, see #6189, #6114, #3644)
868 static Uint64 frequency = SDL_GetPerformanceFrequency();
869 Uint64 current_time = SDL_GetPerformanceCounter();
870 if (current_time <= bd->Time)
871 current_time = bd->Time + 1;
872 io.DeltaTime = bd->Time > 0 ? (float)((double)(current_time - bd->Time) / frequency) : (float)(1.0f / 60.0f);
873 bd->Time = current_time;
874
875 if (bd->MouseLastLeaveFrame && bd->MouseLastLeaveFrame >= ImGui::GetFrameCount() && bd->MouseButtonsDown == 0)
876 {
877 bd->MouseWindowID = 0;
878 bd->MouseLastLeaveFrame = 0;
879 io.AddMousePosEvent(-FLT_MAX, -FLT_MAX);
880 }
881
882 // Our io.AddMouseViewportEvent() calls will only be valid when not capturing.
883 // Technically speaking testing for 'bd->MouseButtonsDown == 0' would be more rygorous, but testing for payload reduces noise and potential side-effects.
884 if (bd->MouseCanReportHoveredViewport && ImGui::GetDragDropPayload() == nullptr)
885 io.BackendFlags |= ImGuiBackendFlags_HasMouseHoveredViewport;
886 else
887 io.BackendFlags &= ~ImGuiBackendFlags_HasMouseHoveredViewport;
888
889 ImGui_ImplSDL2_UpdateMouseData();
890 ImGui_ImplSDL2_UpdateMouseCursor();
891
892 // Update game controllers (if enabled and available)
893 ImGui_ImplSDL2_UpdateGamepads();
894}
895
896//--------------------------------------------------------------------------------------------------------
897// MULTI-VIEWPORT / PLATFORM INTERFACE SUPPORT
898// This is an _advanced_ and _optional_ feature, allowing the backend to create and handle multiple viewports simultaneously.
899// If you are new to dear imgui or creating a new binding for dear imgui, it is recommended that you completely ignore this section first..
900//--------------------------------------------------------------------------------------------------------
901
902// Helper structure we store in the void* RendererUserData field of each ImGuiViewport to easily retrieve our backend data.
904{
905 SDL_Window* Window;
906 Uint32 WindowID;
908 SDL_GLContext GLContext;
909
910 ImGui_ImplSDL2_ViewportData() { Window = nullptr; WindowID = 0; WindowOwned = false; GLContext = nullptr; }
911 ~ImGui_ImplSDL2_ViewportData() { IM_ASSERT(Window == nullptr && GLContext == nullptr); }
912};
913
914static void ImGui_ImplSDL2_CreateWindow(ImGuiViewport* viewport)
915{
916 ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
918 viewport->PlatformUserData = vd;
919
920 ImGuiViewport* main_viewport = ImGui::GetMainViewport();
921 ImGui_ImplSDL2_ViewportData* main_viewport_data = (ImGui_ImplSDL2_ViewportData*)main_viewport->PlatformUserData;
922
923 // Share GL resources with main context
924 bool use_opengl = (main_viewport_data->GLContext != nullptr);
925 SDL_GLContext backup_context = nullptr;
926 if (use_opengl)
927 {
928 backup_context = SDL_GL_GetCurrentContext();
929 SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);
930 SDL_GL_MakeCurrent(main_viewport_data->Window, main_viewport_data->GLContext);
931 }
932
933 Uint32 sdl_flags = 0;
934 sdl_flags |= use_opengl ? SDL_WINDOW_OPENGL : (bd->UseVulkan ? SDL_WINDOW_VULKAN : 0);
935 sdl_flags |= SDL_GetWindowFlags(bd->Window) & SDL_WINDOW_ALLOW_HIGHDPI;
936 sdl_flags |= SDL_WINDOW_HIDDEN;
937 sdl_flags |= (viewport->Flags & ImGuiViewportFlags_NoDecoration) ? SDL_WINDOW_BORDERLESS : 0;
938 sdl_flags |= (viewport->Flags & ImGuiViewportFlags_NoDecoration) ? 0 : SDL_WINDOW_RESIZABLE;
939#if !defined(_WIN32)
940 // See SDL hack in ImGui_ImplSDL2_ShowWindow().
941 sdl_flags |= (viewport->Flags & ImGuiViewportFlags_NoTaskBarIcon) ? SDL_WINDOW_SKIP_TASKBAR : 0;
942#endif
943#if SDL_HAS_ALWAYS_ON_TOP
944 sdl_flags |= (viewport->Flags & ImGuiViewportFlags_TopMost) ? SDL_WINDOW_ALWAYS_ON_TOP : 0;
945#endif
946 vd->Window = SDL_CreateWindow("No Title Yet", (int)viewport->Pos.x, (int)viewport->Pos.y, (int)viewport->Size.x, (int)viewport->Size.y, sdl_flags);
947 vd->WindowOwned = true;
948 if (use_opengl)
949 {
950 vd->GLContext = SDL_GL_CreateContext(vd->Window);
951 SDL_GL_SetSwapInterval(0);
952 }
953 if (use_opengl && backup_context)
954 SDL_GL_MakeCurrent(vd->Window, backup_context);
955
956 viewport->PlatformHandle = (void*)vd->Window;
957 viewport->PlatformHandleRaw = nullptr;
958 SDL_SysWMinfo info;
959 SDL_VERSION(&info.version);
960 if (SDL_GetWindowWMInfo(vd->Window, &info))
961 {
962#if defined(SDL_VIDEO_DRIVER_WINDOWS)
963 viewport->PlatformHandleRaw = info.info.win.window;
964#elif defined(__APPLE__) && defined(SDL_VIDEO_DRIVER_COCOA)
965 viewport->PlatformHandleRaw = (void*)info.info.cocoa.window;
966#endif
967 }
968}
969
970static void ImGui_ImplSDL2_DestroyWindow(ImGuiViewport* viewport)
971{
972 if (ImGui_ImplSDL2_ViewportData* vd = (ImGui_ImplSDL2_ViewportData*)viewport->PlatformUserData)
973 {
974 if (vd->GLContext && vd->WindowOwned)
975 SDL_GL_DeleteContext(vd->GLContext);
976 if (vd->Window && vd->WindowOwned)
977 SDL_DestroyWindow(vd->Window);
978 vd->GLContext = nullptr;
979 vd->Window = nullptr;
980 IM_DELETE(vd);
981 }
982 viewport->PlatformUserData = viewport->PlatformHandle = nullptr;
983}
984
985static void ImGui_ImplSDL2_ShowWindow(ImGuiViewport* viewport)
986{
987 ImGui_ImplSDL2_ViewportData* vd = (ImGui_ImplSDL2_ViewportData*)viewport->PlatformUserData;
988#if defined(_WIN32)
989 HWND hwnd = (HWND)viewport->PlatformHandleRaw;
990
991 // SDL hack: Hide icon from task bar
992 // Note: SDL 2.0.6+ has a SDL_WINDOW_SKIP_TASKBAR flag which is supported under Windows but the way it create the window breaks our seamless transition.
993 if (viewport->Flags & ImGuiViewportFlags_NoTaskBarIcon)
994 {
995 LONG ex_style = ::GetWindowLong(hwnd, GWL_EXSTYLE);
996 ex_style &= ~WS_EX_APPWINDOW;
997 ex_style |= WS_EX_TOOLWINDOW;
998 ::SetWindowLong(hwnd, GWL_EXSTYLE, ex_style);
999 }
1000
1001 // SDL hack: SDL always activate/focus windows :/
1002 if (viewport->Flags & ImGuiViewportFlags_NoFocusOnAppearing)
1003 {
1004 ::ShowWindow(hwnd, SW_SHOWNA);
1005 return;
1006 }
1007#endif
1008
1009 SDL_ShowWindow(vd->Window);
1010}
1011
1012static ImVec2 ImGui_ImplSDL2_GetWindowPos(ImGuiViewport* viewport)
1013{
1014 ImGui_ImplSDL2_ViewportData* vd = (ImGui_ImplSDL2_ViewportData*)viewport->PlatformUserData;
1015 int x = 0, y = 0;
1016 SDL_GetWindowPosition(vd->Window, &x, &y);
1017 return ImVec2((float)x, (float)y);
1018}
1019
1020static void ImGui_ImplSDL2_SetWindowPos(ImGuiViewport* viewport, ImVec2 pos)
1021{
1022 ImGui_ImplSDL2_ViewportData* vd = (ImGui_ImplSDL2_ViewportData*)viewport->PlatformUserData;
1023 SDL_SetWindowPosition(vd->Window, (int)pos.x, (int)pos.y);
1024}
1025
1026static ImVec2 ImGui_ImplSDL2_GetWindowSize(ImGuiViewport* viewport)
1027{
1028 ImGui_ImplSDL2_ViewportData* vd = (ImGui_ImplSDL2_ViewportData*)viewport->PlatformUserData;
1029 int w = 0, h = 0;
1030 SDL_GetWindowSize(vd->Window, &w, &h);
1031 return ImVec2((float)w, (float)h);
1032}
1033
1034static void ImGui_ImplSDL2_SetWindowSize(ImGuiViewport* viewport, ImVec2 size)
1035{
1036 ImGui_ImplSDL2_ViewportData* vd = (ImGui_ImplSDL2_ViewportData*)viewport->PlatformUserData;
1037 SDL_SetWindowSize(vd->Window, (int)size.x, (int)size.y);
1038}
1039
1040static void ImGui_ImplSDL2_SetWindowTitle(ImGuiViewport* viewport, const char* title)
1041{
1042 ImGui_ImplSDL2_ViewportData* vd = (ImGui_ImplSDL2_ViewportData*)viewport->PlatformUserData;
1043 SDL_SetWindowTitle(vd->Window, title);
1044}
1045
1046#if SDL_HAS_WINDOW_ALPHA
1047static void ImGui_ImplSDL2_SetWindowAlpha(ImGuiViewport* viewport, float alpha)
1048{
1049 ImGui_ImplSDL2_ViewportData* vd = (ImGui_ImplSDL2_ViewportData*)viewport->PlatformUserData;
1050 SDL_SetWindowOpacity(vd->Window, alpha);
1051}
1052#endif
1053
1054static void ImGui_ImplSDL2_SetWindowFocus(ImGuiViewport* viewport)
1055{
1056 ImGui_ImplSDL2_ViewportData* vd = (ImGui_ImplSDL2_ViewportData*)viewport->PlatformUserData;
1057 SDL_RaiseWindow(vd->Window);
1058}
1059
1060static bool ImGui_ImplSDL2_GetWindowFocus(ImGuiViewport* viewport)
1061{
1062 ImGui_ImplSDL2_ViewportData* vd = (ImGui_ImplSDL2_ViewportData*)viewport->PlatformUserData;
1063 return (SDL_GetWindowFlags(vd->Window) & SDL_WINDOW_INPUT_FOCUS) != 0;
1064}
1065
1066static bool ImGui_ImplSDL2_GetWindowMinimized(ImGuiViewport* viewport)
1067{
1068 ImGui_ImplSDL2_ViewportData* vd = (ImGui_ImplSDL2_ViewportData*)viewport->PlatformUserData;
1069 return (SDL_GetWindowFlags(vd->Window) & SDL_WINDOW_MINIMIZED) != 0;
1070}
1071
1072static void ImGui_ImplSDL2_RenderWindow(ImGuiViewport* viewport, void*)
1073{
1074 ImGui_ImplSDL2_ViewportData* vd = (ImGui_ImplSDL2_ViewportData*)viewport->PlatformUserData;
1075 if (vd->GLContext)
1076 SDL_GL_MakeCurrent(vd->Window, vd->GLContext);
1077}
1078
1079static void ImGui_ImplSDL2_SwapBuffers(ImGuiViewport* viewport, void*)
1080{
1081 ImGui_ImplSDL2_ViewportData* vd = (ImGui_ImplSDL2_ViewportData*)viewport->PlatformUserData;
1082 if (vd->GLContext)
1083 {
1084 SDL_GL_MakeCurrent(vd->Window, vd->GLContext);
1085 SDL_GL_SwapWindow(vd->Window);
1086 }
1087}
1088
1089// Vulkan support (the Vulkan renderer needs to call a platform-side support function to create the surface)
1090// SDL is graceful enough to _not_ need <vulkan/vulkan.h> so we can safely include this.
1091#if SDL_HAS_VULKAN
1092#include <SDL_vulkan.h>
1093static int ImGui_ImplSDL2_CreateVkSurface(ImGuiViewport* viewport, ImU64 vk_instance, const void* vk_allocator, ImU64* out_vk_surface)
1094{
1095 ImGui_ImplSDL2_ViewportData* vd = (ImGui_ImplSDL2_ViewportData*)viewport->PlatformUserData;
1096 (void)vk_allocator;
1097 SDL_bool ret = SDL_Vulkan_CreateSurface(vd->Window, (VkInstance)vk_instance, (VkSurfaceKHR*)out_vk_surface);
1098 return ret ? 0 : 1; // ret ? VK_SUCCESS : VK_NOT_READY
1099}
1100#endif // SDL_HAS_VULKAN
1101
1102static void ImGui_ImplSDL2_InitPlatformInterface(SDL_Window* window, void* sdl_gl_context)
1103{
1104 // Register platform interface (will be coupled with a renderer interface)
1105 ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
1106 platform_io.Platform_CreateWindow = ImGui_ImplSDL2_CreateWindow;
1107 platform_io.Platform_DestroyWindow = ImGui_ImplSDL2_DestroyWindow;
1108 platform_io.Platform_ShowWindow = ImGui_ImplSDL2_ShowWindow;
1109 platform_io.Platform_SetWindowPos = ImGui_ImplSDL2_SetWindowPos;
1110 platform_io.Platform_GetWindowPos = ImGui_ImplSDL2_GetWindowPos;
1111 platform_io.Platform_SetWindowSize = ImGui_ImplSDL2_SetWindowSize;
1112 platform_io.Platform_GetWindowSize = ImGui_ImplSDL2_GetWindowSize;
1113 platform_io.Platform_SetWindowFocus = ImGui_ImplSDL2_SetWindowFocus;
1114 platform_io.Platform_GetWindowFocus = ImGui_ImplSDL2_GetWindowFocus;
1115 platform_io.Platform_GetWindowMinimized = ImGui_ImplSDL2_GetWindowMinimized;
1116 platform_io.Platform_SetWindowTitle = ImGui_ImplSDL2_SetWindowTitle;
1117 platform_io.Platform_RenderWindow = ImGui_ImplSDL2_RenderWindow;
1118 platform_io.Platform_SwapBuffers = ImGui_ImplSDL2_SwapBuffers;
1119#if SDL_HAS_WINDOW_ALPHA
1120 platform_io.Platform_SetWindowAlpha = ImGui_ImplSDL2_SetWindowAlpha;
1121#endif
1122#if SDL_HAS_VULKAN
1123 platform_io.Platform_CreateVkSurface = ImGui_ImplSDL2_CreateVkSurface;
1124#endif
1125
1126 // Register main window handle (which is owned by the main application, not by us)
1127 // This is mostly for simplicity and consistency, so that our code (e.g. mouse handling etc.) can use same logic for main and secondary viewports.
1128 ImGuiViewport* main_viewport = ImGui::GetMainViewport();
1130 vd->Window = window;
1131 vd->WindowID = SDL_GetWindowID(window);
1132 vd->WindowOwned = false;
1133 vd->GLContext = sdl_gl_context;
1134 main_viewport->PlatformUserData = vd;
1135 main_viewport->PlatformHandle = vd->Window;
1136}
1137
1138static void ImGui_ImplSDL2_ShutdownPlatformInterface()
1139{
1140 ImGui::DestroyPlatformWindows();
1141}
1142
1143//-----------------------------------------------------------------------------
1144
1145#if defined(__clang__)
1146#pragma clang diagnostic pop
1147#endif
1148
1149#endif // #ifndef IMGUI_DISABLE
void ImGui_ImplSDL2_SetGamepadMode(ImGui_ImplSDL2_GamepadMode mode, struct _SDL_GameController **manual_gamepads_array, int manual_gamepads_count)
bool ImGui_ImplSDL2_InitForVulkan(SDL_Window *window)
bool ImGui_ImplSDL2_InitForSDLRenderer(SDL_Window *window, SDL_Renderer *renderer)
bool ImGui_ImplSDL2_InitForOpenGL(SDL_Window *window, void *sdl_gl_context)
bool ImGui_ImplSDL2_InitForOther(SDL_Window *window)
bool ImGui_ImplSDL2_InitForMetal(SDL_Window *window)
void ImGui_ImplSDL2_NewFrame()
bool ImGui_ImplSDL2_InitForD3D(SDL_Window *window)
bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event *event)
void ImGui_ImplSDL2_Shutdown()
size_t size(std::string_view utf8)
ImGui_ImplSDL2_GamepadMode GamepadMode
SDL_Renderer * Renderer
SDL_Cursor * MouseLastCursor
SDL_Cursor * MouseCursors[ImGuiMouseCursor_COUNT]
ImVector< SDL_GameController * > Gamepads