MyGUI: MyGUI_TextBox.cpp Source File

MyGUI 3.4.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"
9#include "MyGUI_LanguageManager.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
MyGUI_Constants.h
MyGUI_LanguageManager.h
MyGUI_Precompiled.h
MyGUI_TextBox.h
MyGUI::Constants::getEmptyUString
static const UString & getEmptyUString()
Definition MyGUI_Constants.h:20
MyGUI::ICroppedRectangle::getCoord
const IntCoord & getCoord() const
Definition MyGUI_ICroppedRectangle.h:56
MyGUI::ISubWidgetText::getShadow
virtual bool getShadow() const
Definition MyGUI_ISubWidgetText.h:61
MyGUI::ISubWidgetText::setTextColour
virtual void setTextColour(const Colour &)
Definition MyGUI_ISubWidgetText.h:144
MyGUI::ISubWidgetText::getTextColour
virtual const Colour & getTextColour() const
Definition MyGUI_ISubWidgetText.h:147
MyGUI::ISubWidgetText::getCaption
virtual const UString & getCaption() const
Definition MyGUI_ISubWidgetText.h:139
MyGUI::ISubWidgetText::setTextAlign
virtual void setTextAlign(Align)
Definition MyGUI_ISubWidgetText.h:168
MyGUI::ISubWidgetText::setCaption
virtual void setCaption(const UString &)
Definition MyGUI_ISubWidgetText.h:136
MyGUI::ISubWidgetText::getTextSize
virtual IntSize getTextSize() const
Definition MyGUI_ISubWidgetText.h:122
MyGUI::ISubWidgetText::setShadowColour
virtual void setShadowColour(const Colour &)
Definition MyGUI_ISubWidgetText.h:180
MyGUI::ISubWidgetText::setFontHeight
virtual void setFontHeight(int)
Definition MyGUI_ISubWidgetText.h:160
MyGUI::ISubWidgetText::getFontHeight
virtual int getFontHeight() const
Definition MyGUI_ISubWidgetText.h:163
MyGUI::ISubWidgetText::setFontName
virtual void setFontName(std::string_view)
Definition MyGUI_ISubWidgetText.h:152
MyGUI::ISubWidgetText::getTextAlign
virtual Align getTextAlign() const
Definition MyGUI_ISubWidgetText.h:171
MyGUI::ISubWidgetText::getFontName
virtual std::string_view getFontName() const
Definition MyGUI_ISubWidgetText.h:155
MyGUI::ISubWidgetText::getShadowColour
virtual const Colour & getShadowColour() const
Definition MyGUI_ISubWidgetText.h:183
MyGUI::ISubWidgetText::setShadow
virtual void setShadow(bool)
Definition MyGUI_ISubWidgetText.h:66
MyGUI::LanguageManager::getInstance
static LanguageManager & getInstance()
Definition MyGUI_LanguageManager.cpp:18
MyGUI::SkinItem::getSubWidgetText
ISubWidgetText * getSubWidgetText() const
Definition MyGUI_SkinItem.cpp:148
MyGUI::TextBox::getTextShadowColour
const Colour & getTextShadowColour() const
Definition MyGUI_TextBox.cpp:113
MyGUI::TextBox::setTextAlign
virtual void setTextAlign(Align _value)
Definition MyGUI_TextBox.cpp:25
MyGUI::TextBox::setCaption
virtual void setCaption(const UString &_caption)
Definition MyGUI_TextBox.cpp:73
MyGUI::TextBox::setPropertyOverride
void setPropertyOverride(std::string_view _key, std::string_view _value) override
Definition MyGUI_TextBox.cpp:129
MyGUI::TextBox::getFontHeight
virtual int getFontHeight() const
Definition MyGUI_TextBox.cpp:68
MyGUI::TextBox::setTextColour
virtual void setTextColour(const Colour &_value)
Definition MyGUI_TextBox.cpp:38
MyGUI::TextBox::getCaption
virtual const UString & getCaption() const
Definition MyGUI_TextBox.cpp:79
MyGUI::TextBox::getTextSize
virtual IntSize getTextSize() const
Definition MyGUI_TextBox.cpp:20
MyGUI::TextBox::getTextShadow
bool getTextShadow() const
Definition MyGUI_TextBox.cpp:124
MyGUI::TextBox::setTextShadowColour
virtual void setTextShadowColour(const Colour &_value)
Definition MyGUI_TextBox.cpp:107
MyGUI::TextBox::setCaptionWithReplacing
void setCaptionWithReplacing(std::string_view _value)
Definition MyGUI_TextBox.cpp:86
MyGUI::TextBox::setFontName
virtual void setFontName(std::string_view _value)
Definition MyGUI_TextBox.cpp:49
MyGUI::TextBox::setTextShadow
virtual void setTextShadow(bool _value)
Definition MyGUI_TextBox.cpp:118
MyGUI::TextBox::getTextColour
const Colour & getTextColour() const
Definition MyGUI_TextBox.cpp:44
MyGUI::TextBox::getTextRegion
virtual IntCoord getTextRegion() const
Definition MyGUI_TextBox.cpp:15
MyGUI::TextBox::setFontHeight
virtual void setFontHeight(int _height)
Definition MyGUI_TextBox.cpp:62
MyGUI::TextBox::getFontName
std::string_view getFontName() const
Definition MyGUI_TextBox.cpp:55
MyGUI::TextBox::getTextAlign
Align getTextAlign() const
Definition MyGUI_TextBox.cpp:31
MyGUI::UString
A UTF-16 string with implicit conversion to/from std::string and std::wstring.
Definition MyGUI_UString.h:144
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:1268
MyGUI::Widget::eventChangeProperty
EventHandle_WidgetStringString eventChangeProperty
Definition MyGUI_Widget.h:324
MyGUI::utility::parseValue
T parseValue(std::string_view _value)
Definition MyGUI_StringUtility.h:60
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:53
MyGUI::Colour::Black
static const Colour Black
Definition MyGUI_Colour.h:54