sfml_impl 0.1.0
Vendor SFML 3.0.2 : IGraphic2Module / IAudioModule
Loading...
Searching...
No Matches
SfmlText.hpp
Go to the documentation of this file.
1
11#ifndef SFMLTEXT_HPP_
12#define SFMLTEXT_HPP_
13
14//Sfml
15#include <SFML/Graphics.hpp>
16#include <SFML/System.hpp>
17
18//Interface
19#include "IText.hpp"
20
21//encapsulation
22#include "SfmlFont.hpp"
23
28class SfmlText : public graphic::IText {
29
30 public:
31 SfmlText(std::string data, SfmlFont &font) : _font(&font), _text(font.handle()) {
32 _text.setString(data);
33 }
34
35 ~SfmlText() override = default;
36
37 bool isReady() const override {
38 return _font->isReady();
39 }
40
41 void setText(const std::string text) override {
42 _text.setString(text);
43 }
44
45 std::string getText() const override {
46 return _text.getString();
47 }
48
49 void setFont(graphic::IFont *font) override {
50 _font = static_cast<SfmlFont *>(font);
51 _text.setFont(_font->handle());
52 }
53
54 void setFontSize(unsigned int size) override {
55 _text.setCharacterSize(size);
56 }
57 unsigned int getFontSize() const override {
58 return _text.getCharacterSize();
59 }
60
61 void setTextColor(Color color) override {
62 _text.setFillColor(sf::Color(color.r, color.g, color.b, color.a));
63 }
64
65 Color getTextColor() const override {
66 const sf::Color color = _text.getFillColor();
67 return Color{color.r, color.g, color.b, color.a};
68 }
69
70 void setPosition(Vector2f position) override {
71 _text.setPosition({static_cast<float>(position.x), static_cast<float>(position.y)});
72 }
73 Vector2f getPosition() const override {
74 const sf::Vector2f pos = _text.getPosition();
75 return Vector2f{static_cast<double>(pos.x), static_cast<double>(pos.y)};
76 }
77
78 void setRotation(float angle) override {
79 _text.setRotation(sf::degrees(angle));
80 }
81
82 float getRotation() const override {
83 return _text.getRotation().asDegrees();
84 }
85
86 friend class SfmlWindow;
87
88 private:
89 SfmlFont *_font;
90 sf::Text _text;
91};
92
95#endif /* !SFMLTEXT_HPP_ */
Sfml Font class - owns the loaded font. SfmlText only references it (sf::Text itself already takes a ...
Definition SfmlFont.hpp:27
bool isReady() const override
Definition SfmlFont.hpp:40
const sf::Font & handle() const
Definition SfmlFont.hpp:44
Sfml Text class - references a SfmlFont, does not own it. Deleting the text never touches the font.
Definition SfmlText.hpp:28
void setFontSize(unsigned int size) override
Definition SfmlText.hpp:54
void setRotation(float angle) override
Definition SfmlText.hpp:78
void setFont(graphic::IFont *font) override
Definition SfmlText.hpp:49
bool isReady() const override
Definition SfmlText.hpp:37
unsigned int getFontSize() const override
Definition SfmlText.hpp:57
void setTextColor(Color color) override
Definition SfmlText.hpp:61
void setText(const std::string text) override
Definition SfmlText.hpp:41
Vector2f getPosition() const override
Definition SfmlText.hpp:73
std::string getText() const override
Definition SfmlText.hpp:45
float getRotation() const override
Definition SfmlText.hpp:82
SfmlText(std::string data, SfmlFont &font)
Definition SfmlText.hpp:31
~SfmlText() override=default
void setPosition(Vector2f position) override
Definition SfmlText.hpp:70
Color getTextColor() const override
Definition SfmlText.hpp:65
Sfml Window class - implements IWindow2 only, sfml has no 3D.
Definition SfmlWindow.hpp:46