mirror of https://github.com/axmolengine/axmol.git
Merge pull request #9028 from andyque/fixWidgetFlipIssue
Fix widget flip issue
This commit is contained in:
commit
b8bb61c7c6
|
@ -236,8 +236,7 @@ void Button::loadTextureNormal(const std::string& normal,TextureResType texType)
|
||||||
}
|
}
|
||||||
|
|
||||||
_normalTextureSize = _buttonNormalRenderer->getContentSize();
|
_normalTextureSize = _buttonNormalRenderer->getContentSize();
|
||||||
updateFlippedX();
|
|
||||||
updateFlippedY();
|
|
||||||
this->updateChildrenDisplayedRGBA();
|
this->updateChildrenDisplayedRGBA();
|
||||||
|
|
||||||
if (_unifySize )
|
if (_unifySize )
|
||||||
|
@ -277,9 +276,7 @@ void Button::loadTexturePressed(const std::string& selected,TextureResType texTy
|
||||||
}
|
}
|
||||||
|
|
||||||
_pressedTextureSize = _buttonClickedRenderer->getContentSize();
|
_pressedTextureSize = _buttonClickedRenderer->getContentSize();
|
||||||
//TODO: mark as dirty
|
|
||||||
updateFlippedX();
|
|
||||||
updateFlippedY();
|
|
||||||
this->updateChildrenDisplayedRGBA();
|
this->updateChildrenDisplayedRGBA();
|
||||||
|
|
||||||
_pressedTextureLoaded = true;
|
_pressedTextureLoaded = true;
|
||||||
|
@ -308,8 +305,7 @@ void Button::loadTextureDisabled(const std::string& disabled,TextureResType texT
|
||||||
}
|
}
|
||||||
|
|
||||||
_disabledTextureSize = _buttonDisableRenderer->getContentSize();
|
_disabledTextureSize = _buttonDisableRenderer->getContentSize();
|
||||||
updateFlippedX();
|
|
||||||
updateFlippedY();
|
|
||||||
this->updateChildrenDisplayedRGBA();
|
this->updateChildrenDisplayedRGBA();
|
||||||
|
|
||||||
_disabledTextureLoaded = true;
|
_disabledTextureLoaded = true;
|
||||||
|
@ -540,25 +536,6 @@ void Button::onPressStateChangedToDisabled()
|
||||||
_buttonClickedRenderer->setScale(_pressedTextureScaleXInSize, _pressedTextureScaleYInSize);
|
_buttonClickedRenderer->setScale(_pressedTextureScaleXInSize, _pressedTextureScaleYInSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Button::updateFlippedX()
|
|
||||||
{
|
|
||||||
float flip = _flippedX ? -1.0f : 1.0f;
|
|
||||||
_titleRenderer->setScaleX(flip);
|
|
||||||
|
|
||||||
_buttonNormalRenderer->setFlippedX(_flippedX);
|
|
||||||
_buttonClickedRenderer->setFlippedX(_flippedX);
|
|
||||||
_buttonDisableRenderer->setFlippedX(_flippedX);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Button::updateFlippedY()
|
|
||||||
{
|
|
||||||
float flip = _flippedY ? -1.0f : 1.0f;
|
|
||||||
_titleRenderer->setScaleY(flip);
|
|
||||||
_buttonNormalRenderer->setFlippedY(_flippedY);
|
|
||||||
_buttonClickedRenderer->setFlippedY(_flippedY);
|
|
||||||
_buttonDisableRenderer->setFlippedY(_flippedY);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Button::updateTitleLocation()
|
void Button::updateTitleLocation()
|
||||||
{
|
{
|
||||||
_titleRenderer->setPosition(_contentSize.width * 0.5f, _contentSize.height * 0.5f);
|
_titleRenderer->setPosition(_contentSize.width * 0.5f, _contentSize.height * 0.5f);
|
||||||
|
|
|
@ -220,9 +220,6 @@ protected:
|
||||||
virtual void onPressStateChangedToDisabled() override;
|
virtual void onPressStateChangedToDisabled() override;
|
||||||
virtual void onSizeChanged() override;
|
virtual void onSizeChanged() override;
|
||||||
|
|
||||||
virtual void updateFlippedX() override;
|
|
||||||
virtual void updateFlippedY() override;
|
|
||||||
|
|
||||||
void normalTextureScaleChangedWithSize();
|
void normalTextureScaleChangedWithSize();
|
||||||
void pressedTextureScaleChangedWithSize();
|
void pressedTextureScaleChangedWithSize();
|
||||||
void disabledTextureScaleChangedWithSize();
|
void disabledTextureScaleChangedWithSize();
|
||||||
|
|
|
@ -182,8 +182,7 @@ void CheckBox::loadTextureBackGround(const std::string& backGround,TextureResTyp
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
updateFlippedX();
|
|
||||||
updateFlippedY();
|
|
||||||
this->updateChildrenDisplayedRGBA();
|
this->updateChildrenDisplayedRGBA();
|
||||||
|
|
||||||
updateContentSizeWithTextureSize(_backGroundBoxRenderer->getContentSize());
|
updateContentSizeWithTextureSize(_backGroundBoxRenderer->getContentSize());
|
||||||
|
@ -209,8 +208,7 @@ void CheckBox::loadTextureBackGroundSelected(const std::string& backGroundSelect
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
updateFlippedX();
|
|
||||||
updateFlippedY();
|
|
||||||
this->updateChildrenDisplayedRGBA();
|
this->updateChildrenDisplayedRGBA();
|
||||||
|
|
||||||
_backGroundSelectedBoxRendererAdaptDirty = true;
|
_backGroundSelectedBoxRendererAdaptDirty = true;
|
||||||
|
@ -235,8 +233,7 @@ void CheckBox::loadTextureFrontCross(const std::string& cross,TextureResType tex
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
updateFlippedX();
|
|
||||||
updateFlippedY();
|
|
||||||
this->updateChildrenDisplayedRGBA();
|
this->updateChildrenDisplayedRGBA();
|
||||||
|
|
||||||
_frontCrossRendererAdaptDirty = true;
|
_frontCrossRendererAdaptDirty = true;
|
||||||
|
@ -261,8 +258,7 @@ void CheckBox::loadTextureBackGroundDisabled(const std::string& backGroundDisabl
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
updateFlippedX();
|
|
||||||
updateFlippedY();
|
|
||||||
this->updateChildrenDisplayedRGBA();
|
this->updateChildrenDisplayedRGBA();
|
||||||
|
|
||||||
_backGroundBoxDisabledRendererAdaptDirty = true;
|
_backGroundBoxDisabledRendererAdaptDirty = true;
|
||||||
|
@ -287,8 +283,7 @@ void CheckBox::loadTextureFrontCrossDisabled(const std::string& frontCrossDisabl
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
updateFlippedX();
|
|
||||||
updateFlippedY();
|
|
||||||
this->updateChildrenDisplayedRGBA();
|
this->updateChildrenDisplayedRGBA();
|
||||||
|
|
||||||
_frontCrossDisabledRendererAdaptDirty = true;
|
_frontCrossDisabledRendererAdaptDirty = true;
|
||||||
|
@ -397,24 +392,6 @@ void CheckBox::addEventListener(const ccCheckBoxCallback& callback)
|
||||||
_checkBoxEventCallback = callback;
|
_checkBoxEventCallback = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckBox::updateFlippedX()
|
|
||||||
{
|
|
||||||
_backGroundBoxRenderer->setFlippedX(_flippedX);
|
|
||||||
_backGroundSelectedBoxRenderer->setFlippedX(_flippedX);
|
|
||||||
_frontCrossRenderer->setFlippedX(_flippedX);
|
|
||||||
_backGroundBoxDisabledRenderer->setFlippedX(_flippedX);
|
|
||||||
_frontCrossDisabledRenderer->setFlippedX(_flippedX);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckBox::updateFlippedY()
|
|
||||||
{
|
|
||||||
_backGroundBoxRenderer->setFlippedY(_flippedY);
|
|
||||||
_backGroundSelectedBoxRenderer->setFlippedY(_flippedY);
|
|
||||||
_frontCrossRenderer->setFlippedY(_flippedY);
|
|
||||||
_backGroundBoxDisabledRenderer->setFlippedY(_flippedY);
|
|
||||||
_frontCrossDisabledRenderer->setFlippedY(_flippedY);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckBox::onSizeChanged()
|
void CheckBox::onSizeChanged()
|
||||||
{
|
{
|
||||||
Widget::onSizeChanged();
|
Widget::onSizeChanged();
|
||||||
|
|
|
@ -216,9 +216,6 @@ protected:
|
||||||
|
|
||||||
virtual void onSizeChanged() override;
|
virtual void onSizeChanged() override;
|
||||||
|
|
||||||
virtual void updateFlippedX() override;
|
|
||||||
virtual void updateFlippedY() override;
|
|
||||||
|
|
||||||
void backGroundTextureScaleChangedWithSize();
|
void backGroundTextureScaleChangedWithSize();
|
||||||
void backGroundSelectedTextureScaleChangedWithSize();
|
void backGroundSelectedTextureScaleChangedWithSize();
|
||||||
void frontCrossTextureScaleChangedWithSize();
|
void frontCrossTextureScaleChangedWithSize();
|
||||||
|
|
|
@ -131,8 +131,7 @@ void ImageView::loadTexture(const std::string& fileName, TextureResType texType)
|
||||||
}
|
}
|
||||||
|
|
||||||
_imageTextureSize = _imageRenderer->getContentSize();
|
_imageTextureSize = _imageRenderer->getContentSize();
|
||||||
updateFlippedX();
|
|
||||||
updateFlippedY();
|
|
||||||
this->updateChildrenDisplayedRGBA();
|
this->updateChildrenDisplayedRGBA();
|
||||||
|
|
||||||
updateContentSizeWithTextureSize(_imageTextureSize);
|
updateContentSizeWithTextureSize(_imageTextureSize);
|
||||||
|
@ -159,17 +158,6 @@ void ImageView::setTextureRect(const Rect &rect)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImageView::updateFlippedX()
|
|
||||||
{
|
|
||||||
_imageRenderer->setFlippedX(_flippedX);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImageView::updateFlippedY()
|
|
||||||
{
|
|
||||||
_imageRenderer->setFlippedY(_flippedY);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImageView::setScale9Enabled(bool able)
|
void ImageView::setScale9Enabled(bool able)
|
||||||
{
|
{
|
||||||
if (_scale9Enabled == able)
|
if (_scale9Enabled == able)
|
||||||
|
|
|
@ -120,9 +120,6 @@ protected:
|
||||||
virtual void initRenderer() override;
|
virtual void initRenderer() override;
|
||||||
virtual void onSizeChanged() override;
|
virtual void onSizeChanged() override;
|
||||||
|
|
||||||
virtual void updateFlippedX() override;
|
|
||||||
virtual void updateFlippedY() override;
|
|
||||||
|
|
||||||
virtual void adaptRenderers() override;
|
virtual void adaptRenderers() override;
|
||||||
|
|
||||||
void imageTextureScaleChangedWithSize();
|
void imageTextureScaleChangedWithSize();
|
||||||
|
|
|
@ -257,30 +257,6 @@ void Text::onPressStateChangedToDisabled()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Text::updateFlippedX()
|
|
||||||
{
|
|
||||||
if (_flippedX)
|
|
||||||
{
|
|
||||||
_labelRenderer->setScaleX(-1.0f);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_labelRenderer->setScaleX(1.0f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Text::updateFlippedY()
|
|
||||||
{
|
|
||||||
if (_flippedY)
|
|
||||||
{
|
|
||||||
_labelRenderer->setScaleY(-1.0f);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_labelRenderer->setScaleY(1.0f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Text::onSizeChanged()
|
void Text::onSizeChanged()
|
||||||
{
|
{
|
||||||
Widget::onSizeChanged();
|
Widget::onSizeChanged();
|
||||||
|
|
|
@ -197,8 +197,6 @@ protected:
|
||||||
virtual void onPressStateChangedToDisabled() override;
|
virtual void onPressStateChangedToDisabled() override;
|
||||||
virtual void onSizeChanged() override;
|
virtual void onSizeChanged() override;
|
||||||
|
|
||||||
virtual void updateFlippedX() override;
|
|
||||||
virtual void updateFlippedY() override;
|
|
||||||
void labelScaleChangedWithSize();
|
void labelScaleChangedWithSize();
|
||||||
virtual Widget* createCloneInstance() override;
|
virtual Widget* createCloneInstance() override;
|
||||||
virtual void copySpecialProperties(Widget* model) override;
|
virtual void copySpecialProperties(Widget* model) override;
|
||||||
|
|
|
@ -1135,17 +1135,77 @@ void Widget::copyProperties(Widget *widget)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::setFlippedX(bool flippedX)
|
void Widget::setFlippedX(bool flippedX)
|
||||||
{
|
{
|
||||||
_flippedX = flippedX;
|
|
||||||
updateFlippedX();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Widget::setFlippedY(bool flippedY)
|
float realScale = this->getScaleX();
|
||||||
{
|
_flippedX = flippedX;
|
||||||
_flippedY = flippedY;
|
this->setScaleX(realScale);
|
||||||
updateFlippedY();
|
}
|
||||||
}
|
|
||||||
|
void Widget::setFlippedY(bool flippedY)
|
||||||
|
{
|
||||||
|
float realScale = this->getScaleY();
|
||||||
|
_flippedY = flippedY;
|
||||||
|
this->setScaleY(realScale);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Widget::setScaleX(float scaleX)
|
||||||
|
{
|
||||||
|
if (_flippedX) {
|
||||||
|
scaleX = scaleX * -1;
|
||||||
|
}
|
||||||
|
Node::setScaleX(scaleX);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Widget::setScaleY(float scaleY)
|
||||||
|
{
|
||||||
|
if (_flippedY) {
|
||||||
|
scaleY = scaleY * -1;
|
||||||
|
}
|
||||||
|
Node::setScaleY(scaleY);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Widget::setScale(float scale)
|
||||||
|
{
|
||||||
|
this->setScaleX(scale);
|
||||||
|
this->setScaleY(scale);
|
||||||
|
this->setScaleZ(scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Widget::setScale(float scaleX, float scaleY)
|
||||||
|
{
|
||||||
|
this->setScaleX(scaleX);
|
||||||
|
this->setScaleY(scaleY);
|
||||||
|
}
|
||||||
|
|
||||||
|
float Widget::getScaleX()const
|
||||||
|
{
|
||||||
|
float originalScale = Node::getScaleX();
|
||||||
|
if (_flippedX)
|
||||||
|
{
|
||||||
|
originalScale = originalScale * -1.0;
|
||||||
|
}
|
||||||
|
return originalScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Widget::getScaleY()const
|
||||||
|
{
|
||||||
|
float originalScale = Node::getScaleY();
|
||||||
|
if (_flippedY)
|
||||||
|
{
|
||||||
|
originalScale = originalScale * -1.0;
|
||||||
|
}
|
||||||
|
return originalScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Widget::getScale()const
|
||||||
|
{
|
||||||
|
CCASSERT(this->getScaleX() == this->getScaleY(), "");
|
||||||
|
return this->getScaleX();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*temp action*/
|
/*temp action*/
|
||||||
|
|
|
@ -333,6 +333,17 @@ public:
|
||||||
/** @deprecated Use setFlippedY() instead */
|
/** @deprecated Use setFlippedY() instead */
|
||||||
CC_DEPRECATED_ATTRIBUTE void setFlipY(bool flipY) { setFlippedY(flipY); };
|
CC_DEPRECATED_ATTRIBUTE void setFlipY(bool flipY) { setFlippedY(flipY); };
|
||||||
|
|
||||||
|
//override the setScale function of Node
|
||||||
|
virtual void setScaleX(float scaleX) override;
|
||||||
|
virtual void setScaleY(float scaleY) override;
|
||||||
|
virtual void setScale(float scale) override;
|
||||||
|
virtual void setScale(float scalex, float scaley) override;
|
||||||
|
using Node::setScaleZ;
|
||||||
|
virtual float getScaleX() const override;
|
||||||
|
virtual float getScaleY() const override;
|
||||||
|
virtual float getScale() const override;
|
||||||
|
using Node::getScaleZ;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Checks a point if in parent's area.
|
* Checks a point if in parent's area.
|
||||||
*
|
*
|
||||||
|
@ -663,8 +674,7 @@ protected:
|
||||||
virtual void releaseUpEvent();
|
virtual void releaseUpEvent();
|
||||||
virtual void cancelUpEvent();
|
virtual void cancelUpEvent();
|
||||||
|
|
||||||
virtual void updateFlippedX(){};
|
|
||||||
virtual void updateFlippedY(){};
|
|
||||||
virtual void adaptRenderers(){};
|
virtual void adaptRenderers(){};
|
||||||
void updateChildrenDisplayedRGBA();
|
void updateChildrenDisplayedRGBA();
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,7 @@ g_guisTests[] =
|
||||||
UISceneManager* sceneManager = UISceneManager::sharedUISceneManager();
|
UISceneManager* sceneManager = UISceneManager::sharedUISceneManager();
|
||||||
sceneManager->setCurrentUISceneId(kUIButtonTest);
|
sceneManager->setCurrentUISceneId(kUIButtonTest);
|
||||||
sceneManager->setMinUISceneId(kUIButtonTest);
|
sceneManager->setMinUISceneId(kUIButtonTest);
|
||||||
sceneManager->setMaxUISceneId(kUIButtonTitleEffectTest);
|
sceneManager->setMaxUISceneId(kUIButtonFlipTest);
|
||||||
Scene* scene = sceneManager->currentUIScene();
|
Scene* scene = sceneManager->currentUIScene();
|
||||||
Director::getInstance()->replaceScene(scene);
|
Director::getInstance()->replaceScene(scene);
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ g_guisTests[] =
|
||||||
UISceneManager* sceneManager = UISceneManager::sharedUISceneManager();
|
UISceneManager* sceneManager = UISceneManager::sharedUISceneManager();
|
||||||
sceneManager->setCurrentUISceneId(kUIImageViewTest);
|
sceneManager->setCurrentUISceneId(kUIImageViewTest);
|
||||||
sceneManager->setMinUISceneId(kUIImageViewTest);
|
sceneManager->setMinUISceneId(kUIImageViewTest);
|
||||||
sceneManager->setMaxUISceneId(kUIImageViewTest_ContentSize);
|
sceneManager->setMaxUISceneId(kUIImageViewFlipTest);
|
||||||
Scene* scene = sceneManager->currentUIScene();
|
Scene* scene = sceneManager->currentUIScene();
|
||||||
Director::getInstance()->replaceScene(scene);
|
Director::getInstance()->replaceScene(scene);
|
||||||
}
|
}
|
||||||
|
|
|
@ -290,7 +290,7 @@ bool UIButtonTest_Title::init()
|
||||||
_uiLayer->addChild(_displayValueLabel);
|
_uiLayer->addChild(_displayValueLabel);
|
||||||
|
|
||||||
// Add the alert
|
// Add the alert
|
||||||
Text* alert = Text::create("Button with title", "fonts/Marker Felt.ttf", 30);
|
Text* alert = Text::create("Button with title, title should be flipped!", "fonts/Marker Felt.ttf", 30);
|
||||||
alert->setColor(Color3B(159, 168, 176));
|
alert->setColor(Color3B(159, 168, 176));
|
||||||
alert->setPosition(Vec2(widgetSize.width / 2.0f,
|
alert->setPosition(Vec2(widgetSize.width / 2.0f,
|
||||||
widgetSize.height / 2.0f - alert->getContentSize().height * 1.75f));
|
widgetSize.height / 2.0f - alert->getContentSize().height * 1.75f));
|
||||||
|
@ -305,7 +305,9 @@ bool UIButtonTest_Title::init()
|
||||||
CCASSERT(button->getTitleColor() == Color3B::YELLOW, "Button setTitleColotr & getTitleColor not match!");
|
CCASSERT(button->getTitleColor() == Color3B::YELLOW, "Button setTitleColotr & getTitleColor not match!");
|
||||||
button->addTouchEventListener(CC_CALLBACK_2(UIButtonTest_Title::touchEvent, this));
|
button->addTouchEventListener(CC_CALLBACK_2(UIButtonTest_Title::touchEvent, this));
|
||||||
_uiLayer->addChild(button);
|
_uiLayer->addChild(button);
|
||||||
|
button->setFlippedX(true);
|
||||||
|
auto label = button->getTitleRenderer();
|
||||||
|
label->setScale(4.0);
|
||||||
button->runAction(RepeatForever::create(Sequence::create(ScaleTo::create(1.0f, 1.2f),
|
button->runAction(RepeatForever::create(Sequence::create(ScaleTo::create(1.0f, 1.2f),
|
||||||
ScaleTo::create(1.0f, 1.0f),nullptr)));
|
ScaleTo::create(1.0f, 1.0f),nullptr)));
|
||||||
|
|
||||||
|
@ -470,14 +472,6 @@ bool UIButtonTestSwitchScale9::init()
|
||||||
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
|
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
|
||||||
_uiLayer->addChild(_displayValueLabel);
|
_uiLayer->addChild(_displayValueLabel);
|
||||||
|
|
||||||
// Add the alert
|
|
||||||
Text* alert = Text::create("Button","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
|
// Create the button
|
||||||
Button* button = Button::create("cocosui/animationbuttonnormal.png",
|
Button* button = Button::create("cocosui/animationbuttonnormal.png",
|
||||||
|
@ -550,14 +544,6 @@ bool UIButtonTestZoomScale::init()
|
||||||
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 20));
|
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 20));
|
||||||
_uiLayer->addChild(_displayValueLabel);
|
_uiLayer->addChild(_displayValueLabel);
|
||||||
|
|
||||||
// Add the alert
|
|
||||||
Text* alert = Text::create("Button","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
|
// Create the button
|
||||||
Button* button = Button::create("cocosui/animationbuttonnormal.png",
|
Button* button = Button::create("cocosui/animationbuttonnormal.png",
|
||||||
|
@ -622,14 +608,6 @@ bool UIButtonTextOnly::init()
|
||||||
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 20));
|
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 20));
|
||||||
_uiLayer->addChild(_displayValueLabel);
|
_uiLayer->addChild(_displayValueLabel);
|
||||||
|
|
||||||
// Add the alert
|
|
||||||
Text* alert = Text::create("Button","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
|
// Create the button
|
||||||
auto button = Button::create();
|
auto button = Button::create();
|
||||||
|
@ -673,14 +651,6 @@ bool UIButtonIgnoreContentSizeTest::init()
|
||||||
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 20));
|
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 20));
|
||||||
_uiLayer->addChild(_displayValueLabel);
|
_uiLayer->addChild(_displayValueLabel);
|
||||||
|
|
||||||
// Add the alert
|
|
||||||
Text* alert = Text::create("Button","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
|
// Create the button
|
||||||
auto button = Button::create("cocosui/animationbuttonnormal.png",
|
auto button = Button::create("cocosui/animationbuttonnormal.png",
|
||||||
|
@ -741,14 +711,6 @@ bool UIButtonTitleEffectTest::init()
|
||||||
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 20));
|
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 20));
|
||||||
_uiLayer->addChild(_displayValueLabel);
|
_uiLayer->addChild(_displayValueLabel);
|
||||||
|
|
||||||
// Add the alert
|
|
||||||
Text* alert = Text::create("Button","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
|
// Create the button
|
||||||
auto button = Button::create("cocosui/animationbuttonnormal.png",
|
auto button = Button::create("cocosui/animationbuttonnormal.png",
|
||||||
|
@ -779,5 +741,57 @@ bool UIButtonTitleEffectTest::init()
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// UIButtonFlipTest
|
||||||
|
UIButtonFlipTest::UIButtonFlipTest()
|
||||||
|
: _displayValueLabel(nullptr)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
UIButtonFlipTest::~UIButtonFlipTest()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool UIButtonFlipTest::init()
|
||||||
|
{
|
||||||
|
if (UIScene::init())
|
||||||
|
{
|
||||||
|
Size widgetSize = _widget->getContentSize();
|
||||||
|
|
||||||
|
// Add a label in which the button events will be displayed
|
||||||
|
_displayValueLabel = Text::create("Button X Flipped", "fonts/Marker Felt.ttf",20);
|
||||||
|
_displayValueLabel->setNormalizedPosition(Vec2(0.3, 0.7));
|
||||||
|
_uiLayer->addChild(_displayValueLabel);
|
||||||
|
|
||||||
|
|
||||||
|
// Create the button
|
||||||
|
auto button = Button::create("cocosui/animationbuttonnormal.png",
|
||||||
|
"cocosui/animationbuttonpressed.png");
|
||||||
|
button->setNormalizedPosition(Vec2(0.3f, 0.5f));
|
||||||
|
button->setTitleText("PLAY GAME");
|
||||||
|
button->setTitleFontName("fonts/Marker Felt.ttf");
|
||||||
|
button->setZoomScale(0.3f);
|
||||||
|
button->setScale(2.0f);
|
||||||
|
button->setFlippedX(true);
|
||||||
|
button->setPressedActionEnabled(true);
|
||||||
|
|
||||||
|
|
||||||
|
_uiLayer->addChild(button);
|
||||||
|
|
||||||
|
// Create the button
|
||||||
|
auto button2 = Button::create("cocosui/animationbuttonnormal.png",
|
||||||
|
"cocosui/animationbuttonpressed.png");
|
||||||
|
button2->setNormalizedPosition(Vec2(0.8f, 0.5f));
|
||||||
|
button2->setTitleText("PLAY GAME");
|
||||||
|
button2->setFlippedY(true);
|
||||||
|
_uiLayer->addChild(button2);
|
||||||
|
|
||||||
|
auto titleLabel = Text::create("Button Y flipped", "Arial", 20);
|
||||||
|
titleLabel->setNormalizedPosition(Vec2(0.8, 0.7));
|
||||||
|
this->addChild(titleLabel);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -153,4 +153,16 @@ protected:
|
||||||
UI_SCENE_CREATE_FUNC(UIButtonTitleEffectTest)
|
UI_SCENE_CREATE_FUNC(UIButtonTitleEffectTest)
|
||||||
Text* _displayValueLabel;
|
Text* _displayValueLabel;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class UIButtonFlipTest : public UIScene
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
UIButtonFlipTest();
|
||||||
|
~UIButtonFlipTest();
|
||||||
|
bool init();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
UI_SCENE_CREATE_FUNC(UIButtonFlipTest)
|
||||||
|
Text* _displayValueLabel;
|
||||||
|
};
|
||||||
#endif /* defined(__TestCpp__UIButtonTest__) */
|
#endif /* defined(__TestCpp__UIButtonTest__) */
|
||||||
|
|
|
@ -129,3 +129,55 @@ bool UIImageViewTest_ContentSize::init()
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// UIImageViewFlipTest
|
||||||
|
|
||||||
|
bool UIImageViewFlipTest::init()
|
||||||
|
{
|
||||||
|
if (UIScene::init())
|
||||||
|
{
|
||||||
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("Images/blocks9ss.plist");
|
||||||
|
Size widgetSize = _widget->getContentSize();
|
||||||
|
|
||||||
|
Text* alert = Text::create("ImageView flip test", "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("blocks9r.png", Widget::TextureResType::PLIST);
|
||||||
|
imageView->setScale9Enabled(true);
|
||||||
|
imageView->setContentSize(Size(250, 115));
|
||||||
|
imageView->setFlippedX(true);
|
||||||
|
imageView->setScale(0.5);
|
||||||
|
imageView->ignoreContentAdaptWithSize(false);
|
||||||
|
imageView->setPosition(Vec2(widgetSize.width / 2.0f,
|
||||||
|
widgetSize.height / 2.0f));
|
||||||
|
|
||||||
|
_uiLayer->addChild(imageView);
|
||||||
|
|
||||||
|
auto toggleButton = Button::create();
|
||||||
|
toggleButton->setTitleText("Toggle FlipX");
|
||||||
|
toggleButton->setPosition(imageView->getPosition() + Vec2(-50, - imageView->getContentSize().height/2 - 20));
|
||||||
|
this->addChild(toggleButton);
|
||||||
|
toggleButton->addClickEventListener([=](Ref*){
|
||||||
|
imageView->setFlippedX(!imageView->isFlippedX());
|
||||||
|
});
|
||||||
|
|
||||||
|
auto toggleScale9 = Button::create();
|
||||||
|
toggleScale9->setTitleText("Toggle Scale9");
|
||||||
|
toggleScale9->setPosition(imageView->getPosition() + Vec2(+50, - imageView->getContentSize().height/2- 20));
|
||||||
|
this->addChild(toggleScale9);
|
||||||
|
toggleScale9->addClickEventListener([=](Ref*){
|
||||||
|
imageView->setScale9Enabled(!imageView->isScale9Enabled());
|
||||||
|
//after switching scale9, you must call setContentSize to keep the size not change
|
||||||
|
imageView->setContentSize(Size(250, 115));
|
||||||
|
});
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
|
@ -54,4 +54,13 @@ protected:
|
||||||
UI_SCENE_CREATE_FUNC(UIImageViewTest_ContentSize)
|
UI_SCENE_CREATE_FUNC(UIImageViewTest_ContentSize)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class UIImageViewFlipTest : public UIScene
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
bool init();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
UI_SCENE_CREATE_FUNC(UIImageViewFlipTest)
|
||||||
|
};
|
||||||
|
|
||||||
#endif /* defined(__TestCpp__UIImageViewTest__) */
|
#endif /* defined(__TestCpp__UIImageViewTest__) */
|
||||||
|
|
|
@ -44,6 +44,7 @@ static const char* s_testArray[] =
|
||||||
"UIButtonTextOnly",
|
"UIButtonTextOnly",
|
||||||
"UIButtonIgnoreContentSizeTest",
|
"UIButtonIgnoreContentSizeTest",
|
||||||
"UIButtonTitleEffectTest",
|
"UIButtonTitleEffectTest",
|
||||||
|
"UIButtonFlipTest",
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
||||||
"UIEditBoxTest",
|
"UIEditBoxTest",
|
||||||
|
@ -55,6 +56,7 @@ static const char* s_testArray[] =
|
||||||
"UIImageViewTest",
|
"UIImageViewTest",
|
||||||
"UIImageViewTest_Scale9",
|
"UIImageViewTest_Scale9",
|
||||||
"UIImageViewTest_ContentSize",
|
"UIImageViewTest_ContentSize",
|
||||||
|
"UIImageViewFlipTest",
|
||||||
|
|
||||||
"UILoadingBarTest_Left",
|
"UILoadingBarTest_Left",
|
||||||
"UILoadingBarTest_Right",
|
"UILoadingBarTest_Right",
|
||||||
|
@ -218,6 +220,8 @@ Scene *UISceneManager::currentUIScene()
|
||||||
return UIButtonIgnoreContentSizeTest::sceneWithTitle(s_testArray[_currentUISceneId]);
|
return UIButtonIgnoreContentSizeTest::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||||
case kUIButtonTitleEffectTest:
|
case kUIButtonTitleEffectTest:
|
||||||
return UIButtonTitleEffectTest::sceneWithTitle(s_testArray[_currentUISceneId]);
|
return UIButtonTitleEffectTest::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||||
|
case kUIButtonFlipTest:
|
||||||
|
return UIButtonFlipTest::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||||
case kUICheckBoxTest:
|
case kUICheckBoxTest:
|
||||||
return UICheckBoxTest::sceneWithTitle(s_testArray[_currentUISceneId]);
|
return UICheckBoxTest::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||||
|
|
||||||
|
@ -234,6 +238,9 @@ Scene *UISceneManager::currentUIScene()
|
||||||
return UIImageViewTest_Scale9::sceneWithTitle(s_testArray[_currentUISceneId]);
|
return UIImageViewTest_Scale9::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:
|
||||||
|
return UIImageViewFlipTest::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||||
|
|
||||||
case kUILoadingBarTest_Left:
|
case kUILoadingBarTest_Left:
|
||||||
return UILoadingBarTest_Left::sceneWithTitle(s_testArray[_currentUISceneId]);
|
return UILoadingBarTest_Left::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@ enum
|
||||||
kUIButtonTextOnly,
|
kUIButtonTextOnly,
|
||||||
kUIButtonIgnoreContentSizeTest,
|
kUIButtonIgnoreContentSizeTest,
|
||||||
kUIButtonTitleEffectTest,
|
kUIButtonTitleEffectTest,
|
||||||
|
kUIButtonFlipTest,
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
||||||
kUIEditBoxTest,
|
kUIEditBoxTest,
|
||||||
#endif
|
#endif
|
||||||
|
@ -50,6 +51,8 @@ enum
|
||||||
kUIImageViewTest,
|
kUIImageViewTest,
|
||||||
kUIImageViewTest_Scale9,
|
kUIImageViewTest_Scale9,
|
||||||
kUIImageViewTest_ContentSize,
|
kUIImageViewTest_ContentSize,
|
||||||
|
kUIImageViewFlipTest,
|
||||||
|
|
||||||
kUILoadingBarTest_Left,
|
kUILoadingBarTest_Left,
|
||||||
kUILoadingBarTest_Right,
|
kUILoadingBarTest_Right,
|
||||||
kUILoadingBarTest_Left_Scale9,
|
kUILoadingBarTest_Left_Scale9,
|
||||||
|
|
Loading…
Reference in New Issue