mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-04 12:08:47 +02:00
Texture-based round corners: Store rounded corners in texture to use 1 quad per corner.
This commit is contained in:
committed by
ocornut
parent
b6b8f6634e
commit
fbc6bce06b
109
imgui_demo.cpp
109
imgui_demo.cpp
@ -240,6 +240,113 @@ void ImGui::ShowUserGuide()
|
||||
ImGui::Unindent();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
static void GetVtxIdxDelta(ImDrawList* dl, int* vtx, int *idx)
|
||||
{
|
||||
static int vtx_n, idx_n;
|
||||
static int vtx_o, idx_o;
|
||||
vtx_n = dl->VtxBuffer.Size;
|
||||
idx_n = dl->IdxBuffer.Size;
|
||||
|
||||
*vtx = vtx_n - vtx_o;
|
||||
*idx = idx_n - idx_o;
|
||||
|
||||
vtx_o = vtx_n;
|
||||
idx_o = idx_n;
|
||||
}
|
||||
|
||||
static void TestTextureBasedRender()
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
ImGui::TextUnformatted("Press SHIFT to toggle quads (hold to see them).");
|
||||
ImGui::TextUnformatted(io.KeyShift ? "SHIFT ON -- Rasterized quad circle! w00t! OPTIMIZATION!"
|
||||
: "SHIFT OFF -- Regular, boring circle with PathArcToFast.");
|
||||
|
||||
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;
|
||||
ImGui::PushItemWidth(120);
|
||||
ImGui::SliderInt("segments", &segments, 3, 100);
|
||||
ImGui::PopItemWidth();
|
||||
|
||||
int vtx = 0;
|
||||
int idx = 0;
|
||||
ImDrawList* dl = ImGui::GetWindowDrawList();
|
||||
|
||||
{
|
||||
ImGui::Button("##1", ImVec2(200, 200));
|
||||
GetVtxIdxDelta(dl, &vtx, &idx);
|
||||
ImVec2 min = ImGui::GetItemRectMin();
|
||||
ImVec2 size = ImGui::GetItemRectSize();
|
||||
dl->AddCircleFilled(ImVec2(min.x + size.x * 0.5f, min.y + size.y * 0.5f), radius, 0xFFFF00FF, segments);
|
||||
GetVtxIdxDelta(dl, &vtx, &idx);
|
||||
ImGui::Text("AddCircleFilled\n %d vtx, %d idx", vtx, idx);
|
||||
}
|
||||
{
|
||||
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::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));
|
||||
ImVec2 r_min = ImGui::GetItemRectMin();
|
||||
ImVec2 r_max = ImGui::GetItemRectMax();
|
||||
|
||||
GetVtxIdxDelta(dl, &vtx, &idx);
|
||||
dl->AddRectFilled(r_min, r_max, 0xFFFF00FF, radius, flags);
|
||||
GetVtxIdxDelta(dl, &vtx, &idx);
|
||||
ImGui::Text("AddRectFilled\n %d vtx, %d idx", vtx, idx);
|
||||
}
|
||||
{
|
||||
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();
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// [SECTION] Demo Window / ShowDemoWindow()
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -409,6 +516,8 @@ void ImGui::ShowDemoWindow(bool* p_open)
|
||||
ImGui::Text("dear imgui says hello. (%s)", IMGUI_VERSION);
|
||||
ImGui::Spacing();
|
||||
|
||||
TestTextureBasedRender();
|
||||
|
||||
IMGUI_DEMO_MARKER("Help");
|
||||
if (ImGui::CollapsingHeader("Help"))
|
||||
{
|
||||
|
Reference in New Issue
Block a user