Gamedev Framework (gf) 1.2.0
A C++17 framework for 2D games
BasicText.h
1/*
2 * Gamedev Framework (gf)
3 * Copyright (C) 2016-2022 Julien Bernard
4 *
5 * This software is provided 'as-is', without any express or implied
6 * warranty. In no event will the authors be held liable for any damages
7 * 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
11 * freely, subject to the following restrictions:
12 *
13 * 1. The origin of this software must not be misrepresented; you must not
14 * claim that you wrote the original software. If you use this software
15 * in a product, an acknowledgment in the product documentation would be
16 * appreciated but is not required.
17 * 2. Altered source versions must be plainly marked as such, and must not be
18 * misrepresented as being the original software.
19 * 3. This notice may not be removed or altered from any source distribution.
20 *
21 * Part of this file comes from SFML, with the same license:
22 * Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
23 */
24#ifndef GF_BASIC_TEXT_H
25#define GF_BASIC_TEXT_H
26
27#include <string>
28
29#include "Alignment.h"
30#include "GraphicsApi.h"
31#include "Vector.h"
32#include "VertexArray.h"
33
34namespace gf {
35#ifndef DOXYGEN_SHOULD_SKIP_THIS
36inline namespace v1 {
37#endif
38
39 class Font;
40 class AlphaTexture;
41
50 class GF_GRAPHICS_API BasicText {
51 public:
58
66 BasicText(std::string string, Font& font, unsigned characterSize = 30);
67
78 void setString(std::string string);
79
89 const std::string& getString() const {
90 return m_string;
91 }
92
102 void setCharacterSize(unsigned characterSize);
103
111 unsigned getCharacterSize() const {
112 return m_characterSize;
113 }
114
129 void setFont(Font& font);
130
142 const Font *getFont() const {
143 return m_font;
144 }
145
147
157 void setOutlineThickness(float thickness);
158
167 return m_outlineThickness;
168 }
169
182 void setLineSpacing(float spacingFactor);
183
191 float getLineSpacing() const {
192 return m_lineSpacingFactor;
193 }
194
211 void setLetterSpacing(float spacingFactor);
212
220 float getLetterSpacing() const {
221 return m_letterSpacingFactor;
222 }
223
232 void setParagraphWidth(float paragraphWidth);
233
240 float getParagraphWidth() const {
241 return m_paragraphWidth;
242 }
243
253
261 return m_align;
262 }
263
276 return m_bounds;
277 }
278
279 void updateGeometry(VertexArray& vertices, VertexArray& outlineVertices);
280
281 private:
282 std::string m_string;
283 Font *m_font;
284
285 unsigned m_characterSize;
286 float m_outlineThickness;
287 float m_lineSpacingFactor;
288 float m_letterSpacingFactor;
289
290 float m_paragraphWidth;
291 Alignment m_align;
292
293 RectF m_bounds;
294 };
295
296#ifndef DOXYGEN_SHOULD_SKIP_THIS
297}
298#endif
299}
300
301#endif // GF_BASIC_TEXT_H
A texture with a single alpha channel.
Definition: Texture.h:427
A basic text.
Definition: BasicText.h:50
float getLineSpacing() const
Get the size of the line spacing factor.
Definition: BasicText.h:191
void setCharacterSize(unsigned characterSize)
Set the character size.
void setString(std::string string)
Set the text's string.
BasicText(std::string string, Font &font, unsigned characterSize=30)
Construct the text from a string, font and size.
void setAlignment(Alignment align)
Set the alignement of the text.
void setParagraphWidth(float paragraphWidth)
Set the paragraph width for aligned text.
void setOutlineThickness(float thickness)
Set the thickness of the text's outline.
void setFont(Font &font)
Set the text's font.
Alignment getAlignment() const
Get the alignment of the text.
Definition: BasicText.h:260
const std::string & getString() const
Get the text's string.
Definition: BasicText.h:89
void updateGeometry(VertexArray &vertices, VertexArray &outlineVertices)
RectF getLocalBounds() const
Get the local bounding rectangle of the entity.
Definition: BasicText.h:275
float getParagraphWidth() const
Get the paragraph width.
Definition: BasicText.h:240
void setLineSpacing(float spacingFactor)
Set the line spacing factor.
BasicText()
Default constructor.
float getOutlineThickness()
Get the outline thickness of the text.
Definition: BasicText.h:166
void setLetterSpacing(float spacingFactor)
Set the letter spacing factor.
const Font * getFont() const
Get the text's font.
Definition: BasicText.h:142
float getLetterSpacing() const
Get the size of the letter spacing factor.
Definition: BasicText.h:220
unsigned getCharacterSize() const
Get the character size.
Definition: BasicText.h:111
const AlphaTexture * getFontTexture()
A character font.
Definition: Font.h:109
A set of primitives.
Definition: VertexArray.h:65
Alignment
The alignement of a text.
Definition: Alignment.h:33
The namespace for gf classes.