TGUI
0.7.8
|
Public Types | |
enum class | ScalingType { Normal , Horizontal , Vertical , NineSlice } |
The way the image should be scaled. More... | |
Public Member Functions | |
Texture () | |
Default constructor. | |
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. More... | |
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. More... | |
Texture (const Texture &texture) | |
Copy constructor. More... | |
Texture & | operator= (const Texture &right) |
Overload of assignment operator. More... | |
void | load (const sf::Texture &texture, const sf::IntRect &partRect={}, const sf::IntRect &middleRect={}) |
Creates the texture from an existing sf::Texture. More... | |
void | load (const sf::String &id, const sf::IntRect &partRect={}, const sf::IntRect &middleRect={}) |
Creates the texture. More... | |
void | setTexture (std::shared_ptr< TextureData > data, const sf::IntRect &middleRect={}) |
Changes the texture. More... | |
std::string | getId () const |
Returns the id that was used to load the texture (for the default loader, the id is the filename) More... | |
std::shared_ptr< TextureData > & | getData () |
Returns a reference to the texture data. More... | |
std::shared_ptr< const TextureData > | getData () const |
Returns the constant texture data. More... | |
void | setSize (const sf::Vector2f &size) |
Changes the size that the image will have when drawing. More... | |
sf::Vector2f | getSize () const |
Returns the size that the image has when drawing. More... | |
sf::Vector2f | getImageSize () const |
Returns the size that the loaded image. More... | |
void | setColor (const sf::Color &color) |
Set the global color of the sprite. More... | |
const sf::Color & | getColor () const |
Returns the global color of the sprite. More... | |
void | setTextureRect (const sf::FloatRect &textureRect) |
Changes the part of the texture that should be drawn. More... | |
sf::FloatRect | getTextureRect () const |
Returns the part of the texture that is drawn. More... | |
sf::IntRect | getMiddleRect () const |
Returns the middle rect of the texture which is used for 9-slice scaling. More... | |
void | setSmooth (bool smooth) |
Enable or disable the smooth filter. More... | |
bool | isSmooth () const |
Tell whether the smooth filter is enabled or not. More... | |
bool | isTransparentPixel (float x, float y) const |
Check if a certain pixel is transparent. More... | |
ScalingType | getScalingType () const |
Returns the way in which the image is being scaled. More... | |
bool | isLoaded () const |
Check if the texture has been correctly loaded. More... | |
void | setCopyCallback (const std::function< void(std::shared_ptr< TextureData >)> func) |
Sets a callback function for when this texture is copied. More... | |
void | setDestructCallback (const std::function< void(std::shared_ptr< TextureData >)> func) |
Sets a callback function for when this texture is destroyed. More... | |
Static Public Member Functions | |
static void | setImageLoader (const ImageLoaderFunc &func) |
Sets a different image loader. More... | |
static void | setTextureLoader (const TextureLoaderFunc &func) |
Sets a different texture loader. More... | |
static ImageLoaderFunc | getImageLoader () |
Returns the used image loader. More... | |
static TextureLoaderFunc | getTextureLoader () |
Returns the used texture loader. More... | |
|
strong |
The way the image should be scaled.
tgui::Texture::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.
id | Id for the the image to load (for the default loader, the id is the filename). |
partRect | Load only part of the image. Pass an empty rectangle if you want to load the full image. |
middlePart | Choose the middle part of the image for 9-slice scaling (relative to the part defined by partRect) |
This constructor just calls the corresponding load function.
tgui::Texture::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.
texture | Existing texture to copy. |
partRect | Load only part of the image. Pass an empty rectangle if you want to load the full image. |
middlePart | Choose the middle part of the image for 9-slice scaling (relative to the part defined by partRect) |
The texture will be copied, you do not have to keep the sf::Texture alive after calling this function.
This constructor just calls the corresponding load function.
tgui::Texture::Texture | ( | const Texture & | texture | ) |
Copy constructor.
texture | Instance to copy |
const sf::Color & tgui::Texture::getColor | ( | ) | const |
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.
By default, the sprite's color is opaque white.
std::shared_ptr< TextureData > & tgui::Texture::getData | ( | ) |
Returns a reference to the texture data.
std::shared_ptr< const TextureData > tgui::Texture::getData | ( | ) | const |
Returns the constant texture data.
std::string tgui::Texture::getId | ( | ) | const |
Returns the id that was used to load the texture (for the default loader, the id is the filename)
|
static |
Returns the used image loader.
|
inline |
Returns the size that the loaded image.
|
inline |
Returns the middle rect of the texture which is used for 9-slice scaling.
|
inline |
Returns the way in which the image is being scaled.
|
inline |
Returns the size that the image has when drawing.
|
static |
Returns the used texture loader.
|
inline |
Returns the part of the texture that is drawn.
|
inline |
Check if the texture has been correctly loaded.
|
inline |
Tell whether the smooth filter is enabled or not.
bool tgui::Texture::isTransparentPixel | ( | float | x, |
float | y | ||
) | const |
Check if a certain pixel is transparent.
x | global X coordinate of the pixel |
y | global Y coordinate of the pixel |
void tgui::Texture::load | ( | const sf::String & | id, |
const sf::IntRect & | partRect = {} , |
||
const sf::IntRect & | middleRect = {} |
||
) |
Creates the texture.
id | Id for the the image to load (for the default loader, the id is the filename). |
partRect | Load only part of the image. Don't pass this parameter if you want to load the full image. |
middleRect | Choose the middle part of the image for 9-slice scaling (relative to the part defined by partRect) |
void tgui::Texture::load | ( | const sf::Texture & | texture, |
const sf::IntRect & | partRect = {} , |
||
const sf::IntRect & | middleRect = {} |
||
) |
Creates the texture from an existing sf::Texture.
texture | Existing texture to copy. |
partRect | Load only part of the texture. Don't pass this parameter if you want to load the full image. |
middleRect | Choose the middle part of the image for 9-slice scaling (relative to the part defined by partRect) |
The texture will be copied, you do not have to keep the sf::Texture alive after calling this function.
Overload of assignment operator.
right | Instance to assign |
void tgui::Texture::setColor | ( | const sf::Color & | color | ) |
Set 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.
By default, the sprite's color is opaque white.
color | New color of the sprite |
void tgui::Texture::setCopyCallback | ( | const std::function< void(std::shared_ptr< TextureData >)> | func | ) |
Sets a callback function for when this texture is copied.
func | Function that will be called when this texture is copied |
This function can be useful when implementing a resource manager.
void tgui::Texture::setDestructCallback | ( | const std::function< void(std::shared_ptr< TextureData >)> | func | ) |
Sets a callback function for when this texture is destroyed.
func | Function that will be called when this texture is destroyed |
This function can be useful when implementing a resource manager.
|
static |
Sets a different image loader.
func | New image loader function |
The image loader will be called inside the texture loader to create the sf::Image.
The default loader will simply load the image from a file.
void tgui::Texture::setSize | ( | const sf::Vector2f & | size | ) |
Changes the size that the image will have when drawing.
size | Size of the image |
void tgui::Texture::setSmooth | ( | bool | smooth | ) |
Enable or disable the smooth filter.
When the filter is activated, the texture appears smoother so that pixels are less noticeable. However if you want the texture to look exactly the same as its source file, you should leave it disabled. The smooth filter is disabled by default.
smooth | True to enable smoothing, false to disable it |
void tgui::Texture::setTexture | ( | std::shared_ptr< TextureData > | data, |
const sf::IntRect & | middleRect = {} |
||
) |
Changes the texture.
data | New texture data |
middleRect | Choose the middle part of the image part to determine scaling (e.g. 9-slice scaling) |
This function is not intended to be used directly, except from custom loaders.
|
static |
Sets a different texture loader.
func | New texture loader function |
The texture loader will initialize this Texture object.
The default loader will use an internal texture manager to prevent the same thing from being loaded twice.
|
inline |
Changes the part of the texture that should be drawn.
textureRect | Visible part of the texture |
Set this to (0, 0, 0, 0) to show the entire texture