mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-12 07:49:55 +02:00
Merge branch 'master' into docking
# Conflicts: # backends/imgui_impl_dx10.cpp # backends/imgui_impl_dx10.h # backends/imgui_impl_vulkan.h # backends/imgui_impl_win32.cpp # docs/CHANGELOG.txt # examples/README.txt # examples/example_glfw_opengl2/main.cpp # examples/example_glfw_opengl3/main.cpp # examples/example_glfw_vulkan/main.cpp # examples/example_sdl_directx11/main.cpp # examples/example_sdl_opengl2/main.cpp # examples/example_sdl_opengl3/main.cpp # examples/example_sdl_vulkan/main.cpp # examples/example_win32_directx10/main.cpp # examples/example_win32_directx11/main.cpp # examples/example_win32_directx12/main.cpp # examples/example_win32_directx9/main.cpp # imgui.cpp # imgui.h # imgui_demo.cpp # imgui_internal.h
This commit is contained in:
158
imgui.cpp
158
imgui.cpp
@ -1,4 +1,4 @@
|
||||
// dear imgui, v1.79
|
||||
// dear imgui, v1.80 WIP
|
||||
// (main code and documentation)
|
||||
|
||||
// Help:
|
||||
@ -169,21 +169,21 @@ CODE
|
||||
GETTING STARTED WITH INTEGRATING DEAR IMGUI IN YOUR CODE/ENGINE
|
||||
---------------------------------------------------------------
|
||||
- Run and study the examples and demo in imgui_demo.cpp to get acquainted with the library.
|
||||
- In the majority of cases you should be able to use unmodified back-ends files available in the examples/ folder.
|
||||
- Add the Dear ImGui source files + selected back-end source files to your projects or using your preferred build system.
|
||||
- In the majority of cases you should be able to use unmodified backends files available in the examples/ folder.
|
||||
- Add the Dear ImGui source files + selected backend source files to your projects or using your preferred build system.
|
||||
It is recommended you build and statically link the .cpp files as part of your project and NOT as shared library (DLL).
|
||||
- You can later customize the imconfig.h file to tweak some compile-time behavior, such as integrating Dear ImGui types with your own maths types.
|
||||
- When using Dear ImGui, your programming IDE is your friend: follow the declaration of variables, functions and types to find comments about them.
|
||||
- Dear ImGui never touches or knows about your GPU state. The only function that knows about GPU is the draw function that you provide.
|
||||
Effectively it means you can create widgets at any time in your code, regardless of considerations of being in "update" vs "render"
|
||||
phases of your own application. All rendering information are stored into command-lists that you will retrieve after calling ImGui::Render().
|
||||
- Refer to the bindings and demo applications in the examples/ folder for instruction on how to setup your code.
|
||||
- Refer to the backends and demo applications in the examples/ folder for instruction on how to setup your code.
|
||||
- If you are running over a standard OS with a common graphics API, you should be able to use unmodified imgui_impl_*** files from the examples/ folder.
|
||||
|
||||
|
||||
HOW A SIMPLE APPLICATION MAY LOOK LIKE
|
||||
--------------------------------------
|
||||
EXHIBIT 1: USING THE EXAMPLE BINDINGS (= imgui_impl_XXX.cpp files from the examples/ folder).
|
||||
EXHIBIT 1: USING THE EXAMPLE BACKENDS (= imgui_impl_XXX.cpp files from the backends/ folder).
|
||||
The sub-folders in examples/ contains examples applications following this structure.
|
||||
|
||||
// Application init: create a dear imgui context, setup some options, load fonts
|
||||
@ -193,7 +193,7 @@ CODE
|
||||
// TODO: Fill optional fields of the io structure later.
|
||||
// TODO: Load TTF/OTF fonts if you don't want to use the default font.
|
||||
|
||||
// Initialize helper Platform and Renderer bindings (here we are using imgui_impl_win32.cpp and imgui_impl_dx11.cpp)
|
||||
// Initialize helper Platform and Renderer backends (here we are using imgui_impl_win32.cpp and imgui_impl_dx11.cpp)
|
||||
ImGui_ImplWin32_Init(hwnd);
|
||||
ImGui_ImplDX11_Init(g_pd3dDevice, g_pd3dDeviceContext);
|
||||
|
||||
@ -219,7 +219,7 @@ CODE
|
||||
ImGui_ImplWin32_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
|
||||
EXHIBIT 2: IMPLEMENTING CUSTOM BINDING / CUSTOM ENGINE
|
||||
EXHIBIT 2: IMPLEMENTING CUSTOM BACKEND / CUSTOM ENGINE
|
||||
|
||||
// Application init: create a dear imgui context, setup some options, load fonts
|
||||
ImGui::CreateContext();
|
||||
@ -244,7 +244,7 @@ CODE
|
||||
while (true)
|
||||
{
|
||||
// Setup low-level inputs, e.g. on Win32: calling GetKeyboardState(), or write to those fields from your Windows message handlers, etc.
|
||||
// (In the examples/ app this is usually done within the ImGui_ImplXXX_NewFrame() function from one of the demo Platform bindings)
|
||||
// (In the examples/ app this is usually done within the ImGui_ImplXXX_NewFrame() function from one of the demo Platform Backends)
|
||||
io.DeltaTime = 1.0f/60.0f; // set the time elapsed since the previous frame (in seconds)
|
||||
io.DisplaySize.x = 1920.0f; // set the current display width
|
||||
io.DisplaySize.y = 1280.0f; // set the current display height here
|
||||
@ -280,7 +280,7 @@ CODE
|
||||
|
||||
HOW A SIMPLE RENDERING FUNCTION MAY LOOK LIKE
|
||||
---------------------------------------------
|
||||
The bindings in impl_impl_XXX.cpp files contains many working implementations of a rendering function.
|
||||
The backends in impl_impl_XXX.cpp files contains many working implementations of a rendering function.
|
||||
|
||||
void void MyImGuiRenderFunction(ImDrawData* draw_data)
|
||||
{
|
||||
@ -359,7 +359,7 @@ CODE
|
||||
- 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.
|
||||
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 back-end NEEDS to move the OS or underlying mouse cursor on the next frame. Some of the binding in examples/ do that.
|
||||
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, imgui will misbehave as it will see your mouse as moving back and forth!)
|
||||
(In a setup when you may not have easy control over the mouse cursor, e.g. uSynergy.c doesn't expose moving remote mouse cursor, you may want
|
||||
to set a boolean to ignore your other external mouse positions until the external source is moved again.)
|
||||
@ -382,6 +382,16 @@ CODE
|
||||
- 2020/XX/XX (1.XX) - Moved IME support functions from io.ImeSetInputScreenPosFn, io.ImeWindowHandle to the PlatformIO api.
|
||||
|
||||
|
||||
- 2020/10/14 (1.80) - backends: moved all backends files (imgui_impl_XXXX.cpp, imgui_impl_XXXX.h) from examples/ to backends/.
|
||||
- 2020/10/12 (1.80) - removed redirecting functions/enums that were marked obsolete in 1.60 (April 2018):
|
||||
- io.RenderDrawListsFn pointer -> use ImGui::GetDrawData() value and call the render function of your backend
|
||||
- ImGui::IsAnyWindowFocused() -> use ImGui::IsWindowFocused(ImGuiFocusedFlags_AnyWindow)
|
||||
- ImGui::IsAnyWindowHovered() -> use ImGui::IsWindowHovered(ImGuiHoveredFlags_AnyWindow)
|
||||
- ImGuiStyleVar_Count_ -> use ImGuiStyleVar_COUNT
|
||||
- ImGuiMouseCursor_Count_ -> use ImGuiMouseCursor_COUNT
|
||||
- removed redirecting functions names that were marked obsolete in 1.61 (May 2018):
|
||||
- InputFloat (... int decimal_precision ...) -> use InputFloat (... const char* format ...) with format = "%.Xf" where X is your value for decimal_precision.
|
||||
- same for InputFloat2()/InputFloat3()/InputFloat4() variants taking a `int decimal_precision` parameter.
|
||||
- 2020/10/05 (1.79) - removed ImGuiListClipper: Renamed constructor parameters which created an ambiguous alternative to using the ImGuiListClipper::Begin() function, with misleading edge cases (note: imgui_memory_editor <0.40 from imgui_club/ used this old clipper API. Update your copy if needed).
|
||||
- 2020/09/25 (1.79) - renamed ImGuiSliderFlags_ClampOnInput to ImGuiSliderFlags_AlwaysClamp. Kept redirection enum (will obsolete sooner because previous name was added recently).
|
||||
- 2020/09/25 (1.79) - renamed style.TabMinWidthForUnselectedCloseButton to style.TabMinWidthForCloseButton.
|
||||
@ -464,10 +474,10 @@ CODE
|
||||
- 2018/08/01 (1.63) - renamed io.OptCursorBlink to io.ConfigCursorBlink [-> io.ConfigInputTextCursorBlink in 1.65], io.OptMacOSXBehaviors to ConfigMacOSXBehaviors for consistency.
|
||||
- 2018/07/22 (1.63) - changed ImGui::GetTime() return value from float to double to avoid accumulating floating point imprecisions over time.
|
||||
- 2018/07/08 (1.63) - style: renamed ImGuiCol_ModalWindowDarkening to ImGuiCol_ModalWindowDimBg for consistency with other features. Kept redirection enum (will obsolete).
|
||||
- 2018/06/08 (1.62) - examples: the imgui_impl_xxx files have been split to separate platform (Win32, Glfw, SDL2, etc.) from renderer (DX11, OpenGL, Vulkan, etc.).
|
||||
old bindings will still work as is, however prefer using the separated bindings as they will be updated to support multi-viewports.
|
||||
when adopting new bindings follow the main.cpp code of your preferred examples/ folder to know which functions to call.
|
||||
in particular, note that old bindings called ImGui::NewFrame() at the end of their ImGui_ImplXXXX_NewFrame() function.
|
||||
- 2018/06/08 (1.62) - examples: the imgui_impl_XXX files have been split to separate platform (Win32, GLFW, SDL2, etc.) from renderer (DX11, OpenGL, Vulkan, etc.).
|
||||
old backends will still work as is, however prefer using the separated backends as they will be updated to support multi-viewports.
|
||||
when adopting new backends follow the main.cpp code of your preferred examples/ folder to know which functions to call.
|
||||
in particular, note that old backends called ImGui::NewFrame() at the end of their ImGui_ImplXXXX_NewFrame() function.
|
||||
- 2018/06/06 (1.62) - renamed GetGlyphRangesChinese() to GetGlyphRangesChineseFull() to distinguish other variants and discourage using the full set.
|
||||
- 2018/06/06 (1.62) - TreeNodeEx()/TreeNodeBehavior(): the ImGuiTreeNodeFlags_CollapsingHeader helper now include the ImGuiTreeNodeFlags_NoTreePushOnOpen flag. See Changelog for details.
|
||||
- 2018/05/03 (1.61) - DragInt(): the default compile-time format string has been changed from "%.0f" to "%d", as we are not using integers internally any more.
|
||||
@ -477,7 +487,7 @@ CODE
|
||||
- 2018/04/28 (1.61) - obsoleted InputFloat() functions taking an optional "int decimal_precision" in favor of an equivalent and more flexible "const char* format",
|
||||
consistent with other functions. Kept redirection functions (will obsolete).
|
||||
- 2018/04/09 (1.61) - IM_DELETE() helper function added in 1.60 doesn't clear the input _pointer_ reference, more consistent with expectation and allows passing r-value.
|
||||
- 2018/03/20 (1.60) - renamed io.WantMoveMouse to io.WantSetMousePos for consistency and ease of understanding (was added in 1.52, _not_ used by core and only honored by some binding ahead of merging the Nav branch).
|
||||
- 2018/03/20 (1.60) - renamed io.WantMoveMouse to io.WantSetMousePos for consistency and ease of understanding (was added in 1.52, _not_ used by core and only honored by some backend ahead of merging the Nav branch).
|
||||
- 2018/03/12 (1.60) - removed ImGuiCol_CloseButton, ImGuiCol_CloseButtonActive, ImGuiCol_CloseButtonHovered as the closing cross uses regular button colors now.
|
||||
- 2018/03/08 (1.60) - changed ImFont::DisplayOffset.y to default to 0 instead of +1. Fixed rounding of Ascent/Descent to match TrueType renderer. If you were adding or subtracting to ImFont::DisplayOffset check if your fonts are correctly aligned vertically.
|
||||
- 2018/03/03 (1.60) - renamed ImGuiStyleVar_Count_ to ImGuiStyleVar_COUNT and ImGuiMouseCursor_Count_ to ImGuiMouseCursor_COUNT for consistency with other public enums.
|
||||
@ -521,7 +531,7 @@ CODE
|
||||
- 2017/10/11 (1.52) - renamed AlignFirstTextHeightToWidgets() to AlignTextToFramePadding(). Kept inline redirection function (will obsolete).
|
||||
- 2017/09/26 (1.52) - renamed ImFont::Glyph to ImFontGlyph. Kept redirection typedef (will obsolete).
|
||||
- 2017/09/25 (1.52) - removed SetNextWindowPosCenter() because SetNextWindowPos() now has the optional pivot information to do the same and more. Kept redirection function (will obsolete).
|
||||
- 2017/08/25 (1.52) - io.MousePos needs to be set to ImVec2(-FLT_MAX,-FLT_MAX) when mouse is unavailable/missing. Previously ImVec2(-1,-1) was enough but we now accept negative mouse coordinates. In your binding if you need to support unavailable mouse, make sure to replace "io.MousePos = ImVec2(-1,-1)" with "io.MousePos = ImVec2(-FLT_MAX,-FLT_MAX)".
|
||||
- 2017/08/25 (1.52) - io.MousePos needs to be set to ImVec2(-FLT_MAX,-FLT_MAX) when mouse is unavailable/missing. Previously ImVec2(-1,-1) was enough but we now accept negative mouse coordinates. In your backend if you need to support unavailable mouse, make sure to replace "io.MousePos = ImVec2(-1,-1)" with "io.MousePos = ImVec2(-FLT_MAX,-FLT_MAX)".
|
||||
- 2017/08/22 (1.51) - renamed IsItemHoveredRect() to IsItemRectHovered(). Kept inline redirection function (will obsolete). -> (1.52) use IsItemHovered(ImGuiHoveredFlags_RectOnly)!
|
||||
- renamed IsMouseHoveringAnyWindow() to IsAnyWindowHovered() for consistency. Kept inline redirection function (will obsolete).
|
||||
- renamed IsMouseHoveringWindow() to IsWindowRectHovered() for consistency. Kept inline redirection function (will obsolete).
|
||||
@ -568,7 +578,7 @@ CODE
|
||||
you need to render your textured triangles with bilinear filtering to benefit from sub-pixel positioning of text.
|
||||
- 2015/07/08 (1.43) - switched rendering data to use indexed rendering. this is saving a fair amount of CPU/GPU and enables us to get anti-aliasing for a marginal cost.
|
||||
this necessary change will break your rendering function! the fix should be very easy. sorry for that :(
|
||||
- if you are using a vanilla copy of one of the imgui_impl_XXXX.cpp provided in the example, you just need to update your copy and you can ignore the rest.
|
||||
- if you are using a vanilla copy of one of the imgui_impl_XXX.cpp provided in the example, you just need to update your copy and you can ignore the rest.
|
||||
- the signature of the io.RenderDrawListsFn handler has changed!
|
||||
old: ImGui_XXXX_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_count)
|
||||
new: ImGui_XXXX_RenderDrawLists(ImDrawData* draw_data).
|
||||
@ -819,7 +829,7 @@ CODE
|
||||
static const float NAV_WINDOWING_HIGHLIGHT_DELAY = 0.20f; // Time before the highlight and screen dimming starts fading in
|
||||
static const float NAV_WINDOWING_LIST_APPEAR_DELAY = 0.15f; // Time before the window list starts to appear
|
||||
|
||||
// Window resizing from edges (when io.ConfigWindowsResizeFromEdges = true and ImGuiBackendFlags_HasMouseCursors is set in io.BackendFlags by back-end)
|
||||
// Window resizing from edges (when io.ConfigWindowsResizeFromEdges = true and ImGuiBackendFlags_HasMouseCursors is set in io.BackendFlags by backend)
|
||||
static const float WINDOWS_RESIZE_FROM_EDGES_HALF_THICKNESS = 4.0f; // Extend outside and inside windows. Affect FindHoveredWindow().
|
||||
static const float WINDOWS_RESIZE_FROM_EDGES_FEEDBACK_TIMER = 0.04f; // Reduce visual noise by only highlighting the border after a certain time.
|
||||
static const float WINDOWS_MOUSE_WHEEL_SCROLL_LOCK_TIMER = 2.00f; // Lock scrolled window (so it doesn't pick child windows that are scrolling through) for a certain time, unless mouse moved.
|
||||
@ -979,7 +989,7 @@ ImGuiStyle::ImGuiStyle()
|
||||
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 back-end to render with bilinear filtering.
|
||||
AntiAliasedLinesUseTex = true; // Enable anti-aliased lines/borders using textures where possible. Require backend to render with bilinear 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.
|
||||
CircleSegmentMaxError = 1.60f; // 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.
|
||||
@ -1075,10 +1085,6 @@ ImGuiIO::ImGuiIO()
|
||||
SetClipboardTextFn = SetClipboardTextFn_DefaultImpl;
|
||||
ClipboardUserData = NULL;
|
||||
|
||||
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||
RenderDrawListsFn = NULL;
|
||||
#endif
|
||||
|
||||
// Input (NB: we already have memset zero the entire structure!)
|
||||
MousePos = ImVec2(-FLT_MAX, -FLT_MAX);
|
||||
MousePosPrev = ImVec2(-FLT_MAX, -FLT_MAX);
|
||||
@ -3368,6 +3374,24 @@ void ImGui::DestroyContext(ImGuiContext* ctx)
|
||||
IM_DELETE(ctx);
|
||||
}
|
||||
|
||||
// No specific ordering/dependency support, will see as needed
|
||||
void ImGui::AddContextHook(ImGuiContext* ctx, const ImGuiContextHook* hook)
|
||||
{
|
||||
ImGuiContext& g = *ctx;
|
||||
IM_ASSERT(hook->Callback != NULL);
|
||||
g.Hooks.push_back(*hook);
|
||||
}
|
||||
|
||||
// Call context hooks (used by e.g. test engine)
|
||||
// We assume a small number of hooks so all stored in same array
|
||||
void ImGui::CallContextHooks(ImGuiContext* ctx, ImGuiContextHookType hook_type)
|
||||
{
|
||||
ImGuiContext& g = *ctx;
|
||||
for (int n = 0; n < g.Hooks.Size; n++)
|
||||
if (g.Hooks[n].Type == hook_type)
|
||||
g.Hooks[n].Callback(&g, &g.Hooks[n]);
|
||||
}
|
||||
|
||||
ImGuiIO& ImGui::GetIO()
|
||||
{
|
||||
IM_ASSERT(GImGui != NULL && "No current context. Did you call ImGui::CreateContext() and ImGui::SetCurrentContext() ?");
|
||||
@ -3380,7 +3404,7 @@ ImGuiPlatformIO& ImGui::GetPlatformIO()
|
||||
return GImGui->PlatformIO;
|
||||
}
|
||||
|
||||
// Same value as passed to the old io.RenderDrawListsFn function. Valid after Render() and until the next call to NewFrame()
|
||||
// Pass this to your backend rendering function! Valid after Render() and until the next call to NewFrame()
|
||||
ImDrawData* ImGui::GetDrawData()
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
@ -3903,9 +3927,7 @@ void ImGui::NewFrame()
|
||||
IM_ASSERT(GImGui != NULL && "No current context. Did you call ImGui::CreateContext() and ImGui::SetCurrentContext() ?");
|
||||
ImGuiContext& g = *GImGui;
|
||||
|
||||
#ifdef IMGUI_ENABLE_TEST_ENGINE
|
||||
ImGuiTestEngineHook_PreNewFrame(&g);
|
||||
#endif
|
||||
CallContextHooks(&g, ImGuiContextHookType_NewFramePre);
|
||||
|
||||
// Check and assert for various common IO and Configuration mistakes
|
||||
g.ConfigFlagsLastFrame = g.ConfigFlagsCurrFrame;
|
||||
@ -4088,9 +4110,7 @@ void ImGui::NewFrame()
|
||||
Begin("Debug##Default");
|
||||
IM_ASSERT(g.CurrentWindow->IsFallbackWindow == true);
|
||||
|
||||
#ifdef IMGUI_ENABLE_TEST_ENGINE
|
||||
ImGuiTestEngineHook_PostNewFrame(&g);
|
||||
#endif
|
||||
CallContextHooks(&g, ImGuiContextHookType_NewFramePost);
|
||||
}
|
||||
|
||||
// [DEBUG] Item picker tool - start with DebugStartItemPicker() - useful to visually select an item and break into its call-stack.
|
||||
@ -4186,7 +4206,7 @@ void ImGui::Shutdown(ImGuiContext* context)
|
||||
if (g.SettingsLoaded && g.IO.IniFilename != NULL)
|
||||
{
|
||||
ImGuiContext* backup_context = GImGui;
|
||||
SetCurrentContext(context);
|
||||
SetCurrentContext(&g);
|
||||
SaveIniSettingsToDisk(g.IO.IniFilename);
|
||||
SetCurrentContext(backup_context);
|
||||
}
|
||||
@ -4200,10 +4220,7 @@ void ImGui::Shutdown(ImGuiContext* context)
|
||||
// Shutdown extensions
|
||||
DockContextShutdown(&g);
|
||||
|
||||
// Notify hooked test engine, if any
|
||||
#ifdef IMGUI_ENABLE_TEST_ENGINE
|
||||
ImGuiTestEngineHook_Shutdown(context);
|
||||
#endif
|
||||
CallContextHooks(&g, ImGuiContextHookType_Shutdown);
|
||||
|
||||
// Clear everything else
|
||||
for (int i = 0; i < g.Windows.Size; i++)
|
||||
@ -4302,11 +4319,11 @@ static void AddDrawListToDrawData(ImVector<ImDrawList*>* out_list, ImDrawList* d
|
||||
// - First, make sure you are coarse clipping yourself and not trying to draw many things outside visible bounds.
|
||||
// Be mindful that the ImDrawList API doesn't filter vertices. Use the Metrics window to inspect draw list contents.
|
||||
// - If you want large meshes with more than 64K vertices, you can either:
|
||||
// (A) Handle the ImDrawCmd::VtxOffset value in your renderer back-end, and set 'io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset'.
|
||||
// Most example back-ends already support this from 1.71. Pre-1.71 back-ends won't.
|
||||
// (A) Handle the ImDrawCmd::VtxOffset value in your renderer backend, and set 'io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset'.
|
||||
// Most example backends already support this from 1.71. Pre-1.71 backends won't.
|
||||
// Some graphics API such as GL ES 1/2 don't have a way to offset the starting vertex so it is not supported for them.
|
||||
// (B) Or handle 32-bit indices in your renderer back-end, and uncomment '#define ImDrawIdx unsigned int' line in imconfig.h.
|
||||
// Most example back-ends already support this. For example, the OpenGL example code detect index size at compile-time:
|
||||
// (B) Or handle 32-bit indices in your renderer backend, and uncomment '#define ImDrawIdx unsigned int' line in imconfig.h.
|
||||
// Most example backends already support this. For example, the OpenGL example code detect index size at compile-time:
|
||||
// glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer_offset);
|
||||
// Your own engine or render API may use different parameters or function calls to specify index sizes.
|
||||
// 2 and 4 bytes indices are generally supported by most graphics API.
|
||||
@ -4359,7 +4376,7 @@ void ImDrawDataBuilder::FlattenIntoSingleLayer()
|
||||
static void SetupViewportDrawData(ImGuiViewportP* viewport, ImVector<ImDrawList*>* draw_lists)
|
||||
{
|
||||
// When minimized, we report draw_data->DisplaySize as zero to be consistent with non-viewport mode,
|
||||
// and to allow applications/back-ends to easily skip rendering.
|
||||
// and to allow applications/backends to easily skip rendering.
|
||||
// FIXME: Note that we however do NOT attempt to report "zero drawlist / vertices" into the ImDrawData structure.
|
||||
// This is because the work has been done already, and its wasted! We should fix that and add optimizations for
|
||||
// it earlier in the pipeline, rather than pretend to hide the data at the end of the pipeline.
|
||||
@ -4474,6 +4491,8 @@ void ImGui::EndFrame()
|
||||
return;
|
||||
IM_ASSERT(g.WithinFrameScope && "Forgot to call ImGui::NewFrame()?");
|
||||
|
||||
CallContextHooks(&g, ImGuiContextHookType_EndFramePre);
|
||||
|
||||
ErrorCheckEndFrameSanityChecks();
|
||||
|
||||
// Notify OS when our Input Method Editor cursor has moved (e.g. CJK inputs using Microsoft IME)
|
||||
@ -4550,6 +4569,8 @@ void ImGui::EndFrame()
|
||||
g.IO.MouseWheel = g.IO.MouseWheelH = 0.0f;
|
||||
g.IO.InputQueueCharacters.resize(0);
|
||||
memset(g.IO.NavInputs, 0, sizeof(g.IO.NavInputs));
|
||||
|
||||
CallContextHooks(&g, ImGuiContextHookType_EndFramePost);
|
||||
}
|
||||
|
||||
void ImGui::Render()
|
||||
@ -4562,6 +4583,8 @@ void ImGui::Render()
|
||||
g.FrameCountRendered = g.FrameCount;
|
||||
g.IO.MetricsRenderWindows = 0;
|
||||
|
||||
CallContextHooks(&g, ImGuiContextHookType_RenderPre);
|
||||
|
||||
// Add background ImDrawList (for each active viewport)
|
||||
for (int n = 0; n != g.Viewports.Size; n++)
|
||||
{
|
||||
@ -4614,11 +4637,7 @@ void ImGui::Render()
|
||||
g.IO.MetricsRenderIndices += viewport->DrawData->TotalIdxCount;
|
||||
}
|
||||
|
||||
// (Legacy) Call the Render callback function. The current prefer way is to let the user retrieve GetDrawData() and call the render function themselves.
|
||||
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||
if (g.Viewports[0]->DrawData->CmdListsCount > 0 && g.IO.RenderDrawListsFn != NULL)
|
||||
g.IO.RenderDrawListsFn(g.Viewports[0]->DrawData);
|
||||
#endif
|
||||
CallContextHooks(&g, ImGuiContextHookType_RenderPost);
|
||||
}
|
||||
|
||||
// Calculate text size. Text can be multi-line. Optionally ignore text after a ## marker.
|
||||
@ -4740,7 +4759,7 @@ int ImGui::GetKeyIndex(ImGuiKey imgui_key)
|
||||
}
|
||||
|
||||
// Note that dear imgui doesn't know the semantic of each entry of io.KeysDown[]!
|
||||
// Use your own indices/enums according to how your back-end/engine stored them into io.KeysDown[]!
|
||||
// Use your own indices/enums according to how your backend/engine stored them into io.KeysDown[]!
|
||||
bool ImGui::IsKeyDown(int user_key_index)
|
||||
{
|
||||
if (user_key_index < 0)
|
||||
@ -4896,7 +4915,7 @@ bool ImGui::IsAnyMouseDown()
|
||||
|
||||
// Return the delta from the initial clicking position while the mouse button is clicked or was just released.
|
||||
// This is locked and return 0.0f until the mouse moves past a distance threshold at least once.
|
||||
// NB: This is only valid if IsMousePosValid(). Back-ends in theory should always keep mouse position valid when dragging even outside the client window.
|
||||
// NB: This is only valid if IsMousePosValid(). backends in theory should always keep mouse position valid when dragging even outside the client window.
|
||||
ImVec2 ImGui::GetMouseDragDelta(ImGuiMouseButton button, float lock_threshold)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
@ -5485,7 +5504,7 @@ static bool ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& s
|
||||
|
||||
// Clip mouse interaction rectangles within the viewport rectangle (in practice the narrowing is going to happen most of the time).
|
||||
// - Not narrowing would mostly benefit the situation where OS windows _without_ decoration have a threshold for hovering when outside their limits.
|
||||
// This is however not the case with current back-ends under Win32, but a custom borderless window implementation would benefit from it.
|
||||
// This is however not the case with current backends under Win32, but a custom borderless window implementation would benefit from it.
|
||||
// - When decoration are enabled we typically benefit from that distance, but then our resize elements would be conflicting with OS resize elements, so we also narrow.
|
||||
// - Note that we are unable to tell if the platform setup allows hovering with a distance threshold (on Win32, decorated window have such threshold).
|
||||
// We only clip interaction so we overwrite window->ClipRect, cannot call PushClipRect() yet as DrawList is not yet setup.
|
||||
@ -6283,7 +6302,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
||||
if (window->WindowClass.ViewportFlagsOverrideClear)
|
||||
viewport_flags &= ~window->WindowClass.ViewportFlagsOverrideClear;
|
||||
|
||||
// We also tell the back-end that clearing the platform window won't be necessary, as our window is filling the viewport and we have disabled BgAlpha
|
||||
// We also tell the backend that clearing the platform window won't be necessary, as our window is filling the viewport and we have disabled BgAlpha
|
||||
if (!(flags & ImGuiWindowFlags_NoBackground))
|
||||
viewport_flags &= ~ImGuiViewportFlags_NoRendererClear;
|
||||
|
||||
@ -7559,7 +7578,7 @@ static void ImGui::ErrorCheckNewFrameSanityChecks()
|
||||
if (g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard)
|
||||
IM_ASSERT(g.IO.KeyMap[ImGuiKey_Space] != -1 && "ImGuiKey_Space is not mapped, required for keyboard navigation.");
|
||||
|
||||
// Perform simple check: the beta io.ConfigWindowsResizeFromEdges option requires back-end to honor mouse cursor changes and set the ImGuiBackendFlags_HasMouseCursors flag accordingly.
|
||||
// Perform simple check: the beta io.ConfigWindowsResizeFromEdges option requires backend to honor mouse cursor changes and set the ImGuiBackendFlags_HasMouseCursors flag accordingly.
|
||||
if (g.IO.ConfigWindowsResizeFromEdges && !(g.IO.BackendFlags & ImGuiBackendFlags_HasMouseCursors))
|
||||
g.IO.ConfigWindowsResizeFromEdges = false;
|
||||
|
||||
@ -7585,13 +7604,10 @@ static void ImGui::ErrorCheckNewFrameSanityChecks()
|
||||
IM_ASSERT((g.Viewports[0]->PlatformUserData != NULL || g.Viewports[0]->PlatformHandle != NULL) && "Platform init didn't setup main viewport.");
|
||||
if (g.IO.ConfigDockingTransparentPayload && (g.IO.ConfigFlags & ImGuiConfigFlags_DockingEnable))
|
||||
IM_ASSERT(g.PlatformIO.Platform_SetWindowAlpha != NULL && "Platform_SetWindowAlpha handler is required to use io.ConfigDockingTransparent!");
|
||||
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||
IM_ASSERT(g.IO.RenderDrawListsFn == NULL); // Call ImGui::Render() then pass ImGui::GetDrawData() yourself to your render function!
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
// Disable feature, our back-ends do not support it
|
||||
// Disable feature, our backends do not support it
|
||||
g.IO.ConfigFlags &= ~ImGuiConfigFlags_ViewportsEnable;
|
||||
}
|
||||
|
||||
@ -7611,7 +7627,7 @@ static void ImGui::ErrorCheckEndFrameSanityChecks()
|
||||
ImGuiContext& g = *GImGui;
|
||||
|
||||
// Verify that io.KeyXXX fields haven't been tampered with. Key mods should not be modified between NewFrame() and EndFrame()
|
||||
// One possible reason leading to this assert is that your back-ends update inputs _AFTER_ NewFrame().
|
||||
// One possible reason leading to this assert is that your backends update inputs _AFTER_ NewFrame().
|
||||
const ImGuiKeyModFlags expected_key_mod_flags = GetMergedKeyModFlags();
|
||||
IM_ASSERT(g.IO.KeyMods == expected_key_mod_flags && "Mismatching io.KeyCtrl/io.KeyShift/io.KeyAlt/io.KeySuper vs io.KeyMods");
|
||||
IM_UNUSED(expected_key_mod_flags);
|
||||
@ -9299,7 +9315,7 @@ static ImVec2 ImGui::NavCalcPreferredRefPos()
|
||||
const ImRect& rect_rel = g.NavWindow->NavRectRel[g.NavLayer];
|
||||
ImVec2 pos = g.NavWindow->Pos + ImVec2(rect_rel.Min.x + ImMin(g.Style.FramePadding.x * 4, rect_rel.GetWidth()), rect_rel.Max.y - ImMin(g.Style.FramePadding.y, rect_rel.GetHeight()));
|
||||
ImRect visible_rect = g.NavWindow->Viewport->GetMainRect();
|
||||
return ImFloor(ImClamp(pos, visible_rect.Min, visible_rect.Max)); // ImFloor() is important because non-integer mouse position application in back-end might be lossy and result in undesirable non-zero delta.
|
||||
return ImFloor(ImClamp(pos, visible_rect.Min, visible_rect.Max)); // ImFloor() is important because non-integer mouse position application in backend might be lossy and result in undesirable non-zero delta.
|
||||
}
|
||||
}
|
||||
|
||||
@ -9941,7 +9957,7 @@ static void ImGui::NavUpdateWindowing()
|
||||
}
|
||||
|
||||
// Keyboard: Press and Release ALT to toggle menu layer
|
||||
// FIXME: We lack an explicit IO variable for "is the imgui window focused", so compare mouse validity to detect the common case of back-end clearing releases all keys on ALT-TAB
|
||||
// FIXME: We lack an explicit IO variable for "is the imgui window focused", so compare mouse validity to detect the common case of backend clearing releases all keys on ALT-TAB
|
||||
if (IsNavInputTest(ImGuiNavInput_KeyMenu_, ImGuiInputReadMode_Pressed))
|
||||
g.NavWindowingToggleLayer = true;
|
||||
if ((g.ActiveId == 0 || g.ActiveIdAllowOverlap) && g.NavWindowingToggleLayer && IsNavInputTest(ImGuiNavInput_KeyMenu_, ImGuiInputReadMode_Released))
|
||||
@ -11083,9 +11099,9 @@ void ImGui::ScaleWindowsInViewport(ImGuiViewportP* viewport, float scale)
|
||||
}
|
||||
}
|
||||
|
||||
// If the back-end doesn't set MouseLastHoveredViewport or doesn't honor ImGuiViewportFlags_NoInputs, we do a search ourselves.
|
||||
// If the backend doesn't set MouseLastHoveredViewport or doesn't honor ImGuiViewportFlags_NoInputs, we do a search ourselves.
|
||||
// A) It won't take account of the possibility that non-imgui windows may be in-between our dragged window and our target window.
|
||||
// B) It requires Platform_GetWindowFocus to be implemented by back-end.
|
||||
// B) It requires Platform_GetWindowFocus to be implemented by backend.
|
||||
static ImGuiViewportP* FindHoveredViewportFromPlatformWindowStack(const ImVec2 mouse_platform_pos)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
@ -11127,7 +11143,7 @@ static void ImGui::UpdateViewportsNewFrame()
|
||||
}
|
||||
|
||||
// Create/update main viewport with current platform position.
|
||||
// FIXME-VIEWPORT: Size is driven by back-end/user code for backward-compatibility but we should aim to make this more consistent.
|
||||
// FIXME-VIEWPORT: Size is driven by backend/user code for backward-compatibility but we should aim to make this more consistent.
|
||||
ImGuiViewportP* main_viewport = g.Viewports[0];
|
||||
IM_ASSERT(main_viewport->ID == IMGUI_VIEWPORT_DEFAULT_ID);
|
||||
IM_ASSERT(main_viewport->Window == NULL);
|
||||
@ -11241,14 +11257,14 @@ static void ImGui::UpdateViewportsNewFrame()
|
||||
viewport_hovered = g.IO.MouseHoveredViewport ? (ImGuiViewportP*)FindViewportByID(g.IO.MouseHoveredViewport) : NULL;
|
||||
if (viewport_hovered && (viewport_hovered->Flags & ImGuiViewportFlags_NoInputs))
|
||||
{
|
||||
// Back-end failed at honoring its contract if it returned a viewport with the _NoInputs flag.
|
||||
// Backend failed at honoring its contract if it returned a viewport with the _NoInputs flag.
|
||||
IM_ASSERT(0);
|
||||
viewport_hovered = FindHoveredViewportFromPlatformWindowStack(g.IO.MousePos);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// If the back-end doesn't know how to honor ImGuiViewportFlags_NoInputs, we do a search ourselves. Note that this search:
|
||||
// If the backend doesn't know how to honor ImGuiViewportFlags_NoInputs, we do a search ourselves. Note that this search:
|
||||
// A) won't take account of the possibility that non-imgui windows may be in-between our dragged window and our target window.
|
||||
// B) uses LastFrameAsRefViewport as a flawed replacement for the last time a window was focused (we could/should fix that by introducing Focus functions in PlatformIO)
|
||||
viewport_hovered = FindHoveredViewportFromPlatformWindowStack(g.IO.MousePos);
|
||||
@ -11369,7 +11385,7 @@ static void ImGui::UpdateSelectWindowViewport(ImGuiWindow* window)
|
||||
ImGuiWindowFlags flags = window->Flags;
|
||||
window->ViewportAllowPlatformMonitorExtend = -1;
|
||||
|
||||
// Restore main viewport if multi-viewport is not supported by the back-end
|
||||
// Restore main viewport if multi-viewport is not supported by the backend
|
||||
ImGuiViewportP* main_viewport = g.Viewports[0];
|
||||
if (!(g.ConfigFlagsCurrFrame & ImGuiConfigFlags_ViewportsEnable))
|
||||
{
|
||||
@ -11535,7 +11551,7 @@ void ImGui::UpdatePlatformWindows()
|
||||
viewport->PlatformWindowCreated = true;
|
||||
}
|
||||
|
||||
// Apply Position and Size (from ImGui to Platform/Renderer back-ends)
|
||||
// Apply Position and Size (from ImGui to Platform/Renderer backends)
|
||||
if ((viewport->LastPlatformPos.x != viewport->Pos.x || viewport->LastPlatformPos.y != viewport->Pos.y) && !viewport->PlatformRequestMove)
|
||||
g.PlatformIO.Platform_SetWindowPos(viewport, viewport->Pos);
|
||||
if ((viewport->LastPlatformSize.x != viewport->Size.x || viewport->LastPlatformSize.y != viewport->Size.y) && !viewport->PlatformRequestResize)
|
||||
@ -11566,7 +11582,7 @@ void ImGui::UpdatePlatformWindows()
|
||||
g.PlatformIO.Platform_SetWindowAlpha(viewport, viewport->Alpha);
|
||||
viewport->LastAlpha = viewport->Alpha;
|
||||
|
||||
// Optional, general purpose call to allow the back-end to perform general book-keeping even if things haven't changed.
|
||||
// Optional, general purpose call to allow the backend to perform general book-keeping even if things haven't changed.
|
||||
if (g.PlatformIO.Platform_UpdateWindow)
|
||||
g.PlatformIO.Platform_UpdateWindow(viewport);
|
||||
|
||||
@ -11589,8 +11605,8 @@ void ImGui::UpdatePlatformWindows()
|
||||
viewport->ClearRequestFlags();
|
||||
}
|
||||
|
||||
// Update our implicit z-order knowledge of platform windows, which is used when the back-end cannot provide io.MouseHoveredViewport.
|
||||
// When setting Platform_GetWindowFocus, it is expected that the platform back-end can handle calls without crashing if it doesn't have data stored.
|
||||
// Update our implicit z-order knowledge of platform windows, which is used when the backend cannot provide io.MouseHoveredViewport.
|
||||
// When setting Platform_GetWindowFocus, it is expected that the platform backend can handle calls without crashing if it doesn't have data stored.
|
||||
// FIXME-VIEWPORT: We should use this information to also set dear imgui-side focus, allowing us to handle os-level alt+tab.
|
||||
if (g.PlatformIO.Platform_GetWindowFocus != NULL)
|
||||
{
|
||||
@ -11707,7 +11723,7 @@ void ImGui::DestroyPlatformWindow(ImGuiViewportP* viewport)
|
||||
IM_ASSERT(viewport->RendererUserData == NULL && viewport->PlatformUserData == NULL);
|
||||
|
||||
// Don't clear PlatformWindowCreated for the main viewport, as we initially set that up to true in Initialize()
|
||||
// The right-er way may be to leave it to the back-end to set this flag all-together, and made the flag public.
|
||||
// The righter way may be to leave it to the backend to set this flag all-together, and made the flag public.
|
||||
if (viewport->ID != IMGUI_VIEWPORT_DEFAULT_ID)
|
||||
viewport->PlatformWindowCreated = false;
|
||||
}
|
||||
@ -11721,11 +11737,11 @@ void ImGui::DestroyPlatformWindow(ImGuiViewportP* viewport)
|
||||
|
||||
void ImGui::DestroyPlatformWindows()
|
||||
{
|
||||
// We call the destroy window on every viewport (including the main viewport, index 0) to give a chance to the back-end
|
||||
// We call the destroy window on every viewport (including the main viewport, index 0) to give a chance to the backend
|
||||
// to clear any data they may have stored in e.g. PlatformUserData, RendererUserData.
|
||||
// It is convenient for the platform back-end code to store something in the main viewport, in order for e.g. the mouse handling
|
||||
// It is convenient for the platform backend code to store something in the main viewport, in order for e.g. the mouse handling
|
||||
// code to operator a consistent manner.
|
||||
// It is expected that the back-end can handle calls to Renderer_DestroyWindow/Platform_DestroyWindow without
|
||||
// It is expected that the backend can handle calls to Renderer_DestroyWindow/Platform_DestroyWindow without
|
||||
// crashing if it doesn't have data stored.
|
||||
ImGuiContext& g = *GImGui;
|
||||
for (int i = 0; i < g.Viewports.Size; i++)
|
||||
|
Reference in New Issue
Block a user