Browse Source

Remove Decorator::LoadTexture. Instead, use the DecoratorInstancerInterface to load textures and pass it into the decorator.

Michael Ragazzon 4 years ago
parent
commit
330432704e

+ 0 - 5
Include/RmlUi/Core/Decorator.h

@@ -70,11 +70,6 @@ public:
 	static const DecoratorDataHandle INVALID_DECORATORDATAHANDLE = 0;
 	static const DecoratorDataHandle INVALID_DECORATORDATAHANDLE = 0;
 
 
 protected:
 protected:
-	/// Attempts to load a texture into the list of textures in use by the decorator.
-	/// @param[in] texture_name The name of the texture to load.
-	/// @param[in] rcss_path The RCSS file the decorator definition was loaded from; this is used to resolve relative paths.
-	/// @return The index of the texture if the load was successful, or -1 if the load failed.
-	int LoadTexture(const String& texture_name, const String& rcss_path);
 	/// Adds a texture if it is valid into the list of textures in use by the decorator.
 	/// Adds a texture if it is valid into the list of textures in use by the decorator.
 	/// @param[in] texture The texture to add.
 	/// @param[in] texture The texture to add.
 	/// @return The index of the texture if it is successful, or -1 if it is invalid.
 	/// @return The index of the texture if it is successful, or -1 if it is invalid.

+ 4 - 0
Include/RmlUi/Core/DecoratorInstancer.h

@@ -96,6 +96,10 @@ public:
 	/// This will use the document path where the 'decorator' property was declared to locate relative files, if available.
 	/// This will use the document path where the 'decorator' property was declared to locate relative files, if available.
 	Texture GetTexture(const String& filename) const;
 	Texture GetTexture(const String& filename) const;
 
 
+	/// Get the path from the texture from a filename set in the decorator property.
+	/// This will use the document path where the 'decorator' property was declared to locate relative files, if available.
+	const String& GetSourcePath(const String& filename) const;
+
 private:
 private:
 	const StyleSheet& style_sheet;
 	const StyleSheet& style_sheet;
 	const PropertySource* property_source;
 	const PropertySource* property_source;

+ 1 - 1
Samples/assets/invader.rcss

@@ -48,7 +48,7 @@
 	
 	
 	text-l: 162px 192px 14px 31px;
 	text-l: 162px 192px 14px 31px;
 	text-c: 176px 192px 1px 31px;
 	text-c: 176px 192px 1px 31px;
-	textarea: 162px 192px 145px 31px;
+	textarea: 162px 193px 145px 31px;
 	textarea-inner: 173px 206px 127px 10px;
 	textarea-inner: 173px 206px 127px 10px;
 	
 	
 	selectbox-tl: 281px 275px 11px 9px;
 	selectbox-tl: 281px 275px 11px 9px;

+ 2 - 2
Samples/invaders/src/DecoratorDefender.cpp

@@ -36,9 +36,9 @@ DecoratorDefender::~DecoratorDefender()
 {
 {
 }
 }
 
 
