Răsfoiți Sursa

Fixed color on textures

Michael 8 ani în urmă
părinte
comite
0247e5910d

+ 18 - 4
Source/Core/DecoratorTiled.cpp

@@ -25,6 +25,9 @@
  *
  */
 
+// Modified by uniquejack
+// Implement opacity (Check https://github.com/libRocket/libRocket/pull/262)
+
 #include "precompiled.h"
 #include "DecoratorTiled.h"
 #include "../../Include/Rocket/Core.h"
@@ -108,10 +111,21 @@ Vector2f DecoratorTiled::Tile::GetDimensions(Element* element)
 void DecoratorTiled::Tile::GenerateGeometry(std::vector< Vertex >& vertices, std::vector< int >& indices, Element* element, const Vector2f& surface_origin, const Vector2f& surface_dimensions, const Vector2f& tile_dimensions) const
 {
 	RenderInterface* render_interface = element->GetRenderInterface();
-	const Property* element_colour = element->GetProperty(COLOR);
-	Colourb quad_colour = Colourb(255, 255, 255);
-	if (element_colour)
-		quad_colour = element_colour->Get<Colourb>();
+	const Property* element_colour = element->GetProperty(BACKGROUND_COLOR);
+    float opacity = element->GetProperty<float>(OPACITY);
+
+    Colourb quad_colour = Colourb(255, 255, 255);
+    if (element_colour)
+    {
+        Colourb background_colour = element_colour->Get<Colourb>();
+
+        // Should be a non-transparent background
+        if (background_colour.alpha != 0)
+            quad_colour = background_colour;
+    }
+
+    // Apply opacity
+    quad_colour.alpha = (byte)(opacity * (float)quad_colour.alpha);
 	
 	TileDataMap::iterator data_iterator = data.find(render_interface);
 	if (data_iterator == data.end())

+ 13 - 6
Source/Core/Element.cpp

@@ -25,6 +25,9 @@
  *
  */
 
+// Modified by uniquejack
+// Implement opacity (Check https://github.com/libRocket/libRocket/pull/262)
+  
 #include "precompiled.h"
 #include "../../Include/Rocket/Core/Element.h"
 #include "../../Include/Rocket/Core/Dictionary.h"
@@ -52,7 +55,7 @@ namespace Core {
 class ElementSortZOrder
 {
 public:
-	bool operator()(const std::pair< Element*, float >& lhs, const std::pair< Element*, float >& rhs)
+	bool operator()(const std::pair< Element*, float >& lhs, const std::pair< Element*, float >& rhs) const // uniquejack add const
 	{
 		return lhs.second < rhs.second;
 	}
@@ -65,7 +68,7 @@ public:
 class ElementSortZIndex
 {
 public:
-	bool operator()(const Element* lhs, const Element* rhs)
+	bool operator()(const Element* lhs, const Element* rhs) const // uniquejack add const
 	{
 		// Check the z-index.
 		return lhs->GetZIndex() < rhs->GetZIndex();
@@ -1563,9 +1566,12 @@ void Element::OnPropertyChange(const PropertyNameList& changed_properties)
 	}
 
 	// Dirty the background if it's changed.
-	if (all_dirty ||
-		changed_properties.find(BACKGROUND_COLOR) != changed_properties.end())
-		background->DirtyBackground();
+    if (all_dirty ||
+        changed_properties.find(BACKGROUND_COLOR) != changed_properties.end() ||
+        changed_properties.find(OPACITY) != changed_properties.end()) {
+        background->DirtyBackground();
+        decoration->ReloadDecorators();
+    }
 
 	// Dirty the border if it's changed.
 	if (all_dirty || 
@@ -1576,7 +1582,8 @@ void Element::OnPropertyChange(const PropertyNameList& changed_properties)
 		changed_properties.find(BORDER_TOP_COLOR) != changed_properties.end() ||
 		changed_properties.find(BORDER_RIGHT_COLOR) != changed_properties.end() ||
 		changed_properties.find(BORDER_BOTTOM_COLOR) != changed_properties.end() ||
-		changed_properties.find(BORDER_LEFT_COLOR) != changed_properties.end())
+		changed_properties.find(BORDER_LEFT_COLOR) != changed_properties.end() ||
+		changed_properties.find(OPACITY) != changed_properties.end())
 		border->DirtyBorder();
 
 	// Fetch a new font face if it has been changed.

+ 8 - 0
Source/Core/ElementBackground.cpp

@@ -25,6 +25,9 @@
  *
  */
 
+// Modified by uniquejack
+// Implement opacity (Check https://github.com/libRocket/libRocket/pull/262)
+
 #include "precompiled.h"
 #include "ElementBackground.h"
 #include "../../Include/Rocket/Core/Element.h"
@@ -67,6 +70,11 @@ void ElementBackground::GenerateBackground()
 {
 	// Fetch the new colour for the background. If the colour is transparent, then we don't render any background.
 	Colourb colour = element->GetProperty(BACKGROUND_COLOR)->value.Get< Colourb >();
+	float opacity = element->GetProperty<float>(OPACITY);
+
+	// Apply opacity
+	colour.alpha = (byte)(opacity * (float)colour.alpha);
+
 	if (colour.alpha <= 0)
 	{
 		geometry.GetVertices().clear();

+ 9 - 0
Source/Core/ElementBorder.cpp

@@ -25,6 +25,9 @@
  *
  */
 
+// Modified by uniquejack
+// Implement opacity (Check https://github.com/libRocket/libRocket/pull/262)
+ 
 #include "precompiled.h"
 #include "ElementBorder.h"
 #include "../../Include/Rocket/Core/Element.h"
@@ -94,6 +97,12 @@ void ElementBorder::GenerateBorder()
 		border_colours[2] = element->GetProperty(BORDER_BOTTOM_COLOR)->value.Get< Colourb >();
 		border_colours[3] = element->GetProperty(BORDER_LEFT_COLOR)->value.Get< Colourb >();
 
+		// Apply opacity to the border
+		float opacity = element->GetProperty<float>(OPACITY);
+		for(int i = 0; i < 4; ++i) {
+			border_colours[i].alpha = (byte)(opacity * (float)border_colours[i].alpha);
+		}
+
 		for (int i = 0; i < element->GetNumBoxes(); ++i)
 			GenerateBorder(raw_vertices, raw_indices, index_offset, element->GetBox(i), border_colours);
 	}

+ 39 - 3
Source/Core/ElementHandle.cpp

@@ -25,6 +25,8 @@
  *
  */
 
+// Modified by uniquejack
+
 #include "precompiled.h"
 #include "ElementHandle.h"
 #include "../../Include/Rocket/Core/ElementDocument.h"
@@ -40,6 +42,7 @@ ElementHandle::ElementHandle(const String& tag) : Element(tag), drag_start(0, 0)
 	// Make sure we can be dragged!
 	SetProperty(DRAG, DRAG);
 
+	move_clip = NULL;
 	move_target = NULL;
 	size_target = NULL;
 	initialised = false;
@@ -55,7 +58,8 @@ void ElementHandle::OnAttributeChange(const PropertyNameList& changed_attributes
 
 	// Reset initialised state if the move or size targets have changed.
 	if (changed_attributes.find("move_target") != changed_attributes.end() ||
-		changed_attributes.find("size_target") != changed_attributes.end())
+		changed_attributes.find("size_target") != changed_attributes.end() ||
+		changed_attributes.find("move_clip") != changed_attributes.end())
 	{
 		initialised = false;
 		move_target = NULL;
@@ -80,6 +84,11 @@ void ElementHandle::ProcessEvent(Event& event)
 			if (!size_target_name.Empty())
 				size_target = GetElementById(size_target_name);
 
+			String move_clip_name = GetAttribute<String>("move_clip", "");
+            
+			if (!move_clip_name.Empty())
+				move_clip = GetElementById(move_clip_name);
+
 			initialised = true;
 		}
 
@@ -107,8 +116,35 @@ void ElementHandle::ProcessEvent(Event& event)
 			// Update the move and size objects
 			if (move_target)
 			{
-				move_target->SetProperty(LEFT, Property(Math::RealToInteger(move_original_position.x + x), Property::PX));
-				move_target->SetProperty(TOP, Property(Math::RealToInteger(move_original_position.y + y), Property::PX));
+				Vector2f pos, size;
+
+				if (move_clip)
+				{
+					pos = move_clip->GetBox().GetPosition();
+					size = move_clip->GetBox().GetSize();
+				}
+
+				Vector2f move;
+				move.x = (move_original_position.x + x);
+				move.y = (move_original_position.y + y);
+
+				Vector2f object_size = move_target->GetBox().GetSize();
+
+				if (object_size.x <= size.x && object_size.y <= size.y)
+				{
+					if (move.x < pos.x)
+						move.x = pos.x;
+					else if (move.x + object_size.x > pos.x + size.x)
+						move.x = pos.x + size.x - object_size.x;
+
+					if (move.y < pos.y)
+						move.y = pos.y;
+					else if (move.y + object_size.y > pos.y + size.y)
+						move.y = pos.y + size.y - object_size.y;                
+				}
+
+				move_target->SetProperty(LEFT, Property(Math::RealToInteger(move.x), Property::PX));
+				move_target->SetProperty(TOP, Property(Math::RealToInteger(move.y), Property::PX));
 			}
 
 			if (size_target)

+ 3 - 0
Source/Core/ElementHandle.h

@@ -25,6 +25,8 @@
  *
  */
 
+// Modified by uniquejack
+
 #ifndef ROCKETCOREELEMENTHANDLE_H
 #define ROCKETCOREELEMENTHANDLE_H
 
@@ -58,6 +60,7 @@ protected:
 
 	Element* move_target;
 	Element* size_target;
+	Element* move_clip;
 
 	bool initialised;
 };

+ 30 - 2
Source/Core/ElementImage.cpp

@@ -25,6 +25,8 @@
  *
  */
 
+// Modified by uniquejack
+
 #include "precompiled.h"
 #include "ElementImage.h"
 #include "../../Include/Rocket/Core.h"
@@ -156,6 +158,16 @@ void ElementImage::OnAttributeChange(const Rocket::Core::AttributeNameList& chan
 		DirtyLayout();
 }
 
+void ElementImage::OnPropertyChange(const PropertyNameList& changed_properties)
+{
+    Element::OnPropertyChange(changed_properties);
+
+    if (changed_properties.find(BACKGROUND_COLOR) != changed_properties.end() ||
+        changed_properties.find(OPACITY) != changed_properties.end()) {
+        GenerateGeometry();
+    }
+}
+
 // Regenerates the element's geometry.
 void ElementImage::ProcessEvent(Rocket::Core::Event& event)
 {
@@ -201,11 +213,27 @@ void ElementImage::GenerateGeometry()
 		texcoords[1] = Vector2f(1, 1);
 	}
 
+    const Property* element_colour = GetProperty(BACKGROUND_COLOR);
+    float opacity = GetProperty<float>(OPACITY);
+
+    Colourb quad_colour = Colourb(255, 255, 255);
+    if (element_colour)
+    {
+        Colourb background_colour = element_colour->Get<Colourb>();
+
+        // Should be a non-transparent background
+        if (background_colour.alpha != 0)
+            quad_colour = background_colour;
+    }
+
+    // Apply opacity
+    quad_colour.alpha = (byte)(opacity * (float)quad_colour.alpha);
+
 	Rocket::Core::GeometryUtilities::GenerateQuad(&vertices[0],									// vertices to write to
 												  &indices[0],									// indices to write to
-												  Vector2f(0, 0),					// origin of the quad
+												  Vector2f(0, 0),					            // origin of the quad
 												  GetBox().GetSize(Rocket::Core::Box::CONTENT),	// size of the quad
-												  Colourb(255, 255, 255, 255),		// colour of the vertices
+												  quad_colour,		                            // colour of the vertices
 												  texcoords[0],									// top-left texture coordinate
 												  texcoords[1]);								// top-right texture coordinate
 

+ 6 - 0
Source/Core/ElementImage.h

@@ -25,6 +25,8 @@
  *
  */
 
+// Modified by uniquejack
+
 #ifndef ROCKETCOREELEMENTIMAGE_H
 #define ROCKETCOREELEMENTIMAGE_H
 
@@ -84,6 +86,10 @@ protected:
 	/// @param[in] changed_attributes A list of attributes changed on the element.
 	virtual void OnAttributeChange(const AttributeNameList& changed_attributes);
 
+	/// Called when properties on the element are changed.
+	/// @param[in] changed_properties The properties changed on the element.
+	virtual void OnPropertyChange(const PropertyNameList& changed_properties);
+
 	/// Regenerates the element's geometry on a resize event.
 	/// @param[in] event The event to process.
 	virtual void ProcessEvent(Event& event);

+ 4 - 0
Source/Core/StringCache.cpp

@@ -25,6 +25,9 @@
  *
  */
 
+// Modified by uniquejack
+// Implement opacity (Check https://github.com/libRocket/libRocket/pull/262)
+ 
 #include "precompiled.h"
 
 namespace Rocket {
@@ -93,6 +96,7 @@ const String DRAG = "drag";
 const String TAB_INDEX = "tab-index";
 const String SCROLLBAR_MARGIN = "scrollbar-margin";
 const String SCROLL_DEFAULT_STEP_SIZE = "scroll-default-step-size";
+const String OPACITY = "opacity";
 
 const String MOUSEDOWN = "mousedown";
 const String MOUSESCROLL = "mousescroll";

+ 4 - 0
Source/Core/StringCache.h

@@ -25,6 +25,9 @@
  *
  */
 
+// Modified by uniquejack
+// Implement opacity (Check https://github.com/libRocket/libRocket/pull/262)
+ 
 #ifndef ROCKETCORESTRINGCACHE_H
 #define ROCKETCORESTRINGCACHE_H
 
@@ -96,6 +99,7 @@ extern const String DRAG;
 extern const String TAB_INDEX;
 extern const String SCROLLBAR_MARGIN;
 extern const String SCROLL_DEFAULT_STEP_SIZE;
+extern const String OPACITY;
 
 extern const String MOUSEDOWN;
 extern const String MOUSESCROLL;

+ 4 - 0
Source/Core/StyleSheetSpecification.cpp

@@ -25,6 +25,9 @@
  *
  */
 
+// Modified by uniquejack
+// Implement opacity (Check https://github.com/libRocket/libRocket/pull/262)
+ 
 #include "precompiled.h"
 #include "../../Include/Rocket/Core/StyleSheetSpecification.h"
 #include "PropertyParserNumber.h"
@@ -261,6 +264,7 @@ void StyleSheetSpecification::RegisterDefaultProperties()
 	RegisterProperty(FOCUS, "auto", true, false).AddParser("keyword", "none, auto");
 
 	RegisterProperty(SCROLLBAR_MARGIN, "0", false, false).AddParser("number");
+	RegisterProperty(OPACITY, "1", true, false).AddParser("number");
 }
 
 }