1 /***************************************************************************
2  *      Mechanized Assault and Exploration Reloaded Projectfile            *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
18  ***************************************************************************/
19 
20 #ifndef ui_graphical_menu_widgets_labelH
21 #define ui_graphical_menu_widgets_labelH
22 
23 #include <string>
24 #include <vector>
25 
26 #include "maxrconfig.h"
27 #include "ui/graphical/widget.h"
28 #include "ui/graphical/alignment.h"
29 #include "unifonts.h"
30 
31 class cLabel : public cWidget
32 {
33 public:
34 	cLabel (const cBox<cPosition>& area, const std::string& text, eUnicodeFontType fontType_ = FONT_LATIN_NORMAL, AlignmentFlags alignment = toEnumFlag (eAlignmentType::Left)  | eAlignmentType::Top);
35 
36 	void setText (const std::string& text);
37 	const std::string& getText() const;
38 
39 	void setFont (eUnicodeFontType fontType);
40 	void setAlignment (AlignmentFlags alignment);
41 	void setWordWrap (bool wordWrap);
42 
43 	void resizeToTextHeight();
44 
45 	virtual void draw (SDL_Surface& destination, const cBox<cPosition>& clipRect) MAXR_OVERRIDE_FUNCTION;
46 
47 	virtual void handleResized (const cPosition& oldSize) MAXR_OVERRIDE_FUNCTION;
48 private:
49 	std::string text;
50 	eUnicodeFontType fontType;
51 	AlignmentFlags alignment;
52 	bool wordWrap;
53 
54 	std::vector<std::string> drawLines;
55 
56 	AutoSurface surface;
57 
58 	void updateDisplayInformation();
59 
60 	// TODO: may move to some other place
61 	void breakText (const std::string& text, std::vector<std::string>& lines, int maximalWidth, eUnicodeFontType fontType) const;
62 };
63 
64 #endif // ui_graphical_menu_widgets_labelH
65