Gamedev Framework (gf)  0.17.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 
50  class GF_API BasicText {
51  public:
57  BasicText();
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 
146  const AlphaTexture *getFontTexture();
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 
252  void setAlignment(Alignment align);
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
float getLetterSpacing() const
Get the size of the letter spacing factor.
Definition: BasicText.h:220
A set of primitives.
Definition: VertexArray.h:65
const std::string & getString() const
Get the text&#39;s string.
Definition: BasicText.h:89
A basic text.
Definition: BasicText.h:50
RectF getLocalBounds() const
Get the local bounding rectangle of the entity.
Definition: BasicText.h:275
float getLineSpacing() const
Get the size of the line spacing factor.
Definition: BasicText.h:191
float getOutlineThickness()
Get the outline thickness of the text.
Definition: BasicText.h:166
unsigned getCharacterSize() const
Get the character size.
Definition: BasicText.h:111
const Font * getFont() const
Get the text&#39;s font.
Definition: BasicText.h:142
Alignment getAlignment() const
Get the alignment of the text.
Definition: BasicText.h:260
The namespace for gf classes.
Definition: Action.h:35
A character font.
Definition: Font.h:109
Alignment
The alignement of a text.
Definition: Alignment.h:33
A texture with a single alpha channel.
Definition: Texture.h:391
float getParagraphWidth() const
Get the paragraph width.
Definition: BasicText.h:240