From 5727d7099b3675c533eeab0b7341c6196fd624e5 Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 11 Jul 2013 13:59:57 +0800 Subject: [PATCH 1/6] issue #2395: Scale9Sprite's default anchor point is center now. --- extensions/GUI/CCControlExtension/CCScale9Sprite.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/extensions/GUI/CCControlExtension/CCScale9Sprite.cpp b/extensions/GUI/CCControlExtension/CCScale9Sprite.cpp index eaca83b345..47ee0da52c 100644 --- a/extensions/GUI/CCControlExtension/CCScale9Sprite.cpp +++ b/extensions/GUI/CCControlExtension/CCScale9Sprite.cpp @@ -96,8 +96,9 @@ bool Scale9Sprite::initWithBatchNode(SpriteBatchNode* batchnode, Rect rect, bool if(batchnode) { this->updateWithBatchNode(batchnode, rect, rotated, capInsets); - this->setAnchorPoint(ccp(0.5f, 0.5f)); } + + this->setAnchorPoint(ccp(0.5f, 0.5f)); this->_positionsAreDirty = true; return true; From 2e9d727466d63fdd5d0fff4c2e2031e03d584f7f Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 11 Jul 2013 14:00:26 +0800 Subject: [PATCH 2/6] issue #2395: Removing unused codes in ActionTest.h. --- .../TestCpp/Classes/ActionsTest/ActionsTest.h | 47 ------------------- 1 file changed, 47 deletions(-) diff --git a/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.h b/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.h index 3f94eb1c3d..1e70ea8fed 100644 --- a/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.h +++ b/samples/Cpp/TestCpp/Classes/ActionsTest/ActionsTest.h @@ -8,53 +8,6 @@ USING_NS_CC; -enum -{ - ACTION_MANUAL_LAYER = 0, - ACTION_MOVE_LAYER, - ACTION_SCALE_LAYER, - ACTION_ROTATE_LAYER, - ACTION_SKEW_LAYER, - ACTION_ROTATIONAL_SKEW_LAYER, - ACTION_ROTATIONAL_SKEW_VS_STANDARD_SKEW_LAYER, - ACTION_SKEWROTATE_LAYER, - ACTION_JUMP_LAYER, - ACTION_CARDINALSPLINE_LAYER, - ACTION_CATMULLROM_LAYER, - ACTION_BEZIER_LAYER, - ACTION_BLINK_LAYER, - ACTION_FADE_LAYER, - ACTION_TINT_LAYER, - ACTION_ANIMATE_LAYER, - ACTION_SEQUENCE_LAYER, - ACTION_SEQUENCE2_LAYER, - ACTION_SPAWN_LAYER, - ACTION_REVERSE, - ACTION_DELAYTIME_LAYER, - ACTION_REPEAT_LAYER, - ACTION_REPEATEFOREVER_LAYER, - ACTION_ROTATETOREPEATE_LAYER, - ACTION_ROTATEJERK_LAYER, - ACTION_CALLFUNC_LAYER, - ACTION_CALLFUNCND_LAYER, - ACTION_CALLFUNCTION_LAYER, - ACTION_REVERSESEQUENCE_LAYER, - ACTION_REVERSESEQUENCE2_LAYER, - ACTION_ORBIT_LAYER, - ACTION_FLLOW_LAYER, - ACTION_TARGETED_LAYER, - PAUSERESUMEACTIONS_LAYER, - ACTION_ISSUE1305_LAYER, - ACTION_ISSUE1305_2_LAYER, - ACTION_ISSUE1288_LAYER, - ACTION_ISSUE1288_2_LAYER, - ACTION_ISSUE1327_LAYER, - ACTION_ISSUE1398_LAYER, - ACTION_LAYER_COUNT, - ACTION_REMOVE_SELF, -}; - - // the class inherit from TestScene // every Scene each test used must inherit from TestScene, // make sure the test have the menu item for back to main menu From ad95ba4894faf073d2317f24b1e323de683dd1b1 Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 11 Jul 2013 14:07:14 +0800 Subject: [PATCH 3/6] closed #2395: Adding Scale9SpriteTest for TestCpp --- .../Classes/ExtensionsTest/ExtensionsTest.cpp | 11 + .../Scale9SpriteTest/Scale9SpriteTest.cpp | 603 ++++++++++++++++++ .../Scale9SpriteTest/Scale9SpriteTest.h | 180 ++++++ samples/Cpp/TestCpp/Classes/testResource.h | 5 + .../project.pbxproj.REMOVED.git-id | 2 +- 5 files changed, 800 insertions(+), 1 deletion(-) create mode 100644 samples/Cpp/TestCpp/Classes/ExtensionsTest/Scale9SpriteTest/Scale9SpriteTest.cpp create mode 100644 samples/Cpp/TestCpp/Classes/ExtensionsTest/Scale9SpriteTest/Scale9SpriteTest.h diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/ExtensionsTest.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/ExtensionsTest.cpp index c13a6a59b3..2b6b849a56 100644 --- a/samples/Cpp/TestCpp/Classes/ExtensionsTest/ExtensionsTest.cpp +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/ExtensionsTest.cpp @@ -18,6 +18,8 @@ #include "EditBoxTest/EditBoxTest.h" #endif +#include "Scale9SpriteTest/Scale9SpriteTest.h" + enum { LINE_SPACE = 40, @@ -30,6 +32,15 @@ static struct { } g_extensionsTests[] = { { "NotificationCenterTest", [](Object* sender) { runNotificationCenterTest(); } }, + { "Scale9SpriteTest", [](Object* sender) { + S9SpriteTestScene* pScene = new S9SpriteTestScene(); + if (pScene) + { + pScene->runThisTest(); + pScene->release(); + } + } + }, { "CCControlButtonTest", [](Object *sender){ ControlSceneManager* pManager = ControlSceneManager::sharedControlSceneManager(); Scene* pScene = pManager->currentControlScene(); diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/Scale9SpriteTest/Scale9SpriteTest.cpp b/samples/Cpp/TestCpp/Classes/ExtensionsTest/Scale9SpriteTest/Scale9SpriteTest.cpp new file mode 100644 index 0000000000..728edc00dd --- /dev/null +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/Scale9SpriteTest/Scale9SpriteTest.cpp @@ -0,0 +1,603 @@ +/**************************************************************************** + Copyright (c) 2010-2012 cocos2d-x.org + Copyright (c) 2008-2010 Ricardo Quesada + Copyright (c) 2011 Zynga Inc. + Copyright (c) 2013 Surith Thekkiam + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#include "Scale9SpriteTest.h" +#include "testResource.h" +#include "cocos2d.h" +#include "cocos-ext.h" + +USING_NS_CC_EXT; + +static std::function createFunctions[] = { + CL(S9BatchNodeBasic), + CL(S9FrameNameSpriteSheet), + CL(S9FrameNameSpriteSheetRotated), + CL(S9BatchNodeScaledNoInsets), + CL(S9FrameNameSpriteSheetScaledNoInsets), + CL(S9FrameNameSpriteSheetRotatedScaledNoInsets), + CL(S9BatchNodeScaleWithCapInsets), + CL(S9FrameNameSpriteSheetInsets), + CL(S9FrameNameSpriteSheetInsetsScaled), + CL(S9FrameNameSpriteSheetRotatedInsets), + CL(S9_TexturePacker), + CL(S9FrameNameSpriteSheetRotatedInsetsScaled) +}; + +static int sceneIdx=-1; +#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0])) + +static Layer* nextAction() +{ + sceneIdx++; + sceneIdx = sceneIdx % MAX_LAYER; + + Layer* pLayer = (createFunctions[sceneIdx])(); + pLayer->init(); + pLayer->autorelease(); + + return pLayer; +} + +static Layer* backAction() +{ + sceneIdx--; + int total = MAX_LAYER; + if( sceneIdx < 0 ) + sceneIdx += total; + + Layer* pLayer = (createFunctions[sceneIdx])(); + pLayer->init(); + pLayer->autorelease(); + + return pLayer; +} + +static Layer* restartAction() +{ + Layer* pLayer = (createFunctions[sceneIdx])(); + pLayer->init(); + pLayer->autorelease(); + + return pLayer; +} + +void S9SpriteTestScene::runThisTest() +{ + sceneIdx = -1; + addChild(nextAction()); + + Director::sharedDirector()->replaceScene(this); +} + +//------------------------------------------------------------------ +// +// S9SpriteTestDemo +// +//------------------------------------------------------------------ + +void S9SpriteTestDemo::onEnter() +{ + BaseTest::onEnter(); + SpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(s_s9s_blocks9_plist); + CCLOG("sprite frames added to sprite frame cache..."); +} + +void S9SpriteTestDemo::restartCallback(Object* sender) +{ + Scene* s = new S9SpriteTestScene(); + s->addChild( restartAction() ); + Director::sharedDirector()->replaceScene(s); + s->release(); +} + +void S9SpriteTestDemo::nextCallback(Object* sender) +{ + Scene* s = new S9SpriteTestScene(); + s->addChild( nextAction() ); + Director::sharedDirector()->replaceScene(s); + s->release(); +} + +void S9SpriteTestDemo::backCallback(Object* sender) +{ + Scene* s = new S9SpriteTestScene(); + s->addChild( backAction() ); + Director::sharedDirector()->replaceScene(s); + s->release(); +} + + +// S9BatchNodeBasic + +void S9BatchNodeBasic::onEnter() +{ + S9SpriteTestDemo::onEnter(); + Size winSize = Director::sharedDirector()->getWinSize(); + float x = winSize.width / 2; + float y = 0 + (winSize.height / 2); + + CCLog("S9BatchNodeBasic ..."); + + auto batchNode = SpriteBatchNode::create("Images/blocks9.png"); + CCLog("batchNode created with : Images/blocks9.png"); + + auto blocks = Scale9Sprite::create(); + CCLog("... created"); + + blocks->updateWithBatchNode(batchNode, Rect(0, 0, 96, 96), false, Rect(0, 0, 96, 96)); + CCLog("... updateWithBatchNode"); + + blocks->setPosition(Point(x, y)); + CCLog("... setPosition"); + + this->addChild(blocks); + CCLog("this->addChild"); + + CCLog("... S9BatchNodeBasic done."); +} + +std::string S9BatchNodeBasic::title() +{ + return "Scale9Sprite created empty and updated from SpriteBatchNode"; +} + +std::string S9BatchNodeBasic::subtitle() +{ + return "updateWithBatchNode(); capInsets=full size"; +} + + +// S9FrameNameSpriteSheet + +void S9FrameNameSpriteSheet::onEnter() +{ + S9SpriteTestDemo::onEnter(); + Size winSize = Director::sharedDirector()->getWinSize(); + float x = winSize.width / 2; + float y = 0 + (winSize.height / 2); + + CCLog("S9FrameNameSpriteSheet ..."); + + auto blocks = Scale9Sprite::createWithSpriteFrameName("blocks9.png"); + CCLog("... created"); + + blocks->setPosition(Point(x, y)); + CCLog("... setPosition"); + + this->addChild(blocks); + CCLog("this->addChild"); + + CCLog("... S9FrameNameSpriteSheet done."); +} + +std::string S9FrameNameSpriteSheet::title() +{ + return "Scale9Sprite from sprite sheet"; +} + +std::string S9FrameNameSpriteSheet::subtitle() +{ + return "createWithSpriteFrameName(); default cap insets"; +} + +// +//// S9FrameNameSpriteSheetRotated +// +void S9FrameNameSpriteSheetRotated::onEnter() +{ + S9SpriteTestDemo::onEnter(); + Size winSize = Director::sharedDirector()->getWinSize(); + float x = winSize.width / 2; + float y = 0 + (winSize.height / 2); + + CCLog("S9FrameNameSpriteSheetRotated ..."); + + auto blocks = Scale9Sprite::createWithSpriteFrameName("blocks9r.png"); + CCLog("... created"); + + blocks->setPosition(Point(x, y)); + CCLog("... setPosition"); + + this->addChild(blocks); + CCLog("this->addChild"); + + CCLog("... S9FrameNameSpriteSheetRotated done."); +} + +std::string S9FrameNameSpriteSheetRotated::title() +{ + return "Scale9Sprite from sprite sheet (stored rotated)"; +} + +std::string S9FrameNameSpriteSheetRotated::subtitle() +{ + return "createWithSpriteFrameName(); default cap insets"; +} + +// +//// S9BatchNodeScaledNoInsets +// + +void S9BatchNodeScaledNoInsets::onEnter() +{ + S9SpriteTestDemo::onEnter(); + Size winSize = Director::sharedDirector()->getWinSize(); + float x = winSize.width / 2; + float y = 0 + (winSize.height / 2); + + CCLog("S9BatchNodeScaledNoInsets ..."); + + // scaled without insets + auto batchNode_scaled = SpriteBatchNode::create("Images/blocks9.png"); + CCLog("batchNode_scaled created with : Images/blocks9.png"); + + auto blocks_scaled = Scale9Sprite::create(); + CCLog("... created"); + blocks_scaled->updateWithBatchNode(batchNode_scaled, Rect(0, 0, 96, 96), false, Rect(0, 0, 96, 96)); + CCLog("... updateWithBatchNode"); + + blocks_scaled->setPosition(Point(x, y)); + CCLog("... setPosition"); + + blocks_scaled->setContentSize(Size(96 * 4, 96*2)); + CCLog("... setContentSize"); + + this->addChild(blocks_scaled); + CCLog("this->addChild"); + + CCLog("... S9BtchNodeScaledNoInsets done."); +} + +std::string S9BatchNodeScaledNoInsets::title() +{ + return "Scale9Sprite created empty and updated from SpriteBatchNode"; +} + +std::string S9BatchNodeScaledNoInsets::subtitle() +{ + return "updateWithBatchNode(); capInsets=full size; rendered 4 X width, 2 X height"; +} + +// +//// S9FrameNameSpriteSheetScaledNoInsets +// + +void S9FrameNameSpriteSheetScaledNoInsets::onEnter() +{ + S9SpriteTestDemo::onEnter(); + Size winSize = Director::sharedDirector()->getWinSize(); + float x = winSize.width / 2; + float y = 0 + (winSize.height / 2); + + CCLog("S9FrameNameSpriteSheetScaledNoInsets ..."); + + auto blocks_scaled = Scale9Sprite::createWithSpriteFrameName("blocks9.png"); + CCLog("... created"); + + blocks_scaled->setPosition(Point(x, y)); + CCLog("... setPosition"); + + blocks_scaled->setContentSize(Size(96 * 4, 96*2)); + CCLog("... setContentSize"); + + this->addChild(blocks_scaled); + CCLog("this->addChild"); + + CCLog("... S9FrameNameSpriteSheetScaledNoInsets done."); +} + +std::string S9FrameNameSpriteSheetScaledNoInsets::title() +{ + return "Scale9Sprite from sprite sheet"; +} + +std::string S9FrameNameSpriteSheetScaledNoInsets::subtitle() +{ + return "createWithSpriteFrameName(); default cap insets; rendered 4 X width, 2 X height"; +} + + +// +//// S9FrameNameSpriteSheetRotatedScaledNoInsets +// + +void S9FrameNameSpriteSheetRotatedScaledNoInsets::onEnter() +{ + S9SpriteTestDemo::onEnter(); + Size winSize = Director::sharedDirector()->getWinSize(); + float x = winSize.width / 2; + float y = 0 + (winSize.height / 2); + + CCLog("S9FrameNameSpriteSheetRotatedScaledNoInsets ..."); + + auto blocks_scaled = Scale9Sprite::createWithSpriteFrameName("blocks9r.png"); + CCLog("... created"); + + blocks_scaled->setPosition(Point(x, y)); + CCLog("... setPosition"); + + blocks_scaled->setContentSize(Size(96 * 4, 96*2)); + CCLog("... setContentSize"); + + this->addChild(blocks_scaled); + CCLog("this->addChild"); + + CCLog("... S9FrameNameSpriteSheetRotatedScaledNoInsets done."); +} + +std::string S9FrameNameSpriteSheetRotatedScaledNoInsets::title() +{ + return "Scale9Sprite from sprite sheet (stored rotated)"; +} + +std::string S9FrameNameSpriteSheetRotatedScaledNoInsets::subtitle() +{ + return "createWithSpriteFrameName(); default cap insets; rendered 4 X width, 2 X height"; +} + +// +// +//// S9BatchNodeScaleWithCapInsets +// + +void S9BatchNodeScaleWithCapInsets::onEnter() +{ + S9SpriteTestDemo::onEnter(); + Size winSize = Director::sharedDirector()->getWinSize(); + float x = winSize.width / 2; + float y = 0 + (winSize.height / 2); + + CCLog("S9BatchNodeScaleWithCapInsets ..."); + + auto batchNode_scaled_with_insets = SpriteBatchNode::create("Images/blocks9.png"); + CCLog("batchNode_scaled_with_insets created with : Images/blocks9.png"); + + auto blocks_scaled_with_insets = Scale9Sprite::create(); + CCLog("... created"); + + blocks_scaled_with_insets->updateWithBatchNode(batchNode_scaled_with_insets, Rect(0, 0, 96, 96), false, Rect(32, 32, 32, 32)); + CCLog("... updateWithBatchNode"); + + blocks_scaled_with_insets->setContentSize(Size(96 * 4.5, 96 * 2.5)); + CCLog("... setContentSize"); + + blocks_scaled_with_insets->setPosition(Point(x, y)); + CCLog("... setPosition"); + + this->addChild(blocks_scaled_with_insets); + CCLog("this->addChild"); + + CCLog("... S9BatchNodeScaleWithCapInsets done."); +} + +std::string S9BatchNodeScaleWithCapInsets::title() +{ + return "Scale9Sprite created empty and updated from SpriteBatchNode"; +} + +std::string S9BatchNodeScaleWithCapInsets::subtitle() +{ + return "updateWithBatchNode(); capInsets=(32, 32, 32, 32)"; +} + +// +//// S9FrameNameSpriteSheetInsets +// + +void S9FrameNameSpriteSheetInsets::onEnter() +{ + S9SpriteTestDemo::onEnter(); + Size winSize = Director::sharedDirector()->getWinSize(); + float x = winSize.width / 2; + float y = 0 + (winSize.height / 2); + + CCLog("S9FrameNameSpriteSheetInsets ..."); + + auto blocks_with_insets = Scale9Sprite::createWithSpriteFrameName("blocks9.png", Rect(32, 32, 32, 32)); + CCLog("... created"); + + blocks_with_insets->setPosition(Point(x, y)); + CCLog("... setPosition"); + + this->addChild(blocks_with_insets); + CCLog("this->addChild"); + + CCLog("... S9FrameNameSpriteSheetInsets done."); +} + +std::string S9FrameNameSpriteSheetInsets::title() +{ + return "Scale9Sprite scaled with insets sprite sheet"; +} + +std::string S9FrameNameSpriteSheetInsets::subtitle() +{ + return "createWithSpriteFrameName(); cap insets=(32, 32, 32, 32)"; +} + +// +//// S9FrameNameSpriteSheetInsetsScaled +// +void S9FrameNameSpriteSheetInsetsScaled::onEnter() +{ + S9SpriteTestDemo::onEnter(); + Size winSize = Director::sharedDirector()->getWinSize(); + float x = winSize.width / 2; + float y = 0 + (winSize.height / 2); + + CCLog("S9FrameNameSpriteSheetInsetsScaled ..."); + + auto blocks_scaled_with_insets = Scale9Sprite::createWithSpriteFrameName("blocks9.png", Rect(32, 32, 32, 32)); + CCLog("... created"); + + blocks_scaled_with_insets->setContentSize(Size(96 * 4.5, 96 * 2.5)); + CCLog("... setContentSize"); + + blocks_scaled_with_insets->setPosition(Point(x, y)); + CCLog("... setPosition"); + + this->addChild(blocks_scaled_with_insets); + CCLog("this->addChild"); + + CCLog("... S9FrameNameSpriteSheetInsetsScaled done."); +} + +std::string S9FrameNameSpriteSheetInsetsScaled::title() +{ + return "Scale9Sprite scaled with insets sprite sheet"; +} + +std::string S9FrameNameSpriteSheetInsetsScaled::subtitle() +{ + return "createWithSpriteFrameName(); default cap insets; rendered scaled 4.5 X width, 2.5 X height"; +} + +//// S9FrameNameSpriteSheetRotatedInsets +// + +void S9FrameNameSpriteSheetRotatedInsets::onEnter() +{ + S9SpriteTestDemo::onEnter(); + Size winSize = Director::sharedDirector()->getWinSize(); + float x = winSize.width / 2; + float y = 0 + (winSize.height / 2); + + CCLog("S9FrameNameSpriteSheetRotatedInsets ..."); + + auto blocks_with_insets = Scale9Sprite::createWithSpriteFrameName("blocks9r.png", Rect(32, 32, 32, 32)); + CCLog("... created"); + + blocks_with_insets->setPosition(Point(x, y)); + CCLog("... setPosition"); + + this->addChild(blocks_with_insets); + CCLog("this->addChild"); + + CCLog("... S9FrameNameSpriteSheetRotatedInsets done."); +} + +std::string S9FrameNameSpriteSheetRotatedInsets::title() +{ + return "Scale9Sprite scaled with insets sprite sheet (stored rotated)"; +} + +std::string S9FrameNameSpriteSheetRotatedInsets::subtitle() +{ + return "createWithSpriteFrameName(); cap insets=(32, 32, 32, 32)"; +} + +// +//// S9_TexturePacker +// + +void S9_TexturePacker::onEnter() +{ + S9SpriteTestDemo::onEnter(); + Size winSize = Director::sharedDirector()->getWinSize(); + SpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(s_s9s_ui_plist); + + float x = winSize.width / 4; + float y = 0 + (winSize.height / 2); + + CCLog("S9_TexturePacker ..."); + + auto s = Scale9Sprite::createWithSpriteFrameName("button_normal.png"); + CCLog("... created"); + + s->setPosition(Point(x, y)); + CCLog("... setPosition"); + + s->setContentSize(Size(21 * 16, 13 * 16)); + CCLog("... setContentSize"); + + this->addChild(s); + CCLog("this->addChild"); + + x = winSize.width * 3/4; + + auto s2 = Scale9Sprite::createWithSpriteFrameName("button_actived.png"); + CCLog("... created"); + + s2->setPosition(Point(x, y)); + CCLog("... setPosition"); + + s2->setContentSize(Size(21 * 16, 13 * 16)); + CCLog("... setContentSize"); + + this->addChild(s2); + CCLog("this->addChild"); + + CCLog("... S9_TexturePacker done."); +} + +std::string S9_TexturePacker::title() +{ + return "Scale9Sprite from a spritesheet created with TexturePacker"; +} + +std::string S9_TexturePacker::subtitle() +{ + return "createWithSpriteFrameName('button_normal.png');createWithSpriteFrameName('button_actived.png');"; +} + +// +//// S9FrameNameSpriteSheetRotatedInsetsScaled +// + +void S9FrameNameSpriteSheetRotatedInsetsScaled::onEnter() +{ + S9SpriteTestDemo::onEnter(); + Size winSize = Director::sharedDirector()->getWinSize(); + float x = winSize.width / 2; + float y = 0 + (winSize.height / 2); + + CCLog("S9FrameNameSpriteSheetRotatedInsetsScaled ..."); + + auto blocks_scaled_with_insets = Scale9Sprite::createWithSpriteFrameName("blocks9.png", Rect(32, 32, 32, 32)); + CCLog("... created"); + + blocks_scaled_with_insets->setContentSize(Size(96 * 4.5, 96 * 2.5)); + CCLog("... setContentSize"); + + blocks_scaled_with_insets->setPosition(Point(x, y)); + CCLog("... setPosition"); + + this->addChild(blocks_scaled_with_insets); + CCLog("this->addChild"); + + CCLog("... S9FrameNameSpriteSheetRotatedInsetsScaled done."); +} + +std::string S9FrameNameSpriteSheetRotatedInsetsScaled::title() +{ + return "Scale9Sprite scaled with insets sprite sheet (stored rotated)"; +} + +std::string S9FrameNameSpriteSheetRotatedInsetsScaled::subtitle() +{ + return "createWithSpriteFrameName(); default cap insets; rendered scaled 4.5 X width, 2.5 X height"; +} diff --git a/samples/Cpp/TestCpp/Classes/ExtensionsTest/Scale9SpriteTest/Scale9SpriteTest.h b/samples/Cpp/TestCpp/Classes/ExtensionsTest/Scale9SpriteTest/Scale9SpriteTest.h new file mode 100644 index 0000000000..d2f6274502 --- /dev/null +++ b/samples/Cpp/TestCpp/Classes/ExtensionsTest/Scale9SpriteTest/Scale9SpriteTest.h @@ -0,0 +1,180 @@ +/**************************************************************************** + Copyright (c) 2010-2012 cocos2d-x.org + Copyright (c) 2008-2010 Ricardo Quesada + Copyright (c) 2011 Zynga Inc. + Copyright (c) 2013 Surith Thekkiam + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#include "testBasic.h" +#include "BaseTest.h" + + +class S9SpriteTestScene : public TestScene +{ +public: + virtual void runThisTest(); +}; + +class S9SpriteTestDemo : public BaseTest +{ +public: + virtual void onEnter(); + + virtual void restartCallback(Object* sender); + virtual void nextCallback(Object* sender); + virtual void backCallback(Object* sender); +}; + +// S9BatchNodeBasic + +class S9BatchNodeBasic : public S9SpriteTestDemo +{ +public: + virtual void onEnter(); + + virtual std::string title(); + virtual std::string subtitle(); +}; + +// S9FrameNameSpriteSheet + +class S9FrameNameSpriteSheet : public S9SpriteTestDemo +{ +public: + virtual void onEnter(); + + virtual std::string title(); + virtual std::string subtitle(); +}; + +// S9FrameNameSpriteSheetRotated + +class S9FrameNameSpriteSheetRotated : public S9SpriteTestDemo +{ +public: + virtual void onEnter(); + + virtual std::string title(); + virtual std::string subtitle(); +}; + +// S9BatchNodeScaledNoInsets + +class S9BatchNodeScaledNoInsets : public S9SpriteTestDemo +{ +public: + virtual void onEnter(); + + virtual std::string title(); + virtual std::string subtitle(); +}; + +// S9FrameNameSpriteSheetScaledNoInsets + +class S9FrameNameSpriteSheetScaledNoInsets : public S9SpriteTestDemo +{ +public: + virtual void onEnter(); + + virtual std::string title(); + virtual std::string subtitle(); +}; + +// S9FrameNameSpriteSheetRotatedScaledNoInsets + +class S9FrameNameSpriteSheetRotatedScaledNoInsets : public S9SpriteTestDemo +{ +public: + virtual void onEnter(); + + virtual std::string title(); + virtual std::string subtitle(); +}; + + +// S9BatchNodeScaleWithCapInsets + +class S9BatchNodeScaleWithCapInsets : public S9SpriteTestDemo +{ +public: + virtual void onEnter(); + + virtual std::string title(); + virtual std::string subtitle(); +}; + +// S9FrameNameSpriteSheetInsets + +class S9FrameNameSpriteSheetInsets : public S9SpriteTestDemo +{ +public: + virtual void onEnter(); + + virtual std::string title(); + virtual std::string subtitle(); +}; + +// S9FrameNameSpriteSheetInsetsScaled + +class S9FrameNameSpriteSheetInsetsScaled : public S9SpriteTestDemo +{ +public: + virtual void onEnter(); + + virtual std::string title(); + virtual std::string subtitle(); +}; + +// S9FrameNameSpriteSheetRotatedInsets + +class S9FrameNameSpriteSheetRotatedInsets : public S9SpriteTestDemo +{ +public: + virtual void onEnter(); + + virtual std::string title(); + virtual std::string subtitle(); +}; + +// S9_TexturePacker + +class S9_TexturePacker : public S9SpriteTestDemo +{ +public: + virtual void onEnter(); + + virtual std::string title(); + virtual std::string subtitle(); +}; + +// S9FrameNameSpriteSheetRotatedInsetsScaled + +class S9FrameNameSpriteSheetRotatedInsetsScaled : public S9SpriteTestDemo +{ +public: + virtual void onEnter(); + + virtual std::string title(); + virtual std::string subtitle(); +}; + diff --git a/samples/Cpp/TestCpp/Classes/testResource.h b/samples/Cpp/TestCpp/Classes/testResource.h index 6293e6a1d6..72b72c286e 100644 --- a/samples/Cpp/TestCpp/Classes/testResource.h +++ b/samples/Cpp/TestCpp/Classes/testResource.h @@ -39,5 +39,10 @@ static const char s_AtlasTest[] = "Images/atlastest.png"; static const char s_TilesPng[] = "TileMaps/tiles.png"; static const char s_LevelMapTga[] = "TileMaps/levelmap.tga"; +// Scale9Sprite resource +static const char s_s9s_blocks9[] = "Images/blocks9ss.png"; +static const char s_s9s_blocks9_plist[] = "Images/blocks9ss.plist"; +static const char s_s9s_ui[] = "Images/ui.png"; +static const char s_s9s_ui_plist[] = "Images/ui.plist"; #endif diff --git a/samples/samples.xcodeproj/project.pbxproj.REMOVED.git-id b/samples/samples.xcodeproj/project.pbxproj.REMOVED.git-id index 303698521a..3c29d0e657 100644 --- a/samples/samples.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/samples/samples.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -678e714c9c548501d076d34e2af0b13619e0a5aa \ No newline at end of file +14e0d7211e9d0c638e41502416e3d944890dd856 \ No newline at end of file From 9946bc4f00e19b6cf36fd753328048fec8f19c32 Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 11 Jul 2013 14:13:01 +0800 Subject: [PATCH 4/6] issue #2395: Adding Scale9SpriteTest for other platforms. --- samples/Cpp/TestCpp/Android.mk | 1 + samples/Cpp/TestCpp/proj.emscripten/Makefile | 13 +++++++------ samples/Cpp/TestCpp/proj.linux/Makefile | 13 +++++++------ samples/Cpp/TestCpp/proj.nacl/Makefile | 13 +++++++------ 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/samples/Cpp/TestCpp/Android.mk b/samples/Cpp/TestCpp/Android.mk index f60492fda4..d865004371 100644 --- a/samples/Cpp/TestCpp/Android.mk +++ b/samples/Cpp/TestCpp/Android.mk @@ -66,6 +66,7 @@ Classes/ExtensionsTest/NetworkTest/WebSocketTest.cpp \ Classes/ExtensionsTest/EditBoxTest/EditBoxTest.cpp \ Classes/ExtensionsTest/TableViewTest/TableViewTestScene.cpp \ Classes/ExtensionsTest/TableViewTest/CustomTableViewCell.cpp \ +Classes/ExtensionsTest/Scale9SpriteTest/Scale9SpriteTest.cpp \ Classes/FontTest/FontTest.cpp \ Classes/IntervalTest/IntervalTest.cpp \ Classes/KeypadTest/KeypadTest.cpp \ diff --git a/samples/Cpp/TestCpp/proj.emscripten/Makefile b/samples/Cpp/TestCpp/proj.emscripten/Makefile index c580d89eb9..6f069f65bd 100644 --- a/samples/Cpp/TestCpp/proj.emscripten/Makefile +++ b/samples/Cpp/TestCpp/proj.emscripten/Makefile @@ -49,13 +49,14 @@ SOURCES = ../Classes/AccelerometerTest/AccelerometerTest.cpp \ ../Classes/ExtensionsTest/ExtensionsTest.cpp \ ../Classes/ExtensionsTest/NotificationCenterTest/NotificationCenterTest.cpp \ ../Classes/ExtensionsTest/NetworkTest/HttpClientTest.cpp \ - ../Classes/ExtensionsTest/ComponentsTest/ComponentsTestScene.cpp \ - ../Classes/ExtensionsTest/ComponentsTest/EnemyController.cpp \ - ../Classes/ExtensionsTest/ComponentsTest/GameOverScene.cpp \ - ../Classes/ExtensionsTest/ComponentsTest/PlayerController.cpp \ - ../Classes/ExtensionsTest/ComponentsTest/ProjectileController.cpp \ - ../Classes/ExtensionsTest/ComponentsTest/SceneController.cpp \ + ../Classes/ExtensionsTest/ComponentsTest/ComponentsTestScene.cpp \ + ../Classes/ExtensionsTest/ComponentsTest/EnemyController.cpp \ + ../Classes/ExtensionsTest/ComponentsTest/GameOverScene.cpp \ + ../Classes/ExtensionsTest/ComponentsTest/PlayerController.cpp \ + ../Classes/ExtensionsTest/ComponentsTest/ProjectileController.cpp \ + ../Classes/ExtensionsTest/ComponentsTest/SceneController.cpp \ ../Classes/ExtensionsTest/ArmatureTest/ArmatureScene.cpp \ + ../Classes/ExtensionsTest/Scale9SpriteTest/Scale9SpriteTest.cpp \ ../Classes/FontTest/FontTest.cpp \ ../Classes/IntervalTest/IntervalTest.cpp \ ../Classes/KeypadTest/KeypadTest.cpp \ diff --git a/samples/Cpp/TestCpp/proj.linux/Makefile b/samples/Cpp/TestCpp/proj.linux/Makefile index 62c38a39cc..6299d76db2 100644 --- a/samples/Cpp/TestCpp/proj.linux/Makefile +++ b/samples/Cpp/TestCpp/proj.linux/Makefile @@ -52,13 +52,14 @@ SOURCES = ../Classes/AccelerometerTest/AccelerometerTest.cpp \ ../Classes/ExtensionsTest/ExtensionsTest.cpp \ ../Classes/ExtensionsTest/NotificationCenterTest/NotificationCenterTest.cpp \ ../Classes/ExtensionsTest/NetworkTest/HttpClientTest.cpp \ - ../Classes/ExtensionsTest/ComponentsTest/ComponentsTestScene.cpp \ - ../Classes/ExtensionsTest/ComponentsTest/EnemyController.cpp \ - ../Classes/ExtensionsTest/ComponentsTest/GameOverScene.cpp \ - ../Classes/ExtensionsTest/ComponentsTest/PlayerController.cpp \ - ../Classes/ExtensionsTest/ComponentsTest/ProjectileController.cpp \ - ../Classes/ExtensionsTest/ComponentsTest/SceneController.cpp \ + ../Classes/ExtensionsTest/ComponentsTest/ComponentsTestScene.cpp \ + ../Classes/ExtensionsTest/ComponentsTest/EnemyController.cpp \ + ../Classes/ExtensionsTest/ComponentsTest/GameOverScene.cpp \ + ../Classes/ExtensionsTest/ComponentsTest/PlayerController.cpp \ + ../Classes/ExtensionsTest/ComponentsTest/ProjectileController.cpp \ + ../Classes/ExtensionsTest/ComponentsTest/SceneController.cpp \ ../Classes/ExtensionsTest/ArmatureTest/ArmatureScene.cpp \ + ../Classes/ExtensionsTest/Scale9SpriteTest/Scale9SpriteTest.cpp \ ../Classes/FontTest/FontTest.cpp \ ../Classes/IntervalTest/IntervalTest.cpp \ ../Classes/KeyboardTest/KeyboardTest.cpp \ diff --git a/samples/Cpp/TestCpp/proj.nacl/Makefile b/samples/Cpp/TestCpp/proj.nacl/Makefile index 870354d05b..6dac4828f1 100644 --- a/samples/Cpp/TestCpp/proj.nacl/Makefile +++ b/samples/Cpp/TestCpp/proj.nacl/Makefile @@ -55,13 +55,14 @@ SOURCES = ../Classes/AccelerometerTest/AccelerometerTest.cpp \ ../Classes/ExtensionsTest/TableViewTest/CustomTableViewCell.cpp \ ../Classes/ExtensionsTest/ExtensionsTest.cpp \ ../Classes/ExtensionsTest/NotificationCenterTest/NotificationCenterTest.cpp \ - ../Classes/ExtensionsTest/ComponentsTest/ComponentsTestScene.cpp \ - ../Classes/ExtensionsTest/ComponentsTest/EnemyController.cpp \ - ../Classes/ExtensionsTest/ComponentsTest/GameOverScene.cpp \ - ../Classes/ExtensionsTest/ComponentsTest/PlayerController.cpp \ - ../Classes/ExtensionsTest/ComponentsTest/ProjectileController.cpp \ - ../Classes/ExtensionsTest/ComponentsTest/SceneController.cpp \ + ../Classes/ExtensionsTest/ComponentsTest/ComponentsTestScene.cpp \ + ../Classes/ExtensionsTest/ComponentsTest/EnemyController.cpp \ + ../Classes/ExtensionsTest/ComponentsTest/GameOverScene.cpp \ + ../Classes/ExtensionsTest/ComponentsTest/PlayerController.cpp \ + ../Classes/ExtensionsTest/ComponentsTest/ProjectileController.cpp \ + ../Classes/ExtensionsTest/ComponentsTest/SceneController.cpp \ ../Classes/ExtensionsTest/ArmatureTest/ArmatureScene.cpp \ + ../Classes/ExtensionsTest/Scale9SpriteTest/Scale9SpriteTest.cpp \ ../Classes/FileUtilsTest/FileUtilsTest.cpp \ ../Classes/FontTest/FontTest.cpp \ ../Classes/IntervalTest/IntervalTest.cpp \ From ab4e9749b6f3341194eb4cd15ec4042b75232479 Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 11 Jul 2013 14:17:43 +0800 Subject: [PATCH 5/6] issue #2395: [Win32] Updating TestCpp project configuration --- samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj | 2 ++ samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj index fac41ae5e7..09a603fc73 100644 --- a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj +++ b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj @@ -151,6 +151,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\..\..\external\libwebsockets\win32\lib\*.*" "$(O + @@ -258,6 +259,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\..\..\external\libwebsockets\win32\lib\*.*" "$(O + diff --git a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters index da6a8674db..967126a591 100644 --- a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters +++ b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters @@ -232,6 +232,9 @@ {285cdfb8-5749-4969-ae31-99ec25f15e6e} + + {3d73aa04-d66e-43d3-921f-b867a753c113} + @@ -543,6 +546,9 @@ Classes\ExtensionsTest\ComponentsTest + + Classes\ExtensionsTest\Scale9SpriteTest + @@ -1034,5 +1040,8 @@ Classes\ExtensionsTest\ComponentsTest + + Classes\ExtensionsTest\Scale9SpriteTest + \ No newline at end of file From 1527c1b4c3fe19a8b3343dafd3df537205336166 Mon Sep 17 00:00:00 2001 From: James Chen Date: Thu, 11 Jul 2013 15:09:13 +0800 Subject: [PATCH 6/6] issue #2395: Updating TestCpp/Android.mk --- samples/Cpp/TestCpp/Android.mk | 2 ++ 1 file changed, 2 insertions(+) diff --git a/samples/Cpp/TestCpp/Android.mk b/samples/Cpp/TestCpp/Android.mk index d865004371..55e2bdd3c2 100644 --- a/samples/Cpp/TestCpp/Android.mk +++ b/samples/Cpp/TestCpp/Android.mk @@ -111,6 +111,8 @@ Classes/AppDelegate.cpp \ Classes/BaseTest.cpp \ Classes/VisibleRect.cpp +LOCAL_C_INCLUDES := $(LOCAL_PATH)/Classes + LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static LOCAL_WHOLE_STATIC_LIBRARIES += box2d_static