MyGUI 3.2.0

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files
- Examples

- File List
- Globals

MyGUI_TextBox.cpp
Go to the documentation of this file.
1
6 /*
7 This file is part of MyGUI.
8
9 MyGUI is free software: you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 MyGUI is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
21 */
22 #include "MyGUI_Precompiled.h"
23 #include "MyGUI_TextBox.h"
24 #include "MyGUI_LanguageManager.h"
25 #include "MyGUI_Constants.h"
26
27 namespace MyGUI
28 {
29
30 TextBox::TextBox()
31 {
32 }
33
34 IntCoord TextBox::getTextRegion()
35 {
36 return (nullptr == getSubWidgetText()) ? IntCoord() : getSubWidgetText()->getCoord();
37 }
38
39 IntSize TextBox::getTextSize()
40 {
41 return (nullptr == getSubWidgetText()) ? IntSize() : getSubWidgetText()->getTextSize();
42 }
43
44 void TextBox::setTextAlign(Align _value)
45 {
46 if (getSubWidgetText() != nullptr)
47 getSubWidgetText()->setTextAlign(_value);
48 }
49
50 Align TextBox::getTextAlign()
51 {
52 if (getSubWidgetText() != nullptr)
53 return getSubWidgetText()->getTextAlign();
54 return Align::Default;
55 }
56
57 void TextBox::setTextColour(const Colour& _value)
58 {
59 if (nullptr != getSubWidgetText())
60 getSubWidgetText()->setTextColour(_value);
61 }
62
63 const Colour& TextBox::getTextColour()
64 {
65 return (nullptr == getSubWidgetText()) ? Colour::Zero : getSubWidgetText()->getTextColour();
66 }
67
68 void TextBox::setFontName(const std::string& _value)
69 {
70 if (nullptr != getSubWidgetText())
71 getSubWidgetText()->setFontName(_value);
72 }
73
74 const std::string& TextBox::getFontName()
75 {
76 if (nullptr == getSubWidgetText())
77 return Constants::getEmptyString();
78 return getSubWidgetText()->getFontName();
79 }
80
81 void TextBox::setFontHeight(int _height)
82 {
83 if (nullptr != getSubWidgetText())
84 getSubWidgetText()->setFontHeight(_height);
85 }
86
87 int TextBox::getFontHeight()
88 {
89 return (nullptr == getSubWidgetText()) ? 0 : getSubWidgetText()->getFontHeight();
90 }
91
92 void TextBox::setCaption(const UString& _caption)
93 {
94 if (nullptr != getSubWidgetText())
95 getSubWidgetText()->setCaption(_caption);
96 }
97
98 const UString& TextBox::getCaption()
99 {
100 if (nullptr == getSubWidgetText())
101 return Constants::getEmptyUString();
102 return getSubWidgetText()->getCaption();
103 }
104
105 void TextBox::setCaptionWithReplacing(const std::string& _value)
106 {
107 // replace "\\n" with char '\n'
108 size_t pos = _value.find("\\n");
109 if (pos == std::string::npos)
110 {
111 setCaption(LanguageManager::getInstance().replaceTags(_value));
112 }
113 else
114 {
115 std::string value(_value);
116 while (pos != std::string::npos)
117 {
118 value[pos++] = '\n';
119 value.erase(pos, 1);
120 pos = value.find("\\n");
121 }
122 setCaption(LanguageManager::getInstance().replaceTags(value));
123 }
124 }
125
126 void TextBox::setTextShadowColour(const Colour& _value)
127 {
128 if (nullptr != getSubWidgetText())
129 getSubWidgetText()->setShadowColour(_value);
130 }
131
132 const Colour& TextBox::getTextShadowColour()
133 {
134 return (nullptr == getSubWidgetText()) ? Colour::Black : getSubWidgetText()->getShadowColour();
135 }
136
137 void TextBox::setTextShadow(bool _value)
138 {
139 if (nullptr != getSubWidgetText())
140 getSubWidgetText()->setShadow(_value);
141 }
142
143 bool TextBox::getTextShadow()
144 {
145 return (nullptr == getSubWidgetText()) ? false : getSubWidgetText()->getShadow();
146 }
147
148 void TextBox::setPropertyOverride(const std::string& _key, const std::string& _value)
149 {
150 if (_key == "TextColour")
151 setTextColour(utility::parseValue<Colour>(_value));
152 else if (_key == "TextAlign")
153 setTextAlign(utility::parseValue<Align>(_value));
154 else if (_key == "FontName")
155 setFontName(_value);
156 else if (_key == "FontHeight")
157 setFontHeight(utility::parseValue<int>(_value));
158 else if (_key == "Caption")
159 setCaptionWithReplacing(_value);
160 else if (_key == "TextShadowColour")
161 setTextShadowColour(utility::parseValue<Colour>(_value));
162 else if (_key == "TextShadow")
163 setTextShadow(utility::parseValue<bool>(_value));
164 else
165 {
166 Base::setPropertyOverride(_key, _value);
167 return;
168 }
169 eventChangeProperty(this, _key, _value);
170 }
171
172 } // namespace MyGUI
MyGUI::types::TCoord< int >
MyGUI::TextBox::getFontName
const std::string & getFontName()
Definition: MyGUI_TextBox.cpp:74
MyGUI::ISubWidgetText::getFontName
virtual const std::string & getFontName() const
Definition: MyGUI_ISubWidgetText.h:151
MyGUI::TextBox::setTextAlign
virtual void setTextAlign(Align _value)
Definition: MyGUI_TextBox.cpp:44
MyGUI::TextBox::setPropertyOverride
virtual void setPropertyOverride(const std::string &_key, const std::string &_value)
Definition: MyGUI_TextBox.cpp:148
MyGUI::TextBox::setFontHeight
virtual void setFontHeight(int _value)
Definition: MyGUI_TextBox.cpp:81
MyGUI::TextBox::setTextShadow
virtual void setTextShadow(bool _value)
Definition: MyGUI_TextBox.cpp:137
MyGUI::TextBox::getTextColour
const Colour & getTextColour()
Definition: MyGUI_TextBox.cpp:63
MyGUI::TextBox::getTextShadow
bool getTextShadow()
Definition: MyGUI_TextBox.cpp:143
MyGUI::ICroppedRectangle::getCoord
const IntCoord & getCoord() const
Definition: MyGUI_ICroppedRectangle.h:76
MyGUI::IntSize
types::TSize< int > IntSize
Definition: MyGUI_Types.h:44
MyGUI::ISubWidgetText::getShadowColour
virtual const Colour & getShadowColour() const
Definition: MyGUI_ISubWidgetText.h:172
MyGUI_Precompiled.h
MyGUI::TextBox::setFontName
virtual void setFontName(const std::string &_value)
Definition: MyGUI_TextBox.cpp:68
MyGUI::types::TSize< int >
MyGUI::Singleton< LanguageManager >::getInstance
static LanguageManager & getInstance()
Definition: MyGUI_Singleton.h:53
MyGUI::ISubWidgetText::setTextAlign
virtual void setTextAlign(Align _value)
Definition: MyGUI_ISubWidgetText.h:163
MyGUI::TextBox::setTextColour
virtual void setTextColour(const Colour &_value)
Definition: MyGUI_TextBox.cpp:57
MyGUI::ISubWidgetText::setShadowColour
virtual void setShadowColour(const Colour &_value)
Definition: MyGUI_ISubWidgetText.h:171
MyGUI::TextBox::setTextShadowColour
virtual void setTextShadowColour(const Colour &_value)
Definition: MyGUI_TextBox.cpp:126
MyGUI::TextBox::setCaption
virtual void setCaption(const UString &_value)
Definition: MyGUI_TextBox.cpp:92
MyGUI_LanguageManager.h
MyGUI::ISubWidgetText::setCaption
virtual void setCaption(const UString &_value)
Definition: MyGUI_ISubWidgetText.h:137
MyGUI::SkinItem::getSubWidgetText
ISubWidgetText * getSubWidgetText()
Definition: MyGUI_SkinItem.cpp:169
MyGUI::IntCoord
types::TCoord< int > IntCoord
Definition: MyGUI_Types.h:50
MyGUI::Constants::getEmptyString
static const std::string & getEmptyString()
Definition: MyGUI_Constants.h:36
MyGUI::ISubWidgetText::getTextColour
virtual const Colour & getTextColour() const
Definition: MyGUI_ISubWidgetText.h:145
MyGUI::Align::Default
Definition: MyGUI_Align.h:51
MyGUI::Colour::Black
static const Colour Black
Definition: MyGUI_Colour.h:70
MyGUI::TextBox::getCaption
virtual const UString & getCaption()
Definition: MyGUI_TextBox.cpp:98
MyGUI::ISubWidgetText::setFontHeight
virtual void setFontHeight(int _value)
Definition: MyGUI_ISubWidgetText.h:157
MyGUI::ISubWidgetText::getShadow
virtual bool getShadow() const
Definition: MyGUI_ISubWidgetText.h:72
MyGUI::TextBox::TextBox
TextBox()
Definition: MyGUI_TextBox.cpp:30
MyGUI_Constants.h
MyGUI::TextBox::getTextAlign
Align getTextAlign()
Definition: MyGUI_TextBox.cpp:50
MyGUI::Widget::eventChangeProperty
EventHandle_WidgetStringString eventChangeProperty
Definition: MyGUI_Widget.h:271
MyGUI::ISubWidgetText::setShadow
virtual void setShadow(bool _value)
Definition: MyGUI_ISubWidgetText.h:77
MyGUI::ISubWidgetText::setFontName
virtual void setFontName(const std::string &_value)
Definition: MyGUI_ISubWidgetText.h:150
MyGUI::TextBox::setCaptionWithReplacing
void setCaptionWithReplacing(const std::string &_value)
Definition: MyGUI_TextBox.cpp:105
MyGUI::TextBox::getTextRegion
virtual IntCoord getTextRegion()
Definition: MyGUI_TextBox.cpp:34
MyGUI::TextBox::getFontHeight
int getFontHeight()
Definition: MyGUI_TextBox.cpp:87
MyGUI::ISubWidgetText::getTextAlign
virtual Align getTextAlign() const
Definition: MyGUI_ISubWidgetText.h:164
MyGUI::Constants::getEmptyUString
static const UString & getEmptyUString()
Definition: MyGUI_Constants.h:35
MyGUI::ISubWidgetText::getFontHeight
virtual int getFontHeight() const
Definition: MyGUI_ISubWidgetText.h:158
MyGUI::ISubWidgetText::setTextColour
virtual void setTextColour(const Colour &_value)
Definition: MyGUI_ISubWidgetText.h:144
MyGUI::UString
A UTF-16 string with implicit conversion to/from std::string and std::wstring.
Definition: MyGUI_UString.h:169
MyGUI::ISubWidgetText::getCaption
virtual const UString & getCaption() const
Definition: MyGUI_ISubWidgetText.h:138
MyGUI::Align
Definition: MyGUI_Align.h:34
MyGUI::Colour
Definition: MyGUI_Colour.h:31
MyGUI::TextBox::getTextSize
virtual IntSize getTextSize()
Definition: MyGUI_TextBox.cpp:39
MyGUI::Colour::Zero
static const Colour Zero
Definition: MyGUI_Colour.h:69
MyGUI::ISubWidgetText::getTextSize
virtual IntSize getTextSize()
Definition: MyGUI_ISubWidgetText.h:125
MyGUI::TextBox::getTextShadowColour
const Colour & getTextShadowColour()
Definition: MyGUI_TextBox.cpp:132
MyGUI_TextBox.h