axmol/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp

328 lines
8.2 KiB
C++
Raw Normal View History

2013-09-16 20:54:13 +08:00
#include "UILoadingBarTest.h"
// 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();
2013-12-23 15:35:35 +08:00
Size widgetSize = _widget->getSize();
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));
2013-12-23 15:35:35 +08:00
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f));
_uiLayer->addChild(alert);
2013-09-16 20:54:13 +08:00
// Create the loading bar
LoadingBar* loadingBar = LoadingBar::create("cocosui/sliderProgress.png");
2013-12-23 15:35:35 +08:00
loadingBar->setTag(0);
2014-04-03 11:34:06 +08:00
loadingBar->setPosition(Point(widgetSize.width / 2.0f,
widgetSize.height / 2.0f + loadingBar->getSize().height / 4.0f));
2013-09-16 20:54:13 +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::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
}
void UILoadingBarTest_Left::previousCallback(Ref* sender, TouchEventType type)
2013-09-16 20:54:13 +08:00
{
2013-11-07 21:10:48 +08:00
if (type == TOUCH_EVENT_ENDED)
{
unscheduleUpdate();
UIScene::previousCallback(sender, type);
}
2013-09-16 20:54:13 +08:00
}
void UILoadingBarTest_Left::restartCallback(Ref* sender, TouchEventType type)
2013-09-16 20:54:13 +08:00
{
2013-11-07 21:10:48 +08:00
if (type == TOUCH_EVENT_ENDED)
{
unscheduleUpdate();
UIScene::restartCallback(sender, type);
}
2013-09-16 20:54:13 +08:00
}
void UILoadingBarTest_Left::nextCallback(Ref* sender, TouchEventType type)
2013-09-16 20:54:13 +08:00
{
2013-11-07 21:10:48 +08:00
if (type == TOUCH_EVENT_ENDED)
{
unscheduleUpdate();
UIScene::nextCallback(sender, type);
}
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();
2013-12-23 15:35:35 +08:00
Size widgetSize = _widget->getSize();
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));
2013-12-23 15:35:35 +08:00
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f));
_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);
2013-09-16 20:54:13 +08:00
loadingBar->setDirection(LoadingBarTypeRight);
2014-04-03 11:34:06 +08:00
loadingBar->setPosition(Point(widgetSize.width / 2.0f,
widgetSize.height / 2.0f + loadingBar->getSize().height / 4.0f));
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
}
void UILoadingBarTest_Right::previousCallback(Ref* sender, TouchEventType type)
2013-09-16 20:54:13 +08:00
{
2013-11-07 21:10:48 +08:00
if (type == TOUCH_EVENT_ENDED)
{
unscheduleUpdate();
UIScene::previousCallback(sender, type);
}
2013-09-16 20:54:13 +08:00
}
void UILoadingBarTest_Right::restartCallback(Ref* sender, TouchEventType type)
2013-09-16 20:54:13 +08:00
{
2013-11-07 21:10:48 +08:00
if (type == TOUCH_EVENT_ENDED)
{
unscheduleUpdate();
UIScene::restartCallback(sender, type);
}
2013-09-16 20:54:13 +08:00
}
void UILoadingBarTest_Right::nextCallback(Ref* sender, TouchEventType type)
2013-09-16 20:54:13 +08:00
{
2013-11-07 21:10:48 +08:00
if (type == TOUCH_EVENT_ENDED)
{
unscheduleUpdate();
UIScene::nextCallback(sender, type);
}
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();
2013-12-23 15:35:35 +08:00
Size widgetSize = _widget->getSize();
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));
2013-12-23 15:35:35 +08:00
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 2.7f));
_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));
2013-12-23 15:35:35 +08:00
loadingBar->setSize(Size(300, loadingBar->getContentSize().height));
2013-09-16 20:54:13 +08:00
2014-04-03 11:34:06 +08:00
loadingBar->setPosition(Point(widgetSize.width / 2.0f,
widgetSize.height / 2.0f + loadingBar->getSize().height / 4.0f));
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
}
void UILoadingBarTest_Left_Scale9::previousCallback(Ref* sender, TouchEventType type)
2013-09-16 20:54:13 +08:00
{
2013-11-07 21:10:48 +08:00
if (type == TOUCH_EVENT_ENDED)
{
unscheduleUpdate();
UIScene::previousCallback(sender, type);
}
2013-09-16 20:54:13 +08:00
}
void UILoadingBarTest_Left_Scale9::restartCallback(Ref* sender, TouchEventType type)
2013-09-16 20:54:13 +08:00
{
2013-11-07 21:10:48 +08:00
if (type == TOUCH_EVENT_ENDED)
{
unscheduleUpdate();
UIScene::restartCallback(sender, type);
}
2013-09-16 20:54:13 +08:00
}
void UILoadingBarTest_Left_Scale9::nextCallback(Ref* sender, TouchEventType type)
2013-09-16 20:54:13 +08:00
{
2013-11-07 21:10:48 +08:00
if (type == TOUCH_EVENT_ENDED)
{
unscheduleUpdate();
UIScene::nextCallback(sender, type);
}
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();
2013-12-23 15:35:35 +08:00
Size widgetSize = _widget->getSize();
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));
2013-12-23 15:35:35 +08:00
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 2.7f));
_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));
2013-12-23 15:35:35 +08:00
loadingBar->setSize(Size(300, loadingBar->getContentSize().height));
2013-09-16 20:54:13 +08:00
loadingBar->setDirection(LoadingBarTypeRight);
2014-04-03 11:34:06 +08:00
loadingBar->setPosition(Point(widgetSize.width / 2.0f,
widgetSize.height / 2.0f + loadingBar->getSize().height / 4.0f));
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
}
void UILoadingBarTest_Right_Scale9::previousCallback(Ref* sender, TouchEventType type)
2013-09-16 20:54:13 +08:00
{
2013-11-07 21:10:48 +08:00
if (type == TOUCH_EVENT_ENDED)
{
unscheduleUpdate();
UIScene::previousCallback(sender, type);
}
2013-09-16 20:54:13 +08:00
}
void UILoadingBarTest_Right_Scale9::restartCallback(Ref* sender, TouchEventType type)
2013-09-16 20:54:13 +08:00
{
2013-11-07 21:10:48 +08:00
if (type == TOUCH_EVENT_ENDED)
{
unscheduleUpdate();
UIScene::restartCallback(sender, type);
}
2013-09-16 20:54:13 +08:00
}
void UILoadingBarTest_Right_Scale9::nextCallback(Ref* sender, TouchEventType type)
2013-09-16 20:54:13 +08:00
{
2013-11-07 21:10:48 +08:00
if (type == TOUCH_EVENT_ENDED)
{
unscheduleUpdate();
UIScene::nextCallback(sender, type);
}
2014-03-11 17:13:54 +08:00
}