forked from skyrpex/RichText
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRichText.hpp
101 lines (83 loc) · 3.81 KB
/
RichText.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#ifndef RICHTEXT_HPP
#define RICHTEXT_HPP
//////////////////////////////////////////////////////////////////////////
// Headers
//////////////////////////////////////////////////////////////////////////
#include <SFML/Graphics/Drawable.hpp>
#include <SFML/Graphics/Color.hpp>
#include <SFML/Graphics/Text.hpp>
#include <SFML/System/String.hpp>
#include <list>
namespace sfe
{
class RichText : public sf::Drawable, public sf::Transformable
{
public:
//////////////////////////////////////////////////////////////////////////
// Constructor
//////////////////////////////////////////////////////////////////////////
RichText();
//////////////////////////////////////////////////////////////////////////
// Operators
//////////////////////////////////////////////////////////////////////////
RichText & operator << (const sf::Color &color);
RichText & operator << (sf::Text::Style style);
RichText & operator << (const sf::String &string);
//////////////////////////////////////////////////////////////////////////
// Set character size
//////////////////////////////////////////////////////////////////////////
void setCharacterSize(unsigned int size);
//////////////////////////////////////////////////////////////////////////
// Set font
//////////////////////////////////////////////////////////////////////////
void setFont(const sf::Font &font);
//////////////////////////////////////////////////////////////////////////
// Clear
//////////////////////////////////////////////////////////////////////////
void clear();
//////////////////////////////////////////////////////////////////////////
// Get text list
//////////////////////////////////////////////////////////////////////////
const std::list<sf::Text> &getTextList() const;
//////////////////////////////////////////////////////////////////////////
// Get character size
//////////////////////////////////////////////////////////////////////////
unsigned int getCharacterSize() const;
//////////////////////////////////////////////////////////////////////////
// Get font
//////////////////////////////////////////////////////////////////////////
const sf::Font & getFont() const;
//////////////////////////////////////////////////////////////////////////
// Get width
//////////////////////////////////////////////////////////////////////////
float getWidth() const;
//////////////////////////////////////////////////////////////////////////
// Get height
//////////////////////////////////////////////////////////////////////////
float getHeight() const;
private:
//////////////////////////////////////////////////////////////////////////
// Update size
//////////////////////////////////////////////////////////////////////////
void updateSize() const;
//////////////////////////////////////////////////////////////////////////
// Update position
//////////////////////////////////////////////////////////////////////////
void updatePosition() const;
//////////////////////////////////////////////////////////////////////////
// Render
//////////////////////////////////////////////////////////////////////////
void draw(sf::RenderTarget& target, sf::RenderStates states) const;
//////////////////////////////////////////////////////////////////////////
// Member data
//////////////////////////////////////////////////////////////////////////
mutable std::list<sf::Text> myTexts; ///< List of texts
sf::Color myCurrentColor; ///< Last used color
sf::Text::Style myCurrentStyle; ///< Last style used
mutable sf::Vector2f mySize; ///< Size of the text
mutable bool mySizeUpdated; ///< Do we need to recompute the size?
mutable bool myPositionUpdated; ///< Do we need to recompute the
///< position?
};
}
#endif // RICHTEXT_HPP