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