MyGUI 3.5.3
MyGUI_TextBox.cpp
Go to the documentation of this file.
1/*
2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3 * Distributed under the MIT License
4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5 */
6
7#include "MyGUI_Precompiled.h"
8#include "MyGUI_TextBox.h"
10#include "MyGUI_Constants.h"
11
12namespace MyGUI
13{
14
15 IntCoord TextBox::getTextRegion() const
16 {
17 return (nullptr == getSubWidgetText()) ? IntCoord() : getSubWidgetText()->getCoord();
18 }
19
20 IntSize TextBox::getTextSize() const
21 {
22 return (nullptr == getSubWidgetText()) ? IntSize() : getSubWidgetText()->getTextSize();
23 }
24
25 void TextBox::setTextAlign(Align _value)
26 {
27 if (getSubWidgetText() != nullptr)
28 getSubWidgetText()->setTextAlign(_value);
29 }
30
31 Align TextBox::getTextAlign() const
32 {
33 if (getSubWidgetText() != nullptr)
34 return getSubWidgetText()->getTextAlign();
35 return Align::Default;
36 }
37
38 void TextBox::setTextColour(const Colour& _value)
39 {
40 if (nullptr != getSubWidgetText())
41 getSubWidgetText()->setTextColour(_value);
42 }
43
44 const Colour& TextBox::getTextColour() const
45 {
46 return (nullptr == getSubWidgetText()) ? Colour::Zero : getSubWidgetText()->getTextColour();
47 }
48
49 void TextBox::setFontName(std::string_view _value)
50 {
51 if (nullptr != getSubWidgetText())
52 getSubWidgetText()->setFontName(_value);
53 }
54
55 std::string_view TextBox::getFontName() const
56 {
57 if (nullptr == getSubWidgetText())
58 return {};
59 return getSubWidgetText()->getFontName();
60 }
61
62 void TextBox::setFontHeight(int _height)
63 {
64 if (nullptr != getSubWidgetText())
65 getSubWidgetText()->setFontHeight(_height);
66 }
67
68 int TextBox::getFontHeight() const
69 {
70 return (nullptr == getSubWidgetText()) ? 0 : getSubWidgetText()->getFontHeight();
71 }
72
73 void TextBox::setCaption(const UString& _caption)
74 {
75 if (nullptr != getSubWidgetText())
76 getSubWidgetText()->setCaption(_caption);
77 }
78
79 const UString& TextBox::getCaption() const
80 {
81 if (nullptr == getSubWidgetText())
82 return Constants::getEmptyUString();
83 return getSubWidgetText()->getCaption();
84 }
85
86 void TextBox::setCaptionWithReplacing(std::string_view _value)
87 {
88 // replace "\\n" with char '\n'
89 size_t pos = _value.find("\\n");
90 if (pos == std::string::npos)
91 {
92 setCaption(LanguageManager::getInstance().replaceTags(UString(_value)));
93 }
94 else
95 {
96 std::string value(_value);
97 while (pos != std::string::npos)
98 {
99 value[pos++] = '\n';
100 value.erase(pos, 1);
101 pos = value.find("\\n");
102 }
103 setCaption(LanguageManager::getInstance().replaceTags(value));
104 }
105 }
106
107 void TextBox::setTextShadowColour(const Colour& _value)
108 {
109 if (nullptr != getSubWidgetText())
110 getSubWidgetText()->setShadowColour(_value);
111 }
112
113 const Colour& TextBox::getTextShadowColour() const
114 {
115 return (nullptr == getSubWidgetText()) ? Colour::Black : getSubWidgetText()->getShadowColour();
116 }
117
118 void TextBox::setTextShadow(bool _value)
119 {
120 if (nullptr != getSubWidgetText())
121 getSubWidgetText()->setShadow(_value);
122 }
123
124 bool TextBox::getTextShadow() const
125 {
126 return (nullptr == getSubWidgetText()) ? false : getSubWidgetText()->getShadow();
127 }
128
129 void TextBox::setPropertyOverride(std::string_view _key, std::string_view _value)
130 {
132 if (_key == "TextColour")
133 setTextColour(utility::parseValue<Colour>(_value));
134
136 else if (_key == "TextAlign")
137 setTextAlign(utility::parseValue<Align>(_value));
138
140 else if (_key == "FontName")
141 setFontName(_value);
142
144 else if (_key == "FontHeight")
145 setFontHeight(utility::parseValue<int>(_value));
146
148 else if (_key == "Caption")
149 setCaptionWithReplacing(_value);
150
152 else if (_key == "TextShadowColour")
153 setTextShadowColour(utility::parseValue<Colour>(_value));
154
156 else if (_key == "TextShadow")
157 setTextShadow(utility::parseValue<bool>(_value));
158
159 else
160 {
161 Base::setPropertyOverride(_key, _value);
162 return;
163 }
164
165 eventChangeProperty(this, _key, _value);
166 }
167
168} // namespace MyGUI
T parseValue(std::string_view value)
types::TCoord< int > IntCoord
Definition MyGUI_Types.h:35
types::TSize< int > IntSize
Definition MyGUI_Types.h:29