hx3d  1
2D/3D Simple Game Framework
text.hpp
1 /*
2  GUI text.
3  Render text.
4 
5  Copyright (C) 2015 Denis BOURGE
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Lesser General Public
9  License as published by the Free Software Foundation; either
10  version 2.1 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public
18  License along with this library; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
20  USA
21 */
22 
23 #ifndef HX3D_GUI_TEXT
24 #define HX3D_GUI_TEXT
25 
26 #include "hx3d/gui/widget.hpp"
27 
28 #include "hx3d/graphics/font.hpp"
29 #include "hx3d/math/function.hpp"
30 
31 namespace hx3d {
32 namespace gui {
33 
37 class Text: public Widget {
38 
39 public:
40 
45  Text();
46 
52  Text(Ptr<Font> font);
53 
60  Text(Widget* parent, Ptr<Font> font);
61 
67  void setFont(Ptr<Font> font);
68 
74  void setCharacterSize(int size);
75 
81  void setCenterAlignment(bool value);
82 
88  void setContent(std::string content);
89 
96  void functionDraw(Ptr<Shader> shader, math::Function function);
97 
103  Ptr<Font> getFont();
104 
110  int getCharacterSize();
111 
117  float getLength();
118 
124  bool isCenterAligned();
125 
126  virtual void draw(Ptr<Shader> shader) override;
127 
128 protected:
129 
133  void init();
134 
138  float calculateLength();
139 
143  std::string _content;
145  float _length;
150 };
151 
152 } /* gui */
153 } /* hx3d */
154 
155 #endif
bool isCenterAligned()
Is the text center aligned ?
Definition: text.cpp:86
void init()
Initialize the text.
Definition: text.cpp:45
Base GUI element.
Definition: widget.hpp:39
void setCharacterSize(int size)
Set the character size.
Definition: text.cpp:60
void setCenterAlignment(bool value)
Set the center alignment.
Definition: text.cpp:82
bool _centerAligned
Is the text center aligned ?
Definition: text.hpp:149
Text()
Create a text without font. See setFont.
Definition: text.cpp:34
void setFont(Ptr< Font > font)
Set the font.
Definition: text.cpp:54
Text GUI element.
Definition: text.hpp:37
float _length
Text length.
Definition: text.hpp:145
hx3d framework namespace
Definition: audio.hpp:26
float calculateLength()
Calculate the text length.
Definition: text.cpp:138
int _characterSize
Character size.
Definition: text.hpp:147
std::string _content
Text content.
Definition: text.hpp:143
Ptr< Font > _font
Text font.
Definition: text.hpp:141
void setContent(std::string content)
Set the text content.
Definition: text.cpp:65
int getCharacterSize()
Get the character size.
Definition: text.cpp:74
Math function definition.
Definition: function.hpp:33
float getLength()
Get the text length.
Definition: text.cpp:78
std::shared_ptr< T > Ptr
Quick-typing shared ptr.
Definition: ptr.hpp:34
Ptr< Font > getFont()
Get the text font.
Definition: text.cpp:70
void functionDraw(Ptr< Shader > shader, math::Function function)
Draw the text following a function.
Definition: text.cpp:162