MyGUI_TextBox.cpp
Go to the documentation of this file.
/*
* This source file is part of MyGUI. For the latest info, see http://mygui.info/
* Distributed under the MIT License
* (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
*/
#include "MyGUI_Precompiled.h"
#include "MyGUI_TextBox.h"
#include "MyGUI_LanguageManager.h"
#include "MyGUI_Constants.h"
namespace MyGUI
{
IntCoord TextBox::getTextRegion() const
{
return (nullptr == getSubWidgetText()) ? IntCoord() : getSubWidgetText()->getCoord();
}
IntSize TextBox::getTextSize() const
{
return (nullptr == getSubWidgetText()) ? IntSize() : getSubWidgetText()->getTextSize();
}
void TextBox::setTextAlign(Align _value)
{
if (getSubWidgetText() != nullptr)
getSubWidgetText()->setTextAlign(_value);
}
Align TextBox::getTextAlign() const
{
if (getSubWidgetText() != nullptr)
return getSubWidgetText()->getTextAlign();
return Align::Default;
}
void TextBox::setTextColour(const Colour& _value)
{
if (nullptr != getSubWidgetText())
getSubWidgetText()->setTextColour(_value);
}
const Colour& TextBox::getTextColour() const
{
return (nullptr == getSubWidgetText()) ? Colour::Zero : getSubWidgetText()->getTextColour();
}
void TextBox::setFontName(std::string_view _value)
{
if (nullptr != getSubWidgetText())
getSubWidgetText()->setFontName(_value);
}
std::string_view TextBox::getFontName() const
{
if (nullptr == getSubWidgetText())
return {};
return getSubWidgetText()->getFontName();
}
void TextBox::setFontHeight(int _height)
{
if (nullptr != getSubWidgetText())
getSubWidgetText()->setFontHeight(_height);
}
int TextBox::getFontHeight() const
{
return (nullptr == getSubWidgetText()) ? 0 : getSubWidgetText()->getFontHeight();
}
void TextBox::setCaption(const UString& _caption)
{
if (nullptr != getSubWidgetText())
getSubWidgetText()->setCaption(_caption);
}
const UString& TextBox::getCaption() const
{
if (nullptr == getSubWidgetText())
return Constants::getEmptyUString();
return getSubWidgetText()->getCaption();
}
void TextBox::setCaptionWithReplacing(std::string_view _value)
{
// replace "\\n" with char '\n'
size_t pos = _value.find("\\n");
if (pos == std::string::npos)
{
setCaption(LanguageManager::getInstance().replaceTags(UString(_value)));
}
else
{
std::string value(_value);
while (pos != std::string::npos)
{
value[pos++] = '\n';
value.erase(pos, 1);
pos = value.find("\\n");
}
setCaption(LanguageManager::getInstance().replaceTags(value));
}
}
void TextBox::setTextShadowColour(const Colour& _value)
{
if (nullptr != getSubWidgetText())
getSubWidgetText()->setShadowColour(_value);
}
const Colour& TextBox::getTextShadowColour() const
{
return (nullptr == getSubWidgetText()) ? Colour::Black : getSubWidgetText()->getShadowColour();
}
void TextBox::setTextShadow(bool _value)
{
if (nullptr != getSubWidgetText())
getSubWidgetText()->setShadow(_value);
}
bool TextBox::getTextShadow() const
{
return (nullptr == getSubWidgetText()) ? false : getSubWidgetText()->getShadow();
}
void TextBox::setPropertyOverride(std::string_view _key, std::string_view _value)
{
if (_key == "TextColour")
setTextColour(utility::parseValue<Colour>(_value));
else if (_key == "TextAlign")
setTextAlign(utility::parseValue<Align>(_value));
else if (_key == "FontName")
setFontName(_value);
else if (_key == "FontHeight")
setFontHeight(utility::parseValue<int>(_value));
else if (_key == "Caption")
setCaptionWithReplacing(_value);
else if (_key == "TextShadowColour")
setTextShadowColour(utility::parseValue<Colour>(_value));
else if (_key == "TextShadow")
setTextShadow(utility::parseValue<bool>(_value));
else
{
Base::setPropertyOverride(_key, _value);
return;
}
eventChangeProperty(this, _key, _value);
}
} // 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