mirror of https://github.com/axmolengine/axmol.git
finish tests
This commit is contained in:
parent
4bfa94b8c2
commit
8433127b45
|
@ -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)));
|
||||||
|
|
||||||
|
|
|
@ -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__) */
|
||||||
|
|
|
@ -56,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",
|
||||||
|
@ -237,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]);
|
||||||
|
|
||||||
|
|
|
@ -51,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