From 80117afc824d8b2b9cbc4c49d002ff7abd9ca08e Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Thu, 6 Jun 2013 17:12:28 -0700 Subject: [PATCH] Adds Base class to tests Base class displays the Menu( <- O -> ) Improved in some tests the way to create entries. Instead of defining the tests twice: the "create" method, and the entry in the array, it is only needed in the array (ActionsTest, SpriteTest and Texture2DTest) --- .../ActionManagerTest/ActionManagerTest.cpp | 22 -- .../ActionManagerTest/ActionManagerTest.h | 4 +- .../ActionsEaseTest/ActionsEaseTest.cpp | 19 +- .../Classes/ActionsEaseTest/ActionsEaseTest.h | 3 +- .../ActionsProgressTest.cpp | 27 +-- .../ActionsProgressTest/ActionsProgressTest.h | 3 +- .../Classes/ActionsTest/ActionsTest.cpp | 175 +++++----------- .../TestCpp/Classes/ActionsTest/ActionsTest.h | 3 +- samples/Cpp/TestCpp/Classes/BaseTest.cpp | 79 ++++++++ samples/Cpp/TestCpp/Classes/BaseTest.h | 29 +++ .../ClippingNodeTest/ClippingNodeTest.cpp | 29 +-- .../ClippingNodeTest/ClippingNodeTest.h | 3 +- .../ConfigurationTest/ConfigurationTest.cpp | 33 +-- .../ConfigurationTest/ConfigurationTest.h | 3 +- .../DrawPrimitivesTest/DrawPrimitivesTest.cpp | 28 +-- .../DrawPrimitivesTest/DrawPrimitivesTest.h | 3 +- .../EffectsAdvancedTest.cpp | 31 +-- .../EffectsAdvancedTest/EffectsAdvancedTest.h | 3 +- .../Classes/EffectsTest/EffectsTest.cpp | 25 +-- .../TestCpp/Classes/EffectsTest/EffectsTest.h | 3 +- .../Classes/FileUtilsTest/FileUtilsTest.cpp | 26 +-- .../Classes/FileUtilsTest/FileUtilsTest.h | 4 +- .../Cpp/TestCpp/Classes/FontTest/FontTest.cpp | 12 +- .../Cpp/TestCpp/Classes/FontTest/FontTest.h | 3 +- .../TestCpp/Classes/LabelTest/LabelTest.cpp | 29 +-- .../Cpp/TestCpp/Classes/LabelTest/LabelTest.h | 3 +- .../TestCpp/Classes/LayerTest/LayerTest.cpp | 29 +-- .../Cpp/TestCpp/Classes/LayerTest/LayerTest.h | 3 +- .../MotionStreakTest/MotionStreakTest.cpp | 29 +-- .../MotionStreakTest/MotionStreakTest.h | 3 +- .../Cpp/TestCpp/Classes/NodeTest/NodeTest.cpp | 29 +-- .../Cpp/TestCpp/Classes/NodeTest/NodeTest.h | 3 +- .../Classes/ParallaxTest/ParallaxTest.cpp | 21 +- .../Classes/ParallaxTest/ParallaxTest.h | 3 +- .../Classes/ParticleTest/ParticleTest.cpp | 60 ++---- .../Classes/ParticleTest/ParticleTest.h | 4 +- .../SpriteTest/SpriteTest.cpp.REMOVED.git-id | 2 +- .../TestCpp/Classes/SpriteTest/SpriteTest.h | 3 +- .../Classes/Texture2dTest/Texture2dTest.cpp | 190 +++++------------- .../Classes/Texture2dTest/Texture2dTest.h | 3 +- samples/Cpp/TestCpp/Classes/testBasic.h | 4 + .../project.pbxproj.REMOVED.git-id | 2 +- .../project.pbxproj.REMOVED.git-id | 2 +- 43 files changed, 297 insertions(+), 695 deletions(-) create mode 100644 samples/Cpp/TestCpp/Classes/BaseTest.cpp create mode 100644 samples/Cpp/TestCpp/Classes/BaseTest.h diff --git a/samples/Cpp/TestCpp/Classes/ActionManagerTest/ActionManagerTest.cpp b/samples/Cpp/TestCpp/Classes/ActionManagerTest/ActionManagerTest.cpp index 04e47e496d..36bf332977 100644 --- a/samples/Cpp/TestCpp/Classes/ActionManagerTest/ActionManagerTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ActionManagerTest/ActionManagerTest.cpp @@ -82,28 +82,6 @@ std::string ActionManagerTest::title() return "No title"; } -void ActionManagerTest::onEnter() -{ - CCLayer::onEnter(); - - CCLabelTTF* label = CCLabelTTF::create(title().c_str(), "Arial", 32); - addChild(label, 1); - label->setPosition(ccp(VisibleRect::center().x, VisibleRect::top().y-50)); - - CCMenuItemImage *item1 = CCMenuItemImage::create(s_pPathB1, s_pPathB2, std::bind(&ActionManagerTest::backCallback, this, std::placeholders::_1) ); - CCMenuItemImage *item2 = CCMenuItemImage::create(s_pPathR1, s_pPathR2, std::bind(&ActionManagerTest::restartCallback, this, std::placeholders::_1) ); - CCMenuItemImage *item3 = CCMenuItemImage::create(s_pPathF1, s_pPathF2, std::bind(&ActionManagerTest::nextCallback, this, std::placeholders::_1)); - - CCMenu *menu = CCMenu::create(item1, item2, item3, NULL); - - menu->setPosition(CCPointZero); - item1->setPosition(ccp(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y + item2->getContentSize().height/2)); - item2->setPosition(ccp(VisibleRect::center().x, VisibleRect::bottom().y + item2->getContentSize().height/2)); - item3->setPosition(ccp(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y + item2->getContentSize().height/2)); - - addChild(menu, 1); -} - void ActionManagerTest::restartCallback(CCObject* pSender) { CCScene* s = new ActionManagerTestScene(); diff --git a/samples/Cpp/TestCpp/Classes/ActionManagerTest/ActionManagerTest.h b/samples/Cpp/TestCpp/Classes/ActionManagerTest/ActionManagerTest.h index 35afb921d1..02cd6beb0c 100644 --- a/samples/Cpp/TestCpp/Classes/ActionManagerTest/ActionManagerTest.h +++ b/samples/Cpp/TestCpp/Classes/ActionManagerTest/ActionManagerTest.h @@ -2,8 +2,9 @@ #define _ACTION_MANAGER_TEST_H_ #include "../testBasic.h" +#include "../BaseTest.h" -class ActionManagerTest: public CCLayer +class ActionManagerTest: public BaseTest { protected: CCTextureAtlas* m_atlas; @@ -15,7 +16,6 @@ public: ~ActionManagerTest(void); virtual std::string title(); - virtual void onEnter(); void restartCallback(CCObject* pSender); void nextCallback(CCObject* pSender); diff --git a/samples/Cpp/TestCpp/Classes/ActionsEaseTest/ActionsEaseTest.cpp b/samples/Cpp/TestCpp/Classes/ActionsEaseTest/ActionsEaseTest.cpp index 1ca3953d65..32e20083c8 100644 --- a/samples/Cpp/TestCpp/Classes/ActionsEaseTest/ActionsEaseTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ActionsEaseTest/ActionsEaseTest.cpp @@ -606,7 +606,7 @@ std::string EaseSpriteDemo::title() void EaseSpriteDemo::onEnter() { - CCLayer::onEnter(); + BaseTest::onEnter(); // Or you can create an sprite using a filename. PNG and BMP files are supported. Probably TIFF too m_grossini = CCSprite::create(s_pPathGrossini); m_grossini->retain(); @@ -620,23 +620,6 @@ void EaseSpriteDemo::onEnter() m_grossini->setPosition(ccp(VisibleRect::left().x + 60, VisibleRect::bottom().y+VisibleRect::getVisibleRect().size.height*1/5)); m_kathia->setPosition(ccp(VisibleRect::left().x + 60, VisibleRect::bottom().y+VisibleRect::getVisibleRect().size.height*2.5f/5)); m_tamara->setPosition(ccp(VisibleRect::left().x + 60, VisibleRect::bottom().y+VisibleRect::getVisibleRect().size.height*4/5)); - - CCLabelTTF* label = CCLabelTTF::create(title().c_str(), "Arial", 32); - addChild(label); - label->setPosition(ccp(VisibleRect::center().x, VisibleRect::top().y-50)); - - CCMenuItemImage *item1 = CCMenuItemImage::create(s_pPathB1, s_pPathB2, std::bind(&EaseSpriteDemo::backCallback, this, std::placeholders::_1) ); - CCMenuItemImage *item2 = CCMenuItemImage::create(s_pPathR1, s_pPathR2, std::bind(&EaseSpriteDemo::restartCallback , this, std::placeholders::_1) ); - CCMenuItemImage *item3 = CCMenuItemImage::create(s_pPathF1, s_pPathF2, std::bind(&EaseSpriteDemo::nextCallback, this, std::placeholders::_1) ); - - CCMenu *menu = CCMenu::create(item1, item2, item3, NULL); - - menu->setPosition(CCPointZero); - item1->setPosition(ccp(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y + item2->getContentSize().height/2)); - item2->setPosition(ccp(VisibleRect::center().x, VisibleRect::bottom().y + item2->getContentSize().height/2)); - item3->setPosition(ccp(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y + item2->getContentSize().height/2)); - - addChild(menu, 1); } void EaseSpriteDemo::restartCallback(CCObject* pSender) diff --git a/samples/Cpp/TestCpp/Classes/ActionsEaseTest/ActionsEaseTest.h b/samples/Cpp/TestCpp/Classes/ActionsEaseTest/ActionsEaseTest.h index 772f0e2d8e..cc70ce1b11 100644 --- a/samples/Cpp/TestCpp/Classes/ActionsEaseTest/ActionsEaseTest.h +++ b/samples/Cpp/TestCpp/Classes/ActionsEaseTest/ActionsEaseTest.h @@ -3,10 +3,11 @@ ////----#include "cocos2d.h" #include "../testBasic.h" +#include "../BaseTest.h" USING_NS_CC; -class EaseSpriteDemo : public CCLayer +class EaseSpriteDemo : public BaseTest { protected: CCSprite* m_grossini; diff --git a/samples/Cpp/TestCpp/Classes/ActionsProgressTest/ActionsProgressTest.cpp b/samples/Cpp/TestCpp/Classes/ActionsProgressTest/ActionsProgressTest.cpp index 25c90986a9..244c51c089 100644 --- a/samples/Cpp/TestCpp/Classes/ActionsProgressTest/ActionsProgressTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ActionsProgressTest/ActionsProgressTest.cpp @@ -90,32 +90,7 @@ std::string SpriteDemo::subtitle() void SpriteDemo::onEnter() { - CCLayer::onEnter(); - - CCSize s = CCDirector::sharedDirector()->getWinSize(); - - CCLabelTTF* label = CCLabelTTF::create(title().c_str(), "Arial", 18); - addChild(label, 1); - label->setPosition( ccp(s.width/2, s.height-50) ); - - std::string strSubtitle = subtitle(); - if( ! strSubtitle.empty() ) - { - CCLabelTTF* l = CCLabelTTF::create(strSubtitle.c_str(), "Thonburi", 22); - addChild(l, 1); - l->setPosition( ccp(s.width/2, s.height-80) ); - } - - CCMenuItemImage *item1 = CCMenuItemImage::create(s_pPathB1, s_pPathB2, this, menu_selector(SpriteDemo::backCallback) ); - CCMenuItemImage *item2 = CCMenuItemImage::create(s_pPathR1, s_pPathR2, this, menu_selector(SpriteDemo::restartCallback) ); - CCMenuItemImage *item3 = CCMenuItemImage::create(s_pPathF1, s_pPathF2, this, menu_selector(SpriteDemo::nextCallback) ); - - CCMenu *menu = CCMenu::create(item1, item2, item3, NULL); - menu->setPosition(CCPointZero); - item1->setPosition(ccp(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2)); - item2->setPosition(ccp(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2)); - item3->setPosition(ccp(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2)); - addChild(menu, 1); + BaseTest::onEnter(); CCLayerColor *background = CCLayerColor::create(ccc4(255,0,0,255)); addChild(background, -10); diff --git a/samples/Cpp/TestCpp/Classes/ActionsProgressTest/ActionsProgressTest.h b/samples/Cpp/TestCpp/Classes/ActionsProgressTest/ActionsProgressTest.h index 88d4b2ac51..afdb4ce3f9 100644 --- a/samples/Cpp/TestCpp/Classes/ActionsProgressTest/ActionsProgressTest.h +++ b/samples/Cpp/TestCpp/Classes/ActionsProgressTest/ActionsProgressTest.h @@ -2,8 +2,9 @@ #define _ACTIONS_PROGRESS_TEST_H_ #include "../testBasic.h" +#include "../BaseTest.h" -class SpriteDemo : public CCLayer +class SpriteDemo : public BaseTest { public: SpriteDemo(void); diff --git a/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp b/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp index db5fc6ed56..53f71938d1 100644 --- a/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.cpp @@ -2,101 +2,53 @@ #include "../testResource.h" #include "cocos2d.h" -TESTLAYER_CREATE_FUNC(ActionManual); -TESTLAYER_CREATE_FUNC(ActionMove); -TESTLAYER_CREATE_FUNC(ActionRotate); -TESTLAYER_CREATE_FUNC(ActionScale); -TESTLAYER_CREATE_FUNC(ActionSkew); -TESTLAYER_CREATE_FUNC(ActionRotationalSkew); -TESTLAYER_CREATE_FUNC(ActionRotationalSkewVSStandardSkew); -TESTLAYER_CREATE_FUNC(ActionSkewRotateScale); -TESTLAYER_CREATE_FUNC(ActionJump); -TESTLAYER_CREATE_FUNC(ActionCardinalSpline); -TESTLAYER_CREATE_FUNC(ActionCatmullRom); -TESTLAYER_CREATE_FUNC(ActionBezier); -TESTLAYER_CREATE_FUNC(ActionBlink); -TESTLAYER_CREATE_FUNC(ActionFade); -TESTLAYER_CREATE_FUNC(ActionTint); -TESTLAYER_CREATE_FUNC(ActionAnimate); -TESTLAYER_CREATE_FUNC(ActionSequence); -TESTLAYER_CREATE_FUNC(ActionSequence2); -TESTLAYER_CREATE_FUNC(ActionSpawn); -TESTLAYER_CREATE_FUNC(ActionReverse); -TESTLAYER_CREATE_FUNC(ActionDelayTime); -TESTLAYER_CREATE_FUNC(ActionRepeat); -TESTLAYER_CREATE_FUNC(ActionRepeatForever); -TESTLAYER_CREATE_FUNC(ActionRotateToRepeat); -TESTLAYER_CREATE_FUNC(ActionRotateJerk); -TESTLAYER_CREATE_FUNC(ActionCallFunction); -TESTLAYER_CREATE_FUNC(ActionCallFunc); -TESTLAYER_CREATE_FUNC(ActionCallFuncND); -TESTLAYER_CREATE_FUNC(ActionReverseSequence); -TESTLAYER_CREATE_FUNC(ActionReverseSequence2); -TESTLAYER_CREATE_FUNC(ActionRemoveSelf); -TESTLAYER_CREATE_FUNC(ActionOrbit); -TESTLAYER_CREATE_FUNC(ActionFollow); -TESTLAYER_CREATE_FUNC(ActionTargeted); -TESTLAYER_CREATE_FUNC(ActionMoveStacked); -TESTLAYER_CREATE_FUNC(ActionMoveJumpStacked); -TESTLAYER_CREATE_FUNC(ActionMoveBezierStacked); -TESTLAYER_CREATE_FUNC(ActionCardinalSplineStacked); -TESTLAYER_CREATE_FUNC(ActionCatmullRomStacked); -TESTLAYER_CREATE_FUNC(PauseResumeActions); -TESTLAYER_CREATE_FUNC(Issue1305); -TESTLAYER_CREATE_FUNC(Issue1305_2); -TESTLAYER_CREATE_FUNC(Issue1288); -TESTLAYER_CREATE_FUNC(Issue1288_2); -TESTLAYER_CREATE_FUNC(Issue1327); -TESTLAYER_CREATE_FUNC(Issue1398); - - -static NEWTESTFUNC createFunctions[] = { - CF(ActionManual), - CF(ActionMove), - CF(ActionRotate), - CF(ActionScale), - CF(ActionSkew), - CF(ActionRotationalSkew), - CF(ActionRotationalSkewVSStandardSkew), - CF(ActionSkewRotateScale), - CF(ActionJump), - CF(ActionCardinalSpline), - CF(ActionCatmullRom), - CF(ActionBezier), - CF(ActionBlink), - CF(ActionFade), - CF(ActionTint), - CF(ActionAnimate), - CF(ActionSequence), - CF(ActionSequence2), - CF(ActionRemoveSelf), - CF(ActionSpawn), - CF(ActionReverse), - CF(ActionDelayTime), - CF(ActionRepeat), - CF(ActionRepeatForever), - CF(ActionRotateToRepeat), - CF(ActionRotateJerk), - CF(ActionCallFunction), - CF(ActionCallFunc), - CF(ActionCallFuncND), - CF(ActionReverseSequence), - CF(ActionReverseSequence2), - CF(ActionOrbit), - CF(ActionFollow), - CF(ActionTargeted), - CF(ActionMoveStacked), - CF(ActionMoveJumpStacked), - CF(ActionMoveBezierStacked), - CF(ActionCardinalSplineStacked), - CF(ActionCatmullRomStacked), - CF(PauseResumeActions), - CF(Issue1305), - CF(Issue1305_2), - CF(Issue1288), - CF(Issue1288_2), - CF(Issue1327), - CF(Issue1398) +static std::function createFunctions[] = { + CL(ActionManual), + CL(ActionMove), + CL(ActionRotate), + CL(ActionScale), + CL(ActionSkew), + CL(ActionRotationalSkew), + CL(ActionRotationalSkewVSStandardSkew), + CL(ActionSkewRotateScale), + CL(ActionJump), + CL(ActionCardinalSpline), + CL(ActionCatmullRom), + CL(ActionBezier), + CL(ActionBlink), + CL(ActionFade), + CL(ActionTint), + CL(ActionAnimate), + CL(ActionSequence), + CL(ActionSequence2), + CL(ActionRemoveSelf), + CL(ActionSpawn), + CL(ActionReverse), + CL(ActionDelayTime), + CL(ActionRepeat), + CL(ActionRepeatForever), + CL(ActionRotateToRepeat), + CL(ActionRotateJerk), + CL(ActionCallFunction), + CL(ActionCallFunc), + CL(ActionCallFuncND), + CL(ActionReverseSequence), + CL(ActionReverseSequence2), + CL(ActionOrbit), + CL(ActionFollow), + CL(ActionTargeted), + CL(ActionMoveStacked), + CL(ActionMoveJumpStacked), + CL(ActionMoveBezierStacked), + CL(ActionCardinalSplineStacked), + CL(ActionCatmullRomStacked), + CL(PauseResumeActions), + CL(Issue1305), + CL(Issue1305_2), + CL(Issue1288), + CL(Issue1288_2), + CL(Issue1327), + CL(Issue1398) }; static int sceneIdx=-1; @@ -158,7 +110,7 @@ std::string ActionsDemo::subtitle() void ActionsDemo::onEnter() { - CCLayer::onEnter(); + BaseTest::onEnter(); // Or you can create an sprite using a filename. only PNG is supported now. Probably TIFF too m_grossini = CCSprite::create(s_pPathGrossini); @@ -177,35 +129,6 @@ void ActionsDemo::onEnter() m_grossini->setPosition(ccp(VisibleRect::center().x, VisibleRect::bottom().y+VisibleRect::getVisibleRect().size.height/3)); m_tamara->setPosition(ccp(VisibleRect::center().x, VisibleRect::bottom().y+VisibleRect::getVisibleRect().size.height*2/3)); m_kathia->setPosition(ccp(VisibleRect::center().x, VisibleRect::bottom().y+VisibleRect::getVisibleRect().size.height/2)); - - // add title and subtitle - std::string str = title(); - const char * pTitle = str.c_str(); - CCLabelTTF* label = CCLabelTTF::create(pTitle, "Arial", 32); - addChild(label, 1); - label->setPosition( ccp(VisibleRect::center().x, VisibleRect::top().y - 30) ); - - std::string strSubtitle = subtitle(); - if( ! strSubtitle.empty() ) - { - CCLabelTTF* l = CCLabelTTF::create(strSubtitle.c_str(), "Thonburi", 16); - addChild(l, 1); - l->setPosition( ccp(VisibleRect::center().x, VisibleRect::top().y - 60) ); - } - - // add menu - CCMenuItemImage *item1 = CCMenuItemImage::create(s_pPathB1, s_pPathB2, std::bind( &ActionsDemo::backCallback, this, std::placeholders::_1) ); - CCMenuItemImage *item2 = CCMenuItemImage::create(s_pPathR1, s_pPathR2, std::bind( &ActionsDemo::restartCallback, this, std::placeholders::_1) ); - CCMenuItemImage *item3 = CCMenuItemImage::create(s_pPathF1, s_pPathF2, std::bind( &ActionsDemo::nextCallback, this, std::placeholders::_1) ); - - CCMenu *menu = CCMenu::create(item1, item2, item3, NULL); - - menu->setPosition(CCPointZero); - item1->setPosition(ccp(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2)); - item2->setPosition(ccp(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2)); - item3->setPosition(ccp(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2)); - - addChild(menu, 1); } void ActionsDemo::onExit() @@ -214,7 +137,7 @@ void ActionsDemo::onExit() m_tamara->release(); m_kathia->release(); - CCLayer::onExit(); + BaseTest::onExit(); } void ActionsDemo::restartCallback(CCObject* pSender) diff --git a/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.h b/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.h index 751fb5f5f7..7939e5ecfc 100644 --- a/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.h +++ b/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.h @@ -2,6 +2,7 @@ #define _ActionsTest_H_ #include "../testBasic.h" +#include "../BaseTest.h" ////----#include "cocos2d.h" USING_NS_CC; @@ -63,7 +64,7 @@ public: virtual void runThisTest(); }; -class ActionsDemo : public CCLayer +class ActionsDemo : public BaseTest { protected: CCSprite* m_grossini; diff --git a/samples/Cpp/TestCpp/Classes/BaseTest.cpp b/samples/Cpp/TestCpp/Classes/BaseTest.cpp new file mode 100644 index 0000000000..49ff14c193 --- /dev/null +++ b/samples/Cpp/TestCpp/Classes/BaseTest.cpp @@ -0,0 +1,79 @@ +// +// BaseTest.cpp +// TestCpp +// +// Created by Ricardo Quesada on 6/6/13. +// +// + +#include "BaseTest.h" +#include "VisibleRect.h" +#include "testResource.h" + + +USING_NS_CC; + +void BaseTest::onEnter() +{ + CCLayer::onEnter(); + + // add title and subtitle + std::string str = title(); + const char * pTitle = str.c_str(); + CCLabelTTF* label = CCLabelTTF::create(pTitle, "Arial", 32); + addChild(label, 1); + label->setPosition( ccp(VisibleRect::center().x, VisibleRect::top().y - 30) ); + + std::string strSubtitle = subtitle(); + if( ! strSubtitle.empty() ) + { + CCLabelTTF* l = CCLabelTTF::create(strSubtitle.c_str(), "Thonburi", 16); + addChild(l, 1); + l->setPosition( ccp(VisibleRect::center().x, VisibleRect::top().y - 60) ); + } + + // add menu + CCMenuItemImage *item1 = CCMenuItemImage::create(s_pPathB1, s_pPathB2, std::bind( &BaseTest::backCallback, this, std::placeholders::_1) ); + CCMenuItemImage *item2 = CCMenuItemImage::create(s_pPathR1, s_pPathR2, std::bind( &BaseTest::restartCallback, this, std::placeholders::_1) ); + CCMenuItemImage *item3 = CCMenuItemImage::create(s_pPathF1, s_pPathF2, std::bind( &BaseTest::nextCallback, this, std::placeholders::_1) ); + + CCMenu *menu = CCMenu::create(item1, item2, item3, NULL); + + menu->setPosition(CCPointZero); + item1->setPosition(ccp(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2)); + item2->setPosition(ccp(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2)); + item3->setPosition(ccp(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2)); + + addChild(menu, 1); + +} + +void BaseTest::onExit() +{ + CCLayer::onExit(); +} + +std::string BaseTest::title() +{ + return ""; +} + +std::string BaseTest::subtitle() +{ + return ""; +} + +void BaseTest::restartCallback(CCObject* pSender) +{ + CCLog("override restart!"); +} + +void BaseTest::nextCallback(CCObject* pSender) +{ + CCLog("override next!"); +} + +void BaseTest::backCallback(CCObject* pSender) +{ + CCLog("override back!"); +} diff --git a/samples/Cpp/TestCpp/Classes/BaseTest.h b/samples/Cpp/TestCpp/Classes/BaseTest.h new file mode 100644 index 0000000000..d37d472561 --- /dev/null +++ b/samples/Cpp/TestCpp/Classes/BaseTest.h @@ -0,0 +1,29 @@ +// +// BaseTest.h +// TestCpp +// +// Created by Ricardo Quesada on 6/6/13. +// +// + +#ifndef __TestCpp__BaseTest__ +#define __TestCpp__BaseTest__ + +#include "cocos2d.h" + +class BaseTest : public cocos2d::CCLayer +{ +public: + virtual void onEnter(); + virtual void onExit(); + + virtual std::string title(); + virtual std::string subtitle(); + + virtual void restartCallback(CCObject* pSender); + virtual void nextCallback(CCObject* pSender); + virtual void backCallback(CCObject* pSender); +}; + + +#endif /* defined(__TestCpp__BaseTest__) */ diff --git a/samples/Cpp/TestCpp/Classes/ClippingNodeTest/ClippingNodeTest.cpp b/samples/Cpp/TestCpp/Classes/ClippingNodeTest/ClippingNodeTest.cpp index eedc31f983..5fe4ed1244 100644 --- a/samples/Cpp/TestCpp/Classes/ClippingNodeTest/ClippingNodeTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ClippingNodeTest/ClippingNodeTest.cpp @@ -92,40 +92,13 @@ static CCLayer* restartAction() bool BaseClippingNodeTest::init() { - if (CCLayer::init()) { - - CCSize s = CCDirector::sharedDirector()->getWinSize(); + if (BaseTest::init()) { CCSprite *background = CCSprite::create(s_back3); background->setAnchorPoint( CCPointZero ); background->setPosition( CCPointZero ); this->addChild(background, -1); - CCLabelTTF *label = CCLabelTTF::create(this->title().c_str(), "Arial", 32); - this->addChild(label, 1, kTagTitleLabel); - label->setPosition( ccp(s.width / 2, s.height - 50)); - - std::string subtitleText = this->subtitle(); - if (subtitleText.length() > 0) { - CCLabelTTF *subtitle = CCLabelTTF::create(subtitleText.c_str(), "Thonburi", 16); - this->addChild(subtitle, 1, kTagSubtitleLabel); - subtitle->setPosition(ccp(s.width / 2, s.height - 80)); - } - - CCMenuItemImage *item1 = CCMenuItemImage::create(s_pPathB1, s_pPathB2, - this, menu_selector(BaseClippingNodeTest::backCallback)); - CCMenuItemImage *item2 = CCMenuItemImage::create(s_pPathR1, s_pPathR2, - this, menu_selector(BaseClippingNodeTest::restartCallback)); - CCMenuItemImage *item3 = CCMenuItemImage::create(s_pPathF1, s_pPathF2, - this, menu_selector(BaseClippingNodeTest::nextCallback)); - - CCMenu *menu = CCMenu::create(item1, item2, item3, NULL); - menu->setPosition( CCPointZero ); - item1->setPosition( ccp(s.width / 2 - item2->getContentSize().width * 2, item2->getContentSize().height / 2)); - item2->setPosition( ccp(s.width / 2, item2->getContentSize().height / 2)); - item3->setPosition( ccp(s.width / 2 + item2->getContentSize().width * 2, item2->getContentSize().height / 2)); - this->addChild(menu, 1); - this->setup(); return true; } diff --git a/samples/Cpp/TestCpp/Classes/ClippingNodeTest/ClippingNodeTest.h b/samples/Cpp/TestCpp/Classes/ClippingNodeTest/ClippingNodeTest.h index 22ba28c360..1c5af27d92 100644 --- a/samples/Cpp/TestCpp/Classes/ClippingNodeTest/ClippingNodeTest.h +++ b/samples/Cpp/TestCpp/Classes/ClippingNodeTest/ClippingNodeTest.h @@ -2,8 +2,9 @@ #define __CLIPPINGNODETEST_H__ #include "../testBasic.h" +#include "../BaseTest.h" -class BaseClippingNodeTest : public CCLayer +class BaseClippingNodeTest : public BaseTest { public: ~BaseClippingNodeTest(); diff --git a/samples/Cpp/TestCpp/Classes/ConfigurationTest/ConfigurationTest.cpp b/samples/Cpp/TestCpp/Classes/ConfigurationTest/ConfigurationTest.cpp index d0cdcbfb8d..b362f35d1c 100644 --- a/samples/Cpp/TestCpp/Classes/ConfigurationTest/ConfigurationTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ConfigurationTest/ConfigurationTest.cpp @@ -76,41 +76,12 @@ std::string ConfigurationBase::subtitle() void ConfigurationBase::onEnter() { - CCLayer::onEnter(); - - // add title and subtitle - std::string str = title(); - const char * pTitle = str.c_str(); - CCLabelTTF* label = CCLabelTTF::create(pTitle, "Arial", 32); - addChild(label, 1); - label->setPosition( ccp(VisibleRect::center().x, VisibleRect::top().y - 30) ); - - std::string strSubtitle = subtitle(); - if( ! strSubtitle.empty() ) - { - CCLabelTTF* l = CCLabelTTF::create(strSubtitle.c_str(), "Thonburi", 16); - addChild(l, 1); - l->setPosition( ccp(VisibleRect::center().x, VisibleRect::top().y - 60) ); - } - - // add menu - CCMenuItemImage *item1 = CCMenuItemImage::create(s_pPathB1, s_pPathB2, this, menu_selector(ConfigurationBase::backCallback) ); - CCMenuItemImage *item2 = CCMenuItemImage::create(s_pPathR1, s_pPathR2, this, menu_selector(ConfigurationBase::restartCallback) ); - CCMenuItemImage *item3 = CCMenuItemImage::create(s_pPathF1, s_pPathF2, this, menu_selector(ConfigurationBase::nextCallback) ); - - CCMenu *menu = CCMenu::create(item1, item2, item3, NULL); - - menu->setPosition(CCPointZero); - item1->setPosition(ccp(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2)); - item2->setPosition(ccp(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2)); - item3->setPosition(ccp(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2)); - - addChild(menu, 1); + BaseTest::onEnter(); } void ConfigurationBase::onExit() { - CCLayer::onExit(); + BaseTest::onExit(); } void ConfigurationBase::restartCallback(CCObject* pSender) diff --git a/samples/Cpp/TestCpp/Classes/ConfigurationTest/ConfigurationTest.h b/samples/Cpp/TestCpp/Classes/ConfigurationTest/ConfigurationTest.h index c28bcaefd8..274d7e807c 100644 --- a/samples/Cpp/TestCpp/Classes/ConfigurationTest/ConfigurationTest.h +++ b/samples/Cpp/TestCpp/Classes/ConfigurationTest/ConfigurationTest.h @@ -2,6 +2,7 @@ #define __CONFIGURATIONTEST_H__ #include "../testBasic.h" +#include "../BaseTest.h" USING_NS_CC; @@ -15,7 +16,7 @@ public: virtual void runThisTest(); }; -class ConfigurationBase : public CCLayer +class ConfigurationBase : public BaseTest { protected: diff --git a/samples/Cpp/TestCpp/Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp b/samples/Cpp/TestCpp/Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp index f656737a8a..dbc0458177 100644 --- a/samples/Cpp/TestCpp/Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp +++ b/samples/Cpp/TestCpp/Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp @@ -66,33 +66,7 @@ BaseLayer::BaseLayer() void BaseLayer::onEnter() { - CCLayer::onEnter(); - - CCSize s = CCDirector::sharedDirector()->getWinSize(); - - CCLabelTTF *label = CCLabelTTF::create(title().c_str(), "Arial", 32); - addChild(label); - label->setPosition(ccp(s.width/2, s.height-50)); - - string subTitle = subtitle(); - if (subTitle.size() > 0) - { - CCLabelTTF *l = CCLabelTTF::create(subTitle.c_str(), "Thonburi", 16); - addChild(l, 1); - l->setPosition(ccp(s.width/2, s.height-80)); - } - - CCMenuItemImage *item1 = CCMenuItemImage::create("Images/b1.png", "Images/b2.png", this, menu_selector(BaseLayer::backCallback)); - CCMenuItemImage *item2 = CCMenuItemImage::create("Images/r1.png", "Images/r2.png", this, menu_selector(BaseLayer::restartCallback)); - CCMenuItemImage *item3 = CCMenuItemImage::create("Images/f1.png", "Images/f2.png", this, menu_selector(BaseLayer::nextCallback)); - - CCMenu *menu = CCMenu::create(item1, item2, item3, NULL); - menu->setPosition(CCPointZero); - - item1->setPosition(ccp(s.width/2 - item2->getContentSize().width*2, item2->getContentSize().height/2)); - item2->setPosition(ccp(s.width/2, item2->getContentSize().height/2)); - item3->setPosition(ccp(s.width/2 + item2->getContentSize().width*2, item2->getContentSize().height/2)); - addChild(menu, 100); + BaseTest::onEnter(); } void BaseLayer::restartCallback(cocos2d::CCObject *pSender) diff --git a/samples/Cpp/TestCpp/Classes/DrawPrimitivesTest/DrawPrimitivesTest.h b/samples/Cpp/TestCpp/Classes/DrawPrimitivesTest/DrawPrimitivesTest.h index d4c2b9bcf4..ea48f0770b 100644 --- a/samples/Cpp/TestCpp/Classes/DrawPrimitivesTest/DrawPrimitivesTest.h +++ b/samples/Cpp/TestCpp/Classes/DrawPrimitivesTest/DrawPrimitivesTest.h @@ -3,10 +3,11 @@ #include "cocos2d.h" #include "../testBasic.h" +#include "../BaseTest.h" #include -class BaseLayer : public CCLayer +class BaseLayer : public BaseTest { public: BaseLayer(); diff --git a/samples/Cpp/TestCpp/Classes/EffectsAdvancedTest/EffectsAdvancedTest.cpp b/samples/Cpp/TestCpp/Classes/EffectsAdvancedTest/EffectsAdvancedTest.cpp index ac9cd90b3d..e3c3f319d9 100644 --- a/samples/Cpp/TestCpp/Classes/EffectsAdvancedTest/EffectsAdvancedTest.cpp +++ b/samples/Cpp/TestCpp/Classes/EffectsAdvancedTest/EffectsAdvancedTest.cpp @@ -333,7 +333,7 @@ CCLayer* restartEffectAdvanceAction() void EffectAdvanceTextLayer::onEnter(void) { - CCLayer::onEnter(); + BaseTest::onEnter(); CCSprite *bg = CCSprite::create("Images/background3.png"); addChild(bg, 0, kTagBackground); @@ -351,34 +351,7 @@ void EffectAdvanceTextLayer::onEnter(void) tamara->setPosition( ccp(VisibleRect::left().x+2*VisibleRect::getVisibleRect().size.width/3.0f,VisibleRect::bottom().y+200) ); CCActionInterval* sc2 = CCScaleBy::create(2, 5); CCActionInterval* sc2_back = sc2->reverse(); - tamara->runAction( CCRepeatForever::create(CCSequence::create(sc2, sc2_back, NULL) ) ); - - CCLabelTTF* label = CCLabelTTF::create(title().c_str(), "Marker Felt", 28); - - label->setPosition( ccp(VisibleRect::center().x,VisibleRect::top().y-80) ); - addChild(label); - label->setTag( kTagLabel ); - - std::string strSubtitle = subtitle(); - if( ! strSubtitle.empty() ) - { - CCLabelTTF* l = CCLabelTTF::create(strSubtitle.c_str(), "Thonburi", 16); - addChild(l, 101); - l->setPosition( ccp(VisibleRect::center().x,VisibleRect::top().y-80) ); - } - - CCMenuItemImage *item1 = CCMenuItemImage::create("Images/b1.png", "Images/b2.png", this, menu_selector(EffectAdvanceTextLayer::backCallback) ); - CCMenuItemImage *item2 = CCMenuItemImage::create("Images/r1.png","Images/r2.png", this, menu_selector(EffectAdvanceTextLayer::restartCallback) ); - CCMenuItemImage *item3 = CCMenuItemImage::create("Images/f1.png", "Images/f2.png", this, menu_selector(EffectAdvanceTextLayer::nextCallback) ); - - CCMenu *menu = CCMenu::create(item1, item2, item3, NULL); - - menu->setPosition(CCPointZero); - item1->setPosition(ccp(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2)); - item2->setPosition(ccp(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2)); - item3->setPosition(ccp(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2)); - - addChild(menu, 1); + tamara->runAction( CCRepeatForever::create(CCSequence::create(sc2, sc2_back, NULL) ) ); } EffectAdvanceTextLayer::~EffectAdvanceTextLayer(void) diff --git a/samples/Cpp/TestCpp/Classes/EffectsAdvancedTest/EffectsAdvancedTest.h b/samples/Cpp/TestCpp/Classes/EffectsAdvancedTest/EffectsAdvancedTest.h index 9a6e8f1dba..d211c4b486 100644 --- a/samples/Cpp/TestCpp/Classes/EffectsAdvancedTest/EffectsAdvancedTest.h +++ b/samples/Cpp/TestCpp/Classes/EffectsAdvancedTest/EffectsAdvancedTest.h @@ -3,8 +3,9 @@ #include "cocos2d.h" #include "../testBasic.h" +#include "../BaseTest.h" -class EffectAdvanceTextLayer: public CCLayer +class EffectAdvanceTextLayer: public BaseTest { protected: CCTextureAtlas* m_atlas; diff --git a/samples/Cpp/TestCpp/Classes/EffectsTest/EffectsTest.cpp b/samples/Cpp/TestCpp/Classes/EffectsTest/EffectsTest.cpp index 96177dd317..b26a78a90e 100644 --- a/samples/Cpp/TestCpp/Classes/EffectsTest/EffectsTest.cpp +++ b/samples/Cpp/TestCpp/Classes/EffectsTest/EffectsTest.cpp @@ -337,8 +337,10 @@ void EffectTestScene::runThisTest() #define SID_RESTART 1 TextLayer::TextLayer(void) +: BaseTest::BaseTest() { - initWithColor( ccc4(32,128,32,255) ); + CCLayerColor *background = CCLayerColor::create( ccc4(32,128,32,255) ); + this->addChild(background,-20); CCNode* node = CCNode::create(); CCActionInterval* effect = getAction(); @@ -364,25 +366,6 @@ TextLayer::TextLayer(void) CCActionInterval* sc2_back = sc2->reverse(); tamara->runAction( CCRepeatForever::create(CCSequence::create(sc2, sc2_back, NULL)) ); - CCLabelTTF* label = CCLabelTTF::create((effectsList[actionIdx]).c_str(), "Marker Felt", 32); - - label->setPosition( ccp(VisibleRect::center().x,VisibleRect::top().y-80) ); - addChild(label); - label->setTag( kTagLabel ); - - CCMenuItemImage *item1 = CCMenuItemImage::create(s_pPathB1, s_pPathB2, this, menu_selector(TextLayer::backCallback) ); - CCMenuItemImage *item2 = CCMenuItemImage::create(s_pPathR1, s_pPathR2, this, menu_selector(TextLayer::restartCallback) ); - CCMenuItemImage *item3 = CCMenuItemImage::create(s_pPathF1, s_pPathF2, this, menu_selector(TextLayer::nextCallback) ); - - CCMenu *menu = CCMenu::create(item1, item2, item3, NULL); - - menu->setPosition(CCPointZero); - item1->setPosition(ccp(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2)); - item2->setPosition(ccp(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2)); - item3->setPosition(ccp(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2)); - - addChild(menu, 1); - schedule( schedule_selector(TextLayer::checkAnim) ); } @@ -413,7 +396,7 @@ TextLayer* TextLayer::create() void TextLayer::onEnter() { - CCLayer::onEnter(); + BaseTest::onEnter(); } void TextLayer::newScene() diff --git a/samples/Cpp/TestCpp/Classes/EffectsTest/EffectsTest.h b/samples/Cpp/TestCpp/Classes/EffectsTest/EffectsTest.h index 4e2bbc77f6..c8114b74f3 100644 --- a/samples/Cpp/TestCpp/Classes/EffectsTest/EffectsTest.h +++ b/samples/Cpp/TestCpp/Classes/EffectsTest/EffectsTest.h @@ -2,6 +2,7 @@ #define _EFFECTS_TEST_H_ #include "../testBasic.h" +#include "../BaseTest.h" class EffectTestScene : public TestScene { @@ -9,7 +10,7 @@ public: virtual void runThisTest(); }; -class TextLayer : public CCLayerColor +class TextLayer : public BaseTest { protected: //UxString m_strTitle; diff --git a/samples/Cpp/TestCpp/Classes/FileUtilsTest/FileUtilsTest.cpp b/samples/Cpp/TestCpp/Classes/FileUtilsTest/FileUtilsTest.cpp index 78407e4fd0..cd44855e93 100644 --- a/samples/Cpp/TestCpp/Classes/FileUtilsTest/FileUtilsTest.cpp +++ b/samples/Cpp/TestCpp/Classes/FileUtilsTest/FileUtilsTest.cpp @@ -65,31 +65,7 @@ void FileUtilsTestScene::runThisTest() void FileUtilsDemo::onEnter() { - CCLayer::onEnter(); - - CCLabelTTF* label = CCLabelTTF::create(title().c_str(), "Arial", 32); - addChild(label); - label->setPosition(ccp(VisibleRect::center().x, VisibleRect::top().y-50)); - - std::string subTitle = subtitle(); - if(! subTitle.empty()) - { - CCLabelTTF* l = CCLabelTTF::create(subTitle.c_str(), "Thonburi", 16); - addChild(l, 1); - l->setPosition(ccp(VisibleRect::center().x, VisibleRect::top().y-80)); - } - - CCMenuItemImage *item1 = CCMenuItemImage::create("Images/b1.png", "Images/b2.png", this, menu_selector(FileUtilsDemo::backCallback)); - CCMenuItemImage *item2 = CCMenuItemImage::create("Images/r1.png","Images/r2.png", this, menu_selector(FileUtilsDemo::restartCallback) ); - CCMenuItemImage *item3 = CCMenuItemImage::create("Images/f1.png", "Images/f2.png", this, menu_selector(FileUtilsDemo::nextCallback) ); - - CCMenu *menu = CCMenu::create(item1, item2, item3, NULL); - menu->setPosition(CCPointZero); - item1->setPosition(ccp(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2)); - item2->setPosition(ccp(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2)); - item3->setPosition(ccp(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2)); - - addChild(menu, 1); + BaseTest::onEnter(); } void FileUtilsDemo::backCallback(CCObject* pSender) diff --git a/samples/Cpp/TestCpp/Classes/FileUtilsTest/FileUtilsTest.h b/samples/Cpp/TestCpp/Classes/FileUtilsTest/FileUtilsTest.h index fbc29fd0b4..d97efa387c 100644 --- a/samples/Cpp/TestCpp/Classes/FileUtilsTest/FileUtilsTest.h +++ b/samples/Cpp/TestCpp/Classes/FileUtilsTest/FileUtilsTest.h @@ -2,6 +2,8 @@ #define __FILEUTILSTEST_H__ #include "../testBasic.h" +#include "../BaseTest.h" + USING_NS_CC; using namespace std; @@ -11,7 +13,7 @@ public: virtual void runThisTest(); }; -class FileUtilsDemo : public CCLayer +class FileUtilsDemo : public BaseTest { public: virtual void onEnter(); diff --git a/samples/Cpp/TestCpp/Classes/FontTest/FontTest.cpp b/samples/Cpp/TestCpp/Classes/FontTest/FontTest.cpp index 283b0ebce2..78c4266a89 100644 --- a/samples/Cpp/TestCpp/Classes/FontTest/FontTest.cpp +++ b/samples/Cpp/TestCpp/Classes/FontTest/FontTest.cpp @@ -77,18 +77,8 @@ static const char* restartAction(void) FontTest::FontTest() +: BaseTest() { - CCMenuItemImage *item1 = CCMenuItemImage::create(s_pPathB1, s_pPathB2, this, menu_selector(FontTest::backCallback)); - CCMenuItemImage *item2 = CCMenuItemImage::create(s_pPathR1, s_pPathR2, this, menu_selector(FontTest::restartCallback)); - CCMenuItemImage *item3 = CCMenuItemImage::create(s_pPathF1, s_pPathF2, this, menu_selector(FontTest::nextCallback)); - - CCMenu *menu = CCMenu::create(item1, item2, item3, NULL); - menu->setPosition(CCPointZero); - item1->setPosition(ccp(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2)); - item2->setPosition(ccp(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2)); - item3->setPosition(ccp(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2)); - addChild(menu, 1); - showFont(restartAction()); } diff --git a/samples/Cpp/TestCpp/Classes/FontTest/FontTest.h b/samples/Cpp/TestCpp/Classes/FontTest/FontTest.h index 58b3abcc59..ea8ee3ab18 100644 --- a/samples/Cpp/TestCpp/Classes/FontTest/FontTest.h +++ b/samples/Cpp/TestCpp/Classes/FontTest/FontTest.h @@ -3,6 +3,7 @@ #include "cocos2d.h" #include "../testBasic.h" +#include "../BaseTest.h" class FontTestScene : public TestScene { @@ -10,7 +11,7 @@ public: virtual void runThisTest(); }; -class FontTest : public cocos2d::CCLayer +class FontTest : public BaseTest { public: FontTest(); diff --git a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp index adec010026..d2f04a3e0b 100644 --- a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp +++ b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.cpp @@ -134,34 +134,7 @@ std::string AtlasDemo::subtitle() void AtlasDemo::onEnter() { - CCLayer::onEnter(); - - CCSize s = CCDirector::sharedDirector()->getWinSize(); - - CCLabelTTF* label = CCLabelTTF::create(title().c_str(), "Arial", 28); - addChild(label, 1); - label->setPosition( ccp(s.width/2, s.height-50) ); - - std::string strSubtitle = subtitle(); - if( ! strSubtitle.empty() ) - { - CCLabelTTF* l = CCLabelTTF::create(strSubtitle.c_str(), "Thonburi", 16); - addChild(l, 1); - l->setPosition( ccp(s.width/2, s.height-80) ); - } - - CCMenuItemImage *item1 = CCMenuItemImage::create(s_pPathB1, s_pPathB2, this, menu_selector(AtlasDemo::backCallback) ); - CCMenuItemImage *item2 = CCMenuItemImage::create(s_pPathR1, s_pPathR2, this, menu_selector(AtlasDemo::restartCallback) ); - CCMenuItemImage *item3 = CCMenuItemImage::create(s_pPathF1, s_pPathF2, this, menu_selector(AtlasDemo::nextCallback) ); - - CCMenu *menu = CCMenu::create(item1, item2, item3, NULL); - - menu->setPosition( CCPointZero ); - item1->setPosition(ccp(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2)); - item2->setPosition(ccp(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2)); - item3->setPosition(ccp(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2));; - - addChild(menu, 1); + BaseTest::onEnter(); } void AtlasDemo::restartCallback(CCObject* pSender) diff --git a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.h b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.h index 3ca8278605..ab2229c326 100644 --- a/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.h +++ b/samples/Cpp/TestCpp/Classes/LabelTest/LabelTest.h @@ -2,8 +2,9 @@ #define _ATLAS_TEST_H_ #include "../testBasic.h" +#include "../BaseTest.h" -class AtlasDemo : public CCLayer +class AtlasDemo : public BaseTest { protected: diff --git a/samples/Cpp/TestCpp/Classes/LayerTest/LayerTest.cpp b/samples/Cpp/TestCpp/Classes/LayerTest/LayerTest.cpp index f08a9a94c2..fee44e279f 100644 --- a/samples/Cpp/TestCpp/Classes/LayerTest/LayerTest.cpp +++ b/samples/Cpp/TestCpp/Classes/LayerTest/LayerTest.cpp @@ -99,34 +99,7 @@ std::string LayerTest::title() void LayerTest::onEnter() { - CCLayer::onEnter(); - - CCSize s = CCDirector::sharedDirector()->getWinSize(); - - CCLabelTTF* label = CCLabelTTF::create(title().c_str(), "Arial", 32); - addChild(label, 1); - label->setPosition( ccp(s.width/2, s.height-50) ); - - string subtitle_ = subtitle(); - if (subtitle_.size() > 0) - { - CCLabelTTF *l = CCLabelTTF::create(subtitle_.c_str(), "Thonburi", 16); - addChild(l, 1); - l->setPosition(ccp(s.width / 2, s.height - 80)); - } - - CCMenuItemImage *item1 = CCMenuItemImage::create(s_pPathB1, s_pPathB2, this, menu_selector(LayerTest::backCallback) ); - CCMenuItemImage *item2 = CCMenuItemImage::create(s_pPathR1, s_pPathR2, this, menu_selector(LayerTest::restartCallback) ); - CCMenuItemImage *item3 = CCMenuItemImage::create(s_pPathF1, s_pPathF2, this, menu_selector(LayerTest::nextCallback) ); - - CCMenu *menu = CCMenu::create(item1, item2, item3, NULL); - - menu->setPosition( CCPointZero ); - item1->setPosition(ccp(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2)); - item2->setPosition(ccp(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2)); - item3->setPosition(ccp(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2)); - - addChild(menu, 1); + BaseTest::onEnter(); } void LayerTest::restartCallback(CCObject* pSender) diff --git a/samples/Cpp/TestCpp/Classes/LayerTest/LayerTest.h b/samples/Cpp/TestCpp/Classes/LayerTest/LayerTest.h index 4e6625da38..ec16807b62 100644 --- a/samples/Cpp/TestCpp/Classes/LayerTest/LayerTest.h +++ b/samples/Cpp/TestCpp/Classes/LayerTest/LayerTest.h @@ -3,8 +3,9 @@ ////----#include "cocos2d.h" #include "../testBasic.h" +#include "../BaseTest.h" -class LayerTest : public CCLayer +class LayerTest : public BaseTest { protected: std::string m_strTitle; diff --git a/samples/Cpp/TestCpp/Classes/MotionStreakTest/MotionStreakTest.cpp b/samples/Cpp/TestCpp/Classes/MotionStreakTest/MotionStreakTest.cpp index f6202b9dcc..f70bc87f2b 100644 --- a/samples/Cpp/TestCpp/Classes/MotionStreakTest/MotionStreakTest.cpp +++ b/samples/Cpp/TestCpp/Classes/MotionStreakTest/MotionStreakTest.cpp @@ -228,36 +228,11 @@ std::string MotionStreakTest::subtitle() void MotionStreakTest::onEnter() { - CCLayer::onEnter(); + BaseTest::onEnter(); CCSize s = CCDirector::sharedDirector()->getWinSize(); - CCLabelTTF* label = CCLabelTTF::create(title().c_str(), "Arial", 32); - addChild(label, 0, kTagLabel); - label->setPosition(ccp(s.width/2, s.height-50)); - - string subTitle = this->subtitle(); - if (subTitle.size() > 0) - { - CCLabelTTF *l = CCLabelTTF::create(subTitle.c_str(), "Thonburi", 16); - addChild(l, 1); - l->setPosition(ccp(s.width/2, s.height-80)); - } - - CCMenuItemImage *item1 = CCMenuItemImage::create(s_pPathB1, s_pPathB2, this, menu_selector(MotionStreakTest::backCallback) ); - CCMenuItemImage *item2 = CCMenuItemImage::create(s_pPathR1, s_pPathR2, this, menu_selector(MotionStreakTest::restartCallback) ); - CCMenuItemImage *item3 = CCMenuItemImage::create(s_pPathF1, s_pPathF2, this, menu_selector(MotionStreakTest::nextCallback) ); - - CCMenu *menu = CCMenu::create(item1, item2, item3, NULL); - - menu->setPosition(CCPointZero); - item1->setPosition(ccp(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2)); - item2->setPosition(ccp(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2)); - item3->setPosition(ccp(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2)); - - addChild(menu, 1); - - CCMenuItemToggle *itemMode = CCMenuItemToggle::createWithTarget(this, menu_selector(MotionStreakTest::modeCallback), + CCMenuItemToggle *itemMode = CCMenuItemToggle::createWithCallback( std::bind(&MotionStreakTest::modeCallback, this, std::placeholders::_1), CCMenuItemFont::create("Use High Quality Mode"), CCMenuItemFont::create("Use Fast Mode"), NULL); diff --git a/samples/Cpp/TestCpp/Classes/MotionStreakTest/MotionStreakTest.h b/samples/Cpp/TestCpp/Classes/MotionStreakTest/MotionStreakTest.h index ee764338a5..3374edd365 100644 --- a/samples/Cpp/TestCpp/Classes/MotionStreakTest/MotionStreakTest.h +++ b/samples/Cpp/TestCpp/Classes/MotionStreakTest/MotionStreakTest.h @@ -3,10 +3,11 @@ ////----#include "cocos2d.h" #include "../testBasic.h" +#include "../BaseTest.h" //USING_NS_CC; -class MotionStreakTest : public CCLayer +class MotionStreakTest : public BaseTest { public: MotionStreakTest(void); diff --git a/samples/Cpp/TestCpp/Classes/NodeTest/NodeTest.cpp b/samples/Cpp/TestCpp/Classes/NodeTest/NodeTest.cpp index 70ea5a77d2..4214290b95 100644 --- a/samples/Cpp/TestCpp/Classes/NodeTest/NodeTest.cpp +++ b/samples/Cpp/TestCpp/Classes/NodeTest/NodeTest.cpp @@ -100,34 +100,7 @@ std::string TestCocosNodeDemo::subtitle() void TestCocosNodeDemo::onEnter() { - CCLayer::onEnter(); - - CCSize s = CCDirector::sharedDirector()->getWinSize(); - - CCLabelTTF* label = CCLabelTTF::create(title().c_str(), "Arial", 32); - addChild(label, 10); - label->setPosition( ccp(s.width/2, s.height-50) ); - - std::string strSubtitle = subtitle(); - if( ! strSubtitle.empty() ) - { - CCLabelTTF* l = CCLabelTTF::create(strSubtitle.c_str(), "Thonburi", 16); - addChild(l, 1); - l->setPosition( ccp(s.width/2, s.height-80) ); - } - - CCMenuItemImage *item1 = CCMenuItemImage::create(s_pPathB1, s_pPathB2, this, menu_selector(TestCocosNodeDemo::backCallback) ); - CCMenuItemImage *item2 = CCMenuItemImage::create(s_pPathR1,s_pPathR2, this, menu_selector(TestCocosNodeDemo::restartCallback) ); - CCMenuItemImage *item3 = CCMenuItemImage::create(s_pPathF1, s_pPathF2, this, menu_selector(TestCocosNodeDemo::nextCallback) ); - - CCMenu *menu = CCMenu::create(item1, item2, item3, NULL); - - menu->setPosition( CCPointZero ); - item1->setPosition(ccp(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2)); - item2->setPosition(ccp(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2)); - item3->setPosition(ccp(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2)); - - addChild(menu, 11); + BaseTest::onEnter(); } void TestCocosNodeDemo::restartCallback(CCObject* pSender) diff --git a/samples/Cpp/TestCpp/Classes/NodeTest/NodeTest.h b/samples/Cpp/TestCpp/Classes/NodeTest/NodeTest.h index 277625325a..73ded1b88f 100644 --- a/samples/Cpp/TestCpp/Classes/NodeTest/NodeTest.h +++ b/samples/Cpp/TestCpp/Classes/NodeTest/NodeTest.h @@ -3,8 +3,9 @@ ////----#include "cocos2d.h" #include "../testBasic.h" +#include "../BaseTest.h" -class TestCocosNodeDemo : public CCLayer +class TestCocosNodeDemo : public BaseTest { public: TestCocosNodeDemo(void); diff --git a/samples/Cpp/TestCpp/Classes/ParallaxTest/ParallaxTest.cpp b/samples/Cpp/TestCpp/Classes/ParallaxTest/ParallaxTest.cpp index 8ead4b67df..af0ffaf030 100644 --- a/samples/Cpp/TestCpp/Classes/ParallaxTest/ParallaxTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ParallaxTest/ParallaxTest.cpp @@ -216,26 +216,7 @@ std::string ParallaxDemo::title() void ParallaxDemo::onEnter() { - CCLayer::onEnter(); - - CCSize s = CCDirector::sharedDirector()->getWinSize(); - - CCLabelTTF* label = CCLabelTTF::create(title().c_str(), "Arial", 28); - addChild(label, 1); - label->setPosition( ccp(s.width/2, s.height-50) ); - - CCMenuItemImage *item1 = CCMenuItemImage::create(s_pPathB1, s_pPathB2, this, menu_selector(ParallaxDemo::backCallback) ); - CCMenuItemImage *item2 = CCMenuItemImage::create(s_pPathR1, s_pPathR2, this, menu_selector(ParallaxDemo::restartCallback) ); - CCMenuItemImage *item3 = CCMenuItemImage::create(s_pPathF1, s_pPathF2, this, menu_selector(ParallaxDemo::nextCallback) ); - - CCMenu *menu = CCMenu::create(item1, item2, item3, NULL); - - menu->setPosition( CCPointZero ); - item1->setPosition(ccp(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2)); - item2->setPosition(ccp(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2)); - item3->setPosition(ccp(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2)); - - addChild(menu, 1); + BaseTest::onEnter(); } void ParallaxDemo::restartCallback(CCObject* pSender) diff --git a/samples/Cpp/TestCpp/Classes/ParallaxTest/ParallaxTest.h b/samples/Cpp/TestCpp/Classes/ParallaxTest/ParallaxTest.h index bab29515d9..99a2e75c45 100644 --- a/samples/Cpp/TestCpp/Classes/ParallaxTest/ParallaxTest.h +++ b/samples/Cpp/TestCpp/Classes/ParallaxTest/ParallaxTest.h @@ -2,8 +2,9 @@ #define _PARALLAX_TEST_H_ #include "../testBasic.h" +#include "../BaseTest.h" -class ParallaxDemo : public CCLayer +class ParallaxDemo : public BaseTest { protected: CCTextureAtlas* m_atlas; diff --git a/samples/Cpp/TestCpp/Classes/ParticleTest/ParticleTest.cpp b/samples/Cpp/TestCpp/Classes/ParticleTest/ParticleTest.cpp index 95a8ca4c6f..2374bf5e58 100644 --- a/samples/Cpp/TestCpp/Classes/ParticleTest/ParticleTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ParticleTest/ParticleTest.cpp @@ -640,7 +640,7 @@ void RadiusMode1::onEnter() { ParticleDemo::onEnter(); - setColor(ccBLACK); + m_color->setColor(ccBLACK); removeChild(m_background, true); m_background = NULL; @@ -724,7 +724,7 @@ void RadiusMode2::onEnter() { ParticleDemo::onEnter(); - setColor(ccBLACK); + m_color->setColor(ccBLACK); removeChild(m_background, true); m_background = NULL; @@ -808,7 +808,7 @@ void Issue704::onEnter() { ParticleDemo::onEnter(); - setColor(ccBLACK); + m_color->setColor(ccBLACK); removeChild(m_background, true); m_background = NULL; @@ -900,7 +900,7 @@ void Issue870::onEnter() { ParticleDemo::onEnter(); - setColor(ccBLACK); + m_color->setColor(ccBLACK); removeChild(m_background, true); m_background = NULL; @@ -941,7 +941,7 @@ void DemoParticleFromFile::onEnter() { ParticleDemo::onEnter(); - setColor(ccBLACK); + m_color->setColor(ccBLACK); removeChild(m_background, true); m_background = NULL; @@ -1067,41 +1067,26 @@ ParticleDemo::~ParticleDemo(void) void ParticleDemo::onEnter(void) { - CCLayer::onEnter(); - - initWithColor( ccc4(127,127,127,255) ); + BaseTest::onEnter(); + + m_color = CCLayerColor::create( ccc4(127,127,127,255) ); + this->addChild(m_color); m_emitter = NULL; setTouchEnabled( true ); CCSize s = CCDirector::sharedDirector()->getWinSize(); - CCLabelTTF* label = CCLabelTTF::create(title().c_str(), "Arial", 28); - addChild(label, 100, 1000); - label->setPosition( ccp(s.width/2, s.height-50) ); - CCLabelTTF *sub = CCLabelTTF::create(subtitle().c_str(), "Arial", 16); - addChild(sub, 100); - sub->setPosition(ccp(s.width/2, s.height-80)); - - - CCMenuItemImage* item1 = CCMenuItemImage::create(s_pPathB1, s_pPathB2, this, menu_selector(ParticleDemo::backCallback) ); - CCMenuItemImage* item2 = CCMenuItemImage::create(s_pPathR1, s_pPathR2, this, menu_selector(ParticleDemo::restartCallback) ); - CCMenuItemImage* item3 = CCMenuItemImage::create(s_pPathF1, s_pPathF2, this, menu_selector(ParticleDemo::nextCallback) ); - - CCMenuItemToggle* item4 = CCMenuItemToggle::createWithTarget(this, - menu_selector(ParticleDemo::toggleCallback), + CCMenuItemToggle* item4 = CCMenuItemToggle::createWithCallback( std::bind( &ParticleDemo::toggleCallback, this, std::placeholders::_1), CCMenuItemFont::create( "Free Movement" ), CCMenuItemFont::create( "Relative Movement" ), CCMenuItemFont::create( "Grouped Movement" ), NULL ); - CCMenu *menu = CCMenu::create(item1, item2, item3, item4, NULL); + CCMenu *menu = CCMenu::create(item4, NULL); menu->setPosition( CCPointZero ); - item1->setPosition(ccp(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2)); - item2->setPosition(ccp(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2)); - item3->setPosition(ccp(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2)); item4->setPosition( ccp( VisibleRect::left().x, VisibleRect::bottom().y+ 100) ); item4->setAnchorPoint( ccp(0,0) ); @@ -1123,9 +1108,6 @@ void ParticleDemo::onEnter(void) scheduleUpdate(); - - CCLabelTTF* pLabel = (CCLabelTTF*)(this->getChildByTag(1000)); - pLabel->setString(title().c_str()); } std::string ParticleDemo::title() @@ -1229,7 +1211,7 @@ void ParticleBatchHybrid::onEnter() { ParticleDemo::onEnter(); - setColor(ccBLACK); + m_color->setColor(ccBLACK); removeChild(m_background, true); m_background = NULL; @@ -1277,7 +1259,7 @@ void ParticleBatchMultipleEmitters::onEnter() { ParticleDemo::onEnter(); - setColor(ccBLACK); + m_color->setColor(ccBLACK); removeChild(m_background, true); m_background = NULL; @@ -1320,7 +1302,7 @@ void ParticleReorder::onEnter() ParticleDemo::onEnter(); m_nOrder = 0; - setColor(ccBLACK); + m_color->setColor(ccBLACK); removeChild(m_background, true); m_background = NULL; @@ -1490,7 +1472,7 @@ void Issue1201::onEnter() { ParticleDemo::onEnter(); - setColor(ccBLACK); + m_color->setColor(ccBLACK); removeChild(m_background, true); m_background = NULL; @@ -1520,7 +1502,7 @@ void MultipleParticleSystems::onEnter() { ParticleDemo::onEnter(); - setColor(ccBLACK); + m_color->setColor(ccBLACK); removeChild(m_background, true); m_background = NULL; @@ -1575,7 +1557,7 @@ void MultipleParticleSystemsBatched::onEnter() { ParticleDemo::onEnter(); - setColor(ccBLACK); + m_color->setColor(ccBLACK); removeChild(m_background, true); m_background = NULL; @@ -1637,7 +1619,7 @@ void AddAndDeleteParticleSystems::onEnter() { ParticleDemo::onEnter(); - setColor(ccBLACK); + m_color->setColor(ccBLACK); removeChild(m_background, true); m_background = NULL; @@ -1726,7 +1708,7 @@ void ReorderParticleSystems::onEnter() { ParticleDemo::onEnter(); - setColor(ccBLACK); + m_color->setColor(ccBLACK); removeChild(m_background ,true); m_background = NULL; @@ -1872,7 +1854,7 @@ void PremultipliedAlphaTest::onEnter() { ParticleDemo::onEnter(); - this->setColor(ccBLUE); + m_color->setColor(ccBLUE); this->removeChild(m_background, true); m_background = NULL; @@ -1904,7 +1886,7 @@ void PremultipliedAlphaTest2::onEnter() { ParticleDemo::onEnter(); - this->setColor(ccBLACK); + m_color->setColor(ccBLACK); this->removeChild(m_background, true); m_background = NULL; diff --git a/samples/Cpp/TestCpp/Classes/ParticleTest/ParticleTest.h b/samples/Cpp/TestCpp/Classes/ParticleTest/ParticleTest.h index 4ff6cb9947..a4e308ec53 100644 --- a/samples/Cpp/TestCpp/Classes/ParticleTest/ParticleTest.h +++ b/samples/Cpp/TestCpp/Classes/ParticleTest/ParticleTest.h @@ -2,6 +2,7 @@ #define _PARTICLE_TEST_H_ #include "../testBasic.h" +#include "../BaseTest.h" ////----#include "cocos2d.h" // #include "touch_dispatcher/CCTouch.h" // #include "CCParticleExample.h" @@ -12,11 +13,12 @@ public: virtual void runThisTest(); }; -class ParticleDemo : public CCLayerColor +class ParticleDemo : public BaseTest { protected: CCParticleSystem* m_emitter; CCSprite* m_background; + CCLayerColor* m_color; public: ~ParticleDemo(void); diff --git a/samples/Cpp/TestCpp/Classes/SpriteTest/SpriteTest.cpp.REMOVED.git-id b/samples/Cpp/TestCpp/Classes/SpriteTest/SpriteTest.cpp.REMOVED.git-id index 5025b72240..9d37ae6ccf 100644 --- a/samples/Cpp/TestCpp/Classes/SpriteTest/SpriteTest.cpp.REMOVED.git-id +++ b/samples/Cpp/TestCpp/Classes/SpriteTest/SpriteTest.cpp.REMOVED.git-id @@ -1 +1 @@ -eff4f2aa0226630c0b7749f48604f100212b964e \ No newline at end of file +548013044691d4d3c7d3b2dec546b0aaa90cee8c \ No newline at end of file diff --git a/samples/Cpp/TestCpp/Classes/SpriteTest/SpriteTest.h b/samples/Cpp/TestCpp/Classes/SpriteTest/SpriteTest.h index 6112cbaa64..47b3649987 100644 --- a/samples/Cpp/TestCpp/Classes/SpriteTest/SpriteTest.h +++ b/samples/Cpp/TestCpp/Classes/SpriteTest/SpriteTest.h @@ -3,9 +3,10 @@ #include "cocos2d.h" #include "../testBasic.h" +#include "../BaseTest.h" #include -class SpriteTestDemo : public CCLayer +class SpriteTestDemo : public BaseTest { protected: std::string m_strTitle; diff --git a/samples/Cpp/TestCpp/Classes/Texture2dTest/Texture2dTest.cpp b/samples/Cpp/TestCpp/Classes/Texture2dTest/Texture2dTest.cpp index bba47cb0eb..382fee3ceb 100644 --- a/samples/Cpp/TestCpp/Classes/Texture2dTest/Texture2dTest.cpp +++ b/samples/Cpp/TestCpp/Classes/Texture2dTest/Texture2dTest.cpp @@ -8,120 +8,60 @@ enum { kTagSprite2 = 3, }; -typedef CCLayer* (*NEWTEXTURE2DTESTFUNC)(); -#define TEXTURE2D_CREATE_FUNC(className) \ -static CCLayer* create##className() \ -{ return new className(); } - -TEXTURE2D_CREATE_FUNC(TextureMemoryAlloc); - -TEXTURE2D_CREATE_FUNC(TextureAlias); -TEXTURE2D_CREATE_FUNC(TexturePVRMipMap); -TEXTURE2D_CREATE_FUNC(TexturePVRMipMap2); -TEXTURE2D_CREATE_FUNC(TexturePVRNonSquare); -TEXTURE2D_CREATE_FUNC(TexturePVRNPOT4444); -TEXTURE2D_CREATE_FUNC(TexturePVRNPOT8888); -TEXTURE2D_CREATE_FUNC(TexturePVR); - -TEXTURE2D_CREATE_FUNC(TexturePVR2BPP); -TEXTURE2D_CREATE_FUNC(TexturePVR2BPPv3); -TEXTURE2D_CREATE_FUNC(TexturePVR4BPP); -TEXTURE2D_CREATE_FUNC(TexturePVR4BPPv3); -TEXTURE2D_CREATE_FUNC(TexturePVRII4BPPv3); -TEXTURE2D_CREATE_FUNC(TexturePVRRGBA8888); -TEXTURE2D_CREATE_FUNC(TexturePVRRGBA8888v3); -TEXTURE2D_CREATE_FUNC(TexturePVRBGRA8888); -TEXTURE2D_CREATE_FUNC(TexturePVRBGRA8888v3); -TEXTURE2D_CREATE_FUNC(TexturePVRRGBA4444); -TEXTURE2D_CREATE_FUNC(TexturePVRRGBA4444v3); -TEXTURE2D_CREATE_FUNC(TexturePVRRGBA4444GZ); -TEXTURE2D_CREATE_FUNC(TexturePVRRGBA4444CCZ); -TEXTURE2D_CREATE_FUNC(TexturePVRRGBA5551); -TEXTURE2D_CREATE_FUNC(TexturePVRRGBA5551v3); -TEXTURE2D_CREATE_FUNC(TexturePVRRGB565); -TEXTURE2D_CREATE_FUNC(TexturePVRRGB565v3); -TEXTURE2D_CREATE_FUNC(TexturePVRRGB888); -TEXTURE2D_CREATE_FUNC(TexturePVRRGB888v3); -TEXTURE2D_CREATE_FUNC(TexturePVRA8); -TEXTURE2D_CREATE_FUNC(TexturePVRA8v3); -TEXTURE2D_CREATE_FUNC(TexturePVRI8); -TEXTURE2D_CREATE_FUNC(TexturePVRI8v3); -TEXTURE2D_CREATE_FUNC(TexturePVRAI88); -TEXTURE2D_CREATE_FUNC(TexturePVRAI88v3); - -TEXTURE2D_CREATE_FUNC(TexturePVRv3Premult); - -TEXTURE2D_CREATE_FUNC(TexturePVRBadEncoding); -TESTLAYER_CREATE_FUNC(TexturePNG); -TESTLAYER_CREATE_FUNC(TextureJPEG); -TESTLAYER_CREATE_FUNC(TextureTIFF); -TESTLAYER_CREATE_FUNC(TextureWEBP); -TESTLAYER_CREATE_FUNC(TexturePixelFormat); -TESTLAYER_CREATE_FUNC(TextureBlend); -TESTLAYER_CREATE_FUNC(TextureAsync); -TESTLAYER_CREATE_FUNC(TextureGlClamp); -TESTLAYER_CREATE_FUNC(TextureGlRepeat); -TESTLAYER_CREATE_FUNC(TextureSizeTest); -TESTLAYER_CREATE_FUNC(TextureCache1); -TESTLAYER_CREATE_FUNC(TextureDrawAtPoint); -TESTLAYER_CREATE_FUNC(TextureDrawInRect); - -TESTLAYER_CREATE_FUNC(TextureETC1); - -static NEWTEXTURE2DTESTFUNC createFunctions[] = +static std::function createFunctions[] = { - createTextureMemoryAlloc, - createTextureAlias, - createTexturePVRMipMap, - createTexturePVRMipMap2, - createTexturePVRNonSquare, - createTexturePVRNPOT4444, - createTexturePVRNPOT8888, - createTexturePVR, - createTexturePVR2BPP, - createTexturePVR2BPPv3, - createTexturePVR4BPP, - createTexturePVR4BPPv3, - createTexturePVRII4BPPv3, - createTexturePVRRGBA8888, - createTexturePVRRGBA8888v3, - createTexturePVRBGRA8888, - createTexturePVRBGRA8888v3, - createTexturePVRRGBA4444, - createTexturePVRRGBA4444v3, - createTexturePVRRGBA4444GZ, - createTexturePVRRGBA4444CCZ, - createTexturePVRRGBA5551, - createTexturePVRRGBA5551v3, - createTexturePVRRGB565, - createTexturePVRRGB565v3, - createTexturePVRRGB888, - createTexturePVRRGB888v3, - createTexturePVRA8, - createTexturePVRA8v3, - createTexturePVRI8, - createTexturePVRI8v3, - createTexturePVRAI88, - createTexturePVRAI88v3, + CL(TextureMemoryAlloc), + CL(TextureAlias), + CL(TexturePVRMipMap), + CL(TexturePVRMipMap2), + CL(TexturePVRNonSquare), + CL(TexturePVRNPOT4444), + CL(TexturePVRNPOT8888), + CL(TexturePVR), + CL(TexturePVR2BPP), + CL(TexturePVR2BPPv3), + CL(TexturePVR4BPP), + CL(TexturePVR4BPPv3), + CL(TexturePVRII4BPPv3), + CL(TexturePVRRGBA8888), + CL(TexturePVRRGBA8888v3), + CL(TexturePVRBGRA8888), + CL(TexturePVRBGRA8888v3), + CL(TexturePVRRGBA4444), + CL(TexturePVRRGBA4444v3), + CL(TexturePVRRGBA4444GZ), + CL(TexturePVRRGBA4444CCZ), + CL(TexturePVRRGBA5551), + CL(TexturePVRRGBA5551v3), + CL(TexturePVRRGB565), + CL(TexturePVRRGB565v3), + CL(TexturePVRRGB888), + CL(TexturePVRRGB888v3), + CL(TexturePVRA8), + CL(TexturePVRA8v3), + CL(TexturePVRI8), + CL(TexturePVRI8v3), + CL(TexturePVRAI88), + CL(TexturePVRAI88v3), - createTexturePVRv3Premult, + CL(TexturePVRv3Premult), - createTexturePVRBadEncoding, - createTexturePNG, - createTextureJPEG, - createTextureTIFF, - createTextureWEBP, - createTexturePixelFormat, - createTextureBlend, - createTextureAsync, - createTextureGlClamp, - createTextureGlRepeat, - createTextureSizeTest, - createTextureCache1, - createTextureDrawAtPoint, - createTextureDrawInRect, + CL(TexturePVRBadEncoding), + CL(TexturePNG), + CL(TextureJPEG), + CL(TextureTIFF), + CL(TextureWEBP), + CL(TexturePixelFormat), + CL(TextureBlend), + CL(TextureAsync), + CL(TextureGlClamp), + CL(TextureGlRepeat), + CL(TextureSizeTest), + CL(TextureCache1), + CL(TextureDrawAtPoint), + CL(TextureDrawInRect), - createTextureETC1, + CL(TextureETC1), }; static unsigned int TEST_CASE_COUNT = sizeof(createFunctions) / sizeof(createFunctions[0]); @@ -172,33 +112,10 @@ CCLayer* restartTextureTest() //------------------------------------------------------------------ void TextureDemo::onEnter() { - CCLayer::onEnter(); + BaseTest::onEnter(); CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo(); - CCSize s = CCDirector::sharedDirector()->getWinSize(); - CCLabelTTF *label = CCLabelTTF::create(title().c_str(), "Arial", 26); - addChild(label, 1, kTagLabel); - label->setPosition(ccp(s.width/2, s.height-50)); - std::string strSubtitle = subtitle(); - if(strSubtitle.length()) - { - CCLabelTTF *l = CCLabelTTF::create(strSubtitle.c_str(), "Thonburi", 16); - addChild(l, 1); - l->setPosition(ccp(s.width/2, s.height-80)); - } - - CCMenuItemImage *item1 = CCMenuItemImage::create(s_pPathB1, s_pPathB2, this, menu_selector(TextureDemo::backCallback) ); - CCMenuItemImage *item2 = CCMenuItemImage::create(s_pPathR1, s_pPathR2, this, menu_selector(TextureDemo::restartCallback) ); - CCMenuItemImage *item3 = CCMenuItemImage::create(s_pPathF1, s_pPathF2, this, menu_selector(TextureDemo::nextCallback) ); - - CCMenu *menu = CCMenu::create(item1, item2, item3, NULL); - menu->setPosition(CCPointZero); - item1->setPosition(ccp(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2)); - item2->setPosition(ccp(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2)); - item3->setPosition(ccp(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2)); - addChild(menu, 1); - CCLayerColor *col = CCLayerColor::create(ccc4(128,128,128,255)); addChild(col, -10); @@ -1393,10 +1310,7 @@ void TexturePixelFormat::onEnter() // 3- 16-bit RGB5A1 // 4- 16-bit RGB565 TextureDemo::onEnter(); - - CCLabelTTF *label = (CCLabelTTF*) getChildByTag(kTagLabel); - label->setColor(ccc3(16,16,255)); - + CCSize s = CCDirector::sharedDirector()->getWinSize(); CCLayerColor *background = CCLayerColor::create(ccc4(128,128,128,255), s.width, s.height); diff --git a/samples/Cpp/TestCpp/Classes/Texture2dTest/Texture2dTest.h b/samples/Cpp/TestCpp/Classes/Texture2dTest/Texture2dTest.h index d237ea58a3..bb939d9261 100644 --- a/samples/Cpp/TestCpp/Classes/Texture2dTest/Texture2dTest.h +++ b/samples/Cpp/TestCpp/Classes/Texture2dTest/Texture2dTest.h @@ -2,9 +2,10 @@ #define __TEXTURE2D_TEST_H__ #include "../testBasic.h" +#include "../BaseTest.h" -class TextureDemo : public CCLayer +class TextureDemo : public BaseTest { public: virtual ~TextureDemo(); diff --git a/samples/Cpp/TestCpp/Classes/testBasic.h b/samples/Cpp/TestCpp/Classes/testBasic.h index f7eaf1cbae..693920bc84 100644 --- a/samples/Cpp/TestCpp/Classes/testBasic.h +++ b/samples/Cpp/TestCpp/Classes/testBasic.h @@ -26,4 +26,8 @@ static CCLayer* create##className() \ #define CF(className) create##className +// C++ 11 + +#define CL(__className__) [](){ return new __className__();} + #endif diff --git a/samples/Cpp/TestCpp/proj.ios/TestCpp.xcodeproj/project.pbxproj.REMOVED.git-id b/samples/Cpp/TestCpp/proj.ios/TestCpp.xcodeproj/project.pbxproj.REMOVED.git-id index b673535ede..d03cc21038 100644 --- a/samples/Cpp/TestCpp/proj.ios/TestCpp.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/samples/Cpp/TestCpp/proj.ios/TestCpp.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -8922f463911cface3b01435714d824c97adf5948 \ No newline at end of file +509eda87a0dd525207e23c811e04786bf5b2e3c6 \ No newline at end of file diff --git a/samples/Cpp/TestCpp/proj.mac/TestCpp.xcodeproj/project.pbxproj.REMOVED.git-id b/samples/Cpp/TestCpp/proj.mac/TestCpp.xcodeproj/project.pbxproj.REMOVED.git-id index 49c7243bad..408cac7bd2 100644 --- a/samples/Cpp/TestCpp/proj.mac/TestCpp.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/samples/Cpp/TestCpp/proj.mac/TestCpp.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -bd72399cc616a35a20111d4a5bedc5c473e93e37 \ No newline at end of file +04925ef9a72a8d03563f5578810893e794504e6e \ No newline at end of file