xoreos  0.0.5
text.h
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos 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 xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #ifndef GRAPHICS_AURORA_TEXT_H
26 #define GRAPHICS_AURORA_TEXT_H
27 
28 #include "src/common/ustring.h"
29 #include "src/common/maths.h"
30 
31 #include "src/graphics/types.h"
33 
36 
37 namespace Graphics {
38 
39 namespace Aurora {
40 
42 class Text : public GUIElement {
43 public:
44  Text(const FontHandle &font, const Common::UString &str,
45  float r = 1.0f, float g = 1.0f, float b = 1.0f, float a = 1.0f,
46  float halign = kHAlignLeft, float valign = kVAlignTop);
47  Text(const FontHandle &font, float w, float h, const Common::UString &str,
48  float r = 1.0f, float g = 1.0f, float b = 1.0f, float a = 1.0f,
49  float halign = kHAlignLeft, float valign = kVAlignTop);
50  Text(Graphics::GUIElement::GUIElementType type, const FontHandle &font, float w, float h, const Common::UString &str,
51  float r = 1.0f, float g = 1.0f, float b = 1.0f, float a = 1.0f,
52  float halign = kHAlignLeft, float valign = kVAlignTop);
53  ~Text();
54 
55  const Common::UString &get() const;
56  const Common::UString &getFont() const;
57  void getPosition(float &x, float &y, float &z) const;
58  void getColor(float &r, float &g, float &b, float &a) const;
59 
60  float getHorizontalAlign() const;
61  float getVerticalAlign () const;
62 
63  void set(const Common::UString &str, float maxWidth = 0.0f, float maxHeight = 0.0f);
64  void setText(const Common::UString &str);
65  void setPosition(float x, float y, float z = -FLT_MAX);
66  void setSize(float width, float height);
67  void setColor(float r, float g, float b, float a);
68  void unsetColor();
69  void setHorizontalAlign(float halign);
70  void setVerticalAlign(float valign);
71 
73  void setFont(const Common::UString &fnt);
74 
76  void disableColorTokens(bool disabled);
77 
78  bool empty();
79 
80  float getHeight(const Common::UString &text) const;
81 
82  size_t getLineCount() const;
83 
84  float getWidth() const;
85  float getHeight() const;
86 
87  // Renderable
88  void calculateDistance();
89  void render(RenderPass pass);
90  bool isIn(float x, float y) const;
91 
92  void renderImmediate(const glm::mat4 &parentTransform);
93 
94 private:
95  float _r, _g, _b, _a;
97 
98  float _x;
99  float _y;
100 
101  size_t _lineCount;
102 
103  float _width;
104  float _height;
105 
106  float _halign;
107  float _valign;
108 
111 
113 
114  void parseColors(const Common::UString &str, Common::UString &parsed,
115  ColorPositions &colors);
116 
117  void drawLine(const Common::UString &line,
118  ColorPositions::const_iterator color,
119  size_t position);
120 
121  void drawLineImmediate(const Common::UString &line,
122  ColorPositions::const_iterator color,
123  size_t position,
124  float &x,
125  float &y);
126 };
127 
128 } // End of namespace Aurora
129 
130 } // End of namespace Graphics
131 
132 #endif // GRAPHICS_AURORA_TEXT_H
float getHorizontalAlign() const
Definition: text.cpp:142
ColorPositions _colors
Definition: text.h:110
float getWidth() const
Definition: text.cpp:207
A class holding an UTF-8 string.
Definition: ustring.h:48
const float kVAlignTop
Definition: types.h:46
bool _disableColorTokens
Definition: text.h:112
A handle to a font.
Definition: fonthandle.h:52
Mathematical helpers.
void disableColorTokens(bool disabled)
Disable parsing <c color tokens into actual coloring.
Definition: text.cpp:79
void drawLineImmediate(const Common::UString &line, ColorPositions::const_iterator color, size_t position, float &x, float &y)
Definition: text.cpp:417
void setText(const Common::UString &str)
Definition: text.cpp:103
const Common::UString & getFont() const
Definition: text.cpp:162
Basic graphics types.
size_t getLineCount() const
Definition: text.cpp:203
float getHeight() const
Definition: text.cpp:211
Text(const FontHandle &font, const Common::UString &str, float r=1.0f, float g=1.0f, float b=1.0f, float a=1.0f, float halign=kHAlignLeft, float valign=kVAlignTop)
Definition: text.cpp:36
void drawLine(const Common::UString &line, ColorPositions::const_iterator color, size_t position)
Definition: text.cpp:391
void getColor(float &r, float &g, float &b, float &a) const
Definition: text.cpp:120
void getPosition(float &x, float &y, float &z) const
Definition: text.cpp:166
A GUI element.
A text object.
Definition: text.h:42
RenderPass
Definition: types.h:97
void setPosition(float x, float y, float z=-FLT_MAX)
Definition: text.cpp:172
FontHandle _font
Definition: text.h:96
Basic Aurora graphics types.
std::vector< ColorPosition > ColorPositions
Definition: types.h:114
void parseColors(const Common::UString &str, Common::UString &parsed, ColorPositions &colors)
Definition: text.cpp:303
const float kHAlignLeft
Definition: types.h:42
bool isIn(float x, float y) const
Is that point within the object?
Definition: text.cpp:262
A handle to an Aurora font.
Unicode string handling.
void setHorizontalAlign(float halign)
Definition: text.cpp:146
void renderImmediate(const glm::mat4 &parentTransform)
For shader based systems, don&#39;t sort anything, render this right_now.
Definition: text.cpp:272
void render(RenderPass pass)
Render the object.
Definition: text.cpp:218
An element of the GUI.
Definition: guielement.h:33
void setVerticalAlign(float valign)
Definition: text.cpp:154
void calculateDistance()
Calculate the object&#39;s distance.
Definition: text.cpp:215
Common::UString _str
Definition: text.h:109
#define pass
Definition: fft.cpp:257
void setSize(float width, float height)
Definition: text.cpp:184
float getVerticalAlign() const
Definition: text.cpp:150
void setFont(const Common::UString &fnt)
Change the font of the text.
Definition: text.cpp:387
#define FLT_MAX
Definition: maths.h:47
void setColor(float r, float g, float b, float a)
Definition: text.cpp:127