Browse Source

Fix clipping when element position is less than 0

Lloyd Weehuizen 14 years ago
parent
commit
e84bb43a60
3 changed files with 31 additions and 69 deletions
  1. 0 4
      Build/Rocket.xcodeproj/project.pbxproj
  2. 1 1
      Source/Core/Context.cpp
  3. 30 64
      Source/Core/ElementUtilities.cpp

+ 0 - 4
Build/Rocket.xcodeproj/project.pbxproj

@@ -431,7 +431,6 @@
 		6EF3BCD112481DD40014316D /* MathTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 6EF3BBD112481DD40014316D /* MathTypes.h */; };
 		6EF3BCD112481DD40014316D /* MathTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 6EF3BBD112481DD40014316D /* MathTypes.h */; };
 		6EF3BCD212481DD40014316D /* Platform.h in Headers */ = {isa = PBXBuildFile; fileRef = 6EF3BBD212481DD40014316D /* Platform.h */; };
 		6EF3BCD212481DD40014316D /* Platform.h in Headers */ = {isa = PBXBuildFile; fileRef = 6EF3BBD212481DD40014316D /* Platform.h */; };
 		6EF3BCD312481DD40014316D /* Plugin.h in Headers */ = {isa = PBXBuildFile; fileRef = 6EF3BBD312481DD40014316D /* Plugin.h */; };
 		6EF3BCD312481DD40014316D /* Plugin.h in Headers */ = {isa = PBXBuildFile; fileRef = 6EF3BBD312481DD40014316D /* Plugin.h */; };
-		6EF3BCD412481DD40014316D /* Pool.h in Headers */ = {isa = PBXBuildFile; fileRef = 6EF3BBD412481DD40014316D /* Pool.h */; };
 		6EF3BCD512481DD40014316D /* Pool.inl in Resources */ = {isa = PBXBuildFile; fileRef = 6EF3BBD512481DD40014316D /* Pool.inl */; };
 		6EF3BCD512481DD40014316D /* Pool.inl in Resources */ = {isa = PBXBuildFile; fileRef = 6EF3BBD512481DD40014316D /* Pool.inl */; };
 		6EF3BCD612481DD40014316D /* Property.h in Headers */ = {isa = PBXBuildFile; fileRef = 6EF3BBD612481DD40014316D /* Property.h */; };
 		6EF3BCD612481DD40014316D /* Property.h in Headers */ = {isa = PBXBuildFile; fileRef = 6EF3BBD612481DD40014316D /* Property.h */; };
 		6EF3BCD712481DD40014316D /* PropertyDefinition.h in Headers */ = {isa = PBXBuildFile; fileRef = 6EF3BBD712481DD40014316D /* PropertyDefinition.h */; };
 		6EF3BCD712481DD40014316D /* PropertyDefinition.h in Headers */ = {isa = PBXBuildFile; fileRef = 6EF3BBD712481DD40014316D /* PropertyDefinition.h */; };
@@ -776,7 +775,6 @@
 		6EF3BBD112481DD40014316D /* MathTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MathTypes.h; path = ../Include/Rocket/Core/MathTypes.h; sourceTree = SOURCE_ROOT; };
 		6EF3BBD112481DD40014316D /* MathTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MathTypes.h; path = ../Include/Rocket/Core/MathTypes.h; sourceTree = SOURCE_ROOT; };
 		6EF3BBD212481DD40014316D /* Platform.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Platform.h; path = ../Include/Rocket/Core/Platform.h; sourceTree = SOURCE_ROOT; };
 		6EF3BBD212481DD40014316D /* Platform.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Platform.h; path = ../Include/Rocket/Core/Platform.h; sourceTree = SOURCE_ROOT; };
 		6EF3BBD312481DD40014316D /* Plugin.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Plugin.h; path = ../Include/Rocket/Core/Plugin.h; sourceTree = SOURCE_ROOT; };
 		6EF3BBD312481DD40014316D /* Plugin.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Plugin.h; path = ../Include/Rocket/Core/Plugin.h; sourceTree = SOURCE_ROOT; };
-		6EF3BBD412481DD40014316D /* Pool.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Pool.h; path = ../Include/Rocket/Core/Pool.h; sourceTree = SOURCE_ROOT; };
 		6EF3BBD512481DD40014316D /* Pool.inl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = Pool.inl; path = ../Include/Rocket/Core/Pool.inl; sourceTree = SOURCE_ROOT; };
 		6EF3BBD512481DD40014316D /* Pool.inl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = Pool.inl; path = ../Include/Rocket/Core/Pool.inl; sourceTree = SOURCE_ROOT; };
 		6EF3BBD612481DD40014316D /* Property.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Property.h; path = ../Include/Rocket/Core/Property.h; sourceTree = SOURCE_ROOT; };
 		6EF3BBD612481DD40014316D /* Property.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Property.h; path = ../Include/Rocket/Core/Property.h; sourceTree = SOURCE_ROOT; };
 		6EF3BBD712481DD40014316D /* PropertyDefinition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PropertyDefinition.h; path = ../Include/Rocket/Core/PropertyDefinition.h; sourceTree = SOURCE_ROOT; };
 		6EF3BBD712481DD40014316D /* PropertyDefinition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PropertyDefinition.h; path = ../Include/Rocket/Core/PropertyDefinition.h; sourceTree = SOURCE_ROOT; };
@@ -919,7 +917,6 @@
 				6EF3BBD112481DD40014316D /* MathTypes.h */,
 				6EF3BBD112481DD40014316D /* MathTypes.h */,
 				6EF3BBD212481DD40014316D /* Platform.h */,
 				6EF3BBD212481DD40014316D /* Platform.h */,
 				6EF3BBD312481DD40014316D /* Plugin.h */,
 				6EF3BBD312481DD40014316D /* Plugin.h */,
-				6EF3BBD412481DD40014316D /* Pool.h */,
 				6EF3BBD512481DD40014316D /* Pool.inl */,
 				6EF3BBD512481DD40014316D /* Pool.inl */,
 				6EF3BBD612481DD40014316D /* Property.h */,
 				6EF3BBD612481DD40014316D /* Property.h */,
 				6EF3BBD712481DD40014316D /* PropertyDefinition.h */,
 				6EF3BBD712481DD40014316D /* PropertyDefinition.h */,
@@ -1265,7 +1262,6 @@
 				6EF3BCD112481DD40014316D /* MathTypes.h in Headers */,
 				6EF3BCD112481DD40014316D /* MathTypes.h in Headers */,
 				6EF3BCD212481DD40014316D /* Platform.h in Headers */,
 				6EF3BCD212481DD40014316D /* Platform.h in Headers */,
 				6EF3BCD312481DD40014316D /* Plugin.h in Headers */,
 				6EF3BCD312481DD40014316D /* Plugin.h in Headers */,
-				6EF3BCD412481DD40014316D /* Pool.h in Headers */,
 				6EF3BCD612481DD40014316D /* Property.h in Headers */,
 				6EF3BCD612481DD40014316D /* Property.h in Headers */,
 				6EF3BCD712481DD40014316D /* PropertyDefinition.h in Headers */,
 				6EF3BCD712481DD40014316D /* PropertyDefinition.h in Headers */,
 				6EF3BCD812481DD40014316D /* PropertyDictionary.h in Headers */,
 				6EF3BCD812481DD40014316D /* PropertyDictionary.h in Headers */,

+ 1 - 1
Source/Core/Context.cpp

@@ -809,7 +809,7 @@ RenderInterface* Context::GetRenderInterface() const
 // Gets the current clipping region for the render traversal
 // Gets the current clipping region for the render traversal
 bool Context::GetActiveClipRegion(Vector2i& origin, Vector2i& dimensions) const
 bool Context::GetActiveClipRegion(Vector2i& origin, Vector2i& dimensions) const
 {
 {
-	if (clip_origin.x < 0 || clip_origin.y < 0)
+	if (clip_dimensions.x < 0 || clip_dimensions.y < 0)
 		return false;
 		return false;
 	
 	
 	origin = clip_origin;
 	origin = clip_origin;

+ 30 - 64
Source/Core/ElementUtilities.cpp

@@ -35,62 +35,6 @@
 namespace Rocket {
 namespace Rocket {
 namespace Core {
 namespace Core {
 
 
-struct ClipRegion
-{
-	ClipRegion() : origin(-1, -1), dimensions(-1, -1)
-	{
-	}
-
-	ClipRegion(const Vector2i& origin, const Vector2i& dimensions) : origin(origin), dimensions(dimensions)
-	{
-	}
-
-	void AddClipElement(Rocket::Core::Element* element)
-	{
-		Vector2f element_origin_f = element->GetAbsoluteOffset(Box::CONTENT);
-		Vector2f element_dimensions_f = element->GetBox().GetSize(Box::CONTENT);
-
-		Vector2i element_origin(Math::RealToInteger(element_origin_f.x), Math::RealToInteger(element_origin_f.y));
-		Vector2i element_dimensions(Math::RealToInteger(element_dimensions_f.x), Math::RealToInteger(element_dimensions_f.y));
-
-		if (origin == Vector2i(-1, -1) && dimensions == Vector2i(-1, -1))
-		{
-			origin = element_origin;
-			dimensions = element_dimensions;
-		}
-		else
-		{
-			Vector2i top_left(Math::Max(origin.x, element_origin.x),
-										 Math::Max(origin.y, element_origin.y));
-
-			Vector2i bottom_right(Math::Min(origin.x + dimensions.x, element_origin.x + element_dimensions.x),
-											 Math::Min(origin.y + dimensions.y, element_origin.y + element_dimensions.y));
-
-			origin = top_left;
-			dimensions.x = Math::Max(0, bottom_right.x - top_left.x);
-			dimensions.y = Math::Max(0, bottom_right.y - top_left.y);
-		}
-	}
-
-	Vector2i origin;
-	Vector2i dimensions;
-};
-
-struct ClipState
-{
-	ClipState() : clip_region(Vector2i(-1, -1), Vector2i(-1, -1))
-	{
-		clip_on = false;
-	}
-
-	bool clip_on;
-	ClipRegion clip_region;
-};
-
-// The current clipping state.
-typedef std::map< RenderInterface*, ClipState > ClipStateMap;
-ClipStateMap clip_states;
-
 // Builds and sets the box for an element.
 // Builds and sets the box for an element.
 static void SetBox(Element* element);
 static void SetBox(Element* element);
 // Positions an element relative to an offset parent.
 // Positions an element relative to an offset parent.
@@ -223,11 +167,12 @@ void ElementUtilities::BindEventAttributes(Element* element)
 		}
 		}
 	}
 	}
 }
 }
-
+	
 // Generates the clipping region for an element.
 // Generates the clipping region for an element.
 bool ElementUtilities::GetClippingRegion(Vector2i& clip_origin, Vector2i& clip_dimensions, Element* element)
 bool ElementUtilities::GetClippingRegion(Vector2i& clip_origin, Vector2i& clip_dimensions, Element* element)
 {
 {
-	ClipRegion clip_region;
+	clip_origin = Vector2i(-1, -1);
+	clip_dimensions = Vector2i(-1, -1);
 	
 	
 	int num_ignored_clips = element->GetClippingIgnoreDepth();
 	int num_ignored_clips = element->GetClippingIgnoreDepth();
 	if (num_ignored_clips < 0)
 	if (num_ignored_clips < 0)
@@ -245,8 +190,32 @@ bool ElementUtilities::GetClippingRegion(Vector2i& clip_origin, Vector2i& clip_d
 		{
 		{
 			// Ignore nodes that don't clip.
 			// Ignore nodes that don't clip.
 			if (clipping_element->GetClientWidth() < clipping_element->GetScrollWidth()
 			if (clipping_element->GetClientWidth() < clipping_element->GetScrollWidth()
-				|| clipping_element->GetClientHeight() < clipping_element->GetScrollHeight())				 
-				clip_region.AddClipElement(clipping_element);
+				|| clipping_element->GetClientHeight() < clipping_element->GetScrollHeight())
+			{				
+				Vector2f element_origin_f = clipping_element->GetAbsoluteOffset(Box::CONTENT);
+				Vector2f element_dimensions_f = clipping_element->GetBox().GetSize(Box::CONTENT);
+				
+				Vector2i element_origin(Math::RealToInteger(element_origin_f.x), Math::RealToInteger(element_origin_f.y));
+				Vector2i element_dimensions(Math::RealToInteger(element_dimensions_f.x), Math::RealToInteger(element_dimensions_f.y));
+				
+				if (clip_origin == Vector2i(-1, -1) && clip_dimensions == Vector2i(-1, -1))
+				{
+					clip_origin = element_origin;
+					clip_dimensions = element_dimensions;
+				}
+				else
+				{
+					Vector2i top_left(Math::Max(clip_origin.x, element_origin.x),
+									  Math::Max(clip_origin.y, element_origin.y));
+					
+					Vector2i bottom_right(Math::Min(clip_origin.x + clip_dimensions.x, element_origin.x + element_dimensions.x),
+										  Math::Min(clip_origin.y + clip_dimensions.y, element_origin.y + element_dimensions.y));
+					
+					clip_origin = top_left;
+					clip_dimensions.x = Math::Max(0, bottom_right.x - top_left.x);
+					clip_dimensions.y = Math::Max(0, bottom_right.y - top_left.y);
+				}
+			}
 		}
 		}
 
 
 		// If this region is meant to clip and we're skipping regions, update the counter.
 		// If this region is meant to clip and we're skipping regions, update the counter.
@@ -268,10 +237,7 @@ bool ElementUtilities::GetClippingRegion(Vector2i& clip_origin, Vector2i& clip_d
 		clipping_element = clipping_element->GetParentNode();
 		clipping_element = clipping_element->GetParentNode();
 	}
 	}
 	
 	
-	clip_origin = clip_region.origin;
-	clip_dimensions = clip_region.dimensions;
-	
-	return clip_origin.x >= 0 || clip_origin.y >= 0;
+	return clip_dimensions.x >= 0 && clip_dimensions.y >= 0;
 }
 }
 
 
 // Sets the clipping region from an element and its ancestors.
 // Sets the clipping region from an element and its ancestors.