Gamedev Framework (gf)  0.17.0
A C++14 framework for 2D games
Text.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_TEXT_H
25 #define GF_TEXT_H
26 
27 #include <string>
28 
29 #include "Alignment.h"
30 #include "BasicText.h"
31 #include "Portability.h"
32 #include "Transformable.h"
33 #include "Vector.h"
34 #include "VertexArray.h"
35 #include "VertexBuffer.h"
36 
37 namespace gf {
38 #ifndef DOXYGEN_SHOULD_SKIP_THIS
39 inline namespace v1 {
40 #endif
41 
42  class Font;
43 
80  class GF_API Text : public Transformable {
81  public:
87  Text();
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 
326  void setAlignment(Alignment align);
327 
335  return m_basic.getAlignment();
336  }
337 
350  return m_basic.getLocalBounds();
351  }
352 
363  void setAnchor(Anchor anchor);
364 
373  VertexBuffer commitGeometry() const;
374 
383  VertexBuffer commitOutlineGeometry() const;
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
Decomposed transform defined by a position, a rotation and a scale.
Definition: Transformable.h:95
float getOutlineThickness()
Get the outline thickness of the text.
Definition: Text.h:240
float getLineSpacing() const
Get the size of the line spacing factor.
Definition: Text.h:265
float getLetterSpacing() const
Get the size of the letter spacing factor.
Definition: Text.h:294
A set of primitives.
Definition: VertexArray.h:65
Base class for all render targets (window, texture, ...)
Definition: RenderTarget.h:90
Define the states used for drawing to a RenderTarget.
Definition: RenderStates.h:82
unsigned getCharacterSize() const
Get the character size.
Definition: Text.h:141
float getParagraphWidth() const
Get the paragraph width.
Definition: Text.h:314
A basic text.
Definition: BasicText.h:50
Data in the graphics memory.
Definition: VertexBuffer.h:77
RectF getLocalBounds() const
Get the local bounding rectangle of the entity.
Definition: Text.h:349
Graphical text that can be drawn to a render target.
Definition: Text.h:80
The namespace for gf classes.
Definition: Action.h:35
Alignment getAlignment() const
Get the alignment of the text.
Definition: Text.h:334
const Color4f & getOutlineColor() const
Get the outline color of the text.
Definition: Text.h:218
A character font.
Definition: Font.h:109
A 4D vector.
Definition: Vector.h:852
Anchor
An anchor of a box.
Definition: Anchor.h:38
const std::string & getString() const
Get the text&#39;s string.
Definition: Text.h:119
Alignment
The alignement of a text.
Definition: Alignment.h:33
const Color4f & getColor() const
Get the fill color of the text.
Definition: Text.h:196
const Font * getFont() const
Get the text&#39;s font.
Definition: Text.h:172