TGUI  0.9-dev
BackendText.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2021 Bruno Van de Velde (vdv_b@tgui.eu)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25
26#ifndef TGUI_BACKEND_TEXT_HPP
27#define TGUI_BACKEND_TEXT_HPP
28
29#include <TGUI/Text.hpp>
30#include <TGUI/Backend/Font/BackendFont.hpp>
31#include <TGUI/Backend/Renderer/BackendTexture.hpp>
32
34
35namespace tgui
36{
40 class TGUI_API BackendText
41 {
42 public:
43
45 using TextVertexData = std::vector<std::pair<std::shared_ptr<BackendTexture>, std::shared_ptr<std::vector<Vertex>>>>;
46
47
51 virtual ~BackendText() = default;
52
53
58 virtual Vector2f getSize();
59
60
65 virtual void setString(const String& string);
66
67
72 const String& getString() const;
73
74
79 virtual void setCharacterSize(unsigned int characterSize);
80
81
86 unsigned int getCharacterSize() const;
87
88
93 virtual void setFillColor(const Color& color);
94
95
101
102
107 virtual void setOutlineColor(const Color& color);
108
109
115
116
121 virtual void setOutlineThickness(float thickness);
122
123
128 float getOutlineThickness() const;
129
130
135 virtual void setStyle(TextStyles style);
136
137
143
144
149 virtual void setFont(const std::shared_ptr<BackendFont>& font);
150
151
156 std::shared_ptr<BackendFont> getFont() const;
157
158
163 virtual Vector2f findCharacterPos(std::size_t index) const;
164
165
171
172
174 protected:
175
177 // Recreates all vertices if required
179 void updateVertices();
180
181
183 // Helper function used by updateVertices to add vertices for a glyph
185 void addGlyphQuad(std::vector<Vertex>& vertices, Vector2f position, const Vertex::Color& color, const FontGlyph& glyph, float italicShear, float outlineThickness);
186
187
189 // Helper function used by updateVertices to add vertices for a line
191 void addLine(std::vector<Vertex>& vertices, float lineLength, float lineTop, const Vertex::Color& color, float offset, float thickness, float outlineThickness);
192
193
195 protected:
196
197 std::shared_ptr<BackendFont> m_font;
198
199 String m_string;
200#ifdef TGUI_NEXT
201 unsigned int m_characterSize = getGlobalTextSize();
202#else
203 unsigned int m_characterSize = 32;
204#endif
205 Color m_fillColor;
206 Color m_outlineColor;
207 float m_outlineThickness = 0;
208 TextStyles m_style = TextStyle::Regular;
209
210 Vector2f m_size;
211 std::shared_ptr<std::vector<Vertex>> m_vertices;
212 std::shared_ptr<std::vector<Vertex>> m_outlineVertices;
213 bool m_verticesNeedUpdate = true;
214 };
215
216#ifndef TGUI_REMOVE_DEPRECATED_CODE
217 using BackendTextBase TGUI_DEPRECATED("BackendTextBase was renamed to BackendText") = BackendText;
218 using BackendTextSDL TGUI_DEPRECATED("BackendTextSDL was renamed to BackendText") = BackendText;
219#endif
220}
221
223
224#endif // TGUI_BACKEND_TEXT_HPP
Base class for text implementations that depend on the backend.
Definition: BackendText.hpp:41
std::shared_ptr< BackendFont > getFont() const
Returns the font of the text.
virtual void setFont(const std::shared_ptr< BackendFont > &font)
Changes the font used by the text.
virtual void setOutlineThickness(float thickness)
Changes the thickness of the text outline.
virtual void setStyle(TextStyles style)
Changes the text style.
Color getOutlineColor() const
Returns the text outline color.
virtual void setCharacterSize(unsigned int characterSize)
Sets the size of the characters.
Color getFillColor() const
Returns the text fill color.
float getOutlineThickness() const
Returns the text outline thickness.
virtual Vector2f findCharacterPos(std::size_t index) const
Returns the top-left position of the character at the provided index.
virtual void setString(const String &string)
Changes the text.
virtual void setOutlineColor(const Color &color)
Changes the color of the text outline.
virtual Vector2f getSize()
Returns the size of the text.
TextVertexData getVertexData()
Returns the information that is needed to render this text.
virtual void setFillColor(const Color &color)
Changes the color of the text.
unsigned int getCharacterSize() const
Returns the character size of the text.
const String & getString() const
Returns the text.
virtual ~BackendText()=default
Virtual destructor.
std::vector< std::pair< std::shared_ptr< BackendTexture >, std::shared_ptr< std::vector< Vertex > > > > TextVertexData
Type of the data that is passed to BackendRenderTarget where the actual rendering happens.
Definition: BackendText.hpp:45
TextStyles getStyle() const
Returns the style of the text.
Wrapper for colors.
Definition: Color.hpp:63
Wrapper class to store strings.
Definition: String.hpp:79
Wrapper for text styles.
Definition: TextStyle.hpp:58
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
TGUI_API unsigned int getGlobalTextSize()
Retrieves the default text size used for all new widgets.
Information about a glyph in the font.
Definition: Font.hpp:47
Definition: Vertex.hpp:39