MyGUI: MyGUI_TextBox.cpp Source File

MyGUI 3.4.2

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

- File List
- Globals

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
12namespace MyGUI
13{
14
15 TextBox::TextBox()
16 {
17 }
18
19 IntCoord TextBox::getTextRegion() const
20 {
21 return (nullptr == getSubWidgetText()) ? IntCoord() : getSubWidgetText()->getCoord();
22 }
23
24 IntSize TextBox::getTextSize() const
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() const
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() const
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() const
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() const
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() const
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() const
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() const
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_Constants.h
MyGUI_LanguageManager.h
MyGUI_Precompiled.h
MyGUI_TextBox.h
MyGUI::Constants::getEmptyString
static const std::string & getEmptyString()
Definition MyGUI_Constants.h:24
MyGUI::Constants::getEmptyUString
static const UString & getEmptyUString()
Definition MyGUI_Constants.h:20
MyGUI::ICroppedRectangle::getCoord
const IntCoord & getCoord() const
Definition MyGUI_ICroppedRectangle.h:61
MyGUI::ISubWidgetText::getShadow
virtual bool getShadow() const
Definition MyGUI_ISubWidgetText.h:56
MyGUI::ISubWidgetText::setTextColour
virtual void setTextColour(const Colour &)
Definition MyGUI_ISubWidgetText.h:127
MyGUI::ISubWidgetText::getTextColour
virtual const Colour & getTextColour() const
Definition MyGUI_ISubWidgetText.h:128
MyGUI::ISubWidgetText::getCaption
virtual const UString & getCaption() const
Definition MyGUI_ISubWidgetText.h:122
MyGUI::ISubWidgetText::setTextAlign
virtual void setTextAlign(Align)
Definition MyGUI_ISubWidgetText.h:145
MyGUI::ISubWidgetText::setFontName
virtual void setFontName(const std::string &)
Definition MyGUI_ISubWidgetText.h:133
MyGUI::ISubWidgetText::setCaption
virtual void setCaption(const UString &)
Definition MyGUI_ISubWidgetText.h:121
MyGUI::ISubWidgetText::getFontName
virtual const std::string & getFontName() const
Definition MyGUI_ISubWidgetText.h:134
MyGUI::ISubWidgetText::getTextSize
virtual IntSize getTextSize() const
Definition MyGUI_ISubWidgetText.h:109
MyGUI::ISubWidgetText::setShadowColour
virtual void setShadowColour(const Colour &)
Definition MyGUI_ISubWidgetText.h:153
MyGUI::ISubWidgetText::setFontHeight
virtual void setFontHeight(int)
Definition MyGUI_ISubWidgetText.h:139
MyGUI::ISubWidgetText::getFontHeight
virtual int getFontHeight() const
Definition MyGUI_ISubWidgetText.h:140
MyGUI::ISubWidgetText::getTextAlign
virtual Align getTextAlign() const
Definition MyGUI_ISubWidgetText.h:146
MyGUI::ISubWidgetText::getShadowColour
virtual const Colour & getShadowColour() const
Definition MyGUI_ISubWidgetText.h:154
MyGUI::ISubWidgetText::setShadow
virtual void setShadow(bool)
Definition MyGUI_ISubWidgetText.h:61
MyGUI::LanguageManager::getInstance
static LanguageManager & getInstance()
Definition MyGUI_LanguageManager.cpp:18
MyGUI::SkinItem::getSubWidgetText
ISubWidgetText * getSubWidgetText() const
Definition MyGUI_SkinItem.cpp:155
MyGUI::TextBox::getTextShadowColour
const Colour & getTextShadowColour() const
Definition MyGUI_TextBox.cpp:117
MyGUI::TextBox::setTextAlign
virtual void setTextAlign(Align _value)
Definition MyGUI_TextBox.cpp:29
MyGUI::TextBox::setCaptionWithReplacing
void setCaptionWithReplacing(const std::string &_value)
Definition MyGUI_TextBox.cpp:90
MyGUI::TextBox::getFontName
const std::string & getFontName() const
Definition MyGUI_TextBox.cpp:59
MyGUI::TextBox::getFontHeight
virtual int getFontHeight() const
Definition MyGUI_TextBox.cpp:72
MyGUI::TextBox::setTextColour
virtual void setTextColour(const Colour &_value)
Definition MyGUI_TextBox.cpp:42
MyGUI::TextBox::setFontHeight
virtual void setFontHeight(int _value)
Definition MyGUI_TextBox.cpp:66
MyGUI::TextBox::setPropertyOverride
void setPropertyOverride(const std::string &_key, const std::string &_value) override
Definition MyGUI_TextBox.cpp:133
MyGUI::TextBox::getCaption
virtual const UString & getCaption() const
Definition MyGUI_TextBox.cpp:83
MyGUI::TextBox::getTextSize
virtual IntSize getTextSize() const
Definition MyGUI_TextBox.cpp:24
MyGUI::TextBox::getTextShadow
bool getTextShadow() const
Definition MyGUI_TextBox.cpp:128
MyGUI::TextBox::setTextShadowColour
virtual void setTextShadowColour(const Colour &_value)
Definition MyGUI_TextBox.cpp:111
MyGUI::TextBox::setTextShadow
virtual void setTextShadow(bool _value)
Definition MyGUI_TextBox.cpp:122
MyGUI::TextBox::getTextColour
const Colour & getTextColour() const
Definition MyGUI_TextBox.cpp:48
MyGUI::TextBox::setFontName
virtual void setFontName(const std::string &_value)
Definition MyGUI_TextBox.cpp:53
MyGUI::TextBox::setCaption
virtual void setCaption(const UString &_value)
Definition MyGUI_TextBox.cpp:77
MyGUI::TextBox::getTextRegion
virtual IntCoord getTextRegion() const
Definition MyGUI_TextBox.cpp:19
MyGUI::TextBox::TextBox
TextBox()
Definition MyGUI_TextBox.cpp:15
MyGUI::TextBox::getTextAlign
Align getTextAlign() const
Definition MyGUI_TextBox.cpp:35
MyGUI::UString
A UTF-16 string with implicit conversion to/from std::string and std::wstring.
Definition MyGUI_UString.h:145
MyGUI::UString::find
size_type find(const UString &str, size_type index=0) const
returns the index of the first occurrence of str within the current string, starting at index; return...
Definition MyGUI_UString.cpp:1281
MyGUI::Widget::eventChangeProperty
EventHandle_WidgetStringString eventChangeProperty
Definition MyGUI_Widget.h:268
MyGUI::utility::parseValue
T parseValue(const std::string &_value)
Definition MyGUI_StringUtility.h:112
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::IntCoord
types::TCoord< int > IntCoord
Definition MyGUI_Types.h:36
MyGUI::IntSize
types::TSize< int > IntSize
Definition MyGUI_Types.h:30
MyGUI::Align
Definition MyGUI_Align.h:20
MyGUI::Align::Default
@ Default
Definition MyGUI_Align.h:36
MyGUI::Colour
Definition MyGUI_Colour.h:17
MyGUI::Colour::Zero
static const Colour Zero
Definition MyGUI_Colour.h:55
MyGUI::Colour::Black
static const Colour Black
Definition MyGUI_Colour.h:56
MyGUI::types::TCoord< int >
MyGUI::types::TSize< int >