diff --git a/imgui.h b/imgui.h index e1bc834da..c0df01cd5 100644 --- a/imgui.h +++ b/imgui.h @@ -3320,15 +3320,15 @@ struct ImGuiSelectionExternalStorage // The maximum line width to bake anti-aliased textures for. Build atlas with ImFontAtlasFlags_NoBakedLines to disable baking. #ifndef IM_DRAWLIST_TEX_LINES_WIDTH_MAX -#define IM_DRAWLIST_TEX_LINES_WIDTH_MAX (32) -#define IM_DRAWLIST_TEX_LINE_FRACT_WIDTH_MAX (128) +#define IM_DRAWLIST_TEX_LINES_WIDTH_MAX (32) +#define IM_DRAWLIST_TEX_LINE_FRACT_WIDTH_MAX (128) #endif #ifndef IM_DRAWLIST_TEX_CORNERS_ROUNDING_MAX -#define IM_DRAWLIST_TEX_CORNERS_ROUNDING_MAX (16) +#define IM_DRAWLIST_TEX_CORNERS_ROUNDING_MAX (16) #endif #ifndef IM_DRAWLIST_TEX_CORNERS_THICKNESS_MAX -#define IM_DRAWLIST_TEX_CORNERS_THICKNESS_MAX (3) +#define IM_DRAWLIST_TEX_CORNERS_THICKNESS_MAX (4) // 0: fill, 1-3: strokes thickness #endif // ImDrawIdx: vertex index. [Compile-time configurable type] @@ -4017,8 +4017,7 @@ struct ImFontAtlas ImVector Sources; // Source/configuration data ImVec4 TexUvLines[IM_DRAWLIST_TEX_LINES_WIDTH_MAX + 1]; // UVs for baked anti-aliased lines ImVec4 TexUvLineFract; // UVs for fraction thickness baked anti-aliased lines - ImVec4 TexUvCornerFills[IM_DRAWLIST_TEX_CORNERS_ROUNDING_MAX]; // UVs for baked anti-aliased corners - ImVec4 TexUvCornerStrokes[IM_DRAWLIST_TEX_CORNERS_ROUNDING_MAX * IM_DRAWLIST_TEX_CORNERS_THICKNESS_MAX]; // UVs for baked anti-aliased corners + ImVec4 TexUvCorners[IM_DRAWLIST_TEX_CORNERS_ROUNDING_MAX * IM_DRAWLIST_TEX_CORNERS_THICKNESS_MAX]; // UVs for baked anti-aliased corners (0= fill, 1> stroke thickness) int TexNextUniqueID; // Next value to be stored in TexData->UniqueID int FontNextUniqueID; // Next value to be stored in ImFont->FontID ImVector DrawListSharedDatas; // List of users for this atlas. Typically one per Dear ImGui context. diff --git a/imgui_demo.cpp b/imgui_demo.cpp index e340b1a56..892825eef 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -10548,7 +10548,7 @@ static void ShowExampleAppCustomRendering(bool* p_open) // Rotating square for (int n = 0; n < 4; n++) draw_list->PathLineTo({ x + half_sz + rotating_square[n].x, y + half_sz + rotating_square[n].y }); - draw_list->PathStroke(col, flags | ImDrawFlags_Closed, th); + draw_list->PathStroke(col, th, flags | ImDrawFlags_Closed); //for (int n = 0; n < 4; n++) // ...made of individual line // draw_list->AddLine({ x + half_sz + rotating_square[n].x, y + half_sz + rotating_square[n].y }, { x + half_sz + rotating_square[(n + 1) & 3].x, y + half_sz + rotating_square[(n + 1) & 3].y }, col, th, flags); x += sz + spacing; diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 7b832f73c..f55fe4795 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -2529,9 +2529,9 @@ void ImDrawList::AddRect(const ImVec2& p_min, const ImVec2& p_max, ImU32 col, fl // Pixel aligned rect with round corners rendered using baked textures. IM_ASSERT_PARANOID(!(_Data->Font->OwnerAtlas->Flags & ImFontAtlasFlags_NoBakedRoundCorners)); const int size = ImMax(s_rounding, s_thickness); // This is matching the baking calculations. - const int idx = (s_thickness - 1) * IM_DRAWLIST_TEX_CORNERS_ROUNDING_MAX + s_rounding - 1; + const int idx = (s_thickness * IM_DRAWLIST_TEX_CORNERS_ROUNDING_MAX) + s_rounding - 1; IM_ASSERT_PARANOID(idx >= 0 && idx < IM_DRAWLIST_TEX_CORNERS_ROUNDING_MAX * IM_DRAWLIST_TEX_CORNERS_THICKNESS_MAX); - const ImVec4 tex_uvs = _Data->TexUvCornerStrokes[idx]; + const ImVec4 tex_uvs = _Data->TexUvCorners[idx]; _AddRectBaked(outer_min, outer_max, col, (float)size * _FringeScale, (float)thickness, tex_uvs, flags); return; } @@ -2639,9 +2639,9 @@ void ImDrawList::AddRectFilled(const ImVec2& p_min, const ImVec2& p_max, ImU32 c { IM_ASSERT_PARANOID(!(_Data->Font->OwnerAtlas->Flags & ImFontAtlasFlags_NoBakedRoundCorners)); const int size = ImMax(2, s_rounding); // This is matching the baking calculations. - const int idx = s_rounding - 1; + const int idx = (s_rounding - 1); IM_ASSERT_PARANOID(idx >= 0 && idx < IM_DRAWLIST_TEX_CORNERS_ROUNDING_MAX); - ImVec4 tex_uvs = _Data->TexUvCornerFills[idx]; + ImVec4 tex_uvs = _Data->TexUvCorners[idx]; _AddRectFilledBaked(p_min, p_max, col, (float)size * _FringeScale, tex_uvs, flags); } else @@ -4873,13 +4873,13 @@ static void ImFontAtlasBuildUpdateTexDataCorners(ImFontAtlas* atlas) pack_size.x = ImMax(pack_size.x, row_width); pack_size.y += row_height; // Rounded corners - for (int t = 0; t < IM_DRAWLIST_TEX_CORNERS_THICKNESS_MAX; t++) + for (int thickness = 1; thickness < IM_DRAWLIST_TEX_CORNERS_THICKNESS_MAX; thickness++) { row_width = 0; row_height = 0; for (int i = 0; i < IM_DRAWLIST_TEX_CORNERS_ROUNDING_MAX; i++) { - const int size = ImMax(2, ImMax(i+1, t+1)) + 2; + const int size = ImMax(2, ImMax(i + 1, thickness)) + 2; row_width += size; row_height = ImMax(row_height, size); } @@ -4935,7 +4935,7 @@ static void ImFontAtlasBuildUpdateTexDataCorners(ImFontAtlas* atlas) // Refresh UV coordinates ImVec2 uv0 = ImVec2((float)(x + 1), (float)(y + 1)) * atlas->TexUvScale; ImVec2 uv1 = ImVec2((float)(x + 1 + s), (float)(y + 1 + s)) * atlas->TexUvScale; - atlas->TexUvCornerFills[n] = ImVec4(uv0.x, uv0.y, uv1.x, uv1.y); + atlas->TexUvCorners[n] = ImVec4(uv0.x, uv0.y, uv1.x, uv1.y); x += w; row_height = ImMax(row_height, h); @@ -4943,14 +4943,13 @@ static void ImFontAtlasBuildUpdateTexDataCorners(ImFontAtlas* atlas) y += row_height; // Stroked - for (int t = 0; t < IM_DRAWLIST_TEX_CORNERS_THICKNESS_MAX; t++) + for (int thickness = 1; thickness < IM_DRAWLIST_TEX_CORNERS_THICKNESS_MAX; thickness++) { x = r.x; row_height = 0; for (int n = 0; n < IM_DRAWLIST_TEX_CORNERS_ROUNDING_MAX; n++) { const int rounding = n+1; - const int thickness = t+1; const int s = ImMax(rounding, thickness); const int w = s + 2; const int h = s + 2; @@ -4990,7 +4989,7 @@ static void ImFontAtlasBuildUpdateTexDataCorners(ImFontAtlas* atlas) // Refresh UV coordinates ImVec2 uv0 = ImVec2((float)(x + 1), (float)(y + 1)) * atlas->TexUvScale; ImVec2 uv1 = ImVec2((float)(x + 1 + s), (float)(y + 1 + s)) * atlas->TexUvScale; - atlas->TexUvCornerStrokes[t*IM_DRAWLIST_TEX_CORNERS_ROUNDING_MAX + n] = ImVec4(uv0.x, uv0.y, uv1.x, uv1.y); + atlas->TexUvCorners[thickness * IM_DRAWLIST_TEX_CORNERS_ROUNDING_MAX + n] = ImVec4(uv0.x, uv0.y, uv1.x, uv1.y); x += w; row_height = ImMax(row_height, h); @@ -5473,8 +5472,7 @@ void ImFontAtlasUpdateDrawListsSharedData(ImFontAtlas* atlas) shared_data->TexUvWhitePixel = atlas->TexUvWhitePixel; shared_data->TexUvLines = atlas->TexUvLines; shared_data->TexUvLineFract = atlas->TexUvLineFract; - shared_data->TexUvCornerFills = atlas->TexUvCornerFills; - shared_data->TexUvCornerStrokes = atlas->TexUvCornerStrokes; + shared_data->TexUvCorners = atlas->TexUvCorners; } } diff --git a/imgui_internal.h b/imgui_internal.h index 7abbf8c51..fe67beff1 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -924,8 +924,7 @@ struct IMGUI_API ImDrawListSharedData ImVec2 TexUvWhitePixel; // UV of white pixel in the atlas (== FontAtlas->TexUvWhitePixel) const ImVec4* TexUvLines; // UV of anti-aliased lines in the atlas (== FontAtlas->TexUvLines) ImVec4 TexUvLineFract; // UV of fractional anti-aliased lines in the atlas (== FontAtlas->TexUvLineFract) - const ImVec4* TexUvCornerFills; // UV of rounded corner (== FontAtlas->TexUvCornerFills) - const ImVec4* TexUvCornerStrokes; + const ImVec4* TexUvCorners; // UV of rounded corner (== FontAtlas->TexUvCorners) ImFontAtlas* FontAtlas; // Current font atlas ImFont* Font; // Current font (used for simplified AddText overload) float FontSize; // Current font size (used for for simplified AddText overload)