Added setColor function to Texture

0.8
Bruno Van de Velde 2019-01-25 22:28:49 +01:00
parent d0ca923a13
commit 5afd3e379d
13 changed files with 171 additions and 98 deletions

View File

@ -100,7 +100,6 @@
#ifdef TGUI_NEXT
#define TGUI_REMOVE_DEPRECATED_CODE
#define TGUI_USE_CPP17
#endif
#endif // TGUI_CONFIG_HPP

View File

@ -315,6 +315,7 @@ namespace tgui
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Texture& getTexture();
// TGUI_NEXT: const reference
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -117,6 +117,7 @@
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// TGUI_NEXT: const reference
#define TGUI_RENDERER_PROPERTY_TEXTURE(CLASS, NAME) \
Texture& CLASS::get##NAME() const \
{ \

View File

@ -33,7 +33,7 @@
namespace tgui
{
class TGUI_API TreeViewRenderer : public tgui::WidgetRenderer
class TGUI_API TreeViewRenderer : public WidgetRenderer
{
public:
@ -44,13 +44,13 @@ namespace tgui
/// @brief Changes the size of the borders
/// @param borders Size of the borders
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setBorders(const tgui::Borders& borders);
void setBorders(const Borders& borders);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the size of the borders
/// @return border size
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
tgui::Borders getBorders() const;
Borders getBorders() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -70,104 +70,104 @@ namespace tgui
/// @brief Changes the background color of the tree view
/// @param color The new background color
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setBackgroundColor(tgui::Color color);
void setBackgroundColor(Color color);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the background color
/// @return Background color
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
tgui::Color getBackgroundColor() const;
Color getBackgroundColor() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Changes the color of the borders
/// @param color The new border color
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setBorderColor(tgui::Color color);
void setBorderColor(Color color);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the color of the borders
/// @return Border color
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
tgui::Color getBorderColor() const;
Color getBorderColor() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Changes the color of the text
/// @param color The new text color
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setTextColor(tgui::Color color);
void setTextColor(Color color);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the color of the text
/// @return Text color
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
tgui::Color getTextColor() const;
Color getTextColor() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Changes the color of the text of the item below the mouse
/// @param color The new hover text color
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setTextColorHover(tgui::Color color);
void setTextColorHover(Color color);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the color of the text of the item below the mouse
/// @return Hover text color
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
tgui::Color getTextColorHover() const;
Color getTextColorHover() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Changes the color of the text from the selected item
/// @param color The new selected text color
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setSelectedTextColor(tgui::Color color);
void setSelectedTextColor(Color color);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the color of the text from the selected item
/// @return Selected text color
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
tgui::Color getSelectedTextColor() const;
Color getSelectedTextColor() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Changes the color of the text of the selected item when it is below the mouse
/// @param color The new hover text color
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setSelectedTextColorHover(tgui::Color color);
void setSelectedTextColorHover(Color color);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the color of the text of the selected item when it is below the mouse
/// @return Hover text color
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
tgui::Color getSelectedTextColorHover() const;
Color getSelectedTextColorHover() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Changes the background color of the selected item
/// @param color The new selected item background color
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setSelectedBackgroundColor(tgui::Color color);
void setSelectedBackgroundColor(Color color);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the background color of the selected item
/// @return Selected item background color
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
tgui::Color getSelectedBackgroundColor() const;
Color getSelectedBackgroundColor() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Changes the background color used for the item below the mouse
/// @param color The new hover background color
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setBackgroundColorHover(tgui::Color color);
void setBackgroundColorHover(Color color);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the background color used for the item below the mouse
/// @return Background color of hovered item
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
tgui::Color getBackgroundColorHover() const;
Color getBackgroundColorHover() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -187,13 +187,13 @@ namespace tgui
/// @brief Sets the renderer data of the scrollbar
/// @param scrollbarRendererData Data about how the scrollbar should look
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setScrollbar(std::shared_ptr<tgui::RendererData> scrollbarRendererData);
void setScrollbar(std::shared_ptr<RendererData> scrollbarRendererData);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the renderer data of the scrollbar
/// @return Data about how the scrollbar looks
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
std::shared_ptr<tgui::RendererData> getScrollbar() const;
std::shared_ptr<RendererData> getScrollbar() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -218,13 +218,13 @@ namespace tgui
/// If neither of these textures are set, TextureLeaf is tried.
/// If TextureLeaf isn't set either then a "-" symbol will be displayed in the same color as the text.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setTextureBranchExpanded(const tgui::Texture& textureBranchExpanded);
void setTextureBranchExpanded(const Texture& textureBranchExpanded);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the image used in front of an expanded item
/// @return The expanded branch texture
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
tgui::Texture& getTextureBranchExpanded() const;
Texture& getTextureBranchExpanded() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -236,13 +236,13 @@ namespace tgui
/// If neither of these textures are set, TextureLeaf is tried.
/// If TextureLeaf isn't set either then a "+" symbol will be displayed in the same color as the text.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setTextureBranchCollapsed(const tgui::Texture& textureBranchCollapsed);
void setTextureBranchCollapsed(const Texture& textureBranchCollapsed);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the image used in front of a collapsed item
/// @return The collapsed branch texture
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
tgui::Texture& getTextureBranchCollapsed() const;
Texture& getTextureBranchCollapsed() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -252,13 +252,13 @@ namespace tgui
///
/// When neither TextureBranchExpanded and TextureBranchCollapsed are set, this texture is also used for branch nodes.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setTextureLeaf(const tgui::Texture& textureLeaf);
void setTextureLeaf(const Texture& textureLeaf);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the image used in front of a leaf item
/// @return The lead item texture
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
tgui::Texture& getTextureLeaf() const;
Texture& getTextureLeaf() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -77,7 +77,7 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const Texture& getTexture() const;
#ifndef TGUI_NEXT
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns a reference to the texture used by this sprite
///
@ -85,7 +85,7 @@ namespace tgui
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Texture& getTexture();
#endif
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns whether a texture was set
@ -113,7 +113,7 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Vector2f getSize() const;
#ifndef TGUI_REMOVE_DEPRECATED_CODE
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Sets the global color of the sprite
///
@ -125,22 +125,22 @@ namespace tgui
/// @param color New color of the sprite
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setColor(const Color& color);
TGUI_DEPRECATED("Color should be changed through the texture") void setColor(const Color& color);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the global color of the sprite
///
/// This color is modulated (multiplied) with the sprite's texture. It can be used to colorize the sprite,
/// or change its global opacity.
/// or change its global opacity. Note that the alpha component is multiplied with the opacity set by setOpacity.
///
/// By default, the sprite's color is opaque white.
///
/// @return Current color of the sprite
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const Color& getColor() const;
TGUI_DEPRECATED("Color should be changed through the texture") const Color& getColor() const;
#endif
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Changes the opacity of the texture
@ -226,6 +226,7 @@ namespace tgui
FloatRect m_visibleRect;
sf::Shader* m_shader = nullptr;
Color m_vertexColor = Color::White;
float m_opacity = 1;

View File

@ -30,6 +30,7 @@
#include <TGUI/TextureData.hpp>
#include <TGUI/Vector2f.hpp>
#include <TGUI/Color.hpp>
#include <SFML/System/String.hpp>
#include <functional>
@ -234,6 +235,33 @@ namespace tgui
bool isSmooth() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Sets the global color of the texture
///
/// This color is modulated (multiplied) with the pixel color. It can be used to colorize the texture,
/// or change its global opacity. Note that the alpha component is multiplied with the opacity of the widget.
///
/// By default, the texture's color is opaque white.
///
/// @param color New color of the texture
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setColor(const Color& color);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Returns the global color of the texture
///
/// This color is modulated (multiplied) with the pixel color. It can be used to colorize the texture,
/// or change its global opacity. Note that the alpha component is multiplied with the opacity of the widget.
///
/// By default, the texture's color is opaque white.
///
/// @return Current color of the texture
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const Color& getColor() const;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Sets the shader used to draw the texture
/// @param shader New shader to use
@ -367,7 +395,8 @@ namespace tgui
private:
std::shared_ptr<TextureData> m_data = nullptr;
Color m_color = Color::White;
sf::Shader* m_shader = nullptr;
sf::IntRect m_middleRect;
sf::String m_id;

View File

@ -50,7 +50,10 @@ namespace tgui
std::unique_ptr<sf::Image> image;
sf::Texture texture;
sf::IntRect rect;
#ifndef TGUI_NEXT
sf::Shader* shader = nullptr;
#endif
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -39,6 +39,7 @@
#include <TGUI/Widgets/Knob.hpp>
#include <TGUI/Widgets/Label.hpp>
#include <TGUI/Widgets/ListBox.hpp>
#include <TGUI/Widgets/ListView.hpp>
#include <TGUI/Widgets/MenuBar.hpp>
#include <TGUI/Widgets/MessageBox.hpp>
#include <TGUI/Widgets/Panel.hpp>
@ -78,6 +79,7 @@ namespace tgui
{"knob", std::make_shared<Knob>},
{"label", std::make_shared<Label>},
{"listbox", std::make_shared<ListBox>},
{"listview", std::make_shared<ListView>},
{"menubar", std::make_shared<MenuBar>},
{"messagebox", std::make_shared<MessageBox>},
{"panel", std::make_shared<Panel>},

View File

@ -59,11 +59,11 @@ namespace tgui
m_type = Type::Font;
}
#ifdef TGUI_USE_CPP17
#ifdef TGUI_USE_CPP17
return std::get<Font>(m_value);
#else
#else
return m_value.as<Font>();
#endif
#endif
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -79,11 +79,11 @@ namespace tgui
m_type = Type::Color;
}
#ifdef TGUI_USE_CPP17
#ifdef TGUI_USE_CPP17
return std::get<Color>(m_value);
#else
#else
return m_value.as<Color>();
#endif
#endif
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -99,11 +99,11 @@ namespace tgui
m_type = Type::Bool;
}
#ifdef TGUI_USE_CPP17
#ifdef TGUI_USE_CPP17
return std::get<bool>(m_value);
#else
#else
return m_value.as<bool>();
#endif
#endif
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -119,11 +119,11 @@ namespace tgui
m_type = Type::Number;
}
#ifdef TGUI_USE_CPP17
#ifdef TGUI_USE_CPP17
return std::get<float>(m_value);
#else
#else
return m_value.as<float>();
#endif
#endif
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -139,11 +139,11 @@ namespace tgui
m_type = Type::Outline;
}
#ifdef TGUI_USE_CPP17
#ifdef TGUI_USE_CPP17
return std::get<Outline>(m_value);
#else
#else
return m_value.as<Outline>();
#endif
#endif
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -159,11 +159,11 @@ namespace tgui
m_type = Type::Texture;
}
#ifdef TGUI_USE_CPP17
#ifdef TGUI_USE_CPP17
return std::get<Texture>(m_value);
#else
#else
return m_value.as<Texture>();
#endif
#endif
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -179,11 +179,11 @@ namespace tgui
m_type = Type::TextStyle;
}
#ifdef TGUI_USE_CPP17
#ifdef TGUI_USE_CPP17
return std::get<TextStyle>(m_value);
#else
#else
return m_value.as<TextStyle>();
#endif
#endif
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -199,11 +199,11 @@ namespace tgui
m_type = Type::RendererData;
}
#ifdef TGUI_USE_CPP17
#ifdef TGUI_USE_CPP17
return std::get<std::shared_ptr<RendererData>>(m_value);
#else
#else
return m_value.as<std::shared_ptr<RendererData>>();
#endif
#endif
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -229,7 +229,7 @@ namespace tgui
return true;
case Type::String:
return m_string == right.m_string;
#ifdef TGUI_USE_CPP17
#ifdef TGUI_USE_CPP17
case Type::Bool:
return std::get<bool>(m_value) == std::get<bool>(right.m_value);
case Type::Font:
@ -246,7 +246,7 @@ namespace tgui
return std::get<TextStyle>(m_value) == std::get<TextStyle>(right.m_value);
case Type::RendererData:
return std::get<std::shared_ptr<RendererData>>(m_value) == std::get<std::shared_ptr<RendererData>>(right.m_value);
#else
#else
case Type::Bool:
return m_value.as<bool>() == right.m_value.as<bool>();
case Type::Font:
@ -263,7 +263,7 @@ namespace tgui
return m_value.as<TextStyle>() == right.m_value.as<TextStyle>();
case Type::RendererData:
return m_value.as<std::shared_ptr<RendererData>>() == right.m_value.as<std::shared_ptr<RendererData>>();
#endif
#endif
default: // This case should never occur, but prevents a warning that control reaches end of non-void function
return false;
}

