MyGUI  3.2.0
MyGUI_TextBox.cpp
Go to the documentation of this file.
00001 
00006 /*
00007     This file is part of MyGUI.
00008 
00009     MyGUI is free software: you can redistribute it and/or modify
00010     it under the terms of the GNU Lesser General Public License as published by
00011     the Free Software Foundation, either version 3 of the License, or
00012     (at your option) any later version.
00013 
00014     MyGUI is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017     GNU Lesser General Public License for more details.
00018 
00019     You should have received a copy of the GNU Lesser General Public License
00020     along with MyGUI.  If not, see <http://www.gnu.org/licenses/>.
00021 */
00022 #include "MyGUI_Precompiled.h"
00023 #include "MyGUI_TextBox.h"
00024 #include "MyGUI_LanguageManager.h"
00025 #include "MyGUI_Constants.h"
00026 
00027 namespace MyGUI
00028 {
00029 
00030     TextBox::TextBox()
00031     {
00032     }
00033 
00034     IntCoord TextBox::getTextRegion()
00035     {
00036         return (nullptr == getSubWidgetText()) ? IntCoord() : getSubWidgetText()->getCoord();
00037     }
00038 
00039     IntSize TextBox::getTextSize()
00040     {
00041         return (nullptr == getSubWidgetText()) ? IntSize() : getSubWidgetText()->getTextSize();
00042     }
00043 
00044     void TextBox::setTextAlign(Align _value)
00045     {
00046         if (getSubWidgetText() != nullptr)
00047             getSubWidgetText()->setTextAlign(_value);
00048     }
00049 
00050     Align TextBox::getTextAlign()
00051     {
00052         if (getSubWidgetText() != nullptr)
00053             return getSubWidgetText()->getTextAlign();
00054         return Align::Default;
00055     }
00056 
00057     void TextBox::setTextColour(const Colour& _value)
00058     {
00059         if (nullptr != getSubWidgetText())
00060             getSubWidgetText()->setTextColour(_value);
00061     }
00062 
00063     const Colour& TextBox::getTextColour()
00064     {
00065         return (nullptr == getSubWidgetText()) ? Colour::Zero : getSubWidgetText()->getTextColour();
00066     }
00067 
00068     void TextBox::setFontName(const std::string& _value)
00069     {
00070         if (nullptr != getSubWidgetText())
00071             getSubWidgetText()->setFontName(_value);
00072     }
00073 
00074     const std::string& TextBox::getFontName()
00075     {
00076         if (nullptr == getSubWidgetText())
00077             return Constants::getEmptyString();
00078         return getSubWidgetText()->getFontName();
00079     }
00080 
00081     void TextBox::setFontHeight(int _height)
00082     {
00083         if (nullptr != getSubWidgetText())
00084             getSubWidgetText()->setFontHeight(_height);
00085     }
00086 
00087     int TextBox::getFontHeight()
00088     {
00089         return (nullptr == getSubWidgetText()) ? 0 : getSubWidgetText()->getFontHeight();
00090     }
00091 
00092     void TextBox::setCaption(const UString& _caption)
00093     {
00094         if (nullptr != getSubWidgetText())
00095             getSubWidgetText()->setCaption(_caption);
00096     }
00097 
00098     const UString& TextBox::getCaption()
00099     {
00100         if (nullptr == getSubWidgetText())
00101             return Constants::getEmptyUString();
00102         return getSubWidgetText()->getCaption();
00103     }
00104 
00105     void TextBox::setCaptionWithReplacing(const std::string& _value)
00106     {
00107         // replace "\\n" with char '\n'
00108         size_t pos = _value.find("\\n");
00109         if (pos == std::string::npos)
00110         {
00111             setCaption(LanguageManager::getInstance().replaceTags(_value));
00112         }
00113         else
00114         {
00115             std::string value(_value);
00116             while (pos != std::string::npos)
00117             {
00118                 value[pos++] = '\n';
00119                 value.erase(pos, 1);
00120                 pos = value.find("\\n");
00121             }
00122             setCaption(LanguageManager::getInstance().replaceTags(value));
00123         }
00124     }
00125 
00126     void TextBox::setTextShadowColour(const Colour& _value)
00127     {
00128         if (nullptr != getSubWidgetText())
00129             getSubWidgetText()->setShadowColour(_value);
00130     }
00131 
00132     const Colour& TextBox::getTextShadowColour()
00133     {
00134         return (nullptr == getSubWidgetText()) ? Colour::Black : getSubWidgetText()->getShadowColour();
00135     }
00136 
00137     void TextBox::setTextShadow(bool _value)
00138     {
00139         if (nullptr != getSubWidgetText())
00140             getSubWidgetText()->setShadow(_value);
00141     }
00142 
00143     bool TextBox::getTextShadow()
00144     {
00145         return (nullptr == getSubWidgetText()) ? false : getSubWidgetText()->getShadow();
00146     }
00147 
00148     void TextBox::setPropertyOverride(const std::string& _key, const std::string& _value)
00149     {
00150         if (_key == "TextColour")
00151             setTextColour(utility::parseValue<Colour>(_value));
00152         else if (_key == "TextAlign")
00153             setTextAlign(utility::parseValue<Align>(_value));
00154         else if (_key == "FontName")
00155             setFontName(_value);
00156         else if (_key == "FontHeight")
00157             setFontHeight(utility::parseValue<int>(_value));
00158         else if (_key == "Caption")
00159             setCaptionWithReplacing(_value);
00160         else if (_key == "TextShadowColour")
00161             setTextShadowColour(utility::parseValue<Colour>(_value));
00162         else if (_key == "TextShadow")
00163             setTextShadow(utility::parseValue<bool>(_value));
00164         else
00165         {
00166             Base::setPropertyOverride(_key, _value);
00167             return;
00168         }
00169         eventChangeProperty(this, _key, _value);
00170     }
00171 
00172 } // namespace MyGUI