From d10d0343b2d64573645d313189ea57137c20448f Mon Sep 17 00:00:00 2001 From: ocornut Date: Sat, 11 Jul 2015 18:10:43 -0600 Subject: [PATCH 1/4] Plot() function can take 0.0f for both scale_min/scale_max to calculate scale --- imgui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index f4c13809c..0fc4c0200 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -6547,7 +6547,7 @@ static void Plot(ImGuiPlotType plot_type, const char* label, float (*values_gett return; // Determine scale from values if not specified - if (scale_min == FLT_MAX || scale_max == FLT_MAX) + if (scale_min == FLT_MAX || scale_max == FLT_MAX || (scale_min == 0.0f && scale_max == 0.0f)) { float v_min = FLT_MAX; float v_max = -FLT_MAX; From 7a0004eb86f08519aae226fdf7c68284c2862ff6 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sat, 11 Jul 2015 18:15:34 -0600 Subject: [PATCH 2/4] Revert --- imgui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index 0fc4c0200..f4c13809c 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -6547,7 +6547,7 @@ static void Plot(ImGuiPlotType plot_type, const char* label, float (*values_gett return; // Determine scale from values if not specified - if (scale_min == FLT_MAX || scale_max == FLT_MAX || (scale_min == 0.0f && scale_max == 0.0f)) + if (scale_min == FLT_MAX || scale_max == FLT_MAX) { float v_min = FLT_MAX; float v_max = -FLT_MAX; From 6520b6c4583ad2f30aecc4299e1b055208826e06 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 12 Jul 2015 10:48:06 -0600 Subject: [PATCH 3/4] ImDrawList: added AddRectFilledMultiColor() helper + minor optimisation. --- imgui.cpp | 23 +++++++++++++++++++---- imgui.h | 1 + 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index f4c13809c..49eea35f2 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -9202,10 +9202,10 @@ void ImDrawList::AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float roun if (r == 0.0f || rounding_corners == 0) { PrimReserve(4*6); - PrimLine(ImVec2(a.x,a.y), ImVec2(b.x,a.y), col); - PrimLine(ImVec2(b.x,a.y), ImVec2(b.x,b.y), col); - PrimLine(ImVec2(b.x,b.y), ImVec2(a.x,b.y), col); - PrimLine(ImVec2(a.x,b.y), ImVec2(a.x,a.y), col); + PrimLine(a, ImVec2(b.x,a.y), col); + PrimLine(ImVec2(b.x,a.y), b, col); + PrimLine(b, ImVec2(a.x,b.y), col); + PrimLine(ImVec2(a.x,b.y), a, col); } else { @@ -9257,6 +9257,21 @@ void ImDrawList::AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, floa } } +void ImDrawList::AddRectFilledMultiColor(const ImVec2& a, const ImVec2& b, ImU32 col_upr_left, ImU32 col_upr_right, ImU32 col_bot_right, ImU32 col_bot_left) +{ + if (((col_upr_left | col_upr_right | col_bot_right | col_bot_left) >> 24) == 0) + return; + + const ImVec2 uv = GImGui->FontTexUvWhitePixel; + PrimReserve(6); + PrimVtx(a, uv, col_upr_left); + PrimVtx(ImVec2(b.x,a.y), uv, col_upr_right); + PrimVtx(ImVec2(b.x,b.y), uv, col_bot_right); + PrimVtx(a, uv, col_upr_left); + PrimVtx(b, uv, col_bot_right); + PrimVtx(ImVec2(a.x,b.y), uv, col_bot_left); +} + void ImDrawList::AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col) { if ((col >> 24) == 0) diff --git a/imgui.h b/imgui.h index 3964fd946..0f371efd1 100644 --- a/imgui.h +++ b/imgui.h @@ -1044,6 +1044,7 @@ struct ImDrawList IMGUI_API void AddLine(const ImVec2& a, const ImVec2& b, ImU32 col, float thickness = 1.0f); IMGUI_API void AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners = 0x0F); IMGUI_API void AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners = 0x0F); + IMGUI_API void AddRectFilledMultiColor(const ImVec2& a, const ImVec2& b, ImU32 col_upr_left, ImU32 col_upr_right, ImU32 col_bot_right, ImU32 col_bot_left); IMGUI_API void AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col); IMGUI_API void AddCircle(const ImVec2& centre, float radius, ImU32 col, int num_segments = 12); IMGUI_API void AddCircleFilled(const ImVec2& centre, float radius, ImU32 col, int num_segments = 12); From 4565bf98139bc8e4a17820439d781272f4b502de Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 12 Jul 2015 10:52:20 -0600 Subject: [PATCH 4/4] Demo: custom rendering example uses AddRectFilledMultiColor() --- imgui.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index 49eea35f2..75d831308 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -12272,7 +12272,8 @@ static void ShowExampleAppCustomRendering(bool* opened) // If you only use the ImDrawList API, you can notify the owner window of its extends by using SetCursorPos(max). ImVec2 canvas_pos = ImGui::GetCursorScreenPos(); // ImDrawList API uses screen coordinates! ImVec2 canvas_size = ImVec2(ImMax(50.0f,ImGui::GetWindowContentRegionMax().x-ImGui::GetCursorPos().x), ImMax(50.0f,ImGui::GetWindowContentRegionMax().y-ImGui::GetCursorPos().y)); // Resize canvas what's available - draw_list->AddRect(canvas_pos, ImVec2(canvas_pos.x + canvas_size.x, canvas_pos.y + canvas_size.y), 0xFFFFFFFF); + draw_list->AddRectFilledMultiColor(canvas_pos, ImVec2(canvas_pos.x + canvas_size.x, canvas_pos.y + canvas_size.y), ImColor(0,0,0), ImColor(255,0,0), ImColor(255,255,0), ImColor(0,255,0)); + draw_list->AddRect(canvas_pos, ImVec2(canvas_pos.x + canvas_size.x, canvas_pos.y + canvas_size.y), ImColor(255,255,255)); bool adding_preview = false; ImGui::InvisibleButton("canvas", canvas_size); if (ImGui::IsItemHovered())