28using namespace cocos2d::ui;
30UILoadingBarTests::UILoadingBarTests()
61 Size widgetSize =
_widget->getContentSize();
64 Text* alert = Text::create(
"Test LoadingBar Change Direction",
65 "fonts/Marker Felt.ttf", 30);
66 alert->setColor(Color3B(159, 168, 176));
67 alert->setPosition(Vec2(widgetSize.width / 2.0f,
68 widgetSize.height / 2.0f - alert->getContentSize().height * 1.75f));
72 LoadingBar* loadingBar = LoadingBar::create(
"cocosui/sliderProgress.png");
73 loadingBar->setTag(0);
74 loadingBar->setPosition(Vec2(widgetSize.width / 2.0f,
75 widgetSize.height / 2.0f + loadingBar->getContentSize().height / 4.0f));
77 auto loadingBarCopy = (LoadingBar*)loadingBar->clone();
78 loadingBarCopy->setTag(1);
79 loadingBarCopy->setPosition(loadingBar->getPosition()
81 loadingBarCopy->setDirection(LoadingBar::Direction::RIGHT);
83 Button* button = Button::create(
"cocosui/animationbuttonnormal.png",
84 "cocosui/animationbuttonpressed.png");
85 button->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 50));
86 button->setTitleText(
"Click to change direction!");
88 button->addTouchEventListener([=](Ref*, Widget::TouchEventType type)
90 if (type == Widget::TouchEventType::ENDED)
92 if (loadingBar->getDirection() == LoadingBar::Direction::LEFT)
94 loadingBar->setDirection(LoadingBar::Direction::RIGHT);
95 loadingBarCopy->setDirection(LoadingBar::Direction::LEFT);
99 loadingBar->setDirection(LoadingBar::Direction::LEFT);
100 loadingBarCopy->setDirection(LoadingBar::Direction::RIGHT);
105 _uiLayer->addChild(loadingBarCopy,2);
110 TTFConfig ttfConfig(
"fonts/arial.ttf", 15);
111 auto label1 = Label::createWithTTF(ttfConfig,
"Print Resources");
114 auto pMenu1 = Menu::create(item1,
nullptr);
115 pMenu1->setPosition(Vec2(0, 0));
116 this->addChild(pMenu1, 10);
130 LoadingBar* loadingBar =
static_cast<LoadingBar*
>(
_uiLayer->getChildByTag(0));
131 LoadingBar* loadingBarCopy =
static_cast<LoadingBar*
>(
_uiLayer->getChildByTag(1));
132 loadingBar->setPercent(
_count);
133 loadingBarCopy->setPercent(
_count);
138 cocos2d::ResourceData textureFile =
_loadingBar->getRenderFile();
139 CCLOG(
"textureFile Name : %s, Type: %d", textureFile.file.c_str(), textureFile.type);
161 Size widgetSize =
_widget->getContentSize();
164 Text *alert = Text::create(
"LoadingBar right",
"fonts/Marker Felt.ttf", 30);
165 alert->setColor(Color3B(159, 168, 176));
166 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 1.75f));
170 LoadingBar* loadingBar = LoadingBar::create(
"cocosui/sliderProgress.png");
171 loadingBar->setTag(0);
172 loadingBar->setDirection(LoadingBar::Direction::RIGHT);
174 loadingBar->setPosition(Vec2(widgetSize.width / 2.0f,
175 widgetSize.height / 2.0f + loadingBar->getContentSize().height / 4.0f));
191 LoadingBar* loadingBar =
static_cast<LoadingBar*
>(
_uiLayer->getChildByTag(0));
192 loadingBar->setPercent(
_count);
214 Size widgetSize =
_widget->getContentSize();
217 Text* alert = Text::create(
"LoadingBar left scale9 render",
"fonts/Marker Felt.ttf", 20);
218 alert->setColor(Color3B(159, 168, 176));
219 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 2.7f));
223 LoadingBar* loadingBar = LoadingBar::create(
"cocosui/slider_bar_active_9patch.png");
224 loadingBar->setTag(0);
225 loadingBar->setScale9Enabled(
true);
226 loadingBar->setCapInsets(Rect(0, 0, 0, 0));
227 loadingBar->setContentSize(Size(300, 13));
229 loadingBar->setPosition(Vec2(widgetSize.width / 2.0f,
230 widgetSize.height / 2.0f + loadingBar->getContentSize().height / 4.0f));
246 LoadingBar* loadingBar =
static_cast<LoadingBar*
>(
_uiLayer->getChildByTag(0));
247 loadingBar->setPercent(
_count);
269 Size widgetSize =
_widget->getContentSize();
272 Text *alert = Text::create(
"LoadingBar right scale9 render",
"fonts/Marker Felt.ttf", 20);
273 alert->setColor(Color3B(159, 168, 176));
274 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 2.7f));
278 LoadingBar* loadingBar = LoadingBar::create(
"cocosui/slider_bar_active_9patch.png");
279 loadingBar->setTag(0);
280 loadingBar->setScale9Enabled(
true);
281 loadingBar->setCapInsets(Rect(0, 0, 0, 0));
282 loadingBar->setContentSize(Size(300, 13));
283 loadingBar->setDirection(LoadingBar::Direction::RIGHT);
285 loadingBar->setPosition(Vec2(widgetSize.width / 2.0f,
286 widgetSize.height / 2.0f + loadingBar->getContentSize().height / 4.0f));
302 LoadingBar* loadingBar =
static_cast<LoadingBar*
>(
_uiLayer->getChildByTag(0));
303 loadingBar->setPercent(
_count);
323 Size widgetSize =
_widget->getContentSize();
326 Text *alert = Text::create(
"LoadingBar right scale9 render",
"fonts/Marker Felt.ttf", 20);
327 alert->setColor(Color3B(159, 168, 176));
328 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 2.7f));
332 LoadingBar* loadingBar = LoadingBar::create(
"cocosui/sliderThumb.png");
333 loadingBar->setTag(0);
334 loadingBar->ignoreContentAdaptWithSize(
false);
336 loadingBar->setCapInsets(Rect(0, 0, 0, 0));
337 loadingBar->setContentSize(Size(200, 80));
338 loadingBar->setDirection(LoadingBar::Direction::LEFT);
339 loadingBar->setPercent(100);
341 loadingBar->setTouchEnabled(
true);
342 loadingBar->addTouchEventListener([=](Ref* sender, Widget::TouchEventType type){
343 if (type == Widget::TouchEventType::ENDED) {
344 if (loadingBar->isScale9Enabled())
346 loadingBar->setScale9Enabled(false);
349 loadingBar->setScale9Enabled(
true);
353 loadingBar->setPosition(Vec2(widgetSize.width / 2.0f,
354 widgetSize.height / 2.0f + loadingBar->getContentSize().height / 4.0f));
381 Size widgetSize =
_widget->getContentSize();
384 Text *alert = Text::create(
"Click button to Toggle Scale9 and switch Texture.",
"fonts/Marker Felt.ttf", 20);
385 alert->setColor(Color3B(159, 168, 176));
386 alert->setPosition(Vec2(widgetSize.width / 2.0f,
387 widgetSize.height / 2.0f - alert->getContentSize().height * 2.7f));
390 LoadingBar* loadingBar = LoadingBar::create(
"cocosui/slider_bar_active_9patch.png");
391 loadingBar->setTag(0);
392 loadingBar->ignoreContentAdaptWithSize(
false);
394 loadingBar->setCapInsets(Rect(0, 0, 0, 0));
395 loadingBar->setContentSize(Size(300, 13));
396 loadingBar->setName(
"texture0");
397 loadingBar->setDirection(LoadingBar::Direction::RIGHT);
398 loadingBar->setPercent(70);
399 loadingBar->setPosition(Vec2(widgetSize.width / 2.0f,
400 widgetSize.height / 2.0f + loadingBar->getContentSize().height / 4.0f));
404 auto buttonScale9 = Button::create(
"cocosui/animationbuttonnormal.png",
405 "cocosui/animationbuttonpressed.png");
406 buttonScale9->setTitleText(
"ToggleScale9");
407 buttonScale9->addClickEventListener([=](Ref*){
408 loadingBar->setScale9Enabled(!loadingBar->isScale9Enabled());
410 buttonScale9->setPosition(loadingBar->getPosition() + Vec2(-50,50));
413 auto buttonChangeTexture = Button::create(
"cocosui/animationbuttonnormal.png",
414 "cocosui/animationbuttonpressed.png");
415 buttonChangeTexture->setTitleText(
"ChangeTexture");
416 buttonChangeTexture->addClickEventListener([=](Ref*){
417 auto name = loadingBar->getName();
418 if (name ==
"texture0")
420 loadingBar->loadTexture(
"cocosui/slider_bar_active_9patch2.png");
421 loadingBar->setName(
"texture1");
425 loadingBar->loadTexture(
"cocosui/slider_bar_active_9patch.png");
426 loadingBar->setName(
"texture0");
429 buttonChangeTexture->setPosition(loadingBar->getPosition() + Vec2(50,50));
430 _uiLayer->addChild(buttonChangeTexture);
432 this->scheduleUpdate();
445 LoadingBar* loadingBar =
static_cast<LoadingBar*
>(
_uiLayer->getChildByTag(0));
446 loadingBar->setPercent(
_count);
469 Size widgetSize =
_widget->getContentSize();
472 Text* alert = Text::create(
"Test LoadingBar Change Direction",
473 "fonts/Marker Felt.ttf", 30);
474 alert->setColor(Color3B(159, 168, 176));
475 alert->setPosition(Vec2(widgetSize.width / 2.0f,
476 widgetSize.height / 2.0f - alert->getContentSize().height * 1.75f));
480 LoadingBar* loadingBar = LoadingBar::create(
"cocosui/sliderProgress.png");
481 loadingBar->setScale9Enabled(
true);
482 loadingBar->setContentSize(Size(200, loadingBar->getContentSize().height * 1.5));
483 loadingBar->setTag(0);
484 loadingBar->setPosition(Vec2(widgetSize.width / 2.0f,
485 widgetSize.height / 2.0f + loadingBar->getContentSize().height / 4.0f));
487 LoadingBar* loadingBarCopy = LoadingBar::create();
488 loadingBarCopy->setScale9Enabled(
true);
489 loadingBarCopy->loadTexture(
"cocosui/sliderProgress.png");
490 loadingBarCopy->setContentSize(Size(200, loadingBarCopy->getContentSize().height * 1.5));
491 loadingBarCopy->setTag(1);
492 loadingBarCopy->setPosition(loadingBar->getPosition()
494 loadingBarCopy->setDirection(LoadingBar::Direction::RIGHT);
496 Button* button = Button::create(
"cocosui/animationbuttonnormal.png",
497 "cocosui/animationbuttonpressed.png");
498 button->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 50));
499 button->setTitleText(
"Click to change direction!");
501 button->addTouchEventListener([=](Ref*, Widget::TouchEventType type)
503 if (type == Widget::TouchEventType::ENDED)
505 if (loadingBar->getDirection() == LoadingBar::Direction::LEFT)
507 loadingBar->setDirection(LoadingBar::Direction::RIGHT);
508 loadingBarCopy->setDirection(LoadingBar::Direction::LEFT);
512 loadingBar->setDirection(LoadingBar::Direction::LEFT);
513 loadingBarCopy->setDirection(LoadingBar::Direction::RIGHT);
518 _uiLayer->addChild(loadingBarCopy,2);
533 LoadingBar* loadingBar =
static_cast<LoadingBar*
>(
_uiLayer->getChildByTag(0));
534 LoadingBar* loadingBarCopy =
static_cast<LoadingBar*
>(
_uiLayer->getChildByTag(1));
535 loadingBar->setPercent(
_count);
536 loadingBarCopy->setPercent(
_count);
558 Size widgetSize =
_widget->getContentSize();
561 Text* alert = Text::create(
"Test LoadingBar Change Direction",
562 "fonts/Marker Felt.ttf", 30);
563 alert->setColor(Color3B(159, 168, 176));
564 alert->setPosition(Vec2(widgetSize.width / 2.0f,
565 widgetSize.height / 2.0f - alert->getContentSize().height * 1.75f));
569 LoadingBar* loadingBar = LoadingBar::create(
"cocosui/sliderProgress.png");
570 loadingBar->setTag(0);
571 loadingBar->setPercent(80);
572 loadingBar->setPosition(Vec2(widgetSize.width / 2.0f,
573 widgetSize.height / 2.0f + loadingBar->getContentSize().height / 4.0f));
575 auto loadingBarCopy = (LoadingBar*)loadingBar->clone();
576 loadingBarCopy->setTag(1);
577 loadingBarCopy->setPosition(loadingBar->getPosition()
579 loadingBarCopy->setDirection(LoadingBar::Direction::RIGHT);
581 Button* button = Button::create(
"cocosui/animationbuttonnormal.png",
582 "cocosui/animationbuttonpressed.png");
583 button->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 50));
584 button->setTitleText(
"Click to change direction!");
586 button->addTouchEventListener([=](Ref*, Widget::TouchEventType type)
588 if (type == Widget::TouchEventType::ENDED)
590 if (loadingBar->getDirection() == LoadingBar::Direction::LEFT)
592 loadingBar->setDirection(LoadingBar::Direction::RIGHT);
593 loadingBarCopy->setDirection(LoadingBar::Direction::LEFT);
597 loadingBar->setDirection(LoadingBar::Direction::LEFT);
598 loadingBarCopy->setDirection(LoadingBar::Direction::RIGHT);
603 _uiLayer->addChild(loadingBarCopy, 2);
#define ADD_TEST_CASE(__className__)
virtual bool init() override
~UILoadingBarIssue12249()
void update(float delta) override
virtual bool init() override
UILoadingBarReloadTexture()
~UILoadingBarReloadTexture()
void update(float dt) override
cocos2d::ui::LoadingBar * _loadingBar
~UILoadingBarTest_Direction()
UILoadingBarTest_Direction()
virtual bool init() override
void update(float delta) override
UILoadingBarTest_Left_Scale9()
virtual bool init() override
~UILoadingBarTest_Left_Scale9()
void printWidgetResources(cocos2d::Ref *sender)
virtual bool init() override
cocos2d::ui::LoadingBar * _loadingBar
void update(float delta) override
virtual bool init() override
~UILoadingBarTest_Right_Scale9()
UILoadingBarTest_Right_Scale9()
void update(float delta) override
virtual bool init() override
void update(float delta) override
~UILoadingBarTest_Right()
~UILoadingBarTest_Scale9_State_Change()
UILoadingBarTest_Scale9_State_Change()
virtual bool init() override
cocos2d::Layer * _uiLayer
virtual bool init() override
cocos2d::ui::Layout * _widget
static cocos2d::Vec2 bottom()
static cocos2d::Vec2 left()