issue #5110, refactor UITextAtlas

This commit is contained in:
andyque 2014-05-14 15:51:50 +08:00
parent e6889dca36
commit 76cefcaa3f
2 changed files with 28 additions and 9 deletions

View File

@ -62,7 +62,7 @@ TextAtlas* TextAtlas::create()
void TextAtlas::initRenderer()
{
_labelAtlasRenderer = LabelAtlas::create();
_labelAtlasRenderer = Label::create();
_labelAtlasRenderer->setAnchorPoint(Point::ANCHOR_MIDDLE);
addProtectedChild(_labelAtlasRenderer, LABELATLAS_RENDERER_Z, -1);
}
@ -91,26 +91,34 @@ void TextAtlas::setProperty(const std::string& stringValue, const std::string& c
_itemWidth = itemWidth;
_itemHeight = itemHeight;
_startCharMap = startCharMap;
_labelAtlasRenderer->initWithString(stringValue, charMapFile, itemWidth, itemHeight, (int)(startCharMap[0]));
_labelAtlasRenderer->setCharMap(_charMapFileName, _itemWidth, _itemHeight, (int)(_startCharMap[0]));
_labelAtlasRenderer->setString(stringValue);
updateContentSizeWithTextureSize(_labelAtlasRenderer->getContentSize());
_labelAtlasRendererAdaptDirty = true;
CCLOG("cs w %f, h %f", _contentSize.width, _contentSize.height);
// CCLOG("cs w %f, h %f", _contentSize.width, _contentSize.height);
}
void TextAtlas::setStringValue(const std::string& value)
void TextAtlas::setString(const std::string& value)
{
_stringValue = value;
_labelAtlasRenderer->setString(value);
updateContentSizeWithTextureSize(_labelAtlasRenderer->getContentSize());
_labelAtlasRendererAdaptDirty = true;
CCLOG("cssss w %f, h %f", _contentSize.width, _contentSize.height);
// CCLOG("cssss w %f, h %f", _contentSize.width, _contentSize.height);
}
const std::string& TextAtlas::getStringValue() const
const std::string& TextAtlas::getString() const
{
return _labelAtlasRenderer->getString();
}
ssize_t TextAtlas::getStringLength()
{
return _labelAtlasRenderer->getStringLength();
}
void TextAtlas::onSizeChanged()
{
Widget::onSizeChanged();

View File

@ -73,10 +73,21 @@ public:
const std::string& startCharMap);
//set string value for labelatlas.
void setStringValue(const std::string& value);
CC_DEPRECATED_ATTRIBUTE void setStringValue(const std::string& value){this->setString(value);}
void setString(const std::string& value);
//get string value for labelatlas.
const std::string& getStringValue() const;
CC_DEPRECATED_ATTRIBUTE const std::string& getStringValue() const{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
*
* @return string length.
*/
ssize_t getStringLength();
//override "getVirtualRendererSize" method of widget.
virtual const Size& getVirtualRendererSize() const override;
@ -100,7 +111,7 @@ protected:
virtual Widget* createCloneInstance() override;
virtual void copySpecialProperties(Widget* model) override;
protected:
LabelAtlas* _labelAtlasRenderer;
Label* _labelAtlasRenderer;
std::string _stringValue;
std::string _charMapFileName;
int _itemWidth;