TGUI  1.3-dev
Loading...
Searching...
No Matches
BackendText.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2024 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
31#include <TGUI/Backend/Font/BackendFont.hpp>
32#include <TGUI/Backend/Renderer/BackendTexture.hpp>
33
35
36TGUI_MODULE_EXPORT namespace tgui
37{
41 class TGUI_API BackendText
42 {
43 public:
44
46 using TextVertexData = std::vector<std::pair<std::shared_ptr<BackendTexture>, std::shared_ptr<std::vector<Vertex>>>>;
47
48 // Don't allow copying or moving, because we don't expect derived classes to handle it correctly
49 BackendText(const BackendText&) = delete;
50 BackendText(BackendText&&) = delete;
51 BackendText& operator=(const BackendText&) = delete;
52 BackendText& operator=(BackendText&&) = delete;
53
57 BackendText() = default;
58
62 virtual ~BackendText() = default;
63
68 TGUI_NODISCARD virtual Vector2f getSize();
69
74 virtual void setString(const String& string);
75
80 TGUI_NODISCARD const String& getString() const;
81
86 virtual void setCharacterSize(unsigned int characterSize);
87
92 TGUI_NODISCARD unsigned int getCharacterSize() const;
93
98 virtual void setFillColor(const Color& color);
99
104 TGUI_NODISCARD Color getFillColor() const;
105
110 virtual void setOutlineColor(const Color& color);
111
116 TGUI_NODISCARD Color getOutlineColor() const;
117
122 virtual void setOutlineThickness(float thickness);
123
128 TGUI_NODISCARD float getOutlineThickness() const;
129
134 virtual void setStyle(TextStyles style);
135
140 TGUI_NODISCARD TextStyles getStyle() const;
141
146 virtual void setFont(const std::shared_ptr<BackendFont>& font);
147
152 TGUI_NODISCARD std::shared_ptr<BackendFont> getFont() const;
153
158 TGUI_NODISCARD virtual Vector2f findCharacterPos(std::size_t index) const;
159
165
167 protected:
168
170 // Recreates all vertices if required
172 void updateVertices();
173
175 // Helper function used by updateVertices to add vertices for a glyph
177 void addGlyphQuad(std::vector<Vertex>& vertices, Vector2f position, const Vertex::Color& color,
178 const FontGlyph& glyph, float fontScale, float italicShear);
179
181 // Helper function used by updateVertices to add vertices for a line
183 void addLine(std::vector<Vertex>& vertices, float lineLength, float lineTop, const Vertex::Color& color,
184 float offset, float thickness, float outlineThickness, float fontScale);
185
187 protected:
188
189 std::shared_ptr<BackendFont> m_font;
190 unsigned int m_lastFontTextureVersion = 0;
191
192 String m_string;
193 unsigned int m_characterSize = getGlobalTextSize();
194 Color m_fillColor;
195 Color m_outlineColor;
196 float m_outlineThickness = 0;
197 TextStyles m_style = TextStyle::Regular;
198
199 Vector2f m_size;
200 std::shared_ptr<std::vector<Vertex>> m_vertices;
201 std::shared_ptr<std::vector<Vertex>> m_outlineVertices;
202 bool m_verticesNeedUpdate = true;
203 };
204}
205
207
208#endif // TGUI_BACKEND_TEXT_HPP
Base class for text implementations that depend on the backend.
Definition BackendText.hpp:42
TGUI_NODISCARD float getOutlineThickness() const
Returns the text outline thickness.
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.
TGUI_NODISCARD Color getOutlineColor() const
Returns the text outline color.
virtual void setStyle(TextStyles style)
Changes the text style.
virtual void setCharacterSize(unsigned int characterSize)
Sets the size of the characters.
TGUI_NODISCARD unsigned int getCharacterSize() const
Returns the character size of the text.
TGUI_NODISCARD std::shared_ptr< BackendFont > getFont() const
Returns the font of the text.
virtual TGUI_NODISCARD Vector2f findCharacterPos(std::size_t index) const
Returns the top-left position of the character at the provided index.
TGUI_NODISCARD Color getFillColor() const
Returns the text fill color.
virtual void setString(const String &string)
Changes the text.
virtual void setOutlineColor(const Color &color)
Changes the color of the text outline.
TGUI_NODISCARD TextVertexData getVertexData()
Returns the information that is needed to render this text.
BackendText()=default
Default constructor.
virtual void setFillColor(const Color &color)
Changes the color of the text.
virtual TGUI_NODISCARD Vector2f getSize()
Returns the size 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:46
virtual ~BackendText()=default
Virtual destructor.
TGUI_NODISCARD const String & getString() const
Returns the text.
TGUI_NODISCARD TextStyles getStyle() const
Returns the style of the text.
Wrapper for colors.
Definition Color.hpp:72
Wrapper class to store strings.
Definition String.hpp:101
Wrapper for text styles.
Definition TextStyle.hpp:57
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:39
TGUI_NODISCARD 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:50
Definition Vertex.hpp:42