1 /*
2 Copyright © 2011-2012 Clint Bellanger
3 Copyright © 2013 Kurt Rinnert
4 Copyright © 2014 Henrik Andersson
5 Copyright © 2012-2016 Justin Jacobs
6 
7 This file is part of FLARE.
8 
9 FLARE is free software: you can redistribute it and/or modify it under the terms
10 of the GNU General Public License as published by the Free Software Foundation,
11 either version 3 of the License, or (at your option) any later version.
12 
13 FLARE is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15 PARTICULAR PURPOSE.  See the GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License along with
18 FLARE.  If not, see http://www.gnu.org/licenses/
19 */
20 
21 /**
22  * class WidgetLabel
23  *
24  * A simple text display for menus.
25  * This is preferred to directly displaying text because it helps handle positioning
26  */
27 
28 #ifndef WIDGET_LABEL_H
29 #define WIDGET_LABEL_H
30 
31 #include "CommonIncludes.h"
32 #include "Utils.h"
33 #include "Widget.h"
34 
35 class LabelInfo {
36 public:
37 	enum {
38 		VALIGN_CENTER = 0,
39 		VALIGN_TOP = 1,
40 		VALIGN_BOTTOM = 2
41 	};
42 
43 	int x,y;
44 	int justify,valign;
45 	bool hidden;
46 	std::string font_style;
47 
48 	LabelInfo();
49 };
50 
51 class WidgetLabel : public Widget {
52 private:
53 	enum {
54 		UPDATE_NONE = 0,
55 		UPDATE_POS = 1,
56 		UPDATE_RECACHE = 2
57 	};
58 
59 	void recacheTextSprite();
60 	void applyOffsets();
61 	void setUpdateFlag(int _update_flag);
62 	void update();
63 
64 	int justify;
65 	int valign;
66 	int max_width;
67 	int update_flag;
68 	bool hidden;
69 	bool window_resize_flag;
70 	uint8_t alpha;
71 	Sprite *label;
72 
73 	std::string text;
74 	std::string font_style;
75 	Color color;
76 
77 	Rect bounds;
78 
79 public:
80 	static const std::string DEFAULT_FONT;
81 
82 	WidgetLabel();
83 	~WidgetLabel();
84 	void render();
85 	void setMaxWidth(int width);
86 	void setHidden(bool _hidden);
87 	void setPos(int offset_x, int offset_y);
88 	void setJustify(int _justify);
89 	void setVAlign(int _valign);
90 	void setText(const std::string& _text);
91 	void setColor(const Color& _color);
92 	void setFont(const std::string& _font);
93 	void setAlpha(uint8_t _alpha);
94 	void setFromLabelInfo(const LabelInfo& label_info);
95 
96 	std::string getText();
97 	Rect* getBounds();
98 	bool isHidden();
99 };
100 
101 #endif
102