2018-01-29 16:25:32 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-07-09 22:23:34 +08:00
|
|
|
https://axis-project.github.io/
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2018-01-29 16:25:32 +08:00
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2018-01-29 16:25:32 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2018-01-29 16:25:32 +08:00
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-09-16 20:54:13 +08:00
|
|
|
#include "UISliderTest.h"
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
USING_NS_AX;
|
|
|
|
using namespace axis::ui;
|
2015-04-09 12:23:47 +08:00
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
UISliderTests::UISliderTests()
|
|
|
|
{
|
|
|
|
ADD_TEST_CASE(UISliderTest);
|
|
|
|
ADD_TEST_CASE(UISliderTest_Scale9);
|
|
|
|
ADD_TEST_CASE(UISliderTest_Scale9_State_Change);
|
|
|
|
ADD_TEST_CASE(UISliderNormalDefaultTest);
|
|
|
|
ADD_TEST_CASE(UISliderDisabledDefaultTest);
|
2015-06-15 18:31:21 +08:00
|
|
|
ADD_TEST_CASE(UISliderNewEventCallbackTest);
|
2015-12-09 17:15:09 +08:00
|
|
|
ADD_TEST_CASE(UISliderIssue12249Test);
|
2015-04-03 14:31:03 +08:00
|
|
|
}
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
// UISliderTest
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
UISliderTest::UISliderTest() : _displayValueLabel(nullptr) {}
|
2013-09-16 20:54:13 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
UISliderTest::~UISliderTest() {}
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
bool UISliderTest::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
2014-06-20 11:18:53 +08:00
|
|
|
Size widgetSize = _widget->getContentSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2013-09-16 20:54:13 +08:00
|
|
|
// Add a label in which the slider alert will be displayed
|
2015-04-28 10:48:15 +08:00
|
|
|
_displayValueLabel = TextBMFont::create("Move the slider thumb", "ccb/markerfelt24shadow.fnt");
|
2019-09-24 11:31:35 +08:00
|
|
|
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
|
2014-05-15 01:07:09 +08:00
|
|
|
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(_displayValueLabel);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2013-09-16 20:54:13 +08:00
|
|
|
// Add the alert
|
2021-12-28 16:06:23 +08:00
|
|
|
Text* alert = Text::create("Slider", "fonts/Marker Felt.ttf", 30);
|
2013-09-16 20:54:13 +08:00
|
|
|
alert->setColor(Color3B(159, 168, 176));
|
2021-12-28 16:06:23 +08:00
|
|
|
alert->setPosition(
|
|
|
|
Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 1.75f));
|
|
|
|
_uiLayer->addChild(alert);
|
|
|
|
|
2013-09-16 20:54:13 +08:00
|
|
|
// Create the slider
|
2013-12-23 15:35:35 +08:00
|
|
|
Slider* slider = Slider::create();
|
2014-03-11 17:13:54 +08:00
|
|
|
slider->loadBarTexture("cocosui/sliderTrack.png");
|
|
|
|
slider->loadSlidBallTextures("cocosui/sliderThumb.png", "cocosui/sliderThumb.png", "");
|
|
|
|
slider->loadProgressBarTexture("cocosui/sliderProgress.png");
|
2015-06-15 18:31:21 +08:00
|
|
|
slider->setMaxPercent(10000);
|
2021-12-28 16:06:23 +08:00
|
|
|
slider->setPosition(
|
|
|
|
Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f /* + slider->getSize().height * 2.0f*/));
|
2022-07-15 19:17:01 +08:00
|
|
|
slider->addEventListener(AX_CALLBACK_2(UISliderTest::sliderEvent, this));
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(slider);
|
2014-03-04 16:51:35 +08:00
|
|
|
|
2015-11-30 16:17:13 +08:00
|
|
|
_slider = slider;
|
|
|
|
|
|
|
|
TTFConfig ttfConfig("fonts/arial.ttf", 15);
|
|
|
|
auto label1 = Label::createWithTTF(ttfConfig, "Print Resources");
|
2022-07-15 19:17:01 +08:00
|
|
|
auto item1 = MenuItemLabel::create(label1, AX_CALLBACK_1(UISliderTest::printWidgetResources, this));
|
2021-12-28 16:06:23 +08:00
|
|
|
item1->setPosition(
|
|
|
|
Vec2(VisibleRect::left().x + 60, VisibleRect::bottom().y + item1->getContentSize().height * 3));
|
2015-11-30 16:17:13 +08:00
|
|
|
auto pMenu1 = Menu::create(item1, nullptr);
|
2019-09-24 11:31:35 +08:00
|
|
|
pMenu1->setPosition(Vec2(0.0f, 0.0f));
|
2015-11-30 16:17:13 +08:00
|
|
|
this->addChild(pMenu1, 10);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2013-09-16 20:54:13 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void UISliderTest::sliderEvent(Ref* pSender, Slider::EventType type)
|
2013-09-16 20:54:13 +08:00
|
|
|
{
|
2014-05-12 11:17:06 +08:00
|
|
|
if (type == Slider::EventType::ON_PERCENTAGE_CHANGED)
|
2013-09-16 20:54:13 +08:00
|
|
|
{
|
2013-12-23 15:35:35 +08:00
|
|
|
Slider* slider = dynamic_cast<Slider*>(pSender);
|
2021-12-28 16:06:23 +08:00
|
|
|
int percent = slider->getPercent();
|
2015-06-15 18:31:21 +08:00
|
|
|
int maxPercent = slider->getMaxPercent();
|
|
|
|
_displayValueLabel->setString(StringUtils::format("Percent %f", 10000.0 * percent / maxPercent));
|
2013-09-16 20:54:13 +08:00
|
|
|
}
|
|
|
|
}
|
2022-07-11 17:50:21 +08:00
|
|
|
void UISliderTest::printWidgetResources(axis::Ref* /*sender*/)
|
2015-11-30 16:17:13 +08:00
|
|
|
{
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::ResourceData textureFile = _slider->getBackFile();
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("textureFile Name : %s, Type: %d", textureFile.file.c_str(), textureFile.type);
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::ResourceData progressBarTextureFile = _slider->getProgressBarFile();
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("progressBarTextureFile Name : %s, Type: %d", progressBarTextureFile.file.c_str(),
|
2021-12-28 16:06:23 +08:00
|
|
|
progressBarTextureFile.type);
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::ResourceData slidBallNormalTextureFile = _slider->getBallNormalFile();
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("slidBallNormalTextureFile Name : %s, Type: %d", slidBallNormalTextureFile.file.c_str(),
|
2021-12-28 16:06:23 +08:00
|
|
|
slidBallNormalTextureFile.type);
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::ResourceData slidBallPressedTextureFile = _slider->getBallPressedFile();
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("slidBallPressedTextureFile Name : %s, Type: %d", slidBallPressedTextureFile.file.c_str(),
|
2021-12-28 16:06:23 +08:00
|
|
|
slidBallPressedTextureFile.type);
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::ResourceData slidBallDisabledTextureFile = _slider->getBallDisabledFile();
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("slidBallDisabledTextureFile Name : %s, Type: %d", slidBallDisabledTextureFile.file.c_str(),
|
2021-12-28 16:06:23 +08:00
|
|
|
slidBallDisabledTextureFile.type);
|
2015-11-30 16:17:13 +08:00
|
|
|
}
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
// UISliderTest_Scale9
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
UISliderTest_Scale9::UISliderTest_Scale9() : _displayValueLabel(nullptr) {}
|
2013-09-16 20:54:13 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
UISliderTest_Scale9::~UISliderTest_Scale9() {}
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
bool UISliderTest_Scale9::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
2014-06-20 11:18:53 +08:00
|
|
|
Size widgetSize = _widget->getContentSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2013-09-16 20:54:13 +08:00
|
|
|
// Add a label in which the slider alert will be displayed
|
2021-12-28 16:06:23 +08:00
|
|
|
_displayValueLabel = Text::create("Move the slider thumb", "fonts/Marker Felt.ttf", 32);
|
2019-09-24 11:31:35 +08:00
|
|
|
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
|
2014-05-15 01:07:09 +08:00
|
|
|
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(_displayValueLabel);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2013-09-16 20:54:13 +08:00
|
|
|
// Add the alert
|
2021-12-28 16:06:23 +08:00
|
|
|
Text* alert = Text::create("Slider scale9 render", "fonts/Marker Felt.ttf", 30);
|
2013-09-16 20:54:13 +08:00
|
|
|
alert->setColor(Color3B(159, 168, 176));
|
2021-12-28 16:06:23 +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);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2013-09-16 20:54:13 +08:00
|
|
|
// Create the slider
|
2013-12-23 15:35:35 +08:00
|
|
|
Slider* slider = Slider::create();
|
2014-03-11 17:13:54 +08:00
|
|
|
slider->loadBarTexture("cocosui/sliderTrack2.png");
|
|
|
|
slider->loadSlidBallTextures("cocosui/sliderThumb.png", "cocosui/sliderThumb.png", "");
|
|
|
|
slider->loadProgressBarTexture("cocosui/slider_bar_active_9patch.png");
|
2013-09-16 20:54:13 +08:00
|
|
|
slider->setScale9Enabled(true);
|
2019-09-24 11:31:35 +08:00
|
|
|
slider->setCapInsets(Rect(0.0f, 0.0f, 0.0f, 0.0f));
|
|
|
|
slider->setContentSize(Size(250.0f, 19.0f));
|
2021-12-28 16:06:23 +08:00
|
|
|
slider->setPosition(
|
|
|
|
Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f /* + slider->getSize().height * 3.0f*/));
|
2022-07-15 19:17:01 +08:00
|
|
|
slider->addEventListener(AX_CALLBACK_2(UISliderTest_Scale9::sliderEvent, this));
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(slider);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2013-09-16 20:54:13 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void UISliderTest_Scale9::sliderEvent(Ref* pSender, Slider::EventType type)
|
2013-09-16 20:54:13 +08:00
|
|
|
{
|
2014-05-12 11:17:06 +08:00
|
|
|
if (type == Slider::EventType::ON_PERCENTAGE_CHANGED)
|
2013-09-16 20:54:13 +08:00
|
|
|
{
|
2013-12-23 15:35:35 +08:00
|
|
|
Slider* slider = dynamic_cast<Slider*>(pSender);
|
2021-12-28 16:06:23 +08:00
|
|
|
int percent = slider->getPercent();
|
2015-06-15 18:31:21 +08:00
|
|
|
_displayValueLabel->setString(StringUtils::format("Percent %d", percent));
|
2013-09-16 20:54:13 +08:00
|
|
|
}
|
2014-03-11 17:13:54 +08:00
|
|
|
}
|
2014-12-23 15:03:31 +08:00
|
|
|
|
2015-01-20 20:57:54 +08:00
|
|
|
// UISliderTest_Scale9_State_Change
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
UISliderTest_Scale9_State_Change::UISliderTest_Scale9_State_Change() : _displayValueLabel(nullptr) {}
|
2015-01-20 20:57:54 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
UISliderTest_Scale9_State_Change::~UISliderTest_Scale9_State_Change() {}
|
2015-01-20 20:57:54 +08:00
|
|
|
|
|
|
|
bool UISliderTest_Scale9_State_Change::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
|
|
|
Size widgetSize = _widget->getContentSize();
|
|
|
|
|
|
|
|
// Add a label in which the slider alert will be displayed
|
|
|
|
_displayValueLabel = Text::create("Click the slider thumb", "fonts/Marker Felt.ttf", 32);
|
2019-09-24 11:31:35 +08:00
|
|
|
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
|
2015-01-20 20:57:54 +08:00
|
|
|
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
|
|
|
|
_uiLayer->addChild(_displayValueLabel);
|
|
|
|
|
|
|
|
// Add the alert
|
2021-12-28 16:06:23 +08:00
|
|
|
Text* alert = Text::create("Slider scale9 render", "fonts/Marker Felt.ttf", 30);
|
2015-01-20 20:57:54 +08:00
|
|
|
alert->setColor(Color3B(159, 168, 176));
|
2021-12-28 16:06:23 +08:00
|
|
|
alert->setPosition(
|
|
|
|
Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 1.75f));
|
2015-01-20 20:57:54 +08:00
|
|
|
_uiLayer->addChild(alert);
|
|
|
|
|
|
|
|
// Create the slider
|
|
|
|
Slider* slider = Slider::create();
|
|
|
|
slider->loadBarTexture("cocosui/sliderballnormal.png");
|
|
|
|
slider->loadSlidBallTextures("cocosui/sliderThumb.png", "cocosui/sliderThumb.png", "");
|
|
|
|
slider->loadProgressBarTexture("cocosui/slider_bar_active_9patch.png");
|
|
|
|
slider->ignoreContentAdaptWithSize(false);
|
|
|
|
slider->setScale9Enabled(true);
|
2019-09-24 11:31:35 +08:00
|
|
|
slider->setCapInsets(Rect(0.0f, 0.0f, 0.0f, 0.0f));
|
|
|
|
slider->setContentSize(Size(200.0f, 60.0f));
|
2021-12-28 16:06:23 +08:00
|
|
|
slider->setPosition(
|
|
|
|
Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f /* + slider->getSize().height * 3.0f*/));
|
|
|
|
slider->addTouchEventListener([=](Ref* /*sender*/, Widget::TouchEventType type) {
|
|
|
|
if (type == Widget::TouchEventType::ENDED)
|
|
|
|
{
|
2015-01-20 20:57:54 +08:00
|
|
|
if (slider->isScale9Enabled())
|
|
|
|
{
|
|
|
|
slider->setScale9Enabled(false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
slider->setScale9Enabled(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
_uiLayer->addChild(slider);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void UISliderTest_Scale9_State_Change::sliderEvent(Ref* pSender, Slider::EventType type)
|
2015-01-20 20:57:54 +08:00
|
|
|
{
|
|
|
|
if (type == Slider::EventType::ON_PERCENTAGE_CHANGED)
|
|
|
|
{
|
|
|
|
Slider* slider = dynamic_cast<Slider*>(pSender);
|
2021-12-28 16:06:23 +08:00
|
|
|
int percent = slider->getPercent();
|
2015-06-15 18:31:21 +08:00
|
|
|
_displayValueLabel->setString(StringUtils::format("Percent %d", percent));
|
2015-01-20 20:57:54 +08:00
|
|
|
}
|
|
|
|
}
|
2014-12-23 15:03:31 +08:00
|
|
|
|
|
|
|
// UISliderNormalDefaultTest
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
UISliderNormalDefaultTest::UISliderNormalDefaultTest() : _displayValueLabel(nullptr) {}
|
2014-12-23 15:03:31 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
UISliderNormalDefaultTest::~UISliderNormalDefaultTest() {}
|
2014-12-23 15:03:31 +08:00
|
|
|
|
|
|
|
bool UISliderNormalDefaultTest::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
|
|
|
Size widgetSize = _widget->getContentSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-12-23 15:03:31 +08:00
|
|
|
// Add a label in which the slider alert will be displayed
|
2021-12-28 16:06:23 +08:00
|
|
|
_displayValueLabel = Text::create("", "Arial", 32);
|
2019-09-24 11:31:35 +08:00
|
|
|
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
|
2014-12-23 15:03:31 +08:00
|
|
|
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 100));
|
|
|
|
_uiLayer->addChild(_displayValueLabel);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-12-23 15:03:31 +08:00
|
|
|
// Add the alert
|
2021-12-28 16:06:23 +08:00
|
|
|
Text* alert = Text::create("when pressed, the slider ball should scale", "fonts/Marker Felt.ttf", 20);
|
2014-12-23 15:03:31 +08:00
|
|
|
alert->setColor(Color3B(159, 168, 176));
|
2021-12-28 16:06:23 +08:00
|
|
|
alert->setPosition(
|
|
|
|
Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.75f));
|
2014-12-23 15:03:31 +08:00
|
|
|
_uiLayer->addChild(alert);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-12-23 15:03:31 +08:00
|
|
|
// Create the slider
|
|
|
|
Slider* slider = Slider::create();
|
|
|
|
slider->loadBarTexture("cocosui/sliderTrack.png");
|
|
|
|
slider->loadSlidBallTextures("cocosui/sliderThumb.png");
|
2021-12-28 16:06:23 +08:00
|
|
|
slider->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 50));
|
2014-12-23 15:03:31 +08:00
|
|
|
_uiLayer->addChild(slider);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2015-06-05 17:16:10 +08:00
|
|
|
Slider* sliderScale9 = (Slider*)slider->clone();
|
2014-12-23 15:03:31 +08:00
|
|
|
sliderScale9->setScale9Enabled(true);
|
2019-09-24 11:31:35 +08:00
|
|
|
sliderScale9->setCapInsets(Rect(0.0f, 0.0f, 0.0f, 0.0f));
|
2014-12-23 15:03:31 +08:00
|
|
|
sliderScale9->setZoomScale(1.0);
|
2019-09-24 11:31:35 +08:00
|
|
|
sliderScale9->setContentSize(Size(250.0f, 19.0f));
|
2014-12-23 15:03:31 +08:00
|
|
|
sliderScale9->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - 20));
|
|
|
|
_uiLayer->addChild(sliderScale9);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-12-23 15:03:31 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// UISliderDisabledDefaultTest
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
UISliderDisabledDefaultTest::UISliderDisabledDefaultTest() : _displayValueLabel(nullptr) {}
|
2014-12-23 15:03:31 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
UISliderDisabledDefaultTest::~UISliderDisabledDefaultTest() {}
|
2014-12-23 15:03:31 +08:00
|
|
|
|
|
|
|
bool UISliderDisabledDefaultTest::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
|
|
|
Size widgetSize = _widget->getContentSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-12-23 15:03:31 +08:00
|
|
|
// Add a label in which the slider alert will be displayed
|
2021-12-28 16:06:23 +08:00
|
|
|
_displayValueLabel = Text::create("", "Arial", 32);
|
2019-09-24 11:31:35 +08:00
|
|
|
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
|
2014-12-23 15:03:31 +08:00
|
|
|
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 100));
|
|
|
|
_uiLayer->addChild(_displayValueLabel);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-12-23 15:03:31 +08:00
|
|
|
// Add the alert
|
2021-12-28 16:06:23 +08:00
|
|
|
Text* alert = Text::create("slider ball should be gray.", "fonts/Marker Felt.ttf", 20);
|
2014-12-23 15:03:31 +08:00
|
|
|
alert->setColor(Color3B(159, 168, 176));
|
2021-12-28 16:06:23 +08:00
|
|
|
alert->setPosition(
|
|
|
|
Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.75f));
|
2014-12-23 15:03:31 +08:00
|
|
|
_uiLayer->addChild(alert);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-12-23 15:03:31 +08:00
|
|
|
// Create the slider
|
|
|
|
Slider* slider = Slider::create();
|
|
|
|
slider->loadBarTexture("cocosui/slidbar.png");
|
|
|
|
slider->loadSlidBallTextureNormal("cocosui/sliderballnormal.png");
|
|
|
|
slider->setEnabled(false);
|
|
|
|
slider->setBright(false);
|
2021-12-28 16:06:23 +08:00
|
|
|
slider->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 50));
|
2014-12-23 15:03:31 +08:00
|
|
|
_uiLayer->addChild(slider);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2015-06-05 17:16:10 +08:00
|
|
|
Slider* sliderScale9 = (Slider*)slider->clone();
|
2014-12-23 15:03:31 +08:00
|
|
|
sliderScale9->setScale9Enabled(true);
|
|
|
|
sliderScale9->setEnabled(false);
|
|
|
|
sliderScale9->setBright(false);
|
2019-09-24 11:31:35 +08:00
|
|
|
sliderScale9->setCapInsets(Rect(0.0f, 0.0f, 0.0f, 0.0f));
|
|
|
|
sliderScale9->setContentSize(Size(250.0f, 10.0f));
|
2014-12-23 15:03:31 +08:00
|
|
|
sliderScale9->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - 20));
|
|
|
|
_uiLayer->addChild(sliderScale9);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-12-23 15:03:31 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-06-15 18:31:21 +08:00
|
|
|
// UISliderNewEventCallbackTest
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
UISliderNewEventCallbackTest::UISliderNewEventCallbackTest() : _displayValueLabel(nullptr) {}
|
2015-06-15 18:31:21 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
UISliderNewEventCallbackTest::~UISliderNewEventCallbackTest() {}
|
2015-06-15 18:31:21 +08:00
|
|
|
|
|
|
|
bool UISliderNewEventCallbackTest::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
|
|
|
Size widgetSize = _widget->getContentSize();
|
|
|
|
|
|
|
|
// Add a label in which the slider alert will be displayed
|
2021-12-28 16:06:23 +08:00
|
|
|
_displayValueLabel = Text::create("", "Arial", 32);
|
2019-09-24 11:31:35 +08:00
|
|
|
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
|
2015-06-15 18:31:21 +08:00
|
|
|
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 100));
|
|
|
|
_uiLayer->addChild(_displayValueLabel);
|
|
|
|
|
|
|
|
// Add the alert
|
2017-02-23 16:14:39 +08:00
|
|
|
Text* alert = Text::create("See console output for Slider Down and Up event.", "fonts/Marker Felt.ttf", 20);
|
2015-06-15 18:31:21 +08:00
|
|
|
alert->setColor(Color3B(159, 168, 176));
|
2021-12-28 16:06:23 +08:00
|
|
|
alert->setPosition(
|
|
|
|
Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.75f));
|
2015-06-15 18:31:21 +08:00
|
|
|
_uiLayer->addChild(alert);
|
|
|
|
|
|
|
|
// Create the slider
|
|
|
|
Slider* slider = Slider::create();
|
|
|
|
slider->loadBarTexture("cocosui/sliderTrack.png");
|
|
|
|
slider->loadSlidBallTextures("cocosui/sliderThumb.png", "cocosui/sliderThumb.png", "");
|
|
|
|
slider->loadProgressBarTexture("cocosui/sliderProgress.png");
|
|
|
|
slider->setMaxPercent(1000);
|
2021-12-28 16:06:23 +08:00
|
|
|
slider->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 50));
|
|
|
|
slider->addEventListener([=](Ref* widget, Slider::EventType type) {
|
2015-06-15 18:31:21 +08:00
|
|
|
Slider* slider = (Slider*)widget;
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_UNUSED_PARAM(slider);
|
2021-12-28 16:06:23 +08:00
|
|
|
if (type == Slider::EventType::ON_SLIDEBALL_DOWN)
|
2015-06-15 18:31:21 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("slider button pressed!");
|
2015-06-15 18:31:21 +08:00
|
|
|
}
|
2021-12-28 16:06:23 +08:00
|
|
|
else if (type == Slider::EventType::ON_PERCENTAGE_CHANGED)
|
2015-06-15 18:31:21 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("slider is moving! percent = %f", 100.0f * slider->getPercent() / slider->getMaxPercent());
|
2015-06-15 18:31:21 +08:00
|
|
|
}
|
2021-12-28 16:06:23 +08:00
|
|
|
else if (type == Slider::EventType::ON_SLIDEBALL_UP)
|
2015-06-15 18:31:21 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("slider button is released.");
|
2015-06-15 18:31:21 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
_uiLayer->addChild(slider);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2015-12-09 17:15:09 +08:00
|
|
|
|
|
|
|
// UISliderIssue12249Test
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
UISliderIssue12249Test::UISliderIssue12249Test() : _displayValueLabel(nullptr) {}
|
2015-12-09 17:15:09 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
UISliderIssue12249Test::~UISliderIssue12249Test() {}
|
2015-12-09 17:15:09 +08:00
|
|
|
|
|
|
|
bool UISliderIssue12249Test::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
|
|
|
Size widgetSize = _widget->getContentSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2015-12-09 17:15:09 +08:00
|
|
|
// Add a label in which the slider alert will be displayed
|
|
|
|
_displayValueLabel = TextBMFont::create("Move the slider thumb", "ccb/markerfelt24shadow.fnt");
|
2019-09-24 11:31:35 +08:00
|
|
|
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
|
2015-12-09 17:15:09 +08:00
|
|
|
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
|
|
|
|
_uiLayer->addChild(_displayValueLabel);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2015-12-09 17:15:09 +08:00
|
|
|
// Create the slider
|
|
|
|
Slider* slider = Slider::create();
|
|
|
|
slider->setScale9Enabled(true);
|
|
|
|
slider->loadBarTexture("cocosui/sliderTrack.png");
|
|
|
|
slider->loadSlidBallTextures("cocosui/sliderThumb.png", "cocosui/sliderThumb.png", "");
|
|
|
|
slider->loadProgressBarTexture("cocosui/sliderProgress.png");
|
|
|
|
slider->setContentSize(Size(300, slider->getContentSize().height * 1.5));
|
|
|
|
slider->setMaxPercent(10000);
|
2021-12-28 16:06:23 +08:00
|
|
|
slider->setPosition(
|
|
|
|
Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f /* + slider->getSize().height * 2.0f*/));
|
2022-07-15 19:17:01 +08:00
|
|
|
slider->addEventListener(AX_CALLBACK_2(UISliderIssue12249Test::sliderEvent, this));
|
2015-12-09 17:15:09 +08:00
|
|
|
_uiLayer->addChild(slider);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2015-12-09 17:15:09 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void UISliderIssue12249Test::sliderEvent(Ref* pSender, Slider::EventType type)
|
2015-12-09 17:15:09 +08:00
|
|
|
{
|
|
|
|
if (type == Slider::EventType::ON_PERCENTAGE_CHANGED)
|
|
|
|
{
|
|
|
|
Slider* slider = dynamic_cast<Slider*>(pSender);
|
2021-12-28 16:06:23 +08:00
|
|
|
int percent = slider->getPercent();
|
2015-12-09 17:15:09 +08:00
|
|
|
int maxPercent = slider->getMaxPercent();
|
|
|
|
_displayValueLabel->setString(StringUtils::format("Percent %f", 10000.0 * percent / maxPercent));
|
|
|
|
}
|
|
|
|
}
|