Texture-based round corners: Tweaks, renaming to match tex lines branch.

This commit is contained in:
ocornut 2020-06-03 21:27:16 +02:00
parent 57e6b1e7da
commit 624e3a350d
4 changed files with 20 additions and 20 deletions

View File

@ -1294,7 +1294,7 @@ ImGuiStyle::ImGuiStyle()
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).
AntiAliasedFill = true; // Enable anti-aliased filled shapes (rounded rectangles, circles, etc.).
TexturedRoundCorners = true; // Enable using textures instead of strokes to draw rounded corners/circles where possible.
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.
@ -4720,8 +4720,8 @@ static void SetupDrawListSharedData()
g.DrawListSharedData.InitialFlags |= ImDrawListFlags_AntiAliasedFill;
if (g.IO.BackendFlags & ImGuiBackendFlags_RendererHasVtxOffset)
g.DrawListSharedData.InitialFlags |= ImDrawListFlags_AllowVtxOffset;
if (g.Style.TexturedRoundCorners && !(g.IO.Fonts->Flags & ImFontAtlasFlags_NoBakedRoundCorners))
g.DrawListSharedData.InitialFlags |= ImDrawListFlags_TexturedRoundCorners;
if (g.Style.RoundCornersUseTex && !(g.IO.Fonts->Flags & ImFontAtlasFlags_NoBakedRoundCorners))
g.DrawListSharedData.InitialFlags |= ImDrawListFlags_RoundCornersUseTex;
}
void ImGui::NewFrame()
@ -6026,11 +6026,10 @@ static const ImGuiResizeBorderDef resize_border_def[4] =
// FIXME: Probably ok to move this to imgui_draw.cpp in 'Internal Render Helpers' section.
static bool RenderResizeGripWithTex(ImDrawList* draw_list, const ImVec2& corner, unsigned int rad, unsigned int overall_grip_size, ImDrawCornerFlags corners_flags, ImU32 col)
{
if (!(draw_list->Flags & ImDrawListFlags_TexturedRoundCorners)) // Disabled by the draw list flags
if (!(draw_list->Flags & ImDrawListFlags_RoundCornersUseTex)) // Disabled by the draw list flags
return false;
ImFontAtlas* atlas = draw_list->_Data->Font->ContainerAtlas;
IM_UNUSED(atlas);
IM_ASSERT(atlas->TexID == draw_list->_TextureIdStack.back()); // Use high-level ImGui::PushFont() or low-level ImDrawList::PushTextureId() to change font.
IM_ASSERT(ImIsPowerOfTwo(corners_flags)); // Only allow a single corner to be specified here.
IM_ASSERT_PARANOID(!(atlas->Flags & ImFontAtlasFlags_NoBakedRoundCorners));

View File

@ -2168,7 +2168,7 @@ struct ImGuiStyle
bool AntiAliasedLines; // Enable anti-aliased lines/borders. Disable if you are really tight on CPU/GPU. Latched at the beginning of the frame (copied to ImDrawList).
bool AntiAliasedLinesUseTex; // 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).
bool AntiAliasedFill; // 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).
bool TexturedRoundCorners; // Enable using textures instead of strokes to draw rounded corners/circles where possible.
bool RoundCornersUseTex; // Enable using textures instead of strokes to draw rounded corners/circles where possible.
float CurveTessellationTol; // Tessellation tolerance when using PathBezierCurveTo() without a specific number of segments. Decrease for highly tessellated curves (higher quality, more polygons), increase to reduce quality.
float CircleTessellationMaxError; // 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.
ImVec4 Colors[ImGuiCol_COUNT];
@ -3009,7 +3009,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_TexturedRoundCorners = 1 << 4, // Enable using textures instead of strokes to draw rounded corners/circles where possible.
ImDrawListFlags_RoundCornersUseTex = 1 << 4, // Enable using textures instead of strokes to draw rounded corners/circles where possible.
};
// Draw command list

View File

