Minetest 5.9.0-dev
 
Loading...
Searching...
No Matches
static_text.h
Go to the documentation of this file.
1// Copyright (C) 2002-2012 Nikolaus Gebhardt
2// Copyright (C) 2016 Nathanaƫlle Courant
3// Modified this class to work with EnrichedStrings too
4// This file is part of the "Irrlicht Engine".
5// For conditions of distribution and use, see copyright notice in irrlicht.h
6
7#pragma once
8
9#include "IGUIStaticText.h"
10#include "irrArray.h"
11
12#include "log.h"
13
14#include <vector>
15
17#include "config.h"
18#include <IGUIEnvironment.h>
19
20
21namespace irr
22{
23
24namespace gui
25{
26
27 const EGUI_ELEMENT_TYPE EGUIET_ENRICHED_STATIC_TEXT = (EGUI_ELEMENT_TYPE)(0x1000);
28
29 class StaticText : public IGUIStaticText
30 {
31 public:
32
33 // StaticText is translated by EnrichedString.
34 // No need to use translate_string()
35 StaticText(const EnrichedString &text, bool border, IGUIEnvironment* environment,
36 IGUIElement* parent, s32 id, const core::rect<s32>& rectangle,
37 bool background = false);
38
40 virtual ~StaticText();
41
42 static irr::gui::IGUIStaticText *add(
43 irr::gui::IGUIEnvironment *guienv,
44 const EnrichedString &text,
45 const core::rect< s32 > &rectangle,
46 bool border = false,
47 bool wordWrap = true,
48 irr::gui::IGUIElement *parent = NULL,
49 s32 id = -1,
50 bool fillBackground = false)
51 {
52 parent = parent ? parent : guienv->getRootGUIElement();
53 irr::gui::IGUIStaticText *result = new irr::gui::StaticText(
54 text, border, guienv, parent,
55 id, rectangle, fillBackground);
56
57 result->setWordWrap(wordWrap);
58 result->drop();
59 return result;
60 }
61
62 static irr::gui::IGUIStaticText *add(
63 irr::gui::IGUIEnvironment *guienv,
64 const wchar_t *text,
65 const core::rect< s32 > &rectangle,
66 bool border = false,
67 bool wordWrap = true,
68 irr::gui::IGUIElement *parent = NULL,
69 s32 id = -1,
70 bool fillBackground = false)
71 {
72 return add(guienv, EnrichedString(text), rectangle, border, wordWrap, parent,
73 id, fillBackground);
74 }
75
77 virtual void draw();
78
80 virtual void setOverrideFont(IGUIFont* font=0);
81
83 virtual IGUIFont* getOverrideFont() const;
84
86 virtual IGUIFont* getActiveFont() const;
87
89 virtual void setOverrideColor(video::SColor color);
90
92 virtual void setBackgroundColor(video::SColor color);
93
95 virtual void setDrawBackground(bool draw);
96
98 virtual video::SColor getBackgroundColor() const;
99
101 virtual bool isDrawBackgroundEnabled() const;
102
104 virtual void setDrawBorder(bool draw);
105
107 virtual bool isDrawBorderEnabled() const;
108
110 virtual void setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical);
111
113 virtual video::SColor getOverrideColor() const;
114
116 virtual video::SColor getActiveColor() const;
117
120 virtual void enableOverrideColor(bool enable);
121
123 virtual bool isOverrideColorEnabled() const;
124
126 virtual void setTextRestrainedInside(bool restrainedInside);
127
129 virtual bool isTextRestrainedInside() const;
130
133 virtual void setWordWrap(bool enable);
134
136 virtual bool isWordWrapEnabled() const;
137
139 virtual void setText(const wchar_t* text);
140
142 virtual s32 getTextHeight() const;
143
145 virtual s32 getTextWidth() const;
146
148 virtual void updateAbsolutePosition();
149
151
156 virtual void setRightToLeft(bool rtl);
157
159 virtual bool isRightToLeft() const;
160
161 virtual bool hasType(EGUI_ELEMENT_TYPE t) const {
162 return (t == EGUIET_ENRICHED_STATIC_TEXT) || (t == EGUIET_STATIC_TEXT);
163 };
164
165 virtual bool hasType(EGUI_ELEMENT_TYPE t) {
166 return (t == EGUIET_ENRICHED_STATIC_TEXT) || (t == EGUIET_STATIC_TEXT);
167 };
168
169 void setText(const EnrichedString &text);
170
171 private:
172
174 void updateText();
175
176 EGUI_ALIGNMENT HAlign, VAlign;
177 bool Border;
182
183 gui::IGUIFont* OverrideFont;
184 gui::IGUIFont* LastBreakFont; // stored because: if skin changes, line break must be recalculated.
185
187 std::vector<EnrichedString> BrokenText;
188 };
189
190
191} // end namespace gui
192
193} // end namespace irr
194
195inline void setStaticText(irr::gui::IGUIStaticText *static_text, const EnrichedString &text)
196{
197 // dynamic_cast not possible due to some distributions shipped
198 // without rtti support in irrlicht
199 if (static_text->hasType(irr::gui::EGUIET_ENRICHED_STATIC_TEXT)) {
200 irr::gui::StaticText* stext = static_cast<irr::gui::StaticText*>(static_text);
201 stext->setText(text);
202 } else {
203 static_text->setText(text.c_str());
204 }
205}
206
207inline void setStaticText(irr::gui::IGUIStaticText *static_text, const wchar_t *text)
208{
209 setStaticText(static_text, EnrichedString(text, static_text->getOverrideColor()));
210}
Definition: enriched_string.h:28
const wchar_t * c_str() const
Definition: enriched_string.cpp:206
Definition: static_text.h:30
virtual void setWordWrap(bool enable)
Enables or disables word wrap for using the static text as multiline text control.
Definition: static_text.cpp:262
virtual bool isWordWrapEnabled() const
Checks if word wrap is enabled.
Definition: static_text.cpp:269
std::vector< EnrichedString > BrokenText
Definition: static_text.h:187
virtual IGUIFont * getOverrideFont() const
Gets the override font (if any)
Definition: static_text.cpp:147
gui::IGUIFont * OverrideFont
Definition: static_text.h:183
virtual bool isOverrideColorEnabled() const
Checks if an override color is enabled.
Definition: static_text.cpp:254
virtual bool hasType(EGUI_ELEMENT_TYPE t)
Definition: static_text.h:165
virtual void setRightToLeft(bool rtl)
Set whether the string should be interpreted as right-to-left (RTL) text.
Definition: static_text.cpp:275
virtual video::SColor getBackgroundColor() const
Gets the background color.
Definition: static_text.cpp:187
virtual void setTextRestrainedInside(bool restrainedInside)
Set whether the text in this label should be clipped if it goes outside bounds.
Definition: static_text.cpp:217
bool WordWrap
Definition: static_text.h:178
bool RightToLeft
Definition: static_text.h:181
virtual bool hasType(EGUI_ELEMENT_TYPE t) const
Definition: static_text.h:161
virtual bool isTextRestrainedInside() const
Checks if the text in this label should be clipped if it goes outside bounds.
Definition: static_text.cpp:223
virtual video::SColor getOverrideColor() const
Gets the override color.
Definition: static_text.cpp:236
bool Border
Definition: static_text.h:177
gui::IGUIFont * LastBreakFont
Definition: static_text.h:184
virtual IGUIFont * getActiveFont() const
Get the font which is used right now for drawing.
Definition: static_text.cpp:153
virtual void setDrawBorder(bool draw)
Sets whether to draw the border.
Definition: static_text.cpp:204
virtual void setOverrideColor(video::SColor color)
Sets another color for the text.
Definition: static_text.cpp:164
EGUI_ALIGNMENT HAlign
Definition: static_text.h:176
virtual s32 getTextHeight() const
Returns the height of the text in pixels when it is drawn.
Definition: static_text.cpp:547
EGUI_ALIGNMENT VAlign
Definition: static_text.h:176
bool RestrainTextInside
Definition: static_text.h:180
static irr::gui::IGUIStaticText * add(irr::gui::IGUIEnvironment *guienv, const wchar_t *text, const core::rect< s32 > &rectangle, bool border=false, bool wordWrap=true, irr::gui::IGUIElement *parent=NULL, s32 id=-1, bool fillBackground=false)
Definition: static_text.h:62
virtual video::SColor getActiveColor() const
Gets the currently used text color.
Definition: static_text.cpp:241
virtual bool isRightToLeft() const
Checks if the text should be interpreted as right-to-left text.
Definition: static_text.cpp:285
virtual void updateAbsolutePosition()
Updates the absolute position, splits text if word wrap is enabled.
Definition: static_text.cpp:539
virtual void enableOverrideColor(bool enable)
Sets if the static text should use the overide color or the color in the gui skin.
Definition: static_text.cpp:248
virtual bool isDrawBorderEnabled() const
Checks if border drawing is enabled.
Definition: static_text.cpp:211
void updateText()
Breaks the single text line.
Definition: static_text.cpp:293
virtual void setDrawBackground(bool draw)
Sets whether to draw the background.
Definition: static_text.cpp:180
virtual void draw()
draws the element and its children
Definition: static_text.cpp:49
virtual void setBackgroundColor(video::SColor color)
Sets another color for the background.
Definition: static_text.cpp:172
virtual void setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical)
Sets alignment mode for text.
Definition: static_text.cpp:229
virtual ~StaticText()
destructor
Definition: static_text.cpp:42
bool Background
Definition: static_text.h:179
static irr::gui::IGUIStaticText * add(irr::gui::IGUIEnvironment *guienv, const EnrichedString &text, const core::rect< s32 > &rectangle, bool border=false, bool wordWrap=true, irr::gui::IGUIElement *parent=NULL, s32 id=-1, bool fillBackground=false)
Definition: static_text.h:42
virtual void setText(const wchar_t *text)
Sets the new caption of this element.
Definition: static_text.cpp:527
virtual bool isDrawBackgroundEnabled() const
Checks if background drawing is enabled.
Definition: static_text.cpp:197
EnrichedString ColoredText
Definition: static_text.h:186
virtual void setOverrideFont(IGUIFont *font=0)
Sets another skin independent font.
Definition: static_text.cpp:130
virtual s32 getTextWidth() const
Returns the width of the current text, in the current font.
Definition: static_text.cpp:562
gui::IGUIEnvironment * guienv
Definition: clientlauncher.cpp:46
const EGUI_ELEMENT_TYPE EGUIET_ENRICHED_STATIC_TEXT
Definition: static_text.h:27
Definition: shader.h:61
void setStaticText(irr::gui::IGUIStaticText *static_text, const EnrichedString &text)
Definition: static_text.h:195