mirror of https://github.com/axmolengine/axmol.git
add uploading switch scale9 tests
This commit is contained in:
parent
ebc75579a2
commit
fdbf84a118
|
@ -216,7 +216,7 @@ void LoadingBar::setScale9Enabled(bool enabled)
|
||||||
ignoreContentAdaptWithSize(_prevIgnoreSize);
|
ignoreContentAdaptWithSize(_prevIgnoreSize);
|
||||||
}
|
}
|
||||||
setCapInsets(_capInsets);
|
setCapInsets(_capInsets);
|
||||||
setPercent(_percent);
|
this->setPercent(_percent);
|
||||||
_barRendererAdaptDirty = true;
|
_barRendererAdaptDirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,18 +255,24 @@ void LoadingBar::setPercent(float percent)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_percent = percent;
|
_percent = percent;
|
||||||
|
|
||||||
if (_totalLength <= 0)
|
if (_totalLength <= 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
float res = _percent / 100.0f;
|
|
||||||
|
|
||||||
|
this->updateProgressBar();
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoadingBar::updateProgressBar()
|
||||||
|
{
|
||||||
if (_scale9Enabled)
|
if (_scale9Enabled)
|
||||||
{
|
{
|
||||||
setScale9Scale();
|
setScale9Scale();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
float res = _percent / 100.0f;
|
||||||
Sprite* spriteRenderer = _barRenderer->getSprite();
|
Sprite* spriteRenderer = _barRenderer->getSprite();
|
||||||
Rect rect = spriteRenderer->getTextureRect();
|
Rect rect = spriteRenderer->getTextureRect();
|
||||||
rect.size.width = _barRendererTextureSize.width * res;
|
rect.size.width = _barRendererTextureSize.width * res;
|
||||||
|
@ -334,7 +340,7 @@ void LoadingBar::barRendererScaleChangedWithSize()
|
||||||
_totalLength = _contentSize.width;
|
_totalLength = _contentSize.width;
|
||||||
if (_scale9Enabled)
|
if (_scale9Enabled)
|
||||||
{
|
{
|
||||||
setScale9Scale();
|
this->setScale9Scale();
|
||||||
_barRenderer->setScale(1.0f);
|
_barRenderer->setScale(1.0f);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -148,6 +148,7 @@ protected:
|
||||||
virtual void onSizeChanged() override;
|
virtual void onSizeChanged() override;
|
||||||
|
|
||||||
void setScale9Scale();
|
void setScale9Scale();
|
||||||
|
void updateProgressBar();
|
||||||
void barRendererScaleChangedWithSize();
|
void barRendererScaleChangedWithSize();
|
||||||
|
|
||||||
virtual void adaptRenderers() override;
|
virtual void adaptRenderers() override;
|
||||||
|
|
|
@ -139,7 +139,7 @@ g_guisTests[] =
|
||||||
UISceneManager* sceneManager = UISceneManager::sharedUISceneManager();
|
UISceneManager* sceneManager = UISceneManager::sharedUISceneManager();
|
||||||
sceneManager->setCurrentUISceneId(kUILoadingBarTest_Left);
|
sceneManager->setCurrentUISceneId(kUILoadingBarTest_Left);
|
||||||
sceneManager->setMinUISceneId(kUILoadingBarTest_Left);
|
sceneManager->setMinUISceneId(kUILoadingBarTest_Left);
|
||||||
sceneManager->setMaxUISceneId(kUILoadingBarTest_Right_Scale9);
|
sceneManager->setMaxUISceneId(kUILoadingBarReloadTexture);
|
||||||
Scene* scene = sceneManager->currentUIScene();
|
Scene* scene = sceneManager->currentUIScene();
|
||||||
Director::getInstance()->replaceScene(scene);
|
Director::getInstance()->replaceScene(scene);
|
||||||
}
|
}
|
||||||
|
|
|
@ -397,3 +397,86 @@ bool UILoadingBarTest_Scale9_State_Change::init()
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// UILoadingBarReloadTexture
|
||||||
|
|
||||||
|
UILoadingBarReloadTexture::UILoadingBarReloadTexture()
|
||||||
|
: _count(0)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
UILoadingBarReloadTexture::~UILoadingBarReloadTexture()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool UILoadingBarReloadTexture::init()
|
||||||
|
{
|
||||||
|
if (UIScene::init())
|
||||||
|
{
|
||||||
|
Size widgetSize = _widget->getContentSize();
|
||||||
|
|
||||||
|
// Add the alert
|
||||||
|
Text *alert = Text::create("LoadingBar right scale9 render", "fonts/Marker Felt.ttf", 20);
|
||||||
|
alert->setColor(Color3B(159, 168, 176));
|
||||||
|
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 2.7f));
|
||||||
|
_uiLayer->addChild(alert);
|
||||||
|
|
||||||
|
LoadingBar* loadingBar = LoadingBar::create("cocosui/slider_bar_active_9patch.png");
|
||||||
|
loadingBar->setTag(0);
|
||||||
|
loadingBar->ignoreContentAdaptWithSize(false);
|
||||||
|
loadingBar->setScale9Enabled(true);
|
||||||
|
loadingBar->setCapInsets(Rect(0, 0, 0, 0));
|
||||||
|
loadingBar->setContentSize(Size(300, 13));
|
||||||
|
loadingBar->setName("texture0");
|
||||||
|
loadingBar->setDirection(LoadingBar::Direction::RIGHT);
|
||||||
|
|
||||||
|
loadingBar->setPosition(Vec2(widgetSize.width / 2.0f,
|
||||||
|
widgetSize.height / 2.0f + loadingBar->getContentSize().height / 4.0f));
|
||||||
|
|
||||||
|
_uiLayer->addChild(loadingBar);
|
||||||
|
|
||||||
|
auto buttonScale9 = Button::create();
|
||||||
|
buttonScale9->setTitleText("ToggleScale9");
|
||||||
|
buttonScale9->addClickEventListener([=](Ref*){
|
||||||
|
loadingBar->setScale9Enabled(!loadingBar->isScale9Enabled());
|
||||||
|
});
|
||||||
|
buttonScale9->setPosition(loadingBar->getPosition() + Vec2(-50,50));
|
||||||
|
_uiLayer->addChild(buttonScale9);
|
||||||
|
|
||||||
|
auto buttonChangeTexture = Button::create();
|
||||||
|
buttonChangeTexture->setTitleText("ChangeTexture");
|
||||||
|
buttonChangeTexture->addClickEventListener([=](Ref*){
|
||||||
|
auto name = loadingBar->getName();
|
||||||
|
if (name == "texture0")
|
||||||
|
{
|
||||||
|
loadingBar->loadTexture("cocosui/slider_bar_active_9patch2.png");
|
||||||
|
loadingBar->setName("texture1");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
loadingBar->loadTexture("cocosui/slider_bar_active_9patch.png");
|
||||||
|
loadingBar->setName("texture0");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
buttonChangeTexture->setPosition(loadingBar->getPosition() + Vec2(50,50));
|
||||||
|
_uiLayer->addChild(buttonChangeTexture);
|
||||||
|
|
||||||
|
this->scheduleUpdate();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UILoadingBarReloadTexture::update(float delta)
|
||||||
|
{
|
||||||
|
_count++;
|
||||||
|
if (_count > 100)
|
||||||
|
{
|
||||||
|
_count = 0;
|
||||||
|
}
|
||||||
|
LoadingBar* loadingBar = static_cast<LoadingBar*>(_uiLayer->getChildByTag(0));
|
||||||
|
loadingBar->setPercent(_count);
|
||||||
|
}
|
|
@ -107,4 +107,18 @@ protected:
|
||||||
int _count;
|
int _count;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class UILoadingBarReloadTexture : public UIScene
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
UILoadingBarReloadTexture();
|
||||||
|
~UILoadingBarReloadTexture();
|
||||||
|
void update(float dt);
|
||||||
|
bool init();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
UI_SCENE_CREATE_FUNC(UILoadingBarReloadTexture);
|
||||||
|
int _count;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
#endif /* defined(__TestCpp__UILoadingBarTest__) */
|
#endif /* defined(__TestCpp__UILoadingBarTest__) */
|
||||||
|
|
|
@ -71,6 +71,7 @@ static const char* s_testArray[] =
|
||||||
"UILoadingBarTest_Scale9_State_Change",
|
"UILoadingBarTest_Scale9_State_Change",
|
||||||
"UILoadingBarTest_Left_Scale9",
|
"UILoadingBarTest_Left_Scale9",
|
||||||
"UILoadingBarTest_Right_Scale9",
|
"UILoadingBarTest_Right_Scale9",
|
||||||
|
"UILoadingBarReloadTexture",
|
||||||
|
|
||||||
"UITextAtlasTest",
|
"UITextAtlasTest",
|
||||||
"UITextTest",
|
"UITextTest",
|
||||||
|
@ -284,6 +285,8 @@ Scene *UISceneManager::currentUIScene()
|
||||||
|
|
||||||
case kUILoadingBarTest_Right_Scale9:
|
case kUILoadingBarTest_Right_Scale9:
|
||||||
return UILoadingBarTest_Right_Scale9::sceneWithTitle(s_testArray[_currentUISceneId]);
|
return UILoadingBarTest_Right_Scale9::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||||
|
case kUILoadingBarReloadTexture:
|
||||||
|
return UILoadingBarReloadTexture::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||||
|
|
||||||
case kUITextAtlasTest:
|
case kUITextAtlasTest:
|
||||||
return UITextAtlasTest::sceneWithTitle(s_testArray[_currentUISceneId]);
|
return UITextAtlasTest::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||||
|
|
|
@ -66,6 +66,7 @@ enum
|
||||||
kUILoadingBarTest_Scale9_State_Change,
|
kUILoadingBarTest_Scale9_State_Change,
|
||||||
kUILoadingBarTest_Left_Scale9,
|
kUILoadingBarTest_Left_Scale9,
|
||||||
kUILoadingBarTest_Right_Scale9,
|
kUILoadingBarTest_Right_Scale9,
|
||||||
|
kUILoadingBarReloadTexture,
|
||||||
kUITextAtlasTest,
|
kUITextAtlasTest,
|
||||||
kUITextTest,
|
kUITextTest,
|
||||||
kUITextTest_LineWrap,
|
kUITextTest_LineWrap,
|
||||||
|
|
Loading…
Reference in New Issue