AA branch: Test disabling aa at runtime for stroke and fill.

docking
ocornut 10 years ago
parent 431e391ccd
commit 1e69175403

@ -7,8 +7,8 @@
// ANTI-ALIASED PRIMITIVES BRANCH // ANTI-ALIASED PRIMITIVES BRANCH
// TODO // TODO
// - settle on where to the 0.5f offset for lines // - settle on where to the 0.5f offset for lines
// - checkbox, slider grabs are not centered properly if you enable border (relate to point above) // - check-box, slider grabs are not centered properly if you enable border (relate to point above)
// - thick lines? recently been added to the ImDrawList API as a convenience. // - support for thickness stroking. recently been added to the ImDrawList API as a convenience.
/* /*
@ -398,6 +398,7 @@
#include <new> // new (ptr) #include <new> // new (ptr)
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning (disable: 4127) // conditional expression is constant
#pragma warning (disable: 4505) // unreferenced local function has been removed (stb stuff) #pragma warning (disable: 4505) // unreferenced local function has been removed (stb stuff)
#pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen #pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen
#endif #endif
@ -7723,18 +7724,14 @@ void ImDrawList::PrimRectUV(const ImVec2& a, const ImVec2& c, const ImVec2& uv_a
static ImVector<ImVec2> GTempPolyData; static ImVector<ImVec2> GTempPolyData;
void ImDrawList::AddPolyline(const ImVec2* points, const int points_count, ImU32 col, bool closed) void ImDrawList::AddPolyline(const ImVec2* points, const int points_count, ImU32 col, float thickness, bool closed)
{ {
(void)thickness; // Unsupported
if (points_count < 2) if (points_count < 2)
return; return;
const float aa_size = 1.0f; const ImVec2 uv = GImGui->FontTexUvWhitePixel;
// Temporary buffer
GTempPolyData.resize(points_count * 3);
ImVec2* temp_inner = &GTempPolyData[0];
ImVec2* temp_outer = &GTempPolyData[points_count];
ImVec2* temp_normals = &GTempPolyData[points_count * 2];
int start = 0, count = points_count; int start = 0, count = points_count;
if (!closed) if (!closed)
@ -7743,6 +7740,18 @@ void ImDrawList::AddPolyline(const ImVec2* points, const int points_count, ImU32
count = points_count-1; count = points_count-1;
} }
const bool aa_enabled = true;//!ImGui::GetIO().KeyCtrl;
if (aa_enabled)
{
// Anti-aliased stroke
const float aa_size = 1.0f;
// Temporary buffer
GTempPolyData.resize(points_count * 3);
ImVec2* temp_inner = &GTempPolyData[0];
ImVec2* temp_outer = &GTempPolyData[points_count];
ImVec2* temp_normals = &GTempPolyData[points_count * 2];
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
const int ni = (i+1) < points_count ? i+1 : 0; const int ni = (i+1) < points_count ? i+1 : 0;
@ -7784,8 +7793,6 @@ void ImDrawList::AddPolyline(const ImVec2* points, const int points_count, ImU32
} }
const ImU32 col_trans = col & 0x00ffffff; const ImU32 col_trans = col & 0x00ffffff;
const ImVec2 uv = GImGui->FontTexUvWhitePixel;
const int vertex_count = count*12; const int vertex_count = count*12;
PrimReserve(vertex_count); PrimReserve(vertex_count);
@ -7810,9 +7817,52 @@ void ImDrawList::AddPolyline(const ImVec2* points, const int points_count, ImU32
PrimVtx(temp_inner[ni], uv, col_trans); PrimVtx(temp_inner[ni], uv, col_trans);
} }
} }
else
{
// Non Anti-aliased Stroke
const int vertex_count = count*6;
PrimReserve(vertex_count);
for (int i = 0; i < count; i++)
{
const int ni = (i+1) < points_count ? i+1 : 0;
const ImVec2& v0 = points[i];
const ImVec2& v1 = points[ni];
ImVec2 diff = v1 - v0;
float d = ImLengthSqr(diff);
if (d > 0)
diff *= 1.0f / sqrtf(d);
ImVec2 hn;
hn.x = diff.y * 0.5f;
hn.y = -diff.x * 0.5f;
PrimVtx(v0 - hn, uv, col);
PrimVtx(v0 + hn, uv, col);
PrimVtx(v1 + hn, uv, col);
PrimVtx(v0 - hn, uv, col);
PrimVtx(v1 + hn, uv, col);
PrimVtx(v1 - hn, uv, col);
}
/*
const float inv_length = 1.0f / sqrtf(ImLengthSqr(b - a));
const float aa_size = 1.0f;
const ImVec2 hn = (b - a) * (thickness * 0.5f * inv_length);// half normalized
const ImVec2 hp0 = ImVec2(+hn.y, -hn.x); // half perpendiculars + user offset
const ImVec2 hp1 = ImVec2(-hn.y, +hn.x);
*/
}
}
void ImDrawList::AddConvexPolyFilled(const ImVec2* points, const int points_count, ImU32 col) void ImDrawList::AddConvexPolyFilled(const ImVec2* points, const int points_count, ImU32 col)
{ {
const ImVec2 uv = GImGui->FontTexUvWhitePixel;
const bool aa_enabled = true;//!ImGui::GetIO().KeyCtrl;
if (aa_enabled)
{
// Anti-aliased Fill
const float aa_size = 1.0f; const float aa_size = 1.0f;
// Temporary buffer // Temporary buffer
@ -7850,9 +7900,7 @@ void ImDrawList::AddConvexPolyFilled(const ImVec2* points, const int points_coun
} }
const ImU32 col_trans = col & 0x00ffffff; const ImU32 col_trans = col & 0x00ffffff;
const ImVec2 uv = GImGui->FontTexUvWhitePixel; const int vertex_count = (points_count-2)*3 + points_count*6;
int vertex_count = (points_count-2)*3 + points_count*6;
PrimReserve(vertex_count); PrimReserve(vertex_count);
// Fill // Fill
@ -7875,6 +7923,19 @@ void ImDrawList::AddConvexPolyFilled(const ImVec2* points, const int points_coun
PrimVtx(temp_inner[i], uv, col); PrimVtx(temp_inner[i], uv, col);
} }
} }
else
{
// Non Anti-aliased Fill
const int vertex_count = (points_count-2)*3;
PrimReserve(vertex_count);
for (int i = 2; i < points_count; i++)
{
PrimVtx(points[0], uv, col);
PrimVtx(points[i-1], uv, col);
PrimVtx(points[i], uv, col);
}
}
}
void ImDrawList::ClearPath() void ImDrawList::ClearPath()
{ {
@ -7936,10 +7997,10 @@ void ImDrawList::Fill(ImU32 col)
ClearPath(); ClearPath();
} }
void ImDrawList::Stroke(ImU32 col, bool closed) void ImDrawList::Stroke(ImU32 col, float thickness, bool closed)
{ {
// Remove duplicates // Remove duplicates
AddPolyline(&path[0], (int)path.size(), col, closed); AddPolyline(&path[0], (int)path.size(), col, thickness, closed);
ClearPath(); ClearPath();
} }