View File

@ -37,9 +37,13 @@
namespace tgui
{
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Sprite::setTexture(const Texture& texture)
{
m_texture = texture;
m_vertexColor = m_texture.getColor();
m_shader = m_texture.getShader();
if (isSet())
{
@ -58,12 +62,12 @@ namespace tgui
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef TGUI_NEXT
Texture& Sprite::getTexture()
{
return m_texture;
}
#endif
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool Sprite::isSet() const
@ -90,7 +94,7 @@ namespace tgui
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef TGUI_REMOVE_DEPRECATED_CODE
void Sprite::setColor(const Color& color)
{
m_vertexColor = color;
@ -106,13 +110,16 @@ namespace tgui
{
return m_vertexColor;
}
#endif
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Sprite::setOpacity(float opacity)
{
m_opacity = opacity;
setColor(getColor());
const sf::Color vertexColor = Color::calcColorOpacity(m_vertexColor, m_opacity);
for (auto& vertex : m_vertices)
vertex.color = vertexColor;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -395,6 +402,9 @@ namespace tgui
void Sprite::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
if (!isSet())
return;
// A rotation can cause the image to be shifted, so we move it upfront so that it ends at the correct location
if (getRotation() != 0)
{
@ -406,23 +416,20 @@ namespace tgui
states.transform *= getTransform();
if (isSet())
{
// Apply clipping when needed
#ifdef TGUI_USE_CPP17
std::optional<Clipping> clipping;
if (m_visibleRect != FloatRect{})
clipping.emplace(target, states, Vector2f{m_visibleRect.left, m_visibleRect.top}, Vector2f{m_visibleRect.width, m_visibleRect.height});
#else
std::unique_ptr<Clipping> clipping;
if (m_visibleRect != FloatRect{0, 0, 0, 0})
clipping = std::make_unique<Clipping>(target, states, Vector2f{m_visibleRect.left, m_visibleRect.top}, Vector2f{m_visibleRect.width, m_visibleRect.height});
#endif
// Apply clipping when needed
#ifdef TGUI_USE_CPP17
std::optional<Clipping> clipping;
if (m_visibleRect != FloatRect{})
clipping.emplace(target, states, Vector2f{m_visibleRect.left, m_visibleRect.top}, Vector2f{m_visibleRect.width, m_visibleRect.height});
#else
std::unique_ptr<Clipping> clipping;
if (m_visibleRect != FloatRect{0, 0, 0, 0})
clipping = std::make_unique<Clipping>(target, states, Vector2f{m_visibleRect.left, m_visibleRect.top}, Vector2f{m_visibleRect.width, m_visibleRect.height});
#endif
states.shader = m_texture.getData()->shader;
states.texture = &m_texture.getData()->texture;
target.draw(m_vertices.data(), m_vertices.size(), sf::PrimitiveType::TrianglesStrip, states);
}
states.shader = m_shader;
states.texture = &m_texture.getData()->texture;
target.draw(m_vertices.data(), m_vertices.size(), sf::PrimitiveType::TrianglesStrip, states);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -69,6 +69,8 @@ namespace tgui
Texture::Texture(const Texture& other) :
m_data {other.m_data},
m_color {other.m_color},
m_shader {other.m_shader},
m_middleRect {other.m_middleRect},
m_id {other.m_id},
m_copyCallback {other.m_copyCallback},
@ -82,6 +84,8 @@ namespace tgui
Texture::Texture(Texture&& other) :
m_data {std::move(other.m_data)},
m_color {std::move(other.m_color)},
m_shader {std::move(other.m_shader)},
m_middleRect {std::move(other.m_middleRect)},
m_id {std::move(other.m_id)},
m_copyCallback {std::move(other.m_copyCallback)},
@ -109,6 +113,8 @@ namespace tgui
Texture temp{other};
std::swap(m_data, temp.m_data);
std::swap(m_color, temp.m_color);
std::swap(m_shader, temp.m_shader);
std::swap(m_middleRect, temp.m_middleRect);
std::swap(m_id, temp.m_id);
std::swap(m_copyCallback, temp.m_copyCallback);
@ -125,6 +131,8 @@ namespace tgui
if (this != &other)
{
m_data = std::move(other.m_data);
m_color = std::move(other.m_color);
m_shader = std::move(other.m_shader);
m_middleRect = std::move(other.m_middleRect);
m_id = std::move(other.m_id);
m_copyCallback = std::move(other.m_copyCallback);
@ -240,20 +248,42 @@ namespace tgui
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Texture::setColor(const Color& color)
{
m_color = color;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const Color& Texture::getColor() const
{
return m_color;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Texture::setShader(sf::Shader* shader)
{
#ifdef TGUI_NEXT
m_shader = shader;
#else
if (m_data)
m_data->shader = shader;
#endif
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
sf::Shader* Texture::getShader() const
{
#ifdef TGUI_NEXT
return m_shader;
#else
if (m_data)
return m_data->shader;
else
return nullptr;
#endif
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -296,10 +326,11 @@ namespace tgui
bool Texture::operator==(const Texture& right) const
{
if (m_id.isEmpty() && right.m_id.isEmpty())
return (m_data == right.m_data) && (m_middleRect == right.m_middleRect);
else
return (m_middleRect == right.m_middleRect) && (m_id == right.m_id);
return (m_id == right.m_id)
&& (!m_id.isEmpty() || (m_data == right.m_data))
&& (m_middleRect == right.m_middleRect)
&& (m_shader == right.m_shader)
&& (m_color == right.m_color);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -49,7 +49,6 @@ TEST_CASE("[Sprite]")
REQUIRE(sprite.getSize() == sf::Vector2f(50, 50));
}
REQUIRE(sprite.getColor() == sf::Color::White);
REQUIRE(sprite.getVisibleRect() == sf::FloatRect());
REQUIRE(sprite.getScalingType() == tgui::Sprite::ScalingType::Normal);
}
@ -71,15 +70,6 @@ TEST_CASE("[Sprite]")
REQUIRE(sprite.getSize() == sf::Vector2f(80, 60));
}
SECTION("Color")
{
sprite.setTexture({"resources/image.png"});
REQUIRE(sprite.getColor() == sf::Color::White);
sprite.setColor(sf::Color::Blue);
REQUIRE(sprite.getColor() == sf::Color::Blue);
}
SECTION("Opacity")
{
sprite.setTexture("resources/image.png");

View File

@ -179,6 +179,15 @@ TEST_CASE("[Texture]")
REQUIRE(!texture.isSmooth());
}
SECTION("Color")
{
tgui::Texture texture{"resources/image.png"};
REQUIRE(texture.getColor() == sf::Color::White);
texture.setColor("red");
REQUIRE(texture.getColor() == sf::Color::Red);
}
SECTION("Shader")
{
tgui::Texture texture{"resources/image.png"};