25#ifndef TGUI_TEXTURE_HPP
26#define TGUI_TEXTURE_HPP
30#include <TGUI/TextureData.hpp>
31#include <TGUI/Vector2.hpp>
32#include <TGUI/String.hpp>
33#include <TGUI/Global.hpp>
34#include <TGUI/Color.hpp>
35#include <TGUI/Rect.hpp>
39#if TGUI_HAS_RENDERER_BACKEND_SFML_GRAPHICS
40 #include <SFML/Graphics/Texture.hpp>
41 #include <SFML/Graphics/Shader.hpp>
55 using CallbackFunc = std::function<void(std::shared_ptr<TextureData>)>;
56 using BackendTextureLoaderFunc = std::function<bool(
BackendTexture&,
const String&,
bool smooth)>;
57 using TextureLoaderFunc = std::function<std::shared_ptr<TextureData>(
Texture&,
const String&,
bool smooth)>;
75 const UIntRect& partRect = UIntRect(0, 0, 0, 0),
76 const UIntRect& middlePart = UIntRect(0, 0, 0, 0),
77 bool smooth = m_defaultSmooth)
95 const UIntRect& partRect = UIntRect(0, 0, 0, 0),
96 const UIntRect& middlePart = UIntRect(0, 0, 0, 0),
97 bool smooth = m_defaultSmooth);
99#if TGUI_HAS_RENDERER_BACKEND_SFML_GRAPHICS && !defined(TGUI_REMOVE_DEPRECATED_CODE)
114 TGUI_DEPRECATED(
"Use Texture() and loadFromPixelData(texture.getSize(), texture.copyToImage().getPixelsPtr()) instead")
116 const UIntRect& partRect = UIntRect(0, 0, 0, 0),
117 const UIntRect& middlePart = UIntRect(0, 0, 0, 0));
155 const UIntRect& partRect = {},
156 const UIntRect& middleRect = {},
157 bool smooth = m_defaultSmooth);
159#if TGUI_HAS_RENDERER_BACKEND_SFML_GRAPHICS && !defined(TGUI_REMOVE_DEPRECATED_CODE)
174 TGUI_DEPRECATED(
"Use loadFromPixelData(texture.getSize(), texture.copyToImage().getPixelsPtr()) instead")
176 const UIntRect& partRect = {},
177 const UIntRect& middleRect = {});
190 void loadFromMemory(
const std::uint8_t* data, std::size_t dataSize,
const UIntRect& partRect = {},
const UIntRect& middleRect = {},
bool smooth = m_defaultSmooth);
205 void loadFromPixelData(Vector2u size,
const std::uint8_t* pixels,
const UIntRect& partRect = {},
const UIntRect& middleRect = {},
bool smooth = m_defaultSmooth);
219 void loadFromBase64(CharStringView imageAsBase64,
const UIntRect& partRect = {},
const UIntRect& middleRect = {},
bool smooth = m_defaultSmooth);
233 TGUI_NODISCARD std::shared_ptr<TextureData>
getData()
const;
280#if TGUI_HAS_RENDERER_BACKEND_SFML_GRAPHICS
445 void setTextureData(std::shared_ptr<TextureData> data,
const UIntRect& partRect,
const UIntRect& middleRect);
450#if TGUI_HAS_RENDERER_BACKEND_SFML_GRAPHICS
451 sf::Shader* m_shader =
nullptr;
454 std::shared_ptr<TextureData> m_data =
nullptr;
458 UIntRect m_middleRect;
460 bool m_scaledNineSlice =
false;
462 CallbackFunc m_copyCallback;
463 CallbackFunc m_destructCallback;
465 static bool m_defaultSmooth;
467 static TextureLoaderFunc m_textureLoader;
468 static BackendTextureLoaderFunc m_backendTextureLoader;
Base class for texture implementations that depend on the backend.
Definition BackendTexture.hpp:41
Wrapper for colors.
Definition Color.hpp:71
static const Color White
White predefined color.
Definition Color.hpp:258
Wrapper class to store strings.
Definition String.hpp:94
void setScaledNineSlice(bool scaled)
Sets whether the corners of the image can still scale with the image size when 9-slice scaling is use...
UIntRect getMiddleRect() const
Returns the middle rect of the texture which is used for 9-slice scaling.
static void setTextureLoader(const TextureLoaderFunc &func)
Sets a different texture loader.
Texture(const Texture &)
Copy constructor.
static void setDefaultSmooth(bool smooth)
Changes whether textures are smoothed by default or not.
void setMiddleRect(const UIntRect &middleRect)
Sets the middle part of the image for 9-slice scaling (relative to the part defined by partRect)
bool isTransparentPixel(Vector2u pos) const
Checks if a certain pixel is transparent.
std::shared_ptr< TextureData > getData() const
Returns the texture data.
sf::Shader * getShader() const
Returns the shader used to draw the texture.
Texture(Texture &&) noexcept
Move constructor.
void load(const String &id, const UIntRect &partRect={}, const UIntRect &middleRect={}, bool smooth=m_defaultSmooth)
Creates the texture.
static const BackendTextureLoaderFunc & getBackendTextureLoader()
Returns the used backend texture loader.
static bool getDefaultSmooth()
Returns whether textures are smoothed by default or not.
bool operator==(const Texture &right) const
Compares the texture with another one.
Texture(const char *id, const UIntRect &partRect=UIntRect(0, 0, 0, 0), const UIntRect &middlePart=UIntRect(0, 0, 0, 0), bool smooth=m_defaultSmooth)
Constructor that created the texture.
Definition Texture.hpp:74
void setShader(sf::Shader *shader)
Sets the shader used to draw the texture.
bool operator!=(const Texture &right) const
Compares the texture with another one.
void loadFromBase64(CharStringView imageAsBase64, const UIntRect &partRect={}, const UIntRect &middleRect={}, bool smooth=m_defaultSmooth)
Loads the texture from a base64 string.
static const TextureLoaderFunc & getTextureLoader()
Returns the used texture loader.
void setColor(const Color &color)
Sets the global color of the texture.
UIntRect getPartRect() const
Returns which part of the image was loaded.
bool isSmooth() const
Tells whether the smooth filter is enabled or not.
void loadFromPixelData(Vector2u size, const std::uint8_t *pixels, const UIntRect &partRect={}, const UIntRect &middleRect={}, bool smooth=m_defaultSmooth)
Loads the texture from an array of 32-bits RGBA pixels.
bool getScaledNineSlice() const
Returns whether the corners of the image can still scale with the image size when 9-slice scaling is ...
void loadFromMemory(const std::uint8_t *data, std::size_t dataSize, const UIntRect &partRect={}, const UIntRect &middleRect={}, bool smooth=m_defaultSmooth)
Loads the texture from memory (data in memory should contain the entire file, not just the pixels)
static void setBackendTextureLoader(const BackendTextureLoaderFunc &func)
Sets a different backend texture loader.
void setCopyCallback(const CallbackFunc &func)
Sets a callback function for when this texture is copied.
const Color & getColor() const
Returns the global color of the texture.
const String & getId() const
Returns the id that was used to load the texture (for the default loader, the id is the filename)
void setDestructCallback(const CallbackFunc &func)
Sets a callback function for when this texture is destroyed.
Texture(const String &id, const UIntRect &partRect=UIntRect(0, 0, 0, 0), const UIntRect &middlePart=UIntRect(0, 0, 0, 0), bool smooth=m_defaultSmooth)
Constructor that created the texture.
Vector2u getImageSize() const
Returns the size that the loaded image, or the size of the part if only a part of the image is loaded...
Texture()=default
Default constructor.
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:36