MyGUI 3.2.2

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"
9 #include "MyGUI_LanguageManager.h"
10 #include "MyGUI_Constants.h"
11
12 namespace MyGUI
13 {
14
15 TextBox::TextBox()
16 {
17 }
18
19 IntCoord TextBox::getTextRegion()
20 {
21 return (nullptr == getSubWidgetText()) ? IntCoord() : getSubWidgetText()->getCoord();
22 }
23
24 IntSize TextBox::getTextSize()
25 {
26 return (nullptr == getSubWidgetText()) ? IntSize() : getSubWidgetText()->getTextSize();
27 }
28
29 void TextBox::setTextAlign(Align _value)
30 {
31 if (getSubWidgetText() != nullptr)
32 getSubWidgetText()->setTextAlign(_value);
33 }
34
35 Align TextBox::getTextAlign()
36 {
37 if (getSubWidgetText() != nullptr)
38 return getSubWidgetText()->getTextAlign();
39 return Align::Default;
40 }
41
42 void TextBox::setTextColour(const Colour& _value)
43 {
44 if (nullptr != getSubWidgetText())
45 getSubWidgetText()->setTextColour(_value);
46 }
47
48 const Colour& TextBox::getTextColour()
49 {
50 return (nullptr == getSubWidgetText()) ? Colour::Zero : getSubWidgetText()->getTextColour();
51 }
52
53 void TextBox::setFontName(const std::string& _value)
54 {
55 if (nullptr != getSubWidgetText())
56 getSubWidgetText()->setFontName(_value);
57 }
58
59 const std::string& TextBox::getFontName()
60 {
61 if (nullptr == getSubWidgetText())
62 return Constants::getEmptyString();
63 return getSubWidgetText()->getFontName();
64 }
65
66 void TextBox::setFontHeight(int _height)
67 {
68 if (nullptr != getSubWidgetText())
69 getSubWidgetText()->setFontHeight(_height);
70 }
71
72 int TextBox::getFontHeight()
73 {
74 return (nullptr == getSubWidgetText()) ? 0 : getSubWidgetText()->getFontHeight();
75 }
76
77 void TextBox::setCaption(const UString& _caption)
78 {
79 if (nullptr != getSubWidgetText())
80 getSubWidgetText()->setCaption(_caption);
81 }
82
83 const UString& TextBox::getCaption()
84 {
85 if (nullptr == getSubWidgetText())
86 return Constants::getEmptyUString();
87 return getSubWidgetText()->getCaption();
88 }
89
90 void TextBox::setCaptionWithReplacing(const std::string& _value)
91 {
92 // replace "\\n" with char '\n'
93 size_t pos = _value.find("\\n");
94 if (pos == std::string::npos)
95 {
96 setCaption(LanguageManager::getInstance().replaceTags(_value));
97 }
98 else
99 {
100 std::string value(_value);
101 while (pos != std::string::npos)
102 {
103 value[pos++] = '\n';
104 value.erase(pos, 1);
105 pos = value.find("\\n");
106 }
107 setCaption(LanguageManager::getInstance().replaceTags(value));
108 }
109 }
110
111 void TextBox::setTextShadowColour(const Colour& _value)
112 {
113 if (nullptr != getSubWidgetText())
114 getSubWidgetText()->setShadowColour(_value);
115 }
116
117 const Colour& TextBox::getTextShadowColour()
118 {
119 return (nullptr == getSubWidgetText()) ? Colour::Black : getSubWidgetText()->getShadowColour();
120 }
121
122 void TextBox::setTextShadow(bool _value)
123 {
124 if (nullptr != getSubWidgetText())
125 getSubWidgetText()->setShadow(_value);
126 }
127
128 bool TextBox::getTextShadow()
129 {
130 return (nullptr == getSubWidgetText()) ? false : getSubWidgetText()->getShadow();
131 }
132
133 void TextBox::setPropertyOverride(const std::string& _key, const std::string& _value)
134 {
136 if (_key == "TextColour")
137 setTextColour(utility::parseValue<Colour>(_value));
138
140 else if (_key == "TextAlign")
141 setTextAlign(utility::parseValue<Align>(_value));
142
144 else if (_key == "FontName")
145 setFontName(_value);
146
148 else if (_key == "FontHeight")
149 setFontHeight(utility::parseValue<int>(_value));
150
152 else if (_key == "Caption")
153 setCaptionWithReplacing(_value);
154
156 else if (_key == "TextShadowColour")
157 setTextShadowColour(utility::parseValue<Colour>(_value));
158
160 else if (_key == "TextShadow")
161 setTextShadow(utility::parseValue<bool>(_value));
162
163 else
164 {
165 Base::setPropertyOverride(_key, _value);
166 return;
167 }
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:59
MyGUI::TextBox::setTextAlign
virtual void setTextAlign(Align _value)
Definition: MyGUI_TextBox.cpp:29
MyGUI::TextBox::setPropertyOverride
virtual void setPropertyOverride(const std::string &_key, const std::string &_value)
Definition: MyGUI_TextBox.cpp:133
MyGUI::TextBox::setFontHeight
virtual void setFontHeight(int _value)
Definition: MyGUI_TextBox.cpp:66
MyGUI::TextBox::setTextShadow
virtual void setTextShadow(bool _value)
Definition: MyGUI_TextBox.cpp:122
MyGUI::ISubWidgetText::getShadowColour
virtual const Colour & getShadowColour() const
Definition: MyGUI_ISubWidgetText.h:156
MyGUI::TextBox::getTextColour
const Colour & getTextColour()
Definition: MyGUI_TextBox.cpp:48
MyGUI::TextBox::getTextShadow
bool getTextShadow()
Definition: MyGUI_TextBox.cpp:128
MyGUI::IntSize
types::TSize< int > IntSize
Definition: MyGUI_Types.h:29
MyGUI::ISubWidgetText::getTextColour
virtual const Colour & getTextColour() const
Definition: MyGUI_ISubWidgetText.h:130
MyGUI_Precompiled.h
MyGUI::TextBox::setFontName
virtual void setFontName(const std::string &_value)
Definition: MyGUI_TextBox.cpp:53
MyGUI::types::TSize< int >
MyGUI::Singleton< LanguageManager >::getInstance
static LanguageManager & getInstance()
Definition: MyGUI_Singleton.h:38
MyGUI::ISubWidgetText::getShadow
virtual bool getShadow() const
Definition: MyGUI_ISubWidgetText.h:58
MyGUI::ISubWidgetText::setTextAlign
virtual void setTextAlign(Align _value)
Definition: MyGUI_ISubWidgetText.h:147
MyGUI::TextBox::setTextColour
virtual void setTextColour(const Colour &_value)
Definition: MyGUI_TextBox.cpp:42
MyGUI::ISubWidgetText::setShadowColour
virtual void setShadowColour(const Colour &_value)
Definition: MyGUI_ISubWidgetText.h:155
MyGUI::TextBox::setTextShadowColour
virtual void setTextShadowColour(const Colour &_value)
Definition: MyGUI_TextBox.cpp:111
MyGUI::TextBox::setCaption
virtual void setCaption(const UString &_value)
Definition: MyGUI_TextBox.cpp:77
MyGUI_LanguageManager.h
MyGUI::ISubWidgetText::getFontName
virtual const std::string & getFontName() const
Definition: MyGUI_ISubWidgetText.h:136
MyGUI::ISubWidgetText::setCaption
virtual void setCaption(const UString &_value)
Definition: MyGUI_ISubWidgetText.h:123
MyGUI::SkinItem::getSubWidgetText
ISubWidgetText * getSubWidgetText()
Definition: MyGUI_SkinItem.cpp:155
MyGUI::IntCoord
types::TCoord< int > IntCoord
Definition: MyGUI_Types.h:35
MyGUI::Constants::getEmptyString
static const std::string & getEmptyString()
Definition: MyGUI_Constants.h:24
MyGUI::Align::Default
Definition: MyGUI_Align.h:36
MyGUI::Colour::Black
static const Colour Black
Definition: MyGUI_Colour.h:55
MyGUI::TextBox::getCaption
virtual const UString & getCaption()
Definition: MyGUI_TextBox.cpp:83
MyGUI::ISubWidgetText::setFontHeight
virtual void setFontHeight(int _value)
Definition: MyGUI_ISubWidgetText.h:141
MyGUI::TextBox::TextBox
TextBox()
Definition: MyGUI_TextBox.cpp:15
MyGUI_Constants.h
MyGUI
Definition: MyGUI_ActionController.h:14
MyGUI::TextBox::getTextAlign
Align getTextAlign()
Definition: MyGUI_TextBox.cpp:35
MyGUI::Widget::eventChangeProperty
EventHandle_WidgetStringString eventChangeProperty
Definition: MyGUI_Widget.h:266
MyGUI::ISubWidgetText::setShadow
virtual void setShadow(bool _value)
Definition: MyGUI_ISubWidgetText.h:63
MyGUI::ISubWidgetText::getFontHeight
virtual int getFontHeight() const
Definition: MyGUI_ISubWidgetText.h:142
MyGUI::ISubWidgetText::setFontName
virtual void setFontName(const std::string &_value)
Definition: MyGUI_ISubWidgetText.h:135
MyGUI::TextBox::setCaptionWithReplacing
void setCaptionWithReplacing(const std::string &_value)
Definition: MyGUI_TextBox.cpp:90
MyGUI::TextBox::getTextRegion
virtual IntCoord getTextRegion()
Definition: MyGUI_TextBox.cpp:19
MyGUI::ISubWidgetText::getCaption
virtual const UString & getCaption() const
Definition: MyGUI_ISubWidgetText.h:124
MyGUI::TextBox::getFontHeight
int getFontHeight()
Definition: MyGUI_TextBox.cpp:72
MyGUI::Constants::getEmptyUString
static const UString & getEmptyUString()
Definition: MyGUI_Constants.h:20
MyGUI::ISubWidgetText::setTextColour
virtual void setTextColour(const Colour &_value)
Definition: MyGUI_ISubWidgetText.h:129
MyGUI::UString
A UTF-16 string with implicit conversion to/from std::string and std::wstring.
Definition: MyGUI_UString.h:168
MyGUI::Align
Definition: MyGUI_Align.h:19
MyGUI::Colour
Definition: MyGUI_Colour.h:16
MyGUI::TextBox::getTextSize
virtual IntSize getTextSize()
Definition: MyGUI_TextBox.cpp:24
MyGUI::ISubWidgetText::getTextAlign
virtual Align getTextAlign() const
Definition: MyGUI_ISubWidgetText.h:148
MyGUI::Colour::Zero
static const Colour Zero
Definition: MyGUI_Colour.h:54
MyGUI::ISubWidgetText::getTextSize
virtual IntSize getTextSize()
Definition: MyGUI_ISubWidgetText.h:111
MyGUI::TextBox::getTextShadowColour
const Colour & getTextShadowColour()
Definition: MyGUI_TextBox.cpp:117
MyGUI::ICroppedRectangle::getCoord
const IntCoord & getCoord() const
Definition: MyGUI_ICroppedRectangle.h:61
MyGUI_TextBox.h