Gamedev Framework (gf)  0.12.0
A C++14 framework for 2D games
BasicText.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2019 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 "Portability.h"
31 #include "Vector.h"
32 #include "VertexArray.h"
33 
34 namespace gf {
35 #ifndef DOXYGEN_SHOULD_SKIP_THIS
36 inline namespace v1 {
37 #endif
38 
39  class Font;
40  class AlphaTexture;
41 
47  class GF_API BasicText {
48  public:
54  BasicText();
55 
63  BasicText(std::string string, Font& font, unsigned characterSize = 30);
64 
75  void setString(std::string string);
76 
86  const std::string& getString() const {
87  return m_string;
88  }
89 
99  void setCharacterSize(unsigned characterSize);
100 
108  unsigned getCharacterSize() const {
109  return m_characterSize;
110  }
111 
126  void setFont(Font& font);
127 
139  const Font *getFont() const {
140  return m_font;
141  }
142 
143  const AlphaTexture *getFontTexture();
144 
154  void setOutlineThickness(float thickness);
155 
164  return m_outlineThickness;
165  }
166 
179  void setLineSpacing(float spacingFactor);
180 
188  float getLineSpacing() const {
189  return m_lineSpacingFactor;
190  }
191 
208  void setLetterSpacing(float spacingFactor);
209 
217  float getLetterSpacing() const {
218  return m_letterSpacingFactor;
219  }
220 
229  void setParagraphWidth(float paragraphWidth);
230 
237  float getParagraphWidth() const {
238  return m_paragraphWidth;
239  }
240 
249  void setAlignment(Alignment align);
250 
258  return m_align;
259  }
260 
273  return m_bounds;
274  }
275 
276  void updateGeometry(VertexArray& vertices, VertexArray& outlineVertices);
277 
278  private:
279  std::string m_string;
280  Font *m_font;
281 
282  unsigned m_characterSize;
283  float m_outlineThickness;
284  float m_lineSpacingFactor;
285  float m_letterSpacingFactor;
286 
287  float m_paragraphWidth;
288  Alignment m_align;
289 
290  RectF m_bounds;
291  };
292 
293 #ifndef DOXYGEN_SHOULD_SKIP_THIS
294 }
295 #endif
296 }
297 
298 #endif // GF_BASIC_TEXT_H
float getLetterSpacing() const
Get the size of the letter spacing factor.
Definition: BasicText.h:217
A set of primitives.
Definition: VertexArray.h:65
const std::string & getString() const
Get the text&#39;s string.
Definition: BasicText.h:86
Definition: BasicText.h:47
RectF getLocalBounds() const
Get the local bounding rectangle of the entity.
Definition: BasicText.h:272
float getLineSpacing() const
Get the size of the line spacing factor.
Definition: BasicText.h:188
float getOutlineThickness()
Get the outline thickness of the text.
Definition: BasicText.h:163
unsigned getCharacterSize() const
Get the character size.
Definition: BasicText.h:108
const Font * getFont() const
Get the text&#39;s font.
Definition: BasicText.h:139
Alignment getAlignment() const
Get the alignment of the text.
Definition: BasicText.h:257
The namespace for gf classes.
Definition: Action.h:35
A character font.
Definition: Font.h:130
Alignment
The alignement of a text.
Definition: Alignment.h:33
A texture with a single alpha channel.
Definition: Texture.h:474
float getParagraphWidth() const
Get the paragraph width.
Definition: BasicText.h:237