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