DrawList: removed g_LEGACY_STROKES.

This commit is contained in:
ocornut
2026-07-28 18:27:36 +02:00
parent fe8acacdde
commit 5f7012f7ac
4 changed files with 22 additions and 110 deletions

View File

@@ -1398,9 +1398,6 @@ static const float DOCKING_TRANSPARENT_PAYLOAD_ALPHA = 0.50f; // For u
// [SECTION] FORWARD DECLARATIONS
//-------------------------------------------------------------------------
extern bool g_LEGACY_STROKES;
bool g_LEGACY_STROKES = false;
static void SetCurrentWindow(ImGuiWindow* window);
static ImGuiWindow* CreateNewWindow(const char* name, ImGuiWindowFlags flags);
static ImVec2 CalcNextScrollFromScrollTargetAndClamp(ImGuiWindow* window);
@@ -6107,9 +6104,6 @@ void ImGui::NewFrame()
g.DebugBeginReturnValueCullDepth = -1;
#endif
g_LEGACY_STROKES = g.IO.KeyShift;
ImGui::Checkbox("g_LEGACY_STROKES", &g_LEGACY_STROKES);
CallContextHooks(&g, ImGuiContextHookType_NewFramePost);
}
@@ -7614,9 +7608,6 @@ static void ImGui::RenderWindowOuterBorders(ImGuiWindow* window)
if (g.Style.FrameBorderSize > 0 && !(window->Flags & ImGuiWindowFlags_NoTitleBar) && !window->DockIsActive)
{
float y = window->Pos.y + window->TitleBarHeight - 1;
if (g_LEGACY_STROKES)
window->DrawList->AddLineH(window->Pos.x + border_size * 0.5f, window->Pos.x + window->Size.x - border_size * 0.5f, y, border_col, g.Style.FrameBorderSize);
else
window->DrawList->AddLineH(window->Pos.x + border_size, window->Pos.x + window->Size.x - border_size, y, border_col, g.Style.FrameBorderSize, ImDrawFlags_StrokeCenterBiased);
}
}
@@ -7727,12 +7718,7 @@ void ImGui::RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar
menu_bar_rect.ClipWith(window->Rect()); // Soft clipping, in particular child window don't have minimum size covering the menu bar so this is useful for them.
window->DrawList->AddRectFilled(menu_bar_rect.Min, menu_bar_rect.Max, GetColorU32(ImGuiCol_MenuBarBg), (flags & ImGuiWindowFlags_NoTitleBar) ? window_rounding : 0.0f, ImDrawFlags_RoundCornersTop);
if (style.FrameBorderSize > 0.0f && menu_bar_rect.Max.y < window->Pos.y + window->Size.y)
{
if (g_LEGACY_STROKES)
window->DrawList->AddLineH(menu_bar_rect.Min.x + window_border_size * 0.5f, menu_bar_rect.Max.x - window_border_size * 0.5f, menu_bar_rect.Max.y, GetColorU32(ImGuiCol_Border), style.FrameBorderSize);
else
window->DrawList->AddLineH(menu_bar_rect.Min.x + window_border_size, menu_bar_rect.Max.x - window_border_size, menu_bar_rect.Max.y, GetColorU32(ImGuiCol_Border), style.FrameBorderSize, ImDrawFlags_StrokeCenterBiased);
}
}
// Docking: Unhide tab bar (small triangle in the corner), drag from small triangle to quickly undock
@@ -24268,9 +24254,6 @@ void ImGui::DebugDrawLineExtents(ImU32 col)
float line_y1 = (window->DC.IsSameLine ? window->DC.CursorPosPrevLine.y : window->DC.CursorPos.y);
float line_y2 = line_y1 + (window->DC.IsSameLine ? window->DC.PrevLineSize.y : window->DC.CurrLineSize.y);
window->DrawList->AddLineH(curr_x - 4.0f, curr_x + 5.0f, line_y1, col, 1.0f);
if (g_LEGACY_STROKES)
window->DrawList->AddLineV(curr_x - 0.5f, line_y1, line_y2, col, 1.0f);
else
window->DrawList->AddLineV(curr_x, line_y1, line_y2, col, 1.0f);
window->DrawList->AddLineH(curr_x - 4.0f, curr_x + 5.0f, line_y2, col, 1.0f);
}

