DrawList: added PushDrawFlag(), PopDrawFlag(), ImSmallStack_<>

This commit is contained in:
ocornut
2026-07-28 15:48:40 +02:00
parent 59014d15e7
commit fb9fd9a250
5 changed files with 52 additions and 18 deletions

View File

@@ -476,6 +476,7 @@ void ImDrawList::_ResetForNewFrame()
_ClipRectStack.resize(0);
_TextureStack.resize(0);
_CallbacksDataBuf.resize(0);
_DrawFlagsStack.clear();
_Path.resize(0);
_Splitter.Clear();
CmdBuffer.push_back(ImDrawCmd());
@@ -494,6 +495,7 @@ void ImDrawList::_ClearFreeMemory()
_ClipRectStack.clear();
_TextureStack.clear();
_CallbacksDataBuf.clear();
_DrawFlagsStack.clear();
_Path.clear();
_Splitter.ClearFreeMemory();
}
@@ -717,6 +719,24 @@ void ImDrawList::PopTexture()
_OnChangedTexture();
}
// IMPORTANT: currently limited to 3 deep
void ImDrawList::PushDrawFlag(ImDrawFlags flags, bool enabled)
{
IM_ASSERT((flags & ~ImDrawFlags_AllowedInScope_) == 0);
_DrawFlagsStack.push_back(Flags);
if (enabled)
Flags |= flags;
else
Flags &= ~flags;
}
void ImDrawList::PopDrawFlag()
{
IM_ASSERT_USER_ERROR_RET(_DrawFlagsStack.Size > 0, "Calling PopDrawFlags() too many times!");
Flags = _DrawFlagsStack.back();
_DrawFlagsStack.pop_back();
}
// This is used by ImGui::PushFont()/PopFont(). It works because we never use _TextureIdStack[] elsewhere than in PushTexture()/PopTexture().
void ImDrawList::_SetTexture(ImTextureRef tex_ref)
{
@@ -3144,7 +3164,7 @@ void ImDrawList::AddNgon(const ImVec2& center, float radius, ImU32 col, int num_
radius = ImMax(0.01f, radius);
// Check overestimate first before testing details.
// Check overestimate first before testing details (+1.0f is intended, not FringeScale)
if (radius < (thickness * 2.0f + 1.0f))
{
const float unit_apothem = ImCos(IM_PI / (float)num_segments);
@@ -5349,7 +5369,7 @@ static void ImFontAtlasBuildUpdateTexDataCorners(ImFontAtlas* atlas)
const int pitch = tex->Width;
for (int ly = 0; ly < h; ly++)
{
for (int lx = 0; lx < h; lx++)
for (int lx = 0; lx < w; lx++)
write_ptr[lx] = SampleCorner((float)lx + 0.5f, (float)ly + 0.5f, line_normals, line_distances, num_lines) & DEBUG_TEX_CORNER_U8(lx, h);
write_ptr += pitch;
}
@@ -5360,7 +5380,7 @@ static void ImFontAtlasBuildUpdateTexDataCorners(ImFontAtlas* atlas)
const int pitch = tex->Width;
for (int ly = 0; ly < h; ly++)
{
for (int lx = 0; lx < h; lx++)
for (int lx = 0; lx < w; lx++)
write_ptr[lx] = IM_COL32(255, 255, 255, SampleCorner((float)lx + 0.5f, (float)ly + 0.5f, line_normals, line_distances, num_lines)) & DEBUG_TEX_CORNER_U32(lx, h);
write_ptr += pitch;
}