Smolgui
Immediate gui library based on SFML
Loading...
Searching...
No Matches
sgui::TextureAtlas Class Reference

Contains texture position and sub-box of all sprites for a given sprite sheet. Animations ca be handled with the following restrictions: More...

#include <TextureAtlas.h>

Public Member Functions

 TextureAtlas ()=default
 Build an empty atlas.
 TextureAtlas (const std::string &filename)
 Build texture atlas from file.
bool loadFromFile (const std::string &filename)
 Load texture atlas from file.
void add (const std::string &entry, sf::IntRect &&textureRect, const uint32_t framesCount=1)
 Add a texture to the atlas.
void remove (const std::string &entry)
 Remove a texture from the atlas.
void clear ()
 Clear all textures from the atlas.
uint32_t texturesCount () const
 Get number of textures stored in the atlas.
std::optional< sf::IntRect > textureRect (const std::string &entry, const uint32_t frame=0) const
 Get texture rect of an entry, if the entry exist.
auto begin ()
auto end ()
auto begin () const
auto end () const

Detailed Description

Contains texture position and sub-box of all sprites for a given sprite sheet. Animations ca be handled with the following restrictions:

  • texture rect need to represent the first frame
  • all frames stand in one line on the sprite sheet
  • all frames have the same size as the first one

Constructor & Destructor Documentation

◆ TextureAtlas() [1/2]

sgui::TextureAtlas::TextureAtlas ( )
default

Build an empty atlas.

◆ TextureAtlas() [2/2]

sgui::TextureAtlas::TextureAtlas ( const std::string & filename)

Build texture atlas from file.

Parameters
filenameFile from which atlas is loaded

Member Function Documentation

◆ add()

void sgui::TextureAtlas::add ( const std::string & entry,
sf::IntRect && textureRect,
const uint32_t framesCount = 1 )

Add a texture to the atlas.

Parameters
entryTexture name
textureRectTexture position and size
framesCountNumber of frames in the animation if needed (1 by default)

◆ begin() [1/2]

auto sgui::TextureAtlas::begin ( )
inline

Iterator to store TextureAtlas in json

◆ begin() [2/2]

auto sgui::TextureAtlas::begin ( ) const
inline

◆ clear()

void sgui::TextureAtlas::clear ( )

Clear all textures from the atlas.

◆ end() [1/2]

auto sgui::TextureAtlas::end ( )
inline

◆ end() [2/2]

auto sgui::TextureAtlas::end ( ) const
inline

◆ loadFromFile()

bool sgui::TextureAtlas::loadFromFile ( const std::string & filename)

Load texture atlas from file.

Parameters
filenameFile from which atlas is loaded
Returns
true if loading was successful

◆ remove()

void sgui::TextureAtlas::remove ( const std::string & entry)

Remove a texture from the atlas.

Parameters
entryTexture name

◆ textureRect()

std::optional< sf::IntRect > sgui::TextureAtlas::textureRect ( const std::string & entry,
const uint32_t frame = 0 ) const

Get texture rect of an entry, if the entry exist.

Parameters
entryTexture name
frameTexture frame it its part of an animation
Returns
Texture rect if it's stored in the atlas, std::nullopt otherwise

◆ texturesCount()

uint32_t sgui::TextureAtlas::texturesCount ( ) const
inline

Get number of textures stored in the atlas.

Returns
Number of textures stored.

The documentation for this class was generated from the following files: