Neo  0.5.0
Developer Documentation
Label.h
Go to the documentation of this file.
1 /*
2  * Copyright 2014 (C) Yannick Pflanzer <neo-engine.de>
3  *
4  * This file is part of Neo2D.
5  *
6  * Neo2D is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Neo2D is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with Neo2D. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * Diese Datei ist Teil von Neo2D.
20  *
21  * Neo2D ist Freie Software: Sie können es unter den Bedingungen
22  * der GNU Lesser General Public License, wie von der Free Software Foundation,
23  * Version 3 der Lizenz oder (nach Ihrer Wahl) jeder späteren
24  * veröffentlichten Version, weiterverbreiten und/oder modifizieren.
25  *
26  * Neo2D wird in der Hoffnung, dass es nützlich sein wird, aber
27  * OHNE JEDE GEWÄHRLEISTUNG, bereitgestellt; sogar ohne die implizite
28  * Gewährleistung der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK.
29  * Siehe die GNU Lesser General Public License für weitere Details.
30  *
31  * Sie sollten eine Kopie der GNU Lesser General Public License zusammen mit
32  *diesem
33  * Programm erhalten haben. Wenn nicht, siehe <http://www.gnu.org/licenses/>.
34  */
35 
36 #ifndef __LABEL_H__
37 #define __LABEL_H__
38 
39 #include <string>
40 #include <NeoEngine.h>
41 #include <Widget.h>
42 
43 namespace Neo2D
44 {
45 namespace Gui
46 {
47 
48 using namespace Neo;
49 
55 class NEO2D_EXPORT Label : public Widget
56 {
57 protected:
61 
63 
64 public:
65  Label(unsigned int x, unsigned int y, unsigned int width,
66  unsigned int height, const char* label)
67  : Widget(x, y, width, height, label), m_labelText(NULL),
68  m_alignment(TEXT_ALIGN_LEFT), m_font("assets/default.ttf"),
69  m_color(0,0,0,1)
70  {
71  }
72 
79  void setAlignment(int mode) { m_alignment = (Neo::TEXT_ALIGN_MODES) mode; }
80 
86  TEXT_ALIGN_MODES getAlignment() { return m_alignment; }
87 
95  void setFont(const char* file) { m_font = file; }
96 
102  const char* getFont() { return m_font.getSafeString(); }
103 
104  Vector4 getColor() { return m_color; }
105  void setColor(Vector4 color) { m_color = color; }
106 
107  void draw(Vector2 offset);
108  void draw() { draw(Vector2()); }
109  void update();
110 };
111 }
112 }
113 #endif
Definition: Vector4.h:31
OText * m_labelText
Definition: Label.h:58
Label(unsigned int x, unsigned int y, unsigned int width, unsigned int height, const char *label)
Definition: Label.h:65
void draw()
Draws the widget to the canvas it belongs to.
Definition: Label.h:108
void setAlignment(int mode)
Changes the text alignment.
Definition: Label.h:79
Definition: OText.h:40
TEXT_ALIGN_MODES m_alignment
Definition: Label.h:59
Implements a framework for string manipulation that operates directly on C strings.
Definition: NeoString.h:35
The Label class displays a string on the screen.
Definition: Label.h:55
The Widget class contains all information that is common to all GUI widgets.
Definition: Widget.h:72
void setFont(const char *file)
Changes the font used to display text.
Definition: Label.h:95
Definition: OText.h:34
TEXT_ALIGN_MODES
Definition: OText.h:32
String m_font
Definition: Label.h:60
Definition: Vector2.h:31
Definition: Button.h:42
const char * getSafeString(void)
Returns the C string. This method is ensured to return a valid C string and never NULL...
Vector4 getColor()
Definition: Label.h:104
void setColor(Vector4 color)
Definition: Label.h:105
const char * getFont()
Returns the path to the currently used font file.
Definition: Label.h:102
Definition: Color.h:29
Vector4 m_color
Definition: Label.h:62
TEXT_ALIGN_MODES getAlignment()
Returns the current align mode.
Definition: Label.h:86