1 /*
2  * Copyright 2010-2014 OpenXcom Developers.
3  *
4  * This file is part of OpenXcom.
5  *
6  * OpenXcom is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU 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  * OpenXcom 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 General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with OpenXcom.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 #ifndef OPENXCOM_TEXT_H
20 #define OPENXCOM_TEXT_H
21 
22 #include "../Engine/Surface.h"
23 #include <vector>
24 #include <string>
25 
26 namespace OpenXcom
27 {
28 
29 class Font;
30 class Language;
31 
32 enum TextHAlign { ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT };
33 enum TextVAlign { ALIGN_TOP, ALIGN_MIDDLE, ALIGN_BOTTOM };
34 
35 /**
36  * Text string displayed on screen.
37  * Takes the characters from a Font and puts them together on screen
38  * to display a string of text, taking care of any required aligning
39  * or wrapping.
40  */
41 class Text : public Surface
42 {
43 private:
44 	Font *_big, *_small, *_font;
45 	Language *_lang;
46 	std::wstring _text, _wrappedText;
47 	std::vector<int> _lineWidth, _lineHeight;
48 	bool _wrap, _invert, _contrast, _indent;
49 	TextHAlign _align;
50 	TextVAlign _valign;
51 	Uint8 _color, _color2;
52 
53 	/// Processes the contained text.
54 	void processText();
55 	/// Gets the X position of a text line.
56 	int getLineX(int line) const;
57 public:
58 	/// Creates a new text with the specified size and position.
59 	Text(int width, int height, int x = 0, int y = 0);
60 	/// Cleans up the text.
61 	~Text();
62 	/// Formats an integer value as number with separators.
63 	static std::wstring formatNumber(int value, std::wstring currency = L"");
64 	/// Formats an integer value as currency.
65 	static std::wstring formatFunding(int funds);
66 	/// Formats an integer value as percentage.
67 	static std::wstring formatPercentage(int value);
68 	/// Sets the text size to big.
69 	void setBig();
70 	/// Sets the text size to small.
71 	void setSmall();
72 	/// Gets the text's current font.
73 	Font *getFont() const;
74 	/// Initializes the resources for the text.
75 	void initText(Font *big, Font *small, Language *lang);
76 	/// Sets the text's string.
77 	void setText(const std::wstring &text);
78 	/// Gets the text's string.
79 	std::wstring getText() const;
80 	/// Sets the text's wordwrap setting.
81 	void setWordWrap(bool wrap, bool indent = false);
82 	/// Sets the text's color invert setting.
83 	void setInvert(bool invert);
84 	/// Sets the text's high contrast color setting.
85 	void setHighContrast(bool contrast);
86 	/// Sets the text's horizontal alignment.
87 	void setAlign(TextHAlign align);
88 	/// Gets the text's horizontal alignment.
89 	TextHAlign getAlign() const;
90 	/// Sets the text's vertical alignment.
91 	void setVerticalAlign(TextVAlign valign);
92 	/// Sets the text's color.
93 	void setColor(Uint8 color);
94 	/// Gets the text's color.
95 	Uint8 getColor() const;
96 	/// Sets the text's secondary color.
97 	void setSecondaryColor(Uint8 color);
98 	/// Gets the text's secondary color.
99 	Uint8 getSecondaryColor() const;
100 	/// Gets the rendered text's width.
101 	int getTextWidth(int line = -1) const;
102 	/// Gets the rendered text's height.
103 	int getTextHeight(int line = -1) const;
104 	/// Draws the text.
105 	void draw();
106 };
107 
108 }
109 
110 #endif
111