MyGUI  3.2.1
MyGUI_TextBox.cpp
Go to the documentation of this file.
00001 /*
00002  * This source file is part of MyGUI. For the latest info, see http://mygui.info/
00003  * Distributed under the MIT License
00004  * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
00005  */
00006 
00007 #include "MyGUI_Precompiled.h"
00008 #include "MyGUI_TextBox.h"
00009 #include "MyGUI_LanguageManager.h"
00010 #include "MyGUI_Constants.h"
00011 
00012 namespace MyGUI
00013 {
00014 
00015     TextBox::TextBox()
00016     {
00017     }
00018 
00019     IntCoord TextBox::getTextRegion()
00020     {
00021         return (nullptr == getSubWidgetText()) ? IntCoord() : getSubWidgetText()->getCoord();
00022     }
00023 
00024     IntSize TextBox::getTextSize()
00025     {
00026         return (nullptr == getSubWidgetText()) ? IntSize() : getSubWidgetText()->getTextSize();
00027     }
00028 
00029     void TextBox::setTextAlign(Align _value)
00030     {
00031         if (getSubWidgetText() != nullptr)
00032             getSubWidgetText()->setTextAlign(_value);
00033     }
00034 
00035     Align TextBox::getTextAlign()
00036     {
00037         if (getSubWidgetText() != nullptr)
00038             return getSubWidgetText()->getTextAlign();
00039         return Align::Default;
00040     }
00041 
00042     void TextBox::setTextColour(const Colour& _value)
00043     {
00044         if (nullptr != getSubWidgetText())
00045             getSubWidgetText()->setTextColour(_value);
00046     }
00047 
00048     const Colour& TextBox::getTextColour()
00049     {
00050         return (nullptr == getSubWidgetText()) ? Colour::Zero : getSubWidgetText()->getTextColour();
00051     }
00052 
00053     void TextBox::setFontName(const std::string& _value)
00054     {
00055         if (nullptr != getSubWidgetText())
00056             getSubWidgetText()->setFontName(_value);
00057     }
00058 
00059     const std::string& TextBox::getFontName()
00060     {
00061         if (nullptr == getSubWidgetText())
00062             return Constants::getEmptyString();
00063         return getSubWidgetText()->getFontName();
00064     }
00065 
00066     void TextBox::setFontHeight(int _height)
00067     {
00068         if (nullptr != getSubWidgetText())
00069             getSubWidgetText()->setFontHeight(_height);
00070     }
00071 
00072     int TextBox::getFontHeight()
00073     {
00074         return (nullptr == getSubWidgetText()) ? 0 : getSubWidgetText()->getFontHeight();
00075     }
00076 
00077     void TextBox::setCaption(const UString& _caption)
00078     {
00079         if (nullptr != getSubWidgetText())
00080             getSubWidgetText()->setCaption(_caption);
00081     }
00082 
00083     const UString& TextBox::getCaption()
00084     {
00085         if (nullptr == getSubWidgetText())
00086             return Constants::getEmptyUString();
00087         return getSubWidgetText()->getCaption();
00088     }
00089 
00090     void TextBox::setCaptionWithReplacing(const std::string& _value)
00091     {
00092         // replace "\\n" with char '\n'
00093         size_t pos = _value.find("\\n");
00094         if (pos == std::string::npos)
00095         {
00096             setCaption(LanguageManager::getInstance().replaceTags(_value));
00097         }
00098         else
00099         {
00100             std::string value(_value);
00101             while (pos != std::string::npos)
00102             {
00103                 value[pos++] = '\n';
00104                 value.erase(pos, 1);
00105                 pos = value.find("\\n");
00106             }
00107             setCaption(LanguageManager::getInstance().replaceTags(value));
00108         }
00109     }
00110 
00111     void TextBox::setTextShadowColour(const Colour& _value)
00112     {
00113         if (nullptr != getSubWidgetText())
00114             getSubWidgetText()->setShadowColour(_value);
00115     }
00116 
00117     const Colour& TextBox::getTextShadowColour()
00118     {
00119         return (nullptr == getSubWidgetText()) ? Colour::Black : getSubWidgetText()->getShadowColour();
00120     }
00121 
00122     void TextBox::setTextShadow(bool _value)
00123     {
00124         if (nullptr != getSubWidgetText())
00125             getSubWidgetText()->setShadow(_value);
00126     }
00127 
00128     bool TextBox::getTextShadow()
00129     {
00130         return (nullptr == getSubWidgetText()) ? false : getSubWidgetText()->getShadow();
00131     }
00132 
00133     void TextBox::setPropertyOverride(const std::string& _key, const std::string& _value)
00134     {
00136         if (_key == "TextColour")
00137             setTextColour(utility::parseValue<Colour>(_value));
00138 
00140         else if (_key == "TextAlign")
00141             setTextAlign(utility::parseValue<Align>(_value));
00142 
00144         else if (_key == "FontName")
00145             setFontName(_value);
00146 
00148         else if (_key == "FontHeight")
00149             setFontHeight(utility::parseValue<int>(_value));
00150 
00152         else if (_key == "Caption")
00153             setCaptionWithReplacing(_value);
00154 
00156         else if (_key == "TextShadowColour")
00157             setTextShadowColour(utility::parseValue<Colour>(_value));
00158 
00160         else if (_key == "TextShadow")
00161             setTextShadow(utility::parseValue<bool>(_value));
00162 
00163         else
00164         {
00165             Base::setPropertyOverride(_key, _value);
00166             return;
00167         }
00168 
00169         eventChangeProperty(this, _key, _value);
00170     }
00171 
00172 } // namespace MyGUI