Browse Source

Fix pixel-rounding errors in edges of tiled decorators and ninepatch decorator.

Michael Ragazzon 4 years ago
parent
commit
7d8ef828b3
2 changed files with 10 additions and 4 deletions
  1. 6 2
      Source/Core/DecoratorNinePatch.cpp
  2. 4 2
      Source/Core/DecoratorTiled.cpp

+ 6 - 2
Source/Core/DecoratorNinePatch.cpp

@@ -65,7 +65,7 @@ DecoratorDataHandle DecoratorNinePatch::GenerateElementData(Element* element) co
 	data->SetTexture(texture);
 	const Vector2f texture_dimensions(texture->GetDimensions(render_interface));
 
-	const Vector2f surface_dimensions = element->GetBox().GetSize(Box::PADDING);
+	const Vector2f surface_dimensions = element->GetBox().GetSize(Box::PADDING).Round();
 
 	const float opacity = computed.opacity;
 	Colourb quad_colour = computed.image_color;
@@ -124,6 +124,10 @@ DecoratorDataHandle DecoratorNinePatch::GenerateElementData(Element* element) co
 		}
 	}
 
+	// Round the inner corners
+	surface_pos[1] = surface_pos[1].Round();
+	surface_pos[2] = surface_pos[2].Round();
+
 	/* Now we have all the coordinates we need. Expand the diagonal vertices to the 16 individual vertices. */
 
 	Vector<Vertex>& vertices = data->GetVertices();
@@ -170,7 +174,7 @@ void DecoratorNinePatch::ReleaseElementData(DecoratorDataHandle element_data) co
 void DecoratorNinePatch::RenderElement(Element* element, DecoratorDataHandle element_data) const
 {
 	Geometry* data = reinterpret_cast< Geometry* >(element_data);
-	data->Render(element->GetAbsoluteOffset(Box::PADDING).Round());
+	data->Render(element->GetAbsoluteOffset(Box::PADDING));
 }
 
 

+ 4 - 2
Source/Core/DecoratorTiled.cpp

@@ -229,9 +229,11 @@ void DecoratorTiled::Tile::GenerateGeometry(Vector< Vertex >& vertices, Vector<
 	int* new_indices = &indices[0] + num_indices;
 
 	// Generate the vertices for the tiled surface.
-	Vector2f tile_position = (surface_origin + tile_offset).Round();
+	Vector2f tile_position = (surface_origin + tile_offset);
 
-	GeometryUtilities::GenerateQuad(new_vertices, new_indices, tile_position, final_tile_dimensions.Round(), quad_colour, scaled_texcoords[0], scaled_texcoords[1], index_offset);
+	Math::SnapToPixelGrid(tile_position, final_tile_dimensions);
+
+	GeometryUtilities::GenerateQuad(new_vertices, new_indices, tile_position, final_tile_dimensions, quad_colour, scaled_texcoords[0], scaled_texcoords[1], index_offset);
 }
 
 // Scales a tile dimensions by a fixed value along one axis.