2014-03-11 17:13:54 +08:00
|
|
|
/****************************************************************************
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2022-10-01 16:24:52 +08:00
|
|
|
https://axmolengine.github.io/
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "ui/UIText.h"
|
2014-06-04 14:26:21 +08:00
|
|
|
#include "2d/CCLabel.h"
|
|
|
|
#include "platform/CCFileUtils.h"
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
namespace ui
|
|
|
|
{
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
static const int LABEL_RENDERER_Z = (-1);
|
2015-04-10 14:18:16 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
IMPLEMENT_CLASS_GUI_INFO(Text)
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Text::Text()
|
|
|
|
: _touchScaleChangeEnabled(false)
|
|
|
|
, _normalScaleValueX(1.0f)
|
|
|
|
, _normalScaleValueY(1.0f)
|
|
|
|
, _fontName("Thonburi")
|
|
|
|
, _fontSize(10.f)
|
|
|
|
, _onSelectedScaleOffset(0.5)
|
|
|
|
, _labelRenderer(nullptr)
|
|
|
|
, _labelRendererAdaptDirty(true)
|
|
|
|
, _type(Type::SYSTEM)
|
|
|
|
{}
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Text::~Text() {}
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
Text* Text::create()
|
|
|
|
{
|
2021-12-08 00:11:53 +08:00
|
|
|
Text* widget = new Text();
|
|
|
|
if (widget->init())
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
widget->autorelease();
|
|
|
|
return widget;
|
|
|
|
}
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_SAFE_DELETE(widget);
|
2014-03-11 17:13:54 +08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Text::init()
|
|
|
|
{
|
|
|
|
if (Widget::init())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2015-04-10 14:18:16 +08:00
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
Text* Text::create(std::string_view textContent, std::string_view fontName, float fontSize)
|
2014-04-02 17:40:09 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
Text* text = new Text();
|
2021-12-08 00:11:53 +08:00
|
|
|
if (text->init(textContent, fontName, fontSize))
|
2014-11-25 18:16:34 +08:00
|
|
|
{
|
2014-04-02 17:40:09 +08:00
|
|
|
text->autorelease();
|
|
|
|
return text;
|
|
|
|
}
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_SAFE_DELETE(text);
|
2014-04-03 17:13:24 +08:00
|
|
|
return nullptr;
|
2014-04-02 17:40:09 +08:00
|
|
|
}
|
2015-04-10 14:18:16 +08:00
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
bool Text::init(std::string_view textContent, std::string_view fontName, float fontSize)
|
2014-04-02 17:40:09 +08:00
|
|
|
{
|
2014-04-04 18:26:53 +08:00
|
|
|
bool ret = true;
|
2014-11-25 18:16:34 +08:00
|
|
|
do
|
|
|
|
{
|
|
|
|
if (!Widget::init())
|
|
|
|
{
|
2014-04-04 18:26:53 +08:00
|
|
|
ret = false;
|
2014-04-02 17:40:09 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
this->setFontName(fontName);
|
|
|
|
this->setFontSize(fontSize);
|
2015-01-07 17:21:41 +08:00
|
|
|
this->setString(textContent);
|
2014-04-02 17:40:09 +08:00
|
|
|
} while (0);
|
2014-04-04 18:26:53 +08:00
|
|
|
return ret;
|
2014-04-02 17:40:09 +08:00
|
|
|
}
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
void Text::initRenderer()
|
|
|
|
{
|
2014-03-14 21:06:40 +08:00
|
|
|
_labelRenderer = Label::create();
|
2014-03-24 15:25:44 +08:00
|
|
|
addProtectedChild(_labelRenderer, LABEL_RENDERER_Z, -1);
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
2021-12-01 03:35:34 +08:00
|
|
|
void Text::setString(std::string_view text)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
2014-11-25 16:50:46 +08:00
|
|
|
if (text == _labelRenderer->getString())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2014-03-11 17:13:54 +08:00
|
|
|
_labelRenderer->setString(text);
|
2014-04-17 14:08:25 +08:00
|
|
|
updateContentSizeWithTextureSize(_labelRenderer->getContentSize());
|
|
|
|
_labelRendererAdaptDirty = true;
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
2015-04-10 14:18:16 +08:00
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
std::string_view Text::getString() const
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
return _labelRenderer->getString();
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
ssize_t Text::getStringLength() const
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
2014-05-14 15:26:14 +08:00
|
|
|
return _labelRenderer->getStringLength();
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
2015-07-28 14:48:01 +08:00
|
|
|
void Text::setFontSize(float size)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
2014-11-25 18:16:34 +08:00
|
|
|
if (_type == Type::SYSTEM)
|
|
|
|
{
|
2014-05-13 17:45:15 +08:00
|
|
|
_labelRenderer->setSystemFontSize(size);
|
|
|
|
}
|
2014-11-25 18:16:34 +08:00
|
|
|
else
|
|
|
|
{
|
2014-05-13 17:45:15 +08:00
|
|
|
TTFConfig config = _labelRenderer->getTTFConfig();
|
2021-12-25 10:04:45 +08:00
|
|
|
config.fontSize = size;
|
2014-05-13 17:45:15 +08:00
|
|
|
_labelRenderer->setTTFConfig(config);
|
|
|
|
}
|
2014-03-11 17:13:54 +08:00
|
|
|
_fontSize = size;
|
2014-04-17 14:08:25 +08:00
|
|
|
updateContentSizeWithTextureSize(_labelRenderer->getContentSize());
|
|
|
|
_labelRendererAdaptDirty = true;
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
2015-04-10 14:18:16 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
float Text::getFontSize() const
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
return _fontSize;
|
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
void Text::setFontName(std::string_view name)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (FileUtils::getInstance()->isFileExist(name))
|
2014-05-13 17:45:15 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
TTFConfig config = _labelRenderer->getTTFConfig();
|
2014-05-13 17:45:15 +08:00
|
|
|
config.fontFilePath = name;
|
2021-12-25 10:04:45 +08:00
|
|
|
config.fontSize = _fontSize;
|
2014-05-13 17:45:15 +08:00
|
|
|
_labelRenderer->setTTFConfig(config);
|
|
|
|
_type = Type::TTF;
|
|
|
|
}
|
2014-11-25 18:16:34 +08:00
|
|
|
else
|
|
|
|
{
|
2014-05-13 17:45:15 +08:00
|
|
|
_labelRenderer->setSystemFontName(name);
|
2014-10-09 18:28:09 +08:00
|
|
|
if (_type == Type::TTF)
|
|
|
|
{
|
|
|
|
_labelRenderer->requestSystemFontRefresh();
|
|
|
|
}
|
2014-05-13 17:45:15 +08:00
|
|
|
_type = Type::SYSTEM;
|
|
|
|
}
|
2014-03-11 17:13:54 +08:00
|
|
|
_fontName = name;
|
2014-04-17 14:08:25 +08:00
|
|
|
updateContentSizeWithTextureSize(_labelRenderer->getContentSize());
|
|
|
|
_labelRendererAdaptDirty = true;
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
2015-04-10 14:18:16 +08:00
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
std::string_view Text::getFontName() const
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
return _fontName;
|
|
|
|
}
|
2015-04-10 14:18:16 +08:00
|
|
|
|
2014-05-13 17:45:15 +08:00
|
|
|
Text::Type Text::getType() const
|
|
|
|
{
|
|
|
|
return _type;
|
|
|
|
}
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void Text::setTextAreaSize(const Vec2& size)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
_labelRenderer->setDimensions(size.width, size.height);
|
2014-11-25 18:16:34 +08:00
|
|
|
if (!_ignoreSize)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
_customSize = size;
|
2014-11-25 18:16:34 +08:00
|
|
|
}
|
2014-04-17 14:08:25 +08:00
|
|
|
updateContentSizeWithTextureSize(_labelRenderer->getContentSize());
|
|
|
|
_labelRendererAdaptDirty = true;
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
2015-04-10 14:18:16 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
const Vec2& Text::getTextAreaSize() const
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
return _labelRenderer->getDimensions();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Text::setTextHorizontalAlignment(TextHAlignment alignment)
|
|
|
|
{
|
|
|
|
_labelRenderer->setHorizontalAlignment(alignment);
|
|
|
|
}
|
2015-04-10 14:18:16 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
TextHAlignment Text::getTextHorizontalAlignment() const
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
return _labelRenderer->getHorizontalAlignment();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Text::setTextVerticalAlignment(TextVAlignment alignment)
|
|
|
|
{
|
|
|
|
_labelRenderer->setVerticalAlignment(alignment);
|
|
|
|
}
|
2015-04-10 14:18:16 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
TextVAlignment Text::getTextVerticalAlignment() const
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
return _labelRenderer->getVerticalAlignment();
|
|
|
|
}
|
2015-04-10 14:18:16 +08:00
|
|
|
|
2014-07-29 12:47:21 +08:00
|
|
|
void Text::setTextColor(const Color4B color)
|
2014-07-25 13:46:25 +08:00
|
|
|
{
|
|
|
|
_labelRenderer->setTextColor(color);
|
|
|
|
}
|
2015-04-10 14:18:16 +08:00
|
|
|
|
2014-07-27 07:23:16 +08:00
|
|
|
const Color4B& Text::getTextColor() const
|
2014-07-25 13:46:25 +08:00
|
|
|
{
|
|
|
|
return _labelRenderer->getTextColor();
|
|
|
|
}
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
void Text::setTouchScaleChangeEnabled(bool enable)
|
|
|
|
{
|
|
|
|
_touchScaleChangeEnabled = enable;
|
|
|
|
}
|
2015-04-10 14:18:16 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
bool Text::isTouchScaleChangeEnabled() const
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
return _touchScaleChangeEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Text::onPressStateChangedToNormal()
|
|
|
|
{
|
|
|
|
if (!_touchScaleChangeEnabled)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2014-03-14 21:06:40 +08:00
|
|
|
_labelRenderer->setScaleX(_normalScaleValueX);
|
|
|
|
_labelRenderer->setScaleY(_normalScaleValueY);
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Text::onPressStateChangedToPressed()
|
|
|
|
{
|
|
|
|
if (!_touchScaleChangeEnabled)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2014-03-14 21:06:40 +08:00
|
|
|
_labelRenderer->setScaleX(_normalScaleValueX + _onSelectedScaleOffset);
|
|
|
|
_labelRenderer->setScaleY(_normalScaleValueY + _onSelectedScaleOffset);
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void Text::onPressStateChangedToDisabled() {}
|
2014-03-11 17:13:54 +08:00
|
|
|
|
|
|
|
void Text::onSizeChanged()
|
|
|
|
{
|
|
|
|
Widget::onSizeChanged();
|
2014-04-17 14:08:25 +08:00
|
|
|
_labelRendererAdaptDirty = true;
|
|
|
|
}
|
2015-04-10 14:18:16 +08:00
|
|
|
|
2014-04-17 14:08:25 +08:00
|
|
|
void Text::adaptRenderers()
|
|
|
|
{
|
|
|
|
if (_labelRendererAdaptDirty)
|
|
|
|
{
|
|
|
|
labelScaleChangedWithSize();
|
|
|
|
_labelRendererAdaptDirty = false;
|
|
|
|
}
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
2021-10-23 23:27:14 +08:00
|
|
|
Vec2 Text::getVirtualRendererSize() const
|
2015-01-20 18:40:25 +08:00
|
|
|
{
|
|
|
|
return _labelRenderer->getContentSize();
|
|
|
|
}
|
|
|
|
|
2021-10-23 23:27:14 +08:00
|
|
|
Vec2 Text::getAutoRenderSize()
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
2021-10-23 23:27:14 +08:00
|
|
|
Vec2 virtualSize = _labelRenderer->getContentSize();
|
2015-01-19 17:02:28 +08:00
|
|
|
if (!_ignoreSize)
|
|
|
|
{
|
|
|
|
_labelRenderer->setDimensions(0, 0);
|
|
|
|
virtualSize = _labelRenderer->getContentSize();
|
|
|
|
_labelRenderer->setDimensions(_contentSize.width, _contentSize.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
return virtualSize;
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Node* Text::getVirtualRenderer()
|
|
|
|
{
|
|
|
|
return _labelRenderer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Text::labelScaleChangedWithSize()
|
|
|
|
{
|
|
|
|
if (_ignoreSize)
|
|
|
|
{
|
|
|
|
_labelRenderer->setScale(1.0f);
|
|
|
|
_normalScaleValueX = _normalScaleValueY = 1.0f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
_labelRenderer->setDimensions(_contentSize.width, _contentSize.height);
|
2021-10-23 23:27:14 +08:00
|
|
|
Vec2 textureSize = _labelRenderer->getContentSize();
|
2014-03-11 17:13:54 +08:00
|
|
|
if (textureSize.width <= 0.0f || textureSize.height <= 0.0f)
|
|
|
|
{
|
|
|
|
_labelRenderer->setScale(1.0f);
|
|
|
|
return;
|
|
|
|
}
|
2014-06-20 10:40:16 +08:00
|
|
|
float scaleX = _contentSize.width / textureSize.width;
|
|
|
|
float scaleY = _contentSize.height / textureSize.height;
|
2014-03-11 17:13:54 +08:00
|
|
|
_labelRenderer->setScaleX(scaleX);
|
|
|
|
_labelRenderer->setScaleY(scaleY);
|
|
|
|
_normalScaleValueX = scaleX;
|
|
|
|
_normalScaleValueY = scaleY;
|
|
|
|
}
|
2014-04-17 14:08:25 +08:00
|
|
|
_labelRenderer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f);
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string Text::getDescription() const
|
|
|
|
{
|
|
|
|
return "Label";
|
|
|
|
}
|
2015-04-10 14:18:16 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void Text::enableShadow(const Color4B& shadowColor, const Vec2& offset, int blurRadius)
|
2014-12-16 16:44:04 +08:00
|
|
|
{
|
2014-06-05 19:20:16 +08:00
|
|
|
_labelRenderer->enableShadow(shadowColor, offset, blurRadius);
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void Text::enableOutline(const Color4B& outlineColor, int outlineSize)
|
2014-12-16 16:44:04 +08:00
|
|
|
{
|
2014-06-06 16:41:45 +08:00
|
|
|
_labelRenderer->enableOutline(outlineColor, outlineSize);
|
2015-04-10 15:30:18 +08:00
|
|
|
updateContentSizeWithTextureSize(_labelRenderer->getContentSize());
|
|
|
|
_labelRendererAdaptDirty = true;
|
2014-06-05 19:20:16 +08:00
|
|
|
}
|
2015-04-10 14:18:16 +08:00
|
|
|
|
2014-12-16 16:44:04 +08:00
|
|
|
void Text::enableGlow(const Color4B& glowColor)
|
|
|
|
{
|
2014-06-06 16:50:25 +08:00
|
|
|
if (_type == Type::TTF)
|
|
|
|
_labelRenderer->enableGlow(glowColor);
|
2014-06-05 19:20:16 +08:00
|
|
|
}
|
2014-06-09 14:17:57 +08:00
|
|
|
|
2014-12-16 16:44:04 +08:00
|
|
|
void Text::disableEffect()
|
|
|
|
{
|
2014-06-05 19:20:16 +08:00
|
|
|
_labelRenderer->disableEffect();
|
2015-04-10 15:30:18 +08:00
|
|
|
updateContentSizeWithTextureSize(_labelRenderer->getContentSize());
|
|
|
|
_labelRendererAdaptDirty = true;
|
2014-06-05 19:20:16 +08:00
|
|
|
}
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2015-04-10 14:18:16 +08:00
|
|
|
void Text::disableEffect(LabelEffect effect)
|
|
|
|
{
|
|
|
|
_labelRenderer->disableEffect(effect);
|
2021-12-25 10:04:45 +08:00
|
|
|
// only outline effect will affect the content size of label
|
|
|
|
if (LabelEffect::OUTLINE == effect)
|
2015-04-10 15:30:18 +08:00
|
|
|
{
|
|
|
|
updateContentSizeWithTextureSize(_labelRenderer->getContentSize());
|
|
|
|
_labelRendererAdaptDirty = true;
|
|
|
|
}
|
2015-04-10 14:18:16 +08:00
|
|
|
}
|
|
|
|
|
2015-12-10 13:17:31 +08:00
|
|
|
bool Text::isShadowEnabled() const
|
|
|
|
{
|
|
|
|
return _labelRenderer->isShadowEnabled();
|
|
|
|
}
|
2021-10-23 23:27:14 +08:00
|
|
|
Vec2 Text::getShadowOffset() const
|
2015-12-10 13:17:31 +08:00
|
|
|
{
|
|
|
|
return _labelRenderer->getShadowOffset();
|
|
|
|
}
|
|
|
|
float Text::getShadowBlurRadius() const
|
|
|
|
{
|
|
|
|
return _labelRenderer->getShadowBlurRadius();
|
|
|
|
}
|
|
|
|
Color4B Text::getShadowColor() const
|
|
|
|
{
|
|
|
|
Color4F effect = _labelRenderer->getShadowColor();
|
|
|
|
return Color4B(effect.r * 255, effect.g * 255, effect.b * 255, effect.a * 255);
|
|
|
|
}
|
|
|
|
|
|
|
|
int Text::getOutlineSize() const
|
|
|
|
{
|
|
|
|
return _labelRenderer->getOutlineSize();
|
|
|
|
}
|
|
|
|
LabelEffect Text::getLabelEffectType() const
|
|
|
|
{
|
|
|
|
return _labelRenderer->getLabelEffectType();
|
|
|
|
}
|
|
|
|
Color4B Text::getEffectColor() const
|
|
|
|
{
|
|
|
|
Color4F effect = _labelRenderer->getEffectColor();
|
|
|
|
return Color4B(effect.r * 255, effect.g * 255, effect.b * 255, effect.a * 255);
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Sprite* Text::getLetter(int lettetIndex)
|
2017-01-13 18:06:01 +08:00
|
|
|
{
|
|
|
|
return _labelRenderer->getLetter(lettetIndex);
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void Text::setBlendFunc(const BlendFunc& blendFunc)
|
2018-01-19 09:19:36 +08:00
|
|
|
{
|
|
|
|
_labelRenderer->setBlendFunc(blendFunc);
|
|
|
|
}
|
|
|
|
|
|
|
|
const BlendFunc& Text::getBlendFunc() const
|
|
|
|
{
|
|
|
|
return _labelRenderer->getBlendFunc();
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-03-11 17:13:54 +08:00
|
|
|
Widget* Text::createCloneInstance()
|
|
|
|
{
|
|
|
|
return Text::create();
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void Text::copySpecialProperties(Widget* widget)
|
2014-03-11 17:13:54 +08:00
|
|
|
{
|
|
|
|
Text* label = dynamic_cast<Text*>(widget);
|
|
|
|
if (label)
|
|
|
|
{
|
2014-04-03 15:56:45 +08:00
|
|
|
setFontName(label->_fontName);
|
2014-06-26 17:29:07 +08:00
|
|
|
setFontSize(label->getFontSize());
|
2015-05-15 16:04:34 +08:00
|
|
|
setTextColor(label->getTextColor());
|
2014-05-14 15:26:14 +08:00
|
|
|
setString(label->getString());
|
2014-03-11 17:13:54 +08:00
|
|
|
setTouchScaleChangeEnabled(label->_touchScaleChangeEnabled);
|
|
|
|
setTextHorizontalAlignment(label->_labelRenderer->getHorizontalAlignment());
|
|
|
|
setTextVerticalAlignment(label->_labelRenderer->getVerticalAlignment());
|
|
|
|
setTextAreaSize(label->_labelRenderer->getDimensions());
|
2014-12-11 13:33:28 +08:00
|
|
|
setContentSize(label->getContentSize());
|
2015-12-10 13:17:31 +08:00
|
|
|
|
|
|
|
LabelEffect effectType = label->getLabelEffectType();
|
|
|
|
if (effectType == LabelEffect::GLOW)
|
|
|
|
{
|
|
|
|
enableGlow(label->getEffectColor());
|
|
|
|
}
|
|
|
|
else if (effectType == LabelEffect::OUTLINE)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
enableOutline(label->getEffectColor(), label->getOutlineSize());
|
2015-12-10 13:17:31 +08:00
|
|
|
}
|
|
|
|
if (label->isShadowEnabled())
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
enableShadow(label->getShadowColor(), label->getShadowOffset(), label->getShadowBlurRadius());
|
2015-12-10 13:17:31 +08:00
|
|
|
}
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
} // namespace ui
|
2014-03-11 17:13:54 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END
|