View File

@@ -936,8 +936,6 @@ void ImDrawList::_SelectFringeTexture(float screen_thickness, ImVec4* out_tex_uv
}
}
// We intently don't turn g_LEGACY_STROKES into ImDrawFlags_StrokeLegacy here.
// The earlier should use verbatim legacy code but will be removed before release once we confirm that both matches.
static inline ImDrawFlags _GetStrokePos(ImDrawFlags flags, ImDrawFlags default_stroke_pos)
{
if (flags & ImDrawFlags_StrokeMask_)
@@ -947,16 +945,8 @@ static inline ImDrawFlags _GetStrokePos(ImDrawFlags flags, ImDrawFlags default_s
IM_MSVC_RUNTIME_CHECKS_RESTORE
extern bool g_LEGACY_STROKES;
void ImDrawList::AddPolyline(const ImVec2* points, const int points_count, ImU32 col, float thickness, ImDrawFlags flags)
{
if (g_LEGACY_STROKES)
{
AddPolylineLegacy(points, points_count, col, thickness, flags);
return;
}
if (points_count < 2 || (col & IM_COL32_A_MASK) == 0)
return;
@@ -2200,13 +2190,6 @@ void ImDrawList::PathRect(const ImVec2& a, const ImVec2& b, float rounding, ImDr
void ImDrawList::_AddLine(const ImVec2& p1, const ImVec2& p2, ImU32 col, float thickness, ImDrawFlags flags)
{
if (g_LEGACY_STROKES) IM_UNLIKELY
{
ImVec2 points[2] = { p1, p2 };
AddPolylineLegacy(points, 2, col, thickness, flags);
return;
}
if ((col & IM_COL32_A_MASK) == 0) IM_UNLIKELY
return;
@@ -2349,7 +2332,7 @@ void ImDrawList::AddLine(const ImVec2& p1, const ImVec2& p2, ImU32 col, float th
flags |= Flags;
ImDrawFlags stroke_pos = _GetStrokePos(flags, ImDrawFlags_StrokeCenter);
if (g_LEGACY_STROKES || stroke_pos == ImDrawFlags_StrokeLegacy)
if (stroke_pos == ImDrawFlags_StrokeLegacy)
{
_AddLine(ImVec2(p1.x + 0.5f, p1.y + 0.5f), ImVec2(p2.x + 0.5f, p2.y + 0.5f), col, thickness, flags);
return;
@@ -2365,7 +2348,7 @@ void ImDrawList::AddLineH(float min_x, float max_x, float y, ImU32 col, float th
flags |= Flags;
ImDrawFlags stroke_pos = _GetStrokePos(flags, ImDrawFlags_StrokeInside);
if (g_LEGACY_STROKES || stroke_pos == ImDrawFlags_StrokeLegacy)
if (stroke_pos == ImDrawFlags_StrokeLegacy)
{
_AddLine(ImVec2(min_x + 0.5f, y + 0.5f), ImVec2(max_x + 0.5f, y + 0.5f), col, thickness, flags);
return;
@@ -2411,7 +2394,7 @@ void ImDrawList::AddLineV(float x, float min_y, float max_y, ImU32 col, float th
flags |= Flags;
ImDrawFlags stroke_pos = _GetStrokePos(flags, ImDrawFlags_StrokeInside);
if (g_LEGACY_STROKES || stroke_pos == ImDrawFlags_StrokeLegacy)
if (stroke_pos == ImDrawFlags_StrokeLegacy)
{
_AddLine(ImVec2(x + 0.5f, min_y + 0.5f), ImVec2(x + 0.5f, max_y + 0.5f), col, thickness, flags);
return;
@@ -2708,8 +2691,7 @@ void ImDrawList::AddRect(const ImVec2& p_min, const ImVec2& p_max, ImU32 col, fl
flags |= Flags;
ImDrawFlags stroke_pos = _GetStrokePos(flags, ImDrawFlags_StrokeInside);
if (g_LEGACY_STROKES || stroke_pos == ImDrawFlags_StrokeLegacy) IM_UNLIKELY
if (stroke_pos == ImDrawFlags_StrokeLegacy) IM_UNLIKELY
{
if (Flags & ImDrawFlags_AALines)
PathRect(ImVec2(p_min.x + 0.50f, p_min.y + 0.50f), ImVec2(p_max.x - 0.50f, p_max.y - 0.50f), rounding, flags);
@@ -2992,8 +2974,9 @@ void ImDrawList::AddQuad(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, c
if ((col & IM_COL32_A_MASK) == 0)
return;
ImDrawFlags stroke_pos = g_LEGACY_STROKES ? ImDrawFlags_StrokeLegacy : _GetStrokePos(flags, ImDrawFlags_StrokeInside);
ImDrawFlags stroke_pos = _GetStrokePos(flags, ImDrawFlags_StrokeInside);
flags = (flags & ~ImDrawFlags_StrokeMask_) | stroke_pos;
const ImVec2 points[4] = { p1, p2, p3, p4 };
AddPolyline(points, 4, col, thickness, flags | ImDrawFlags_Closed);
}
@@ -3012,7 +2995,7 @@ void ImDrawList::AddTriangle(const ImVec2& p1, const ImVec2& p2, const ImVec2& p
if ((col & IM_COL32_A_MASK) == 0)
return;
ImDrawFlags stroke_pos = g_LEGACY_STROKES ? ImDrawFlags_StrokeLegacy : _GetStrokePos(flags, ImDrawFlags_StrokeInside);
ImDrawFlags stroke_pos = _GetStrokePos(flags, ImDrawFlags_StrokeInside);
flags = (flags & ~ImDrawFlags_StrokeMask_) | stroke_pos;
const ImVec2 points[3] = { p1, p2, p3 };
@@ -3035,7 +3018,7 @@ void ImDrawList::AddCircle(const ImVec2& center, float radius, ImU32 col, int nu
flags |= Flags;
ImDrawFlags stroke_pos = _GetStrokePos(flags, ImDrawFlags_StrokeInside);
if (g_LEGACY_STROKES || stroke_pos == ImDrawFlags_StrokeLegacy) IM_UNLIKELY
if (stroke_pos == ImDrawFlags_StrokeLegacy) IM_UNLIKELY
{
radius -= 0.5f;
stroke_pos = ImDrawFlags_StrokeCenter;
@@ -3119,7 +3102,7 @@ void ImDrawList::AddNgon(const ImVec2& center, float radius, ImU32 col, int num_
flags |= Flags;
ImDrawFlags stroke_pos = _GetStrokePos(flags, ImDrawFlags_StrokeInside);
if (g_LEGACY_STROKES || stroke_pos == ImDrawFlags_StrokeLegacy) IM_UNLIKELY
if (stroke_pos == ImDrawFlags_StrokeLegacy) IM_UNLIKELY
{
radius -= 0.5f;
stroke_pos = ImDrawFlags_StrokeCenter;
@@ -3183,8 +3166,7 @@ void ImDrawList::AddEllipse(const ImVec2& center, const ImVec2& radius, ImU32 co
return;
ImDrawFlags stroke_pos = _GetStrokePos(flags, ImDrawFlags_StrokeInside);
if (g_LEGACY_STROKES || stroke_pos == ImDrawFlags_StrokeLegacy)
if (stroke_pos == ImDrawFlags_StrokeLegacy)
stroke_pos = ImDrawFlags_StrokeCenter;
ImVec2 rad = radius;

View File

@@ -2950,8 +2950,6 @@ static ImU32 TableGetColumnBorderCol(ImGuiTable* table, int order_n, int column_
return table->BorderColorLight;
}
extern bool g_LEGACY_STROKES;
// FIXME-TABLE: This is a mess, need to redesign how we render borders (as some are also done in TableEndRow)
void ImGui::TableDrawBorders(ImGuiTable* table)
{
@@ -2966,11 +2964,7 @@ void ImGui::TableDrawBorders(ImGuiTable* table)
// Draw inner border and resizing feedback
ImGuiTableInstanceData* table_instance = TableGetInstanceData(table, table->InstanceCurrent);
const float border_size = TABLE_BORDER_SIZE;
float draw_y1;
if (g_LEGACY_STROKES)
draw_y1 = ImMax(table->InnerRect.Min.y, (table->FreezeRowsCount >= 1 ? table->InnerRect.Min.y : table->WorkRect.Min.y) + table->AngledHeadersHeight) + ((table->Flags & ImGuiTableFlags_BordersOuterH) ? 1.0f : 0.0f);
else
draw_y1 = ImMax(table->InnerRect.Min.y, (table->FreezeRowsCount >= 1 ? table->InnerRect.Min.y : table->WorkRect.Min.y) + table->AngledHeadersHeight) + ((table->Flags & ImGuiTableFlags_BordersOuterH) ? border_size : 0.0f);
const float draw_y1 = ImMax(table->InnerRect.Min.y, (table->FreezeRowsCount >= 1 ? table->InnerRect.Min.y : table->WorkRect.Min.y) + table->AngledHeadersHeight) + ((table->Flags & ImGuiTableFlags_BordersOuterH) ? border_size : 0.0f);
const float draw_y2_body = table->InnerRect.Max.y;
const float draw_y2_head = table->IsUsingHeaders ? ImMin(table->InnerRect.Max.y, (table->FreezeRowsCount >= 1 ? table->InnerRect.Min.y : table->WorkRect.Min.y) + table_instance->LastTopHeadersRowHeight) : draw_y1;
if (table->Flags & ImGuiTableFlags_BordersInnerV)
@@ -3041,12 +3035,7 @@ void ImGui::TableDrawBorders(ImGuiTable* table)
const float h_inset = (table->Flags & ImGuiTableFlags_BordersOuterV) ? border_size : 0.0f;
const float border_y = table->RowPosY2;
if (border_y >= table->BgClipRect.Min.y && border_y < table->BgClipRect.Max.y)
{
if (g_LEGACY_STROKES)
inner_drawlist->AddLineH(table->BorderX1, table->BorderX2, border_y, table->BorderColorLight, border_size);
else
inner_drawlist->AddLineH(table->BorderX1 + h_inset, table->BorderX2 - h_inset, border_y, table->BorderColorLight, border_size);
}
}
inner_drawlist->PopClipRect();
@@ -3640,10 +3629,7 @@ void ImGui::TableAngledHeadersRowEx(ImGuiID row_id, float angle, float max_label
{
// Draw border
const float border_size = TABLE_BORDER_SIZE;
if (g_LEGACY_STROKES)
draw_list->AddLine(bg_shape[0] - ImVec2(border_size * 0.5f, 0.0f), bg_shape[3] - ImVec2(border_size * 0.5f, 0.0f), TableGetColumnBorderCol(table, order_n, column_n), border_size);
else
draw_list->AddLine(bg_shape[0] + ImVec2(border_size * 0.5f, 0.0f), bg_shape[3] + ImVec2(border_size * 0.5f, 0.0f), TableGetColumnBorderCol(table, order_n, column_n), border_size);
draw_list->AddLine(bg_shape[0] + ImVec2(border_size * 0.5f, 0.0f), bg_shape[3] + ImVec2(border_size * 0.5f, 0.0f), TableGetColumnBorderCol(table, order_n, column_n), border_size);
}
}
PopClipRect();

View File

@@ -901,8 +901,6 @@ bool ImGui::ArrowButton(const char* str_id, ImGuiDir dir)
return ArrowButtonEx(str_id, dir, ImVec2(sz, sz), ImGuiButtonFlags_None);
}
extern bool g_LEGACY_STROKES;
// Button to close a window
bool ImGui::CloseButton(ImGuiID id, const ImVec2& pos)
{
@@ -932,7 +930,7 @@ bool ImGui::CloseButton(ImGuiID id, const ImVec2& pos)
window->DrawList->AddRectFilled(bb.Min, bb.Max, bg_col);
RenderNavCursor(bb, id, ImGuiNavRenderCursorFlags_Compact);
const ImU32 cross_col = GetColorU32(ImGuiCol_Text);
const ImVec2 cross_center = g_LEGACY_STROKES ? (bb.GetCenter() - ImVec2(0.5f, 0.5f)) : bb.GetCenter();
const ImVec2 cross_center = bb.GetCenter();
const float cross_extent = g.FontSize * 0.5f * 0.7071f - 1.0f;
const float cross_thickness = 1.0f * (float)(int)g.Style._MainScale; // FIXME-DPI
window->DrawList->AddLine(cross_center + ImVec2(+cross_extent, +cross_extent), cross_center + ImVec2(-cross_extent, -cross_extent), cross_col, cross_thickness);
@@ -1764,11 +1762,7 @@ void ImGui::SeparatorTextEx(ImGuiID id, const char* label, const char* label_end
const float sep1_x1 = pos.x;
const float sep2_x2 = bb.Max.x;
float seps_y;
if (g_LEGACY_STROKES)
seps_y = ImTrunc((bb.Min.y + bb.Max.y) * 0.5f + 0.999f);
else
seps_y = ImTrunc((bb.Min.y + bb.Max.y) * 0.5f) + 1.0f;
float seps_y = ImTrunc((bb.Min.y + bb.Max.y) * 0.5f) + 1.0f;
const float label_avail_w = ImMax(0.0f, sep2_x2 - sep1_x1 - padding.x * 2.0f);
const ImVec2 label_pos(pos.x + padding.x + ImMax(0.0f, (label_avail_w - label_size.x - extra_w) * style.SeparatorTextAlign.x), pos.y + text_baseline_y); // FIXME-ALIGN
@@ -5697,11 +5691,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
state->CursorAnim += io.DeltaTime;
bool cursor_is_visible = (!g.IO.ConfigInputTextCursorBlink) || (state->CursorAnim <= 0.0f) || ImFmod(state->CursorAnim, 1.20f) <= 0.80f;
ImVec2 cursor_screen_pos = ImTrunc(draw_pos + cursor_offset - draw_scroll);
ImRect cursor_screen_rect;
if (g_LEGACY_STROKES)
cursor_screen_rect = ImRect(cursor_screen_pos.x, cursor_screen_pos.y - g.FontSize + 0.5f, cursor_screen_pos.x + 1.0f, cursor_screen_pos.y - 1.5f);
else
cursor_screen_rect = ImRect(cursor_screen_pos.x, cursor_screen_pos.y - g.FontSize + 1.0f, cursor_screen_pos.x + 1.0f, cursor_screen_pos.y - 1.0f);
ImRect cursor_screen_rect = ImRect(cursor_screen_pos.x, cursor_screen_pos.y - g.FontSize + 1.0f, cursor_screen_pos.x + 1.0f, cursor_screen_pos.y - 1.0f);
if (cursor_is_visible && cursor_screen_rect.Overlaps(clip_rect))
draw_window->DrawList->AddLineV(cursor_screen_rect.Min.x, cursor_screen_rect.Min.y, cursor_screen_rect.Max.y, GetColorU32(ImGuiCol_InputTextCursor), style.InputTextCursorSize, ImDrawFlags_StrokeInside);
@@ -7221,27 +7211,16 @@ void ImGui::TreeNodeDrawLineToChildNode(const ImVec2& target_pos)
// FIXME: Could this be simplified using new stroke flags?
ImGuiTreeNodeStackData* parent_data = &g.TreeNodeStack.Data[g.TreeNodeStack.Size - 1];
const float half_size = g.Style.TreeLinesSize * 0.5f;
float x1;
if (g_LEGACY_STROKES)
x1 = ImTrunc(parent_data->DrawLinesX1);
else
x1 = ImTrunc(parent_data->DrawLinesX1 - half_size) + half_size; // Draw line centered at X1, but snap to pixels boundary.
float x1 = ImTrunc(parent_data->DrawLinesX1 - half_size) + half_size; // Draw line centered at X1, but snap to pixels boundary.
float x2 = ImTrunc(target_pos.x - g.Style.ItemInnerSpacing.x);
float y;
if (g_LEGACY_STROKES)
y = ImTrunc(target_pos.y);
else
y = ImTrunc(target_pos.y - half_size) + half_size;
float y = ImTrunc(target_pos.y - half_size) + half_size;
float rounding = (g.Style.TreeLinesRounding > 0.0f) ? ImMin(x2 - x1, g.Style.TreeLinesRounding) : 0.0f;
parent_data->DrawLinesToNodesY2 = ImMax(parent_data->DrawLinesToNodesY2, y - rounding);
if (x1 >= x2)
return;
if (rounding > 0.0f && rounding > half_size)
{
if (g_LEGACY_STROKES)
x1 += 0.5f + rounding;
else
x1 += rounding;
x1 += rounding;
window->DrawList->PathArcToFast(ImVec2(x1, y - rounding), rounding, 6, 3);
if (x1 < x2)
window->DrawList->PathLineTo(ImVec2(x2, y));
@@ -7251,8 +7230,7 @@ void ImGui::TreeNodeDrawLineToChildNode(const ImVec2& target_pos)
{
// We use AddLine() instead of AddLineH() as we provide coordinates for line center,
// in order to make the code use same coordinates for both rounded and non-rounded version. (FIXME-OPT)
if (!g_LEGACY_STROKES)
x1 += half_size; // Avoid overdraw
x1 += half_size; // Avoid overdraw
window->DrawList->AddLine(ImVec2(x1, y), ImVec2(x2, y), GetColorU32(ImGuiCol_TreeLines), g.Style.TreeLinesSize);
}
}
@@ -7276,11 +7254,7 @@ void ImGui::TreeNodeDrawLineToTreePop(const ImGuiTreeNodeStackData* data)
y2 = ImMin(y2, window->ClipRect.Max.y);
if (y2 <= y1)
return;
float x;
if (g_LEGACY_STROKES)
x = ImTrunc(data->DrawLinesX1);
else
x = ImTrunc(data->DrawLinesX1 - g.Style.TreeLinesSize * 0.5f) + g.Style.TreeLinesSize * 0.5f; // Draw line centered at X1, but snap to pixels boundary.
float x = ImTrunc(data->DrawLinesX1 - g.Style.TreeLinesSize * 0.5f) + g.Style.TreeLinesSize * 0.5f; // Draw line centered at X1, but snap to pixels boundary.
if (data->DrawLinesTableColumn != -1)
TablePushColumnChannel(data->DrawLinesTableColumn);
@@ -10967,18 +10941,8 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open,
if (tab_contents_visible && (tab_bar->Flags & ImGuiTabBarFlags_DrawSelectedOverline) && style.TabBarOverlineSize > 0.0f)
{
// Might be moved to TabItemBackground() ?
ImVec2 tl;
ImVec2 tr;
if (g_LEGACY_STROKES)
{
tl = bb.GetTL() + ImVec2(0, 1.0f * g.CurrentDpiScale);
tr = bb.GetTR() + ImVec2(0, 1.0f * g.CurrentDpiScale);
}
else
{
tl = bb.GetTL() + ImVec2(0, style.TabBarOverlineSize * 0.5f);
tr = bb.GetTR() + ImVec2(0, style.TabBarOverlineSize * 0.5f);
}
ImVec2 tl = bb.GetTL() + ImVec2(0, style.TabBarOverlineSize * 0.5f);
ImVec2 tr = bb.GetTR() + ImVec2(0, style.TabBarOverlineSize * 0.5f);
ImU32 overline_col = GetColorU32(tab_bar_focused ? ImGuiCol_TabSelectedOverline : ImGuiCol_TabDimmedSelectedOverline);
if (style.TabRounding > 0.0f)
{
@@ -10989,9 +10953,6 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open,
}
else
{
if (g_LEGACY_STROKES)
display_draw_list->AddLine(tl - ImVec2(0.5f, 0.5f), tr - ImVec2(0.5f, 0.5f), overline_col, style.TabBarOverlineSize);
else
display_draw_list->AddLine(tl, tr, overline_col, style.TabBarOverlineSize);
}
}