Gamedev Framework (gf)  0.9.0
A C++14 framework for 2D games
Text.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_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 
92  class GF_API Text : public Transformable {
93  public:
99  Text();
100 
108  Text(std::string string, Font& font, unsigned characterSize = 30);
109 
120  void setString(std::string string);
121 
131  const std::string& getString() const {
132  return m_basic.getString();
133  }
134 
144  void setCharacterSize(unsigned characterSize);
145 
153  unsigned getCharacterSize() const {
154  return m_basic.getCharacterSize();
155  }
156 
171  void setFont(Font& font);
172 
184  const Font *getFont() const {
185  return m_basic.getFont();
186  }
187 
199  void setColor(const Color4f& color);
200 
208  const Color4f& getColor() const {
209  return m_color;
210  }
211 
221  void setOutlineColor(const Color4f& color);
222 
230  const Color4f& getOutlineColor() const {
231  return m_outlineColor;
232  }
233 
243  void setOutlineThickness(float thickness);
244 
253  return m_basic.getOutlineThickness();
254  }
255 
264  void setParagraphWidth(float paragraphWidth);
265 
272  float getParagraphWidth() const {
273  return m_basic.getParagraphWidth();
274  }
275 
284  void setAlignment(Alignment align);
285 
293  return m_basic.getAlignment();
294  }
295 
308  return m_basic.getLocalBounds();
309  }
310 
321  void setAnchor(Anchor anchor);
322 
331  VertexBuffer commitGeometry() const;
332 
341  VertexBuffer commitOutlineGeometry() const;
342 
343  virtual void draw(RenderTarget& target, RenderStates states) override;
344 
345  private:
346  void updateGeometry();
347 
348  private:
349  BasicText m_basic;
350 
351  Color4f m_color;
352  VertexArray m_vertices;
353 
354  Color4f m_outlineColor;
355  VertexArray m_outlineVertices;
356  };
357 
358 #ifndef DOXYGEN_SHOULD_SKIP_THIS
359 }
360 #endif
361 }
362 
363 #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:252
A set of primitives.
Definition: VertexArray.h:65
Base class for all render targets (window, texture, ...)
Definition: RenderTarget.h:66
Define the states used for drawing to a RenderTarget.
Definition: RenderStates.h:82
unsigned getCharacterSize() const
Get the character size.
Definition: Text.h:153
float getParagraphWidth() const
Get the paragraph width.
Definition: Text.h:272
Definition: BasicText.h:47
Data in the graphics memory.
Definition: VertexBuffer.h:70
RectF getLocalBounds() const
Get the local bounding rectangle of the entity.
Definition: Text.h:307
Graphical text that can be drawn to a render target.
Definition: Text.h:92
The namespace for gf classes.
Definition: Action.h:34
Alignment getAlignment() const
Get the alignment of the text.
Definition: Text.h:292
const Color4f & getOutlineColor() const
Get the outline color of the text.
Definition: Text.h:230
A character font.
Definition: Font.h:130
Anchor
An anchor of a box.
Definition: Anchor.h:38
const std::string & getString() const
Get the text&#39;s string.
Definition: Text.h:131
Alignment
The alignement of a text.
Definition: Alignment.h:33
const Color4f & getColor() const
Get the fill color of the text.
Definition: Text.h:208
const Font * getFont() const
Get the text&#39;s font.
Definition: Text.h:184