Gamedev Framework (gf)  0.10.0
A C++14 framework for 2D games
BasicText.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2018 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 
175  void setParagraphWidth(float paragraphWidth);
176 
183  float getParagraphWidth() const {
184  return m_paragraphWidth;
185  }
186 
195  void setAlignment(Alignment align);
196 
204  return m_align;
205  }
206 
219  return m_bounds;
220  }
221 
222  void updateGeometry(VertexArray& vertices, VertexArray& outlineVertices);
223 
224  private:
225  std::string m_string;
226  Font *m_font;
227 
228  unsigned m_characterSize;
229  float m_outlineThickness;
230 
231  float m_paragraphWidth;
232  Alignment m_align;
233 
234  RectF m_bounds;
235  };
236 
237 #ifndef DOXYGEN_SHOULD_SKIP_THIS
238 }
239 #endif
240 }
241 
242 #endif // GF_BASIC_TEXT_H
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:218
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:203
The namespace for gf classes.
Definition: Action.h:34
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:183