class EE::Graphics::TextureAtlas

Overview

The texture atlas class represents a large image containing a collection of sub-images, or “atlas” which contains many smaller sub-images. The texture atlas in eepp can represent more than one texture or image, but the common use should be a image with sub-images. More information about Texture Atlases: http://en.wikipedia.org/wiki/Texture_atlas. More…

#include <textureatlas.hpp>

class TextureAtlas: public EE::System::ResourceManager {
public:
    // construction

    TextureAtlas(const std::string& name = "");
    ~TextureAtlas();

    // methods

    static TextureAtlas* New(const std::string& name = "");
    TextureRegion* add(TextureRegion* textureRegion);
    TextureRegion* add(const Uint32& TexId, const std::string& Name = "");
    TextureRegion* add(const Uint32& TexId, const Rect& SrcRect, const std::string& Name = "");
    TextureRegion* add(const Uint32& TexId, const Rect& SrcRect, const Sizef& DestSize, const std::string& Name = "");
    TextureRegion* add(const Uint32& TexId, const Rect& SrcRect, const Sizef& DestSize, const Vector2i& Offset, const std::string& Name = "");
    TextureRegion* add(Texture* tex, const std::string& Name = "");
    TextureRegion* add(Texture* tex, const Rect& SrcRect, const std::string& Name = "");
    TextureRegion* add(Texture* tex, const Rect& SrcRect, const Sizef& DestSize, const std::string& Name = "");
    TextureRegion* add(Texture* tex, const Rect& SrcRect, const Sizef& DestSize, const Vector2i& Offset, const std::string& Name = "");
    const std::string& getName() const;
    void setName(const std::string& name);
    const std::string& getPath() const;
    void setPath(const std::string& path);
    const String::HashType& getId() const;
    Uint32 getCount();
    Texture* getTexture(const Uint32& texnum = 0) const;
    Uint32 getTexturesCount();
};

Inherited Members

public:
    // methods

    virtual T* add(T* resource);
    bool remove(T* resource, bool remove = true);
    bool removeById(const String::HashType& id, bool remove = true);
    bool removeByName(const std::string& name, bool remove = true);
    T* getByName(const std::string& name);
    T* getById(const String::HashType& id);
    Uint32 getCount();
    Uint32 getCount(const std::string& name);
    Uint32 getCount(const String::HashType& id);
    bool exists(const std::string& name);
    bool existsId(const String::HashType& id);
    void destroy();
    void printNames();
    UnorderedMap<String::HashType, T*>& getResources();
    const bool& isDestroying() const;

    template <typename Predicate>
    void each(Predicate pred) const;

    template <typename Predicate>
    void each(Predicate pred);

    template <typename Predicate>
    T* findIf(Predicate pred) const;

    template <typename Predicate>
    T* findIf(Predicate pred);

Detailed Documentation

The texture atlas class represents a large image containing a collection of sub-images, or “atlas” which contains many smaller sub-images. The texture atlas in eepp can represent more than one texture or image, but the common use should be a image with sub-images. More information about Texture Atlases: http://en.wikipedia.org/wiki/Texture_atlas.

Construction

TextureAtlas(const std::string& name = "")

Creates a new texture atlas with the given name.

Methods

TextureRegion* add(TextureRegion* textureRegion)

Adds a TextureRegion to the Texture Atlas

TextureRegion* add(const Uint32& TexId, const std::string& Name = "")

Creates and add to the texture atlas a TextureRegion from a Texture. It will use the full Texture as a TextureRegion.

Parameters:

TexId

The texture id

Name

The texture name ( if any )

TextureRegion* add(const Uint32& TexId, const Rect& SrcRect, const std::string& Name = "")

Creates and add to the texture atlas a TextureRegion of the indicated part of the texture.

Parameters:

TexId

The texture id

SrcRect

The texture part that will be used as the TextureRegion.

Name

The texture name ( if any )

TextureRegion* add(const Uint32& TexId, const Rect& SrcRect, const Sizef& DestSize, const std::string& Name = "")

Creates and add to the texture atlas a TextureRegion of the indicated part of the texture.

Parameters:

TexId

The texture id

SrcRect

The texture part that will be used as the TextureRegion.

DestSize

The destination size that the TextureRegion will have when rendered.

Name

The texture name ( if any )

TextureRegion* add(const Uint32& TexId, const Rect& SrcRect, const Sizef& DestSize, const Vector2i& Offset, const std::string& Name = "")

Creates and add to the texture atlas a TextureRegion of the indicated part of the texture.

Parameters:

TexId

The texture id

SrcRect

The texture part that will be used as the TextureRegion.

DestSize

The destination size that the TextureRegion will have when rendered.

Offset

The offset that will be added to the position passed when any Draw call is used.

Name

The texture name ( if any )

TextureRegion* add(Texture* tex, const std::string& Name = "")

Creates and add to the texture atlas a TextureRegion from a Texture. It will use the full Texture as a TextureRegion.

Parameters:

tex

The texture

Name

The texture name ( if any )

TextureRegion* add(Texture* tex, const Rect& SrcRect, const std::string& Name = "")

Creates and add to the texture atlas a TextureRegion of the indicated part of the texture.

Parameters:

tex

The texture

SrcRect

The texture part that will be used as the TextureRegion.

Name

The texture name ( if any )

TextureRegion* add(Texture* tex, const Rect& SrcRect, const Sizef& DestSize, const std::string& Name = "")

Creates and add to the texture atlas a TextureRegion of the indicated part of the texture.

Parameters:

tex

The texture

SrcRect

The texture part that will be used as the TextureRegion.

DestSize

The destination size that the TextureRegion will have when rendered.

Name

The texture name ( if any )

TextureRegion* add(Texture* tex, const Rect& SrcRect, const Sizef& DestSize, const Vector2i& Offset, const std::string& Name = "")

Creates and add to the texture atlas a TextureRegion of the indicated part of the texture.

Parameters:

tex

The texture

SrcRect

The texture part that will be used as the TextureRegion.

DestSize

The destination size that the TextureRegion will have when rendered.

Offset

The offset that will be added to the position passed when any Draw call is used.

Name

The texture name ( if any )

const std::string& getName() const

Returns:

The texture atlas name.

void setName(const std::string& name)

Sets the texture atlas name.

const std::string& getPath() const

Returns:

The texture atlas path.

void setPath(const std::string& path)

Sets the texture atlas path.

const String::HashType& getId() const

Returns:

The texture atlas Id. The Id is the String::hash of the texture atlas name.

Uint32 getCount()

Returns:

The number of TextureRegions inside the texture atlas.

Texture* getTexture(const Uint32& texnum = 0) const

Note

Some texture atlases could not have any texture, since you can use it as a container of TextureRegions from any texture.

The texture atlases loaded from a file always will be linked to a texture.

The Global Texture Atlas for example doesn’t have any texture linked to it.

Parameters:

texnum

The texture index. A texture atlas can use more than one texture, so it can be 0 to getTexturesCount(). Usually a texture atlas corresponds to only one texture, so the texture index is 0.

Returns:

The texture that corresponds to the texture atlas.

Uint32 getTexturesCount()

Returns:

The number of textures linked to the texture atlas.