diff --git a/imgui.cpp b/imgui.cpp index a476e875..61bb11f5 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -7229,6 +7229,18 @@ void ImDrawList::PushClipRect(const ImVec4& clip_rect) UpdateClipRect(); } +void ImDrawList::PushClipRectFullScreen() +{ + PushClipRect(GNullClipRect); + + // This would be more correct but we're not supposed to access ImGuiState from here? + //ImGuiState& g = *GImGui; + //if (g.IO.DisplayVisibleMin.x != g.IO.DisplayVisibleMax.x && g.IO.DisplayVisibleMin.y != g.IO.DisplayVisibleMax.y) + // PushClipRect(ImVec4(g.IO.DisplayVisibleMin.x, g.IO.DisplayVisibleMin.y, g.IO.DisplayVisibleMax.x, g.IO.DisplayVisibleMax.y)); + //else + // PushClipRect(ImVec4(0.0f, 0.0f, g.IO.DisplaySize.x, g.IO.DisplaySize.y)); +} + void ImDrawList::PopClipRect() { IM_ASSERT(clip_rect_stack.size() > 0); @@ -7291,11 +7303,11 @@ void ImDrawList::AddVtxUV(const ImVec2& pos, ImU32 col, const ImVec2& uv) } // NB: memory should be reserved for 6 vertices by the caller. -void ImDrawList::AddVtxLine(const ImVec2& a, const ImVec2& b, ImU32 col) +void ImDrawList::AddVtxLine(const ImVec2& a, const ImVec2& b, ImU32 col, float half_thickness) { - const float length = sqrtf(ImLengthSqr(b - a)); - const ImVec2 hn = (b - a) * (0.50f / length); // half normal - const ImVec2 hp0 = ImVec2(+hn.y, -hn.x); // half perpendiculars + user offset + const float inv_length = 1.0f / sqrtf(ImLengthSqr(b - a)); + const ImVec2 hn = (b - a) * (half_thickness * inv_length); // half normal + const ImVec2 hp0 = ImVec2(+hn.y, -hn.x); // half perpendiculars + user offset const ImVec2 hp1 = ImVec2(-hn.y, +hn.x); // Two triangles makes up one line. Using triangles allows us to reduce amount of draw calls. @@ -7307,13 +7319,13 @@ void ImDrawList::AddVtxLine(const ImVec2& a, const ImVec2& b, ImU32 col) AddVtx(a + hp1, col); } -void ImDrawList::AddLine(const ImVec2& a, const ImVec2& b, ImU32 col) +void ImDrawList::AddLine(const ImVec2& a, const ImVec2& b, ImU32 col, float half_thickness) { if ((col >> 24) == 0) return; ReserveVertices(6); - AddVtxLine(a, b, col); + AddVtxLine(a, b, col, half_thickness); } void ImDrawList::AddArc(const ImVec2& center, float rad, ImU32 col, int a_min, int a_max, bool tris, const ImVec2& third_point_offset) diff --git a/imgui.h b/imgui.h index ec0846b3..0fb22eec 100644 --- a/imgui.h +++ b/imgui.h @@ -861,12 +861,13 @@ struct ImDrawList ImDrawList() { Clear(); } IMGUI_API void Clear(); IMGUI_API void PushClipRect(const ImVec4& clip_rect); // Scissoring. The values are x1, y1, x2, y2. + IMGUI_API void PushClipRectFullScreen(); IMGUI_API void PopClipRect(); IMGUI_API void PushTextureID(const ImTextureID& texture_id); IMGUI_API void PopTextureID(); // Primitives - IMGUI_API void AddLine(const ImVec2& a, const ImVec2& b, ImU32 col); + IMGUI_API void AddLine(const ImVec2& a, const ImVec2& b, ImU32 col, float half_thickness = 0.50f); 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 AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col); @@ -884,7 +885,7 @@ struct ImDrawList IMGUI_API void ReserveVertices(unsigned int vtx_count); IMGUI_API void AddVtx(const ImVec2& pos, ImU32 col); IMGUI_API void AddVtxUV(const ImVec2& pos, ImU32 col, const ImVec2& uv); - IMGUI_API void AddVtxLine(const ImVec2& a, const ImVec2& b, ImU32 col); + IMGUI_API void AddVtxLine(const ImVec2& a, const ImVec2& b, ImU32 col, float half_thickness = 0.50f); IMGUI_API void UpdateClipRect(); IMGUI_API void UpdateTextureID(); };