Procházet zdrojové kódy

Minor Box optimizations

Michael Ragazzon před 3 roky
rodič
revize
37b0728387

+ 4 - 1
Include/RmlUi/Core/Box.h

@@ -78,10 +78,13 @@ public:
 	/// @param area[in] The desired area.
 	/// @return The position of the area.
 	Vector2f GetPosition(Area area = Box::CONTENT) const;
+	/// Returns the size of the box's content area.
+	/// @return The size of the content area.
+	Vector2f GetSize() const;
 	/// Returns the size of one of the box's areas. This will include all inner areas.
 	/// @param area[in] The desired area.
 	/// @return The size of the requested area.
-	Vector2f GetSize(Area area = Box::CONTENT) const;
+	Vector2f GetSize(Area area) const;
 
 	/// Sets the size of the content area.
 	/// @param content[in] The size of the new content area.

+ 6 - 2
Source/Core/Box.cpp

@@ -60,11 +60,15 @@ Vector2f Box::GetPosition(Area area) const
 	return area_position;
 }
 
-// Returns the size of one of the box's areas. This will include all inner areas.
+Vector2f Box::GetSize() const
+{
+	return content;
+}
+
 Vector2f Box::GetSize(Area area) const
 {
 	Vector2f area_size(content);
-	for (int i = PADDING; i >= area; i--)
+	for (int i = area; i <= PADDING; i++)
 	{
 		area_size.x += (area_edges[i][LEFT] + area_edges[i][RIGHT]);
 		area_size.y += (area_edges[i][TOP] + area_edges[i][BOTTOM]);

+ 1 - 1
Source/Core/GeometryBackgroundBorder.cpp

@@ -67,7 +67,7 @@ void GeometryBackgroundBorder::Draw(Vector<Vertex>& vertices, Vector<int>& indic
 
 	// -- Find the corner positions --
 
-	const Vector2f border_position = (offset + box.GetPosition(Box::BORDER)).Round();
+	const Vector2f border_position = offset.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]);
 

+ 1 - 1
Source/Debugger/DebuggerPlugin.cpp

@@ -188,7 +188,7 @@ void DebuggerPlugin::Render()
 						Vector2f box_offset;
 						const Box& box = element->GetBox(j, box_offset);
 						Geometry::RenderOutline(
-							element->GetAbsoluteOffset(Box::BORDER) + box_offset + box.GetPosition(Box::BORDER),
+							element->GetAbsoluteOffset(Box::BORDER) + box_offset,
 							box.GetSize(Box::BORDER), 
 							Colourb(255, 0, 0, 128), 
 							1

+ 1 - 1
Source/Debugger/ElementInfo.cpp

@@ -143,7 +143,7 @@ void ElementInfo::RenderHoverElement()
 			Vector2f size = element_box.GetSize(Box::BORDER);
 			size = Vector2f(std::max(size.x, 2.0f), std::max(size.y, 2.0f));
 			Geometry::RenderOutline(
-				hover_element->GetAbsoluteOffset(Box::BORDER) + box_offset + element_box.GetPosition(Box::BORDER),
+				hover_element->GetAbsoluteOffset(Box::BORDER) + box_offset,
 				size,
 				Colourb(255, 0, 0, 255), 
 				1