2013-09-16 20:54:13 +08:00
|
|
|
#include "UILoadingBarTest.h"
|
|
|
|
|
2015-04-09 12:23:47 +08:00
|
|
|
USING_NS_CC;
|
|
|
|
using namespace cocos2d::ui;
|
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
UILoadingBarTests::UILoadingBarTests()
|
|
|
|
{
|
|
|
|
ADD_TEST_CASE(UILoadingBarTest_Left);
|
|
|
|
ADD_TEST_CASE(UILoadingBarTest_Right);
|
|
|
|
ADD_TEST_CASE(UILoadingBarTest_Left_Scale9);
|
|
|
|
ADD_TEST_CASE(UILoadingBarTest_Right_Scale9);
|
|
|
|
ADD_TEST_CASE(UILoadingBarTest_Scale9_State_Change);
|
|
|
|
ADD_TEST_CASE(UILoadingBarReloadTexture);
|
|
|
|
}
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
// UILoadingBarTest_Left
|
|
|
|
|
|
|
|
UILoadingBarTest_Left::UILoadingBarTest_Left()
|
2013-12-23 15:35:35 +08:00
|
|
|
: _count(0)
|
2013-09-16 20:54:13 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UILoadingBarTest_Left::~UILoadingBarTest_Left()
|
|
|
|
{
|
|
|
|
unscheduleUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UILoadingBarTest_Left::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
|
|
|
scheduleUpdate();
|
|
|
|
|
2014-06-20 11:18:53 +08:00
|
|
|
Size widgetSize = _widget->getContentSize();
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
// Add the alert
|
2014-04-03 11:34:06 +08:00
|
|
|
Text* alert = Text::create("LoadingBar left", "fonts/Marker Felt.ttf", 30);
|
2013-09-16 20:54:13 +08:00
|
|
|
alert->setColor(Color3B(159, 168, 176));
|
2014-06-20 11:18:53 +08:00
|
|
|
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 1.75f));
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(alert);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
// Create the loading bar
|
2014-04-02 17:53:06 +08:00
|
|
|
LoadingBar* loadingBar = LoadingBar::create("cocosui/sliderProgress.png");
|
2013-12-23 15:35:35 +08:00
|
|
|
loadingBar->setTag(0);
|
2014-05-15 01:07:09 +08:00
|
|
|
loadingBar->setPosition(Vec2(widgetSize.width / 2.0f,
|
2014-06-20 11:18:53 +08:00
|
|
|
widgetSize.height / 2.0f + loadingBar->getContentSize().height / 4.0f));
|
2014-08-08 11:17:17 +08:00
|
|
|
Button* button = Button::create("cocosui/animationbuttonnormal.png",
|
|
|
|
"cocosui/animationbuttonpressed.png");
|
|
|
|
button->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 50));
|
|
|
|
button->setTitleText("Click to change direction!");
|
|
|
|
// button->addTouchEventListener(this, toucheventselector(UIButtonTest::touchEvent));
|
|
|
|
button->addTouchEventListener([=](Ref*, Widget::TouchEventType type){
|
|
|
|
if (type == Widget::TouchEventType::ENDED) {
|
|
|
|
if (loadingBar->getDirection() == LoadingBar::Direction::LEFT) {
|
|
|
|
loadingBar->setDirection(LoadingBar::Direction::RIGHT);
|
|
|
|
}else{
|
|
|
|
loadingBar->setDirection(LoadingBar::Direction::LEFT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
_uiLayer->addChild(button);
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(loadingBar);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UILoadingBarTest_Left::update(float delta)
|
|
|
|
{
|
2013-12-23 15:35:35 +08:00
|
|
|
_count++;
|
|
|
|
if (_count > 100)
|
2013-09-16 20:54:13 +08:00
|
|
|
{
|
2013-12-23 15:35:35 +08:00
|
|
|
_count = 0;
|
2013-09-16 20:54:13 +08:00
|
|
|
}
|
2013-12-23 15:35:35 +08:00
|
|
|
LoadingBar* loadingBar = static_cast<LoadingBar*>(_uiLayer->getChildByTag(0));
|
|
|
|
loadingBar->setPercent(_count);
|
2013-09-16 20:54:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// UILoadingBarTest_Right
|
|
|
|
|
|
|
|
UILoadingBarTest_Right::UILoadingBarTest_Right()
|
2013-12-23 15:35:35 +08:00
|
|
|
: _count(0)
|
2013-09-16 20:54:13 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UILoadingBarTest_Right::~UILoadingBarTest_Right()
|
|
|
|
{
|
|
|
|
unscheduleUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UILoadingBarTest_Right::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
|
|
|
scheduleUpdate();
|
|
|
|
|
2014-06-20 11:18:53 +08:00
|
|
|
Size widgetSize = _widget->getContentSize();
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
// Add the alert
|
2014-04-03 11:34:06 +08:00
|
|
|
Text *alert = Text::create("LoadingBar right", "fonts/Marker Felt.ttf", 30);
|
2013-09-16 20:54:13 +08:00
|
|
|
alert->setColor(Color3B(159, 168, 176));
|
2014-06-20 11:18:53 +08:00
|
|
|
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 1.75f));
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(alert);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
// Create the loading bar
|
2014-04-03 11:34:06 +08:00
|
|
|
LoadingBar* loadingBar = LoadingBar::create("cocosui/sliderProgress.png");
|
2013-12-23 15:35:35 +08:00
|
|
|
loadingBar->setTag(0);
|
2014-05-14 10:48:16 +08:00
|
|
|
loadingBar->setDirection(LoadingBar::Direction::RIGHT);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
loadingBar->setPosition(Vec2(widgetSize.width / 2.0f,
|
2014-06-20 11:18:53 +08:00
|
|
|
widgetSize.height / 2.0f + loadingBar->getContentSize().height / 4.0f));
|
2014-04-03 11:34:06 +08:00
|
|
|
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(loadingBar);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UILoadingBarTest_Right::update(float delta)
|
|
|
|
{
|
2013-12-23 15:35:35 +08:00
|
|
|
_count++;
|
|
|
|
if (_count > 100)
|
2013-09-16 20:54:13 +08:00
|
|
|
{
|
2013-12-23 15:35:35 +08:00
|
|
|
_count = 0;
|
2013-09-16 20:54:13 +08:00
|
|
|
}
|
2013-12-23 15:35:35 +08:00
|
|
|
LoadingBar* loadingBar = static_cast<LoadingBar*>(_uiLayer->getChildByTag(0));
|
|
|
|
loadingBar->setPercent(_count);
|
2013-09-16 20:54:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// UILoadingBarTest_Left_Scale9
|
|
|
|
|
|
|
|
UILoadingBarTest_Left_Scale9::UILoadingBarTest_Left_Scale9()
|
2013-12-23 15:35:35 +08:00
|
|
|
: _count(0)
|
2013-09-16 20:54:13 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UILoadingBarTest_Left_Scale9::~UILoadingBarTest_Left_Scale9()
|
|
|
|
{
|
|
|
|
unscheduleUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UILoadingBarTest_Left_Scale9::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
|
|
|
scheduleUpdate();
|
|
|
|
|
2014-06-20 11:18:53 +08:00
|
|
|
Size widgetSize = _widget->getContentSize();
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
// Add the alert
|
2014-04-03 11:34:06 +08:00
|
|
|
Text* alert = Text::create("LoadingBar left scale9 render", "fonts/Marker Felt.ttf", 20);
|
2013-09-16 20:54:13 +08:00
|
|
|
alert->setColor(Color3B(159, 168, 176));
|
2014-06-20 11:18:53 +08:00
|
|
|
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 2.7f));
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(alert);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
// Create the loading bar
|
2014-04-03 11:34:06 +08:00
|
|
|
LoadingBar* loadingBar = LoadingBar::create("cocosui/slider_bar_active_9patch.png");
|
2013-12-23 15:35:35 +08:00
|
|
|
loadingBar->setTag(0);
|
2013-09-16 20:54:13 +08:00
|
|
|
loadingBar->setScale9Enabled(true);
|
|
|
|
loadingBar->setCapInsets(Rect(0, 0, 0, 0));
|
2014-06-20 14:03:33 +08:00
|
|
|
loadingBar->setContentSize(Size(300, 13));
|
2013-09-16 20:54:13 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
loadingBar->setPosition(Vec2(widgetSize.width / 2.0f,
|
2014-06-20 11:18:53 +08:00
|
|
|
widgetSize.height / 2.0f + loadingBar->getContentSize().height / 4.0f));
|
2014-04-03 11:34:06 +08:00
|
|
|
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(loadingBar);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UILoadingBarTest_Left_Scale9::update(float delta)
|
|
|
|
{
|
2013-12-23 15:35:35 +08:00
|
|
|
_count++;
|
|
|
|
if (_count > 100)
|
2013-09-16 20:54:13 +08:00
|
|
|
{
|
2013-12-23 15:35:35 +08:00
|
|
|
_count = 0;
|
2013-09-16 20:54:13 +08:00
|
|
|
}
|
2013-12-23 15:35:35 +08:00
|
|
|
LoadingBar* loadingBar = static_cast<LoadingBar*>(_uiLayer->getChildByTag(0));
|
|
|
|
loadingBar->setPercent(_count);
|
2013-09-16 20:54:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// UILoadingBarTest_Right_Scale9
|
|
|
|
|
|
|
|
UILoadingBarTest_Right_Scale9::UILoadingBarTest_Right_Scale9()
|
2013-12-23 15:35:35 +08:00
|
|
|
: _count(0)
|
2013-09-16 20:54:13 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UILoadingBarTest_Right_Scale9::~UILoadingBarTest_Right_Scale9()
|
|
|
|
{
|
|
|
|
unscheduleUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UILoadingBarTest_Right_Scale9::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
|
|
|
scheduleUpdate();
|
|
|
|
|
2014-06-20 11:18:53 +08:00
|
|
|
Size widgetSize = _widget->getContentSize();
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
// Add the alert
|
2014-04-03 11:34:06 +08:00
|
|
|
Text *alert = Text::create("LoadingBar right scale9 render", "fonts/Marker Felt.ttf", 20);
|
2013-09-16 20:54:13 +08:00
|
|
|
alert->setColor(Color3B(159, 168, 176));
|
2014-06-20 11:18:53 +08:00
|
|
|
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 2.7f));
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(alert);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
// Create the loading bar
|
2014-04-03 11:34:06 +08:00
|
|
|
LoadingBar* loadingBar = LoadingBar::create("cocosui/slider_bar_active_9patch.png");
|
2013-12-23 15:35:35 +08:00
|
|
|
loadingBar->setTag(0);
|
2013-09-16 20:54:13 +08:00
|
|
|
loadingBar->setScale9Enabled(true);
|
|
|
|
loadingBar->setCapInsets(Rect(0, 0, 0, 0));
|
2014-06-20 14:03:33 +08:00
|
|
|
loadingBar->setContentSize(Size(300, 13));
|
2014-05-14 10:48:16 +08:00
|
|
|
loadingBar->setDirection(LoadingBar::Direction::RIGHT);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
loadingBar->setPosition(Vec2(widgetSize.width / 2.0f,
|
2014-06-20 11:18:53 +08:00
|
|
|
widgetSize.height / 2.0f + loadingBar->getContentSize().height / 4.0f));
|
2014-04-03 11:34:06 +08:00
|
|
|
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(loadingBar);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UILoadingBarTest_Right_Scale9::update(float delta)
|
|
|
|
{
|
2013-12-23 15:35:35 +08:00
|
|
|
_count++;
|
|
|
|
if (_count > 100)
|
2013-09-16 20:54:13 +08:00
|
|
|
{
|
2013-12-23 15:35:35 +08:00
|
|
|
_count = 0;
|
2013-09-16 20:54:13 +08:00
|
|
|
}
|
2013-12-23 15:35:35 +08:00
|
|
|
LoadingBar* loadingBar = static_cast<LoadingBar*>(_uiLayer->getChildByTag(0));
|
|
|
|
loadingBar->setPercent(_count);
|
2013-09-16 20:54:13 +08:00
|
|
|
}
|
|
|
|
|
2015-01-20 20:57:54 +08:00
|
|
|
// UILoadingBarTest_Scale9_State_Change
|
|
|
|
|
|
|
|
UILoadingBarTest_Scale9_State_Change::UILoadingBarTest_Scale9_State_Change()
|
|
|
|
: _count(0)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UILoadingBarTest_Scale9_State_Change::~UILoadingBarTest_Scale9_State_Change()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UILoadingBarTest_Scale9_State_Change::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);
|
|
|
|
|
|
|
|
// Create the loading bar
|
|
|
|
LoadingBar* loadingBar = LoadingBar::create("cocosui/sliderThumb.png");
|
|
|
|
loadingBar->setTag(0);
|
|
|
|
loadingBar->ignoreContentAdaptWithSize(false);
|
|
|
|
//loadingBar->setScale9Enabled(true);
|
|
|
|
loadingBar->setCapInsets(Rect(0, 0, 0, 0));
|
|
|
|
loadingBar->setContentSize(Size(200, 80));
|
|
|
|
loadingBar->setDirection(LoadingBar::Direction::LEFT);
|
|
|
|
loadingBar->setPercent(100);
|
|
|
|
|
|
|
|
loadingBar->setTouchEnabled(true);
|
|
|
|
loadingBar->addTouchEventListener([=](Ref* sender, Widget::TouchEventType type){
|
|
|
|
if (type == Widget::TouchEventType::ENDED) {
|
|
|
|
if (loadingBar->isScale9Enabled())
|
|
|
|
{
|
|
|
|
loadingBar->setScale9Enabled(false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
loadingBar->setScale9Enabled(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
loadingBar->setPosition(Vec2(widgetSize.width / 2.0f,
|
|
|
|
widgetSize.height / 2.0f + loadingBar->getContentSize().height / 4.0f));
|
|
|
|
|
|
|
|
_uiLayer->addChild(loadingBar);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2015-01-26 13:49:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// UILoadingBarReloadTexture
|
|
|
|
|
|
|
|
UILoadingBarReloadTexture::UILoadingBarReloadTexture()
|
|
|
|
: _count(0)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UILoadingBarReloadTexture::~UILoadingBarReloadTexture()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UILoadingBarReloadTexture::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
|
|
|
Size widgetSize = _widget->getContentSize();
|
|
|
|
|
|
|
|
// Add the alert
|
2015-01-26 14:46:45 +08:00
|
|
|
Text *alert = Text::create("Click button to Toggle Scale9 and switch Texture.", "fonts/Marker Felt.ttf", 20);
|
2015-01-26 13:49:54 +08:00
|
|
|
alert->setColor(Color3B(159, 168, 176));
|
2015-01-26 14:46:45 +08:00
|
|
|
alert->setPosition(Vec2(widgetSize.width / 2.0f,
|
|
|
|
widgetSize.height / 2.0f - alert->getContentSize().height * 2.7f));
|
2015-01-26 13:49:54 +08:00
|
|
|
_uiLayer->addChild(alert);
|
|
|
|
|
|
|
|
LoadingBar* loadingBar = LoadingBar::create("cocosui/slider_bar_active_9patch.png");
|
|
|
|
loadingBar->setTag(0);
|
|
|
|
loadingBar->ignoreContentAdaptWithSize(false);
|
2015-01-26 14:39:44 +08:00
|
|
|
// loadingBar->setScale9Enabled(true);
|
2015-01-26 13:49:54 +08:00
|
|
|
loadingBar->setCapInsets(Rect(0, 0, 0, 0));
|
|
|
|
loadingBar->setContentSize(Size(300, 13));
|
|
|
|
loadingBar->setName("texture0");
|
|
|
|
loadingBar->setDirection(LoadingBar::Direction::RIGHT);
|
2015-01-26 14:39:44 +08:00
|
|
|
loadingBar->setPercent(70);
|
2015-01-26 13:49:54 +08:00
|
|
|
loadingBar->setPosition(Vec2(widgetSize.width / 2.0f,
|
|
|
|
widgetSize.height / 2.0f + loadingBar->getContentSize().height / 4.0f));
|
|
|
|
|
|
|
|
_uiLayer->addChild(loadingBar);
|
|
|
|
|
2015-01-26 14:39:44 +08:00
|
|
|
auto buttonScale9 = Button::create("cocosui/animationbuttonnormal.png",
|
|
|
|
"cocosui/animationbuttonpressed.png");
|
2015-01-26 13:49:54 +08:00
|
|
|
buttonScale9->setTitleText("ToggleScale9");
|
|
|
|
buttonScale9->addClickEventListener([=](Ref*){
|
|
|
|
loadingBar->setScale9Enabled(!loadingBar->isScale9Enabled());
|
|
|
|
});
|
|
|
|
buttonScale9->setPosition(loadingBar->getPosition() + Vec2(-50,50));
|
|
|
|
_uiLayer->addChild(buttonScale9);
|
|
|
|
|
2015-01-26 14:39:44 +08:00
|
|
|
auto buttonChangeTexture = Button::create("cocosui/animationbuttonnormal.png",
|
|
|
|
"cocosui/animationbuttonpressed.png");
|
2015-01-26 13:49:54 +08:00
|
|
|
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);
|
2015-01-20 20:57:54 +08:00
|
|
|
}
|