diff --git a/CHANGELOG.txt b/CHANGELOG.txt index f7241749..7f4cac80 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -60,6 +60,7 @@ Other Changes: - Demo: Fixed Overlay: Added a context menu item to enable freely moving the window. - Examples: Allegro 5: Added support for 32-bit indices setup via defining ImDrawIdx, to avoid an unnecessary conversion (Allegro 5 doesn't support 16-bit indices). - Examples: Allegro 5: Renamed bindings from imgui_impl_a5.cpp to imgui_impl_allegro5.cpp. +- Various minor fixes, tweaks, refactoring, comments. ----------------------------------------------------------------------- diff --git a/imgui.cpp b/imgui.cpp index 19bdfe0d..b39848c6 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -752,6 +752,7 @@ static void NavUpdateWindowing(); static void NavProcessItem(ImGuiWindow* window, const ImRect& nav_bb, const ImGuiID id); static void UpdateMovingWindow(); +static void UpdateMouseInputs(); static void UpdateManualResize(ImGuiWindow* window, const ImVec2& size_auto_fit, int* border_held, int resize_grip_count, ImU32 resize_grip_col[4]); static void FocusFrontMostActiveWindow(ImGuiWindow* ignore_window); @@ -1761,7 +1762,10 @@ void ImGuiTextBuffer::appendfv(const char* fmt, va_list args) int len = ImFormatStringV(NULL, 0, fmt, args); // FIXME-OPT: could do a first pass write attempt, likely successful on first pass. if (len <= 0) + { + va_end(args_copy); return; + } const int write_off = Buf.Size; const int needed_sz = write_off + len; @@ -1773,6 +1777,7 @@ void ImGuiTextBuffer::appendfv(const char* fmt, va_list args) Buf.resize(needed_sz); ImFormatStringV(&Buf[write_off - 1], (size_t)len + 1, fmt, args_copy); + va_end(args_copy); } void ImGuiTextBuffer::appendf(const char* fmt, ...) @@ -3671,12 +3676,12 @@ void ImGui::RenderPlatformWindowsDefault(void* platform_render_arg, void* render } } -static void NewFrameUpdateMouseInputs() +static void ImGui::UpdateMouseInputs() { ImGuiContext& g = *GImGui; // If mouse just appeared or disappeared (usually denoted by -FLT_MAX component, but in reality we test for -256000.0f) we cancel out movement in MouseDelta - if (ImGui::IsMousePosValid(&g.IO.MousePos) && ImGui::IsMousePosValid(&g.IO.MousePosPrev) && g.MouseRefViewport == g.MouseRefPrevViewport) + if (IsMousePosValid(&g.IO.MousePos) && IsMousePosValid(&g.IO.MousePosPrev) && g.MouseRefViewport == g.MouseRefPrevViewport) g.IO.MouseDelta = g.IO.MousePos - g.IO.MousePosPrev; else g.IO.MouseDelta = ImVec2(0.0f, 0.0f); @@ -3910,7 +3915,7 @@ void ImGui::NewFrame() NavUpdate(); // Update mouse input state - NewFrameUpdateMouseInputs(); + UpdateMouseInputs(); // Calculate frame-rate for the user, as a purely luxurious feature g.FramerateSecPerFrameAccum += g.IO.DeltaTime - g.FramerateSecPerFrame[g.FramerateSecPerFrameIdx]; @@ -5814,7 +5819,7 @@ enum ImGuiPopupPositionPolicy ImGuiPopupPositionPolicy_Default, ImGuiPopupPositionPolicy_ComboBox }; - + // r_avoid = the rectangle to avoid (e.g. for tooltip it is a rectangle around the mouse cursor which we want to avoid. for popups it's a small point around the cursor.) // r_outer = the visible area rectangle, minus safe area padding. If our popup size won't fit because of safe area padding we ignore it. // (r_outer is usually equivalent to the viewport rectangle minus padding, but when multi-viewports are enabled and monitor @@ -14056,10 +14061,6 @@ static void SetClipboardTextFn_DefaultImpl(void*, const char* text) #endif -//----------------------------------------------------------------------------- -// HELP -//----------------------------------------------------------------------------- - static void ScaleWindow(ImGuiWindow* window, float scale) { ImVec2 origin = window->Viewport->Pos; @@ -14085,6 +14086,10 @@ void ImGui::ScaleWindowsInViewport(ImGuiViewportP* viewport, float scale) } } +//----------------------------------------------------------------------------- +// HELP, METRICS +//----------------------------------------------------------------------------- + static void RenderViewportThumbnail(ImDrawList* draw_list, ImGuiViewportP* viewport, const ImRect& bb) { ImGuiContext& g = *GImGui; diff --git a/imgui_internal.h b/imgui_internal.h index 72665d96..9b0e64ed 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -323,7 +323,6 @@ struct IMGUI_API ImRect void Expand(const float amount) { Min.x -= amount; Min.y -= amount; Max.x += amount; Max.y += amount; } void Expand(const ImVec2& amount) { Min.x -= amount.x; Min.y -= amount.y; Max.x += amount.x; Max.y += amount.y; } void Translate(const ImVec2& d) { Min.x += d.x; Min.y += d.y; Max.x += d.x; Max.y += d.y; } - void Translate(float dx, float dy) { Min.x += dx; Min.y += dy; Max.x += dx; Max.y += dy; } void ClipWith(const ImRect& r) { Min = ImMax(Min, r.Min); Max = ImMin(Max, r.Max); } // Simple version, may lead to an inverted rectangle, which is fine for Contains/Overlaps test but not for display. void ClipWithFull(const ImRect& r) { Min = ImClamp(Min, r.Min, r.Max); Max = ImClamp(Max, r.Min, r.Max); } // Full version, ensure both points are fully clipped. void Floor() { Min.x = (float)(int)Min.x; Min.y = (float)(int)Min.y; Max.x = (float)(int)Max.x; Max.y = (float)(int)Max.y; } @@ -984,10 +983,9 @@ struct IMGUI_API ImGuiWindow int AutoFitChildAxises; ImGuiDir AutoPosLastDirection; int HiddenFrames; - ImGuiCond SetWindowPosAllowFlags; // store accepted condition flags for SetNextWindowPos() use. - ImGuiCond SetWindowSizeAllowFlags; // store accepted condition flags for SetNextWindowSize() use. - ImGuiCond SetWindowCollapsedAllowFlags; // store accepted condition flags for SetNextWindowCollapsed() use. - + ImGuiCond SetWindowPosAllowFlags; // store acceptable condition flags for SetNextWindowPos() use. + ImGuiCond SetWindowSizeAllowFlags; // store acceptable condition flags for SetNextWindowSize() use. + ImGuiCond SetWindowCollapsedAllowFlags; // store acceptable condition flags for SetNextWindowCollapsed() use. ImVec2 SetWindowPosVal; // store window position when using a non-zero Pivot (position set needs to be processed when we know the window size) ImVec2 SetWindowPosPivot; // store window pivot for positioning. ImVec2(0,0) when positioning from top-left corner; ImVec2(0.5f,0.5f) for centering; ImVec2(1,1) for bottom right. @@ -1003,6 +1001,7 @@ struct IMGUI_API ImGuiWindow ImVector ColumnsStorage; float FontWindowScale; // User scale multiplier per-window float FontDpiScale; + ImDrawList* DrawList; // == &DrawListInst (for backward compatibility reason with code using imgui_internal.h we keep this a pointer) ImDrawList DrawListInst; ImGuiWindow* ParentWindow; // If we are a child _or_ popup window, this is pointing to our parent. Otherwise NULL.