Smolgui
Immediate gui library based on SFML
Loading...
Searching...
No Matches
TextureAtlas.h
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <cstdint>
5#include <optional>
6#include <unordered_map>
7#include <SFML/Graphics/Rect.hpp>
8
9namespace sgui
10{
14struct Frames {
15 Frames () = default;
16 uint32_t count = 1;
17 sf::IntRect texture = {};
18};
19
28{
29public:
33 TextureAtlas () = default;
38 TextureAtlas (const std::string& filename);
44 bool loadFromFile (const std::string& filename);
51 void add (const std::string& entry, sf::IntRect&& textureRect, const uint32_t framesCount = 1);
56 void remove (const std::string& entry);
60 void clear ();
65 uint32_t texturesCount () const { return mTexturesCount; }
72 std::optional <sf::IntRect> textureRect (const std::string& entry, const uint32_t frame = 0) const;
76 auto begin () { return std::begin (mAtlas); }
77 auto end () { return std::end (mAtlas); }
78 auto begin () const { return std::cbegin (mAtlas); }
79 auto end () const { return std::cend (mAtlas); }
80private:
81 uint32_t mTexturesCount = { 0 };
82 sf::Vector2u mTextureDimension = {};
83 std::unordered_map <std::string, Frames> mAtlas;
84};
85
86} // namespace sgui
void remove(const std::string &entry)
Remove a texture from the atlas.
Definition TextureAtlas.cpp:38
auto begin()
Definition TextureAtlas.h:76
auto begin() const
Definition TextureAtlas.h:78
TextureAtlas()=default
Build an empty atlas.
void clear()
Clear all textures from the atlas.
Definition TextureAtlas.cpp:44
uint32_t texturesCount() const
Get number of textures stored in the atlas.
Definition TextureAtlas.h:65
auto end()
Definition TextureAtlas.h:77
void add(const std::string &entry, sf::IntRect &&textureRect, const uint32_t framesCount=1)
Add a texture to the atlas.
Definition TextureAtlas.cpp:24
auto end() const
Definition TextureAtlas.h:79
bool loadFromFile(const std::string &filename)
Load texture atlas from file.
Definition TextureAtlas.cpp:16
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.
Definition TextureAtlas.cpp:52
Definition Interpolation.h:16
Frames()=default
uint32_t count
Definition TextureAtlas.h:16
sf::IntRect texture
Definition TextureAtlas.h:17