-bool DecoratorDefender::Initialise(const Rml::String& image_source, const Rml::String& image_path)
+bool DecoratorDefender::Initialise(const Rml::Texture& texture)
 {
 {
-	image_index = LoadTexture(image_source, image_path);
+	image_index = AddTexture(texture);
 	if (image_index == -1)
 	if (image_index == -1)
 	{
 	{
 		return false;
 		return false;

+ 1 - 1
Samples/invaders/src/DecoratorDefender.h

@@ -36,7 +36,7 @@ class DecoratorDefender : public Rml::Decorator
 public:
 public:
 	virtual ~DecoratorDefender();
 	virtual ~DecoratorDefender();
 
 
-	bool Initialise(const Rml::String& image_source, const Rml::String& image_path);
+	bool Initialise(const Rml::Texture& texture);
 
 
 	/// Called on a decorator to generate any required per-element data for a newly decorated element.
 	/// Called on a decorator to generate any required per-element data for a newly decorated element.
 	/// @param element[in] The newly decorated element.
 	/// @param element[in] The newly decorated element.

+ 3 - 5
Samples/invaders/src/DecoratorInstancerDefender.cpp

@@ -44,16 +44,14 @@ DecoratorInstancerDefender::~DecoratorInstancerDefender()
 
 
 // Instances a decorator given the property tag and attributes from the RCSS file.
 // Instances a decorator given the property tag and attributes from the RCSS file.
 Rml::SharedPtr<Rml::Decorator> DecoratorInstancerDefender::InstanceDecorator(const Rml::String& /*name*/,
 Rml::SharedPtr<Rml::Decorator> DecoratorInstancerDefender::InstanceDecorator(const Rml::String& /*name*/,
-	const Rml::PropertyDictionary& properties, const Rml::DecoratorInstancerInterface& /*instancer_interface*/)
+	const Rml::PropertyDictionary& properties, const Rml::DecoratorInstancerInterface& instancer_interface)
 {
 {
 	const Rml::Property* image_source_property = properties.GetProperty(id_image_src);
 	const Rml::Property* image_source_property = properties.GetProperty(id_image_src);
 	Rml::String image_source = image_source_property->Get< Rml::String >();
 	Rml::String image_source = image_source_property->Get< Rml::String >();
-	Rml::String source_path;
-	if (auto & source = image_source_property->source)
-		source_path = source->path;
+	Rml::Texture texture = instancer_interface.GetTexture(image_source);
 
 
 	auto decorator = Rml::MakeShared<DecoratorDefender>();
 	auto decorator = Rml::MakeShared<DecoratorDefender>();
-	if (decorator->Initialise(image_source, source_path))
+	if (decorator->Initialise(texture))
 		return decorator;
 		return decorator;
 	
 	
 	return nullptr;
 	return nullptr;

+ 2 - 2
Samples/luainvaders/src/DecoratorDefender.cpp

@@ -36,9 +36,9 @@ DecoratorDefender::~DecoratorDefender()
 {
 {
 }
 }
 
 
-bool DecoratorDefender::Initialise(const Rml::String& image_source, const Rml::String& image_path)
+bool DecoratorDefender::Initialise(const Rml::Texture& texture)
 {
 {
-	image_index = LoadTexture(image_source, image_path);
+	image_index = AddTexture(texture);
 	if (image_index == -1)
 	if (image_index == -1)
 	{
 	{
 		return false;
 		return false;

+ 1 - 1
Samples/luainvaders/src/DecoratorDefender.h

@@ -36,7 +36,7 @@ class DecoratorDefender : public Rml::Decorator
 public:
 public:
 	virtual ~DecoratorDefender();
 	virtual ~DecoratorDefender();
 
 
-	bool Initialise(const Rml::String& image_source, const Rml::String& image_path);
+	bool Initialise(const Rml::Texture& texture);
 
 
 	/// Called on a decorator to generate any required per-element data for a newly decorated element.
 	/// Called on a decorator to generate any required per-element data for a newly decorated element.
 	/// @param element[in] The newly decorated element.
 	/// @param element[in] The newly decorated element.

+ 3 - 5
Samples/luainvaders/src/DecoratorInstancerDefender.cpp

@@ -44,16 +44,14 @@ DecoratorInstancerDefender::~DecoratorInstancerDefender()
 
 
 // Instances a decorator given the property tag and attributes from the RCSS file.
 // Instances a decorator given the property tag and attributes from the RCSS file.
 Rml::SharedPtr<Rml::Decorator> DecoratorInstancerDefender::InstanceDecorator(const Rml::String& /*name*/,
 Rml::SharedPtr<Rml::Decorator> DecoratorInstancerDefender::InstanceDecorator(const Rml::String& /*name*/,
-	const Rml::PropertyDictionary& properties, const Rml::DecoratorInstancerInterface& /*instancer_interface*/)
+	const Rml::PropertyDictionary& properties, const Rml::DecoratorInstancerInterface& instancer_interface)
 {
 {
 	const Rml::Property* image_source_property = properties.GetProperty(id_image_src);
 	const Rml::Property* image_source_property = properties.GetProperty(id_image_src);
 	Rml::String image_source = image_source_property->Get< Rml::String >();
 	Rml::String image_source = image_source_property->Get< Rml::String >();
-	Rml::String source_path;
-	if (auto & source = image_source_property->source)
-		source_path = source->path;
+	Rml::Texture texture = instancer_interface.GetTexture(image_source);
 
 
 	auto decorator = Rml::MakeShared<DecoratorDefender>();
 	auto decorator = Rml::MakeShared<DecoratorDefender>();
-	if (decorator->Initialise(image_source, source_path))
+	if (decorator->Initialise(texture))
 		return decorator;
 		return decorator;
 
 
 	return nullptr;
 	return nullptr;

+ 2 - 2
Samples/tutorial/datagrid/src/DecoratorDefender.cpp

@@ -19,9 +19,9 @@ DecoratorDefender::~DecoratorDefender()
 {
 {
 }
 }
 
 
-bool DecoratorDefender::Initialise(const Rml::String& image_source, const Rml::String& image_path)
+bool DecoratorDefender::Initialise(const Rml::Texture& texture)
 {
 {
-	image_index = LoadTexture(image_source, image_path);
+	image_index = AddTexture(texture);
 	if (image_index == -1)
 	if (image_index == -1)
 	{
 	{
 		return false;
 		return false;

+ 1 - 1
Samples/tutorial/datagrid/src/DecoratorDefender.h

@@ -24,7 +24,7 @@ class DecoratorDefender : public Rml::Decorator
 public:
 public:
 	virtual ~DecoratorDefender();
 	virtual ~DecoratorDefender();
 
 
-	bool Initialise(const Rml::String& image_source, const Rml::String& image_path);
+	bool Initialise(const Rml::Texture& texture);
 
 
 	/// Called on a decorator to generate any required per-element data for a newly decorated element.
 	/// Called on a decorator to generate any required per-element data for a newly decorated element.
 	/// @param element[in] The newly decorated element.
 	/// @param element[in] The newly decorated element.

+ 3 - 5
Samples/tutorial/datagrid/src/DecoratorInstancerDefender.cpp

@@ -27,16 +27,14 @@ DecoratorInstancerDefender::~DecoratorInstancerDefender()
 
 
 // Instances a decorator given the property tag and attributes from the RCSS file.
 // Instances a decorator given the property tag and attributes from the RCSS file.
 Rml::SharedPtr<Rml::Decorator> DecoratorInstancerDefender::InstanceDecorator(const Rml::String& /*name*/,
 Rml::SharedPtr<Rml::Decorator> DecoratorInstancerDefender::InstanceDecorator(const Rml::String& /*name*/,
-	const Rml::PropertyDictionary& properties, const Rml::DecoratorInstancerInterface& /*instancer_interface*/)
+	const Rml::PropertyDictionary& properties, const Rml::DecoratorInstancerInterface& instancer_interface)
 {
 {
 	const Rml::Property* image_source_property = properties.GetProperty(id_image_src);
 	const Rml::Property* image_source_property = properties.GetProperty(id_image_src);
 	Rml::String image_source = image_source_property->Get< Rml::String >();
 	Rml::String image_source = image_source_property->Get< Rml::String >();
-	Rml::String source_path;
-	if (auto & source = image_source_property->source)
-		source_path = source->path;
+	Rml::Texture texture = instancer_interface.GetTexture(image_source);
 
 
 	auto decorator = Rml::MakeShared<DecoratorDefender>();
 	auto decorator = Rml::MakeShared<DecoratorDefender>();
-	if (decorator->Initialise(image_source, source_path))
+	if (decorator->Initialise(texture))
 		return decorator;
 		return decorator;
 
 
 	return nullptr;
 	return nullptr;

+ 2 - 2
Samples/tutorial/datagrid_tree/src/DecoratorDefender.cpp

@@ -19,9 +19,9 @@ DecoratorDefender::~DecoratorDefender()
 {
 {
 }
 }
 
 
-bool DecoratorDefender::Initialise(const Rml::String& image_source, const Rml::String& image_path)
+bool DecoratorDefender::Initialise(const Rml::Texture& texture)
 {
 {
-	image_index = LoadTexture(image_source, image_path);
+	image_index = AddTexture(texture);
 	if (image_index == -1)
 	if (image_index == -1)
 	{
 	{
 		return false;
 		return false;

+ 1 - 1
Samples/tutorial/datagrid_tree/src/DecoratorDefender.h

@@ -24,7 +24,7 @@ class DecoratorDefender : public Rml::Decorator
 public:
 public:
 	virtual ~DecoratorDefender();
 	virtual ~DecoratorDefender();
 
 
-	bool Initialise(const Rml::String& image_source, const Rml::String& image_path);
+	bool Initialise(const Rml::Texture& texture);
 
 
 	/// Called on a decorator to generate any required per-element data for a newly decorated element.
 	/// Called on a decorator to generate any required per-element data for a newly decorated element.
 	/// @param element[in] The newly decorated element.
 	/// @param element[in] The newly decorated element.

+ 3 - 5
Samples/tutorial/datagrid_tree/src/DecoratorInstancerDefender.cpp

@@ -27,16 +27,14 @@ DecoratorInstancerDefender::~DecoratorInstancerDefender()
 
 
 // Instances a decorator given the property tag and attributes from the RCSS file.
 // Instances a decorator given the property tag and attributes from the RCSS file.
 Rml::SharedPtr<Rml::Decorator> DecoratorInstancerDefender::InstanceDecorator(const Rml::String& /*name*/,
 Rml::SharedPtr<Rml::Decorator> DecoratorInstancerDefender::InstanceDecorator(const Rml::String& /*name*/,
-	const Rml::PropertyDictionary& properties, const Rml::DecoratorInstancerInterface& /*instancer_interface*/)
+	const Rml::PropertyDictionary& properties, const Rml::DecoratorInstancerInterface& instancer_interface)
 {
 {
 	const Rml::Property* image_source_property = properties.GetProperty(id_image_src);
 	const Rml::Property* image_source_property = properties.GetProperty(id_image_src);
 	Rml::String image_source = image_source_property->Get< Rml::String >();
 	Rml::String image_source = image_source_property->Get< Rml::String >();
-	Rml::String source_path;
-	if (auto & source = image_source_property->source)
-		source_path = source->path;
+	Rml::Texture texture = instancer_interface.GetTexture(image_source);
 
 
 	auto decorator = Rml::MakeShared<DecoratorDefender>();
 	auto decorator = Rml::MakeShared<DecoratorDefender>();
-	if (decorator->Initialise(image_source, source_path))
+	if (decorator->Initialise(texture))
 		return decorator;
 		return decorator;
 
 
 	return nullptr;
 	return nullptr;

+ 0 - 19
Source/Core/Decorator.cpp

@@ -42,25 +42,6 @@ Decorator::~Decorator()
 {
 {
 }
 }
 
 
-// Attempts to load a texture into the list of textures in use by the decorator.
-int Decorator::LoadTexture(const String& texture_name, const String& rcss_path)
-{
-	if (texture_name == first_texture.GetSource())
-		return 0;
-
-	for (size_t i = 0; i < additional_textures.size(); i++)
-	{
-		if (texture_name == additional_textures[i].GetSource())
-			return (int)i + 1;
-	}
-
-	Texture texture;
-	texture.Set(texture_name, rcss_path);
-
-	additional_textures.push_back(std::move(texture));
-	return (int)additional_textures.size();
-}
-
 int Decorator::AddTexture(const Texture& texture)
 int Decorator::AddTexture(const Texture& texture)
 {
 {
 	if (!texture)
 	if (!texture)