2013-09-16 20:54:13 +08:00
|
|
|
#include "CocosGUIScene.h"
|
2014-03-04 16:51:35 +08:00
|
|
|
#include "CocoStudioGUITest.h"
|
2013-09-16 20:54:13 +08:00
|
|
|
#include "UISceneManager.h"
|
2013-10-16 11:19:01 +08:00
|
|
|
#include "cocostudio/CocoStudio.h"
|
2013-09-16 20:54:13 +08:00
|
|
|
|
2013-12-23 15:35:35 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
LINE_SPACE = 40,
|
|
|
|
kItemTagBasic = 1000,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct
|
|
|
|
{
|
|
|
|
const char *name;
|
2014-02-20 10:53:49 +08:00
|
|
|
std::function<void(Ref* sender)> callback;
|
2013-12-23 15:35:35 +08:00
|
|
|
}
|
|
|
|
g_guisTests[] =
|
|
|
|
{
|
2014-05-14 11:26:04 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
|
|
|
{
|
|
|
|
"VideoPlayerTest",
|
|
|
|
[](Ref* sender)
|
|
|
|
{
|
2014-05-14 17:07:24 +08:00
|
|
|
UISceneManager* sceneManager = UISceneManager::sharedUISceneManager();
|
|
|
|
sceneManager->setCurrentUISceneId(kUIVideoPlayerTest);
|
|
|
|
sceneManager->setMinUISceneId(kUIVideoPlayerTest);
|
|
|
|
sceneManager->setMaxUISceneId(kUIVideoPlayerTest);
|
|
|
|
Scene* scene = sceneManager->currentUIScene();
|
|
|
|
Director::getInstance()->replaceScene(scene);
|
2014-05-14 11:26:04 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
#endif
|
2014-05-08 11:26:29 +08:00
|
|
|
{
|
2014-05-14 11:26:04 +08:00
|
|
|
"focus test",
|
2014-05-08 11:26:29 +08:00
|
|
|
[](Ref* sender)
|
|
|
|
{
|
2014-05-14 17:07:24 +08:00
|
|
|
UISceneManager* sceneManager = UISceneManager::sharedUISceneManager();
|
|
|
|
sceneManager->setCurrentUISceneId(KUIFocusTest_HBox);
|
|
|
|
sceneManager->setMinUISceneId(KUIFocusTest_HBox);
|
2014-05-20 17:56:52 +08:00
|
|
|
sceneManager->setMaxUISceneId(kUIFocusTest_ListView);
|
2014-05-14 17:07:24 +08:00
|
|
|
Scene* scene = sceneManager->currentUIScene();
|
|
|
|
Director::getInstance()->replaceScene(scene);
|
2014-05-08 11:26:29 +08:00
|
|
|
}
|
|
|
|
},
|
2013-12-23 15:35:35 +08:00
|
|
|
{
|
2014-05-08 11:26:29 +08:00
|
|
|
|
2014-05-14 11:26:04 +08:00
|
|
|
"ButtonTest",
|
2014-02-20 10:53:49 +08:00
|
|
|
[](Ref* sender)
|
2013-12-23 15:35:35 +08:00
|
|
|
{
|
2014-05-14 17:07:24 +08:00
|
|
|
UISceneManager* sceneManager = UISceneManager::sharedUISceneManager();
|
|
|
|
sceneManager->setCurrentUISceneId(kUIButtonTest);
|
|
|
|
sceneManager->setMinUISceneId(kUIButtonTest);
|
|
|
|
sceneManager->setMaxUISceneId(kUIButtonTest_Title);
|
|
|
|
Scene* scene = sceneManager->currentUIScene();
|
|
|
|
Director::getInstance()->replaceScene(scene);
|
2013-12-23 15:35:35 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2014-05-14 11:26:04 +08:00
|
|
|
"CheckBoxTest",
|
2014-02-20 10:53:49 +08:00
|
|
|
[](Ref* sender)
|
2013-12-23 15:35:35 +08:00
|
|
|
{
|
2014-05-14 17:07:24 +08:00
|
|
|
UISceneManager* sceneManager = UISceneManager::sharedUISceneManager();
|
|
|
|
sceneManager->setCurrentUISceneId(kUICheckBoxTest);
|
|
|
|
sceneManager->setMinUISceneId(kUICheckBoxTest);
|
|
|
|
sceneManager->setMaxUISceneId(kUICheckBoxTest);
|
|
|
|
Scene* scene = sceneManager->currentUIScene();
|
|
|
|
Director::getInstance()->replaceScene(scene);
|
2013-12-23 15:35:35 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2014-05-14 11:26:04 +08:00
|
|
|
"SliderTest",
|
2014-02-20 10:53:49 +08:00
|
|
|
[](Ref* sender)
|
2013-12-23 15:35:35 +08:00
|
|
|
{
|
2014-05-14 17:07:24 +08:00
|
|
|
UISceneManager* sceneManager = UISceneManager::sharedUISceneManager();
|
|
|
|
sceneManager->setCurrentUISceneId(kUISliderTest);
|
|
|
|
sceneManager->setMinUISceneId(kUISliderTest);
|
|
|
|
sceneManager->setMaxUISceneId(kUISliderTest_Scale9);
|
|
|
|
Scene* scene = sceneManager->currentUIScene();
|
|
|
|
Director::getInstance()->replaceScene(scene);
|
2013-12-23 15:35:35 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2014-05-14 11:26:04 +08:00
|
|
|
"ImageViewTest",
|
2014-02-20 10:53:49 +08:00
|
|
|
[](Ref* sender)
|
2013-12-23 15:35:35 +08:00
|
|
|
{
|
2014-05-14 17:07:24 +08:00
|
|
|
UISceneManager* sceneManager = UISceneManager::sharedUISceneManager();
|
|
|
|
sceneManager->setCurrentUISceneId(kUIImageViewTest);
|
|
|
|
sceneManager->setMinUISceneId(kUIImageViewTest);
|
|
|
|
sceneManager->setMaxUISceneId(kUIImageViewTest_Scale9);
|
|
|
|
Scene* scene = sceneManager->currentUIScene();
|
|
|
|
Director::getInstance()->replaceScene(scene);
|
2013-12-23 15:35:35 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2014-05-14 11:26:04 +08:00
|
|
|
"LoadingBarTest",
|
2014-02-20 10:53:49 +08:00
|
|
|
[](Ref* sender)
|
2013-12-23 15:35:35 +08:00
|
|
|
{
|
2014-05-14 17:07:24 +08:00
|
|
|
UISceneManager* sceneManager = UISceneManager::sharedUISceneManager();
|
|
|
|
sceneManager->setCurrentUISceneId(kUILoadingBarTest_Left);
|
|
|
|
sceneManager->setMinUISceneId(kUILoadingBarTest_Left);
|
|
|
|
sceneManager->setMaxUISceneId(kUILoadingBarTest_Right_Scale9);
|
|
|
|
Scene* scene = sceneManager->currentUIScene();
|
|
|
|
Director::getInstance()->replaceScene(scene);
|
2013-12-23 15:35:35 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2014-05-14 11:26:04 +08:00
|
|
|
"TextAtalsTest",
|
2014-02-20 10:53:49 +08:00
|
|
|
[](Ref* sender)
|
2013-12-23 15:35:35 +08:00
|
|
|
{
|
2014-05-14 17:07:24 +08:00
|
|
|
UISceneManager* sceneManager = UISceneManager::sharedUISceneManager();
|
|
|
|
sceneManager->setCurrentUISceneId(kUITextAtlasTest);
|
|
|
|
sceneManager->setMinUISceneId(kUITextAtlasTest);
|
|
|
|
sceneManager->setMaxUISceneId(kUITextAtlasTest);
|
|
|
|
Scene* scene = sceneManager->currentUIScene();
|
|
|
|
Director::getInstance()->replaceScene(scene);
|
2013-12-23 15:35:35 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2014-05-14 11:26:04 +08:00
|
|
|
"TextTest",
|
2014-02-20 10:53:49 +08:00
|
|
|
[](Ref* sender)
|
2013-12-23 15:35:35 +08:00
|
|
|
{
|
2014-05-14 17:07:24 +08:00
|
|
|
UISceneManager* sceneManager = UISceneManager::sharedUISceneManager();
|
|
|
|
sceneManager->setCurrentUISceneId(kUITextTest);
|
|
|
|
sceneManager->setMinUISceneId(kUITextTest);
|
|
|
|
sceneManager->setMaxUISceneId(kUITextTest_TTF);
|
|
|
|
Scene* scene = sceneManager->currentUIScene();
|
|
|
|
Director::getInstance()->replaceScene(scene);
|
2013-12-23 15:35:35 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2014-05-14 11:26:04 +08:00
|
|
|
"TextBMFontTest",
|
2014-02-20 10:53:49 +08:00
|
|
|
[](Ref* sender)
|
2013-12-23 15:35:35 +08:00
|
|
|
{
|
2014-05-14 17:07:24 +08:00
|
|
|
UISceneManager* sceneManager = UISceneManager::sharedUISceneManager();
|
|
|
|
sceneManager->setCurrentUISceneId(kUITextBMFontTest);
|
|
|
|
sceneManager->setMinUISceneId(kUITextBMFontTest);
|
|
|
|
sceneManager->setMaxUISceneId(kUITextBMFontTest);
|
|
|
|
Scene* scene = sceneManager->currentUIScene();
|
|
|
|
Director::getInstance()->replaceScene(scene);
|
2013-12-23 15:35:35 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2014-05-14 11:26:04 +08:00
|
|
|
"TextFieldTest",
|
2014-02-20 10:53:49 +08:00
|
|
|
[](Ref* sender)
|
2013-12-23 15:35:35 +08:00
|
|
|
{
|
2014-05-14 17:07:24 +08:00
|
|
|
UISceneManager* sceneManager = UISceneManager::sharedUISceneManager();
|
|
|
|
sceneManager->setCurrentUISceneId(kUITextFieldTest);
|
|
|
|
sceneManager->setMinUISceneId(kUITextFieldTest);
|
|
|
|
sceneManager->setMaxUISceneId(kUITextFieldTest_LineWrap);
|
|
|
|
Scene* scene = sceneManager->currentUIScene();
|
|
|
|
Director::getInstance()->replaceScene(scene);
|
2013-12-23 15:35:35 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2014-05-14 11:26:04 +08:00
|
|
|
"LayoutTest",
|
2014-02-20 10:53:49 +08:00
|
|
|
[](Ref* sender)
|
2013-12-23 15:35:35 +08:00
|
|
|
{
|
2014-05-14 17:07:24 +08:00
|
|
|
UISceneManager* sceneManager = UISceneManager::sharedUISceneManager();
|
|
|
|
sceneManager->setCurrentUISceneId(kUILayoutTest);
|
|
|
|
sceneManager->setMinUISceneId(kUILayoutTest);
|
|
|
|
sceneManager->setMaxUISceneId(kUILayoutTest_Layout_Relative_Location);
|
|
|
|
Scene* scene = sceneManager->currentUIScene();
|
|
|
|
Director::getInstance()->replaceScene(scene);
|
2013-12-23 15:35:35 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2014-05-14 11:26:04 +08:00
|
|
|
"ScrollViewTest",
|
2014-02-20 10:53:49 +08:00
|
|
|
[](Ref* sender)
|
2013-12-23 15:35:35 +08:00
|
|
|
{
|
2014-05-14 17:07:24 +08:00
|
|
|
UISceneManager* sceneManager = UISceneManager::sharedUISceneManager();
|
|
|
|
sceneManager->setCurrentUISceneId(kUIScrollViewTest_Vertical);
|
|
|
|
sceneManager->setMinUISceneId(kUIScrollViewTest_Vertical);
|
|
|
|
sceneManager->setMaxUISceneId(kUIScrollViewTest_ScrollToPercentBothDirection_Bounce);
|
|
|
|
Scene* scene = sceneManager->currentUIScene();
|
|
|
|
Director::getInstance()->replaceScene(scene);
|
2013-12-23 15:35:35 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2014-05-14 11:26:04 +08:00
|
|
|
"PageViewTest",
|
2014-02-20 10:53:49 +08:00
|
|
|
[](Ref* sender)
|
2013-12-23 15:35:35 +08:00
|
|
|
{
|
2014-05-14 17:07:24 +08:00
|
|
|
UISceneManager* sceneManager = UISceneManager::sharedUISceneManager();
|
|
|
|
sceneManager->setCurrentUISceneId(kUIPageViewTest);
|
|
|
|
sceneManager->setMinUISceneId(kUIPageViewTest);
|
|
|
|
sceneManager->setMaxUISceneId(kUIPageViewTest);
|
|
|
|
Scene* scene = sceneManager->currentUIScene();
|
|
|
|
Director::getInstance()->replaceScene(scene);
|
2013-12-23 15:35:35 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2014-05-14 11:26:04 +08:00
|
|
|
"ListViewTest",
|
2014-02-20 10:53:49 +08:00
|
|
|
[](Ref* sender)
|
2013-12-23 15:35:35 +08:00
|
|
|
{
|
2014-05-14 17:07:24 +08:00
|
|
|
UISceneManager* sceneManager = UISceneManager::sharedUISceneManager();
|
|
|
|
sceneManager->setCurrentUISceneId(kUIListViewTest_Vertical);
|
|
|
|
sceneManager->setMinUISceneId(kUIListViewTest_Vertical);
|
|
|
|
sceneManager->setMaxUISceneId(kUIListViewTest_Horizontal);
|
|
|
|
Scene* scene = sceneManager->currentUIScene();
|
|
|
|
Director::getInstance()->replaceScene(scene);
|
2013-12-23 15:35:35 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2014-05-14 11:26:04 +08:00
|
|
|
"WidgetAddNodeTest",
|
2014-02-20 10:53:49 +08:00
|
|
|
[](Ref* sender)
|
2013-12-23 15:35:35 +08:00
|
|
|
{
|
2014-05-14 17:07:24 +08:00
|
|
|
UISceneManager* sceneManager = UISceneManager::sharedUISceneManager();
|
|
|
|
sceneManager->setCurrentUISceneId(kUIWidgetAddNodeTest);
|
|
|
|
sceneManager->setMinUISceneId(kUIWidgetAddNodeTest);
|
|
|
|
sceneManager->setMaxUISceneId(kUIWidgetAddNodeTest);
|
|
|
|
Scene* scene = sceneManager->currentUIScene();
|
|
|
|
Director::getInstance()->replaceScene(scene);
|
2014-03-06 20:52:29 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2014-05-14 11:26:04 +08:00
|
|
|
"RichTextTest",
|
2014-03-06 20:52:29 +08:00
|
|
|
[](Ref* sender)
|
|
|
|
{
|
2014-05-14 17:07:24 +08:00
|
|
|
UISceneManager* sceneManager = UISceneManager::sharedUISceneManager();
|
|
|
|
sceneManager->setCurrentUISceneId(kUIRichTextTest);
|
|
|
|
sceneManager->setMinUISceneId(kUIRichTextTest);
|
|
|
|
sceneManager->setMaxUISceneId(kUIRichTextTest);
|
|
|
|
Scene* scene = sceneManager->currentUIScene();
|
|
|
|
Director::getInstance()->replaceScene(scene);
|
2013-12-23 15:35:35 +08:00
|
|
|
}
|
|
|
|
},
|
2014-05-14 11:26:04 +08:00
|
|
|
|
2013-12-23 15:35:35 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static const int g_maxTests = sizeof(g_guisTests) / sizeof(g_guisTests[0]);
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
static Vec2 s_tCurPos = Vec2::ZERO;
|
2013-12-23 15:35:35 +08:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// CocosGUITestMainLayer
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
void CocosGUITestMainLayer::onEnter()
|
|
|
|
{
|
|
|
|
Layer::onEnter();
|
|
|
|
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
_itemMenu = Menu::create();
|
|
|
|
_itemMenu->setPosition( s_tCurPos );
|
2014-03-26 23:33:58 +08:00
|
|
|
MenuItemFont::setFontName("fonts/arial.ttf");
|
2013-12-23 15:35:35 +08:00
|
|
|
MenuItemFont::setFontSize(24);
|
|
|
|
for (int i = 0; i < g_maxTests; ++i)
|
|
|
|
{
|
|
|
|
auto pItem = MenuItemFont::create(g_guisTests[i].name, g_guisTests[i].callback);
|
2014-05-15 01:07:09 +08:00
|
|
|
pItem->setPosition(Vec2(s.width / 2, s.height - (i + 1) * LINE_SPACE));
|
2013-12-23 15:35:35 +08:00
|
|
|
_itemMenu->addChild(pItem, kItemTagBasic + i);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto listener = EventListenerTouchAllAtOnce::create();
|
|
|
|
listener->onTouchesBegan = CC_CALLBACK_2(CocosGUITestMainLayer::onTouchesBegan, this);
|
|
|
|
listener->onTouchesMoved = CC_CALLBACK_2(CocosGUITestMainLayer::onTouchesMoved, this);
|
|
|
|
|
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
|
|
|
|
|
|
|
addChild(_itemMenu);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CocosGUITestMainLayer::onTouchesBegan(const std::vector<Touch*>& touches, Event *event)
|
|
|
|
{
|
|
|
|
auto touch = static_cast<Touch*>(touches[0]);
|
|
|
|
|
|
|
|
_beginPos = touch->getLocation();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CocosGUITestMainLayer::onTouchesMoved(const std::vector<Touch*>& touches, Event *event)
|
|
|
|
{
|
|
|
|
auto touch = static_cast<Touch*>(touches[0]);
|
|
|
|
|
|
|
|
auto touchLocation = touch->getLocation();
|
|
|
|
float nMoveY = touchLocation.y - _beginPos.y;
|
|
|
|
|
|
|
|
auto curPos = _itemMenu->getPosition();
|
2014-05-15 01:07:09 +08:00
|
|
|
auto nextPos = Vec2(curPos.x, curPos.y + nMoveY);
|
2013-12-23 15:35:35 +08:00
|
|
|
|
|
|
|
if (nextPos.y < 0.0f)
|
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
_itemMenu->setPosition(Vec2::ZERO);
|
2013-12-23 15:35:35 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nextPos.y > ((g_maxTests + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height))
|
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
_itemMenu->setPosition(Vec2(0, ((g_maxTests + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height)));
|
2013-12-23 15:35:35 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_itemMenu->setPosition(nextPos);
|
|
|
|
_beginPos = touchLocation;
|
|
|
|
s_tCurPos = nextPos;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// CocosGUITestScene
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
void CocosGUITestScene::onEnter()
|
|
|
|
{
|
|
|
|
Scene::onEnter();
|
|
|
|
|
2014-04-09 23:31:05 +08:00
|
|
|
auto label = Label::createWithTTF("Back", "fonts/arial.ttf", 20);
|
2014-03-04 16:51:35 +08:00
|
|
|
//#endif
|
|
|
|
auto pMenuItem = MenuItemLabel::create(label, CC_CALLBACK_1(CocosGUITestScene::BackCallback, this));
|
|
|
|
|
|
|
|
Menu* pMenu =Menu::create(pMenuItem, NULL);
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
pMenu->setPosition( Vec2::ZERO );
|
|
|
|
pMenuItem->setPosition( Vec2( VisibleRect::right().x - 50, VisibleRect::bottom().y + 25) );
|
2014-03-04 16:51:35 +08:00
|
|
|
|
|
|
|
addChild(pMenu, 1);
|
|
|
|
}
|
|
|
|
|
2013-12-23 15:35:35 +08:00
|
|
|
void CocosGUITestScene::runThisTest()
|
|
|
|
{
|
|
|
|
auto layer = new CocosGUITestMainLayer();
|
|
|
|
addChild(layer);
|
|
|
|
layer->release();
|
|
|
|
|
|
|
|
Director::getInstance()->replaceScene(this);
|
2014-03-04 16:51:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CocosGUITestScene::BackCallback(Ref* pSender)
|
|
|
|
{
|
|
|
|
CocoStudioGUITestScene* pScene = new CocoStudioGUITestScene();
|
|
|
|
pScene->runThisTest();
|
|
|
|
pScene->release();
|
|
|
|
}
|