Merge pull request #11378 from andyque/fix-outline-update-do-not-change-content-size

fix ui::Text outline don't change content size
This commit is contained in:
minggo 2015-04-10 16:41:24 +08:00
commit 3d2fb6250e
3 changed files with 49 additions and 12 deletions

View File

@ -345,6 +345,8 @@ void Text::enableShadow(const Color4B& shadowColor,const Size &offset, int blurR
void Text::enableOutline(const Color4B& outlineColor,int outlineSize)
{
_labelRenderer->enableOutline(outlineColor, outlineSize);
updateContentSizeWithTextureSize(_labelRenderer->getContentSize());
_labelRendererAdaptDirty = true;
}
void Text::enableGlow(const Color4B& glowColor)
@ -356,11 +358,19 @@ void Text::enableGlow(const Color4B& glowColor)
void Text::disableEffect()
{
_labelRenderer->disableEffect();
updateContentSizeWithTextureSize(_labelRenderer->getContentSize());
_labelRendererAdaptDirty = true;
}
void Text::disableEffect(LabelEffect effect)
{
_labelRenderer->disableEffect(effect);
//only outline effect will affect the content size of label
if(LabelEffect::OUTLINE == effect)
{
updateContentSizeWithTextureSize(_labelRenderer->getContentSize());
_labelRendererAdaptDirty = true;
}
}
Widget* Text::createCloneInstance()

View File

@ -80,8 +80,13 @@ public:
/**
* Create a Text object with textContent, fontName and fontSize.
* The fontName could be a system font name or a TTF file path.
* Usage: Text *text = Text::create("Hello", "Arial", 20); //create a system font UIText.
* Text *text = Text::create("Hello", "xxx\xxx.ttf", 20); //create a TTF font UIText.
* Usage:
* @code
* //create a system font UIText.
* Text *text = Text::create("Hello", "Arial", 20);
* //create a TTF font UIText.
* Text *text = Text::create("Hello", "xxx\xxx.ttf", 20);
* @endcode
*
* @param textContent Text content string.
* @param fontName A given font name.
@ -97,7 +102,10 @@ public:
*
* @param text String value.
*/
CC_DEPRECATED_ATTRIBUTE void setText(const std::string& text){this->setString(text);}
CC_DEPRECATED_ATTRIBUTE void setText(const std::string& text)
{
this->setString(text);
}
void setString(const std::string& text);
/**
@ -105,13 +113,17 @@ public:
*
* @return String value.
*/
CC_DEPRECATED_ATTRIBUTE const std::string& getStringValue(){ return this->getString();}
CC_DEPRECATED_ATTRIBUTE const std::string& getStringValue()
{
return this->getString();
}
const std::string& getString()const;
/**
* Gets the string length of the label.
* Note: This length will be larger than the raw string length,
* if you want to get the raw string length, you should call this->getString().size() instead.
* if you want to get the raw string length,
* you should call this->getString().size() instead.
*
* @return String length.
*/
@ -135,9 +147,15 @@ public:
* Sets the font name of label.
* If you are trying to use a system font, you could just pass a font name
* If you are trying to use a TTF, you should pass a file path to the TTF file
* Usage: Text *text = Text::create("Hello", "Arial", 20); //create a system font UIText
* text->setFontName("Marfelt"); // it will change the font to system font no matter the previous font type is TTF or system font
* text->setFontName("xxxx/xxx.ttf"); //it will change the font to TTF font no matter the previous font type is TTF or system font
* Usage:
* @code
* //create a system font UIText
* Text *text = Text::create("Hello", "Arial", 20);
* // it will change the font to system font no matter the previous font type is TTF or system font
* text->setFontName("Marfelt");
* //it will change the font to TTF font no matter the previous font type is TTF or system font
* text->setFontName("xxxx/xxx.ttf");
* @endcode
* @param name Font name.
*/
void setFontName(const std::string& name);
@ -245,7 +263,9 @@ public:
* @param offset The offset of shadow effect.
* @param blurRadius The blur radius of shadow effect.
*/
void enableShadow(const Color4B& shadowColor = Color4B::BLACK,const Size &offset = Size(2,-2), int blurRadius = 0);
void enableShadow(const Color4B& shadowColor = Color4B::BLACK,
const Size &offset = Size(2,-2),
int blurRadius = 0);
/**
* Enable outline for the label.

View File

@ -134,13 +134,19 @@ bool UILabelTest_Effect::init()
// create the label stroke and shadow
Text* outline_label = Text::create();
outline_label->enableOutline(Color4B::GREEN, 4);
outline_label->setString("Outline");
CCLOG("content size without outline: %f %f",
outline_label->getContentSize().width,
outline_label->getContentSize().height);
outline_label->enableOutline(Color4B::GREEN, 4);
outline_label->setPosition(Vec2(widgetSize.width / 2.0f,
widgetSize.height / 2.0f
- shadow_label->getContentSize().height - 50));
_uiLayer->addChild(outline_label);
CCLOG("content size after applying outline: %f %f",
outline_label->getContentSize().width,
outline_label->getContentSize().height);
//create buttons to disable effect and add
auto disableOutlineBtn= Button::create();
@ -151,6 +157,9 @@ bool UILabelTest_Effect::init()
disableOutlineBtn->setPressedActionEnabled(true);
disableOutlineBtn->addClickEventListener([=](Ref*){
outline_label->disableEffect(LabelEffect::OUTLINE);
CCLOG("content size after disable outline: %f %f",
outline_label->getContentSize().width,
outline_label->getContentSize().height);
});
this->addChild(disableOutlineBtn);
@ -252,8 +261,6 @@ bool UITextTest_IgnoreConentSize::init()
widgetSize.height/2 - 50));
_uiLayer->addChild(halighButton);
return true;
}
return false;