OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Text.h
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 
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 
54  void processText();
56  int getLineX(int line) const;
57 public:
59  Text(int width, int height, int x = 0, int y = 0);
61  ~Text();
63  static std::wstring formatNumber(int value, std::wstring currency = L"");
65  static std::wstring formatFunding(int funds);
67  static std::wstring formatPercentage(int value);
69  void setBig();
71  void setSmall();
73  Font *getFont() const;
75  void initText(Font *big, Font *small, Language *lang);
77  void setText(const std::wstring &text);
79  std::wstring getText() const;
81  void setWordWrap(bool wrap, bool indent = false);
83  void setInvert(bool invert);
85  void setHighContrast(bool contrast);
87  void setAlign(TextHAlign align);
89  TextHAlign getAlign() const;
91  void setVerticalAlign(TextVAlign valign);
93  void setColor(Uint8 color);
95  Uint8 getColor() const;
97  void setSecondaryColor(Uint8 color);
99  Uint8 getSecondaryColor() const;
101  int getTextWidth(int line = -1) const;
103  int getTextHeight(int line = -1) const;
105  void draw();
106 };
107 
108 }
109 
110 #endif
void setInvert(bool invert)
Sets the text's color invert setting.
Definition: Text.cpp:204
TextHAlign getAlign() const
Gets the text's horizontal alignment.
Definition: Text.cpp:237
void setBig()
Sets the text size to big.
Definition: Text.cpp:116
~Text()
Cleans up the text.
Definition: Text.cpp:46
void setHighContrast(bool contrast)
Sets the text's high contrast color setting.
Definition: Text.cpp:215
void setAlign(TextHAlign align)
Sets the text's horizontal alignment.
Definition: Text.cpp:226
Text string displayed on screen.
Definition: Text.h:41
std::wstring getText() const
Gets the text's string.
Definition: Text.cpp:177
void setWordWrap(bool wrap, bool indent=false)
Sets the text's wordwrap setting.
Definition: Text.cpp:189
Contains strings used throughout the game for localization.
Definition: Language.h:42
void setSecondaryColor(Uint8 color)
Sets the text's secondary color.
Definition: Text.cpp:281
Takes care of loading and storing each character in a sprite font.
Definition: Font.h:40
void initText(Font *big, Font *small, Language *lang)
Initializes the resources for the text.
Definition: Text.cpp:149
void setVerticalAlign(TextVAlign valign)
Sets the text's vertical alignment.
Definition: Text.cpp:247
Uint8 getSecondaryColor() const
Gets the text's secondary color.
Definition: Text.cpp:291
static std::wstring formatNumber(int value, std::wstring currency=L"")
Formats an integer value as number with separators.
Definition: Text.cpp:57
Font * getFont() const
Gets the text's current font.
Definition: Text.cpp:135
int getTextHeight(int line=-1) const
Gets the rendered text's height.
Definition: Text.cpp:301
Text(int width, int height, int x=0, int y=0)
Creates a new text with the specified size and position.
Definition: Text.cpp:39
Element that is blit (rendered) onto the screen.
Definition: Surface.h:39
void invert(Uint8 mid)
Inverts the surface's colors.
Definition: Surface.cpp:451
int getTextWidth(int line=-1) const
Gets the rendered text's width.
Definition: Text.cpp:323
void setText(const std::wstring &text)
Sets the text's string.
Definition: Text.cpp:162
void draw()
Draws the text.
Definition: Text.cpp:520
void setColor(Uint8 color)
Sets the text's color.
Definition: Text.cpp:259
static std::wstring formatPercentage(int value)
Formats an integer value as percentage.
Definition: Text.cpp:106
void setSmall()
Sets the text size to small.
Definition: Text.cpp:125
static std::wstring formatFunding(int funds)
Formats an integer value as currency.
Definition: Text.cpp:95
Uint8 getColor() const
Gets the text's color.
Definition: Text.cpp:270