Selaa lähdekoodia

Avoid subpixel rendering, round the geometry offset and background-border positioning/sizing. Tweak border-radius num_points.

Michael Ragazzon 5 vuotta sitten
vanhempi
sitoutus
afb141eae8

+ 1 - 1
Include/RmlUi/Core/Geometry.h

@@ -67,7 +67,7 @@ public:
 
 
 	/// Attempts to compile the geometry if appropriate, then renders the geometry, compiled if it can.
 	/// Attempts to compile the geometry if appropriate, then renders the geometry, compiled if it can.
 	/// @param[in] translation The translation of the geometry.
 	/// @param[in] translation The translation of the geometry.
-	void Render(const Vector2f& translation);
+	void Render(Vector2f translation);
 
 
 	/// Returns the geometry's vertices. If these are written to, Release() should be called to force a recompile.
 	/// Returns the geometry's vertices. If these are written to, Release() should be called to force a recompile.
 	/// @return The geometry's vertex array.
 	/// @return The geometry's vertex array.

+ 3 - 1
Source/Core/Geometry.cpp

@@ -97,12 +97,14 @@ void Geometry::SetHostElement(Element* _host_element)
 	host_element = _host_element;
 	host_element = _host_element;
 }
 }
 
 
-void Geometry::Render(const Vector2f& translation)
+void Geometry::Render(Vector2f translation)
 {
 {
 	RenderInterface* const render_interface = GetRenderInterface();
 	RenderInterface* const render_interface = GetRenderInterface();
 	if (!render_interface)
 	if (!render_interface)
 		return;
 		return;
 
 
+	translation = translation.Round();
+
 	// Render our compiled geometry if possible.
 	// Render our compiled geometry if possible.
 	if (compiled_geometry)
 	if (compiled_geometry)
 	{
 	{

+ 13 - 15
Source/Core/GeometryBackgroundBorder.cpp

@@ -42,10 +42,10 @@ void GeometryBackgroundBorder::Draw(Vector<Vertex>& vertices, Vector<int>& indic
 	using Edge = Box::Edge;
 	using Edge = Box::Edge;
 
 
 	EdgeSizes border_widths = {
 	EdgeSizes border_widths = {
-		box.GetEdge(Box::BORDER, Edge::TOP),
-		box.GetEdge(Box::BORDER, Edge::RIGHT),
-		box.GetEdge(Box::BORDER, Edge::BOTTOM),
-		box.GetEdge(Box::BORDER, Edge::LEFT),
+		Math::RoundFloat(box.GetEdge(Box::BORDER, Edge::TOP)),
+		Math::RoundFloat(box.GetEdge(Box::BORDER, Edge::RIGHT)),
+		Math::RoundFloat(box.GetEdge(Box::BORDER, Edge::BOTTOM)),
+		Math::RoundFloat(box.GetEdge(Box::BORDER, Edge::LEFT)),
 	};
 	};
 
 
 	int num_borders = 0;
 	int num_borders = 0;
@@ -57,7 +57,7 @@ void GeometryBackgroundBorder::Draw(Vector<Vertex>& vertices, Vector<int>& indic
 				num_borders += 1;
 				num_borders += 1;
 	}
 	}
 
 
-	const Vector2f padding_size = box.GetSize(Box::PADDING);
+	const Vector2f padding_size = box.GetSize(Box::PADDING).Round();
 
 
 	const bool has_background = (background_color.alpha > 0 && padding_size.x > 0 && padding_size.y > 0);
 	const bool has_background = (background_color.alpha > 0 && padding_size.x > 0 && padding_size.y > 0);
 	const bool has_border = (num_borders > 0);
 	const bool has_border = (num_borders > 0);
@@ -65,11 +65,10 @@ void GeometryBackgroundBorder::Draw(Vector<Vertex>& vertices, Vector<int>& indic
 	if (!has_background && !has_border)
 	if (!has_background && !has_border)
 		return;
 		return;
 
 
-
 	// -- Find the corner positions --
 	// -- Find the corner positions --
 
 
-	const Vector2f padding_position = box.GetPosition(Box::PADDING);
-	const Vector2f border_position = padding_position - Vector2f(border_widths[Edge::LEFT], border_widths[Edge::TOP]);
+	const Vector2f border_position = box.GetPosition(Box::BORDER).Round();
+	const Vector2f padding_position = border_position + Vector2f(border_widths[Edge::LEFT], border_widths[Edge::TOP]);
 	const Vector2f border_size = padding_size + Vector2f(border_widths[Edge::LEFT] + border_widths[Edge::RIGHT], border_widths[Edge::TOP] + border_widths[Edge::BOTTOM]);
 	const Vector2f border_size = padding_size + Vector2f(border_widths[Edge::LEFT] + border_widths[Edge::RIGHT], border_widths[Edge::TOP] + border_widths[Edge::BOTTOM]);
 
 
 	// Border edge positions
 	// Border edge positions
@@ -92,7 +91,7 @@ void GeometryBackgroundBorder::Draw(Vector<Vertex>& vertices, Vector<int>& indic
 	// -- For curved borders, find the positions to draw ellipses around, and the scaled outer and inner radii --
 	// -- For curved borders, find the positions to draw ellipses around, and the scaled outer and inner radii --
 
 
 	const float sum_radius = (radii[TOP_LEFT] + radii[TOP_RIGHT] + radii[BOTTOM_RIGHT] + radii[BOTTOM_LEFT]);
 	const float sum_radius = (radii[TOP_LEFT] + radii[TOP_RIGHT] + radii[BOTTOM_RIGHT] + radii[BOTTOM_LEFT]);
-	const bool has_radius = (sum_radius > 0);
+	const bool has_radius = (sum_radius > 1.f);
 
 
 	// Curved borders are drawn as circles (outer border) and ellipses (inner border) around the centers.
 	// Curved borders are drawn as circles (outer border) and ellipses (inner border) around the centers.
 	CornerPositions positions_circle_center;
 	CornerPositions positions_circle_center;
@@ -111,11 +110,10 @@ void GeometryBackgroundBorder::Draw(Vector<Vertex>& vertices, Vector<int>& indic
 		scale_factor = Math::Min(scale_factor, padding_size.x / (radii[BOTTOM_RIGHT] + radii[BOTTOM_LEFT])); // Bottom
 		scale_factor = Math::Min(scale_factor, padding_size.x / (radii[BOTTOM_RIGHT] + radii[BOTTOM_LEFT])); // Bottom
 		scale_factor = Math::Min(scale_factor, padding_size.y / (radii[BOTTOM_LEFT] + radii[TOP_LEFT]));     // Left
 		scale_factor = Math::Min(scale_factor, padding_size.y / (radii[BOTTOM_LEFT] + radii[TOP_LEFT]));     // Left
 
 
-		if (scale_factor < 1)
-		{
-			for (int i = 0; i < 4; i++)
-				radii[i] *= scale_factor;
-		}
+		scale_factor = Math::Min(1.0f, scale_factor);
+
+		for (float& radius : radii)
+			radius = Math::RoundFloat(radius * scale_factor);
 
 
 		// Place the circle/ellipse centers
 		// Place the circle/ellipse centers
 		positions_circle_center = {
 		positions_circle_center = {
@@ -417,7 +415,7 @@ void GeometryBackgroundBorder::FillEdge(int index_next_corner)
 
 
 int GeometryBackgroundBorder::GetNumPoints(float R) const
 int GeometryBackgroundBorder::GetNumPoints(float R) const
 {
 {
-	return Math::Clamp(3 + int(R / 6.f), 2, 100);
+	return Math::Clamp(3 + Math::RoundToInteger(R / 6.f), 2, 100);
 }
 }
 
 
 } // namespace Rml
 } // namespace Rml