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 TextBox()15 TextBox::TextBox() 16 { 17 } 18 getTextRegion()19 IntCoord TextBox::getTextRegion() 20 { 21 return (nullptr == getSubWidgetText()) ? IntCoord() : getSubWidgetText()->getCoord(); 22 } 23 getTextSize()24 IntSize TextBox::getTextSize() 25 { 26 return (nullptr == getSubWidgetText()) ? IntSize() : getSubWidgetText()->getTextSize(); 27 } 28 setTextAlign(Align _value)29 void TextBox::setTextAlign(Align _value) 30 { 31 if (getSubWidgetText() != nullptr) 32 getSubWidgetText()->setTextAlign(_value); 33 } 34 getTextAlign()35 Align TextBox::getTextAlign() 36 { 37 if (getSubWidgetText() != nullptr) 38 return getSubWidgetText()->getTextAlign(); 39 return Align::Default; 40 } 41 setTextColour(const Colour & _value)42 void TextBox::setTextColour(const Colour& _value) 43 { 44 if (nullptr != getSubWidgetText()) 45 getSubWidgetText()->setTextColour(_value); 46 } 47 getTextColour()48 const Colour& TextBox::getTextColour() 49 { 50 return (nullptr == getSubWidgetText()) ? Colour::Zero : getSubWidgetText()->getTextColour(); 51 } 52 setFontName(const std::string & _value)53 void TextBox::setFontName(const std::string& _value) 54 { 55 if (nullptr != getSubWidgetText()) 56 getSubWidgetText()->setFontName(_value); 57 } 58 getFontName()59 const std::string& TextBox::getFontName() 60 { 61 if (nullptr == getSubWidgetText()) 62 return Constants::getEmptyString(); 63 return getSubWidgetText()->getFontName(); 64 } 65 setFontHeight(int _height)66 void TextBox::setFontHeight(int _height) 67 { 68 if (nullptr != getSubWidgetText()) 69 getSubWidgetText()->setFontHeight(_height); 70 } 71 getFontHeight()72 int TextBox::getFontHeight() 73 { 74 return (nullptr == getSubWidgetText()) ? 0 : getSubWidgetText()->getFontHeight(); 75 } 76 setCaption(const UString & _caption)77 void TextBox::setCaption(const UString& _caption) 78 { 79 if (nullptr != getSubWidgetText()) 80 getSubWidgetText()->setCaption(_caption); 81 } 82 getCaption()83 const UString& TextBox::getCaption() 84 { 85 if (nullptr == getSubWidgetText()) 86 return Constants::getEmptyUString(); 87 return getSubWidgetText()->getCaption(); 88 } 89 setCaptionWithReplacing(const std::string & _value)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 setTextShadowColour(const Colour & _value)111 void TextBox::setTextShadowColour(const Colour& _value) 112 { 113 if (nullptr != getSubWidgetText()) 114 getSubWidgetText()->setShadowColour(_value); 115 } 116 getTextShadowColour()117 const Colour& TextBox::getTextShadowColour() 118 { 119 return (nullptr == getSubWidgetText()) ? Colour::Black : getSubWidgetText()->getShadowColour(); 120 } 121 setTextShadow(bool _value)122 void TextBox::setTextShadow(bool _value) 123 { 124 if (nullptr != getSubWidgetText()) 125 getSubWidgetText()->setShadow(_value); 126 } 127 getTextShadow()128 bool TextBox::getTextShadow() 129 { 130 return (nullptr == getSubWidgetText()) ? false : getSubWidgetText()->getShadow(); 131 } 132 setPropertyOverride(const std::string & _key,const std::string & _value)133 void TextBox::setPropertyOverride(const std::string& _key, const std::string& _value) 134 { 135 /// @wproperty{TextBox, TextColour, Colour} Цвет текста. 136 if (_key == "TextColour") 137 setTextColour(utility::parseValue<Colour>(_value)); 138 139 /// @wproperty{TextBox, TextAlign, Align} Выравнивание текста. 140 else if (_key == "TextAlign") 141 setTextAlign(utility::parseValue<Align>(_value)); 142 143 /// @wproperty{TextBox, FontName, string} Имя шрифта. 144 else if (_key == "FontName") 145 setFontName(_value); 146 147 /// @wproperty{TextBox, FontHeight, int} Высота шрифта. 148 else if (_key == "FontHeight") 149 setFontHeight(utility::parseValue<int>(_value)); 150 151 /// @wproperty{TextBox, Caption, string} Содержимое поля редактирования. 152 else if (_key == "Caption") 153 setCaptionWithReplacing(_value); 154 155 /// @wproperty{TextBox, TextShadowColour, Colour} Цвет тени текста. 156 else if (_key == "TextShadowColour") 157 setTextShadowColour(utility::parseValue<Colour>(_value)); 158 159 /// @wproperty{TextBox, TextShadow, bool} Режим показа тени текста. 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 173