Changed texture-based rounded rectangle edges to draw using thin polygons
Rearranged data for texture-based rounded rectangles to reduce allocations and pre-calculate parametric coordinate
Made max texture-based corner size a constant
Added API for drawing n-gons
Added support in circle API to auto-calculate suitable segment count
Combined filled/outline arc textures into one texture rectangle per radius
Made rounded rectangles/circles draw using (moderately) tight-fitting geometry to minimise fill-rate usage
Hooked up texture-based rounded rectangle/circle code to main render path, with fallback to stroke system
Made AddCircleFilled/AddCircle explicitly not draw circles of radius 0 or less (to avoid inconsistency between them)
Fixed bug in PrimReserve() where releasing more vertices/indices than you used would try and immediately render the entire buffer
AntiAliasedLines=true;// Enable anti-aliased lines/borders. Disable if you are really tight on CPU/GPU.
AntiAliasedLinesUseTex=true;// Enable anti-aliased lines/borders using textures where possible. Require backend to render with bilinear filtering (NOT point/nearest filtering).
RoundCornersUseTex=true;// Enable using textures instead of strokes to draw rounded corners/circles where possible.
CurveTessellationTol=1.25f;// Tessellation tolerance when using PathBezierCurveTo() without a specific number of segments. Decrease for highly tessellated curves (higher quality, more polygons), increase to reduce quality.
CircleTessellationMaxError=0.30f;// Maximum error (in pixels) allowed when using AddCircle()/AddCircleFilled() or drawing rounded corner rectangles with no explicit segment count specified. Decrease for higher quality but more geometry.
boolAntiAliasedLines;// Enable anti-aliased lines/borders. Disable if you are really tight on CPU/GPU. Latched at the beginning of the frame (copied to ImDrawList).
boolAntiAliasedLinesUseTex;// Enable anti-aliased lines/borders using textures where possible. Require backend to render with bilinear filtering (NOT point/nearest filtering). Latched at the beginning of the frame (copied to ImDrawList).
boolAntiAliasedFill;// Enable anti-aliased edges around filled shapes (rounded rectangles, circles, etc.). Disable if you are really tight on CPU/GPU. Latched at the beginning of the frame (copied to ImDrawList).
boolRoundCornersUseTex;// Enable using textures instead of strokes to draw rounded corners/circles where possible.
floatCurveTessellationTol;// Tessellation tolerance when using PathBezierCurveTo() without a specific number of segments. Decrease for highly tessellated curves (higher quality, more polygons), increase to reduce quality.
floatCircleTessellationMaxError;// Maximum error (in pixels) allowed when using AddCircle()/AddCircleFilled() or drawing rounded corner rectangles with no explicit segment count specified. Decrease for higher quality but more geometry.
ImVec4Colors[ImGuiCol_COUNT];
@ -2752,6 +2753,7 @@ enum ImDrawListFlags_
ImDrawListFlags_AntiAliasedLinesUseTex=1<<1,// Enable anti-aliased lines/borders using textures when possible. Require backend to render with bilinear filtering (NOT point/nearest filtering).
ImDrawListFlags_AntiAliasedFill=1<<2,// Enable anti-aliased edge around filled shapes (rounded rectangles, circles).
ImDrawListFlags_AllowVtxOffset=1<<3,// Can emit 'VtxOffset > 0' to allow large meshes. Set when 'ImGuiBackendFlags_RendererHasVtxOffset' is enabled.
ImDrawListFlags_RoundCornersUseTex=1<<4,// Enable using textures instead of strokes to draw rounded corners/circles where possible.
IMGUI_APIvoidBuildRanges(ImVector<ImWchar>*out_ranges);// Output new ranges
};
// Data for texture-based rounded corners for a given radius
structImFontRoundedCornerData
{
ImVec4TexUvFilled;// UV of filled round corner quad in the atlas (only valid when stroke width is 1)
ImVec4TexUvStroked;// UV of stroked round corner quad in the atlas
floatParametricStrokeWidth;// Pre-calculated value for stroke width divided by the radius
intRectId;// Rect ID in the atlas, or -1 if there is no data
boolStrokedUsesAlternateUVs;// True if stroked drawing should use the alternate (i.e. other corner) UVs
};
// See ImFontAtlas::AddCustomRectXXX functions.
structImFontAtlasCustomRect
{
@ -3003,6 +3015,7 @@ enum ImFontAtlasFlags_
ImFontAtlasFlags_NoPowerOfTwoHeight=1<<0,// Don't round the height to next power of two
ImFontAtlasFlags_NoMouseCursors=1<<1,// Don't build software mouse cursors into the atlas (save a little texture memory)
ImFontAtlasFlags_NoBakedLines=1<<2,// Don't build thick line textures into the atlas (save a little texture memory, allow support for point/nearest filtering). The AntiAliasedLinesUseTex features uses them, otherwise they will be rendered using polygons (more expensive for CPU/GPU).
ImFontAtlasFlags_NoBakedRoundCorners=1<<3,// Don't build round corners into the atlas.
};
// Load and rasterize multiple TTF/OTF fonts into a same texture. The font atlas will build a single texture holding:
@ -3119,6 +3132,9 @@ struct ImFontAtlas
intPackIdMouseCursors;// Custom texture rectangle ID for white pixel and mouse cursors
intPackIdLines;// Custom texture rectangle ID for baked anti-aliased lines
ImVector<ImFontRoundedCornerData>TexRoundCornerData;// Data for texture-based round corners indexed by radius/size (from 1 to ImFontAtlasRoundCornersMaxSize) and stroke width (from 1 to ImFontAtlasRoundCornersMaxStrokeWidth), with index = stroke_width_index + (radius_index * ImFontAtlasRoundCornersMaxStrokeWidth).
ImVector<ImFontRoundedCornerData>TexSquareCornerData;// The same as TexRoundCornerData, but with square corners instead of rounded ones
// [Obsolete]
//typedef ImFontAtlasCustomRect CustomRect; // OBSOLETED in 1.72+
//typedef ImFontGlyphRangesBuilder GlyphRangesBuilder; // OBSOLETED in 1.67+
#define IMGUI_DEMO_MARKER(section) do { if (GImGuiDemoMarkerCallback != NULL) GImGuiDemoMarkerCallback(__FILE__, __LINE__, section, GImGuiDemoMarkerCallbackUserData); } while (0)
// If we have a >1 stroke width, we actually need to increase the radius appropriately as well to match how the geometry renderer does things
constintrad=(int)rounding+(stroke_width-1);
// We don't support zero radius
if(rad<=0||rad>ImFontAtlasRoundCornersMaxSize)
returnfalse;// We can't handle this
// This is a very awkward special case - if two opposing corners are curved *and* the width/height of the rectangle is <= 2x radius, the non-curved corner overlaps with the curved one
// Technically this is fixable but it's a major PITA to do so instead we just don't support that (hopefully very rare) case
constintsquare_rad=stroke_width+(stroke_width-1);// Radius to use for square corners and sides - because increasing stroke width grows the line on both sides, we need to do this slightly odd calculation
// Another awkward special case - if rectangle is smaller than the stroke width then we can get bits of one corner poking out from the other at small sizes when we draw a non-filled rect with a mix of rounded and square corners
// (technically this test can be refined to check for possible left/right and top/bottom clashes independently, but it's almost certainly not worth the added complexity)
IM_ASSERT(data->Font->ContainerAtlas->TexID==draw_list->_TextureIdStack.back());// Use high-level ImGui::PushFont() or low-level ImDrawList::PushTextureId() to change font.
// Calculate UVs for the three points we are interested in from the texture
// - corner_uv[0] is the innermost point of the circle (solid for filled circles)
// - corner_uv[1] is either straight down or across from it (depending on if we are using the filled or stroked version)
// - corner_uv[2] is diagonally across from it
// - corner_uv[1] is always solid (either inside the circle or on the line), whilst corner_uv[2] is always blank
// This represents a 45 degree "wedge" of circle, which then gets mirrored here to produce a 90 degree curve
// See ImFontAtlasBuildRenderRoundCornersTexData() for more details of the texture contents
// If use_alternative_uvs is true then this means we are drawing a stroked texture that has been packed into the "filled"
// corner of the area on the texture page, so we need to calculate UVs appropriately
if(!(draw_list->Flags&ImDrawListFlags_RoundCornersUseTex))// Disabled by the draw list flags
returnfalse;
constImDrawListSharedData*data=draw_list->_Data;
IM_ASSERT(data->Font->ContainerAtlas->TexID==draw_list->_TextureIdStack.back());// Use high-level ImGui::PushFont() or low-level ImDrawList::PushTextureId() to change font.
IM_ASSERT_PARANOID(!(data->Font->ContainerAtlas->Flags&ImFontAtlasFlags_NoBakedRoundCorners));// No data in font
constintFONT_ATLAS_ROUNDED_CORNER_TEX_CENTER_PADDING=4;// Padding applied to the Y axis to separate the two halves of the image (this must be a multiple of two)
// Register the rectangles we need for the rounded corner images
IM_ASSERT(atlas->TexID==draw_list->_TextureIdStack.back());// Use high-level ImGui::PushFont() or low-level ImDrawList::PushTextureId() to change font.
IM_ASSERT(ImIsPowerOfTwo(flags));// Only allow a single corner to be specified here.
// NB: This is rather brittle and will show artifact when rounding this enabled if rounded corners overlap multiple cells. Caller currently responsible for avoiding that.
// Spent a non reasonable amount of time trying to getting this right for ColorButton with rounding+anti-aliasing+ImGuiColorEditFlags_HalfAlphaPreview flag + various grid sizes and offsets, and eventually gave up... probably more reasonable to disable rounding altogether.
@ -4396,6 +5269,7 @@ void ImGui::RenderColorRectWithAlphaCheckerboard(ImDrawList* draw_list, ImVec2 p
// Note that stroke width increases effective radius, so (e.g.) a max radius circle will have to use the fallback path if stroke width is > 1. Note that ImFontAtlasRoundCornersSizeMask is 64 bits so this value can only go up to a maximum of 64 at present.
constintImFontAtlasRoundCornersMaxSize=32;// Maximum size of rounded corner texture to generate in fonts
// Bit mask for which radii will have texture generated for them, starting from radius 1. Only bits up to ImFontAtlasRoundCornersMaxSize are considered.
constintImFontAtlasRoundCornersMaxStrokeWidth=4;// Maximum stroke width of rounded corner texture to generate in fonts
// Bit mask for which stroke widths should have textures generated for them (the default of 0x0B means widths 1, 2 and 4)
// Only bits up to ImFontAtlasRoundCornersMaxStrokeWidth are considered, and bit 0 (stroke width 1) must always be set
// Optimally there should be an odd number of bits set, as the texture packing packs the data in pairs, with one half of one pair being occupied by the filled texture