ImDrawList: added thickness param to AddLine(). Added PushClipRectFullScreen() helper.

This commit is contained in:
ocornut 2015-03-18 12:54:44 +00:00
parent 7d26e85b05
commit 9f1b407def
2 changed files with 21 additions and 8 deletions

View File

@ -7229,6 +7229,18 @@ void ImDrawList::PushClipRect(const ImVec4& clip_rect)
UpdateClipRect(); 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() void ImDrawList::PopClipRect()
{ {
IM_ASSERT(clip_rect_stack.size() > 0); IM_ASSERT(clip_rect_stack.size() > 0);
@ -7291,10 +7303,10 @@ void ImDrawList::AddVtxUV(const ImVec2& pos, ImU32 col, const ImVec2& uv)
} }
// NB: memory should be reserved for 6 vertices by the caller. // 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 float inv_length = 1.0f / sqrtf(ImLengthSqr(b - a));
const ImVec2 hn = (b - a) * (0.50f / length); // half normal 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 hp0 = ImVec2(+hn.y, -hn.x); // half perpendiculars + user offset
const ImVec2 hp1 = ImVec2(-hn.y, +hn.x); const ImVec2 hp1 = ImVec2(-hn.y, +hn.x);
@ -7307,13 +7319,13 @@ void ImDrawList::AddVtxLine(const ImVec2& a, const ImVec2& b, ImU32 col)
AddVtx(a + hp1, 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) if ((col >> 24) == 0)
return; return;
ReserveVertices(6); 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) void ImDrawList::AddArc(const ImVec2& center, float rad, ImU32 col, int a_min, int a_max, bool tris, const ImVec2& third_point_offset)

View File

@ -861,12 +861,13 @@ struct ImDrawList
ImDrawList() { Clear(); } ImDrawList() { Clear(); }
IMGUI_API void Clear(); IMGUI_API void Clear();
IMGUI_API void PushClipRect(const ImVec4& clip_rect); // Scissoring. The values are x1, y1, x2, y2. 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 PopClipRect();
IMGUI_API void PushTextureID(const ImTextureID& texture_id); IMGUI_API void PushTextureID(const ImTextureID& texture_id);
IMGUI_API void PopTextureID(); IMGUI_API void PopTextureID();
// Primitives // 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 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 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); 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 ReserveVertices(unsigned int vtx_count);
IMGUI_API void AddVtx(const ImVec2& pos, ImU32 col); IMGUI_API void AddVtx(const ImVec2& pos, ImU32 col);
IMGUI_API void AddVtxUV(const ImVec2& pos, ImU32 col, const ImVec2& uv); 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 UpdateClipRect();
IMGUI_API void UpdateTextureID(); IMGUI_API void UpdateTextureID();
}; };