Gamedev Framework (gf)  0.11.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 
268  void setLineSpacing(float spacingFactor);
269 
277  float getLineSpacing() const {
278  return m_basic.getLineSpacing();
279  }
280 
297  void setLetterSpacing(float spacingFactor);
298 
306  float getLetterSpacing() const {
307  return m_basic.getLetterSpacing();
308  }
309 
318  void setParagraphWidth(float paragraphWidth);
319 
326  float getParagraphWidth() const {
327  return m_basic.getParagraphWidth();
328  }
329 
338  void setAlignment(Alignment align);
339 
347  return m_basic.getAlignment();
348  }
349 
362  return m_basic.getLocalBounds();
363  }
364 
375  void setAnchor(Anchor anchor);
376 
385  VertexBuffer commitGeometry() const;
386 
395  VertexBuffer commitOutlineGeometry() const;
396 
397  virtual void draw(RenderTarget& target, const RenderStates& states) override;
398 
399  private:
400  void updateGeometry();
401 
402  private:
403  BasicText m_basic;
404 
405  Color4f m_color;
406  VertexArray m_vertices;
407 
408  Color4f m_outlineColor;
409  VertexArray m_outlineVertices;
410  };
411 
412 #ifndef DOXYGEN_SHOULD_SKIP_THIS
413 }
414 #endif
415 }
416 
417 #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
float getLineSpacing() const
Get the size of the line spacing factor.
Definition: Text.h:277
float getLetterSpacing() const
Get the size of the letter spacing factor.
Definition: Text.h:306
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:326
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:361
Graphical text that can be drawn to a render target.
Definition: Text.h:92
The namespace for gf classes.
Definition: Action.h:35
Alignment getAlignment() const
Get the alignment of the text.
Definition: Text.h:346
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