2014-03-04 16:51:35 +08:00
|
|
|
|
|
|
|
|
|
|
|
#include "CocoStudioGUITest.h"
|
|
|
|
#include "../../ExtensionsTest/ExtensionsTest.h"
|
|
|
|
#include "CocosGUIScene.h"
|
|
|
|
#include "GUIEditorTest.h"
|
2014-03-05 21:18:51 +08:00
|
|
|
#include "CustomGUIScene.h"
|
2014-03-04 16:51:35 +08:00
|
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
LINE_SPACE = 40,
|
|
|
|
kItemTagBasic = 1000,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
std::function<void(Ref* sender)> callback;
|
|
|
|
}
|
|
|
|
g_guisTests[] =
|
|
|
|
{
|
|
|
|
{
|
|
|
|
"GUI Dynamic Create Test",
|
|
|
|
[](Ref* sender)
|
|
|
|
{
|
|
|
|
CocosGUITestScene *pScene = new CocosGUITestScene();
|
|
|
|
pScene->runThisTest();
|
|
|
|
pScene->release();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"GUI Editor Test",
|
|
|
|
[](Ref* sender)
|
|
|
|
{
|
|
|
|
GUIEditorTestScene* pScene = new GUIEditorTestScene();
|
|
|
|
pScene->runThisTest();
|
|
|
|
pScene->release();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Custom GUI Test",
|
|
|
|
[](Ref* sender)
|
|
|
|
{
|
|
|
|
CustomGUITestScene* pScene = new CustomGUITestScene();
|
|
|
|
pScene->runThisTest();
|
|
|
|
pScene->release();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static const int g_maxTests = sizeof(g_guisTests) / sizeof(g_guisTests[0]);
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// CocoStudioGUIMainLayer
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
|
2014-04-15 18:23:40 +08:00
|
|
|
static Vector2 _curPos = Vector2::ZERO;
|
2014-03-04 16:51:35 +08:00
|
|
|
|
|
|
|
void CocoStudioGUIMainLayer::onEnter()
|
|
|
|
{
|
|
|
|
using namespace ui;
|
|
|
|
|
|
|
|
CCLayer::onEnter();
|
|
|
|
|
|
|
|
Size s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
_itemMenu = CCMenu::create();
|
2014-04-15 18:23:40 +08:00
|
|
|
_itemMenu->setPosition(Vector2::ZERO);
|
2014-03-26 23:33:58 +08:00
|
|
|
CCMenuItemFont::setFontName("fonts/arial.ttf");
|
2014-03-04 16:51:35 +08:00
|
|
|
CCMenuItemFont::setFontSize(24);
|
|
|
|
for (int i = 0; i < g_maxTests; ++i)
|
|
|
|
{
|
|
|
|
auto pItem = MenuItemFont::create(g_guisTests[i].name, g_guisTests[i].callback);
|
2014-04-15 18:23:40 +08:00
|
|
|
pItem->setPosition(Vector2(s.width / 2, s.height / 4 * 3 - (i + 1) * LINE_SPACE));
|
2014-03-04 16:51:35 +08:00
|
|
|
_itemMenu->addChild(pItem, kItemTagBasic + i);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto listener = EventListenerTouchAllAtOnce::create();
|
|
|
|
listener->onTouchesBegan = CC_CALLBACK_2(CocoStudioGUIMainLayer::onTouchesBegan, this);
|
|
|
|
listener->onTouchesMoved = CC_CALLBACK_2(CocoStudioGUIMainLayer::onTouchesMoved, this);
|
|
|
|
|
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
|
|
|
addChild(_itemMenu);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CocoStudioGUIMainLayer::onTouchesBegan(const std::vector<Touch*>& touches, Event *event)
|
|
|
|
{
|
|
|
|
auto touch = static_cast<Touch*>(touches[0]);
|
|
|
|
|
|
|
|
_beginPos = touch->getLocation();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
void CocoStudioGUIMainLayer::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-04-15 18:23:40 +08:00
|
|
|
auto nextPos = Vector2(curPos.x, curPos.y + nMoveY);
|
2014-03-04 16:51:35 +08:00
|
|
|
|
|
|
|
if (nextPos.y < 0.0f)
|
|
|
|
{
|
2014-04-15 18:23:40 +08:00
|
|
|
_itemMenu->setPosition(Vector2::ZERO);
|
2014-03-04 16:51:35 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
float y = (g_maxTests + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height;
|
|
|
|
if (nextPos.y > y)
|
|
|
|
{
|
2014-04-15 18:23:40 +08:00
|
|
|
_itemMenu->setPosition(Vector2(0, y));
|
2014-03-04 16:51:35 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_itemMenu->setPosition(nextPos);
|
|
|
|
_beginPos = touchLocation;
|
|
|
|
_curPos = nextPos;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// CocoStudioGUITestScene
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void CocoStudioGUITestScene::onEnter()
|
|
|
|
{
|
|
|
|
CCScene::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
|
|
|
|
MenuItemLabel* pMenuItem = MenuItemLabel::create(label, CC_CALLBACK_1(CocoStudioGUITestScene::BackCallback, this));
|
|
|
|
|
|
|
|
Menu* pMenu = Menu::create(pMenuItem, NULL);
|
|
|
|
|
2014-04-15 18:23:40 +08:00
|
|
|
pMenu->setPosition( Vector2::ZERO );
|
|
|
|
pMenuItem->setPosition( Vector2( VisibleRect::right().x - 50, VisibleRect::bottom().y + 25) );
|
2014-03-04 16:51:35 +08:00
|
|
|
|
|
|
|
addChild(pMenu, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CocoStudioGUITestScene::runThisTest()
|
|
|
|
{
|
|
|
|
Layer* pLayer = new CocoStudioGUIMainLayer();
|
|
|
|
addChild(pLayer);
|
|
|
|
pLayer->release();
|
|
|
|
|
|
|
|
CCDirector::getInstance()->replaceScene(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CocoStudioGUITestScene::BackCallback(Ref* pSender)
|
|
|
|
{
|
|
|
|
ExtensionsTestScene* pScene = new ExtensionsTestScene();
|
|
|
|
pScene->runThisTest();
|
|
|
|
pScene->release();
|
|
|
|
}
|