OpenXcom  1.0
Open-source clone of the original X-Com
Text.h
1 #pragma once
2 /*
3  * Copyright 2010-2016 OpenXcom Developers.
4  *
5  * This file is part of OpenXcom.
6  *
7  * OpenXcom is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * OpenXcom is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
19  */
20 #include "../Engine/InteractiveSurface.h"
21 #include <vector>
22 #include <string>
23 #include <stdint.h>
24 
25 namespace OpenXcom
26 {
27 
28 class Font;
29 class Language;
30 
31 enum TextHAlign { ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT };
32 enum TextVAlign { ALIGN_TOP, ALIGN_MIDDLE, ALIGN_BOTTOM };
33 
40 class Text : public InteractiveSurface
41 {
42 private:
43  Font *_big, *_small, *_font;
44  Language *_lang;
45  std::wstring _text, _wrappedText;
46  std::vector<int> _lineWidth, _lineHeight;
47  bool _wrap, _invert, _contrast, _indent;
48  TextHAlign _align;
49  TextVAlign _valign;
50  Uint8 _color, _color2;
51 
53  void processText();
55  int getLineX(int line) const;
56 public:
58  Text(int width, int height, int x = 0, int y = 0);
60  ~Text();
62  static std::wstring formatNumber(int64_t value, const std::wstring &currency = L"");
64  static std::wstring formatFunding(int64_t funds);
66  static std::wstring formatPercentage(int value);
68  void setBig();
70  void setSmall();
72  Font *getFont() const;
74  void initText(Font *big, Font *small, Language *lang);
76  void setText(const std::wstring &text);
78  std::wstring getText() const;
80  void setWordWrap(bool wrap, bool indent = false);
82  void setInvert(bool invert);
84  void setHighContrast(bool contrast);
86  void setAlign(TextHAlign align);
88  TextHAlign getAlign() const;
90  void setVerticalAlign(TextVAlign valign);
92  TextVAlign getVerticalAlign() const;
94  void setColor(Uint8 color);
96  Uint8 getColor() const;
98  void setSecondaryColor(Uint8 color);
100  Uint8 getSecondaryColor() const;
102  int getNumLines() const;
104  int getTextWidth(int line = -1) const;
106  int getTextHeight(int line = -1) const;
108  void draw();
109 };
110 
111 }
void setInvert(bool invert)
Sets the text&#39;s color invert setting.
Definition: Text.cpp:203
void setBig()
Sets the text size to big.
Definition: Text.cpp:115
~Text()
Cleans up the text.
Definition: Text.cpp:45
void setHighContrast(bool contrast)
Sets the text&#39;s high contrast color setting.
Definition: Text.cpp:214
void setAlign(TextHAlign align)
Sets the text&#39;s horizontal alignment.
Definition: Text.cpp:225
Surface that the user can interact with.
Definition: InteractiveSurface.h:37
Uint8 getSecondaryColor() const
Gets the text&#39;s secondary color.
Definition: Text.cpp:300
std::wstring getText() const
Gets the text&#39;s string.
Definition: Text.cpp:176
Text string displayed on screen.
Definition: Text.h:40
Font * getFont() const
Gets the text&#39;s current font.
Definition: Text.cpp:134
int getTextWidth(int line=-1) const
Gets the rendered text&#39;s width.
Definition: Text.cpp:337
void setWordWrap(bool wrap, bool indent=false)
Sets the text&#39;s wordwrap setting.
Definition: Text.cpp:188
int getTextHeight(int line=-1) const
Gets the rendered text&#39;s height.
Definition: Text.cpp:315
Contains strings used throughout the game for localization.
Definition: Language.h:39
void setSecondaryColor(Uint8 color)
Sets the text&#39;s secondary color.
Definition: Text.cpp:290
Takes care of loading and storing each character in a sprite font.
Definition: Font.h:45
void initText(Font *big, Font *small, Language *lang)
Initializes the resources for the text.
Definition: Text.cpp:148
void setVerticalAlign(TextVAlign valign)
Sets the text&#39;s vertical alignment.
Definition: Text.cpp:246
int getNumLines() const
Gets the number of lines in the (wrapped, if wrapping is enabled) text.
Definition: Text.cpp:305
static std::wstring formatFunding(int64_t funds)
Formats an integer value as currency.
Definition: Text.cpp:94
TextHAlign getAlign() const
Gets the text&#39;s horizontal alignment.
Definition: Text.cpp:236
TextVAlign getVerticalAlign() const
Gets the text&#39;s vertical alignment.
Definition: Text.cpp:257
Text(int width, int height, int x=0, int y=0)
Creates a new text with the specified size and position.
Definition: Text.cpp:38
void invert(Uint8 mid)
Inverts the surface&#39;s colors.
Definition: Surface.cpp:552
void setText(const std::wstring &text)
Sets the text&#39;s string.
Definition: Text.cpp:161
void draw()
Draws the text.
Definition: Text.cpp:549
Uint8 getColor() const
Gets the text&#39;s color.
Definition: Text.cpp:279
static std::wstring formatNumber(int64_t value, const std::wstring &currency=L"")
Formats an integer value as number with separators.
Definition: Text.cpp:56
void setColor(Uint8 color)
Sets the text&#39;s color.
Definition: Text.cpp:268
static std::wstring formatPercentage(int value)
Formats an integer value as percentage.
Definition: Text.cpp:105
void setSmall()
Sets the text size to small.
Definition: Text.cpp:124
Definition: BaseInfoState.cpp:40