@ -914,7 +914,7 @@ struct ImDrawList
IMGUI_API void ArcTo(const ImVec2& centre, float radius, float a_min, float a_max, int num_segments = 12); IMGUI_API void ArcTo(const ImVec2& centre, float radius, float a_min, float a_max, int num_segments = 12);
IMGUI_API void Rect(const ImVec2& a, const ImVec2& b, float rounding = 0.0f, int rounding_corners = 0x0F); IMGUI_API void Rect(const ImVec2& a, const ImVec2& b, float rounding = 0.0f, int rounding_corners = 0x0F);
IMGUI_API void Fill(ImU32 col); IMGUI_API void Fill(ImU32 col);
IMGUI_API void Stroke(ImU32 col, bool closed = false); IMGUI_API void Stroke(ImU32 col, float thickness, bool closed = false);
// Primitives // Primitives
IMGUI_API void AddLine(const ImVec2& a, const ImVec2& b, ImU32 col, float thickness = 1.0f); IMGUI_API void AddLine(const ImVec2& a, const ImVec2& b, ImU32 col, float thickness = 1.0f);
@ -925,7 +925,7 @@ struct ImDrawList
IMGUI_API void AddCircleFilled(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);
IMGUI_API void AddText(const ImFont* font, float font_size, const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end = NULL, float wrap_width = 0.0f, const ImVec2* cpu_clip_max = NULL); IMGUI_API void AddText(const ImFont* font, float font_size, const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end = NULL, float wrap_width = 0.0f, const ImVec2* cpu_clip_max = NULL);
IMGUI_API void AddImage(ImTextureID user_texture_id, const ImVec2& a, const ImVec2& b, const ImVec2& uv0, const ImVec2& uv1, ImU32 col = 0xFFFFFFFF); IMGUI_API void AddImage(ImTextureID user_texture_id, const ImVec2& a, const ImVec2& b, const ImVec2& uv0, const ImVec2& uv1, ImU32 col = 0xFFFFFFFF);
IMGUI_API void AddPolyline(const ImVec2* points, const int num_points, ImU32 col, bool closed); IMGUI_API void AddPolyline(const ImVec2* points, const int num_points, ImU32 col, float thickness, bool closed);
IMGUI_API void AddConvexPolyFilled(const ImVec2* points, const int num_points, ImU32 col); IMGUI_API void AddConvexPolyFilled(const ImVec2* points, const int num_points, ImU32 col);
// Advanced // Advanced

Loading…
Cancel
Save