16#include <SDL3_ttf/SDL_ttf.h>
44 bool isReady()
const override {
return _font && _font->isReady(); }
46 void setText(
const std::string text)
override { _text = text; _dirty =
true; }
47 std::string
getText()
const override {
return _text; }
50 _font =
static_cast<SdlFont *
>(font);
54 void setFontSize(
unsigned int size)
override { _size = size; _dirty =
true; }
71 SDL_Texture *handle(SDL_Renderer *renderer)
const {
72 if (!renderer || !_font || !_font->
isReady())
74 if (_texture && !_dirty && _owner == renderer)
79 const SDL_Color color{_color.
r, _color.
g, _color.
b, _color.
a};
86 SDL_Surface *surface = TTF_RenderText_Blended_Wrapped(_font->handle(_size), _text.c_str(), _text.size(), color, 0);
90 _texture = SDL_CreateTextureFromSurface(renderer, surface);
93 SDL_DestroySurface(surface);
102 SDL_DestroyTexture(_texture);
108 SdlFont *_font =
nullptr;
110 Color _color{255, 255, 255, 255};
112 float _rotation = 0.f;
117 mutable SDL_Texture *_texture =
nullptr;
118 mutable SDL_Renderer *_owner =
nullptr;
119 mutable bool _dirty =
true;
120 mutable int _width = 0;
121 mutable int _height = 0;
Une police ouverte a une taille donnee.
Definition SdlFont.hpp:32
bool isReady() const override
notice if the font is ready
Definition SdlFont.hpp:46
Une chaine rendue en texture, refaite quand elle change.
Definition SdlText.hpp:37
void setRotation(float angle) override
Set the Rotation object.
Definition SdlText.hpp:64
void setText(const std::string text) override
Set the Text value.
Definition SdlText.hpp:46
float getRotation() const override
Get the Rotation object.
Definition SdlText.hpp:65
Vector2f getPosition() const override
Get the Position text.
Definition SdlText.hpp:61
void setFont(graphic::IFont *font) override
Set the Font value - a loaded IFont, not a path, so changing font never implies a reload from disk.
Definition SdlText.hpp:49
Color getTextColor() const override
Get the Text Color text.
Definition SdlText.hpp:58
SdlText(std::string data, SdlFont &font)
Definition SdlText.hpp:40
void setTextColor(Color color) override
Set the Text Color text.
Definition SdlText.hpp:57
~SdlText() override
Definition SdlText.hpp:42
void setPosition(Vector2f position) override
Set the Position text.
Definition SdlText.hpp:60
std::string getText() const override
Get the Text value.
Definition SdlText.hpp:47
bool isReady() const override
Definition SdlText.hpp:44
void setFontSize(unsigned int size) override
Set the Font Size text.
Definition SdlText.hpp:54
unsigned int getFontSize() const override
Get the Font Size text.
Definition SdlText.hpp:55
Une fenetre SDL et son renderer, implemente IWindow2.
Definition SdlWindow.hpp:50
Loaded font data, independent of any IText that references it. Deleting every IText built with a font...
Definition IFont.hpp:22
Text interface.
Definition IText.hpp:26
Vector2< double > Vector2f
Definition Vector2.hpp:112
std::uint8_t g
Definition Color.hpp:18
std::uint8_t a
Definition Color.hpp:20
std::uint8_t b
Definition Color.hpp:19
std::uint8_t r
Definition Color.hpp:17