class EE::Graphics::Text

Overview

#include <text.hpp>

class Text {
public:
    // enums

    enum Style;

    // structs

    struct VertexCoords;

    // construction

    Text();
    Text(const String& string, Font* font, unsigned int characterSize = 12);
    Text(Font* font, unsigned int characterSize = 12);

    // methods

    static std::string styleFlagToString(const Uint32& flags);
    static Uint32 stringToStyleFlag(const std::string& str);
    static Float getTextWidth(Font* font, const Uint32& fontSize, const String& string, const Uint32& style, const Uint32& tabWidth = 4, const Float& outlineThickness = 0.f);

    static Int32 findCharacterFromPos(
        const Vector2i& pos,
        bool returnNearest,
        Font* font,
        const Uint32& fontSize,
        const String& string,
        const Uint32& style,
        const Uint32& tabWidth = 4,
        const Float& outlineThickness = 0.f
    );

    static Vector2f findCharacterPos(
        std::size_t index,
        Font* font,
        const Uint32& fontSize,
        const String& string,
        const Uint32& style,
        const Uint32& tabWidth = 4,
        const Float& outlineThickness = 0.f
    );

    static Text* New();
    static Text* New(const String& string, Font* font, unsigned int characterSize = 12);
    static Text* New(Font* font, unsigned int characterSize = 12);
    void create(Graphics::Font* font, const String& text = "", Color FontColor = Color(255, 255, 255, 255), Color FontShadowColor = Color(0, 0, 0, 255), Uint32 characterSize = 12);
    void setString(const String& string);
    void setFont(Font* font);
    void setFontSize(unsigned int size);
    void setStyle(Uint32 style);
    void setColor(const Color& color);
    void setFillColor(const Color& color);
    void setFillColor(const Color& color, Uint32 from, Uint32 to);
    void setOutlineColor(const Color& color);
    void setOutlineThickness(Float thickness);
    void transformText(const TextTransform::Value& transform);
    String& getString();
    Font* getFont() const;
    unsigned int getCharacterSize() const;
    unsigned int getCharacterSizePx() const;
    const Uint32& getFontHeight() const;
    Uint32 getStyle() const;
    void setAlpha(const Uint8& alpha);
    const Color& getFillColor() const;
    const Color& getColor() const;
    const Color& getOutlineColor() const;
    Float getOutlineThickness() const;
    Vector2f findCharacterPos(std::size_t index) const;
    Rectf getLocalBounds();
    Float getTextWidth();
    Float getTextHeight();
    Float getLineSpacing();

    void draw(
        const Float& X,
        const Float& Y,
        const Vector2f& scale = Vector2f::One,
        const Float& rotation = 0,
        BlendMode effect = BlendMode::Alpha(),
        const OriginPoint& rotationCenter = OriginPoint::OriginCenter,
        const OriginPoint& scaleCenter = OriginPoint::OriginCenter
    );

    const Color& getShadowColor() const;
    void setShadowColor(const Color& color);
    const std::vector<Float>& getLinesWidth();
    void setAlign(const Uint32& align);
    const Uint32& getAlign() const;
    const int& getNumLines();
    void setStyleConfig(const FontStyleConfig& styleConfig);
    Int32 findCharacterFromPos(const Vector2i& pos, bool returnNearest = true) const;
    void findWordFromCharacterIndex(Int32 characterIndex, Int32& initCur, Int32& endCur) const;
    void wrapText(const Uint32& maxWidth);
    void invalidateColors();
    void invalidate();
    void setTabWidth(const Uint32& tabWidth);
    const Uint32& getTabWidth() const;
    Color getBackgroundColor() const;
    void setBackgroundColor(const Color& backgroundColor);
    bool getDisableCacheWidth() const;
    void setDisableCacheWidth(bool newDisableCacheWidth);
    const Vector2f& getShadowOffset() const;
    void setShadowOffset(const Vector2f& shadowOffset);
};

Detailed Documentation

Methods

void create(Graphics::Font* font, const String& text = "", Color FontColor = Color(255, 255, 255, 255), Color FontShadowColor = Color(0, 0, 0, 255), Uint32 characterSize = 12)

Create a text from a font

void setAlpha(const Uint8& alpha)

See also:

Set the alpha of each individual character. This doesn’t break any custom color per-character setted.

Rectf getLocalBounds()

Returns:

The current text local bounds.

Float getTextWidth()

Returns:

The cached text width

Float getTextHeight()

Returns:

The cached text height

Float getLineSpacing()

Returns:

The line espacing

void draw(
    const Float& X,
    const Float& Y,
    const Vector2f& scale = Vector2f::One,
    const Float& rotation = 0,
    BlendMode effect = BlendMode::Alpha(),
    const OriginPoint& rotationCenter = OriginPoint::OriginCenter,
    const OriginPoint& scaleCenter = OriginPoint::OriginCenter
)

Draw the cached text on screen

const Color& getShadowColor() const

Returns:

The Shadow Font Color

void setShadowColor(const Color& color)

Set the shadow color of the string rendered

const std::vector<Float>& getLinesWidth()

Returns:

Every cached text line width

void setAlign(const Uint32& align)

Set the text draw align

const Uint32& getAlign() const

Returns:

The text align

const int& getNumLines()

Returns:

The number of lines that the cached text contains

Int32 findCharacterFromPos(const Vector2i& pos, bool returnNearest = true) const

Finds the closest cursor position to the point position

void findWordFromCharacterIndex(Int32 characterIndex, Int32& initCur, Int32& endCur) const

Simulates a selection request and return the initial and end cursor position when the selection worked. Otherwise both parameters will be -1.

void wrapText(const Uint32& maxWidth)

Shrink the String to a max width

Parameters:

MaxWidth

The maximum possible width

void invalidateColors()

Invalidates the color cache

void invalidate()

Invalidates the text cache

void setTabWidth(const Uint32& tabWidth)

Sets the tab character width.

const Uint32& getTabWidth() const

Returns:

The tab character width

Color getBackgroundColor() const

Returns:

The text background color

void setBackgroundColor(const Color& backgroundColor)

Sets text background color.

bool getDisableCacheWidth() const

Returns:

True if the text width cache is disabled.

void setDisableCacheWidth(bool newDisableCacheWidth)

The text width is cached every time the geometry of the text is updated. It’s possible to disable this to improve performance in very specific scenarios.