mirror of
				https://github.com/Drezil/imgui.git
				synced 2025-10-31 21:21:06 +01:00 
			
		
		
		
	Texture-based round corners: Minor tweaks
This commit is contained in:
		| @@ -350,6 +350,7 @@ static void TestTextureBasedRender() | ||||
|     ImGui::Separator(); | ||||
|  | ||||
|     ImGui::Text("Style"); | ||||
|     ImGui::SliderFloat("FrameBorderSize", &style.FrameBorderSize, 0.0f, 3.0f, "%.0f"); | ||||
|     ImGui::SliderFloat("FrameRounding", &style.FrameRounding, 0.0f, 100.0f, "%.0f"); | ||||
|     ImGui::SliderFloat("WindowRounding", &style.WindowRounding, 0.0f, 100.0f, "%.0f"); | ||||
|  | ||||
|   | ||||
| @@ -1393,6 +1393,7 @@ void ImDrawList::AddLine(const ImVec2& p1, const ImVec2& p2, ImU32 col, float th | ||||
| // flags should contains a mask indicating which corners should be drawn rounded | ||||
| // Returns true if the rectangle was drawn, false for some reason it couldn't | ||||
| // be (in which case the caller should try again with the regular path drawing API) | ||||
| // We are using the textures generated by ImFontAtlasBuildRenderRoundCornersTexData() | ||||
| inline bool AddRoundCornerRect(ImDrawList* draw_list, const ImVec2& a, const ImVec2& b, ImU32 col, float rounding, ImDrawFlags flags, bool fill) | ||||
| { | ||||
| #if 1 | ||||
| @@ -1668,13 +1669,8 @@ void ImDrawList::AddRect(const ImVec2& p_min, const ImVec2& p_max, ImU32 col, fl | ||||
|  | ||||
|     // Try to use fast path if we can | ||||
|     if (rounding > 0) | ||||
|     { | ||||
|         if (AddRoundCornerRect(this, p_min, p_max, col, rounding, flags, /* fill */ false)) | ||||
|         { | ||||
|             // Fast path handled this | ||||
|             return; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     if (Flags & ImDrawListFlags_AntiAliasedLines) | ||||
|         PathRect(p_min + ImVec2(0.50f, 0.50f), p_max - ImVec2(0.50f, 0.50f), rounding, flags); | ||||
| @@ -1703,14 +1699,10 @@ void ImDrawList::AddRectFilled(const ImVec2& p_min, const ImVec2& p_max, ImU32 c | ||||
|     { | ||||
|         // Try fast path first | ||||
|         if (AddRoundCornerRect(this, p_min, p_max, col, rounding, flags, /* fill */ true)) | ||||
|         { | ||||
|             return; | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             PathRect(p_min, p_max, rounding, flags); | ||||
|             PathFillConvex(col); | ||||
|         } | ||||
|  | ||||
|         PathRect(p_min, p_max, rounding, flags); | ||||
|         PathFillConvex(col); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @@ -1786,8 +1778,7 @@ inline bool AddRoundCornerCircle(ImDrawList* draw_list, const ImVec2& center, fl | ||||
|     IM_ASSERT(tex_id == draw_list->_TextureIdStack.back());  // Use high-level ImGui::PushFont() or low-level ImDrawList::PushTextureId() to change font. | ||||
|  | ||||
|     const int rad = (int)radius; | ||||
|     if ((rad < 1) || // Radius 0 will cause issues with the UV lookup below | ||||
|         (rad > data->Font->ContainerAtlas->RoundCornersMaxSize)) | ||||
|     if (rad < 1 || rad > data->Font->ContainerAtlas->RoundCornersMaxSize) // Radius 0 will cause issues with the UV lookup below | ||||
|         return false; // We can't handle this | ||||
|  | ||||
|     // Debug command to force this render path to only execute when shift is held | ||||
| @@ -1819,7 +1810,6 @@ inline bool AddRoundCornerCircle(ImDrawList* draw_list, const ImVec2& center, fl | ||||
|  | ||||
|     // Some useful constants for our calculations | ||||
|     const float half_sqrt_two = 0.70710678f; // sqrtf(2.0f) * 0.5f | ||||
|     const float sqrt_two_minus_one = 0.41421356f; // sqrt(2.0f) - 1.0f | ||||
|     const float width_offset_parametric = line_width / rad; // Line width in our parametric coordinate space | ||||
|  | ||||
|     const int num_verts = fill ? 9 : 16; // Number of vertices we are going to write | ||||
| @@ -3265,7 +3255,11 @@ static void ImFontAtlasBuildRegisterRoundCornersCustomRects(ImFontAtlas* atlas) | ||||
|     const int pad = FONT_ATLAS_ROUNDED_CORNER_TEX_PADDING; | ||||
|     const int max = atlas->RoundCornersMaxSize; | ||||
|     for (int n = 0; n < max; n++) | ||||
|         atlas->RoundCornersRectIds.push_back(atlas->AddCustomRectRegular(n + 1 + pad * 2, n + 1 + FONT_ATLAS_ROUNDED_CORNER_TEX_CENTER_PADDING  + pad * 2)); | ||||
|     { | ||||
|         const int width = n + 1 + pad * 2; | ||||
|         const int height = n + 1 + FONT_ATLAS_ROUNDED_CORNER_TEX_CENTER_PADDING + pad * 2; | ||||
|         atlas->RoundCornersRectIds.push_back(atlas->AddCustomRectRegular(width, height)); | ||||
|     } | ||||
| } | ||||
|  | ||||
| // Generate the actual pixel data for rounded corners in the atlas | ||||
| @@ -3318,7 +3312,6 @@ static void ImFontAtlasBuildRenderRoundCornersTexData(ImFontAtlas* atlas) | ||||
|                 } | ||||
|  | ||||
|                 const float dist = ImSqrt((float)(cx*cx+cy*cy)) - (float)(radius - (filled ? 0 : stroke_width)); | ||||
|  | ||||
|                 float alpha = 0.0f; | ||||
|                 if (filled) | ||||
|                 { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user