bool UILoadingBarReloadTexture::init() { if (UIScene::init()) { Size widgetSize = _widget->getContentSize(); // Add the alert Text *alert = Text::create("Click button to Toggle Scale9 and switch Texture.", "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->setPercent(70); loadingBar->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + loadingBar->getContentSize().height / 4.0f)); _uiLayer->addChild(loadingBar); auto buttonScale9 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); buttonScale9->setTitleText("ToggleScale9"); buttonScale9->addClickEventListener([=](Ref*){ loadingBar->setScale9Enabled(!loadingBar->isScale9Enabled()); }); buttonScale9->setPosition(loadingBar->getPosition() + Vec2(-50,50)); _uiLayer->addChild(buttonScale9); auto buttonChangeTexture = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); 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; }
bool UILoadingBarTest_Right_Scale9::init() { if (UIScene::init()) { scheduleUpdate(); 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/slider_bar_active_9patch.png"); loadingBar->setTag(0); loadingBar->setScale9Enabled(true); loadingBar->setCapInsets(Rect(0, 0, 0, 0)); loadingBar->setContentSize(Size(300, 13)); loadingBar->setDirection(LoadingBar::Direction::RIGHT); loadingBar->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + loadingBar->getContentSize().height / 4.0f)); _uiLayer->addChild(loadingBar); return true; } return false; }
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; }
void LoadingBarReader::setPropsFromJsonDictionary(Widget *widget, const rapidjson::Value &options) { WidgetReader::setPropsFromJsonDictionary(widget, options); LoadingBar* loadingBar = static_cast<LoadingBar*>(widget); const rapidjson::Value& imageFileNameDic = DICTOOL->getSubDictionary_json(options, P_TextureData); int imageFileNameType = DICTOOL->getIntValue_json(imageFileNameDic, P_ResourceType); std::string imageFileName = this->getResourcePath(imageFileNameDic, P_Path, (Widget::TextureResType)imageFileNameType); loadingBar->loadTexture(imageFileName, (Widget::TextureResType)imageFileNameType); /* gui mark add load bar scale9 parse */ bool scale9Enable = DICTOOL->getBooleanValue_json(options, P_Scale9Enable); loadingBar->setScale9Enabled(scale9Enable); float cx = DICTOOL->getFloatValue_json(options, P_CapInsetsX); float cy = DICTOOL->getFloatValue_json(options, P_CapInsetsY); float cw = DICTOOL->getFloatValue_json(options, P_CapInsetsWidth,1); float ch = DICTOOL->getFloatValue_json(options, P_CapInsetsHeight,1); if (scale9Enable) { loadingBar->setCapInsets(Rect(cx, cy, cw, ch)); } float width = DICTOOL->getFloatValue_json(options, P_Width); float height = DICTOOL->getFloatValue_json(options, P_Height); loadingBar->setContentSize(Size(width, height)); /**/ loadingBar->setDirection(LoadingBar::Direction(DICTOOL->getIntValue_json(options, P_Direction))); loadingBar->setPercent(DICTOOL->getIntValue_json(options, P_Percent,100)); WidgetReader::setColorPropsFromJsonDictionary(widget, options); }
bool UILoadingBarIssue12249::init() { if (UIScene::init()) { scheduleUpdate(); Size widgetSize = _widget->getContentSize(); // Add the alert Text* alert = Text::create("Test LoadingBar Change Direction", "fonts/Marker Felt.ttf", 30); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 1.75f)); _uiLayer->addChild(alert); // Create the loading bar LoadingBar* loadingBar = LoadingBar::create("cocosui/sliderProgress.png"); loadingBar->setScale9Enabled(true); loadingBar->setContentSize(Size(200, loadingBar->getContentSize().height * 1.5)); loadingBar->setTag(0); loadingBar->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + loadingBar->getContentSize().height / 4.0f)); LoadingBar* loadingBarCopy = LoadingBar::create(); loadingBarCopy->setScale9Enabled(true); loadingBarCopy->loadTexture("cocosui/sliderProgress.png"); loadingBarCopy->setContentSize(Size(200, loadingBarCopy->getContentSize().height * 1.5)); loadingBarCopy->setTag(1); loadingBarCopy->setPosition(loadingBar->getPosition() + Vec2(0, -40)); loadingBarCopy->setDirection(LoadingBar::Direction::RIGHT); 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([=](Ref*, Widget::TouchEventType type) { if (type == Widget::TouchEventType::ENDED) { if (loadingBar->getDirection() == LoadingBar::Direction::LEFT) { loadingBar->setDirection(LoadingBar::Direction::RIGHT); loadingBarCopy->setDirection(LoadingBar::Direction::LEFT); } else { loadingBar->setDirection(LoadingBar::Direction::LEFT); loadingBarCopy->setDirection(LoadingBar::Direction::RIGHT); } } }); _uiLayer->addChild(loadingBar,1); _uiLayer->addChild(loadingBarCopy,2); _uiLayer->addChild(button); return true; } return false; }