Revision 932a86a1
Added by david.sorber over 1 year ago
| CMakeLists.txt | ||
|---|---|---|
|
#
|
||
|
# Set the compile flags
|
||
|
#
|
||
|
SET(CMAKE_CXX_STANDARD 17)
|
||
|
SET(CMAKE_CXX_STANDARD 20)
|
||
|
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||
|
# NOTE: gnu extensions are essentially required for proper 128 bit integer support
|
||
|
# See: https://quuxplusone.github.io/blog/2019/02/28/is-int128-integral/
|
||
| src/backend/imgui_impl_sdl2.cpp | ||
|---|---|---|
|
// Implemented features:
|
||
|
// [X] Platform: Clipboard support.
|
||
|
// [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen.
|
||
|
// [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]
|
||
|
// [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 are obsolete since 1.87 and not supported since 1.91.5]
|
||
|
// [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
|
||
|
// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
|
||
|
// [X] Platform: Basic IME support. App needs to call 'SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1");' before SDL_CreateWindow()!.
|
||
| ... | ... | |
|
|
||
|
// CHANGELOG
|
||
|
// (minor and older changes stripped away, please see git history for details)
|
||
|
// 2024-10-24: Emscripten: from SDL 2.30.9, SDL_EVENT_MOUSE_WHEEL event doesn't require dividing by 100.0f.
|
||
|
// 2024-09-09: use SDL_Vulkan_GetDrawableSize() when available. (#7967, #3190)
|
||
|
// 2024-08-22: moved some OS/backend related function pointers from ImGuiIO to ImGuiPlatformIO:
|
||
|
// - io.GetClipboardTextFn -> platform_io.Platform_GetClipboardTextFn
|
||
|
// - io.SetClipboardTextFn -> platform_io.Platform_SetClipboardTextFn
|
||
|
// - io.PlatformOpenInShellFn -> platform_io.Platform_OpenInShellFn
|
||
|
// - io.PlatformSetImeDataFn -> platform_io.Platform_SetImeDataFn
|
||
|
// 2024-08-19: Storing SDL's Uint32 WindowID inside ImGuiViewport::PlatformHandle instead of SDL_Window*.
|
||
|
// 2024-08-19: ImGui_ImplSDL2_ProcessEvent() now ignores events intended for other SDL windows. (#7853)
|
||
|
// 2024-07-02: Emscripten: Added io.PlatformOpenInShellFn() handler for Emscripten versions.
|
||
|
// 2024-07-02: Update for io.SetPlatformImeDataFn() -> io.PlatformSetImeDataFn() renaming in main library.
|
||
|
// 2024-02-14: Inputs: Handle gamepad disconnection. Added ImGui_ImplSDL2_SetGamepadMode().
|
||
|
// 2023-10-05: Inputs: Added support for extra ImGuiKey values: F13 to F24 function keys, app back/forward keys.
|
||
|
// 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)
|
||
|
// 2023-04-04: Inputs: Added support for io.AddMouseSourceEvent() to discriminate ImGuiMouseSource_Mouse/ImGuiMouseSource_TouchScreen. (#2702)
|
||
| ... | ... | |
|
// SDL
|
||
|
#include <SDL.h>
|
||
|
#include <SDL_syswm.h>
|
||
|
#if defined(__APPLE__)
|
||
|
#ifdef __APPLE__
|
||
|
#include <TargetConditionals.h>
|
||
|
#endif
|
||
|
#ifdef __EMSCRIPTEN__
|
||
|
#include <emscripten/em_js.h>
|
||
|
#endif
|
||
|
|
||
|
#if SDL_VERSION_ATLEAST(2,0,4) && !defined(__EMSCRIPTEN__) && !defined(__ANDROID__) && !(defined(__APPLE__) && TARGET_OS_IOS) && !defined(__amigaos4__)
|
||
|
#define SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE 1
|
||
| ... | ... | |
|
#define SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE 0
|
||
|
#endif
|
||
|
#define SDL_HAS_VULKAN SDL_VERSION_ATLEAST(2,0,6)
|
||
|
#if SDL_HAS_VULKAN
|
||
|
#include <SDL_vulkan.h>
|
||
|
#endif
|
||
|
|
||
|
// SDL Data
|
||
|
struct ImGui_ImplSDL2_Data
|
||
|
{
|
||
|
SDL_Window* Window;
|
||
|
SDL_Renderer* Renderer;
|
||
|
Uint64 Time;
|
||
|
Uint32 MouseWindowID;
|
||
|
int MouseButtonsDown;
|
||
|
SDL_Cursor* MouseCursors[ImGuiMouseCursor_COUNT];
|
||
|
SDL_Cursor* LastMouseCursor;
|
||
|
int PendingMouseLeaveFrame;
|
||
|
char* ClipboardTextData;
|
||
|
bool MouseCanUseGlobalState;
|
||
|
SDL_Window* Window;
|
||
|
Uint32 WindowID;
|
||
|
SDL_Renderer* Renderer;
|
||
|
Uint64 Time;
|
||
|
char* ClipboardTextData;
|
||
|
|
||
|
// Mouse handling
|
||
|
Uint32 MouseWindowID;
|
||
|
int MouseButtonsDown;
|
||
|
SDL_Cursor* MouseCursors[ImGuiMouseCursor_COUNT];
|
||
|
SDL_Cursor* MouseLastCursor;
|
||
|
int MouseLastLeaveFrame;
|
||
|
bool MouseCanUseGlobalState;
|
||
|
|
||
|
// Gamepad handling
|
||
|
ImVector<SDL_GameController*> Gamepads;
|
||
|
ImGui_ImplSDL2_GamepadMode GamepadMode;
|
||
|
bool WantUpdateGamepadsList;
|
||
|
|
||
|
ImGui_ImplSDL2_Data() { memset((void*)this, 0, sizeof(*this)); }
|
||
|
};
|
||
| ... | ... | |
|
}
|
||
|
|
||
|
// Functions
|
||
|
static const char* ImGui_ImplSDL2_GetClipboardText(void*)
|
||
|
static const char* ImGui_ImplSDL2_GetClipboardText(ImGuiContext*)
|
||
|
{
|
||
|
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
|
||
|
if (bd->ClipboardTextData)
|
||
| ... | ... | |
|
return bd->ClipboardTextData;
|
||
|
}
|
||
|
|
||
|
static void ImGui_ImplSDL2_SetClipboardText(void*, const char* text)
|
||
|
static void ImGui_ImplSDL2_SetClipboardText(ImGuiContext*, const char* text)
|
||
|
{
|
||
|
SDL_SetClipboardText(text);
|
||
|
}
|
||
|
|
||
|
// Note: native IME will only display if user calls SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1") _before_ SDL_CreateWindow().
|
||
|
static void ImGui_ImplSDL2_SetPlatformImeData(ImGuiViewport*, ImGuiPlatformImeData* data)
|
||
|
static void ImGui_ImplSDL2_PlatformSetImeData(ImGuiContext*, ImGuiViewport*, ImGuiPlatformImeData* data)
|
||
|
{
|
||
|
if (data->WantVisible)
|
||
|
{
|
||
| ... | ... | |
|
}
|
||
|
}
|
||
|
|
||
|
static ImGuiKey ImGui_ImplSDL2_KeycodeToImGuiKey(int keycode)
|
||
|
// Not static to allow third-party code to use that if they want to (but undocumented)
|
||
|
ImGuiKey ImGui_ImplSDL2_KeyEventToImGuiKey(SDL_Keycode keycode, SDL_Scancode scancode);
|
||
|
ImGuiKey ImGui_ImplSDL2_KeyEventToImGuiKey(SDL_Keycode keycode, SDL_Scancode scancode)
|
||
|
{
|
||
|
IM_UNUSED(scancode);
|
||
|
switch (keycode)
|
||
|
{
|
||
|
case SDLK_TAB: return ImGuiKey_Tab;
|
||
| ... | ... | |
|
case SDLK_F24: return ImGuiKey_F24;
|
||
|
case SDLK_AC_BACK: return ImGuiKey_AppBack;
|
||
|
case SDLK_AC_FORWARD: return ImGuiKey_AppForward;
|
||
|
default: break;
|
||
|
}
|
||
|
return ImGuiKey_None;
|
||
|
}
|
||
| ... | ... | |
|
io.AddKeyEvent(ImGuiMod_Super, (sdl_key_mods & KMOD_GUI) != 0);
|
||
|
}
|
||
|
|
||
|
static ImGuiViewport* ImGui_ImplSDL2_GetViewportForWindowID(Uint32 window_id)
|
||
|
{
|
||
|
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
|
||
|
return (window_id == bd->WindowID) ? ImGui::GetMainViewport() : NULL;
|
||
|
}
|
||
|
|
||
|
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
|
||
|
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data.
|
||
|
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data.
|
||
| ... | ... | |
|
// If you have multiple SDL events and some of them are not meant to be used by dear imgui, you may need to filter events based on their windowID field.
|
||
|
bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event)
|
||
|
{
|
||
|
ImGuiIO& io = ImGui::GetIO();
|
||
|
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
|
||
|
IM_ASSERT(bd != nullptr && "Context or backend not initialized! Did you call ImGui_ImplSDL2_Init()?");
|
||
|
ImGuiIO& io = ImGui::GetIO();
|
||
|
|
||
|
switch (event->type)
|
||
|
{
|
||
|
case SDL_MOUSEMOTION:
|
||
|
{
|
||
|
if (ImGui_ImplSDL2_GetViewportForWindowID(event->motion.windowID) == NULL)
|
||
|
return false;
|
||
|
ImVec2 mouse_pos((float)event->motion.x, (float)event->motion.y);
|
||
|
io.AddMouseSourceEvent(event->motion.which == SDL_TOUCH_MOUSEID ? ImGuiMouseSource_TouchScreen : ImGuiMouseSource_Mouse);
|
||
|
io.AddMousePosEvent(mouse_pos.x, mouse_pos.y);
|
||
| ... | ... | |
|
}
|
||
|
case SDL_MOUSEWHEEL:
|
||
|
{
|
||
|
if (ImGui_ImplSDL2_GetViewportForWindowID(event->wheel.windowID) == NULL)
|
||
|
return false;
|
||
|
//IMGUI_DEBUG_LOG("wheel %.2f %.2f, precise %.2f %.2f\n", (float)event->wheel.x, (float)event->wheel.y, event->wheel.preciseX, event->wheel.preciseY);
|
||
|
#if SDL_VERSION_ATLEAST(2,0,18) // If this fails to compile on Emscripten: update to latest Emscripten!
|
||
|
float wheel_x = -event->wheel.preciseX;
|
||
| ... | ... | |
|
float wheel_x = -(float)event->wheel.x;
|
||
|
float wheel_y = (float)event->wheel.y;
|
||
|
#endif
|
||
|
#ifdef __EMSCRIPTEN__
|
||
|
#if defined(__EMSCRIPTEN__) && !SDL_VERSION_ATLEAST(2,31,0)
|
||
|
wheel_x /= 100.0f;
|
||
|
#endif
|
||
|
io.AddMouseSourceEvent(event->wheel.which == SDL_TOUCH_MOUSEID ? ImGuiMouseSource_TouchScreen : ImGuiMouseSource_Mouse);
|
||
| ... | ... | |
|
case SDL_MOUSEBUTTONDOWN:
|
||
|
case SDL_MOUSEBUTTONUP:
|
||
|
{
|
||
|
if (ImGui_ImplSDL2_GetViewportForWindowID(event->button.windowID) == NULL)
|
||
|
return false;
|
||
|
int mouse_button = -1;
|
||
|
if (event->button.button == SDL_BUTTON_LEFT) { mouse_button = 0; }
|
||
|
if (event->button.button == SDL_BUTTON_RIGHT) { mouse_button = 1; }
|
||
| ... | ... | |
|
}
|
||
|
case SDL_TEXTINPUT:
|
||
|
{
|
||
|
if (ImGui_ImplSDL2_GetViewportForWindowID(event->text.windowID) == NULL)
|
||
|
return false;
|
||
|
io.AddInputCharactersUTF8(event->text.text);
|
||
|
return true;
|
||
|
}
|
||
|
case SDL_KEYDOWN:
|
||
|
case SDL_KEYUP:
|
||
|
{
|
||
|
if (ImGui_ImplSDL2_GetViewportForWindowID(event->key.windowID) == NULL)
|
||
|
return false;
|
||
|
ImGui_ImplSDL2_UpdateKeyModifiers((SDL_Keymod)event->key.keysym.mod);
|
||
|
ImGuiKey key = ImGui_ImplSDL2_KeycodeToImGuiKey(event->key.keysym.sym);
|
||
|
ImGuiKey key = ImGui_ImplSDL2_KeyEventToImGuiKey(event->key.keysym.sym, event->key.keysym.scancode);
|
||
|
io.AddKeyEvent(key, (event->type == SDL_KEYDOWN));
|
||
|
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.
|
||
|
return true;
|
||
|
}
|
||
|
case SDL_WINDOWEVENT:
|
||
|
{
|
||
|
if (ImGui_ImplSDL2_GetViewportForWindowID(event->window.windowID) == NULL)
|
||
|
return false;
|
||
|
// - 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.
|
||
|
// - However we won't get a correct LEAVE event for a captured window.
|
||
|
// - In some cases, when detaching a window from main viewport SDL may send SDL_WINDOWEVENT_ENTER one frame too late,
|
||
| ... | ... | |
|
if (window_event == SDL_WINDOWEVENT_ENTER)
|
||
|
{
|
||
|
bd->MouseWindowID = event->window.windowID;
|
||
|
bd->PendingMouseLeaveFrame = 0;
|
||
|
bd->MouseLastLeaveFrame = 0;
|
||
|
}
|
||
|
if (window_event == SDL_WINDOWEVENT_LEAVE)
|
||
|
bd->PendingMouseLeaveFrame = ImGui::GetFrameCount() + 1;
|
||
|
bd->MouseLastLeaveFrame = ImGui::GetFrameCount() + 1;
|
||
|
if (window_event == SDL_WINDOWEVENT_FOCUS_GAINED)
|
||
|
io.AddFocusEvent(true);
|
||
|
else if (event->window.event == SDL_WINDOWEVENT_FOCUS_LOST)
|
||
|
io.AddFocusEvent(false);
|
||
|
return true;
|
||
|
}
|
||
|
case SDL_CONTROLLERDEVICEADDED:
|
||
|
case SDL_CONTROLLERDEVICEREMOVED:
|
||
|
{
|
||
|
bd->WantUpdateGamepadsList = true;
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
static bool ImGui_ImplSDL2_Init(SDL_Window* window, SDL_Renderer* renderer)
|
||
|
#ifdef __EMSCRIPTEN__
|
||
|
EM_JS(void, ImGui_ImplSDL2_EmscriptenOpenURL, (char const* url), { url = url ? UTF8ToString(url) : null; if (url) window.open(url, '_blank'); });
|
||
|
#endif
|
||
|
|
||
|
static bool ImGui_ImplSDL2_Init(SDL_Window* window, SDL_Renderer* renderer, void* sdl_gl_context)
|
||
|
{
|
||
|
ImGuiIO& io = ImGui::GetIO();
|
||
|
IMGUI_CHECKVERSION();
|
||
|
IM_ASSERT(io.BackendPlatformUserData == nullptr && "Already initialized a platform backend!");
|
||
|
|
||
|
// Check and store if we are on a SDL backend that supports global mouse position
|
||
| ... | ... | |
|
io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used)
|
||
|
|
||
|
bd->Window = window;
|
||
|
bd->WindowID = SDL_GetWindowID(window);
|
||
|
bd->Renderer = renderer;
|
||
|
bd->MouseCanUseGlobalState = mouse_can_use_global_state;
|
||
|
|
||
|
io.SetClipboardTextFn = ImGui_ImplSDL2_SetClipboardText;
|
||
|
io.GetClipboardTextFn = ImGui_ImplSDL2_GetClipboardText;
|
||
|
io.ClipboardUserData = nullptr;
|
||
|
io.SetPlatformImeDataFn = ImGui_ImplSDL2_SetPlatformImeData;
|
||
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||
|
platform_io.Platform_SetClipboardTextFn = ImGui_ImplSDL2_SetClipboardText;
|
||
|
platform_io.Platform_GetClipboardTextFn = ImGui_ImplSDL2_GetClipboardText;
|
||
|
platform_io.Platform_ClipboardUserData = nullptr;
|
||
|
platform_io.Platform_SetImeDataFn = ImGui_ImplSDL2_PlatformSetImeData;
|
||
|
#ifdef __EMSCRIPTEN__
|
||
|
platform_io.Platform_OpenInShellFn = [](ImGuiContext*, const char* url) { ImGui_ImplSDL2_EmscriptenOpenURL(url); return true; };
|
||
|
#endif
|
||
|
|
||
|
// Gamepad handling
|
||
|
bd->GamepadMode = ImGui_ImplSDL2_GamepadMode_AutoFirst;
|
||
|
bd->WantUpdateGamepadsList = true;
|
||
|
|
||
|
// Load mouse cursors
|
||
|
bd->MouseCursors[ImGuiMouseCursor_Arrow] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
|
||
| ... | ... | |
|
// Set platform dependent data in viewport
|
||
|
// Our mouse update function expect PlatformHandle to be filled for the main viewport
|
||
|
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
||
|
main_viewport->PlatformHandle = (void*)(intptr_t)bd->WindowID;
|
||
|
main_viewport->PlatformHandleRaw = nullptr;
|
||
|
SDL_SysWMinfo info;
|
||
|
SDL_VERSION(&info.version);
|
||
| ... | ... | |
|
SDL_SetHint(SDL_HINT_MOUSE_AUTO_CAPTURE, "0");
|
||
|
#endif
|
||
|
|
||
|
(void)sdl_gl_context; // Unused in 'master' branch.
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
bool ImGui_ImplSDL2_InitForOpenGL(SDL_Window* window, void* sdl_gl_context)
|
||
|
{
|
||
|
IM_UNUSED(sdl_gl_context); // Viewport branch will need this.
|
||
|
return ImGui_ImplSDL2_Init(window, nullptr);
|
||
|
return ImGui_ImplSDL2_Init(window, nullptr, sdl_gl_context);
|
||
|
}
|
||
|
|
||
|
bool ImGui_ImplSDL2_InitForVulkan(SDL_Window* window)
|
||
| ... | ... | |
|
#if !SDL_HAS_VULKAN
|
||
|
IM_ASSERT(0 && "Unsupported");
|
||
|
#endif
|
||
|
return ImGui_ImplSDL2_Init(window, nullptr);
|
||
|
return ImGui_ImplSDL2_Init(window, nullptr, nullptr);
|
||
|
}
|
||
|
|
||
|
bool ImGui_ImplSDL2_InitForD3D(SDL_Window* window)
|
||
| ... | ... | |
|
#if !defined(_WIN32)
|
||
|
IM_ASSERT(0 && "Unsupported");
|
||
|
#endif
|
||
|
return ImGui_ImplSDL2_Init(window, nullptr);
|
||
|
return ImGui_ImplSDL2_Init(window, nullptr, nullptr);
|
||
|
}
|
||
|
|
||
|
bool ImGui_ImplSDL2_InitForMetal(SDL_Window* window)
|
||
|
{
|
||
|
return ImGui_ImplSDL2_Init(window, nullptr);
|
||
|
return ImGui_ImplSDL2_Init(window, nullptr, nullptr);
|
||
|
}
|
||
|
|
||
|
bool ImGui_ImplSDL2_InitForSDLRenderer(SDL_Window* window, SDL_Renderer* renderer)
|
||
|
{
|
||
|
return ImGui_ImplSDL2_Init(window, renderer);
|
||
|
return ImGui_ImplSDL2_Init(window, renderer, nullptr);
|
||
|
}
|
||
|
|
||
|
bool ImGui_ImplSDL2_InitForOther(SDL_Window* window)
|
||
|
{
|
||
|
return ImGui_ImplSDL2_Init(window, nullptr);
|
||
|
return ImGui_ImplSDL2_Init(window, nullptr, nullptr);
|
||
|
}
|
||
|
|
||
|
static void ImGui_ImplSDL2_CloseGamepads();
|
||
|
|
||
|
void ImGui_ImplSDL2_Shutdown()
|
||
|
{
|
||
|
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
|
||
| ... | ... | |
|
SDL_free(bd->ClipboardTextData);
|
||
|
for (ImGuiMouseCursor cursor_n = 0; cursor_n < ImGuiMouseCursor_COUNT; cursor_n++)
|
||
|
SDL_FreeCursor(bd->MouseCursors[cursor_n]);
|
||
|
bd->LastMouseCursor = nullptr;
|
||
|
ImGui_ImplSDL2_CloseGamepads();
|
||
|
|
||
|
io.BackendPlatformName = nullptr;
|
||
|
io.BackendPlatformUserData = nullptr;
|
||
| ... | ... | |
|
#endif
|
||
|
if (is_app_focused)
|
||
|
{
|
||
|
// (Optional) Set OS mouse position from Dear ImGui if requested (rarely used, only when ImGuiConfigFlags_NavEnableSetMousePos is enabled by user)
|
||
|
// (Optional) Set OS mouse position from Dear ImGui if requested (rarely used, only when io.ConfigNavMoveSetMousePos is enabled by user)
|
||
|
if (io.WantSetMousePos)
|
||
|
SDL_WarpMouseInWindow(bd->Window, (int)io.MousePos.x, (int)io.MousePos.y);
|
||
|
|
||
| ... | ... | |
|
{
|
||
|
// Show OS mouse cursor
|
||
|
SDL_Cursor* expected_cursor = bd->MouseCursors[imgui_cursor] ? bd->MouseCursors[imgui_cursor] : bd->MouseCursors[ImGuiMouseCursor_Arrow];
|
||
|
if (bd->LastMouseCursor != expected_cursor)
|
||
|
if (bd->MouseLastCursor != expected_cursor)
|
||
|
{
|
||
|
SDL_SetCursor(expected_cursor); // SDL function doesn't have an early out (see #6113)
|
||
|
bd->LastMouseCursor = expected_cursor;
|
||
|
bd->MouseLastCursor = expected_cursor;
|
||
|
}
|
||
|
SDL_ShowCursor(SDL_TRUE);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static void ImGui_ImplSDL2_CloseGamepads()
|
||
|
{
|
||
|
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
|
||
|
if (bd->GamepadMode != ImGui_ImplSDL2_GamepadMode_Manual)
|
||
|
for (SDL_GameController* gamepad : bd->Gamepads)
|
||
|
SDL_GameControllerClose(gamepad);
|
||
|
bd->Gamepads.resize(0);
|
||
|
}
|
||
|
|
||
|
void ImGui_ImplSDL2_SetGamepadMode(ImGui_ImplSDL2_GamepadMode mode, struct _SDL_GameController** manual_gamepads_array, int manual_gamepads_count)
|
||
|
{
|
||
|
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
|
||
|
ImGui_ImplSDL2_CloseGamepads();
|
||
|
if (mode == ImGui_ImplSDL2_GamepadMode_Manual)
|
||
|
{
|
||
|
IM_ASSERT(manual_gamepads_array != nullptr && manual_gamepads_count > 0);
|
||
|
for (int n = 0; n < manual_gamepads_count; n++)
|
||
|
bd->Gamepads.push_back(manual_gamepads_array[n]);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
IM_ASSERT(manual_gamepads_array == nullptr && manual_gamepads_count <= 0);
|
||
|
bd->WantUpdateGamepadsList = true;
|
||
|
}
|
||
|
bd->GamepadMode = mode;
|
||
|
}
|
||
|
|
||
|
static void ImGui_ImplSDL2_UpdateGamepadButton(ImGui_ImplSDL2_Data* bd, ImGuiIO& io, ImGuiKey key, SDL_GameControllerButton button_no)
|
||
|
{
|
||
|
bool merged_value = false;
|
||
|
for (SDL_GameController* gamepad : bd->Gamepads)
|
||
|
merged_value |= SDL_GameControllerGetButton(gamepad, button_no) != 0;
|
||
|
io.AddKeyEvent(key, merged_value);
|
||
|
}
|
||
|
|
||
|
static inline float Saturate(float v) { return v < 0.0f ? 0.0f : v > 1.0f ? 1.0f : v; }
|
||
|
static void ImGui_ImplSDL2_UpdateGamepadAnalog(ImGui_ImplSDL2_Data* bd, ImGuiIO& io, ImGuiKey key, SDL_GameControllerAxis axis_no, float v0, float v1)
|
||
|
{
|
||
|
float merged_value = 0.0f;
|
||
|
for (SDL_GameController* gamepad : bd->Gamepads)
|
||
|
{
|
||
|
float vn = Saturate((float)(SDL_GameControllerGetAxis(gamepad, axis_no) - v0) / (float)(v1 - v0));
|
||
|
if (merged_value < vn)
|
||
|
merged_value = vn;
|
||
|
}
|
||
|
io.AddKeyAnalogEvent(key, merged_value > 0.1f, merged_value);
|
||
|
}
|
||
|
|
||
|
static void ImGui_ImplSDL2_UpdateGamepads()
|
||
|
{
|
||
|
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
|
||
|
ImGuiIO& io = ImGui::GetIO();
|
||
|
if ((io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) == 0) // FIXME: Technically feeding gamepad shouldn't depend on this now that they are regular inputs.
|
||
|
return;
|
||
|
|
||
|
// Get gamepad
|
||
|
// Update list of controller(s) to use
|
||
|
if (bd->WantUpdateGamepadsList && bd->GamepadMode != ImGui_ImplSDL2_GamepadMode_Manual)
|
||
|
{
|
||
|
ImGui_ImplSDL2_CloseGamepads();
|
||
|
int joystick_count = SDL_NumJoysticks();
|
||
|
for (int n = 0; n < joystick_count; n++)
|
||
|
if (SDL_IsGameController(n))
|
||
|
if (SDL_GameController* gamepad = SDL_GameControllerOpen(n))
|
||
|
{
|
||
|
bd->Gamepads.push_back(gamepad);
|
||
|
if (bd->GamepadMode == ImGui_ImplSDL2_GamepadMode_AutoFirst)
|
||
|
break;
|
||
|
}
|
||
|
bd->WantUpdateGamepadsList = false;
|
||
|
}
|
||
|
|
||
|
// FIXME: Technically feeding gamepad shouldn't depend on this now that they are regular inputs.
|
||
|
if ((io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) == 0)
|
||
|
return;
|
||
|
io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad;
|
||
|
SDL_GameController* game_controller = SDL_GameControllerOpen(0);
|
||
|
if (!game_controller)
|
||
|
if (bd->Gamepads.Size == 0)
|
||
|
return;
|
||
|
io.BackendFlags |= ImGuiBackendFlags_HasGamepad;
|
||
|
|
||
|
// Update gamepad inputs
|
||
|
#define IM_SATURATE(V) (V < 0.0f ? 0.0f : V > 1.0f ? 1.0f : V)
|
||
|
#define MAP_BUTTON(KEY_NO, BUTTON_NO) { io.AddKeyEvent(KEY_NO, SDL_GameControllerGetButton(game_controller, BUTTON_NO) != 0); }
|
||
|
#define MAP_ANALOG(KEY_NO, AXIS_NO, V0, V1) { float vn = (float)(SDL_GameControllerGetAxis(game_controller, AXIS_NO) - V0) / (float)(V1 - V0); vn = IM_SATURATE(vn); io.AddKeyAnalogEvent(KEY_NO, vn > 0.1f, vn); }
|
||
|
const int thumb_dead_zone = 8000; // SDL_gamecontroller.h suggests using this value.
|
||
|
MAP_BUTTON(ImGuiKey_GamepadStart, SDL_CONTROLLER_BUTTON_START);
|
||
|
MAP_BUTTON(ImGuiKey_GamepadBack, SDL_CONTROLLER_BUTTON_BACK);
|
||
|
MAP_BUTTON(ImGuiKey_GamepadFaceLeft, SDL_CONTROLLER_BUTTON_X); // Xbox X, PS Square
|
||
|
MAP_BUTTON(ImGuiKey_GamepadFaceRight, SDL_CONTROLLER_BUTTON_B); // Xbox B, PS Circle
|
||
|
MAP_BUTTON(ImGuiKey_GamepadFaceUp, SDL_CONTROLLER_BUTTON_Y); // Xbox Y, PS Triangle
|
||
|
MAP_BUTTON(ImGuiKey_GamepadFaceDown, SDL_CONTROLLER_BUTTON_A); // Xbox A, PS Cross
|
||
|
MAP_BUTTON(ImGuiKey_GamepadDpadLeft, SDL_CONTROLLER_BUTTON_DPAD_LEFT);
|
||
|
MAP_BUTTON(ImGuiKey_GamepadDpadRight, SDL_CONTROLLER_BUTTON_DPAD_RIGHT);
|
||
|
MAP_BUTTON(ImGuiKey_GamepadDpadUp, SDL_CONTROLLER_BUTTON_DPAD_UP);
|
||
|
MAP_BUTTON(ImGuiKey_GamepadDpadDown, SDL_CONTROLLER_BUTTON_DPAD_DOWN);
|
||
|
MAP_BUTTON(ImGuiKey_GamepadL1, SDL_CONTROLLER_BUTTON_LEFTSHOULDER);
|
||
|
MAP_BUTTON(ImGuiKey_GamepadR1, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER);
|
||
|
MAP_ANALOG(ImGuiKey_GamepadL2, SDL_CONTROLLER_AXIS_TRIGGERLEFT, 0.0f, 32767);
|
||
|
MAP_ANALOG(ImGuiKey_GamepadR2, SDL_CONTROLLER_AXIS_TRIGGERRIGHT, 0.0f, 32767);
|
||
|
MAP_BUTTON(ImGuiKey_GamepadL3, SDL_CONTROLLER_BUTTON_LEFTSTICK);
|
||
|
MAP_BUTTON(ImGuiKey_GamepadR3, SDL_CONTROLLER_BUTTON_RIGHTSTICK);
|
||
|
MAP_ANALOG(ImGuiKey_GamepadLStickLeft, SDL_CONTROLLER_AXIS_LEFTX, -thumb_dead_zone, -32768);
|
||
|
MAP_ANALOG(ImGuiKey_GamepadLStickRight, SDL_CONTROLLER_AXIS_LEFTX, +thumb_dead_zone, +32767);
|
||
|
MAP_ANALOG(ImGuiKey_GamepadLStickUp, SDL_CONTROLLER_AXIS_LEFTY, -thumb_dead_zone, -32768);
|
||
|
MAP_ANALOG(ImGuiKey_GamepadLStickDown, SDL_CONTROLLER_AXIS_LEFTY, +thumb_dead_zone, +32767);
|
||
|
MAP_ANALOG(ImGuiKey_GamepadRStickLeft, SDL_CONTROLLER_AXIS_RIGHTX, -thumb_dead_zone, -32768);
|
||
|
MAP_ANALOG(ImGuiKey_GamepadRStickRight, SDL_CONTROLLER_AXIS_RIGHTX, +thumb_dead_zone, +32767);
|
||
|
MAP_ANALOG(ImGuiKey_GamepadRStickUp, SDL_CONTROLLER_AXIS_RIGHTY, -thumb_dead_zone, -32768);
|
||
|
MAP_ANALOG(ImGuiKey_GamepadRStickDown, SDL_CONTROLLER_AXIS_RIGHTY, +thumb_dead_zone, +32767);
|
||
|
#undef MAP_BUTTON
|
||
|
#undef MAP_ANALOG
|
||
|
const int thumb_dead_zone = 8000; // SDL_gamecontroller.h suggests using this value.
|
||
|
ImGui_ImplSDL2_UpdateGamepadButton(bd, io, ImGuiKey_GamepadStart, SDL_CONTROLLER_BUTTON_START);
|
||
|
ImGui_ImplSDL2_UpdateGamepadButton(bd, io, ImGuiKey_GamepadBack, SDL_CONTROLLER_BUTTON_BACK);
|
||
|
ImGui_ImplSDL2_UpdateGamepadButton(bd, io, ImGuiKey_GamepadFaceLeft, SDL_CONTROLLER_BUTTON_X); // Xbox X, PS Square
|
||
|
ImGui_ImplSDL2_UpdateGamepadButton(bd, io, ImGuiKey_GamepadFaceRight, SDL_CONTROLLER_BUTTON_B); // Xbox B, PS Circle
|
||
|
ImGui_ImplSDL2_UpdateGamepadButton(bd, io, ImGuiKey_GamepadFaceUp, SDL_CONTROLLER_BUTTON_Y); // Xbox Y, PS Triangle
|
||
|
ImGui_ImplSDL2_UpdateGamepadButton(bd, io, ImGuiKey_GamepadFaceDown, SDL_CONTROLLER_BUTTON_A); // Xbox A, PS Cross
|
||
|
ImGui_ImplSDL2_UpdateGamepadButton(bd, io, ImGuiKey_GamepadDpadLeft, SDL_CONTROLLER_BUTTON_DPAD_LEFT);
|
||
|
ImGui_ImplSDL2_UpdateGamepadButton(bd, io, ImGuiKey_GamepadDpadRight, SDL_CONTROLLER_BUTTON_DPAD_RIGHT);
|
||
|
ImGui_ImplSDL2_UpdateGamepadButton(bd, io, ImGuiKey_GamepadDpadUp, SDL_CONTROLLER_BUTTON_DPAD_UP);
|
||
|
ImGui_ImplSDL2_UpdateGamepadButton(bd, io, ImGuiKey_GamepadDpadDown, SDL_CONTROLLER_BUTTON_DPAD_DOWN);
|
||
|
ImGui_ImplSDL2_UpdateGamepadButton(bd, io, ImGuiKey_GamepadL1, SDL_CONTROLLER_BUTTON_LEFTSHOULDER);
|
||
|
ImGui_ImplSDL2_UpdateGamepadButton(bd, io, ImGuiKey_GamepadR1, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER);
|
||
|
ImGui_ImplSDL2_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadL2, SDL_CONTROLLER_AXIS_TRIGGERLEFT, 0.0f, 32767);
|
||
|
ImGui_ImplSDL2_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadR2, SDL_CONTROLLER_AXIS_TRIGGERRIGHT, 0.0f, 32767);
|
||
|
ImGui_ImplSDL2_UpdateGamepadButton(bd, io, ImGuiKey_GamepadL3, SDL_CONTROLLER_BUTTON_LEFTSTICK);
|
||
|
ImGui_ImplSDL2_UpdateGamepadButton(bd, io, ImGuiKey_GamepadR3, SDL_CONTROLLER_BUTTON_RIGHTSTICK);
|
||
|
ImGui_ImplSDL2_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadLStickLeft, SDL_CONTROLLER_AXIS_LEFTX, -thumb_dead_zone, -32768);
|
||
|
ImGui_ImplSDL2_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadLStickRight, SDL_CONTROLLER_AXIS_LEFTX, +thumb_dead_zone, +32767);
|
||
|
ImGui_ImplSDL2_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadLStickUp, SDL_CONTROLLER_AXIS_LEFTY, -thumb_dead_zone, -32768);
|
||
|
ImGui_ImplSDL2_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadLStickDown, SDL_CONTROLLER_AXIS_LEFTY, +thumb_dead_zone, +32767);
|
||
|
ImGui_ImplSDL2_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadRStickLeft, SDL_CONTROLLER_AXIS_RIGHTX, -thumb_dead_zone, -32768);
|
||
|
ImGui_ImplSDL2_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadRStickRight, SDL_CONTROLLER_AXIS_RIGHTX, +thumb_dead_zone, +32767);
|
||
|
ImGui_ImplSDL2_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadRStickUp, SDL_CONTROLLER_AXIS_RIGHTY, -thumb_dead_zone, -32768);
|
||
|
ImGui_ImplSDL2_UpdateGamepadAnalog(bd, io, ImGuiKey_GamepadRStickDown, SDL_CONTROLLER_AXIS_RIGHTY, +thumb_dead_zone, +32767);
|
||
|
}
|
||
|
|
||
|
void ImGui_ImplSDL2_NewFrame()
|
||
|
{
|
||
|
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
|
||
|
IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplSDL2_Init()?");
|
||
|
IM_ASSERT(bd != nullptr && "Context or backend not initialized! Did you call ImGui_ImplSDL2_Init()?");
|
||
|
ImGuiIO& io = ImGui::GetIO();
|
||
|
|
||
|
// Setup display size (every frame to accommodate for window resizing)
|
||
| ... | ... | |
|
w = h = 0;
|
||
|
if (bd->Renderer != nullptr)
|
||
|
SDL_GetRendererOutputSize(bd->Renderer, &display_w, &display_h);
|
||
|
#if SDL_HAS_VULKAN
|
||
|
else if (SDL_GetWindowFlags(bd->Window) & SDL_WINDOW_VULKAN)
|
||
|
SDL_Vulkan_GetDrawableSize(bd->Window, &display_w, &display_h);
|
||
|
#endif
|
||
|
else
|
||
|
SDL_GL_GetDrawableSize(bd->Window, &display_w, &display_h);
|
||
|
io.DisplaySize = ImVec2((float)w, (float)h);
|
||
| ... | ... | |
|
io.DeltaTime = bd->Time > 0 ? (float)((double)(current_time - bd->Time) / frequency) : (float)(1.0f / 60.0f);
|
||
|
bd->Time = current_time;
|
||
|
|
||
|
if (bd->PendingMouseLeaveFrame && bd->PendingMouseLeaveFrame >= ImGui::GetFrameCount() && bd->MouseButtonsDown == 0)
|
||
|
if (bd->MouseLastLeaveFrame && bd->MouseLastLeaveFrame >= ImGui::GetFrameCount() && bd->MouseButtonsDown == 0)
|
||
|
{
|
||
|
bd->MouseWindowID = 0;
|
||
|
bd->PendingMouseLeaveFrame = 0;
|
||
|
bd->MouseLastLeaveFrame = 0;
|
||
|
io.AddMousePosEvent(-FLT_MAX, -FLT_MAX);
|
||
|
}
|
||
|
|
||
| src/backend/imgui_impl_sdl2.h | ||
|---|---|---|
|
// Implemented features:
|
||
|
// [X] Platform: Clipboard support.
|
||
|
// [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen.
|
||
|
// [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]
|
||
|
// [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 are obsolete since 1.87 and not supported since 1.91.5]
|
||
|
// [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
|
||
|
// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
|
||
|
// [X] Platform: Basic IME support. App needs to call 'SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1");' before SDL_CreateWindow()!.
|
||
| ... | ... | |
|
|
||
|
struct SDL_Window;
|
||
|
struct SDL_Renderer;
|
||
|
struct _SDL_GameController;
|
||
|
typedef union SDL_Event SDL_Event;
|
||
|
|
||
|
// Follow "Getting Started" link and check examples/ folder to learn about using backends!
|
||
|
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForOpenGL(SDL_Window* window, void* sdl_gl_context);
|
||
|
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForVulkan(SDL_Window* window);
|
||
|
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForD3D(SDL_Window* window);
|
||
| ... | ... | |
|
IMGUI_IMPL_API void ImGui_ImplSDL2_NewFrame();
|
||
|
IMGUI_IMPL_API bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event);
|
||
|
|
||
|
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||
|
static inline void ImGui_ImplSDL2_NewFrame(SDL_Window*) { ImGui_ImplSDL2_NewFrame(); } // 1.84: removed unnecessary parameter
|
||
|
#endif
|
||
|
// Gamepad selection automatically starts in AutoFirst mode, picking first available SDL_Gamepad. You may override this.
|
||
|
// When using manual mode, caller is responsible for opening/closing gamepad.
|
||
|
enum ImGui_ImplSDL2_GamepadMode { ImGui_ImplSDL2_GamepadMode_AutoFirst, ImGui_ImplSDL2_GamepadMode_AutoAll, ImGui_ImplSDL2_GamepadMode_Manual };
|
||
|
IMGUI_IMPL_API void ImGui_ImplSDL2_SetGamepadMode(ImGui_ImplSDL2_GamepadMode mode, struct _SDL_GameController** manual_gamepads_array = NULL, int manual_gamepads_count = -1);
|
||
|
|
||
|
#endif // #ifndef IMGUI_DISABLE
|
||
| src/backend/imgui_impl_sdlrenderer2.cpp | ||
|---|---|---|
|
// Implemented features:
|
||
|
// [X] Renderer: User texture binding. Use 'SDL_Texture*' as ImTextureID. Read the FAQ about ImTextureID!
|
||
|
// [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices.
|
||
|
// [X] Renderer: Expose selected render state for draw callbacks to use. Access in '(ImGui_ImplXXXX_RenderState*)GetPlatformIO().Renderer_RenderState'.
|
||
|
|
||
|
// You can copy and use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||
|
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||
| ... | ... | |
|
// - Introduction, links and more at the top of imgui.cpp
|
||
|
|
||
|
// CHANGELOG
|
||
|
// 2024-10-09: Expose selected render state in ImGui_ImplSDLRenderer2_RenderState, which you can access in 'void* platform_io.Renderer_RenderState' during draw callbacks.
|
||
|
// 2024-05-14: *BREAKING CHANGE* ImGui_ImplSDLRenderer3_RenderDrawData() requires SDL_Renderer* passed as parameter.
|
||
|
// 2023-05-30: Renamed imgui_impl_sdlrenderer.h/.cpp to imgui_impl_sdlrenderer2.h/.cpp to accommodate for upcoming SDL3.
|
||
|
// 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11.
|
||
|
// 2021-12-21: Update SDL_RenderGeometryRaw() format to work with SDL 2.0.19.
|
||
| ... | ... | |
|
// SDL_Renderer data
|
||
|
struct ImGui_ImplSDLRenderer2_Data
|
||
|
{
|
||
|
SDL_Renderer* SDLRenderer;
|
||
|
SDL_Renderer* Renderer; // Main viewport's renderer
|
||
|
SDL_Texture* FontTexture;
|
||
|
ImGui_ImplSDLRenderer2_Data() { memset((void*)this, 0, sizeof(*this)); }
|
||
|
ImGui_ImplSDLRenderer2_Data() { memset((void*)this, 0, sizeof(*this)); }
|
||
|
};
|
||
|
|
||
|
// Backend data stored in io.BackendRendererUserData to allow support for multiple Dear ImGui contexts
|
||
| ... | ... | |
|
bool ImGui_ImplSDLRenderer2_Init(SDL_Renderer* renderer)
|
||
|
{
|
||
|
ImGuiIO& io = ImGui::GetIO();
|
||
|
IMGUI_CHECKVERSION();
|
||
|
IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!");
|
||
|
IM_ASSERT(renderer != nullptr && "SDL_Renderer not initialized!");
|
||
|
|
||
| ... | ... | |
|
io.BackendRendererName = "imgui_impl_sdlrenderer2";
|
||
|
io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
|
||
|
|
||
|
bd->SDLRenderer = renderer;
|
||
|
bd->Renderer = renderer;
|
||
|
|
||
|
return true;
|
||
|
}
|
||
| ... | ... | |
|
IM_DELETE(bd);
|
||
|
}
|
||
|
|
||
|
static void ImGui_ImplSDLRenderer2_SetupRenderState()
|
||
|
static void ImGui_ImplSDLRenderer2_SetupRenderState(SDL_Renderer* renderer)
|
||
|
{
|
||
|
ImGui_ImplSDLRenderer2_Data* bd = ImGui_ImplSDLRenderer2_GetBackendData();
|
||
|
|
||
|
// Clear out any viewports and cliprect set by the user
|
||
|
// FIXME: Technically speaking there are lots of other things we could backup/setup/restore during our render process.
|
||
|
SDL_RenderSetViewport(bd->SDLRenderer, nullptr);
|
||
|
SDL_RenderSetClipRect(bd->SDLRenderer, nullptr);
|
||
|
SDL_RenderSetViewport(renderer, nullptr);
|
||
|
SDL_RenderSetClipRect(renderer, nullptr);
|
||
|
}
|
||
|
|
||
|
void ImGui_ImplSDLRenderer2_NewFrame()
|
||
|
{
|
||
|
ImGui_ImplSDLRenderer2_Data* bd = ImGui_ImplSDLRenderer2_GetBackendData();
|
||
|
IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplSDLRenderer2_Init()?");
|
||
|
IM_ASSERT(bd != nullptr && "Context or backend not initialized! Did you call ImGui_ImplSDLRenderer2_Init()?");
|
||
|
|
||
|
if (!bd->FontTexture)
|
||
|
ImGui_ImplSDLRenderer2_CreateDeviceObjects();
|
||
|
}
|
||
|
|
||
|
void ImGui_ImplSDLRenderer2_RenderDrawData(ImDrawData* draw_data)
|
||
|
void ImGui_ImplSDLRenderer2_RenderDrawData(ImDrawData* draw_data, SDL_Renderer* renderer)
|
||
|
{
|
||
|
ImGui_ImplSDLRenderer2_Data* bd = ImGui_ImplSDLRenderer2_GetBackendData();
|
||
|
|
||
|
// If there's a scale factor set by the user, use that instead
|
||
|
// If the user has specified a scale factor to SDL_Renderer already via SDL_RenderSetScale(), SDL will scale whatever we pass
|
||
|
// to SDL_RenderGeometryRaw() by that scale factor. In that case we don't want to be also scaling it ourselves here.
|
||
|
float rsx = 1.0f;
|
||
|
float rsy = 1.0f;
|
||
|
SDL_RenderGetScale(bd->SDLRenderer, &rsx, &rsy);
|
||
|
SDL_RenderGetScale(renderer, &rsx, &rsy);
|
||
|
ImVec2 render_scale;
|
||
|
render_scale.x = (rsx == 1.0f) ? draw_data->FramebufferScale.x : 1.0f;
|
||
|
render_scale.y = (rsy == 1.0f) ? draw_data->FramebufferScale.y : 1.0f;
|
||
| ... | ... | |
|
SDL_Rect ClipRect;
|
||
|
};
|
||
|
BackupSDLRendererState old = {};
|
||
|
old.ClipEnabled = SDL_RenderIsClipEnabled(bd->SDLRenderer) == SDL_TRUE;
|
||
|
SDL_RenderGetViewport(bd->SDLRenderer, &old.Viewport);
|
||
|
SDL_RenderGetClipRect(bd->SDLRenderer, &old.ClipRect);
|
||
|
old.ClipEnabled = SDL_RenderIsClipEnabled(renderer) == SDL_TRUE;
|
||
|
SDL_RenderGetViewport(renderer, &old.Viewport);
|
||
|
SDL_RenderGetClipRect(renderer, &old.ClipRect);
|
||
|
|
||
|
// Setup desired state
|
||
|
ImGui_ImplSDLRenderer2_SetupRenderState(renderer);
|
||
|
|
||
|
// Setup render state structure (for callbacks and custom texture bindings)
|
||
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||
|
ImGui_ImplSDLRenderer2_RenderState render_state;
|
||
|
render_state.Renderer = renderer;
|
||
|
platform_io.Renderer_RenderState = &render_state;
|
||
|
|
||
|
// Will project scissor/clipping rectangles into framebuffer space
|
||
|
ImVec2 clip_off = draw_data->DisplayPos; // (0,0) unless using multi-viewports
|
||
|
ImVec2 clip_scale = render_scale;
|
||
|
|
||
|
// Render command lists
|
||
|
ImGui_ImplSDLRenderer2_SetupRenderState();
|
||
|
for (int n = 0; n < draw_data->CmdListsCount; n++)
|
||
|
{
|
||
|
const ImDrawList* cmd_list = draw_data->CmdLists[n];
|
||
|
const ImDrawVert* vtx_buffer = cmd_list->VtxBuffer.Data;
|
||
|
const ImDrawIdx* idx_buffer = cmd_list->IdxBuffer.Data;
|
||
|
const ImDrawList* draw_list = draw_data->CmdLists[n];
|
||
|
const ImDrawVert* vtx_buffer = draw_list->VtxBuffer.Data;
|
||
|
const ImDrawIdx* idx_buffer = draw_list->IdxBuffer.Data;
|
||
|
|
||
|
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
|
||
|
for (int cmd_i = 0; cmd_i < draw_list->CmdBuffer.Size; cmd_i++)
|
||
|
{
|
||
|
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
|
||
|
const ImDrawCmd* pcmd = &draw_list->CmdBuffer[cmd_i];
|
||
|
if (pcmd->UserCallback)
|
||
|
{
|
||
|
// User callback, registered via ImDrawList::AddCallback()
|
||
|
// (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
|
||
|
if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
|
||
|
ImGui_ImplSDLRenderer2_SetupRenderState();
|
||
|
ImGui_ImplSDLRenderer2_SetupRenderState(renderer);
|
||
|
else
|
||
|
pcmd->UserCallback(cmd_list, pcmd);
|
||
|
pcmd->UserCallback(draw_list, pcmd);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
| ... | ... | |
|
continue;
|
||
|
|
||
|
SDL_Rect r = { (int)(clip_min.x), (int)(clip_min.y), (int)(clip_max.x - clip_min.x), (int)(clip_max.y - clip_min.y) };
|
||
|
SDL_RenderSetClipRect(bd->SDLRenderer, &r);
|
||
|
SDL_RenderSetClipRect(renderer, &r);
|
||
|
|
||
|
const float* xy = (const float*)(const void*)((const char*)(vtx_buffer + pcmd->VtxOffset) + offsetof(ImDrawVert, pos));
|
||
|
const float* uv = (const float*)(const void*)((const char*)(vtx_buffer + pcmd->VtxOffset) + offsetof(ImDrawVert, uv));
|
||
| ... | ... | |
|
|
||
|
// Bind texture, Draw
|
||
|
SDL_Texture* tex = (SDL_Texture*)pcmd->GetTexID();
|
||
|
SDL_RenderGeometryRaw(bd->SDLRenderer, tex,
|
||
|
SDL_RenderGeometryRaw(renderer, tex,
|
||
|
xy, (int)sizeof(ImDrawVert),
|
||
|
color, (int)sizeof(ImDrawVert),
|
||
|
uv, (int)sizeof(ImDrawVert),
|
||
|
cmd_list->VtxBuffer.Size - pcmd->VtxOffset,
|
||
|
draw_list->VtxBuffer.Size - pcmd->VtxOffset,
|
||
|
idx_buffer + pcmd->IdxOffset, pcmd->ElemCount, sizeof(ImDrawIdx));
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
platform_io.Renderer_RenderState = NULL;
|
||
|
|
||
|
// Restore modified SDL_Renderer state
|
||
|
SDL_RenderSetViewport(bd->SDLRenderer, &old.Viewport);
|
||
|
SDL_RenderSetClipRect(bd->SDLRenderer, old.ClipEnabled ? &old.ClipRect : nullptr);
|
||
|
SDL_RenderSetViewport(renderer, &old.Viewport);
|
||
|
SDL_RenderSetClipRect(renderer, old.ClipEnabled ? &old.ClipRect : nullptr);
|
||
|
}
|
||
|
|
||
|
// Called by Init/NewFrame/Shutdown
|
||
| ... | ... | |
|
|
||
|
// Upload texture to graphics system
|
||
|
// (Bilinear sampling is required by default. Set 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines' or 'style.AntiAliasedLinesUseTex = false' to allow point/nearest sampling)
|
||
|
bd->FontTexture = SDL_CreateTexture(bd->SDLRenderer, SDL_PIXELFORMAT_ABGR8888, SDL_TEXTUREACCESS_STATIC, width, height);
|
||
|
bd->FontTexture = SDL_CreateTexture(bd->Renderer, SDL_PIXELFORMAT_ABGR8888, SDL_TEXTUREACCESS_STATIC, width, height);
|
||
|
if (bd->FontTexture == nullptr)
|
||
|
{
|
||
|
SDL_Log("error creating texture");
|
||
| src/backend/imgui_impl_sdlrenderer2.h | ||
|---|---|---|
|
// Implemented features:
|
||
|
// [X] Renderer: User texture binding. Use 'SDL_Texture*' as ImTextureID. Read the FAQ about ImTextureID!
|
||
|
// [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices.
|
||
|
// [X] Renderer: Expose selected render state for draw callbacks to use. Access in '(ImGui_ImplXXXX_RenderState*)GetPlatformIO().Renderer_RenderState'.
|
||
|
|
||
|
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||
|
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||
| ... | ... | |
|
|
||
|
struct SDL_Renderer;
|
||
|
|
||
|
// Follow "Getting Started" link and check examples/ folder to learn about using backends!
|
||
|
IMGUI_IMPL_API bool ImGui_ImplSDLRenderer2_Init(SDL_Renderer* renderer);
|
||
|
IMGUI_IMPL_API void ImGui_ImplSDLRenderer2_Shutdown();
|
||
|
IMGUI_IMPL_API void ImGui_ImplSDLRenderer2_NewFrame();
|
||
|
IMGUI_IMPL_API void ImGui_ImplSDLRenderer2_RenderDrawData(ImDrawData* draw_data);
|
||
|
IMGUI_IMPL_API void ImGui_ImplSDLRenderer2_RenderDrawData(ImDrawData* draw_data, SDL_Renderer* renderer);
|
||
|
|
||
|
// Called by Init/NewFrame/Shutdown
|
||
|
IMGUI_IMPL_API bool ImGui_ImplSDLRenderer2_CreateFontsTexture();
|
||
| ... | ... | |
|
IMGUI_IMPL_API bool ImGui_ImplSDLRenderer2_CreateDeviceObjects();
|
||
|
IMGUI_IMPL_API void ImGui_ImplSDLRenderer2_DestroyDeviceObjects();
|
||
|
|
||
|
// [BETA] Selected render state data shared with callbacks.
|
||
|
// This is temporarily stored in GetPlatformIO().Renderer_RenderState during the ImGui_ImplSDLRenderer2_RenderDrawData() call.
|
||
|
// (Please open an issue if you feel you need access to more data)
|
||
|
struct ImGui_ImplSDLRenderer2_RenderState
|
||
|
{
|
||
|
SDL_Renderer* Renderer;
|
||
|
};
|
||
|
|
||
|
#endif // #ifndef IMGUI_DISABLE
|
||
| src/imgui/imconfig.h | ||
|---|---|---|
|
|
||
|
//---- Define attributes of all API symbols declarations, e.g. for DLL under Windows
|
||
|
// Using Dear ImGui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility.
|
||
|
// DLL users: heaps and globals are not shared across DLL boundaries! You will need to call SetCurrentContext() + SetAllocatorFunctions()
|
||
|
// for each static/DLL boundary you are calling from. Read "Context and Memory Allocators" section of imgui.cpp for more details.
|
||
|
//#define IMGUI_API __declspec( dllexport )
|
||
|
//#define IMGUI_API __declspec( dllimport )
|
||
|
// - Windows DLL users: heaps and globals are not shared across DLL boundaries! You will need to call SetCurrentContext() + SetAllocatorFunctions()
|
||
|
// for each static/DLL boundary you are calling from. Read "Context and Memory Allocators" section of imgui.cpp for more details.
|
||
|
//#define IMGUI_API __declspec(dllexport) // MSVC Windows: DLL export
|
||
|
//#define IMGUI_API __declspec(dllimport) // MSVC Windows: DLL import
|
||
|
//#define IMGUI_API __attribute__((visibility("default"))) // GCC/Clang: override visibility when set is hidden
|
||
|
|
||
|
//---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to clean your code of obsolete function/names.
|
||
|
//#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||
|
//#define IMGUI_DISABLE_OBSOLETE_KEYIO // 1.87+ disable legacy io.KeyMap[]+io.KeysDown[] in favor io.AddKeyEvent(). This is automatically done by IMGUI_DISABLE_OBSOLETE_FUNCTIONS.
|
||
|
|
||
|
//---- Disable all of Dear ImGui or don't implement standard windows/tools.
|
||
|
// It is very strongly recommended to NOT disable the demo windows and debug tool during development. They are extremely useful in day to day work. Please read comments in imgui_demo.cpp.
|
||
| ... | ... | |
|
//#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with non-Visual Studio compilers] Don't implement default IME handler (won't require imm32.lib/.a)
|
||
|
//#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function (clipboard, IME).
|
||
|
//#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement default OSX clipboard handler (need to link with '-framework ApplicationServices', this is why this is not the default).
|
||
|
//#define IMGUI_DISABLE_DEFAULT_SHELL_FUNCTIONS // Don't implement default platform_io.Platform_OpenInShellFn() handler (Win32: ShellExecute(), require shell32.lib/.a, Mac/Linux: use system("")).
|
||
|
//#define IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf)
|
||
|
//#define IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 so you can implement them yourself.
|
||
|
//#define IMGUI_DISABLE_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle at all (replace them with dummies)
|
||
| ... | ... | |
|
//#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions().
|
||
|
//#define IMGUI_DISABLE_SSE // Disable use of SSE intrinsics even if available
|
||
|
|
||
|
//---- Enable Test Engine / Automation features.
|
||
|
//#define IMGUI_ENABLE_TEST_ENGINE // Enable imgui_test_engine hooks. Generally set automatically by include "imgui_te_config.h", see Test Engine for details.
|
||
|
|
||
|
//---- Include imgui_user.h at the end of imgui.h as a convenience
|
||
|
// May be convenient for some users to only explicitly include vanilla imgui.h and have extra stuff included.
|
||
|
//#define IMGUI_INCLUDE_IMGUI_USER_H
|
||
| ... | ... | |
|
// On Windows you may use vcpkg with 'vcpkg install freetype --triplet=x64-windows' + 'vcpkg integrate install'.
|
||
|
//#define IMGUI_ENABLE_FREETYPE
|
||
|
|
||
|
//---- Use FreeType+lunasvg library to render OpenType SVG fonts (SVGinOT)
|
||
|
// Requires lunasvg headers to be available in the include path + program to be linked with the lunasvg library (not provided).
|
||
|
//---- Use FreeType + plutosvg or lunasvg to render OpenType SVG fonts (SVGinOT)
|
||
|
// Only works in combination with IMGUI_ENABLE_FREETYPE.
|
||
|
// (implementation is based on Freetype's rsvg-port.c which is licensed under CeCILL-C Free Software License Agreement)
|
||
|
// - lunasvg is currently easier to acquire/install, as e.g. it is part of vcpkg.
|
||
|
// - plutosvg will support more fonts and may load them faster. It currently requires to be built manually but it is fairly easy. See misc/freetype/README for instructions.
|
||
|
// - Both require headers to be available in the include path + program to be linked with the library code (not provided).
|
||
|
// - (note: lunasvg implementation is based on Freetype's rsvg-port.c which is licensed under CeCILL-C Free Software License Agreement)
|
||
|
//#define IMGUI_ENABLE_FREETYPE_PLUTOSVG
|
||
|
//#define IMGUI_ENABLE_FREETYPE_LUNASVG
|
||
|
|
||
|
//---- Use stb_truetype to build and rasterize the font atlas (default)
|
||
| src/imgui/imgui.cpp | ||
|---|---|---|
|
// dear imgui, v1.90.2 WIP
|
||
|
// dear imgui, v1.91.5
|
||
|
// (main code and documentation)
|
||
|
|
||
|
// Help:
|
||
| ... | ... | |
|
// - Read top of imgui.cpp for more details, links and comments.
|
||
|
|
||
|
// Resources:
|
||
|
// - FAQ https://dearimgui.com/faq
|
||
|
// - Getting Started https://dearimgui.com/getting-started
|
||
|
// - Homepage https://github.com/ocornut/imgui
|
||
|
// - Releases & changelog https://github.com/ocornut/imgui/releases
|
||
|
// - Gallery https://github.com/ocornut/imgui/issues/6897 (please post your screenshots/video there!)
|
||
|
// - Wiki https://github.com/ocornut/imgui/wiki (lots of good stuff there)
|
||
|
// - Glossary https://github.com/ocornut/imgui/wiki/Glossary
|
||
|
// - Issues & support https://github.com/ocornut/imgui/issues
|
||
|
// - Tests & Automation https://github.com/ocornut/imgui_test_engine
|
||
|
// - FAQ ........................ https://dearimgui.com/faq (in repository as docs/FAQ.md)
|
||
|
// - Homepage ................... https://github.com/ocornut/imgui
|
||
|
// - Releases & changelog ....... https://github.com/ocornut/imgui/releases
|
||
|
// - Gallery .................... https://github.com/ocornut/imgui/issues?q=label%3Agallery (please post your screenshots/video there!)
|
||
|
// - Wiki ....................... https://github.com/ocornut/imgui/wiki (lots of good stuff there)
|
||
|
// - Getting Started https://github.com/ocornut/imgui/wiki/Getting-Started (how to integrate in an existing app by adding ~25 lines of code)
|
||
|
// - Third-party Extensions https://github.com/ocornut/imgui/wiki/Useful-Extensions (ImPlot & many more)
|
||
|
// - Bindings/Backends https://github.com/ocornut/imgui/wiki/Bindings (language bindings, backends for various tech/engines)
|
||
|
// - Glossary https://github.com/ocornut/imgui/wiki/Glossary
|
||
|
// - Debug Tools https://github.com/ocornut/imgui/wiki/Debug-Tools
|
||
|
// - Software using Dear ImGui https://github.com/ocornut/imgui/wiki/Software-using-dear-imgui
|
||
|
// - Issues & support ........... https://github.com/ocornut/imgui/issues
|
||
|
// - Test Engine & Automation ... https://github.com/ocornut/imgui_test_engine (test suite, test engine to automate your apps)
|
||
|
|
||
|
// For first-time users having issues compiling/linking/running/loading fonts:
|
||
|
// please post in https://github.com/ocornut/imgui/discussions if you cannot find a solution in resources above.
|
||
| ... | ... | |
|
// See LICENSE.txt for copyright and licensing details (standard MIT License).
|
||
|
// This library is free but needs your support to sustain development and maintenance.
|
||
|
// Businesses: you can support continued development via B2B invoiced technical support, maintenance and sponsoring contracts.
|
||
|
// PLEASE reach out at omar AT dearimgui DOT com. See https://github.com/ocornut/imgui/wiki/Sponsors
|
||
|
// PLEASE reach out at omar AT dearimgui DOT com. See https://github.com/ocornut/imgui/wiki/Funding
|
||
|
// Businesses: you can also purchase licenses for the Dear ImGui Automation/Test Engine.
|
||
|
|
||
|
// It is recommended that you don't modify imgui.cpp! It will become difficult for you to update the library.
|
||
| ... | ... | |
|
// [SECTION] INCLUDES
|
||
|
// [SECTION] FORWARD DECLARATIONS
|
||
|
// [SECTION] CONTEXT AND MEMORY ALLOCATORS
|
||
|
// [SECTION] USER FACING STRUCTURES (ImGuiStyle, ImGuiIO)
|
||
|
// [SECTION] USER FACING STRUCTURES (ImGuiStyle, ImGuiIO, ImGuiPlatformIO)
|
||
|
// [SECTION] MISC HELPERS/UTILITIES (Geometry functions)
|
||
|
// [SECTION] MISC HELPERS/UTILITIES (String, Format, Hash functions)
|
||
|
// [SECTION] MISC HELPERS/UTILITIES (File functions)
|
||
| ... | ... | |
|
// [SECTION] RENDER HELPERS
|
||
|
// [SECTION] INITIALIZATION, SHUTDOWN
|
||
|
// [SECTION] MAIN CODE (most of the code! lots of stuff, needs tidying up!)
|
||
|
// [SECTION] ID STACK
|
||
|
// [SECTION] INPUTS
|
||
|
// [SECTION] ERROR CHECKING
|
||
|
// [SECTION] ERROR CHECKING, STATE RECOVERY
|
||
|
// [SECTION] ITEM SUBMISSION
|
||
|
// [SECTION] LAYOUT
|
||
|
// [SECTION] SCROLLING
|
||
| ... | ... | |
|
- CTRL+X, CTRL+C, CTRL+V: Use OS clipboard.
|
||
|
- CTRL+Z, CTRL+Y: Undo, Redo.
|
||
|
- ESCAPE: Revert text to its original value.
|
||
|
- On OSX, controls are automatically adjusted to match standard OSX text editing shortcuts and behaviors.
|
||
|
- On OSX, controls are automatically adjusted to match standard OSX text editing 2ts and behaviors.
|
||
|
|
||
|
- KEYBOARD CONTROLS
|
||
|
- Basic:
|
||
| ... | ... | |
|
- Set 'io.BackendFlags |= ImGuiBackendFlags_HasGamepad' + call io.AddKeyEvent/AddKeyAnalogEvent() with ImGuiKey_Gamepad_XXX keys.
|
||
|
- For analog values (0.0f to 1.0f), backend is responsible to handling a dead-zone and rescaling inputs accordingly.
|
||
|
Backend code will probably need to transform your raw inputs (such as e.g. remapping your 0.2..0.9 raw input range to 0.0..1.0 imgui range, etc.).
|
||
|
- BEFORE 1.87, BACKENDS USED TO WRITE TO io.NavInputs[]. This is now obsolete. Please call io functions instead!
|
||
|
- If you need to share inputs between your game and the Dear ImGui interface, the easiest approach is to go all-or-nothing,
|
||
|
with a buttons combo to toggle the target. Please reach out if you think the game vs navigation input sharing could be improved.
|
||
|
|
||
| ... | ... | |
|
- Consoles/Tablet/Phone users: Consider using a Synergy 1.x server (on your PC) + run examples/libs/synergy/uSynergy.c (on your console/tablet/phone app)
|
||
|
in order to share your PC mouse/keyboard.
|
||
|
- See https://github.com/ocornut/imgui/wiki/Useful-Extensions#remoting for other remoting solutions.
|
||
|
- On a TV/console system where readability may be lower or mouse inputs may be awkward, you may want to set the ImGuiConfigFlags_NavEnableSetMousePos flag.
|
||
|
Enabling ImGuiConfigFlags_NavEnableSetMousePos + ImGuiBackendFlags_HasSetMousePos instructs Dear ImGui to move your mouse cursor along with navigation movements.
|
||
|
- On a TV/console system where readability may be lower or mouse inputs may be awkward, you may want to set the io.ConfigNavMoveSetMousePos flag.
|
||
|
Enabling io.ConfigNavMoveSetMousePos + ImGuiBackendFlags_HasSetMousePos instructs Dear ImGui to move your mouse cursor along with navigation movements.
|
||
|
When enabled, the NewFrame() function may alter 'io.MousePos' and set 'io.WantSetMousePos' to notify you that it wants the mouse cursor to be moved.
|
||
|
When that happens your backend NEEDS to move the OS or underlying mouse cursor on the next frame. Some of the backends in examples/ do that.
|
||
|
(If you set the NavEnableSetMousePos flag but don't honor 'io.WantSetMousePos' properly, Dear ImGui will misbehave as it will see your mouse moving back & forth!)
|
||
| ... | ... | |
|
When you are not sure about an old symbol or function name, try using the Search/Find function of your IDE to look for comments or references in all imgui files.
|
||
|
You can read releases logs https://github.com/ocornut/imgui/releases for more details.
|
||
|
|
||
|
- 2024/11/06 (1.91.5) - commented/obsoleted out pre-1.87 IO system (equivalent to using IMGUI_DISABLE_OBSOLETE_KEYIO or IMGUI_DISABLE_OBSOLETE_FUNCTIONS before)
|
||
|
- io.KeyMap[] and io.KeysDown[] are removed (obsoleted February 2022).
|
||
|
- io.NavInputs[] and ImGuiNavInput are removed (obsoleted July 2022).
|
||
|
- pre-1.87 backends are not supported:
|
||
|
- backends need to call io.AddKeyEvent(), io.AddMouseEvent() instead of writing to io.KeysDown[], io.MouseDown[] fields.
|
||
|
- backends need to call io.AddKeyAnalogEvent() for gamepad values instead of writing to io.NavInputs[] fields.
|
||
|
- for more reference:
|
||
|
- read 1.87 and 1.88 part of this section or read Changelog for 1.87 and 1.88.
|
||
|
- read https://github.com/ocornut/imgui/issues/4921
|
||
|
- if you have trouble updating a very old codebase using legacy backend-specific key codes: consider updating to 1.91.4 first, then #define IMGUI_DISABLE_OBSOLETE_KEYIO, then update to latest.
|
||
|
- obsoleted ImGuiKey_COUNT (it is unusually error-prone/misleading since valid keys don't start at 0). probably use ImGuiKey_NamedKey_BEGIN/ImGuiKey_NamedKey_END?
|
||
|
- fonts: removed const qualifiers from most font functions in prevision for upcoming font improvements.
|
||
|
- 2024/10/18 (1.91.4) - renamed ImGuiCol_NavHighlight to ImGuiCol_NavCursor (for consistency with newly exposed and reworked features). Kept inline redirection enum (will obsolete).
|
||
|
- 2024/10/14 (1.91.4) - moved ImGuiConfigFlags_NavEnableSetMousePos to standalone io.ConfigNavMoveSetMousePos bool.
|
||
|
moved ImGuiConfigFlags_NavNoCaptureKeyboard to standalone io.ConfigNavCaptureKeyboard bool (note the inverted value!).
|
||
|
kept legacy names (will obsolete) + code that copies settings once the first time. Dynamically changing the old value won't work. Switch to using the new value!
|
||
|
- 2024/10/10 (1.91.4) - the typedef for ImTextureID now defaults to ImU64 instead of void*. (#1641)
|
||
|
this removes the requirement to redefine it for backends which are e.g. storing descriptor sets or other 64-bits structures when building on 32-bits archs. It therefore simplify various building scripts/helpers.
|
||
|
you may have compile-time issues if you were casting to 'void*' instead of 'ImTextureID' when passing your types to functions taking ImTextureID values, e.g. ImGui::Image().
|
||
|
in doubt it is almost always better to do an intermediate intptr_t cast, since it allows casting any pointer/integer type without warning:
|
||
|
- May warn: ImGui::Image((void*)MyTextureData, ...);
|
||
|
- May warn: ImGui::Image((void*)(intptr_t)MyTextureData, ...);
|
||
|
- Won't warn: ImGui::Image((ImTextureID)(intptr_t)MyTextureData), ...);
|
||
|
- note that you can always define ImTextureID to be your own high-level structures (with dedicated constructors) if you like.
|
||
|
- 2024/10/03 (1.91.3) - drags: treat v_min==v_max as a valid clamping range when != 0.0f. Zero is a still special value due to legacy reasons, unless using ImGuiSliderFlags_ClampZeroRange. (#7968, #3361, #76)
|
||
|
- drags: extended behavior of ImGuiSliderFlags_AlwaysClamp to include _ClampZeroRange. It considers v_min==v_max==0.0f as a valid clamping range (aka edits not allowed).
|
||
|
although unlikely, it you wish to only clamp on text input but want v_min==v_max==0.0f to mean unclamped drags, you can use _ClampOnInput instead of _AlwaysClamp. (#7968, #3361, #76)
|
||
|
- 2024/09/10 (1.91.2) - internals: using multiple overlayed ButtonBehavior() with same ID will now have io.ConfigDebugHighlightIdConflicts=true feature emit a warning. (#8030)
|
||
|
it was one of the rare case where using same ID is legal. workarounds: (1) use single ButtonBehavior() call with multiple _MouseButton flags, or (2) surround the calls with PushItemFlag(ImGuiItemFlags_AllowDuplicateId, true); ... PopItemFlag()
|
||
|
- 2024/08/23 (1.91.1) - renamed ImGuiChildFlags_Border to ImGuiChildFlags_Borders for consistency. kept inline redirection flag.
|
||
|
- 2024/08/22 (1.91.1) - moved some functions from ImGuiIO to ImGuiPlatformIO structure:
|
||
|
- io.GetClipboardTextFn -> platform_io.Platform_GetClipboardTextFn + changed 'void* user_data' to 'ImGuiContext* ctx'. Pull your user data from platform_io.ClipboardUserData.
|
||
|
- io.SetClipboardTextFn -> platform_io.Platform_SetClipboardTextFn + same as above line.
|
||
|
- io.PlatformOpenInShellFn -> platform_io.Platform_OpenInShellFn (#7660)
|
||
|
- io.PlatformSetImeDataFn -> platform_io.Platform_SetImeDataFn
|
||
|
- io.PlatformLocaleDecimalPoint -> platform_io.Platform_LocaleDecimalPoint (#7389, #6719, #2278)
|
||
|
- access those via GetPlatformIO() instead of GetIO().
|
||
|
some were introduced very recently and often automatically setup by core library and backends, so for those we are exceptionally not maintaining a legacy redirection symbol.
|
||
|
- commented the old ImageButton() signature obsoleted in 1.89 (~August 2022). As a reminder:
|
||
|
- old ImageButton() before 1.89 used ImTextureId as item id (created issue with e.g. multiple buttons in same scope, transient texture id values, opaque computation of ID)
|
||
|
- new ImageButton() since 1.89 requires an explicit 'const char* str_id'
|
||
|
- old ImageButton() before 1.89 had frame_padding' override argument.
|
||
|
- new ImageButton() since 1.89 always use style.FramePadding, which you can freely override with PushStyleVar()/PopStyleVar().
|
||
|
- 2024/07/25 (1.91.0) - obsoleted GetContentRegionMax(), GetWindowContentRegionMin() and GetWindowContentRegionMax(). (see #7838 on GitHub for more info)
|
||
|
you should never need those functions. you can do everything with GetCursorScreenPos() and GetContentRegionAvail() in a more simple way.
|
||
|
- instead of: GetWindowContentRegionMax().x - GetCursorPos().x
|
||
|
- you can use: GetContentRegionAvail().x
|
||
|
- instead of: GetWindowContentRegionMax().x + GetWindowPos().x
|
||
|
- you can use: GetCursorScreenPos().x + GetContentRegionAvail().x // when called from left edge of window
|
||
|
- instead of: GetContentRegionMax()
|
||
|
- you can use: GetContentRegionAvail() + GetCursorScreenPos() - GetWindowPos() // right edge in local coordinates
|
||
|
- instead of: GetWindowContentRegionMax().x - GetWindowContentRegionMin().x
|
||
|
- you can use: GetContentRegionAvail() // when called from left edge of window
|
||
|
- 2024/07/15 (1.91.0) - renamed ImGuiSelectableFlags_DontClosePopups to ImGuiSelectableFlags_NoAutoClosePopups. (#1379, #1468, #2200, #4936, #5216, #7302, #7573)
|
||
|
(internals: also renamed ImGuiItemFlags_SelectableDontClosePopup into ImGuiItemFlags_AutoClosePopups with inverted behaviors)
|
||
|
- 2024/07/15 (1.91.0) - obsoleted PushButtonRepeat()/PopButtonRepeat() in favor of using new PushItemFlag(ImGuiItemFlags_ButtonRepeat, ...)/PopItemFlag().
|
||
|
- 2024/07/02 (1.91.0) - commented out obsolete ImGuiModFlags (renamed to ImGuiKeyChord in 1.89). (#4921, #456)
|
||
|
- commented out obsolete ImGuiModFlags_XXX values (renamed to ImGuiMod_XXX in 1.89). (#4921, #456)
|
||
|
- ImGuiModFlags_Ctrl -> ImGuiMod_Ctrl, ImGuiModFlags_Shift -> ImGuiMod_Shift etc.
|
||
|
- 2024/07/02 (1.91.0) - IO, IME: renamed platform IME hook and added explicit context for consistency and future-proofness.
|
||
|
- old: io.SetPlatformImeDataFn(ImGuiViewport* viewport, ImGuiPlatformImeData* data);
|
||
|
- new: io.PlatformSetImeDataFn(ImGuiContext* ctx, ImGuiViewport* viewport, ImGuiPlatformImeData* data);
|
||
|
- 2024/06/21 (1.90.9) - BeginChild: added ImGuiChildFlags_NavFlattened as a replacement for the window flag ImGuiWindowFlags_NavFlattened: the feature only ever made sense for BeginChild() anyhow.
|
||
|
- old: BeginChild("Name", size, 0, ImGuiWindowFlags_NavFlattened);
|
||
|
- new: BeginChild("Name", size, ImGuiChildFlags_NavFlattened, 0);
|
||
|
- 2024/06/21 (1.90.9) - io: ClearInputKeys() (first exposed in 1.89.8) doesn't clear mouse data, newly added ClearInputMouse() does.
|
||
|
- 2024/06/20 (1.90.9) - renamed ImGuiDragDropFlags_SourceAutoExpirePayload to ImGuiDragDropFlags_PayloadAutoExpire.
|
||
|
- 2024/06/18 (1.90.9) - style: renamed ImGuiCol_TabActive -> ImGuiCol_TabSelected, ImGuiCol_TabUnfocused -> ImGuiCol_TabDimmed, ImGuiCol_TabUnfocusedActive -> ImGuiCol_TabDimmedSelected.
|
||
|
- 2024/06/10 (1.90.9) - removed old nested structure: renaming ImGuiStorage::ImGuiStoragePair type to ImGuiStoragePair (simpler for many languages).
|
||
|
- 2024/06/06 (1.90.8) - reordered ImGuiInputTextFlags values. This should not be breaking unless you are using generated headers that have values not matching the main library.
|
||
|
- 2024/06/06 (1.90.8) - removed 'ImGuiButtonFlags_MouseButtonDefault_ = ImGuiButtonFlags_MouseButtonLeft', was mostly unused and misleading.
|
||
|
- 2024/05/27 (1.90.7) - commented out obsolete symbols marked obsolete in 1.88 (May 2022):
|
||
|
- old: CaptureKeyboardFromApp(bool)
|
||
|
- new: SetNextFrameWantCaptureKeyboard(bool)
|
||
|
- old: CaptureMouseFromApp(bool)
|
||
|
- new: SetNextFrameWantCaptureMouse(bool)
|
||
|
- 2024/05/22 (1.90.7) - inputs (internals): renamed ImGuiKeyOwner_None to ImGuiKeyOwner_NoOwner, to make use more explicit and reduce confusion with the default it is a non-zero value and cannot be the default value (never made public, but disclosing as I expect a few users caught on owner-aware inputs).
|
||
|
- inputs (internals): renamed ImGuiInputFlags_RouteGlobalLow -> ImGuiInputFlags_RouteGlobal, ImGuiInputFlags_RouteGlobal -> ImGuiInputFlags_RouteGlobalOverFocused, ImGuiInputFlags_RouteGlobalHigh -> ImGuiInputFlags_RouteGlobalHighest.
|
||
|
- inputs (internals): Shortcut(), SetShortcutRouting(): swapped last two parameters order in function signatures:
|
||
|
- old: Shortcut(ImGuiKeyChord key_chord, ImGuiID owner_id = 0, ImGuiInputFlags flags = 0);
|
||
|
- new: Shortcut(ImGuiKeyChord key_chord, ImGuiInputFlags flags = 0, ImGuiID owner_id = 0);
|
||
|
- inputs (internals): owner-aware versions of IsKeyPressed(), IsKeyChordPressed(), IsMouseClicked(): swapped last two parameters order in function signatures.
|
||
|
- old: IsKeyPressed(ImGuiKey key, ImGuiID owner_id, ImGuiInputFlags flags = 0);
|
||
|
- new: IsKeyPressed(ImGuiKey key, ImGuiInputFlags flags, ImGuiID owner_id = 0);
|
||
|
- old: IsMouseClicked(ImGuiMouseButton button, ImGuiID owner_id, ImGuiInputFlags flags = 0);
|
||
|
- new: IsMouseClicked(ImGuiMouseButton button, ImGuiInputFlags flags, ImGuiID owner_id = 0);
|
||
|
for various reasons those changes makes sense. They are being made because making some of those API public.
|
||
|
only past users of imgui_internal.h with the extra parameters will be affected. Added asserts for valid flags in various functions to detect _some_ misuses, BUT NOT ALL.
|
||
|
- 2024/05/16 (1.90.7) - inputs: on macOS X, Cmd and Ctrl keys are now automatically swapped by io.AddKeyEvent() as this naturally align with how macOS X uses those keys.
|
||
|
- it shouldn't really affect you unless you had custom shortcut swapping in place for macOS X apps.
|
||
|
- removed ImGuiMod_Shortcut which was previously dynamically remapping to Ctrl or Cmd/Super. It is now unnecessary to specific cross-platform idiomatic shortcuts. (#2343, #4084, #5923, #456)
|
||
|
- 2024/05/14 (1.90.7) - backends: SDL_Renderer2 and SDL_Renderer3 backend now take a SDL_Renderer* in their RenderDrawData() functions.
|
||
|
- 2024/04/18 (1.90.6) - TreeNode: Fixed a layout inconsistency when using an empty/hidden label followed by a SameLine() call. (#7505, #282)
|
||
|
- old: TreeNode("##Hidden"); SameLine(); Text("Hello"); // <-- This was actually incorrect! BUT appeared to look ok with the default style where ItemSpacing.x == FramePadding.x * 2 (it didn't look aligned otherwise).
|
||
|
- new: TreeNode("##Hidden"); SameLine(0, 0); Text("Hello"); // <-- This is correct for all styles values.
|
||
|
with the fix, IF you were successfully using TreeNode("")+SameLine(); you will now have extra spacing between your TreeNode and the following item.
|
||
|
You'll need to change the SameLine() call to SameLine(0,0) to remove this extraneous spacing. This seemed like the more sensible fix that's not making things less consistent.
|
||
|
(Note: when using this idiom you are likely to also use ImGuiTreeNodeFlags_SpanAvailWidth).
|
||
|
- 2024/03/18 (1.90.5) - merged the radius_x/radius_y parameters in ImDrawList::AddEllipse(), AddEllipseFilled() and PathEllipticalArcTo() into a single ImVec2 parameter. Exceptionally, because those functions were added in 1.90, we are not adding inline redirection functions. The transition is easy and should affect few users. (#2743, #7417)
|
||
|
- 2024/03/08 (1.90.5) - inputs: more formally obsoleted GetKeyIndex() when IMGUI_DISABLE_OBSOLETE_FUNCTIONS is set. It has been unnecessary and a no-op since 1.87 (it returns the same value as passed when used with a 1.87+ backend using io.AddKeyEvent() function). (#4921)
|
||
|
- IsKeyPressed(GetKeyIndex(ImGuiKey_XXX)) -> use IsKeyPressed(ImGuiKey_XXX)
|
||
|
- 2024/01/15 (1.90.2) - commented out obsolete ImGuiIO::ImeWindowHandle marked obsolete in 1.87, favor of writing to 'void* ImGuiViewport::PlatformHandleRaw'.
|
||
|
- 2023/12/19 (1.90.1) - commented out obsolete ImGuiKey_KeyPadEnter redirection to ImGuiKey_KeypadEnter.
|
||
|
- 2023/11/06 (1.90.1) - removed CalcListClipping() marked obsolete in 1.86. Prefer using ImGuiListClipper which can return non-contiguous ranges.
|
||
| ... | ... | |
|
- new: BeginChild("Name", size, ImGuiChildFlags_Border)
|
||
|
- old: BeginChild("Name", size, false)
|
||
|
- new: BeginChild("Name", size) or BeginChild("Name", 0) or BeginChild("Name", size, ImGuiChildFlags_None)
|
||
|
**AMEND FROM THE FUTURE: from 1.91.1, 'ImGuiChildFlags_Border' is called 'ImGuiChildFlags_Borders'**
|
||
|
- 2023/11/02 (1.90.0) - BeginChild: added child-flag ImGuiChildFlags_AlwaysUseWindowPadding as a replacement for the window-flag ImGuiWindowFlags_AlwaysUseWindowPadding: the feature only ever made sense for BeginChild() anyhow.
|
||
|
- old: BeginChild("Name", size, 0, ImGuiWindowFlags_AlwaysUseWindowPadding);
|
||
|
- new: BeginChild("Name", size, ImGuiChildFlags_AlwaysUseWindowPadding, 0);
|
||
| ... | ... | |
|
- Backend writing to io.MouseHoveredViewport -> backend should call io.AddMouseViewportEvent() [Docking branch w/ multi-viewports only]
|
||
|
note: for all calls to IO new functions, the Dear ImGui context should be bound/current.
|
||
|
read https://github.com/ocornut/imgui/issues/4921 for details.
|
||
|
- 2022/01/10 (1.87) - inputs: reworked keyboard IO. Removed io.KeyMap[], io.KeysDown[] in favor of calling io.AddKeyEvent(). Removed GetKeyIndex(), now unecessary. All IsKeyXXX() functions now take ImGuiKey values. All features are still functional until IMGUI_DISABLE_OBSOLETE_KEYIO is defined. Read Changelog and Release Notes for details.
|
||
|
- 2022/01/10 (1.87) - inputs: reworked keyboard IO. Removed io.KeyMap[], io.KeysDown[] in favor of calling io.AddKeyEvent(). Removed GetKeyIndex(), now unnecessary. All IsKeyXXX() functions now take ImGuiKey values. All features are still functional until IMGUI_DISABLE_OBSOLETE_KEYIO is defined. Read Changelog and Release Notes for details.
|
||
|
- IsKeyPressed(MY_NATIVE_KEY_XXX) -> use IsKeyPressed(ImGuiKey_XXX)
|
||
|
- IsKeyPressed(GetKeyIndex(ImGuiKey_XXX)) -> use IsKeyPressed(ImGuiKey_XXX)
|
||
|
- Backend writing to io.KeyMap[],io.KeysDown[] -> backend should call io.AddKeyEvent() (+ call io.SetKeyEventNativeData() if you want legacy user code to stil function with legacy key codes).
|
||
| ... | ... | |
|
Q: How can I easily use icons in my application?
|
||
|
Q: How can I load multiple fonts?
|
||
|
Q: How can I display and input non-Latin characters such as Chinese, Japanese, Korean, Cyrillic?
|
||
|
>> See https://www.dearimgui.com/faq and https://github.com/ocornut/imgui/edit/master/docs/FONTS.md
|
||
|
>> See https://www.dearimgui.com/faq and https://github.com/ocornut/imgui/blob/master/docs/FONTS.md
|
||
|
|
||
|
Q&A: Concerns
|
||
|
=============
|
||
| ... | ... | |
|
A: - Businesses: please reach out to "omar AT dearimgui DOT com" if you work in a place using Dear ImGui!
|
||
|
We can discuss ways for your company to fund development via invoiced technical support, maintenance or sponsoring contacts.
|
||
|
This is among the most useful thing you can do for Dear ImGui. With increased funding, we sustain and grow work on this project.
|
||
|
Also see https://github.com/ocornut/imgui/wiki/Sponsors
|
||
|
>>> See https://github.com/ocornut/imgui/wiki/Funding
|
||
|
- Businesses: you can also purchase licenses for the Dear ImGui Automation/Test Engine.
|
||
|
- If you are experienced with Dear ImGui and C++, look at the GitHub issues, look at the Wiki, and see how you want to help and can help!
|
||
|
- Disclose your usage of Dear ImGui via a dev blog post, a tweet, a screenshot, a mention somewhere etc.
|
||
| ... | ... | |
|
#endif
|
||
|
|
||
|
// [Windows] OS specific includes (optional)
|
||
|
#if defined(_WIN32) && defined(IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS) && defined(IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS) && defined(IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS)
|
||
|
#if defined(_WIN32) && defined(IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS) && defined(IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS) && defined(IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS) && defined(IMGUI_DISABLE_DEFAULT_SHELL_FUNCTIONS) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS)
|
||
|
#define IMGUI_DISABLE_WIN32_FUNCTIONS
|
||
|
#endif
|
||
|
#if defined(_WIN32) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS)
|
||
| ... | ... | |
|
#else
|
||
|
#include <windows.h>
|
||
|
#endif
|
||
|
#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP) // UWP doesn't have all Win32 functions
|
||
|
#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP || WINAPI_FAMILY == WINAPI_FAMILY_GAMES)
|
||
|
// The UWP and GDK Win32 API subsets don't support clipboard nor IME functions
|
||
|
#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS
|
||
|
#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS
|
||
|
#define IMGUI_DISABLE_DEFAULT_SHELL_FUNCTIONS
|
||
|
#endif
|
||
|
#endif
|
||
|
|
||
| ... | ... | |
|
#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant" // warning: zero as null pointer constant // some standard header variations use #define NULL 0
|
||
|
#pragma clang diagnostic ignored "-Wdouble-promotion" // warning: implicit conversion from 'float' to 'double' when passing argument to function // using printf() is a misery with this as C++ va_arg ellipsis changes float to double.
|
||
|
#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion" // warning: implicit conversion from 'xxx' to 'float' may lose precision
|
||
|
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage" // warning: 'xxx' is an unsafe pointer used for buffer access
|
||
|
#pragma clang diagnostic ignored "-Wnontrivial-memaccess" // warning: first argument in call to 'memset' is a pointer to non-trivially copyable type
|
||
|
#elif defined(__GNUC__)
|
||
|
// We disable -Wpragmas because GCC doesn't provide a has_warning equivalent and some forks/patches may not follow the warning/version association.
|
||
|
#pragma GCC diagnostic ignored "-Wpragmas" // warning: unknown option after '#pragma GCC diagnostic' kind
|
||
|
#pragma GCC diagnostic ignored "-Wunused-function" // warning: 'xxxx' defined but not used
|
||
|
#pragma GCC diagnostic ignored "-Wint-to-pointer-cast" // warning: cast to pointer from integer of different size
|
||
|
#pragma GCC diagnostic ignored "-Wformat" // warning: format '%p' expects argument of type 'void*', but argument 6 has type 'ImGuiWindow*'
|
||
|
#pragma GCC diagnostic ignored "-Wdouble-promotion" // warning: implicit conversion from 'float' to 'double' when passing argument to function
|
||
|
#pragma GCC diagnostic ignored "-Wconversion" // warning: conversion to 'xxxx' from 'xxxx' may alter its value
|
||
|
#pragma GCC diagnostic ignored "-Wformat-nonliteral" // warning: format not a string literal, format string not checked
|
||
|
#pragma GCC diagnostic ignored "-Wstrict-overflow" // warning: assuming signed overflow does not occur when assuming that (X - c) > X is always false
|
||
|
#pragma GCC diagnostic ignored "-Wclass-memaccess" // [__GNUC__ >= 8] warning: 'memset/memcpy' clearing/writing an object of type 'xxxx' with no trivial copy-assignment; use assignment or value-initialization instead
|
||
|
#pragma GCC diagnostic ignored "-Wpragmas" // warning: unknown option after '#pragma GCC diagnostic' kind
|
||
|
#pragma GCC diagnostic ignored "-Wunused-function" // warning: 'xxxx' defined but not used
|
||
|
#pragma GCC diagnostic ignored "-Wint-to-pointer-cast" // warning: cast to pointer from integer of different size
|
||
|
#pragma GCC diagnostic ignored "-Wformat" // warning: format '%p' expects argument of type 'void*', but argument 6 has type 'ImGuiWindow*'
|
||
|
#pragma GCC diagnostic ignored "-Wdouble-promotion" // warning: implicit conversion from 'float' to 'double' when passing argument to function
|
||
|
#pragma GCC diagnostic ignored "-Wconversion" // warning: conversion to 'xxxx' from 'xxxx' may alter its value
|
||
|
#pragma GCC diagnostic ignored "-Wformat-nonliteral" // warning: format not a string literal, format string not checked
|
||
|
#pragma GCC diagnostic ignored "-Wstrict-overflow" // warning: assuming signed overflow does not occur when assuming that (X - c) > X is always false
|
||
|
#pragma GCC diagnostic ignored "-Wclass-memaccess" // [__GNUC__ >= 8] warning: 'memset/memcpy' clearing/writing an object of type 'xxxx' with no trivial copy-assignment; use assignment or value-initialization instead
|
||
|
#endif
|
||
|
|
||
|
// Debug options
|
||
|
#define IMGUI_DEBUG_NAV_SCORING 0 // Display navigation scoring preview when hovering items. Display last moving direction matches when holding CTRL
|
||
|
#define IMGUI_DEBUG_NAV_SCORING 0 // Display navigation scoring preview when hovering items. Hold CTRL to display for all candidates. CTRL+Arrow to change last direction.
|
||
|
#define IMGUI_DEBUG_NAV_RECTS 0 // Display the reference navigation rectangle for each window
|
||
|
|
||
|
// When using CTRL+TAB (or Gamepad Square+L/R) we delay the visual a little in order to reduce visual noise doing a fast switch.
|
||
| ... | ... | |
|
static const float WINDOWS_MOUSE_WHEEL_SCROLL_LOCK_TIMER = 0.70f; // Lock scrolled window (so it doesn't pick child windows that are scrolling through) for a certain time, unless mouse moved.
|
||
|
|
||
|
// Tooltip offset
|
||
|
static const ImVec2 TOOLTIP_DEFAULT_OFFSET = ImVec2(16, 10); // Multiplied by g.Style.MouseCursorScale
|
||
|
static const ImVec2 TOOLTIP_DEFAULT_OFFSET_MOUSE = ImVec2(16, 10); // Multiplied by g.Style.MouseCursorScale
|
||
|
static const ImVec2 TOOLTIP_DEFAULT_OFFSET_TOUCH = ImVec2(0, -20); // Multiplied by g.Style.MouseCursorScale
|
||
|
static const ImVec2 TOOLTIP_DEFAULT_PIVOT_TOUCH = ImVec2(0.5f, 1.0f); // Multiplied by g.Style.MouseCursorScale
|
||
|
|
||
|
//-------------------------------------------------------------------------
|
||
|
// [SECTION] FORWARD DECLARATIONS
|
||
|
//-------------------------------------------------------------------------
|
||
|
|
||
|
static void SetCurrentWindow(ImGuiWindow* window);
|
||
|
static void FindHoveredWindow();
|
||
|
static ImGuiWindow* CreateNewWindow(const char* name, ImGuiWindowFlags flags);
|
||
|
static ImVec2 CalcNextScrollFromScrollTargetAndClamp(ImGuiWindow* window);
|
||
|
|
||
| ... | ... | |
|
static void WindowSettingsHandler_ApplyAll(ImGuiContext*, ImGuiSettingsHandler*);
|
||
|
static void WindowSettingsHandler_WriteAll(ImGuiContext*, ImGuiSettingsHandler*, ImGuiTextBuffer* buf);
|
||
|
|
||
|
// Platform Dependents default implementation for IO functions
|
||
|
static const char* GetClipboardTextFn_DefaultImpl(void* user_data_ctx);
|
||
|
static void SetClipboardTextFn_DefaultImpl(void* user_data_ctx, const char* text);
|
||
|
static void SetPlatformImeDataFn_DefaultImpl(ImGuiViewport* viewport, ImGuiPlatformImeData* data);
|
||
|
// Platform Dependents default implementation for ImGuiPlatformIO functions
|
||
|
static const char* Platform_GetClipboardTextFn_DefaultImpl(ImGuiContext* ctx);
|
||
|
static void Platform_SetClipboardTextFn_DefaultImpl(ImGuiContext* ctx, const char* text);
|
||
|
static void Platform_SetImeDataFn_DefaultImpl(ImGuiContext* ctx, ImGuiViewport* viewport, ImGuiPlatformImeData* data);
|
||
|
static bool Platform_OpenInShellFn_DefaultImpl(ImGuiContext* ctx, const char* path);
|
||
|
|
||
|
namespace ImGui
|
||
|
{
|
||
|
// Item
|
||
|
static void ItemHandleShortcut(ImGuiID id);
|
||
|
|
||
|
// Navigation
|
||
|
static void NavUpdate();
|
||
|
static void NavUpdateWindowing();
|
||
| ... | ... | |
|
static void NavApplyItemToResult(ImGuiNavItemData* result);
|
||
|
static void NavProcessItem();
|
||
|
static void NavProcessItemForTabbingRequest(ImGuiID id, ImGuiItemFlags item_flags, ImGuiNavMoveFlags move_flags);
|
||
|
static ImGuiInputSource NavCalcPreferredRefPosSource();
|
||
|
static ImVec2 NavCalcPreferredRefPos();
|
||
|
static void NavSaveLastChildNavWindowIntoParent(ImGuiWindow* nav_window);
|
||
|
static ImGuiWindow* NavRestoreLastChildNavWindow(ImGuiWindow* window);
|
||
| ... | ... | |
|
// Error Checking and Debug Tools
|
||
|
static void ErrorCheckNewFrameSanityChecks();
|
||
|
static void ErrorCheckEndFrameSanityChecks();
|
||
|
#ifndef IMGUI_DISABLE_DEBUG_TOOLS
|
||
|
static void UpdateDebugToolItemPicker();
|
||
|
static void UpdateDebugToolStackQueries();
|
||
|
static void UpdateDebugToolFlashStyleColor();
|
||
|
#endif
|
||
|
|
||
|
// Inputs
|
||
|
static void UpdateKeyboardInputs();
|
||
| ... | ... | |
|
static void RenderWindowTitleBarContents(ImGuiWindow* window, const ImRect& title_bar_rect, const char* name, bool* p_open);
|
||
|
static void RenderDimmedBackgroundBehindWindow(ImGuiWindow* window, ImU32 col);
|
||
|
static void RenderDimmedBackgrounds();
|
||
|
static void SetLastItemDataForWindow(ImGuiWindow* window, const ImRect& rect);
|
||
|
|
||
|
// Viewports
|
||
|
const ImGuiID IMGUI_VIEWPORT_DEFAULT_ID = 0x11111111; // Using an arbitrary constant instead of e.g. ImHashStr("ViewportDefault", 0); so it's easier to spot in the debugger. The exact value doesn't matter.
|
||
|
static void UpdateViewportsNewFrame();
|
||
|
|
||
|
}
|
||
| ... | ... | |
|
static void* GImAllocatorUserData = NULL;
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
|
// [SECTION] USER FACING STRUCTURES (ImGuiStyle, ImGuiIO)
|
||
|
// [SECTION] USER FACING STRUCTURES (ImGuiStyle, ImGuiIO, ImGuiPlatformIO)
|
||
|
//-----------------------------------------------------------------------------
|
||
|
|
||
|
ImGuiStyle::ImGuiStyle()
|
||
|
{
|
||
|
Alpha = 1.0f; // Global alpha applies to everything in Dear ImGui.
|
||
|
DisabledAlpha = 0.60f; // Additional alpha multiplier applied by BeginDisabled(). Multiply over current value of Alpha.
|
||
|
WindowPadding = ImVec2(8,8); // Padding within a window
|
||
|
WindowRounding = 0.0f; // Radius of window corners rounding. Set to 0.0f to have rectangular windows. Large values tend to lead to variety of artifacts and are not recommended.
|
||
|
WindowBorderSize = 1.0f; // Thickness of border around windows. Generally set to 0.0f or 1.0f. Other values not well tested.
|
||
|
WindowMinSize = ImVec2(32,32); // Minimum window size
|
||
|
WindowTitleAlign = ImVec2(0.0f,0.5f);// Alignment for title bar text
|
||
|
WindowMenuButtonPosition= ImGuiDir_Left; // Position of the collapsing/docking button in the title bar (left/right). Defaults to ImGuiDir_Left.
|
||
|
ChildRounding = 0.0f; // Radius of child window corners rounding. Set to 0.0f to have rectangular child windows
|
||
|
ChildBorderSize = 1.0f; // Thickness of border around child windows. Generally set to 0.0f or 1.0f. Other values not well tested.
|
||
|
PopupRounding = 0.0f; // Radius of popup window corners rounding. Set to 0.0f to have rectangular child windows
|
||
|
PopupBorderSize = 1.0f; // Thickness of border around popup or tooltip windows. Generally set to 0.0f or 1.0f. Other values not well tested.
|
||
|
FramePadding = ImVec2(4,3); // Padding within a framed rectangle (used by most widgets)
|
||
|
FrameRounding = 0.0f; // Radius of frame corners rounding. Set to 0.0f to have rectangular frames (used by most widgets).
|
||
|
FrameBorderSize = 0.0f; // Thickness of border around frames. Generally set to 0.0f or 1.0f. Other values not well tested.
|
||
|
ItemSpacing = ImVec2(8,4); // Horizontal and vertical spacing between widgets/lines
|
||
|
ItemInnerSpacing = ImVec2(4,4); // Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider and its label)
|
||
|
CellPadding = ImVec2(4,2); // Padding within a table cell. CellPadding.y may be altered between different rows.
|
||
|
TouchExtraPadding = ImVec2(0,0); // Expand reactive bounding box for touch-based system where touch position is not accurate enough. Unfortunately we don't sort widgets so priority on overlap will always be given to the first widget. So don't grow this too much!
|
||
|
IndentSpacing = 21.0f; // Horizontal spacing when e.g. entering a tree node. Generally == (FontSize + FramePadding.x*2).
|
||
|
ColumnsMinSpacing = 6.0f; // Minimum horizontal spacing between two columns. Preferably > (FramePadding.x + 1).
|
||
|
ScrollbarSize = 14.0f; // Width of the vertical scrollbar, Height of the horizontal scrollbar
|
||
|
ScrollbarRounding = 9.0f; // Radius of grab corners rounding for scrollbar
|
||
|
GrabMinSize = 12.0f; // Minimum width/height of a grab box for slider/scrollbar
|
||
|
GrabRounding = 0.0f; // Radius of grabs corners rounding. Set to 0.0f to have rectangular slider grabs.
|
||
|
LogSliderDeadzone = 4.0f; // The size in pixels of the dead-zone around zero on logarithmic sliders that cross zero.
|
||
|
TabRounding = 4.0f; // Radius of upper corners of a tab. Set to 0.0f to have rectangular tabs.
|
||
|
TabBorderSize = 0.0f; // Thickness of border around tabs.
|
||
|
TabMinWidthForCloseButton = 0.0f; // Minimum width for close button to appear on an unselected tab when hovered. Set to 0.0f to always show when hovering, set to FLT_MAX to never show close button unless selected.
|
||
|
TabBarBorderSize = 1.0f; // Thickness of tab-bar separator, which takes on the tab active color to denote focus.
|
||
|
TableAngledHeadersAngle = 35.0f * (IM_PI / 180.0f); // Angle of angled headers (supported values range from -50 degrees to +50 degrees).
|
||
|
ColorButtonPosition = ImGuiDir_Right; // Side of the color button in the ColorEdit4 widget (left/right). Defaults to ImGuiDir_Right.
|
||
|
ButtonTextAlign = ImVec2(0.5f,0.5f);// Alignment of button text when button is larger than text.
|
||
|
SelectableTextAlign = ImVec2(0.0f,0.0f);// Alignment of selectable text. Defaults to (0.0f, 0.0f) (top-left aligned). It's generally important to keep this left-aligned if you want to lay multiple items on a same line.
|
||
|
SeparatorTextBorderSize = 3.0f; // Thickkness of border in SeparatorText()
|
||
|
SeparatorTextAlign = ImVec2(0.0f,0.5f);// Alignment of text within the separator. Defaults to (0.0f, 0.5f) (left aligned, center).
|
||
|
SeparatorTextPadding = ImVec2(20.0f,3.f);// Horizontal offset of text from each edge of the separator + spacing on other axis. Generally small values. .y is recommended to be == FramePadding.y.
|
||
|
DisplayWindowPadding = ImVec2(19,19); // Window position are clamped to be visible within the display area or monitors by at least this amount. Only applies to regular windows.
|
||
|
DisplaySafeAreaPadding = ImVec2(3,3); // If you cannot see the edge of your screen (e.g. on a TV) increase the safe area padding. Covers popups/tooltips as well regular windows.
|
||
|
MouseCursorScale = 1.0f; // Scale software rendered mouse cursor (when io.MouseDrawCursor is enabled). May be removed later.
|
||
|
AntiAliasedLines = true; // Enable anti-aliased lines/borders. Disable if you are really tight on CPU/GPU.
|
||
|
AntiAliasedLinesUseTex = true; // Enable anti-aliased lines/borders using textures where possible. Require backend to render with bilinear filtering (NOT point/nearest filtering).
|
||
|
AntiAliasedFill = true; // Enable anti-aliased filled shapes (rounded rectangles, circles, etc.).
|
||
|
CurveTessellationTol = 1.25f; // Tessellation tolerance when using PathBezierCurveTo() without a specific number of segments. Decrease for highly tessellated curves (higher quality, more polygons), increase to reduce quality.
|
||
|
CircleTessellationMaxError = 0.30f; // Maximum error (in pixels) allowed when using AddCircle()/AddCircleFilled() or drawing rounded corner rectangles with no explicit segment count specified. Decrease for higher quality but more geometry.
|
||
|
Alpha = 1.0f; // Global alpha applies to everything in Dear ImGui.
|
||
|
DisabledAlpha = 0.60f; // Additional alpha multiplier applied by BeginDisabled(). Multiply over current value of Alpha.
|
||
|
WindowPadding = ImVec2(8,8); // Padding within a window
|
||
|
WindowRounding = 0.0f; // Radius of window corners rounding. Set to 0.0f to have rectangular windows. Large values tend to lead to variety of artifacts and are not recommended.
|
||
|
WindowBorderSize = 1.0f; // Thickness of border around windows. Generally set to 0.0f or 1.0f. Other values not well tested.
|
||
|
WindowMinSize = ImVec2(32,32); // Minimum window size
|
||
|
WindowTitleAlign = ImVec2(0.0f,0.5f);// Alignment for title bar text
|
||
|
WindowMenuButtonPosition = ImGuiDir_Left; // Position of the collapsing/docking button in the title bar (left/right). Defaults to ImGuiDir_Left.
|
||
|
ChildRounding = 0.0f; // Radius of child window corners rounding. Set to 0.0f to have rectangular child windows
|
||
|
ChildBorderSize = 1.0f; // Thickness of border around child windows. Generally set to 0.0f or 1.0f. Other values not well tested.
|
||
|
PopupRounding = 0.0f; // Radius of popup window corners rounding. Set to 0.0f to have rectangular child windows
|
||
|
PopupBorderSize = 1.0f; // Thickness of border around popup or tooltip windows. Generally set to 0.0f or 1.0f. Other values not well tested.
|
||
|
FramePadding = ImVec2(4,3); // Padding within a framed rectangle (used by most widgets)
|
||
|
FrameRounding = 0.0f; // Radius of frame corners rounding. Set to 0.0f to have rectangular frames (used by most widgets).
|
||
|
FrameBorderSize = 0.0f; // Thickness of border around frames. Generally set to 0.0f or 1.0f. Other values not well tested.
|
||
|
ItemSpacing = ImVec2(8,4); // Horizontal and vertical spacing between widgets/lines
|
||
|
ItemInnerSpacing = ImVec2(4,4); // Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider and its label)
|
||
|
CellPadding = ImVec2(4,2); // Padding within a table cell. Cellpadding.x is locked for entire table. CellPadding.y may be altered between different rows.
|
||
|
TouchExtraPadding = ImVec2(0,0); // Expand reactive bounding box for touch-based system where touch position is not accurate enough. Unfortunately we don't sort widgets so priority on overlap will always be given to the first widget. So don't grow this too much!
|
||
|
IndentSpacing = 21.0f; // Horizontal spacing when e.g. entering a tree node. Generally == (FontSize + FramePadding.x*2).
|
||
|
ColumnsMinSpacing = 6.0f; // Minimum horizontal spacing between two columns. Preferably > (FramePadding.x + 1).
|
||
|
ScrollbarSize = 14.0f; // Width of the vertical scrollbar, Height of the horizontal scrollbar
|
||
|
ScrollbarRounding = 9.0f; // Radius of grab corners rounding for scrollbar
|
||
|
GrabMinSize = 12.0f; // Minimum width/height of a grab box for slider/scrollbar
|
||
|
GrabRounding = 0.0f; // Radius of grabs corners rounding. Set to 0.0f to have rectangular slider grabs.
|
||
|
LogSliderDeadzone = 4.0f; // The size in pixels of the dead-zone around zero on logarithmic sliders that cross zero.
|
||
|
TabRounding = 4.0f; // Radius of upper corners of a tab. Set to 0.0f to have rectangular tabs.
|
||
|
TabBorderSize = 0.0f; // Thickness of border around tabs.
|
||
|
TabMinWidthForCloseButton = 0.0f; // Minimum width for close button to appear on an unselected tab when hovered. Set to 0.0f to always show when hovering, set to FLT_MAX to never show close button unless selected.
|
||
|
TabBarBorderSize = 1.0f; // Thickness of tab-bar separator, which takes on the tab active color to denote focus.
|
||
|
TabBarOverlineSize = 2.0f; // Thickness of tab-bar overline, which highlights the selected tab-bar.
|
||
|
TableAngledHeadersAngle = 35.0f * (IM_PI / 180.0f); // Angle of angled headers (supported values range from -50 degrees to +50 degrees).
|
||
|
TableAngledHeadersTextAlign = ImVec2(0.5f,0.0f);// Alignment of angled headers within the cell
|
||
|
ColorButtonPosition = ImGuiDir_Right; // Side of the color button in the ColorEdit4 widget (left/right). Defaults to ImGuiDir_Right.
|
||
|
ButtonTextAlign = ImVec2(0.5f,0.5f);// Alignment of button text when button is larger than text.
|
||
|
SelectableTextAlign = ImVec2(0.0f,0.0f);// Alignment of selectable text. Defaults to (0.0f, 0.0f) (top-left aligned). It's generally important to keep this left-aligned if you want to lay multiple items on a same line.
|
||
|
SeparatorTextBorderSize = 3.0f; // Thickness of border in SeparatorText()
|
||
|
SeparatorTextAlign = ImVec2(0.0f,0.5f);// Alignment of text within the separator. Defaults to (0.0f, 0.5f) (left aligned, center).
|
||
|
SeparatorTextPadding = ImVec2(20.0f,3.f);// Horizontal offset of text from each edge of the separator + spacing on other axis. Generally small values. .y is recommended to be == FramePadding.y.
|
||
|
DisplayWindowPadding = ImVec2(19,19); // Window position are clamped to be visible within the display area or monitors by at least this amount. Only applies to regular windows.
|
||
|
DisplaySafeAreaPadding = ImVec2(3,3); // If you cannot see the edge of your screen (e.g. on a TV) increase the safe area padding. Covers popups/tooltips as well regular windows.
|
||
|
MouseCursorScale = 1.0f; // Scale software rendered mouse cursor (when io.MouseDrawCursor is enabled). May be removed later.
|
||
|
AntiAliasedLines = true; // Enable anti-aliased lines/borders. Disable if you are really tight on CPU/GPU.
|
||
|
AntiAliasedLinesUseTex = true; // Enable anti-aliased lines/borders using textures where possible. Require backend to render with bilinear filtering (NOT point/nearest filtering).
|
||
|
AntiAliasedFill = true; // Enable anti-aliased filled shapes (rounded rectangles, circles, etc.).
|
||
|
CurveTessellationTol = 1.25f; // Tessellation tolerance when using PathBezierCurveTo() without a specific number of segments. Decrease for highly tessellated curves (higher quality, more polygons), increase to reduce quality.
|
||
|
CircleTessellationMaxError = 0.30f; // Maximum error (in pixels) allowed when using AddCircle()/AddCircleFilled() or drawing rounded corner rectangles with no explicit segment count specified. Decrease for higher quality but more geometry.
|
||
|
|
||
|
// Behaviors
|
||
|
HoverStationaryDelay = 0.15f; // Delay for IsItemHovered(ImGuiHoveredFlags_Stationary). Time required to consider mouse stationary.
|
||
|
HoverDelayShort = 0.15f; // Delay for IsItemHovered(ImGuiHoveredFlags_DelayShort). Usually used along with HoverStationaryDelay.
|
||
|
HoverDelayNormal = 0.40f; // Delay for IsItemHovered(ImGuiHoveredFlags_DelayNormal). "
|
||
|
HoverFlagsForTooltipMouse = ImGuiHoveredFlags_Stationary | ImGuiHoveredFlags_DelayShort | ImGuiHoveredFlags_AllowWhenDisabled; // Default flags when using IsItemHovered(ImGuiHoveredFlags_ForTooltip) or BeginItemTooltip()/SetItemTooltip() while using mouse.
|
||
|
HoverFlagsForTooltipNav = ImGuiHoveredFlags_NoSharedDelay | ImGuiHoveredFlags_DelayNormal | ImGuiHoveredFlags_AllowWhenDisabled; // Default flags when using IsItemHovered(ImGuiHoveredFlags_ForTooltip) or BeginItemTooltip()/SetItemTooltip() while using keyboard/gamepad.
|
||
|
HoverStationaryDelay = 0.15f; // Delay for IsItemHovered(ImGuiHoveredFlags_Stationary). Time required to consider mouse stationary.
|
||
|
HoverDelayShort = 0.15f; // Delay for IsItemHovered(ImGuiHoveredFlags_DelayShort). Usually used along with HoverStationaryDelay.
|
||
|
HoverDelayNormal = 0.40f; // Delay for IsItemHovered(ImGuiHoveredFlags_DelayNormal). "
|
||
|
HoverFlagsForTooltipMouse = ImGuiHoveredFlags_Stationary | ImGuiHoveredFlags_DelayShort | ImGuiHoveredFlags_AllowWhenDisabled; // Default flags when using IsItemHovered(ImGuiHoveredFlags_ForTooltip) or BeginItemTooltip()/SetItemTooltip() while using mouse.
|
||
|
HoverFlagsForTooltipNav = ImGuiHoveredFlags_NoSharedDelay | ImGuiHoveredFlags_DelayNormal | ImGuiHoveredFlags_AllowWhenDisabled; // Default flags when using IsItemHovered(ImGuiHoveredFlags_ForTooltip) or BeginItemTooltip()/SetItemTooltip() while using keyboard/gamepad.
|
||
|
|
||
|
// Default theme
|
||
|
ImGui::StyleColorsDark(this);
|
||
| ... | ... | |
|
LogSliderDeadzone = ImTrunc(LogSliderDeadzone * scale_factor);
|
||
|
TabRounding = ImTrunc(TabRounding * scale_factor);
|
||
|
TabMinWidthForCloseButton = (TabMinWidthForCloseButton != FLT_MAX) ? ImTrunc(TabMinWidthForCloseButton * scale_factor) : FLT_MAX;
|
||
|
TabBarOverlineSize = ImTrunc(TabBarOverlineSize * scale_factor);
|
||
|
SeparatorTextPadding = ImTrunc(SeparatorTextPadding * scale_factor);
|
||
|
DisplayWindowPadding = ImTrunc(DisplayWindowPadding * scale_factor);
|
||
|
DisplaySafeAreaPadding = ImTrunc(DisplaySafeAreaPadding * scale_factor);
|
||
| ... | ... | |
|
IniSavingRate = 5.0f;
|
||
|
IniFilename = "imgui.ini"; // Important: "imgui.ini" is relative to current working dir, most apps will want to lock this to an absolute path (e.g. same path as executables).
|
||
|
LogFilename = "imgui_log.txt";
|
||
|
#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO
|
||
|
for (int i = 0; i < ImGuiKey_COUNT; i++)
|
||
|
KeyMap[i] = -1;
|
||
|
#endif
|
||
|
UserData = NULL;
|
||
|
|
||
|
Fonts = NULL;
|
||
| ... | ... | |
|
FontAllowUserScaling = false;
|
||
|
DisplayFramebufferScale = ImVec2(1.0f, 1.0f);
|
||
|
|
||
|
MouseDoubleClickTime = 0.30f;
|
||
|
MouseDoubleClickMaxDist = 6.0f;
|
||
|
MouseDragThreshold = 6.0f;
|
||
|
KeyRepeatDelay = 0.275f;
|
||
|
KeyRepeatRate = 0.050f;
|
||
|
// Keyboard/Gamepad Navigation options
|
||
|
ConfigNavSwapGamepadButtons = false;
|
||
|
ConfigNavMoveSetMousePos = false;
|
||
|
ConfigNavCaptureKeyboard = true;
|
||
|
ConfigNavEscapeClearFocusItem = true;
|
||
|
ConfigNavEscapeClearFocusWindow = false;
|
||
|
ConfigNavCursorVisibleAuto = true;
|
||
|
ConfigNavCursorVisibleAlways = false;
|
||
|
|
||
|
// Miscellaneous options
|
||
|
MouseDrawCursor = false;
|
||
| ... | ... | |
|
ConfigDragClickToInputText = false;
|
||
|
ConfigWindowsResizeFromEdges = true;
|
||
|
ConfigWindowsMoveFromTitleBarOnly = false;
|
||
|
ConfigWindowsCopyContentsWithCtrlC = false;
|
||
|
ConfigScrollbarScrollByPage = true;
|
||
|
ConfigMemoryCompactTimer = 60.0f;
|
||
|
ConfigDebugIsDebuggerPresent = false;
|
||
|
ConfigDebugHighlightIdConflicts = true;
|
||
|
ConfigDebugBeginReturnValueOnce = false;
|
||
|
ConfigDebugBeginReturnValueLoop = false;
|
||
|
|
||
|
ConfigErrorRecovery = true;
|
||
|
ConfigErrorRecoveryEnableAssert = true;
|
||
|
ConfigErrorRecoveryEnableDebugLog = true;
|
||
|
ConfigErrorRecoveryEnableTooltip = true;
|
||
|
|
||
|
// Inputs Behaviors
|
||
|
MouseDoubleClickTime = 0.30f;
|
||
|
MouseDoubleClickMaxDist = 6.0f;
|
||
|
MouseDragThreshold = 6.0f;
|
||
|
KeyRepeatDelay = 0.275f;
|
||
|
KeyRepeatRate = 0.050f;
|
||
|
|
||
|
// Platform Functions
|
||
|
// Note: Initialize() will setup default clipboard/ime handlers.
|
||
|
BackendPlatformName = BackendRendererName = NULL;
|
||
|
BackendPlatformUserData = BackendRendererUserData = BackendLanguageUserData = NULL;
|
||
|
PlatformLocaleDecimalPoint = '.';
|
||
|
|
||
|
// Input (NB: we already have memset zero the entire structure!)
|
||
|
MousePos = ImVec2(-FLT_MAX, -FLT_MAX);
|
||
| ... | ... | |
|
for (int i = 0; i < IM_ARRAYSIZE(MouseDownDuration); i++) MouseDownDuration[i] = MouseDownDurationPrev[i] = -1.0f;
|
||
|
for (int i = 0; i < IM_ARRAYSIZE(KeysData); i++) { KeysData[i].DownDuration = KeysData[i].DownDurationPrev = -1.0f; }
|
||
|
AppAcceptingEvents = true;
|
||
|
BackendUsingLegacyKeyArrays = (ImS8)-1;
|
||
|
BackendUsingLegacyNavInputArray = true; // assume using legacy array until proven wrong
|
||
|
}
|
||
|
|
||
|
// Pass in translated ASCII characters for text input.
|
||
| ... | ... | |
|
g.InputEventsQueue.clear();
|
||
|
}
|
||
|
|
||
|
// Clear current keyboard/mouse/gamepad state + current frame text input buffer. Equivalent to releasing all keys/buttons.
|
||
|
// Clear current keyboard/gamepad state + current frame text input buffer. Equivalent to releasing all keys/buttons.
|
||
|
void ImGuiIO::ClearInputKeys()
|
||
|
{
|
||
|
#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO
|
||
|
memset(KeysDown, 0, sizeof(KeysDown));
|
||
|
#endif
|
||
|
for (int n = 0; n < IM_ARRAYSIZE(KeysData); n++)
|
||
|
ImGuiContext& g = *Ctx;
|
||
|
for (int key = ImGuiKey_NamedKey_BEGIN; key < ImGuiKey_NamedKey_END; key++)
|
||
|
{
|
||
|
KeysData[n].Down = false;
|
||
|
KeysData[n].DownDuration = -1.0f;
|
||
|
KeysData[n].DownDurationPrev = -1.0f;
|
||
|
if (ImGui::IsMouseKey((ImGuiKey)key))
|
||
|
continue;
|
||
|
ImGuiKeyData* key_data = &g.IO.KeysData[key - ImGuiKey_NamedKey_BEGIN];
|
||
|
key_data->Down = false;
|
||
|
key_data->DownDuration = -1.0f;
|
||
|
key_data->DownDurationPrev = -1.0f;
|
||
|
}
|
||
|
KeyCtrl = KeyShift = KeyAlt = KeySuper = false;
|
||
|
KeyMods = ImGuiMod_None;
|
||
|
InputQueueCharacters.resize(0); // Behavior of old ClearInputCharacters().
|
||
|
}
|
||
|
|
||
|
void ImGuiIO::ClearInputMouse()
|
||
|
{
|
||
|
for (ImGuiKey key = ImGuiKey_Mouse_BEGIN; key < ImGuiKey_Mouse_END; key = (ImGuiKey)(key + 1))
|
||
|
{
|
||
|
ImGuiKeyData* key_data = &KeysData[key - ImGuiKey_NamedKey_BEGIN];
|
||
|
key_data->Down = false;
|
||
|
key_data->DownDuration = -1.0f;
|
||
|
key_data->DownDurationPrev = -1.0f;
|
||
|
}
|
||
|
MousePos = ImVec2(-FLT_MAX, -FLT_MAX);
|
||
|
for (int n = 0; n < IM_ARRAYSIZE(MouseDown); n++)
|
||
|
{
|
||
Update Dear ImGui to v1.91.5.