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"
10 #include "MyGUI_Constants.h"
11 
12 namespace MyGUI
13 {
14 
16  {
17  }
18 
20  {
21  return (nullptr == getSubWidgetText()) ? IntCoord() : getSubWidgetText()->getCoord();
22  }
23 
25  {
26  return (nullptr == getSubWidgetText()) ? IntSize() : getSubWidgetText()->getTextSize();
27  }
28 
30  {
31  if (getSubWidgetText() != nullptr)
32  getSubWidgetText()->setTextAlign(_value);
33  }
34 
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())
46  }
47 
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())
63  return getSubWidgetText()->getFontName();
64  }
65 
66  void TextBox::setFontHeight(int _height)
67  {
68  if (nullptr != getSubWidgetText())
69  getSubWidgetText()->setFontHeight(_height);
70  }
71 
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 
84  {
85  if (nullptr == getSubWidgetText())
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 
112  {
113  if (nullptr != getSubWidgetText())
115  }
116 
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 
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
const std::string & getFontName()
virtual const std::string & getFontName() const
virtual void setTextAlign(Align _value)
virtual void setPropertyOverride(const std::string &_key, const std::string &_value)
virtual void setFontHeight(int _value)
virtual void setTextShadow(bool _value)
const Colour & getTextColour()
const IntCoord & getCoord() const
types::TSize< int > IntSize
Definition: MyGUI_Types.h:29
virtual const Colour & getShadowColour() const
virtual void setFontName(const std::string &_value)
static LanguageManager & getInstance()
virtual void setTextAlign(Align _value)
virtual void setTextColour(const Colour &_value)
virtual void setShadowColour(const Colour &_value)
virtual void setTextShadowColour(const Colour &_value)
virtual void setCaption(const UString &_value)
virtual void setCaption(const UString &_value)
ISubWidgetText * getSubWidgetText()
types::TCoord< int > IntCoord
Definition: MyGUI_Types.h:35
static const std::string & getEmptyString()
virtual const Colour & getTextColour() const
static const Colour Black
Definition: MyGUI_Colour.h:55
virtual const UString & getCaption()
virtual void setFontHeight(int _value)
virtual bool getShadow() const
Align getTextAlign()
EventHandle_WidgetStringString eventChangeProperty
Definition: MyGUI_Widget.h:266
virtual void setShadow(bool _value)
virtual void setFontName(const std::string &_value)
void setCaptionWithReplacing(const std::string &_value)
virtual IntCoord getTextRegion()
virtual Align getTextAlign() const
static const UString & getEmptyUString()
virtual int getFontHeight() const
virtual void setTextColour(const Colour &_value)
A UTF-16 string with implicit conversion to/from std::string and std::wstring.
virtual const UString & getCaption() const
virtual IntSize getTextSize()
static const Colour Zero
Definition: MyGUI_Colour.h:54
virtual IntSize getTextSize()
const Colour & getTextShadowColour()