diff --git a/cocos2dx/CCConfiguration.cpp b/cocos2dx/CCConfiguration.cpp index b2b17b105e..c571d33b82 100644 --- a/cocos2dx/CCConfiguration.cpp +++ b/cocos2dx/CCConfiguration.cpp @@ -83,9 +83,9 @@ bool CCConfiguration::init(void) bEnableProfilers ? "YES - *** Disable it when you finish profiling ***" : "NO"); #if CC_ENABLE_GL_STATE_CACHE == 0 - CCLOG(""); - CCLOG("cocos2d: **** WARNING **** CC_ENABLE_GL_STATE_CACHE is disabled. To improve performance, enable it by editing ccConfig.h"); - printf("\n"); + CCLOG(""); + CCLOG("cocos2d: **** WARNING **** CC_ENABLE_GL_STATE_CACHE is disabled. To improve performance, enable it by editing ccConfig.h"); + printf("\n"); #endif CHECK_GL_ERROR_DEBUG(); diff --git a/cocos2dx/CCDirector.cpp b/cocos2dx/CCDirector.cpp index b7270e4791..d0a4ef7111 100644 --- a/cocos2dx/CCDirector.cpp +++ b/cocos2dx/CCDirector.cpp @@ -353,10 +353,10 @@ void CCDirector::setProjection(ccDirectorProjection kProjection) case kCCDirectorProjection3D: { - // reset the viewport if 3d proj & retina display - if( CC_CONTENT_SCALE_FACTOR() != 1.0f ) - { - glViewport((GLint)-size.width/2, (GLint)-size.height/2, (GLsizei)(size.width * CC_CONTENT_SCALE_FACTOR()), (GLsizei)(size.height * CC_CONTENT_SCALE_FACTOR()) ); + // reset the viewport if 3d proj & retina display + if( CC_CONTENT_SCALE_FACTOR() != 1.0f ) + { + glViewport((GLint)-size.width/2, (GLint)-size.height/2, (GLsizei)(size.width * CC_CONTENT_SCALE_FACTOR()), (GLsizei)(size.height * CC_CONTENT_SCALE_FACTOR()) ); } float zeye = this->getZEye(); diff --git a/cocos2dx/include/cocos2d.h b/cocos2dx/include/cocos2d.h index a74a42b2ff..d3bcff4233 100755 --- a/cocos2dx/include/cocos2d.h +++ b/cocos2dx/include/cocos2d.h @@ -34,16 +34,16 @@ THE SOFTWARE. #include "ccConfig.h" // actions -#include "CCAction.h" -#include "CCActionInterval.h" -#include "CCActionCamera.h" -#include "CCActionManager.h" -#include "CCActionEase.h" -#include "CCActionPageTurn3D.h" -#include "CCActionGrid.h" -#include "CCActionProgressTimer.h" -#include "CCActionGrid3D.h" -#include "CCActionTiledGrid.h" +#include "CCAction.h" +#include "CCActionInterval.h" +#include "CCActionCamera.h" +#include "CCActionManager.h" +#include "CCActionEase.h" +#include "CCActionPageTurn3D.h" +#include "CCActionGrid.h" +#include "CCActionProgressTimer.h" +#include "CCActionGrid3D.h" +#include "CCActionTiledGrid.h" #include "CCActionInstant.h" #include "CCActionTween.h" @@ -52,15 +52,15 @@ THE SOFTWARE. #include "CCAtlasNode.h" // cocoa -#include "CCAffineTransform.h" -#include "CCDictionary.h" -#include "CCObject.h" -#include "CCArray.h" -#include "CCGeometry.h" -#include "CCSet.h" -#include "CCAutoreleasePool.h" -#include "CCInteger.h" -#include "CCString.h" +#include "CCAffineTransform.h" +#include "CCDictionary.h" +#include "CCObject.h" +#include "CCArray.h" +#include "CCGeometry.h" +#include "CCSet.h" +#include "CCAutoreleasePool.h" +#include "CCInteger.h" +#include "CCString.h" #include "CCData.h" #include "CCNS.h" #include "CCZone.h" @@ -70,11 +70,11 @@ THE SOFTWARE. #include "CCGrid.h" // include -#include "CCEventType.h" -#include "CCProtocols.h" -#include "ccConfig.h" -#include "ccMacros.h" -#include "ccTypes.h" +#include "CCEventType.h" +#include "CCProtocols.h" +#include "ccConfig.h" +#include "ccMacros.h" +#include "ccTypes.h" #include "cocos2dExt.h" // kazmath @@ -86,15 +86,15 @@ THE SOFTWARE. #include "CCKeypadDispatcher.h" // label_nodes -#include "CCLabelAtlas.h" -#include "CCLabelTTF.h" +#include "CCLabelAtlas.h" +#include "CCLabelTTF.h" #include "CCLabelBMFont.h" // layers_scenes_transitions_nodes -#include "CCLayer.h" -#include "CCScene.h" -#include "CCTransition.h" -#include "CCTransitionPageTurn.h" +#include "CCLayer.h" +#include "CCScene.h" +#include "CCTransition.h" +#include "CCTransitionPageTurn.h" #include "CCTransitionProgress.h" // menu_nodes @@ -107,8 +107,8 @@ THE SOFTWARE. #include "CCRenderTexture.h" // particle_nodes -#include "CCParticleBatchNode.h" -#include "CCParticleSystem.h" +#include "CCParticleBatchNode.h" +#include "CCParticleSystem.h" #include "CCParticleExamples.h" #include "CCParticleSystemQuad.h" @@ -135,18 +135,18 @@ THE SOFTWARE. #include "ccShaders.h" // sprite_nodes -#include "CCAnimation.h" -#include "CCAnimationCache.h" -#include "CCSprite.h" -#include "CCSpriteBatchNode.h" -#include "CCSpriteFrame.h" +#include "CCAnimation.h" +#include "CCAnimationCache.h" +#include "CCSprite.h" +#include "CCSpriteBatchNode.h" +#include "CCSpriteFrame.h" #include "CCSpriteFrameCache.h" // support -#include "CCPointExtension.h" -#include "CCProfiling.h" -#include "CCUserDefault.h" -#include "CCVertex.h" +#include "CCPointExtension.h" +#include "CCProfiling.h" +#include "CCUserDefault.h" +#include "CCVertex.h" // text_input_node #include "CCIMEDelegate.h" @@ -160,17 +160,17 @@ THE SOFTWARE. #include "CCTexturePVR.h" // tileMap_parallax_nodes -#include "CCParallaxNode.h" -#include "CCTMXLayer.h" -#include "CCTMXObjectGroup.h" -#include "CCTMXTiledMap.h" -#include "CCTMXXMLParser.h" +#include "CCParallaxNode.h" +#include "CCTMXLayer.h" +#include "CCTMXObjectGroup.h" +#include "CCTMXTiledMap.h" +#include "CCTMXXMLParser.h" #include "CCTileMapAtlas.h" // touch_dispatcher -#include "CCTouch.h" -#include "CCTouchDelegateProtocol.h" -#include "CCTouchDispatcher.h" +#include "CCTouch.h" +#include "CCTouchDelegateProtocol.h" +#include "CCTouchDispatcher.h" #include "CCTouchHandler.h" // root diff --git a/cocos2dx/label_nodes/CCLabelBMFont.cpp b/cocos2dx/label_nodes/CCLabelBMFont.cpp index 220fc33e37..4c0820ebfd 100644 --- a/cocos2dx/label_nodes/CCLabelBMFont.cpp +++ b/cocos2dx/label_nodes/CCLabelBMFont.cpp @@ -954,9 +954,9 @@ void CCLabelBMFont::setString(const char *newString) void CCLabelBMFont::setString(const char *newString, bool fromUpdate) { - CC_SAFE_DELETE_ARRAY(m_sString); - m_sString = cc_utf8_from_cstr(newString); - m_sString_initial = newString; + CC_SAFE_DELETE_ARRAY(m_sString); + m_sString = cc_utf8_from_cstr(newString); + m_sString_initial = newString; updateString(fromUpdate); } @@ -1082,11 +1082,11 @@ void CCLabelBMFont::updateLabel() vector str_whole = cc_utf8_vec_from_cstr(m_sString); unsigned int stringLength = str_whole.size(); vector multiline_string; - multiline_string.reserve( stringLength ); + multiline_string.reserve( stringLength ); vector last_word; - last_word.reserve( stringLength ); + last_word.reserve( stringLength ); - unsigned int line = 1, i = 0; + unsigned int line = 1, i = 0; bool start_line = false, start_word = false; float startOfLine = -1, startOfWord = -1; int skip = 0; @@ -1108,7 +1108,7 @@ void CCLabelBMFont::updateLabel() if (!start_word) { - startOfWord = getLetterPosXLeft( characterSprite ); + startOfWord = getLetterPosXLeft( characterSprite ); start_word = true; } if (!start_line) @@ -1122,15 +1122,15 @@ void CCLabelBMFont::updateLabel() { cc_utf8_trim_ws(&last_word); - last_word.push_back('\n'); - multiline_string.insert(multiline_string.end(), last_word.begin(), last_word.end()); - last_word.clear(); - start_word = false; - start_line = false; - startOfWord = -1; - startOfLine = -1; - i++; - line++; + last_word.push_back('\n'); + multiline_string.insert(multiline_string.end(), last_word.begin(), last_word.end()); + last_word.clear(); + start_word = false; + start_line = false; + startOfWord = -1; + startOfLine = -1; + i++; + line++; if (i >= stringLength || i < 0) break; @@ -1139,7 +1139,7 @@ void CCLabelBMFont::updateLabel() if (!startOfWord) { - startOfWord = getLetterPosXLeft( characterSprite ); + startOfWord = getLetterPosXLeft( characterSprite ); start_word = true; } if (!startOfLine) @@ -1162,7 +1162,7 @@ void CCLabelBMFont::updateLabel() } // Out of bounds. - if ( getLetterPosXRight( characterSprite ) - startOfLine > m_fWidth ) + if ( getLetterPosXRight( characterSprite ) - startOfLine > m_fWidth ) { if (!m_bLineBreakWithoutSpaces) { @@ -1200,7 +1200,7 @@ void CCLabelBMFont::updateLabel() if (!startOfWord) { - startOfWord = getLetterPosXLeft( characterSprite ); + startOfWord = getLetterPosXLeft( characterSprite ); start_word = true; } if (!startOfLine) @@ -1251,13 +1251,13 @@ void CCLabelBMFont::updateLabel() if (m_sString[ctr] == '\n' || m_sString[ctr] == 0) { float lineWidth = 0.0f; - unsigned int line_length = last_line.size(); + unsigned int line_length = last_line.size(); int index = i + line_length - 1 + lineNumber; if (index < 0) continue; CCSprite* lastChar = (CCSprite*)getChildByTag(index); - if ( lastChar == NULL ) - continue; + if ( lastChar == NULL ) + continue; lineWidth = lastChar->getPosition().x + lastChar->getContentSize().width/2.0f; @@ -1318,30 +1318,30 @@ void CCLabelBMFont::setLineBreakWithoutSpace( bool breakWithoutSpace ) void CCLabelBMFont::setScale(float scale) { - CCSpriteBatchNode::setScale(scale); - updateLabel(); + CCSpriteBatchNode::setScale(scale); + updateLabel(); } void CCLabelBMFont::setScaleX(float scaleX) { - CCSpriteBatchNode::setScaleX(scaleX); - updateLabel(); + CCSpriteBatchNode::setScaleX(scaleX); + updateLabel(); } void CCLabelBMFont::setScaleY(float scaleY) { - CCSpriteBatchNode::setScaleY(scaleY); - updateLabel(); + CCSpriteBatchNode::setScaleY(scaleY); + updateLabel(); } float CCLabelBMFont::getLetterPosXLeft( CCSprite* sp ) { - return sp->getPosition().x * m_fScaleX - (sp->getContentSize().width * m_fScaleX * sp->getAnchorPoint().x); + return sp->getPosition().x * m_fScaleX - (sp->getContentSize().width * m_fScaleX * sp->getAnchorPoint().x); } float CCLabelBMFont::getLetterPosXRight( CCSprite* sp ) { - return sp->getPosition().x * m_fScaleX + (sp->getContentSize().width * m_fScaleX * sp->getAnchorPoint().x); + return sp->getPosition().x * m_fScaleX + (sp->getContentSize().width * m_fScaleX * sp->getAnchorPoint().x); } //LabelBMFont - Debug draw #if CC_LABELBMFONT_DEBUG_DRAW diff --git a/cocos2dx/label_nodes/CCLabelBMFont.h b/cocos2dx/label_nodes/CCLabelBMFont.h index 9898ee70d1..42fc6abcaa 100644 --- a/cocos2dx/label_nodes/CCLabelBMFont.h +++ b/cocos2dx/label_nodes/CCLabelBMFont.h @@ -198,9 +198,9 @@ public: virtual void setAlignment(CCTextAlignment alignment); virtual void setWidth(float width); virtual void setLineBreakWithoutSpace(bool breakWithoutSpace); - virtual void setScale(float scale); - virtual void setScaleX(float scaleX); - virtual void setScaleY(float scaleY); + virtual void setScale(float scale); + virtual void setScaleX(float scaleX); + virtual void setScaleY(float scaleY); #if CC_LABELBMFONT_DEBUG_DRAW virtual void draw(); @@ -208,8 +208,8 @@ public: private: char * atlasNameFromFntFile(const char *fntFile); int kerningAmountForFirst(unsigned short first, unsigned short second); - float getLetterPosXLeft( CCSprite* characterSprite ); - float getLetterPosXRight( CCSprite* characterSprite ); + float getLetterPosXLeft( CCSprite* characterSprite ); + float getLetterPosXRight( CCSprite* characterSprite ); }; diff --git a/cocos2dx/misc_nodes/CCRenderTexture.cpp b/cocos2dx/misc_nodes/CCRenderTexture.cpp index 2492085f54..c4eb592e00 100644 --- a/cocos2dx/misc_nodes/CCRenderTexture.cpp +++ b/cocos2dx/misc_nodes/CCRenderTexture.cpp @@ -229,19 +229,19 @@ void CCRenderTexture::end(bool bIsTOCacheTexture) { CC_SAFE_DELETE(m_pUITextureImage); - // to get the rendered texture data - const CCSize& s = m_pTexture->getContentSizeInPixels(); + // to get the rendered texture data + const CCSize& s = m_pTexture->getContentSizeInPixels(); m_pUITextureImage = newCCImage(); - if (m_pUITextureImage) - { - VolatileTexture::addDataTexture(m_pTexture, m_pUITextureImage->getData(), kTexture2DPixelFormat_RGBA8888, s); - } - else - { - CCLOG("Cache rendertexture failed!"); - } - } + if (m_pUITextureImage) + { + VolatileTexture::addDataTexture(m_pTexture, m_pUITextureImage->getData(), kTexture2DPixelFormat_RGBA8888, s); + } + else + { + CCLOG("Cache rendertexture failed!"); + } + } #endif } diff --git a/cocos2dx/platform/android/CCPlatformDefine.h b/cocos2dx/platform/android/CCPlatformDefine.h index 6530015eae..ab19688f60 100644 --- a/cocos2dx/platform/android/CCPlatformDefine.h +++ b/cocos2dx/platform/android/CCPlatformDefine.h @@ -1,28 +1,28 @@ -#ifndef __CCPLATFORMDEFINE_H__ -#define __CCPLATFORMDEFINE_H__ - -#define CC_DLL - -#define CC_ASSERT(cond) \ -if (! (cond)) \ -{ \ - char content[100]; \ - sprintf(content, "%s function:%s line:%d", __FILE__, __FUNCTION__, __LINE__ - 3); \ - CCMessageBox(content, "Assert error"); \ -} - - -#define CC_UNUSED_PARAM(unusedparam) (void)unusedparam - -/* Define NULL pointer value */ -#ifndef NULL -#ifdef __cplusplus -#define NULL 0 -#else -#define NULL ((void *)0) -#endif -#endif - - - -#endif /* __CCPLATFORMDEFINE_H__*/ +#ifndef __CCPLATFORMDEFINE_H__ +#define __CCPLATFORMDEFINE_H__ + +#define CC_DLL + +#define CC_ASSERT(cond) \ +if (! (cond)) \ +{ \ + char content[100]; \ + sprintf(content, "%s function:%s line:%d", __FILE__, __FUNCTION__, __LINE__ - 3); \ + CCMessageBox(content, "Assert error"); \ +} + + +#define CC_UNUSED_PARAM(unusedparam) (void)unusedparam + +/* Define NULL pointer value */ +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + + + +#endif /* __CCPLATFORMDEFINE_H__*/ diff --git a/cocos2dx/platform/ios/CCPlatformDefine.h b/cocos2dx/platform/ios/CCPlatformDefine.h index 6530015eae..ab19688f60 100644 --- a/cocos2dx/platform/ios/CCPlatformDefine.h +++ b/cocos2dx/platform/ios/CCPlatformDefine.h @@ -1,28 +1,28 @@ -#ifndef __CCPLATFORMDEFINE_H__ -#define __CCPLATFORMDEFINE_H__ - -#define CC_DLL - -#define CC_ASSERT(cond) \ -if (! (cond)) \ -{ \ - char content[100]; \ - sprintf(content, "%s function:%s line:%d", __FILE__, __FUNCTION__, __LINE__ - 3); \ - CCMessageBox(content, "Assert error"); \ -} - - -#define CC_UNUSED_PARAM(unusedparam) (void)unusedparam - -/* Define NULL pointer value */ -#ifndef NULL -#ifdef __cplusplus -#define NULL 0 -#else -#define NULL ((void *)0) -#endif -#endif - - - -#endif /* __CCPLATFORMDEFINE_H__*/ +#ifndef __CCPLATFORMDEFINE_H__ +#define __CCPLATFORMDEFINE_H__ + +#define CC_DLL + +#define CC_ASSERT(cond) \ +if (! (cond)) \ +{ \ + char content[100]; \ + sprintf(content, "%s function:%s line:%d", __FILE__, __FUNCTION__, __LINE__ - 3); \ + CCMessageBox(content, "Assert error"); \ +} + + +#define CC_UNUSED_PARAM(unusedparam) (void)unusedparam + +/* Define NULL pointer value */ +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + + + +#endif /* __CCPLATFORMDEFINE_H__*/ diff --git a/cocos2dx/platform/win32/CCPlatformDefine.h b/cocos2dx/platform/win32/CCPlatformDefine.h index 472bb9f4df..7cd65d4ec2 100644 --- a/cocos2dx/platform/win32/CCPlatformDefine.h +++ b/cocos2dx/platform/win32/CCPlatformDefine.h @@ -1,26 +1,26 @@ -#ifndef __CCPLATFORMDEFINE_H__ -#define __CCPLATFORMDEFINE_H__ - - -#if defined(_USRDLL) - #define CC_DLL __declspec(dllexport) -#else /* use a DLL library */ - #define CC_DLL __declspec(dllimport) -#endif - -#include -#define CC_ASSERT(cond) assert(cond) -#define CC_UNUSED_PARAM(unusedparam) (void)unusedparam - -/* Define NULL pointer value */ -#ifndef NULL -#ifdef __cplusplus -#define NULL 0 -#else -#define NULL ((void *)0) -#endif -#endif - - - -#endif /* __CCPLATFORMDEFINE_H__*/ +#ifndef __CCPLATFORMDEFINE_H__ +#define __CCPLATFORMDEFINE_H__ + + +#if defined(_USRDLL) + #define CC_DLL __declspec(dllexport) +#else /* use a DLL library */ + #define CC_DLL __declspec(dllimport) +#endif + +#include +#define CC_ASSERT(cond) assert(cond) +#define CC_UNUSED_PARAM(unusedparam) (void)unusedparam + +/* Define NULL pointer value */ +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + + + +#endif /* __CCPLATFORMDEFINE_H__*/ diff --git a/tests/tests/MutiTouchTest/MutiTouchTest.cpp b/tests/tests/MutiTouchTest/MutiTouchTest.cpp index 910f1bb2b6..0e9199c544 100644 --- a/tests/tests/MutiTouchTest/MutiTouchTest.cpp +++ b/tests/tests/MutiTouchTest/MutiTouchTest.cpp @@ -1,129 +1,129 @@ -#include "MutiTouchTest.h" - - -static ccColor3B s_TouchColors[CC_MAX_TOUCHES] = { - ccYELLOW, - ccBLUE, - ccGREEN, - ccRED, - ccMAGENTA -}; - -class TouchPoint : public CCNode -{ -public: - TouchPoint() - { - setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor)); - } - - virtual void draw() - { - ccDrawColor4B(m_TouchColor.r, m_TouchColor.g, m_TouchColor.b, 255); - glLineWidth(10); - ccDrawLine( ccp(0, m_pTouchPoint.y), ccp(getContentSize().width, m_pTouchPoint.y) ); - ccDrawLine( ccp(m_pTouchPoint.x, 0), ccp(m_pTouchPoint.x, getContentSize().height) ); - glLineWidth(1); - ccPointSize(30); - ccDrawPoint(m_pTouchPoint); - } - - void setTouchPos(const CCPoint& pt) - { - m_pTouchPoint = pt; - } - - void setTouchColor(ccColor3B color) - { - m_TouchColor = color; - } - - static TouchPoint* touchPointWithParent(CCNode* pParent) - { - TouchPoint* pRet = new TouchPoint(); - pRet->setContentSize(pParent->getContentSize()); - pRet->setAnchorPoint(ccp(0.0f, 0.0f)); - pRet->autorelease(); - return pRet; - } - -private: - CCPoint m_pTouchPoint; - ccColor3B m_TouchColor; -}; - -bool MutiTouchTestLayer::init() -{ - if (CCLayer::init()) - { - setIsTouchEnabled(true); - return true; - } - return false; -} - -static CCDictionary s_dic; - -void MutiTouchTestLayer::registerWithTouchDispatcher(void) -{ - CCDirector::sharedDirector()->getTouchDispatcher()->addStandardDelegate(this, 0); -} - -void MutiTouchTestLayer::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent) -{ - CCSetIterator iter = pTouches->begin(); - for (; iter != pTouches->end(); iter++) - { - CCTouch* pTouch = (CCTouch*)(*iter); - TouchPoint* pTouchPoint = TouchPoint::touchPointWithParent(this); - CCPoint location = pTouch->locationInView(); - location = CCDirector::sharedDirector()->convertToGL(location); - - pTouchPoint->setTouchPos(location); - pTouchPoint->setTouchColor(s_TouchColors[pTouch->getID()]); - - addChild(pTouchPoint); - s_dic.setObject(pTouchPoint, pTouch->getID()); - } - - -} - -void MutiTouchTestLayer::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent) -{ - CCSetIterator iter = pTouches->begin(); - for (; iter != pTouches->end(); iter++) - { - CCTouch* pTouch = (CCTouch*)(*iter); - TouchPoint* pTP = (TouchPoint*)s_dic.objectForKey(pTouch->getID()); - CCPoint location = pTouch->locationInView(); - location = CCDirector::sharedDirector()->convertToGL(location); - pTP->setTouchPos(location); - } -} - -void MutiTouchTestLayer::ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent) -{ - CCSetIterator iter = pTouches->begin(); - for (; iter != pTouches->end(); iter++) - { - CCTouch* pTouch = (CCTouch*)(*iter); - TouchPoint* pTP = (TouchPoint*)s_dic.objectForKey(pTouch->getID()); - removeChild(pTP, true); - s_dic.removeObjectForKey(pTouch->getID()); - } -} - -void MutiTouchTestLayer::ccTouchesCancelled(CCSet *pTouches, CCEvent *pEvent) -{ - ccTouchesEnded(pTouches, pEvent); -} - -void MutiTouchTestScene::runThisTest() -{ - MutiTouchTestLayer* pLayer = MutiTouchTestLayer::node(); - - addChild(pLayer, 0); - - CCDirector::sharedDirector()->replaceScene(this); -} +#include "MutiTouchTest.h" + + +static ccColor3B s_TouchColors[CC_MAX_TOUCHES] = { + ccYELLOW, + ccBLUE, + ccGREEN, + ccRED, + ccMAGENTA +}; + +class TouchPoint : public CCNode +{ +public: + TouchPoint() + { + setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor)); + } + + virtual void draw() + { + ccDrawColor4B(m_TouchColor.r, m_TouchColor.g, m_TouchColor.b, 255); + glLineWidth(10); + ccDrawLine( ccp(0, m_pTouchPoint.y), ccp(getContentSize().width, m_pTouchPoint.y) ); + ccDrawLine( ccp(m_pTouchPoint.x, 0), ccp(m_pTouchPoint.x, getContentSize().height) ); + glLineWidth(1); + ccPointSize(30); + ccDrawPoint(m_pTouchPoint); + } + + void setTouchPos(const CCPoint& pt) + { + m_pTouchPoint = pt; + } + + void setTouchColor(ccColor3B color) + { + m_TouchColor = color; + } + + static TouchPoint* touchPointWithParent(CCNode* pParent) + { + TouchPoint* pRet = new TouchPoint(); + pRet->setContentSize(pParent->getContentSize()); + pRet->setAnchorPoint(ccp(0.0f, 0.0f)); + pRet->autorelease(); + return pRet; + } + +private: + CCPoint m_pTouchPoint; + ccColor3B m_TouchColor; +}; + +bool MutiTouchTestLayer::init() +{ + if (CCLayer::init()) + { + setIsTouchEnabled(true); + return true; + } + return false; +} + +static CCDictionary s_dic; + +void MutiTouchTestLayer::registerWithTouchDispatcher(void) +{ + CCDirector::sharedDirector()->getTouchDispatcher()->addStandardDelegate(this, 0); +} + +void MutiTouchTestLayer::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent) +{ + CCSetIterator iter = pTouches->begin(); + for (; iter != pTouches->end(); iter++) + { + CCTouch* pTouch = (CCTouch*)(*iter); + TouchPoint* pTouchPoint = TouchPoint::touchPointWithParent(this); + CCPoint location = pTouch->locationInView(); + location = CCDirector::sharedDirector()->convertToGL(location); + + pTouchPoint->setTouchPos(location); + pTouchPoint->setTouchColor(s_TouchColors[pTouch->getID()]); + + addChild(pTouchPoint); + s_dic.setObject(pTouchPoint, pTouch->getID()); + } + + +} + +void MutiTouchTestLayer::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent) +{ + CCSetIterator iter = pTouches->begin(); + for (; iter != pTouches->end(); iter++) + { + CCTouch* pTouch = (CCTouch*)(*iter); + TouchPoint* pTP = (TouchPoint*)s_dic.objectForKey(pTouch->getID()); + CCPoint location = pTouch->locationInView(); + location = CCDirector::sharedDirector()->convertToGL(location); + pTP->setTouchPos(location); + } +} + +void MutiTouchTestLayer::ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent) +{ + CCSetIterator iter = pTouches->begin(); + for (; iter != pTouches->end(); iter++) + { + CCTouch* pTouch = (CCTouch*)(*iter); + TouchPoint* pTP = (TouchPoint*)s_dic.objectForKey(pTouch->getID()); + removeChild(pTP, true); + s_dic.removeObjectForKey(pTouch->getID()); + } +} + +void MutiTouchTestLayer::ccTouchesCancelled(CCSet *pTouches, CCEvent *pEvent) +{ + ccTouchesEnded(pTouches, pEvent); +} + +void MutiTouchTestScene::runThisTest() +{ + MutiTouchTestLayer* pLayer = MutiTouchTestLayer::node(); + + addChild(pLayer, 0); + + CCDirector::sharedDirector()->replaceScene(this); +} diff --git a/tests/tests/MutiTouchTest/MutiTouchTest.h b/tests/tests/MutiTouchTest/MutiTouchTest.h index ff2f623b68..df8db6c149 100644 --- a/tests/tests/MutiTouchTest/MutiTouchTest.h +++ b/tests/tests/MutiTouchTest/MutiTouchTest.h @@ -1,26 +1,26 @@ -#ifndef __MUTITOUCHTEST_H__ -#define __MUTITOUCHTEST_H__ - -#include "../testBasic.h" - -class MutiTouchTestLayer : public CCLayer -{ -public: - bool init(); - - virtual void registerWithTouchDispatcher(void); - virtual void ccTouchesBegan(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent); - virtual void ccTouchesMoved(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent); - virtual void ccTouchesEnded(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent); - virtual void ccTouchesCancelled(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent); - - LAYER_NODE_FUNC(MutiTouchTestLayer) -}; - -class MutiTouchTestScene : public TestScene -{ - public: - virtual void runThisTest(); -}; - -#endif /* __MUTITOUCHTEST_H__ */ +#ifndef __MUTITOUCHTEST_H__ +#define __MUTITOUCHTEST_H__ + +#include "../testBasic.h" + +class MutiTouchTestLayer : public CCLayer +{ +public: + bool init(); + + virtual void registerWithTouchDispatcher(void); + virtual void ccTouchesBegan(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent); + virtual void ccTouchesMoved(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent); + virtual void ccTouchesEnded(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent); + virtual void ccTouchesCancelled(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent); + + LAYER_NODE_FUNC(MutiTouchTestLayer) +}; + +class MutiTouchTestScene : public TestScene +{ + public: + virtual void runThisTest(); +}; + +#endif /* __MUTITOUCHTEST_H__ */