@ -359,8 +359,8 @@ static void TestTextureBasedRender()
ImGui::Begin("tex_round_corners");
style.TexturedRoundCorners = io.KeyShift;
ImGui::Checkbox("style.TexturedRoundCorners (hold SHIFT to toggle)", &style.TexturedRoundCorners);
style.RoundCornersUseTex = io.KeyShift;
ImGui::Checkbox("style.RoundCornersUseTex (hold SHIFT to toggle)", &style.RoundCornersUseTex);
static float radius = 16.0f; // ImFontAtlasRoundCornersMaxSize * 0.5f;
static int segments = 20;
@ -442,7 +442,7 @@ static void TestTextureBasedRender()
ImGui::EndGroup();
}
ImGui::SameLine();
ImGui::SameLine();
{
ImGui::BeginGroup();
@ -8165,7 +8165,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
HelpMarker("Faster lines using texture data. Require backend to render with bilinear filtering (not point/nearest filtering).");
ImGui::Checkbox("Anti-aliased fill", &style.AntiAliasedFill);
ImGui::Checkbox("Rounded corner textures", &style.TexturedRoundCorners);
ImGui::Checkbox("Rounded corner textures", &style.RoundCornersUseTex);
ImGui::PushItemWidth(ImGui::GetFontSize() * 8);
ImGui::DragFloat("Curve Tessellation Tolerance", &style.CurveTessellationTol, 0.02f, 0.10f, 10.0f, "%.2f");
if (style.CurveTessellationTol < 0.10f) style.CurveTessellationTol = 0.10f;

View File

@ -1413,7 +1413,7 @@ void ImDrawList::AddLine(const ImVec2& p1, const ImVec2& p2, ImU32 col, float th
// We are using the textures generated by ImFontAtlasBuildRenderRoundCornersTexData()
inline bool AddRoundCornerRect(ImDrawList* draw_list, const ImVec2& a, const ImVec2& b, ImU32 col, float rounding, float thickness, ImDrawFlags flags, bool fill)
{
if (!(draw_list->Flags & ImDrawListFlags_TexturedRoundCorners)) // Disabled by the draw list flags
if (!(draw_list->Flags & ImDrawListFlags_RoundCornersUseTex)) // Disabled by the draw list flags
return false;
#if 1
@ -1434,7 +1434,7 @@ inline bool AddRoundCornerRect(ImDrawList* draw_list, const ImVec2& a, const ImV
const int rad = (int)rounding + (stroke_width - 1);
// We don't support zero radius
if ((rad <= 0) || (rad > ImFontAtlasRoundCornersMaxSize))
if (rad <= 0 || rad > ImFontAtlasRoundCornersMaxSize)
return false; // We can't handle this
const unsigned int index = (stroke_width - 1) + ((rad - 1) * ImFontAtlasRoundCornersMaxStrokeWidth);
@ -1447,10 +1447,10 @@ inline bool AddRoundCornerRect(ImDrawList* draw_list, const ImVec2& a, const ImV
IM_ASSERT(tex_id == 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
// - 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"
@ -1871,7 +1871,7 @@ void ImDrawList::AddTriangleFilled(const ImVec2& p1, const ImVec2& p2, const ImV
// (in which case the caller should try the regular circle drawing code)
inline bool AddRoundCornerCircle(ImDrawList* draw_list, const ImVec2& center, float radius, float thickness, ImU32 col, bool fill)
{
if (!(draw_list->Flags & ImDrawListFlags_TexturedRoundCorners)) // Disabled by the draw list flags
if (!(draw_list->Flags & ImDrawListFlags_RoundCornersUseTex)) // Disabled by the draw list flags
return false;
const ImDrawListSharedData* data = draw_list->_Data;
@ -3803,7 +3803,7 @@ static void ImFontAtlasBuildRegisterRoundCornersCustomRects(ImFontAtlas* atlas)
{
if (atlas->TexRoundCornerData.Size > 0)
return;
if ((atlas->Flags & ImFontAtlasFlags_NoBakedRoundCorners))
if (atlas->Flags & ImFontAtlasFlags_NoBakedRoundCorners)
return;
const int pad = FONT_ATLAS_ROUNDED_CORNER_TEX_PADDING;
@ -3823,7 +3823,7 @@ static void ImFontAtlasBuildRegisterRoundCornersCustomRects(ImFontAtlas* atlas)
ImFontRoundedCornerData corner_data;
if (ImFontAtlasRoundCornersStrokeWidthMask & (1 << stroke_width_index))
{
if ((stroke_width_index == 0) || (spare_rect_id < 0))
if (stroke_width_index == 0 || spare_rect_id < 0)
{
corner_data.RectId = atlas->AddCustomRectRegular(width, height);
corner_data.StrokedUsesAlternateUVs = false;
@ -5176,6 +5176,7 @@ void ImGui::RenderColorRectWithAlphaCheckerboard(ImDrawList* draw_list, ImVec2 p
}
}
//-----------------------------------------------------------------------------
// [SECTION] Decompression code
//-----------------------------------------------------------------------------