mirror of https://github.com/axmolengine/axmol.git
Revert "loading bar use new scale9 feature"
This reverts commit a671bf7ce9
.
This commit is contained in:
parent
1ac13efacc
commit
ab77e8c520
|
@ -92,7 +92,7 @@ LoadingBar* LoadingBar::create(const std::string &textureName,
|
|||
void LoadingBar::initRenderer()
|
||||
{
|
||||
_barRenderer = Scale9Sprite::create();
|
||||
_barRenderer->setRenderingType(Scale9Sprite::RenderingType::SIMPLE);
|
||||
_barRenderer->setScale9Enabled(false);
|
||||
addProtectedChild(_barRenderer, BAR_RENDERER_Z, -1);
|
||||
_barRenderer->setAnchorPoint(Vec2(0.0,0.5));
|
||||
}
|
||||
|
@ -190,11 +190,7 @@ void LoadingBar::setScale9Enabled(bool enabled)
|
|||
return;
|
||||
}
|
||||
_scale9Enabled = enabled;
|
||||
if (_scale9Enabled) {
|
||||
_barRenderer->setRenderingType(Scale9Sprite::RenderingType::SLICE);
|
||||
}else{
|
||||
_barRenderer->setRenderingType(Scale9Sprite::RenderingType::SIMPLE);
|
||||
}
|
||||
_barRenderer->setScale9Enabled(_scale9Enabled);
|
||||
|
||||
if (_scale9Enabled)
|
||||
{
|
||||
|
@ -257,8 +253,21 @@ void LoadingBar::setPercent(float percent)
|
|||
|
||||
void LoadingBar::updateProgressBar()
|
||||
{
|
||||
float width = (float)(_percent) / 100.0f * _totalLength;
|
||||
_barRenderer->setPreferredSize(Size(width, _contentSize.height));
|
||||
if (_scale9Enabled)
|
||||
{
|
||||
setScale9Scale();
|
||||
}
|
||||
else
|
||||
{
|
||||
Sprite* innerSprite = _barRenderer->getSprite();
|
||||
if (nullptr != innerSprite)
|
||||
{
|
||||
float res = _percent / 100.0f;
|
||||
Rect rect = innerSprite->getTextureRect();
|
||||
rect.size.width = _barRendererTextureSize.width * res;
|
||||
innerSprite->setTextureRect(rect, innerSprite->isTextureRectRotated(), rect.size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float LoadingBar::getPercent() const
|
||||
|
@ -319,7 +328,25 @@ void LoadingBar::barRendererScaleChangedWithSize()
|
|||
else
|
||||
{
|
||||
_totalLength = _contentSize.width;
|
||||
this->updateProgressBar();
|
||||
if (_scale9Enabled)
|
||||
{
|
||||
this->setScale9Scale();
|
||||
_barRenderer->setScale(1.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Size textureSize = _barRendererTextureSize;
|
||||
if (textureSize.width <= 0.0f || textureSize.height <= 0.0f)
|
||||
{
|
||||
_barRenderer->setScale(1.0f);
|
||||
return;
|
||||
}
|
||||
float scaleX = _contentSize.width / textureSize.width;
|
||||
float scaleY = _contentSize.height / textureSize.height;
|
||||
_barRenderer->setScaleX(scaleX);
|
||||
_barRenderer->setScaleY(scaleY);
|
||||
}
|
||||
}
|
||||
switch (_direction)
|
||||
{
|
||||
|
@ -334,6 +361,12 @@ void LoadingBar::barRendererScaleChangedWithSize()
|
|||
}
|
||||
}
|
||||
|
||||
void LoadingBar::setScale9Scale()
|
||||
{
|
||||
float width = (float)(_percent) / 100.0f * _totalLength;
|
||||
_barRenderer->setPreferredSize(Size(width, _contentSize.height));
|
||||
}
|
||||
|
||||
std::string LoadingBar::getDescription() const
|
||||
{
|
||||
return "LoadingBar";
|
||||
|
|
|
@ -180,6 +180,7 @@ protected:
|
|||
virtual void initRenderer() override;
|
||||
virtual void onSizeChanged() override;
|
||||
|
||||
void setScale9Scale();
|
||||
void updateProgressBar();
|
||||
void barRendererScaleChangedWithSize();
|
||||
|
||||
|
|
Loading…
Reference in New Issue