mirror of
https://github.com/Drezil/imgui.git
synced 2025-01-12 00:36:37 +00:00
Texture-based round corners: Tweaks, renaming to match tex lines branch.
This commit is contained in:
parent
f41e86c78e
commit
5947842934
@ -1070,7 +1070,7 @@ ImGuiStyle::ImGuiStyle()
|
|||||||
AntiAliasedLines = true; // Enable anti-aliased lines/borders. Disable if you are really tight on CPU/GPU.
|
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.
|
AntiAliasedLinesUseTex = true; // Enable anti-aliased lines/borders using textures where possible. Require backend to render with bilinear filtering.
|
||||||
AntiAliasedFill = true; // Enable anti-aliased filled shapes (rounded rectangles, circles, etc.).
|
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.
|
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.
|
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.
|
||||||
|
|
||||||
@ -4298,8 +4298,8 @@ void ImGui::NewFrame()
|
|||||||
g.DrawListSharedData.InitialFlags |= ImDrawListFlags_AntiAliasedFill;
|
g.DrawListSharedData.InitialFlags |= ImDrawListFlags_AntiAliasedFill;
|
||||||
if (g.IO.BackendFlags & ImGuiBackendFlags_RendererHasVtxOffset)
|
if (g.IO.BackendFlags & ImGuiBackendFlags_RendererHasVtxOffset)
|
||||||
g.DrawListSharedData.InitialFlags |= ImDrawListFlags_AllowVtxOffset;
|
g.DrawListSharedData.InitialFlags |= ImDrawListFlags_AllowVtxOffset;
|
||||||
if (g.Style.TexturedRoundCorners && !(g.Font->ContainerAtlas->Flags & ImFontAtlasFlags_NoBakedRoundCorners))
|
if (g.Style.RoundCornersUseTex && !(g.Font->ContainerAtlas->Flags & ImFontAtlasFlags_NoBakedRoundCorners))
|
||||||
g.DrawListSharedData.InitialFlags |= ImDrawListFlags_TexturedRoundCorners;
|
g.DrawListSharedData.InitialFlags |= ImDrawListFlags_RoundCornersUseTex;
|
||||||
|
|
||||||
// Mark rendering data as invalid to prevent user who may have a handle on it to use it.
|
// Mark rendering data as invalid to prevent user who may have a handle on it to use it.
|
||||||
for (int n = 0; n < g.Viewports.Size; n++)
|
for (int n = 0; n < g.Viewports.Size; n++)
|
||||||
@ -5552,11 +5552,10 @@ static const ImGuiResizeBorderDef resize_border_def[4] =
|
|||||||
// FIXME: Probably ok to move this to imgui_draw.cpp in 'Internal Render Helpers' section.
|
// 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)
|
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;
|
return false;
|
||||||
|
|
||||||
ImFontAtlas* atlas = draw_list->_Data->Font->ContainerAtlas;
|
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(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(ImIsPowerOfTwo(corners_flags)); // Only allow a single corner to be specified here.
|
||||||
IM_ASSERT_PARANOID(!(atlas->Flags & ImFontAtlasFlags_NoBakedRoundCorners));
|
IM_ASSERT_PARANOID(!(atlas->Flags & ImFontAtlasFlags_NoBakedRoundCorners));
|
||||||
|
4
imgui.h
4
imgui.h
@ -1875,7 +1875,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 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. 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. 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 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 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.
|
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];
|
ImVec4 Colors[ImGuiCol_COUNT];
|
||||||
@ -2486,7 +2486,7 @@ enum ImDrawListFlags_
|
|||||||
ImDrawListFlags_AntiAliasedLinesUseTex = 1 << 1, // Enable anti-aliased lines/borders using textures when possible. Require backend to render with bilinear filtering.
|
ImDrawListFlags_AntiAliasedLinesUseTex = 1 << 1, // Enable anti-aliased lines/borders using textures when possible. Require backend to render with bilinear filtering.
|
||||||
ImDrawListFlags_AntiAliasedFill = 1 << 2, // Enable anti-aliased edge around filled shapes (rounded rectangles, circles).
|
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_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
|
// Draw command list
|
||||||
|
@ -265,8 +265,8 @@ static void TestTextureBasedRender()
|
|||||||
|
|
||||||
ImGui::Begin("tex_round_corners");
|
ImGui::Begin("tex_round_corners");
|
||||||
|
|
||||||
style.TexturedRoundCorners = io.KeyShift;
|
style.RoundCornersUseTex = io.KeyShift;
|
||||||
ImGui::Checkbox("style.TexturedRoundCorners (hold SHIFT to toggle)", &style.TexturedRoundCorners);
|
ImGui::Checkbox("style.RoundCornersUseTex (hold SHIFT to toggle)", &style.RoundCornersUseTex);
|
||||||
|
|
||||||
static float radius = 16.0f; // ImFontAtlasRoundCornersMaxSize * 0.5f;
|
static float radius = 16.0f; // ImFontAtlasRoundCornersMaxSize * 0.5f;
|
||||||
static int segments = 20;
|
static int segments = 20;
|
||||||
@ -348,7 +348,7 @@ static void TestTextureBasedRender()
|
|||||||
ImGui::EndGroup();
|
ImGui::EndGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
|
|
||||||
{
|
{
|
||||||
ImGui::BeginGroup();
|
ImGui::BeginGroup();
|
||||||
@ -6430,7 +6430,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
|
|||||||
HelpMarker("Faster lines using texture data. Require backend to render with bilinear filtering (not point/nearest filtering).");
|
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("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::PushItemWidth(ImGui::GetFontSize() * 8);
|
||||||
ImGui::DragFloat("Curve Tessellation Tolerance", &style.CurveTessellationTol, 0.02f, 0.10f, 10.0f, "%.2f");
|
ImGui::DragFloat("Curve Tessellation Tolerance", &style.CurveTessellationTol, 0.02f, 0.10f, 10.0f, "%.2f");
|
||||||
if (style.CurveTessellationTol < 0.10f) style.CurveTessellationTol = 0.10f;
|
if (style.CurveTessellationTol < 0.10f) style.CurveTessellationTol = 0.10f;
|
||||||
|
@ -1396,7 +1396,7 @@ void ImDrawList::AddLine(const ImVec2& p1, const ImVec2& p2, ImU32 col, float th
|
|||||||
// We are using the textures generated by ImFontAtlasBuildRenderRoundCornersTexData()
|
// 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)
|
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;
|
return false;
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
@ -1417,7 +1417,7 @@ inline bool AddRoundCornerRect(ImDrawList* draw_list, const ImVec2& a, const ImV
|
|||||||
const int rad = (int)rounding + (stroke_width - 1);
|
const int rad = (int)rounding + (stroke_width - 1);
|
||||||
|
|
||||||
// We don't support zero radius
|
// We don't support zero radius
|
||||||
if ((rad <= 0) || (rad > ImFontAtlasRoundCornersMaxSize))
|
if (rad <= 0 || rad > ImFontAtlasRoundCornersMaxSize)
|
||||||
return false; // We can't handle this
|
return false; // We can't handle this
|
||||||
|
|
||||||
const unsigned int index = (stroke_width - 1) + ((rad - 1) * ImFontAtlasRoundCornersMaxStrokeWidth);
|
const unsigned int index = (stroke_width - 1) + ((rad - 1) * ImFontAtlasRoundCornersMaxStrokeWidth);
|
||||||
@ -1430,10 +1430,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.
|
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
|
// 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[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[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[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[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
|
// 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
|
// 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"
|
// If use_alternative_uvs is true then this means we are drawing a stroked texture that has been packed into the "filled"
|
||||||
@ -1854,7 +1854,7 @@ void ImDrawList::AddTriangleFilled(const ImVec2& p1, const ImVec2& p2, const ImV
|
|||||||
// (in which case the caller should try the regular circle drawing code)
|
// (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)
|
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;
|
return false;
|
||||||
|
|
||||||
const ImDrawListSharedData* data = draw_list->_Data;
|
const ImDrawListSharedData* data = draw_list->_Data;
|
||||||
@ -3349,7 +3349,7 @@ static void ImFontAtlasBuildRegisterRoundCornersCustomRects(ImFontAtlas* atlas)
|
|||||||
{
|
{
|
||||||
if (atlas->TexRoundCornerData.Size > 0)
|
if (atlas->TexRoundCornerData.Size > 0)
|
||||||
return;
|
return;
|
||||||
if ((atlas->Flags & ImFontAtlasFlags_NoBakedRoundCorners))
|
if (atlas->Flags & ImFontAtlasFlags_NoBakedRoundCorners)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const int pad = FONT_ATLAS_ROUNDED_CORNER_TEX_PADDING;
|
const int pad = FONT_ATLAS_ROUNDED_CORNER_TEX_PADDING;
|
||||||
@ -3369,7 +3369,7 @@ static void ImFontAtlasBuildRegisterRoundCornersCustomRects(ImFontAtlas* atlas)
|
|||||||
ImFontRoundedCornerData corner_data;
|
ImFontRoundedCornerData corner_data;
|
||||||
if (ImFontAtlasRoundCornersStrokeWidthMask & (1 << stroke_width_index))
|
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.RectId = atlas->AddCustomRectRegular(width, height);
|
||||||
corner_data.StrokedUsesAlternateUVs = false;
|
corner_data.StrokedUsesAlternateUVs = false;
|
||||||
@ -4706,6 +4706,7 @@ void ImGui::RenderColorRectWithAlphaCheckerboard(ImDrawList* draw_list, ImVec2 p
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// [SECTION] Decompression code
|
// [SECTION] Decompression code
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user