2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
|
|
|
|
#include "UISliderTest.h"
|
|
|
|
|
|
|
|
|
|
|
|
// UISliderTest
|
|
|
|
|
|
|
|
UISliderTest::UISliderTest()
|
2013-12-23 15:35:35 +08:00
|
|
|
: _displayValueLabel(nullptr)
|
2013-09-16 20:54:13 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UISliderTest::~UISliderTest()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UISliderTest::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
2014-06-20 11:18:53 +08:00
|
|
|
Size widgetSize = _widget->getContentSize();
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
// Add a label in which the slider alert will be displayed
|
2014-04-03 15:33:57 +08:00
|
|
|
_displayValueLabel = Text::create("Move the slider thumb","Move the slider thumb",32);
|
2014-05-15 01:07:09 +08:00
|
|
|
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1));
|
|
|
|
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(_displayValueLabel);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
// Add the alert
|
2014-04-03 15:33:57 +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));
|
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 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");
|
2014-05-15 01:07:09 +08:00
|
|
|
slider->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f/* + slider->getSize().height * 2.0f*/));
|
2014-05-12 11:17:06 +08:00
|
|
|
slider->addEventListener(CC_CALLBACK_2(UISliderTest::sliderEvent, this));
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(slider);
|
2014-03-04 16:51:35 +08:00
|
|
|
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-12 11:17:06 +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);
|
2013-09-16 20:54:13 +08:00
|
|
|
int percent = slider->getPercent();
|
2014-05-14 15:26:14 +08:00
|
|
|
_displayValueLabel->setString(String::createWithFormat("Percent %d", percent)->getCString());
|
2013-09-16 20:54:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// UISliderTest_Scale9
|
|
|
|
|
|
|
|
UISliderTest_Scale9::UISliderTest_Scale9()
|
2013-12-23 15:35:35 +08:00
|
|
|
: _displayValueLabel(nullptr)
|
2013-09-16 20:54:13 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UISliderTest_Scale9::~UISliderTest_Scale9()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UISliderTest_Scale9::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
2014-06-20 11:18:53 +08:00
|
|
|
Size widgetSize = _widget->getContentSize();
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
// Add a label in which the slider alert will be displayed
|
2014-04-03 15:33:57 +08:00
|
|
|
_displayValueLabel = Text::create("Move the slider thumb","fonts/Marker Felt.ttf",32);
|
2014-05-15 01:07:09 +08:00
|
|
|
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1));
|
|
|
|
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(_displayValueLabel);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
// Add the alert
|
2014-04-03 15:33:57 +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));
|
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 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);
|
|
|
|
slider->setCapInsets(Rect(0, 0, 0, 0));
|
2014-06-20 14:03:33 +08:00
|
|
|
slider->setContentSize(Size(250.0f, 19));
|
2014-05-15 01:07:09 +08:00
|
|
|
slider->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f/* + slider->getSize().height * 3.0f*/));
|
2014-05-12 11:17:06 +08:00
|
|
|
slider->addEventListener(CC_CALLBACK_2(UISliderTest_Scale9::sliderEvent, this));
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(slider);
|
|
|
|
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-12 11:17:06 +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);
|
2013-09-16 20:54:13 +08:00
|
|
|
int percent = slider->getPercent();
|
2014-05-14 15:26:14 +08:00
|
|
|
_displayValueLabel->setString(String::createWithFormat("Percent %d", percent)->getCString());
|
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
|
|
|
|
|
|
|
|
UISliderTest_Scale9_State_Change::UISliderTest_Scale9_State_Change()
|
|
|
|
: _displayValueLabel(nullptr)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UISliderTest_Scale9_State_Change::~UISliderTest_Scale9_State_Change()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1));
|
|
|
|
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
|
|
|
|
_uiLayer->addChild(_displayValueLabel);
|
|
|
|
|
|
|
|
// Add the alert
|
|
|
|
Text *alert = Text::create("Slider scale9 render", "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 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);
|
|
|
|
slider->setCapInsets(Rect(0, 0, 0, 0));
|
|
|
|
slider->setContentSize(Size(200.0f, 60));
|
|
|
|
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) {
|
|
|
|
if (slider->isScale9Enabled())
|
|
|
|
{
|
|
|
|
slider->setScale9Enabled(false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
slider->setScale9Enabled(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
_uiLayer->addChild(slider);
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UISliderTest_Scale9_State_Change::sliderEvent(Ref *pSender, Slider::EventType type)
|
|
|
|
{
|
|
|
|
if (type == Slider::EventType::ON_PERCENTAGE_CHANGED)
|
|
|
|
{
|
|
|
|
Slider* slider = dynamic_cast<Slider*>(pSender);
|
|
|
|
int percent = slider->getPercent();
|
|
|
|
_displayValueLabel->setString(String::createWithFormat("Percent %d", percent)->getCString());
|
|
|
|
}
|
|
|
|
}
|
2014-12-23 15:03:31 +08:00
|
|
|
|
|
|
|
// UISliderNormalDefaultTest
|
|
|
|
|
|
|
|
UISliderNormalDefaultTest::UISliderNormalDefaultTest()
|
|
|
|
: _displayValueLabel(nullptr)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UISliderNormalDefaultTest::~UISliderNormalDefaultTest()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UISliderNormalDefaultTest::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
|
|
|
Size widgetSize = _widget->getContentSize();
|
|
|
|
|
|
|
|
// Add a label in which the slider alert will be displayed
|
|
|
|
_displayValueLabel = Text::create("","Arial",32);
|
|
|
|
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1));
|
|
|
|
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 100));
|
|
|
|
_uiLayer->addChild(_displayValueLabel);
|
|
|
|
|
|
|
|
// Add the alert
|
|
|
|
Text* alert = Text::create("when pressed, the slider ball should scale","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 * 3.75f));
|
|
|
|
_uiLayer->addChild(alert);
|
|
|
|
|
|
|
|
// Create the slider
|
|
|
|
Slider* slider = Slider::create();
|
|
|
|
slider->loadBarTexture("cocosui/sliderTrack.png");
|
|
|
|
slider->loadSlidBallTextures("cocosui/sliderThumb.png");
|
|
|
|
slider->setPosition(Vec2(widgetSize.width / 2.0f,
|
|
|
|
widgetSize.height / 2.0f + 50));
|
|
|
|
_uiLayer->addChild(slider);
|
|
|
|
|
|
|
|
Slider* sliderScale9 = Slider::create("cocosui/sliderTrack2.png", "cocosui/sliderThumb.png");
|
|
|
|
sliderScale9->setScale9Enabled(true);
|
|
|
|
sliderScale9->setCapInsets(Rect(0, 0, 0, 0));
|
|
|
|
sliderScale9->setZoomScale(1.0);
|
|
|
|
sliderScale9->setContentSize(Size(250.0f, 19));
|
|
|
|
sliderScale9->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - 20));
|
|
|
|
_uiLayer->addChild(sliderScale9);
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// UISliderDisabledDefaultTest
|
|
|
|
|
|
|
|
UISliderDisabledDefaultTest::UISliderDisabledDefaultTest()
|
|
|
|
: _displayValueLabel(nullptr)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UISliderDisabledDefaultTest::~UISliderDisabledDefaultTest()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UISliderDisabledDefaultTest::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
|
|
|
Size widgetSize = _widget->getContentSize();
|
|
|
|
|
|
|
|
// Add a label in which the slider alert will be displayed
|
|
|
|
_displayValueLabel = Text::create("","Arial",32);
|
|
|
|
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1));
|
|
|
|
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 100));
|
|
|
|
_uiLayer->addChild(_displayValueLabel);
|
|
|
|
|
|
|
|
// Add the alert
|
|
|
|
Text* alert = Text::create("slider ball should be gray.","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 * 3.75f));
|
|
|
|
_uiLayer->addChild(alert);
|
|
|
|
|
|
|
|
// Create the slider
|
|
|
|
Slider* slider = Slider::create();
|
|
|
|
slider->loadBarTexture("cocosui/slidbar.png");
|
|
|
|
slider->loadSlidBallTextureNormal("cocosui/sliderballnormal.png");
|
|
|
|
slider->setEnabled(false);
|
|
|
|
slider->setBright(false);
|
|
|
|
slider->setPosition(Vec2(widgetSize.width / 2.0f,
|
|
|
|
widgetSize.height / 2.0f + 50));
|
|
|
|
_uiLayer->addChild(slider);
|
|
|
|
|
|
|
|
Slider* sliderScale9 = Slider::create("cocosui/slidbar.png", "cocosui/sliderballnormal.png");
|
|
|
|
sliderScale9->setScale9Enabled(true);
|
|
|
|
sliderScale9->setEnabled(false);
|
|
|
|
sliderScale9->setBright(false);
|
|
|
|
sliderScale9->setCapInsets(Rect(0, 0, 0, 0));
|
|
|
|
sliderScale9->setContentSize(Size(250.0f, 10));
|
|
|
|
sliderScale9->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - 20));
|
|
|
|
_uiLayer->addChild(sliderScale9);
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|