mirror of https://github.com/axmolengine/axmol.git
Merge pull request #10113 from liamcindy/Scale9Error
update for ui object scale9 state refresh
This commit is contained in:
commit
dca1edccd7
|
@ -187,6 +187,10 @@ void Button::setScale9Enabled(bool able)
|
||||||
|
|
||||||
_brightStyle = BrightStyle::NONE;
|
_brightStyle = BrightStyle::NONE;
|
||||||
setBright(_bright);
|
setBright(_bright);
|
||||||
|
|
||||||
|
_normalTextureAdaptDirty = true;
|
||||||
|
_pressedTextureAdaptDirty = true;
|
||||||
|
_disabledTextureAdaptDirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Button::isScale9Enabled()const
|
bool Button::isScale9Enabled()const
|
||||||
|
|
|
@ -186,6 +186,7 @@ void ImageView::setScale9Enabled(bool able)
|
||||||
ignoreContentAdaptWithSize(_prevIgnoreSize);
|
ignoreContentAdaptWithSize(_prevIgnoreSize);
|
||||||
}
|
}
|
||||||
setCapInsets(_capInsets);
|
setCapInsets(_capInsets);
|
||||||
|
_imageRendererAdaptDirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ImageView::isScale9Enabled()const
|
bool ImageView::isScale9Enabled()const
|
||||||
|
|
|
@ -217,6 +217,7 @@ void LoadingBar::setScale9Enabled(bool enabled)
|
||||||
}
|
}
|
||||||
setCapInsets(_capInsets);
|
setCapInsets(_capInsets);
|
||||||
setPercent(_percent);
|
setPercent(_percent);
|
||||||
|
_barRendererAdaptDirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LoadingBar::isScale9Enabled()const
|
bool LoadingBar::isScale9Enabled()const
|
||||||
|
@ -334,6 +335,7 @@ void LoadingBar::barRendererScaleChangedWithSize()
|
||||||
if (_scale9Enabled)
|
if (_scale9Enabled)
|
||||||
{
|
{
|
||||||
setScale9Scale();
|
setScale9Scale();
|
||||||
|
_barRenderer->setScale(1.0f);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -40,6 +40,7 @@ IMPLEMENT_CLASS_GUI_INFO(Slider)
|
||||||
Slider::Slider():
|
Slider::Slider():
|
||||||
_barRenderer(nullptr),
|
_barRenderer(nullptr),
|
||||||
_progressBarRenderer(nullptr),
|
_progressBarRenderer(nullptr),
|
||||||
|
_barTextureSize(Size::ZERO),
|
||||||
_progressBarTextureSize(Size::ZERO),
|
_progressBarTextureSize(Size::ZERO),
|
||||||
_slidBallNormalRenderer(nullptr),
|
_slidBallNormalRenderer(nullptr),
|
||||||
_slidBallPressedRenderer(nullptr),
|
_slidBallPressedRenderer(nullptr),
|
||||||
|
@ -168,6 +169,7 @@ void Slider::loadBarTexture(const std::string& fileName, TextureResType texType)
|
||||||
_barRendererAdaptDirty = true;
|
_barRendererAdaptDirty = true;
|
||||||
_progressBarRendererDirty = true;
|
_progressBarRendererDirty = true;
|
||||||
updateContentSizeWithTextureSize(_barRenderer->getContentSize());
|
updateContentSizeWithTextureSize(_barRenderer->getContentSize());
|
||||||
|
_barTextureSize = _barRenderer->getContentSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Slider::loadProgressBarTexture(const std::string& fileName, TextureResType texType)
|
void Slider::loadProgressBarTexture(const std::string& fileName, TextureResType texType)
|
||||||
|
@ -218,6 +220,8 @@ void Slider::setScale9Enabled(bool able)
|
||||||
}
|
}
|
||||||
setCapInsetsBarRenderer(_capInsetsBarRenderer);
|
setCapInsetsBarRenderer(_capInsetsBarRenderer);
|
||||||
setCapInsetProgressBarRebderer(_capInsetsProgressBarRenderer);
|
setCapInsetProgressBarRebderer(_capInsetsProgressBarRenderer);
|
||||||
|
_barRendererAdaptDirty = true;
|
||||||
|
_progressBarRendererDirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Slider::isScale9Enabled()const
|
bool Slider::isScale9Enabled()const
|
||||||
|
@ -508,10 +512,11 @@ void Slider::barRendererScaleChangedWithSize()
|
||||||
if (_scale9Enabled)
|
if (_scale9Enabled)
|
||||||
{
|
{
|
||||||
_barRenderer->setPreferredSize(_contentSize);
|
_barRenderer->setPreferredSize(_contentSize);
|
||||||
|
_barRenderer->setScale(1.0f);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Size btextureSize = _barRenderer->getContentSize();
|
Size btextureSize = _barTextureSize;
|
||||||
if (btextureSize.width <= 0.0f || btextureSize.height <= 0.0f)
|
if (btextureSize.width <= 0.0f || btextureSize.height <= 0.0f)
|
||||||
{
|
{
|
||||||
_barRenderer->setScale(1.0f);
|
_barRenderer->setScale(1.0f);
|
||||||
|
|
|
@ -245,6 +245,7 @@ protected:
|
||||||
protected:
|
protected:
|
||||||
Scale9Sprite* _barRenderer;
|
Scale9Sprite* _barRenderer;
|
||||||
Scale9Sprite* _progressBarRenderer;
|
Scale9Sprite* _progressBarRenderer;
|
||||||
|
Size _barTextureSize;
|
||||||
Size _progressBarTextureSize;
|
Size _progressBarTextureSize;
|
||||||
|
|
||||||
Sprite* _slidBallNormalRenderer;
|
Sprite* _slidBallNormalRenderer;
|
||||||
|
|
|
@ -465,6 +465,10 @@ void Widget::ignoreContentAdaptWithSize(bool ignore)
|
||||||
this->setContentSize(_customSize);
|
this->setContentSize(_customSize);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (_ignoreSize == ignore)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
_ignoreSize = ignore;
|
_ignoreSize = ignore;
|
||||||
if (_ignoreSize)
|
if (_ignoreSize)
|
||||||
{
|
{
|
||||||
|
|
|
@ -184,6 +184,88 @@ void UIButtonTest_Scale9::touchEvent(Ref *pSender, Widget::TouchEventType type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UIButtonTest_Scale9_State_Change
|
||||||
|
UIButtonTest_Scale9_State_Change::UIButtonTest_Scale9_State_Change()
|
||||||
|
: _displayValueLabel(nullptr)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
UIButtonTest_Scale9_State_Change::~UIButtonTest_Scale9_State_Change()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool UIButtonTest_Scale9_State_Change::init()
|
||||||
|
{
|
||||||
|
if (UIScene::init())
|
||||||
|
{
|
||||||
|
Size widgetSize = _widget->getContentSize();
|
||||||
|
|
||||||
|
// Add a label in which the button events will be displayed
|
||||||
|
_displayValueLabel = Text::create("No Event", "fonts/Marker Felt.ttf", 32);
|
||||||
|
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
|
||||||
|
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
|
||||||
|
_uiLayer->addChild(_displayValueLabel);
|
||||||
|
|
||||||
|
// Add the alert
|
||||||
|
Text* alert = Text::create("Button 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 button
|
||||||
|
Button* button = Button::create("cocosui/backtotopnormal.png", "cocosui/backtotoppressed.png");
|
||||||
|
// open scale9 render
|
||||||
|
button->ignoreContentAdaptWithSize(false);
|
||||||
|
button->setScale9Enabled(true);
|
||||||
|
button->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
|
||||||
|
button->setContentSize(Size(200, 60));
|
||||||
|
button->setCapInsets(Rect(30,10,40,20));
|
||||||
|
button->setPressedActionEnabled(false);
|
||||||
|
button->addTouchEventListener(CC_CALLBACK_2(UIButtonTest_Scale9_State_Change::touchEvent, this));
|
||||||
|
_uiLayer->addChild(button);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UIButtonTest_Scale9_State_Change::touchEvent(Ref *pSender, Widget::TouchEventType type)
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case Widget::TouchEventType::BEGAN:
|
||||||
|
_displayValueLabel->setString(String::createWithFormat("Touch Down")->getCString());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Widget::TouchEventType::MOVED:
|
||||||
|
_displayValueLabel->setString(String::createWithFormat("Touch Move")->getCString());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Widget::TouchEventType::ENDED:
|
||||||
|
{
|
||||||
|
_displayValueLabel->setString(String::createWithFormat("Touch Up")->getCString());
|
||||||
|
Button *btn = (Button*)pSender;
|
||||||
|
if (btn->isScale9Enabled())
|
||||||
|
{
|
||||||
|
btn->setScale9Enabled(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
btn->setScale9Enabled(true);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Widget::TouchEventType::CANCELED:
|
||||||
|
_displayValueLabel->setString(String::createWithFormat("Touch Cancelled")->getCString());
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// UIButtonTest_PressAction
|
// UIButtonTest_PressAction
|
||||||
UIButtonTest_PressedAction::UIButtonTest_PressedAction()
|
UIButtonTest_PressedAction::UIButtonTest_PressedAction()
|
||||||
: _displayValueLabel(nullptr)
|
: _displayValueLabel(nullptr)
|
||||||
|
|
|
@ -53,6 +53,19 @@ protected:
|
||||||
Text* _displayValueLabel;
|
Text* _displayValueLabel;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class UIButtonTest_Scale9_State_Change : public UIScene
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
UIButtonTest_Scale9_State_Change();
|
||||||
|
~UIButtonTest_Scale9_State_Change();
|
||||||
|
bool init();
|
||||||
|
void touchEvent(Ref *pSender, Widget::TouchEventType type);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
UI_SCENE_CREATE_FUNC(UIButtonTest_Scale9_State_Change)
|
||||||
|
Text* _displayValueLabel;
|
||||||
|
};
|
||||||
|
|
||||||
class UIButtonTest_PressedAction : public UIScene
|
class UIButtonTest_PressedAction : public UIScene
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -62,6 +62,50 @@ bool UIImageViewTest_Scale9::init()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UIImageViewTest_Scale9_State_Change
|
||||||
|
|
||||||
|
bool UIImageViewTest_Scale9_State_Change::init()
|
||||||
|
{
|
||||||
|
if (UIScene::init())
|
||||||
|
{
|
||||||
|
Size widgetSize = _widget->getContentSize();
|
||||||
|
|
||||||
|
Text* alert = Text::create("Click The Image", "fonts/Marker Felt.ttf", 26);
|
||||||
|
alert->setColor(Color3B(159, 168, 176));
|
||||||
|
alert->setPosition(Vec2(widgetSize.width / 2.0f,
|
||||||
|
widgetSize.height / 2.0f - alert->getContentSize().height * 2.125f));
|
||||||
|
|
||||||
|
_uiLayer->addChild(alert);
|
||||||
|
|
||||||
|
// Create the imageview
|
||||||
|
ImageView* imageView = ImageView::create("cocosui/ccicon.png");
|
||||||
|
imageView->ignoreContentAdaptWithSize(false);
|
||||||
|
imageView->setScale9Enabled(true);
|
||||||
|
imageView->setContentSize(Size(100, 100));
|
||||||
|
imageView->setCapInsets(Rect(20,20,20,20));
|
||||||
|
imageView->setPosition(Vec2(widgetSize.width / 2.0f,
|
||||||
|
widgetSize.height / 2.0f));
|
||||||
|
|
||||||
|
imageView->setTouchEnabled(true);
|
||||||
|
imageView->addTouchEventListener([=](Ref* sender, Widget::TouchEventType type){
|
||||||
|
if (type == Widget::TouchEventType::ENDED) {
|
||||||
|
if (imageView->isScale9Enabled())
|
||||||
|
{
|
||||||
|
imageView->setScale9Enabled(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
imageView->setScale9Enabled(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
_uiLayer->addChild(imageView);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// UIImageViewTest_ContentSize
|
// UIImageViewTest_ContentSize
|
||||||
|
|
||||||
bool UIImageViewTest_ContentSize::init()
|
bool UIImageViewTest_ContentSize::init()
|
||||||
|
|
|
@ -45,6 +45,15 @@ protected:
|
||||||
UI_SCENE_CREATE_FUNC(UIImageViewTest_Scale9)
|
UI_SCENE_CREATE_FUNC(UIImageViewTest_Scale9)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class UIImageViewTest_Scale9_State_Change : public UIScene
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
bool init();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
UI_SCENE_CREATE_FUNC(UIImageViewTest_Scale9_State_Change)
|
||||||
|
};
|
||||||
|
|
||||||
class UIImageViewTest_ContentSize : public UIScene
|
class UIImageViewTest_ContentSize : public UIScene
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -339,3 +339,61 @@ void UILoadingBarTest_Right_Scale9::nextCallback(Ref* sender, Widget::TouchEvent
|
||||||
UIScene::nextCallback(sender, type);
|
UIScene::nextCallback(sender, type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// UILoadingBarTest_Scale9_State_Change
|
||||||
|
|
||||||
|
UILoadingBarTest_Scale9_State_Change::UILoadingBarTest_Scale9_State_Change()
|
||||||
|
: _count(0)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
UILoadingBarTest_Scale9_State_Change::~UILoadingBarTest_Scale9_State_Change()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
|
@ -95,4 +95,16 @@ protected:
|
||||||
int _count;
|
int _count;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class UILoadingBarTest_Scale9_State_Change : public UIScene
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
UILoadingBarTest_Scale9_State_Change();
|
||||||
|
~UILoadingBarTest_Scale9_State_Change();
|
||||||
|
bool init();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
UI_SCENE_CREATE_FUNC(UILoadingBarTest_Scale9_State_Change)
|
||||||
|
int _count;
|
||||||
|
};
|
||||||
|
|
||||||
#endif /* defined(__TestCpp__UILoadingBarTest__) */
|
#endif /* defined(__TestCpp__UILoadingBarTest__) */
|
||||||
|
|
|
@ -36,6 +36,7 @@ static const char* s_testArray[] =
|
||||||
{
|
{
|
||||||
"UIButtonTest",
|
"UIButtonTest",
|
||||||
"UIButtonTest_Scale9",
|
"UIButtonTest_Scale9",
|
||||||
|
"UIButtonTest_Scale9_State_Change",
|
||||||
"UIButtonTest_PressedAction",
|
"UIButtonTest_PressedAction",
|
||||||
"UIButtonTest_Title",
|
"UIButtonTest_Title",
|
||||||
"UIButtonTest_RemoveSelf",
|
"UIButtonTest_RemoveSelf",
|
||||||
|
@ -55,16 +56,19 @@ static const char* s_testArray[] =
|
||||||
"UICheckBoxDefaultBehaviorTest",
|
"UICheckBoxDefaultBehaviorTest",
|
||||||
"UISliderTest",
|
"UISliderTest",
|
||||||
"UISliderTest_Scale9",
|
"UISliderTest_Scale9",
|
||||||
|
"UISliderTest_Scale9_Stata_Change",
|
||||||
"UISliderNormalDefaultTest",
|
"UISliderNormalDefaultTest",
|
||||||
"UISliderDisabledDefaultTest",
|
"UISliderDisabledDefaultTest",
|
||||||
|
|
||||||
"UIImageViewTest",
|
"UIImageViewTest",
|
||||||
"UIImageViewTest_Scale9",
|
"UIImageViewTest_Scale9",
|
||||||
|
"UIImageViewTest_Scale9_State_Change",
|
||||||
"UIImageViewTest_ContentSize",
|
"UIImageViewTest_ContentSize",
|
||||||
"UIImageViewFlipTest",
|
"UIImageViewFlipTest",
|
||||||
|
|
||||||
"UILoadingBarTest_Left",
|
"UILoadingBarTest_Left",
|
||||||
"UILoadingBarTest_Right",
|
"UILoadingBarTest_Right",
|
||||||
|
"UILoadingBarTest_Scale9_State_Change",
|
||||||
"UILoadingBarTest_Left_Scale9",
|
"UILoadingBarTest_Left_Scale9",
|
||||||
"UILoadingBarTest_Right_Scale9",
|
"UILoadingBarTest_Right_Scale9",
|
||||||
|
|
||||||
|
@ -210,6 +214,8 @@ Scene *UISceneManager::currentUIScene()
|
||||||
|
|
||||||
case kUIButtonTest_Scale9:
|
case kUIButtonTest_Scale9:
|
||||||
return UIButtonTest_Scale9::sceneWithTitle(s_testArray[_currentUISceneId]);
|
return UIButtonTest_Scale9::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||||
|
case kUIButtonTest_Scale9_State_Change:
|
||||||
|
return UIButtonTest_Scale9_State_Change::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||||
|
|
||||||
case kUIButtonTest_PressedAction:
|
case kUIButtonTest_PressedAction:
|
||||||
return UIButtonTest_PressedAction::sceneWithTitle(s_testArray[_currentUISceneId]);
|
return UIButtonTest_PressedAction::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||||
|
@ -245,6 +251,8 @@ Scene *UISceneManager::currentUIScene()
|
||||||
|
|
||||||
case kUISliderTest_Scale9:
|
case kUISliderTest_Scale9:
|
||||||
return UISliderTest_Scale9::sceneWithTitle(s_testArray[_currentUISceneId]);
|
return UISliderTest_Scale9::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||||
|
case kUISliderTest_Scale9_State_Change:
|
||||||
|
return UISliderTest_Scale9_State_Change::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||||
case kUISliderNormalDefaultTest:
|
case kUISliderNormalDefaultTest:
|
||||||
return UISliderNormalDefaultTest::sceneWithTitle(s_testArray[_currentUISceneId]);
|
return UISliderNormalDefaultTest::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||||
case kUISliderDisabledDefaultTest:
|
case kUISliderDisabledDefaultTest:
|
||||||
|
@ -255,6 +263,8 @@ Scene *UISceneManager::currentUIScene()
|
||||||
|
|
||||||
case kUIImageViewTest_Scale9:
|
case kUIImageViewTest_Scale9:
|
||||||
return UIImageViewTest_Scale9::sceneWithTitle(s_testArray[_currentUISceneId]);
|
return UIImageViewTest_Scale9::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||||
|
case kUIImageViewTest_Scale9_State_Change:
|
||||||
|
return UIImageViewTest_Scale9_State_Change::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||||
case kUIImageViewTest_ContentSize:
|
case kUIImageViewTest_ContentSize:
|
||||||
return UIImageViewTest_ContentSize::sceneWithTitle(s_testArray[_currentUISceneId]);
|
return UIImageViewTest_ContentSize::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||||
case kUIImageViewFlipTest:
|
case kUIImageViewFlipTest:
|
||||||
|
@ -266,6 +276,9 @@ Scene *UISceneManager::currentUIScene()
|
||||||
case kUILoadingBarTest_Right:
|
case kUILoadingBarTest_Right:
|
||||||
return UILoadingBarTest_Right::sceneWithTitle(s_testArray[_currentUISceneId]);
|
return UILoadingBarTest_Right::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||||
|
|
||||||
|
case kUILoadingBarTest_Scale9_State_Change:
|
||||||
|
return UILoadingBarTest_Scale9_State_Change::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||||
|
|
||||||
case kUILoadingBarTest_Left_Scale9:
|
case kUILoadingBarTest_Left_Scale9:
|
||||||
return UILoadingBarTest_Left_Scale9::sceneWithTitle(s_testArray[_currentUISceneId]);
|
return UILoadingBarTest_Left_Scale9::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ enum
|
||||||
{
|
{
|
||||||
kUIButtonTest = 0,
|
kUIButtonTest = 0,
|
||||||
kUIButtonTest_Scale9,
|
kUIButtonTest_Scale9,
|
||||||
|
kUIButtonTest_Scale9_State_Change,
|
||||||
kUIButtonTest_PressedAction,
|
kUIButtonTest_PressedAction,
|
||||||
kUIButtonTest_Title,
|
kUIButtonTest_Title,
|
||||||
kUIButtonTest_RemoveSelf,
|
kUIButtonTest_RemoveSelf,
|
||||||
|
@ -51,15 +52,18 @@ enum
|
||||||
kUICheckBoxDefaultBehaviorTest,
|
kUICheckBoxDefaultBehaviorTest,
|
||||||
kUISliderTest,
|
kUISliderTest,
|
||||||
kUISliderTest_Scale9,
|
kUISliderTest_Scale9,
|
||||||
|
kUISliderTest_Scale9_State_Change,
|
||||||
kUISliderNormalDefaultTest,
|
kUISliderNormalDefaultTest,
|
||||||
kUISliderDisabledDefaultTest,
|
kUISliderDisabledDefaultTest,
|
||||||
kUIImageViewTest,
|
kUIImageViewTest,
|
||||||
kUIImageViewTest_Scale9,
|
kUIImageViewTest_Scale9,
|
||||||
|
kUIImageViewTest_Scale9_State_Change,
|
||||||
kUIImageViewTest_ContentSize,
|
kUIImageViewTest_ContentSize,
|
||||||
kUIImageViewFlipTest,
|
kUIImageViewFlipTest,
|
||||||
|
|
||||||
kUILoadingBarTest_Left,
|
kUILoadingBarTest_Left,
|
||||||
kUILoadingBarTest_Right,
|
kUILoadingBarTest_Right,
|
||||||
|
kUILoadingBarTest_Scale9_State_Change,
|
||||||
kUILoadingBarTest_Left_Scale9,
|
kUILoadingBarTest_Left_Scale9,
|
||||||
kUILoadingBarTest_Right_Scale9,
|
kUILoadingBarTest_Right_Scale9,
|
||||||
kUITextAtlasTest,
|
kUITextAtlasTest,
|
||||||
|
|
|
@ -116,6 +116,73 @@ void UISliderTest_Scale9::sliderEvent(Ref *pSender, Slider::EventType type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// UISliderNormalDefaultTest
|
// UISliderNormalDefaultTest
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,19 @@ protected:
|
||||||
Text* _displayValueLabel;
|
Text* _displayValueLabel;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class UISliderTest_Scale9_State_Change : public UIScene
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
UISliderTest_Scale9_State_Change();
|
||||||
|
~UISliderTest_Scale9_State_Change();
|
||||||
|
bool init();
|
||||||
|
void sliderEvent(Ref* pSender, Slider::EventType type);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
UI_SCENE_CREATE_FUNC(UISliderTest_Scale9_State_Change)
|
||||||
|
Text* _displayValueLabel;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class UISliderNormalDefaultTest : public UIScene
|
class UISliderNormalDefaultTest : public UIScene
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue