Gamedev Framework (gf) 1.2.0
A C++17 framework for 2D games
Text.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_TEXT_H
25#define GF_TEXT_H
26
27#include <string>
28
29#include "Alignment.h"
30#include "BasicText.h"
31#include "GraphicsApi.h"
32#include "Transformable.h"
33#include "Vector.h"
34#include "VertexArray.h"
35#include "VertexBuffer.h"
36
37namespace gf {
38#ifndef DOXYGEN_SHOULD_SKIP_THIS
39inline namespace v1 {
40#endif
41
42 class Font;
43
80 class GF_GRAPHICS_API Text : public Transformable {
81 public:
88
96 Text(std::string string, Font& font, unsigned characterSize = 30);
97
108 void setString(std::string string);
109
119 const std::string& getString() const {
120 return m_basic.getString();
121 }
122
132 void setCharacterSize(unsigned characterSize);
133
141 unsigned getCharacterSize() const {
142 return m_basic.getCharacterSize();
143 }
144
159 void setFont(Font& font);
160
172 const Font *getFont() const {
173 return m_basic.getFont();
174 }
175
187 void setColor(const Color4f& color);
188
196 const Color4f& getColor() const {
197 return m_color;
198 }
199
209 void setOutlineColor(const Color4f& color);
210
218 const Color4f& getOutlineColor() const {
219 return m_outlineColor;
220 }
221
231 void setOutlineThickness(float thickness);
232
241 return m_basic.getOutlineThickness();
242 }
243
256 void setLineSpacing(float spacingFactor);
257
265 float getLineSpacing() const {
266 return m_basic.getLineSpacing();
267 }
268
285 void setLetterSpacing(float spacingFactor);
286
294 float getLetterSpacing() const {
295 return m_basic.getLetterSpacing();
296 }
297
306 void setParagraphWidth(float paragraphWidth);
307
314 float getParagraphWidth() const {
315 return m_basic.getParagraphWidth();
316 }
317
327
335 return m_basic.getAlignment();
336 }
337
350 return m_basic.getLocalBounds();
351 }
352
363 void setAnchor(Anchor anchor);
364
374
384
385 virtual void draw(RenderTarget& target, const RenderStates& states) override;
386
387 private:
388 void updateGeometry();
389
390 private:
391 BasicText m_basic;
392
393 Color4f m_color;
394 VertexArray m_vertices;
395
396 Color4f m_outlineColor;
397 VertexArray m_outlineVertices;
398 };
399
400#ifndef DOXYGEN_SHOULD_SKIP_THIS
401}
402#endif
403}
404
405#endif // GF_TEXT_H
A basic text.
Definition: BasicText.h:50
A character font.
Definition: Font.h:109
Base class for all render targets (window, texture, ...)
Definition: RenderTarget.h:102
Graphical text that can be drawn to a render target.
Definition: Text.h:80
const Font * getFont() const
Get the text's font.
Definition: Text.h:172
float getLetterSpacing() const
Get the size of the letter spacing factor.
Definition: Text.h:294
void setOutlineColor(const Color4f &color)
Set the outline color of the text.
VertexBuffer commitOutlineGeometry() const
Create a buffer with the current outline geometry.
void setString(std::string string)
Set the text's string.
float getParagraphWidth() const
Get the paragraph width.
Definition: Text.h:314
RectF getLocalBounds() const
Get the local bounding rectangle of the entity.
Definition: Text.h:349
void setColor(const Color4f &color)
Set the fill color of the text.
void setLineSpacing(float spacingFactor)
Set the line spacing factor.
const Color4f & getColor() const
Get the fill color of the text.
Definition: Text.h:196
unsigned getCharacterSize() const
Get the character size.
Definition: Text.h:141
void setOutlineThickness(float thickness)
Set the thickness of the text's outline.
void setCharacterSize(unsigned characterSize)
Set the character size.
Text()
Default constructor.
VertexBuffer commitGeometry() const
Create a buffer with the current geometry.
void setFont(Font &font)
Set the text's font.
float getOutlineThickness()
Get the outline thickness of the text.
Definition: Text.h:240
void setAlignment(Alignment align)
Set the alignement of the text.
void setLetterSpacing(float spacingFactor)
Set the letter spacing factor.
virtual void draw(RenderTarget &target, const RenderStates &states) override
Draw the object to a render target.
void setParagraphWidth(float paragraphWidth)
Set the paragraph width for aligned text.
void setAnchor(Anchor anchor)
Set the anchor origin of the entity.
float getLineSpacing() const
Get the size of the line spacing factor.
Definition: Text.h:265
const std::string & getString() const
Get the text's string.
Definition: Text.h:119
const Color4f & getOutlineColor() const
Get the outline color of the text.
Definition: Text.h:218
Text(std::string string, Font &font, unsigned characterSize=30)
Construct the text from a string, font and size.
Alignment getAlignment() const
Get the alignment of the text.
Definition: Text.h:334
Decomposed transform defined by a position, a rotation and a scale.
Definition: Transformable.h:95
A set of primitives.
Definition: VertexArray.h:65
Data in the graphics memory.
Definition: VertexBuffer.h:81
Anchor
An anchor of a box.
Definition: Anchor.h:38
Alignment
The alignement of a text.
Definition: Alignment.h:33
The namespace for gf classes.
Define the states used for drawing to a RenderTarget.
Definition: RenderStates.h:82
A 4D vector.
Definition: Vector.h:852