mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-23 04:17:00 +00:00
Texture-based round corners: Make FIXME consistent so they can be grepped. Tidying and added notes of things to fix.
This commit is contained in:
parent
fbc6bce06b
commit
d81c5cbae3
21
imgui.cpp
21
imgui.cpp
@ -5547,25 +5547,10 @@ static const ImGuiResizeBorderDef resize_border_def[4] =
|
|||||||
static void AddResizeGrip(ImDrawList* dl, const ImVec2& corner, unsigned int rad, int corners_flags, ImU32 col)
|
static void AddResizeGrip(ImDrawList* dl, const ImVec2& corner, unsigned int rad, int corners_flags, ImU32 col)
|
||||||
{
|
{
|
||||||
ImTextureID tex = dl->_Data->Font->ContainerAtlas->TexID;
|
ImTextureID tex = dl->_Data->Font->ContainerAtlas->TexID;
|
||||||
IM_ASSERT(tex == dl->_TextureIdStack.back()); // Use high-level ImGui::PushFont() or low-level ImDrawList::PushTextureId() to change font.
|
IM_ASSERT(tex == dl->_TextureIdStack.back()); // Use high-level ImGui::PushFont() or low-level ImDrawList::PushTextureId() to change font.
|
||||||
|
IM_ASSERT(ImIsPowerOfTwo(corners_flags)); // Allow a single corner to be specified here.
|
||||||
switch (corners_flags)
|
|
||||||
{
|
|
||||||
case ImDrawFlags_RoundCornersTopLeft:
|
|
||||||
case ImDrawFlags_RoundCornersTopRight:
|
|
||||||
case ImDrawFlags_RoundCornersBottomLeft:
|
|
||||||
case ImDrawFlags_RoundCornersBottomRight:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
IM_ASSERT("Invalid ImDrawCornerFlags for corner quad. {Top,Bot}{Left,Right} pick exactly one of each!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const ImVec4& uvs = (*dl->_Data->TexUvRoundCornerFilled)[rad - 1];
|
const ImVec4& uvs = (*dl->_Data->TexUvRoundCornerFilled)[rad - 1];
|
||||||
|
|
||||||
// NOTE: test performance using locals instead of array
|
|
||||||
const ImVec2 uv[] =
|
const ImVec2 uv[] =
|
||||||
{
|
{
|
||||||
ImVec2(ImLerp(uvs.x, uvs.z, 0.5f), ImLerp(uvs.y, uvs.w, 0.5f)),
|
ImVec2(ImLerp(uvs.x, uvs.z, 0.5f), ImLerp(uvs.y, uvs.w, 0.5f)),
|
||||||
@ -5861,7 +5846,7 @@ void ImGui::RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar
|
|||||||
{
|
{
|
||||||
const ImGuiResizeGripDef& grip = resize_grip_def[resize_grip_n];
|
const ImGuiResizeGripDef& grip = resize_grip_def[resize_grip_n];
|
||||||
const ImVec2 corner = ImLerp(window->Pos, window->Pos + window->Size, grip.CornerPosN);
|
const ImVec2 corner = ImLerp(window->Pos, window->Pos + window->Size, grip.CornerPosN);
|
||||||
if (g.IO.KeyAlt)
|
if (g.IO.KeyAlt) // FIXME-ROUNDCORNERS
|
||||||
{
|
{
|
||||||
ImVec2 grip_corner = corner;
|
ImVec2 grip_corner = corner;
|
||||||
grip_corner.x += grip.InnerDir.x * window_border_size;
|
grip_corner.x += grip.InnerDir.x * window_border_size;
|
||||||
|
3
imgui.h
3
imgui.h
@ -2833,7 +2833,8 @@ struct ImFontAtlas
|
|||||||
int PackIdMouseCursors; // Custom texture rectangle ID for white pixel and mouse cursors
|
int PackIdMouseCursors; // Custom texture rectangle ID for white pixel and mouse cursors
|
||||||
int PackIdLines; // Custom texture rectangle ID for baked anti-aliased lines
|
int PackIdLines; // Custom texture rectangle ID for baked anti-aliased lines
|
||||||
|
|
||||||
// FIXME-ROUND-SHAPES: WIP
|
// FIXME-ROUNDCORNERS: WIP
|
||||||
|
// FIXME: avoid so many allocations, statically sized buffer removing an indirection may be beneficial here?
|
||||||
int RoundCornersMaxSize; // Max pixel size of round corner textures to generate
|
int RoundCornersMaxSize; // Max pixel size of round corner textures to generate
|
||||||
ImVector<int> RoundCornersRectIds; // Ids of custom rects for round corners indexed by size [0] is 1px, [n] is (n+1)px (index up to RoundCornersMaxSize - 1).
|
ImVector<int> RoundCornersRectIds; // Ids of custom rects for round corners indexed by size [0] is 1px, [n] is (n+1)px (index up to RoundCornersMaxSize - 1).
|
||||||
ImVector<ImVec4> TexUvRoundCornerFilled; // Texture coordinates to filled round corner quads
|
ImVector<ImVec4> TexUvRoundCornerFilled; // Texture coordinates to filled round corner quads
|
||||||
|
148
imgui_demo.cpp
148
imgui_demo.cpp
@ -257,94 +257,108 @@ static void GetVtxIdxDelta(ImDrawList* dl, int* vtx, int *idx)
|
|||||||
idx_o = idx_n;
|
idx_o = idx_n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/ocornut/imgui/issues/1962
|
||||||
|
// FIXME-ROUNDCORNERS: Sizes aren't matching.
|
||||||
|
// FIXME-ROUNDCORNERS: Lift the RoundCornersMaxSize limitation, fallback on existing renderer.
|
||||||
|
// FIXME-ROUNDCORNERS: Work on reducing filtrate for stroked shapes (may need to trade some cpu/vtx to reduce fill-rate for e.g. simple stroked circle) > https://github.com/ocornut/imgui/issues/1962#issuecomment-411507917
|
||||||
|
// FIXME-ROUNDCORNERS: Figure out how to support multiple thickness, might hard-code common steps (1.0, 1.5, 2.0, 3.0), not super satisfactory but may be best
|
||||||
|
// FIXME-ROUNDCORNERS: AddCircle* API relying on num_segments may need rework, might obsolete this parameter, or make it 0 default and rely on automatic subdivision similar to style.CurveTessellationTol for Bezier
|
||||||
|
// FIXME-ROUNDCORNERS: Intentional "low segment count" shapes (e.g. hexagon) currently achieved with AddCircle may need a new API (AddNgon?)
|
||||||
static void TestTextureBasedRender()
|
static void TestTextureBasedRender()
|
||||||
{
|
{
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
ImGuiStyle& style = ImGui::GetStyle();
|
||||||
|
|
||||||
ImGui::TextUnformatted("Press SHIFT to toggle quads (hold to see them).");
|
ImGui::Begin("tex_round_corners");
|
||||||
ImGui::TextUnformatted(io.KeyShift ? "SHIFT ON -- Rasterized quad circle! w00t! OPTIMIZATION!"
|
|
||||||
: "SHIFT OFF -- Regular, boring circle with PathArcToFast.");
|
ImGui::Text("Hold SHIFT to toggle (%s)", io.KeyShift ? "SHIFT ON -- Using textures." : "SHIFT OFF -- Old method.");
|
||||||
|
|
||||||
static float radius = io.Fonts->RoundCornersMaxSize * 0.5f;
|
static float radius = io.Fonts->RoundCornersMaxSize * 0.5f;
|
||||||
ImGui::SliderFloat("radius", &radius, 0.0f, (float)io.Fonts->RoundCornersMaxSize, "%.0f");
|
|
||||||
ImGui::BeginGroup();
|
|
||||||
|
|
||||||
static int segments = 20;
|
static int segments = 20;
|
||||||
ImGui::PushItemWidth(120);
|
|
||||||
ImGui::SliderInt("segments", &segments, 3, 100);
|
|
||||||
ImGui::PopItemWidth();
|
|
||||||
|
|
||||||
int vtx = 0;
|
ImGui::SliderFloat("radius", &radius, 0.0f, (float)io.Fonts->RoundCornersMaxSize, "%.0f");
|
||||||
int idx = 0;
|
|
||||||
ImDrawList* dl = ImGui::GetWindowDrawList();
|
int vtx_n = 0;
|
||||||
|
int idx_n = 0;
|
||||||
|
ImDrawList* draw_list = ImGui::GetWindowDrawList();
|
||||||
|
|
||||||
{
|
{
|
||||||
ImGui::Button("##1", ImVec2(200, 200));
|
ImGui::BeginGroup();
|
||||||
GetVtxIdxDelta(dl, &vtx, &idx);
|
|
||||||
ImVec2 min = ImGui::GetItemRectMin();
|
ImGui::PushItemWidth(120);
|
||||||
ImVec2 size = ImGui::GetItemRectSize();
|
ImGui::SliderInt("segments", &segments, 3, 100);
|
||||||
dl->AddCircleFilled(ImVec2(min.x + size.x * 0.5f, min.y + size.y * 0.5f), radius, 0xFFFF00FF, segments);
|
ImGui::PopItemWidth();
|
||||||
GetVtxIdxDelta(dl, &vtx, &idx);
|
|
||||||
ImGui::Text("AddCircleFilled\n %d vtx, %d idx", vtx, idx);
|
{
|
||||||
|
ImGui::Button("##1", ImVec2(200, 200));
|
||||||
|
GetVtxIdxDelta(draw_list, &vtx_n, &idx_n);
|
||||||
|
ImVec2 min = ImGui::GetItemRectMin();
|
||||||
|
ImVec2 size = ImGui::GetItemRectSize();
|
||||||
|
draw_list->AddCircleFilled(ImVec2(min.x + size.x * 0.5f, min.y + size.y * 0.5f), radius, IM_COL32(255,0,255,255), segments);
|
||||||
|
GetVtxIdxDelta(draw_list, &vtx_n, &idx_n);
|
||||||
|
ImGui::Text("AddCircleFilled\n %d vtx, %d idx", vtx_n, idx_n);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
ImGui::Button("##2", ImVec2(200, 200));
|
||||||
|
GetVtxIdxDelta(draw_list, &vtx_n, &idx_n);
|
||||||
|
ImVec2 min = ImGui::GetItemRectMin();
|
||||||
|
ImVec2 size = ImGui::GetItemRectSize();
|
||||||
|
draw_list->AddCircle(ImVec2(min.x + size.x * 0.5f, min.y + size.y * 0.5f), radius, IM_COL32(255,0,255,255), segments);
|
||||||
|
GetVtxIdxDelta(draw_list, &vtx_n, &idx_n);
|
||||||
|
ImGui::Text("AddCircle\n %d vtx, %d idx", vtx_n, idx_n);
|
||||||
|
}
|
||||||
|
ImGui::EndGroup();
|
||||||
}
|
}
|
||||||
{
|
|
||||||
ImGui::Button("##2", ImVec2(200, 200));
|
|
||||||
GetVtxIdxDelta(dl, &vtx, &idx);
|
|
||||||
ImVec2 min = ImGui::GetItemRectMin();
|
|
||||||
ImVec2 size = ImGui::GetItemRectSize();
|
|
||||||
dl->AddCircle(ImVec2(min.x + size.x * 0.5f, min.y + size.y * 0.5f), radius, 0xFFFF00FF, segments);
|
|
||||||
GetVtxIdxDelta(dl, &vtx, &idx);
|
|
||||||
ImGui::Text("AddCircle\n %d vtx, %d idx", vtx, idx);
|
|
||||||
}
|
|
||||||
ImGui::EndGroup();
|
|
||||||
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
|
|
||||||
ImGui::BeginGroup();
|
|
||||||
static bool tl = true, tr = true, bl = true, br = true;
|
|
||||||
ImGui::Checkbox("TL", &tl);
|
|
||||||
ImGui::SameLine(0, 12);
|
|
||||||
ImGui::Checkbox("TR", &tr);
|
|
||||||
ImGui::SameLine(0, 12);
|
|
||||||
ImGui::Checkbox("BL", &bl);
|
|
||||||
ImGui::SameLine(0, 12);
|
|
||||||
ImGui::Checkbox("BR", &br);
|
|
||||||
|
|
||||||
ImDrawFlags flags = 0;
|
|
||||||
flags |= tl ? ImDrawFlags_RoundCornersTopLeft : 0;
|
|
||||||
flags |= tr ? ImDrawFlags_RoundCornersTopRight : 0;
|
|
||||||
flags |= bl ? ImDrawFlags_RoundCornersBottomLeft : 0;
|
|
||||||
flags |= br ? ImDrawFlags_RoundCornersBottomRight : 0;
|
|
||||||
if (flags == 0)
|
|
||||||
flags |= ImDrawFlags_RoundCornersNone;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
ImGui::Button("", ImVec2(200, 200));
|
ImGui::BeginGroup();
|
||||||
ImVec2 r_min = ImGui::GetItemRectMin();
|
|
||||||
ImVec2 r_max = ImGui::GetItemRectMax();
|
|
||||||
|
|
||||||
GetVtxIdxDelta(dl, &vtx, &idx);
|
static ImDrawFlags corner_flags = ImDrawFlags_RoundCornersAll;
|
||||||
dl->AddRectFilled(r_min, r_max, 0xFFFF00FF, radius, flags);
|
ImGui::CheckboxFlags("TL", (unsigned int*)&corner_flags, ImDrawFlags_RoundCornersTopLeft);
|
||||||
GetVtxIdxDelta(dl, &vtx, &idx);
|
ImGui::SameLine();
|
||||||
ImGui::Text("AddRectFilled\n %d vtx, %d idx", vtx, idx);
|
ImGui::CheckboxFlags("TR", (unsigned int*)&corner_flags, ImDrawFlags_RoundCornersTopRight);
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::CheckboxFlags("BL", (unsigned int*)&corner_flags, ImDrawFlags_RoundCornersBottomLeft);
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::CheckboxFlags("BR", (unsigned int*)&corner_flags, ImDrawFlags_RoundCornersBottomRight);
|
||||||
|
|
||||||
|
{
|
||||||
|
ImGui::Button("##3", ImVec2(200, 200));
|
||||||
|
ImVec2 r_min = ImGui::GetItemRectMin();
|
||||||
|
ImVec2 r_max = ImGui::GetItemRectMax();
|
||||||
|
|
||||||
|
GetVtxIdxDelta(draw_list, &vtx_n, &idx_n);
|
||||||
|
draw_list->AddRectFilled(r_min, r_max, IM_COL32(255,0,255,255), radius, corner_flags ? corner_flags : ImDrawFlags_RoundCornersNone);
|
||||||
|
GetVtxIdxDelta(draw_list, &vtx_n, &idx_n);
|
||||||
|
ImGui::Text("AddRectFilled\n %d vtx, %d idx", vtx_n, idx_n);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
ImGui::Button("##4", ImVec2(200, 200));
|
||||||
|
ImVec2 r_min = ImGui::GetItemRectMin();
|
||||||
|
ImVec2 r_max = ImGui::GetItemRectMax();
|
||||||
|
|
||||||
|
GetVtxIdxDelta(draw_list, &vtx_n, &idx_n);
|
||||||
|
draw_list->AddRect(r_min, r_max, IM_COL32(255,0,255,255), radius, corner_flags);
|
||||||
|
GetVtxIdxDelta(draw_list, &vtx_n, &idx_n);
|
||||||
|
ImGui::Text("AddRect\n %d vtx, %d idx", vtx_n, idx_n);
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::EndGroup();
|
||||||
}
|
}
|
||||||
{
|
|
||||||
ImGui::Button("", ImVec2(200, 200));
|
|
||||||
ImVec2 r_min = ImGui::GetItemRectMin();
|
|
||||||
ImVec2 r_max = ImGui::GetItemRectMax();
|
|
||||||
|
|
||||||
GetVtxIdxDelta(dl, &vtx, &idx);
|
|
||||||
dl->AddRect(r_min, r_max, 0xFFFF00FF, radius, flags);
|
|
||||||
GetVtxIdxDelta(dl, &vtx, &idx);
|
|
||||||
ImGui::Text("AddRect\n %d vtx, %d idx", vtx, idx);
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::EndGroup();
|
|
||||||
|
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
|
|
||||||
|
ImGui::Text("Style");
|
||||||
|
ImGui::SliderFloat("FrameRounding", &style.FrameRounding, 0.0f, 100.0f, "%.0f");
|
||||||
|
ImGui::SliderFloat("WindowRounding", &style.WindowRounding, 0.0f, 100.0f, "%.0f");
|
||||||
|
|
||||||
|
// Show atlas
|
||||||
|
ImGui::Text("Atlas");
|
||||||
ImFontAtlas* atlas = ImGui::GetIO().Fonts;
|
ImFontAtlas* atlas = ImGui::GetIO().Fonts;
|
||||||
ImGui::Image(atlas->TexID, ImVec2((float)atlas->TexWidth, (float)atlas->TexHeight), ImVec2(0, 0), ImVec2(1, 1), ImColor(255, 255, 255, 255), ImColor(255, 255, 255, 128));
|
ImGui::Image(atlas->TexID, ImVec2((float)atlas->TexWidth, (float)atlas->TexHeight), ImVec2(0, 0), ImVec2(1, 1), ImColor(255, 255, 255, 255), ImColor(255, 255, 255, 128));
|
||||||
|
|
||||||
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
@ -1457,7 +1457,7 @@ inline void AddRoundCornerRect(ImDrawList* draw_list, const ImVec2& a, const ImV
|
|||||||
int vyc = vcc, vxc = vcc, vic = vcc;
|
int vyc = vcc, vxc = vcc, vic = vcc;
|
||||||
int vyd = vcd, vxd = vcd, vid = vcd;
|
int vyd = vcd, vxd = vcd, vid = vcd;
|
||||||
|
|
||||||
// FIXME-ROUND_SHAPES: TODO: find a way of saving vertices/triangles here?
|
// FIXME-ROUNDCORNERS: TODO: find a way of saving vertices/triangles here?
|
||||||
// currently it's the same cost regardless of how many corners are rounded
|
// currently it's the same cost regardless of how many corners are rounded
|
||||||
|
|
||||||
if (ba || 1)
|
if (ba || 1)
|
||||||
@ -1577,7 +1577,7 @@ void ImDrawList::AddRect(const ImVec2& p_min, const ImVec2& p_max, ImU32 col, fl
|
|||||||
rounding = ImMin(rounding, ImFabs(p_max.y - p_min.y) * (((flags & ImDrawFlags_RoundCornersLeft) == ImDrawFlags_RoundCornersLeft) || ((flags & ImDrawFlags_RoundCornersRight) == ImDrawFlags_RoundCornersRight) ? 0.5f : 1.0f) - 1.0f);
|
rounding = ImMin(rounding, ImFabs(p_max.y - p_min.y) * (((flags & ImDrawFlags_RoundCornersLeft) == ImDrawFlags_RoundCornersLeft) || ((flags & ImDrawFlags_RoundCornersRight) == ImDrawFlags_RoundCornersRight) ? 0.5f : 1.0f) - 1.0f);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// FIXME-ROUND-SHAPES: NOTE HACK TODO figure out why it's broken on small rounding
|
// FIXME-ROUNDCORNERS: NOTE HACK TODO figure out why it's broken on small rounding
|
||||||
if (ImGui::GetIO().KeyShift && rounding > 3)
|
if (ImGui::GetIO().KeyShift && rounding > 3)
|
||||||
return AddRoundCornerRect(this, p_min, p_max, col, rounding, flags, /* fill */ false);
|
return AddRoundCornerRect(this, p_min, p_max, col, rounding, flags, /* fill */ false);
|
||||||
|
|
||||||
@ -1606,7 +1606,7 @@ void ImDrawList::AddRectFilled(const ImVec2& p_min, const ImVec2& p_max, ImU32 c
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// FIXME-ROUND-SHAPES: NOTE HACK TODO figure out why it's broken on small rounding
|
// FIXME-ROUNDCORNERS: NOTE HACK TODO figure out why it's broken on small rounding
|
||||||
if (ImGui::GetIO().KeyShift && rounding > 3)
|
if (ImGui::GetIO().KeyShift && rounding > 3)
|
||||||
{
|
{
|
||||||
AddRoundCornerRect(this, p_min, p_max, col, rounding, flags, /* fill */ true);
|
AddRoundCornerRect(this, p_min, p_max, col, rounding, flags, /* fill */ true);
|
||||||
@ -1755,7 +1755,7 @@ void ImDrawList::AddCircle(const ImVec2& center, float radius, ImU32 col, int nu
|
|||||||
if ((col & IM_COL32_A_MASK) == 0 || radius <= 0.0f)
|
if ((col & IM_COL32_A_MASK) == 0 || radius <= 0.0f)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (ImGui::GetIO().KeyShift)
|
if (ImGui::GetIO().KeyShift) // FIXME-ROUNDCORNERS
|
||||||
{
|
{
|
||||||
AddRoundCornerCircle(this, center, radius, col, false);
|
AddRoundCornerCircle(this, center, radius, col, false);
|
||||||
return;
|
return;
|
||||||
@ -1823,7 +1823,7 @@ void ImDrawList::AddNgonFilled(const ImVec2& center, float radius, ImU32 col, in
|
|||||||
if ((col & IM_COL32_A_MASK) == 0 || num_segments <= 2)
|
if ((col & IM_COL32_A_MASK) == 0 || num_segments <= 2)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (ImGui::GetIO().KeyShift)
|
if (ImGui::GetIO().KeyShift) // FIXME-ROUNDCORNERS
|
||||||
{
|
{
|
||||||
AddRoundCornerCircle(this, center, radius, col, true);
|
AddRoundCornerCircle(this, center, radius, col, true);
|
||||||
return;
|
return;
|
||||||
@ -3073,9 +3073,8 @@ const int FONT_ATLAS_ROUNDED_CORNER_TEX_PADDING = 2;
|
|||||||
|
|
||||||
static void ImFontAtlasBuildRegisterRoundCornersCustomRects(ImFontAtlas* atlas)
|
static void ImFontAtlasBuildRegisterRoundCornersCustomRects(ImFontAtlas* atlas)
|
||||||
{
|
{
|
||||||
if (atlas->RoundCornersRectIds.size() > 0)
|
if (atlas->RoundCornersRectIds.Size > 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ((atlas->Flags & ImFontAtlasFlags_NoBakedRoundCorners))
|
if ((atlas->Flags & ImFontAtlasFlags_NoBakedRoundCorners))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -3094,32 +3093,28 @@ static void ImFontAtlasBuildRegisterRoundCornersCustomRects(ImFontAtlas* atlas)
|
|||||||
static void ImFontAtlasBuildRenderRoundCornersTexData(ImFontAtlas* atlas)
|
static void ImFontAtlasBuildRenderRoundCornersTexData(ImFontAtlas* atlas)
|
||||||
{
|
{
|
||||||
IM_ASSERT(atlas->TexPixelsAlpha8 != NULL);
|
IM_ASSERT(atlas->TexPixelsAlpha8 != NULL);
|
||||||
IM_ASSERT(atlas->TexUvRoundCornerFilled.size() == 0);
|
IM_ASSERT(atlas->TexUvRoundCornerFilled.Size == 0);
|
||||||
IM_ASSERT(atlas->TexUvRoundCornerStroked.size() == 0);
|
IM_ASSERT(atlas->TexUvRoundCornerStroked.Size == 0);
|
||||||
|
if (atlas->Flags & ImFontAtlasFlags_NoBakedRoundCorners)
|
||||||
if ((atlas->Flags & ImFontAtlasFlags_NoBakedRoundCorners))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// Render the texture
|
||||||
const int w = atlas->TexWidth;
|
const int w = atlas->TexWidth;
|
||||||
const unsigned int max = atlas->RoundCornersMaxSize;
|
const unsigned int max = atlas->RoundCornersMaxSize;
|
||||||
|
const int pad = FONT_ATLAS_ROUNDED_CORNER_TEX_PADDING;
|
||||||
// Filled
|
|
||||||
for (unsigned int stage = 0; stage < 2; stage++)
|
for (unsigned int stage = 0; stage < 2; stage++)
|
||||||
{
|
{
|
||||||
bool filled = stage == 0;
|
const bool filled = (stage == 0);
|
||||||
for (unsigned int n = 0; n < max; n++)
|
for (unsigned int n = 0; n < max; n++)
|
||||||
{
|
{
|
||||||
const unsigned int id = (filled ? 0 : max) + n;
|
const unsigned int id = (filled ? 0 : max) + n;
|
||||||
IM_ASSERT(atlas->RoundCornersRectIds.size() > (int) n);
|
IM_ASSERT(atlas->RoundCornersRectIds.Size > (int)n);
|
||||||
ImFontAtlasCustomRect& r = atlas->CustomRects[atlas->RoundCornersRectIds[id]];
|
ImFontAtlasCustomRect& r = atlas->CustomRects[atlas->RoundCornersRectIds[id]];
|
||||||
IM_ASSERT(r.IsPacked());
|
IM_ASSERT(r.IsPacked());
|
||||||
|
|
||||||
const int pad = FONT_ATLAS_ROUNDED_CORNER_TEX_PADDING;
|
|
||||||
|
|
||||||
IM_ASSERT(r.Width == n + 1 + pad * 2 && r.Height == n + 1 + pad * 2);
|
IM_ASSERT(r.Width == n + 1 + pad * 2 && r.Height == n + 1 + pad * 2);
|
||||||
|
|
||||||
const int radius = (int)(r.Width - pad * 2);
|
const int radius = (int)(r.Width - pad * 2);
|
||||||
const float stroke_width = 1.0f;
|
const float stroke_width = 1.0f; // FIXME-ROUNDCORNERS
|
||||||
|
|
||||||
for (int y = -pad; y < (int) (radius); y++)
|
for (int y = -pad; y < (int) (radius); y++)
|
||||||
for (int x = (filled ? -pad : y); x < (int)(filled ? y + pad : radius); x++)
|
for (int x = (filled ? -pad : y); x < (int)(filled ? y + pad : radius); x++)
|
||||||
@ -3129,10 +3124,12 @@ static void ImFontAtlasBuildRenderRoundCornersTexData(ImFontAtlas* atlas)
|
|||||||
float alpha = 0.0f;
|
float alpha = 0.0f;
|
||||||
if (filled)
|
if (filled)
|
||||||
{
|
{
|
||||||
|
// Fill
|
||||||
alpha = ImClamp(-dist, 0.0f, 1.0f);
|
alpha = ImClamp(-dist, 0.0f, 1.0f);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// Stroke
|
||||||
const float alpha1 = ImClamp(dist + stroke_width, 0.0f, 1.0f);
|
const float alpha1 = ImClamp(dist + stroke_width, 0.0f, 1.0f);
|
||||||
const float alpha2 = ImClamp(dist, 0.0f, 1.0f);
|
const float alpha2 = ImClamp(dist, 0.0f, 1.0f);
|
||||||
alpha = alpha1 - alpha2;
|
alpha = alpha1 - alpha2;
|
||||||
|
@ -725,7 +725,7 @@ struct IMGUI_API ImDrawListSharedData
|
|||||||
ImU8 CircleSegmentCounts[64]; // Precomputed segment count for given radius before we calculate it dynamically (to avoid calculation overhead)
|
ImU8 CircleSegmentCounts[64]; // Precomputed segment count for given radius before we calculate it dynamically (to avoid calculation overhead)
|
||||||
const ImVec4* TexUvLines; // UV of anti-aliased lines in the atlas
|
const ImVec4* TexUvLines; // UV of anti-aliased lines in the atlas
|
||||||
|
|
||||||
// FIXME-ROUNDSHAPES: WIP + need to remove CircleVtx12 before PR
|
// FIXME-ROUNDCORNERS: WIP + need to remove CircleVtx12 before PR
|
||||||
ImVector<ImVec4>* TexUvRoundCornerFilled; // UV of filled round corner quad in the atlas
|
ImVector<ImVec4>* TexUvRoundCornerFilled; // UV of filled round corner quad in the atlas
|
||||||
ImVector<ImVec4>* TexUvRoundCornerStroked; // UV of stroked round corner quad in the atlas
|
ImVector<ImVec4>* TexUvRoundCornerStroked; // UV of stroked round corner quad in the atlas
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user