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 "../Engine/Unicode.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::string _text;
46  UString _processedText;
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  void setBig();
65  void setSmall();
67  Font *getFont() const;
69  void initText(Font *big, Font *small, Language *lang);
71  void setText(const std::string &text);
73  std::string getText() const;
75  void setWordWrap(bool wrap, bool indent = false);
77  void setInvert(bool invert);
79  void setHighContrast(bool contrast);
81  void setAlign(TextHAlign align);
83  TextHAlign getAlign() const;
85  void setVerticalAlign(TextVAlign valign);
87  TextVAlign getVerticalAlign() const;
89  void setColor(Uint8 color);
91  Uint8 getColor() const;
93  void setSecondaryColor(Uint8 color);
95  Uint8 getSecondaryColor() const;
97  int getNumLines() const;
99  int getTextWidth(int line = -1) const;
101  int getTextHeight(int line = -1) const;
103  void draw();
104 };
105 
106 }
void setInvert(bool invert)
Sets the text&#39;s color invert setting.
Definition: Text.cpp:141
void setBig()
Sets the text size to big.
Definition: Text.cpp:53
~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:152
void setText(const std::string &text)
Sets the text&#39;s string.
Definition: Text.cpp:99
void setAlign(TextHAlign align)
Sets the text&#39;s horizontal alignment.
Definition: Text.cpp:163
Surface that the user can interact with.
Definition: InteractiveSurface.h:37
Uint8 getSecondaryColor() const
Gets the text&#39;s secondary color.
Definition: Text.cpp:238
Text string displayed on screen.
Definition: Text.h:40
Font * getFont() const
Gets the text&#39;s current font.
Definition: Text.cpp:72
int getTextWidth(int line=-1) const
Gets the rendered text&#39;s width.
Definition: Text.cpp:275
void setWordWrap(bool wrap, bool indent=false)
Sets the text&#39;s wordwrap setting.
Definition: Text.cpp:126
int getTextHeight(int line=-1) const
Gets the rendered text&#39;s height.
Definition: Text.cpp:253
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:228
Takes care of loading and storing each character in a sprite font.
Definition: Font.h:46
void initText(Font *big, Font *small, Language *lang)
Initializes the resources for the text.
Definition: Text.cpp:86
void setVerticalAlign(TextVAlign valign)
Sets the text&#39;s vertical alignment.
Definition: Text.cpp:184
std::string getText() const
Gets the text&#39;s string.
Definition: Text.cpp:114
int getNumLines() const
Gets the number of lines in the (wrapped, if wrapping is enabled) text.
Definition: Text.cpp:243
TextHAlign getAlign() const
Gets the text&#39;s horizontal alignment.
Definition: Text.cpp:174
TextVAlign getVerticalAlign() const
Gets the text&#39;s vertical alignment.
Definition: Text.cpp:195
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:592
void draw()
Draws the text.
Definition: Text.cpp:476
Uint8 getColor() const
Gets the text&#39;s color.
Definition: Text.cpp:217
void setColor(Uint8 color)
Sets the text&#39;s color.
Definition: Text.cpp:206
void setSmall()
Sets the text size to small.
Definition: Text.cpp:62
Definition: BaseInfoState.cpp:40