TGUI 1.13
Loading...
Searching...
No Matches
BackendText.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2026 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#ifndef TGUI_BACKEND_TEXT_HPP
26#define TGUI_BACKEND_TEXT_HPP
27
28#include <TGUI/Backend/Font/BackendFont.hpp>
29#include <TGUI/Backend/Renderer/BackendTexture.hpp>
30
31#include <TGUI/Text.hpp>
32
34
35namespace tgui
36{
40 class TGUI_API BackendText
41 {
42 public:
44 using TextVertexData = std::vector<std::pair<std::shared_ptr<BackendTexture>, std::shared_ptr<std::vector<Vertex>>>>;
45
46 // Don't allow copying or moving, because we don't expect derived classes to handle it correctly
47 BackendText(const BackendText&) = delete;
48 BackendText(BackendText&&) = delete;
49 BackendText& operator=(const BackendText&) = delete;
50 BackendText& operator=(BackendText&&) = delete;
51
55 BackendText() = default;
56
60 virtual ~BackendText() = default;
61
66 [[nodiscard]] virtual Vector2f getSize();
67
72 virtual void setString(const String& string);
73
78 [[nodiscard]] const String& getString() const;
79
84 virtual void setCharacterSize(unsigned int characterSize);
85
90 [[nodiscard]] unsigned int getCharacterSize() const;
91
96 virtual void setFillColor(const Color& color);
97
102 [[nodiscard]] Color getFillColor() const;
103
108 virtual void setOutlineColor(const Color& color);
109
114 [[nodiscard]] Color getOutlineColor() const;
115
120 virtual void setOutlineThickness(float thickness);
121
126 [[nodiscard]] float getOutlineThickness() const;
127
132 virtual void setStyle(TextStyles style);
133
138 [[nodiscard]] TextStyles getStyle() const;
139
144 virtual void setFont(const std::shared_ptr<BackendFont>& font);
145
150 [[nodiscard]] std::shared_ptr<BackendFont> getFont() const;
151
156 [[nodiscard]] virtual Vector2f findCharacterPos(std::size_t index) const;
157
164 [[nodiscard]] TextVertexData getVertexData(bool includeOutline = true, bool includeText = true);
165
167
168 protected:
170 // Recreates all vertices if required
172 void updateVertices();
173
175 // Helper function used by updateVertices to add vertices for a glyph
177 static void addGlyphQuad(std::vector<Vertex>& vertices,
178 Vector2f position,
179 const Vertex::Color& color,
180 const FontGlyph& glyph,
181 float fontScale,
182 float italicShear);
183
185 // Helper function used by updateVertices to add vertices for a line
187 static void addLine(std::vector<Vertex>& vertices,
188 float lineLength,
189 float lineTop,
190 const Vertex::Color& color,
191 float offset,
192 float thickness,
193 float outlineThickness,
194 float fontScale);
195
197
198 protected:
199 std::shared_ptr<BackendFont> m_font;
200 unsigned int m_lastFontTextureVersion = 0;
201
202 String m_string;
203 unsigned int m_characterSize = getGlobalTextSize();
204 Color m_fillColor;
205 Color m_outlineColor;
206 float m_outlineThickness = 0;
208
209 Vector2f m_size;
210 std::shared_ptr<std::vector<Vertex>> m_vertices;
211 std::shared_ptr<std::vector<Vertex>> m_outlineVertices;
212 bool m_verticesNeedUpdate = true;
213 };
214} // namespace tgui
215
216#endif // TGUI_BACKEND_TEXT_HPP
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.
BackendText()=default
Default constructor.
TextVertexData getVertexData(bool includeOutline=true, bool includeText=true)
Returns the information that is needed to render this text.
virtual void setFillColor(const Color &color)
Changes the color of the text.
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:44
unsigned int getCharacterSize() const
Returns the character size of the text.
const String & getString() const
Returns the text.
virtual ~BackendText()=default
Virtual destructor.
TextStyles getStyle() const
Returns the style of the text.
Wrapper for colors.
Definition Color.hpp:63
Wrapper class to store strings.
Definition String.hpp:94
Wrapper for text styles.
Definition TextStyle.hpp:55
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:37
@ Regular
Regular characters, no style.
Definition TextStyle.hpp:39
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:44
Definition Vertex.hpp:39