26#ifndef TGUI_TEXTURE_HPP
27#define TGUI_TEXTURE_HPP
31#include <TGUI/TextureData.hpp>
32#include <TGUI/TextureManager.hpp>
34#include <TGUI/Global.hpp>
44 class TGUI_API
Texture :
public sf::Transformable,
public sf::Drawable
48 using ImageLoaderFunc = std::function<std::shared_ptr<sf::Image>(
const sf::String&)>;
49 using TextureLoaderFunc = std::function<bool(
Texture&,
const sf::String&,
const sf::IntRect&)>;
86 const sf::IntRect& partRect = sf::IntRect(0, 0, 0, 0),
87 const sf::IntRect& middlePart = sf::IntRect(0, 0, 0, 0));
103 const sf::IntRect& partRect = sf::IntRect(0, 0, 0, 0),
104 const sf::IntRect& middlePart = sf::IntRect(0, 0, 0, 0));
143 void load(
const sf::Texture& texture,
144 const sf::IntRect& partRect = {},
145 const sf::IntRect& middleRect = {});
156 void load(
const sf::String&
id,
157 const sf::IntRect& partRect = {},
158 const sf::IntRect& middleRect = {});
170 void setTexture(std::shared_ptr<TextureData> data,
const sf::IntRect& middleRect = {});
197 std::shared_ptr<const TextureData>
getData()
const;
229 return sf::Vector2f{m_data->texture.getSize()};
271 m_textureRect = textureRect;
283 return m_textureRect;
324 return m_data->texture.isSmooth();
348 return m_scalingType;
441 void updateVertices();
447 void draw(sf::RenderTarget& target, sf::RenderStates states)
const override;
453 std::shared_ptr<TextureData> m_data = std::make_shared<TextureData>();
454 std::vector<sf::Vertex> m_vertices;
457 sf::IntRect m_middleRect;
458 sf::FloatRect m_textureRect;
459 sf::Color m_vertexColor = sf::Color::White;
463 bool m_loaded =
false;
466 std::function<void(std::shared_ptr<TextureData>)> m_copyCallback;
467 std::function<void(std::shared_ptr<TextureData>)> m_destructCallback;
468 static TextureLoaderFunc m_textureLoader;
469 static ImageLoaderFunc m_imageLoader;
Definition: Texture.hpp:45
sf::IntRect getMiddleRect() const
Returns the middle rect of the texture which is used for 9-slice scaling.
Definition: Texture.hpp:293
bool isTransparentPixel(float x, float y) const
Check if a certain pixel is transparent.
static void setTextureLoader(const TextureLoaderFunc &func)
Sets a different texture loader.
void load(const sf::String &id, const sf::IntRect &partRect={}, const sf::IntRect &middleRect={})
Creates the texture.
Texture & operator=(const Texture &right)
Overload of assignment operator.
bool isLoaded() const
Check if the texture has been correctly loaded.
Definition: Texture.hpp:358
void setDestructCallback(const std::function< void(std::shared_ptr< TextureData >)> func)
Sets a callback function for when this texture is destroyed.
sf::FloatRect getTextureRect() const
Returns the part of the texture that is drawn.
Definition: Texture.hpp:281
void load(const sf::Texture &texture, const sf::IntRect &partRect={}, const sf::IntRect &middleRect={})
Creates the texture from an existing sf::Texture.
static void setImageLoader(const ImageLoaderFunc &func)
Sets a different image loader.
void setColor(const sf::Color &color)
Set the global color of the sprite.
std::shared_ptr< const TextureData > getData() const
Returns the constant texture data.
const sf::Color & getColor() const
Returns the global color of the sprite.
void setTexture(std::shared_ptr< TextureData > data, const sf::IntRect &middleRect={})
Changes the texture.
Texture(const Texture &texture)
Copy constructor.
static ImageLoaderFunc getImageLoader()
Returns the used image loader.
sf::Vector2f getSize() const
Returns the size that the image has when drawing.
Definition: Texture.hpp:215
std::string getId() const
Returns the id that was used to load the texture (for the default loader, the id is the filename)
sf::Vector2f getImageSize() const
Returns the size that the loaded image.
Definition: Texture.hpp:227
void setTextureRect(const sf::FloatRect &textureRect)
Changes the part of the texture that should be drawn.
Definition: Texture.hpp:269
void setSmooth(bool smooth)
Enable or disable the smooth filter.
Texture()
Default constructor.
Definition: Texture.hpp:72
bool isSmooth() const
Tell whether the smooth filter is enabled or not.
Definition: Texture.hpp:322
ScalingType
The way the image should be scaled.
Definition: Texture.hpp:57
static TextureLoaderFunc getTextureLoader()
Returns the used texture loader.
void setCopyCallback(const std::function< void(std::shared_ptr< TextureData >)> func)
Sets a callback function for when this texture is copied.
std::shared_ptr< TextureData > & getData()
Returns a reference to the texture data.
Texture(const sf::String &id, const sf::IntRect &partRect=sf::IntRect(0, 0, 0, 0), const sf::IntRect &middlePart=sf::IntRect(0, 0, 0, 0))
Constructor that created the texture.
ScalingType getScalingType() const
Returns the way in which the image is being scaled.
Definition: Texture.hpp:346
Texture(const sf::Texture &texture, const sf::IntRect &partRect=sf::IntRect(0, 0, 0, 0), const sf::IntRect &middlePart=sf::IntRect(0, 0, 0, 0))
Constructor that created the texture from an existing sf::Texture.
void setSize(const sf::Vector2f &size)
Changes the size that the image will have when drawing.
Namespace that contains all TGUI functions and classes.
Definition: Animation.hpp:34