From d4dbedca4d0e942d05745d6a785297973e12100c Mon Sep 17 00:00:00 2001 From: natural-law Date: Mon, 11 Apr 2011 11:24:10 +0800 Subject: [PATCH] fixed #451,remove the code of support mac platform. 1. Remove the EventDispatcher. 2. Refactor CCLayer, CCMenu and CCParticleSystemPoint. 3. Modify the project file of win32, wophone and android. --- cocos2dx/Android.mk | 9 +- cocos2dx/actions/CCActionTiledGrid.cpp | 2108 ++++++++--------- .../event_dispatcher/CCEventDispatcher.cpp | 740 ------ .../CCKeyboardEventDelegate.cpp | 91 - .../event_dispatcher/CCMouseEventDelegate.cpp | 91 - cocos2dx/include/CCEvent.h | 29 - cocos2dx/include/CCEventDispatcher.h | 132 -- cocos2dx/include/CCKeyboardEventDelegate.h | 79 - cocos2dx/include/CCLayer.h | 34 +- cocos2dx/include/CCMenu.h | 10 - cocos2dx/include/CCMouseEventDelegate.h | 151 -- cocos2dx/include/CCParticleSystemPoint.h | 54 +- .../CCLayer.cpp} | 44 - .../CCMenu.cpp} | 30 - .../CCParticleSystemPoint.cpp} | 0 .../platform/CCArchOptimalParticleSystem.h | 1 - cocos2dx/platform/CCGL.cpp | 5 - cocos2dx/platform/CCGL.h | 59 +- .../platform/CCParticleSystemPoint_mobile.h | 75 - .../platform/CCParticleSystemPoint_platform.h | 36 - cocos2dx/platform/CCPlatformConfig.h | 31 +- cocos2dx/platform/CCPlatformMacros.h | 8 +- .../mac/CCDirectorDisplayLinkMacWrapper.h | 44 - .../mac/CCDirectorDisplayLinkMacWrapper.mm | 141 -- cocos2dx/platform/mac/CCDirector_mac.mm | 923 -------- cocos2dx/platform/mac/CCEventDispatcher.h | 233 -- cocos2dx/platform/mac/CCEventDispatcher.m | 578 ----- cocos2dx/platform/mac/CCGrid_mac.cpp | 613 ----- cocos2dx/platform/mac/CCLayer_mac.cpp | 678 ------ cocos2dx/platform/mac/CCMenu_mac.cpp | 627 ----- cocos2dx/platform/mac/CCNS_mac.mm | 69 - cocos2dx/platform/mac/CCNode_mac.cpp | 1084 --------- .../mac/CCParticleSystemPoint_mac.cpp | 28 - .../platform/mac/CCParticleSystemPoint_mac.h | 37 - cocos2dx/platform/mac/CCTransition_mac.cpp | 1408 ----------- cocos2dx/platform/mac/MacGLView.h | 83 - cocos2dx/platform/mac/MacGLView.mm | 241 -- cocos2dx/proj.win32/cocos2d-win32.vcproj | 64 +- cocos2dx/proj.wophone/Makefile.ARM | 40 +- cocos2dx/proj.wophone/cocos2d-wophone.vcproj | 58 +- 40 files changed, 1163 insertions(+), 9603 deletions(-) delete mode 100644 cocos2dx/event_dispatcher/CCEventDispatcher.cpp delete mode 100644 cocos2dx/event_dispatcher/CCKeyboardEventDelegate.cpp delete mode 100644 cocos2dx/event_dispatcher/CCMouseEventDelegate.cpp delete mode 100644 cocos2dx/include/CCEvent.h delete mode 100644 cocos2dx/include/CCEventDispatcher.h delete mode 100644 cocos2dx/include/CCKeyboardEventDelegate.h delete mode 100644 cocos2dx/include/CCMouseEventDelegate.h rename cocos2dx/{platform/CCLayer_mobile.cpp => layers_scenes_transitions_nodes/CCLayer.cpp} (95%) rename cocos2dx/{platform/CCMenu_mobile.cpp => menu_nodes/CCMenu.cpp} (94%) rename cocos2dx/{platform/CCParticleSystemPoint_mobile.cpp => particle_nodes/CCParticleSystemPoint.cpp} (100%) delete mode 100644 cocos2dx/platform/CCParticleSystemPoint_mobile.h delete mode 100644 cocos2dx/platform/CCParticleSystemPoint_platform.h delete mode 100644 cocos2dx/platform/mac/CCDirectorDisplayLinkMacWrapper.h delete mode 100644 cocos2dx/platform/mac/CCDirectorDisplayLinkMacWrapper.mm delete mode 100644 cocos2dx/platform/mac/CCDirector_mac.mm delete mode 100644 cocos2dx/platform/mac/CCEventDispatcher.h delete mode 100644 cocos2dx/platform/mac/CCEventDispatcher.m delete mode 100644 cocos2dx/platform/mac/CCGrid_mac.cpp delete mode 100644 cocos2dx/platform/mac/CCLayer_mac.cpp delete mode 100644 cocos2dx/platform/mac/CCMenu_mac.cpp delete mode 100644 cocos2dx/platform/mac/CCNS_mac.mm delete mode 100644 cocos2dx/platform/mac/CCNode_mac.cpp delete mode 100644 cocos2dx/platform/mac/CCParticleSystemPoint_mac.cpp delete mode 100644 cocos2dx/platform/mac/CCParticleSystemPoint_mac.h delete mode 100644 cocos2dx/platform/mac/CCTransition_mac.cpp delete mode 100644 cocos2dx/platform/mac/MacGLView.h delete mode 100644 cocos2dx/platform/mac/MacGLView.mm diff --git a/cocos2dx/Android.mk b/cocos2dx/Android.mk index ded280b78f..7037db8e85 100644 --- a/cocos2dx/Android.mk +++ b/cocos2dx/Android.mk @@ -31,17 +31,16 @@ cocoa/CCSet.cpp \ cocoa/CCZone.cpp \ cocos2d.cpp \ effects/CCGrabber.cpp \ -event_dispatcher/CCEventDispatcher.cpp \ -event_dispatcher/CCKeyboardEventDelegate.cpp \ -event_dispatcher/CCMouseEventDelegate.cpp \ keypad_dispatcher/CCKeypadDelegate.cpp \ keypad_dispatcher/CCKeypadDispatcher.cpp \ label_nodes/CCLabelAtlas.cpp \ label_nodes/CCLabelBMFont.cpp \ label_nodes/CCLabelTTF.cpp \ +layers_scenes_transitions_nodes/CCLayer.cpp \ layers_scenes_transitions_nodes/CCScene.cpp \ layers_scenes_transitions_nodes/CCTransitionPageTurn.cpp \ layers_scenes_transitions_nodes/CCTransitionRadial.cpp \ +menu_nodes/CCMenu.cpp \ menu_nodes/CCMenuItem.cpp \ misc_nodes/CCMotionStreak.cpp \ misc_nodes/CCProgressTimer.cpp \ @@ -49,12 +48,11 @@ misc_nodes/CCRenderTexture.cpp \ misc_nodes/CCRibbon.cpp \ particle_nodes/CCParticleExamples.cpp \ particle_nodes/CCParticleSystem.cpp \ +particle_nodes/CCParticleSystemPoint.cpp \ particle_nodes/CCParticleSystemQuad.cpp \ platform/CCDirector_mobile.cpp \ platform/CCFileUtils.cpp \ platform/CCGrid_mobile.cpp \ -platform/CCLayer_mobile.cpp \ -platform/CCMenu_mobile.cpp \ platform/CCNode_mobile.cpp \ platform/CCGL.cpp \ platform/CCImage.cpp \ @@ -62,7 +60,6 @@ platform/CCStdC.cpp \ platform/CCSAXParser.cpp \ platform/CCThread.cpp \ platform/CCCommon.cpp \ -platform/CCParticleSystemPoint_mobile.cpp \ platform/CCTransition_mobile.cpp \ platform/platform.cpp \ platform/android/CCEGLView_android.cpp \ diff --git a/cocos2dx/actions/CCActionTiledGrid.cpp b/cocos2dx/actions/CCActionTiledGrid.cpp index dbd582d698..228435adfc 100644 --- a/cocos2dx/actions/CCActionTiledGrid.cpp +++ b/cocos2dx/actions/CCActionTiledGrid.cpp @@ -1,1054 +1,1054 @@ -/**************************************************************************** -Copyright (c) 2010-2011 cocos2d-x.org -Copyright (c) 2009 On-Core - -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 "CCActionTiledGrid.h" -#include "CCDirector.h" -#include "ccMacros.h" -#include "CCPointExtension.h" -#include "effects/CCGrid.h" - -#include - -namespace cocos2d -{ - struct Tile - { - CCPoint position; - CCPoint startPosition; - ccGridSize delta; - }; - - // implementation of ShakyTiles3D - - CCShakyTiles3D* CCShakyTiles3D::actionWithRange(int nRange, bool bShakeZ, cocos2d::ccGridSize gridSize, cocos2d::ccTime duration) - { - CCShakyTiles3D *pAction = new CCShakyTiles3D(); - - if (pAction) - { - if (pAction->initWithRange(nRange, bShakeZ, gridSize, duration)) - { - pAction->autorelease(); - } - else - { - CC_SAFE_RELEASE_NULL(pAction); - } - } - - return pAction; - } - - bool CCShakyTiles3D::initWithRange(int nRange, bool bShakeZ, cocos2d::ccGridSize gridSize, cocos2d::ccTime duration) - { - if (CCTiledGrid3DAction::initWithSize(gridSize, duration)) - { - m_nRandrange = nRange; - m_bShakeZ = bShakeZ; - - return true; - } - - return false; - } - - CCObject* CCShakyTiles3D::copyWithZone(cocos2d::CCZone *pZone) - { - CCZone* pNewZone = NULL; - CCShakyTiles3D* pCopy = NULL; - if(pZone && pZone->m_pCopyObject) - { - //in case of being called at sub class - pCopy = (CCShakyTiles3D*)(pZone->m_pCopyObject); - } - else - { - pCopy = new CCShakyTiles3D(); - pZone = pNewZone = new CCZone(pCopy); - } - - CCTiledGrid3DAction::copyWithZone(pZone); - - pCopy->initWithRange(m_nRandrange, m_bShakeZ, m_sGridSize, m_fDuration); - - CC_SAFE_DELETE(pNewZone); - return pCopy; - } - - void CCShakyTiles3D::update(cocos2d::ccTime time) - { - int i, j; - - for (i = 0; i < m_sGridSize.x; ++i) - { - for (j = 0; j < m_sGridSize.y; ++j) - { - ccQuad3 coords = originalTile(ccg(i, j)); - - // X - coords.bl.x += ( rand() % (m_nRandrange*2) ) - m_nRandrange; - coords.br.x += ( rand() % (m_nRandrange*2) ) - m_nRandrange; - coords.tl.x += ( rand() % (m_nRandrange*2) ) - m_nRandrange; - coords.tr.x += ( rand() % (m_nRandrange*2) ) - m_nRandrange; - - // Y - coords.bl.y += ( rand() % (m_nRandrange*2) ) - m_nRandrange; - coords.br.y += ( rand() % (m_nRandrange*2) ) - m_nRandrange; - coords.tl.y += ( rand() % (m_nRandrange*2) ) - m_nRandrange; - coords.tr.y += ( rand() % (m_nRandrange*2) ) - m_nRandrange; - - if (m_bShakeZ) - { - coords.bl.z += ( rand() % (m_nRandrange*2) ) - m_nRandrange; - coords.br.z += ( rand() % (m_nRandrange*2) ) - m_nRandrange; - coords.tl.z += ( rand() % (m_nRandrange*2) ) - m_nRandrange; - coords.tr.z += ( rand() % (m_nRandrange*2) ) - m_nRandrange; - } - - setTile(ccg(i, j), coords); - } - } - } - - // implementation of CCShatteredTiles3D - - CCShatteredTiles3D* CCShatteredTiles3D::actionWithRange(int nRange, bool bShatterZ, cocos2d::ccGridSize gridSize, cocos2d::ccTime duration) - { - CCShatteredTiles3D *pAction = new CCShatteredTiles3D(); - - if (pAction) - { - if (pAction->initWithRange(nRange, bShatterZ, gridSize, duration)) - { - pAction->autorelease(); - } - else - { - CC_SAFE_RELEASE_NULL(pAction); - } - } - - return pAction; - } - - bool CCShatteredTiles3D::initWithRange(int nRange, bool bShatterZ, cocos2d::ccGridSize gridSize, cocos2d::ccTime duration) - { - if (CCTiledGrid3DAction::initWithSize(gridSize, duration)) - { - m_bOnce = false; - m_nRandrange = nRange; - m_bShatterZ = bShatterZ; - - return true; - } - - return false; - } - - CCObject* CCShatteredTiles3D::copyWithZone(cocos2d::CCZone *pZone) - { - CCZone* pNewZone = NULL; - CCShatteredTiles3D* pCopy = NULL; - if(pZone && pZone->m_pCopyObject) - { - pCopy = (CCShatteredTiles3D*)(pZone->m_pCopyObject); - } - else - { - pCopy = new CCShatteredTiles3D(); - pZone = pNewZone = new CCZone(pCopy); - } - - //copy super class's member - CCTiledGrid3DAction::copyWithZone(pZone); - - pCopy->initWithRange(m_nRandrange, m_bShatterZ, m_sGridSize, m_fDuration); - - CC_SAFE_DELETE(pNewZone); - return pCopy; - } - - void CCShatteredTiles3D::update(cocos2d::ccTime time) - { - int i, j; - - if (m_bOnce == false) - { - for (i = 0; i < m_sGridSize.x; ++i) - { - for (j = 0; j < m_sGridSize.y; ++j) - { - ccQuad3 coords = originalTile(ccg(i ,j)); - - // X - coords.bl.x += ( rand() % (m_nRandrange*2) ) - m_nRandrange; - coords.br.x += ( rand() % (m_nRandrange*2) ) - m_nRandrange; - coords.tl.x += ( rand() % (m_nRandrange*2) ) - m_nRandrange; - coords.tr.x += ( rand() % (m_nRandrange*2) ) - m_nRandrange; - - // Y - coords.bl.y += ( rand() % (m_nRandrange*2) ) - m_nRandrange; - coords.br.y += ( rand() % (m_nRandrange*2) ) - m_nRandrange; - coords.tl.y += ( rand() % (m_nRandrange*2) ) - m_nRandrange; - coords.tr.y += ( rand() % (m_nRandrange*2) ) - m_nRandrange; - - if (m_bShatterZ) - { - coords.bl.z += ( rand() % (m_nRandrange*2) ) - m_nRandrange; - coords.br.z += ( rand() % (m_nRandrange*2) ) - m_nRandrange; - coords.tl.z += ( rand() % (m_nRandrange*2) ) - m_nRandrange; - coords.tr.z += ( rand() % (m_nRandrange*2) ) - m_nRandrange; - } - - setTile(ccg(i, j), coords); - } - } - - m_bOnce = true; - } - } - - // implementation of CCShuffleTiles - - CCShuffleTiles* CCShuffleTiles::actionWithSeed(int s, cocos2d::ccGridSize gridSize, cocos2d::ccTime duration) - { - CCShuffleTiles *pAction = new CCShuffleTiles(); - - if (pAction) - { - if (pAction->initWithSeed(s, gridSize, duration)) - { - pAction->autorelease(); - } - else - { - CC_SAFE_RELEASE_NULL(pAction); - } - } - - return pAction; - } - - bool CCShuffleTiles::initWithSeed(int s, cocos2d::ccGridSize gridSize, cocos2d::ccTime duration) - { - if (CCTiledGrid3DAction::initWithSize(gridSize, duration)) - { - m_nSeed = s; - m_pTilesOrder = NULL; - m_pTiles = NULL; - - return true; - } - - return false; - } - - CCObject* CCShuffleTiles::copyWithZone(cocos2d::CCZone *pZone) - { - CCZone* pNewZone = NULL; - CCShuffleTiles* pCopy = NULL; - if(pZone && pZone->m_pCopyObject) - { - pCopy = (CCShuffleTiles*)(pZone->m_pCopyObject); - } - else - { - pCopy = new CCShuffleTiles(); - pZone = pNewZone = new CCZone(pCopy); - } - - CCTiledGrid3DAction::copyWithZone(pZone); - - pCopy->initWithSeed(m_nSeed, m_sGridSize, m_fDuration); - - CC_SAFE_DELETE(pNewZone); - return pCopy; - } - - CCShuffleTiles::~CCShuffleTiles(void) - { - CC_SAFE_DELETE_ARRAY(m_pTilesOrder); - CC_SAFE_DELETE_ARRAY(m_pTiles); - } - - void CCShuffleTiles::shuffle(int *pArray, int nLen) - { - int i; - for( i = nLen - 1; i >= 0; i-- ) - { - int j = rand() % (i+1); - int v = pArray[i]; - pArray[i] = pArray[j]; - pArray[j] = v; - } - } - - ccGridSize CCShuffleTiles::getDelta(cocos2d::ccGridSize pos) - { - CCPoint pos2; - - int idx = pos.x * m_sGridSize.y + pos.y; - - pos2.x = (float)(m_pTilesOrder[idx] / (int)m_sGridSize.y); - pos2.y = (float)(m_pTilesOrder[idx] % (int)m_sGridSize.y); - - return ccg((int)(pos2.x - pos.x), (int)(pos2.y - pos.y)); - } - - void CCShuffleTiles::placeTile(ccGridSize pos, Tile *t) - { - ccQuad3 coords = originalTile(pos); - - CCPoint step = m_pTarget->getGrid()->getStep(); - coords.bl.x += (int)(t->position.x * step.x); - coords.bl.y += (int)(t->position.y * step.y); - - coords.br.x += (int)(t->position.x * step.x); - coords.br.y += (int)(t->position.y * step.y); - - coords.tl.x += (int)(t->position.x * step.x); - coords.tl.y += (int)(t->position.y * step.y); - - coords.tr.x += (int)(t->position.x * step.x); - coords.tr.y += (int)(t->position.y * step.y); - - setTile(pos, coords); - } - - void CCShuffleTiles::startWithTarget(CCNode *pTarget) - { - CCTiledGrid3DAction::startWithTarget(pTarget); - - if (m_nSeed != -1) - { - srand(m_nSeed); - } - - m_nTilesCount = m_sGridSize.x * m_sGridSize.y; - m_pTilesOrder = new int[m_nTilesCount]; - int i, j; - - for (i = 0; i < m_nTilesCount; ++i) - { - m_pTilesOrder[i] = i; - } - - shuffle(m_pTilesOrder, m_nTilesCount); - - m_pTiles = (struct Tile *)new Tile[m_nTilesCount]; - Tile *tileArray = (Tile*) m_pTiles; - - for (i = 0; i < m_sGridSize.x; ++i) - { - for (j = 0; j < m_sGridSize.y; ++j) - { - tileArray->position = ccp((float)i, (float)j); - tileArray->startPosition = ccp((float)i, (float)j); - tileArray->delta = getDelta(ccg(i, j)); - ++tileArray; - } - } - } - - void CCShuffleTiles::update(cocos2d::ccTime time) - { - int i, j; - - Tile *tileArray = (Tile*)m_pTiles; - - for (i = 0; i < m_sGridSize.x; ++i) - { - for (j = 0; j < m_sGridSize.y; ++j) - { - tileArray->position = ccpMult(ccp((float)tileArray->delta.x, (float)tileArray->delta.y), time); - placeTile(ccg(i, j), tileArray); - ++tileArray; - } - } - } - - // implementation of CCFadeOutTRTiles - - CCFadeOutTRTiles* CCFadeOutTRTiles::actionWithSize(cocos2d::ccGridSize gridSize, cocos2d::ccTime time) - { - CCFadeOutTRTiles *pAction = new CCFadeOutTRTiles(); - - if (pAction) - { - if (pAction->initWithSize(gridSize, time)) - { - pAction->autorelease(); - } - else - { - CC_SAFE_RELEASE_NULL(pAction); - } - } - - return pAction; - } - - float CCFadeOutTRTiles::testFunc(cocos2d::ccGridSize pos, cocos2d::ccTime time) - { - CCPoint n = ccpMult(ccp((float)m_sGridSize.x, (float)m_sGridSize.y), time); - if ((n.x + n.y) == 0.0f) - { - return 1.0f; - } - - return powf((pos.x + pos.y) / (n.x + n.y), 6); - } - - void CCFadeOutTRTiles::turnOnTile(cocos2d::ccGridSize pos) - { - setTile(pos, originalTile(pos)); - } - - void CCFadeOutTRTiles::turnOffTile(cocos2d::ccGridSize pos) - { - ccQuad3 coords; - memset(&coords, 0, sizeof(ccQuad3)); - setTile(pos, coords); - } - - void CCFadeOutTRTiles::transformTile(cocos2d::ccGridSize pos, float distance) - { - ccQuad3 coords = originalTile(pos); - CCPoint step = m_pTarget->getGrid()->getStep(); - - coords.bl.x += (step.x / 2) * (1.0f - distance); - coords.bl.y += (step.y / 2) * (1.0f - distance); - - coords.br.x -= (step.x / 2) * (1.0f - distance); - coords.br.y += (step.y / 2) * (1.0f - distance); - - coords.tl.x += (step.x / 2) * (1.0f - distance); - coords.tl.y -= (step.y / 2) * (1.0f - distance); - - coords.tr.x -= (step.x / 2) * (1.0f - distance); - coords.tr.y -= (step.y / 2) * (1.0f - distance); - - setTile(pos, coords); - } - - void CCFadeOutTRTiles::update(cocos2d::ccTime time) - { - int i, j; - - for (i = 0; i < m_sGridSize.x; ++i) - { - for (j = 0; j < m_sGridSize.y; ++j) - { - float distance = testFunc(ccg(i, j), time); - if ( distance == 0 ) - { - turnOffTile(ccg(i, j)); - } else - if (distance < 1) - { - transformTile(ccg(i, j), distance); - } - else - { - turnOnTile(ccg(i, j)); - } - } - } - } - - // implementation of CCFadeOutBLTiles - CCFadeOutBLTiles* CCFadeOutBLTiles::actionWithSize(cocos2d::ccGridSize gridSize, cocos2d::ccTime time) - { - CCFadeOutBLTiles *pAction = new CCFadeOutBLTiles(); - - if (pAction) - { - if (pAction->initWithSize(gridSize, time)) - { - pAction->autorelease(); - } - else - { - CC_SAFE_RELEASE_NULL(pAction); - } - } - - return pAction; - } - - float CCFadeOutBLTiles::testFunc(cocos2d::ccGridSize pos, cocos2d::ccTime time) - { - CCPoint n = ccpMult(ccp((float)m_sGridSize.x, (float)m_sGridSize.y), (1.0f - time)); - if ((pos.x + pos.y) == 0) - { - return 1.0f; - } - - return powf((n.x + n.y) / (pos.x + pos.y), 6); - } - - // implementation of CCFadeOutUpTiles - - CCFadeOutUpTiles* CCFadeOutUpTiles::actionWithSize(cocos2d::ccGridSize gridSize, cocos2d::ccTime time) - { - CCFadeOutUpTiles *pAction = new CCFadeOutUpTiles(); - - if (pAction) - { - if (pAction->initWithSize(gridSize, time)) - { - pAction->autorelease(); - } - else - { - CC_SAFE_RELEASE_NULL(pAction); - } - } - - return pAction; - } - - float CCFadeOutUpTiles::testFunc(cocos2d::ccGridSize pos, cocos2d::ccTime time) - { - CCPoint n = ccpMult(ccp((float)m_sGridSize.x, (float)m_sGridSize.y), time); - if (n.y == 0.0f) - { - return 1.0f; - } - - return powf(pos.y / n.y, 6); - } - - void CCFadeOutUpTiles::transformTile(cocos2d::ccGridSize pos, float distance) - { - ccQuad3 coords = originalTile(pos); - CCPoint step = m_pTarget->getGrid()->getStep(); - - coords.bl.y += (step.y / 2) * (1.0f - distance); - coords.br.y += (step.y / 2) * (1.0f - distance); - coords.tl.y -= (step.y / 2) * (1.0f - distance); - coords.tr.y -= (step.y / 2) * (1.0f - distance); - - setTile(pos, coords); - } - - // implementation of CCFadeOutDownTiles - CCFadeOutDownTiles* CCFadeOutDownTiles::actionWithSize(cocos2d::ccGridSize gridSize, cocos2d::ccTime time) - { - CCFadeOutDownTiles *pAction = new CCFadeOutDownTiles(); - - if (pAction) - { - if (pAction->initWithSize(gridSize, time)) - { - pAction->autorelease(); - } - else - { - CC_SAFE_RELEASE_NULL(pAction); - } - } - - return pAction; - } - - float CCFadeOutDownTiles::testFunc(cocos2d::ccGridSize pos, cocos2d::ccTime time) - { - CCPoint n = ccpMult(ccp((float)m_sGridSize.x, (float)m_sGridSize.y), (1.0f - time)); - if (pos.y == 0) - { - return 1.0f; - } - - return powf(n.y / pos.y, 6); - } - - // implementation of TurnOffTiles - CCTurnOffTiles* CCTurnOffTiles::actionWithSize(ccGridSize size, ccTime d) - { - CCTurnOffTiles* pAction = new CCTurnOffTiles(); - if (pAction->initWithSize(size, d)) - { - pAction->autorelease(); - } - else - { - CC_SAFE_RELEASE_NULL(pAction); - } - return pAction; - } - - CCTurnOffTiles* CCTurnOffTiles::actionWithSeed(int s, cocos2d::ccGridSize gridSize, cocos2d::ccTime duration) - { - CCTurnOffTiles *pAction = new CCTurnOffTiles(); - - if (pAction) - { - if (pAction->initWithSeed(s, gridSize, duration)) - { - pAction->autorelease(); - } - else - { - CC_SAFE_RELEASE_NULL(pAction); - } - } - - return pAction; - } - - bool CCTurnOffTiles::initWithSeed(int s, cocos2d::ccGridSize gridSize, cocos2d::ccTime duration) - { - if (CCTiledGrid3DAction::initWithSize(gridSize, duration)) - { - m_nSeed = s; - m_pTilesOrder = NULL; - - return true; - } - - return false; - } - - CCObject* CCTurnOffTiles::copyWithZone(cocos2d::CCZone *pZone) - { - CCZone* pNewZone = NULL; - CCTurnOffTiles* pCopy = NULL; - if(pZone && pZone->m_pCopyObject) - { - pCopy = (CCTurnOffTiles*)(pZone->m_pCopyObject); - } - else - { - pCopy = new CCTurnOffTiles(); - pZone = pNewZone = new CCZone(pCopy); - } - - CCTiledGrid3DAction::copyWithZone(pZone); - - pCopy->initWithSeed(m_nSeed, m_sGridSize, m_fDuration); - - CC_SAFE_DELETE(pNewZone); - return pCopy; - } - - CCTurnOffTiles::~CCTurnOffTiles(void) - { - CC_SAFE_DELETE_ARRAY(m_pTilesOrder); - } - - void CCTurnOffTiles::shuffle(int *pArray, int nLen) - { - int i; - for (i = nLen - 1; i >= 0; i--) - { - int j = rand() % (i+1); - int v = pArray[i]; - pArray[i] = pArray[j]; - pArray[j] = v; - } - } - - void CCTurnOffTiles::turnOnTile(cocos2d::ccGridSize pos) - { - setTile(pos, originalTile(pos)); - } - - void CCTurnOffTiles::turnOffTile(cocos2d::ccGridSize pos) - { - ccQuad3 coords; - - memset(&coords, 0, sizeof(ccQuad3)); - setTile(pos, coords); - } - - void CCTurnOffTiles::startWithTarget(CCNode *pTarget) - { - int i; - - CCTiledGrid3DAction::startWithTarget(pTarget); - - if (m_nSeed != -1) - { - srand(m_nSeed); - } - - m_nTilesCount = m_sGridSize.x * m_sGridSize.y; - m_pTilesOrder = new int[m_nTilesCount]; - - for ( i = 0; i < m_nTilesCount; ++i) - { - m_pTilesOrder[i] = i; - } - - shuffle(m_pTilesOrder, m_nTilesCount); - } - - void CCTurnOffTiles::update(cocos2d::ccTime time) - { - int i, l, t; - - l = (int)(time * (float)m_nTilesCount); - - for( i = 0; i < m_nTilesCount; i++ ) - { - t = m_pTilesOrder[i]; - ccGridSize tilePos = ccg( t / m_sGridSize.y, t % m_sGridSize.y ); - - if ( i < l ) - { - turnOffTile(tilePos); - } - else - { - turnOnTile(tilePos); - } - } - } - - // implementation of CCWavesTiles3D - - CCWavesTiles3D* CCWavesTiles3D::actionWithWaves(int wav, float amp, cocos2d::ccGridSize gridSize, cocos2d::ccTime duration) - { - CCWavesTiles3D *pAction = new CCWavesTiles3D(); - - if (pAction) - { - if (pAction->initWithWaves(wav, amp, gridSize, duration)) - { - pAction->autorelease(); - } - else - { - CC_SAFE_RELEASE_NULL(pAction); - } - } - - return pAction; - } - - bool CCWavesTiles3D::initWithWaves(int wav, float amp, cocos2d::ccGridSize gridSize, cocos2d::ccTime duration) - { - if (CCTiledGrid3DAction::initWithSize(gridSize, duration)) - { - m_nWaves = wav; - m_fAmplitude = amp; - m_fAmplitudeRate = 1.0f; - - return true; - } - - return false; - } - - CCObject* CCWavesTiles3D::copyWithZone(cocos2d::CCZone *pZone) - { - CCZone* pNewZone = NULL; - CCWavesTiles3D* pCopy = NULL; - if(pZone && pZone->m_pCopyObject) - { - pCopy = (CCWavesTiles3D*)(pZone->m_pCopyObject); - } - else - { - pCopy = new CCWavesTiles3D(); - pZone = pNewZone = new CCZone(pCopy); - } - - CCTiledGrid3DAction::copyWithZone(pZone); - - pCopy->initWithWaves(m_nWaves, m_fAmplitude, m_sGridSize, m_fDuration); - - CC_SAFE_DELETE(pNewZone); - return pCopy; - } - - void CCWavesTiles3D::update(cocos2d::ccTime time) - { - int i, j; - - for( i = 0; i < m_sGridSize.x; i++ ) - { - for( j = 0; j < m_sGridSize.y; j++ ) - { - ccQuad3 coords = originalTile(ccg(i, j)); - - coords.bl.z = (sinf(time * (CGFloat)M_PI *m_nWaves * 2 + - (coords.bl.y+coords.bl.x) * .01f) * m_fAmplitude * m_fAmplitudeRate ); - coords.br.z = coords.bl.z; - coords.tl.z = coords.bl.z; - coords.tr.z = coords.bl.z; - - setTile(ccg(i, j), coords); - } - } - } - - // implementation of CCJumpTiles3D - - CCJumpTiles3D* CCJumpTiles3D::actionWithJumps(int j, float amp, cocos2d::ccGridSize gridSize, cocos2d::ccTime duration) - { - CCJumpTiles3D *pAction = new CCJumpTiles3D(); - - if (pAction) - { - if (pAction->initWithJumps(j, amp, gridSize, duration)) - { - pAction->autorelease(); - } - else - { - CC_SAFE_RELEASE_NULL(pAction); - } - } - - return pAction; - } - - bool CCJumpTiles3D::initWithJumps(int j, float amp, cocos2d::ccGridSize gridSize, cocos2d::ccTime duration) - { - if (CCTiledGrid3DAction::initWithSize(gridSize, duration)) - { - m_nJumps = j; - m_fAmplitude = amp; - m_fAmplitudeRate = 1.0f; - - return true; - } - - return false; - } - - CCObject* CCJumpTiles3D::copyWithZone(cocos2d::CCZone *pZone) - { - CCZone* pNewZone = NULL; - CCJumpTiles3D* pCopy = NULL; - if(pZone && pZone->m_pCopyObject) - { - pCopy = (CCJumpTiles3D*)(pZone->m_pCopyObject); - } - else - { - pCopy = new CCJumpTiles3D(); - pZone = pNewZone = new CCZone(pCopy); - } - - CCTiledGrid3DAction::copyWithZone(pZone); - pCopy->initWithJumps(m_nJumps, m_fAmplitude, m_sGridSize, m_fDuration); - - CC_SAFE_DELETE(pNewZone); - return pCopy; - } - - void CCJumpTiles3D::update(cocos2d::ccTime time) - { - int i, j; - - float sinz = (sinf((CGFloat)M_PI * time * m_nJumps * 2) * m_fAmplitude * m_fAmplitudeRate ); - float sinz2 = (sinf((CGFloat)M_PI * (time * m_nJumps * 2 + 1)) * m_fAmplitude * m_fAmplitudeRate ); - - for( i = 0; i < m_sGridSize.x; i++ ) - { - for( j = 0; j < m_sGridSize.y; j++ ) - { - ccQuad3 coords = originalTile(ccg(i, j)); - - if ( ((i+j) % 2) == 0 ) - { - coords.bl.z += sinz; - coords.br.z += sinz; - coords.tl.z += sinz; - coords.tr.z += sinz; - } - else - { - coords.bl.z += sinz2; - coords.br.z += sinz2; - coords.tl.z += sinz2; - coords.tr.z += sinz2; - } - - setTile(ccg(i, j), coords); - } - } - } - - // implementation of CCSplitRows - - CCSplitRows* CCSplitRows::actionWithRows(int nRows, cocos2d::ccTime duration) - { - CCSplitRows *pAction = new CCSplitRows(); - - if (pAction) - { - if (pAction->initWithRows(nRows, duration)) - { - pAction->autorelease(); - } - else - { - CC_SAFE_RELEASE_NULL(pAction); - } - } - - return pAction; - } - - bool CCSplitRows::initWithRows(int nRows, cocos2d::ccTime duration) - { - m_nRows = nRows; - - return CCTiledGrid3DAction::initWithSize(ccg(1, nRows), duration); - } - - CCObject* CCSplitRows::copyWithZone(cocos2d::CCZone *pZone) - { - CCZone* pNewZone = NULL; - CCSplitRows* pCopy = NULL; - if(pZone && pZone->m_pCopyObject) - { - pCopy = (CCSplitRows*)(pZone->m_pCopyObject); - } - else - { - pCopy = new CCSplitRows(); - pZone = pNewZone = new CCZone(pCopy); - } - - CCTiledGrid3DAction::copyWithZone(pZone); - - pCopy->initWithRows(m_nRows, m_fDuration); - - CC_SAFE_DELETE(pNewZone); - return pCopy; - } - - void CCSplitRows::startWithTarget(CCNode *pTarget) - { - CCTiledGrid3DAction::startWithTarget(pTarget); - m_winSize = CCDirector::sharedDirector()->getWinSizeInPixels(); - } - - void CCSplitRows::update(cocos2d::ccTime time) - { - int j; - - for (j = 0; j < m_sGridSize.y; ++j) - { - ccQuad3 coords = originalTile(ccg(0, j)); - float direction = 1; - - if ( (j % 2 ) == 0 ) - { - direction = -1; - } - - coords.bl.x += direction * m_winSize.width * time; - coords.br.x += direction * m_winSize.width * time; - coords.tl.x += direction * m_winSize.width * time; - coords.tr.x += direction * m_winSize.width * time; - - setTile(ccg(0, j), coords); - } - } - - // implementation of CCSplitCols - - CCSplitCols* CCSplitCols::actionWithCols(int nCols, cocos2d::ccTime duration) - { - CCSplitCols *pAction = new CCSplitCols(); - - if (pAction) - { - if (pAction->initWithCols(nCols, duration)) - { - pAction->autorelease(); - } - else - { - CC_SAFE_RELEASE_NULL(pAction); - } - } - - return pAction; - } - - bool CCSplitCols::initWithCols(int nCols, cocos2d::ccTime duration) - { - m_nCols = nCols; - return CCTiledGrid3DAction::initWithSize(ccg(nCols, 1), duration); - } - - CCObject* CCSplitCols::copyWithZone(cocos2d::CCZone *pZone) - { - CCZone* pNewZone = NULL; - CCSplitCols* pCopy = NULL; - if(pZone && pZone->m_pCopyObject) - { - pCopy = (CCSplitCols*)(pZone->m_pCopyObject); - } - else - { - pCopy = new CCSplitCols(); - pZone = pNewZone = new CCZone(pCopy); - } - - CCTiledGrid3DAction::copyWithZone(pZone); - pCopy->initWithCols(m_nCols, m_fDuration); - - CC_SAFE_DELETE(pNewZone); - return pCopy; - } - - void CCSplitCols::startWithTarget(CCNode *pTarget) - { - CCTiledGrid3DAction::startWithTarget(pTarget); - m_winSize = CCDirector::sharedDirector()->getWinSizeInPixels(); - } - - void CCSplitCols::update(cocos2d::ccTime time) - { - int i; - - for (i = 0; i < m_sGridSize.x; ++i) - { - ccQuad3 coords = originalTile(ccg(i, 0)); - float direction = 1; - - if ( (i % 2 ) == 0 ) - { - direction = -1; - } - - coords.bl.y += direction * m_winSize.height * time; - coords.br.y += direction * m_winSize.height * time; - coords.tl.y += direction * m_winSize.height * time; - coords.tr.y += direction * m_winSize.height * time; - - setTile(ccg(i, 0), coords); - } - } - - -} // end of namespace cocos2d +/**************************************************************************** +Copyright (c) 20102011 cocos2d-x.org +Copyright (c) 2009 On-Core + +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 "CCActionTiledGrid.h" +#include "CCDirector.h" +#include "ccMacros.h" +#include "CCPointExtension.h" +#include "effects/CCGrid.h" + +#include + +namespace cocos2d +{ + struct Tile + { + CCPoint position; + CCPoint startPosition; + ccGridSize delta; + }; + + // implementation of ShakyTiles3D + + CCShakyTiles3D* CCShakyTiles3D::actionWithRange(int nRange, bool bShakeZ, cocos2d::ccGridSize gridSize, cocos2d::ccTime duration) + { + CCShakyTiles3D *pAction = new CCShakyTiles3D(); + + if (pAction) + { + if (pAction->initWithRange(nRange, bShakeZ, gridSize, duration)) + { + pAction->autorelease(); + } + else + { + CC_SAFE_RELEASE_NULL(pAction); + } + } + + return pAction; + } + + bool CCShakyTiles3D::initWithRange(int nRange, bool bShakeZ, cocos2d::ccGridSize gridSize, cocos2d::ccTime duration) + { + if (CCTiledGrid3DAction::initWithSize(gridSize, duration)) + { + m_nRandrange = nRange; + m_bShakeZ = bShakeZ; + + return true; + } + + return false; + } + + CCObject* CCShakyTiles3D::copyWithZone(cocos2d::CCZone *pZone) + { + CCZone* pNewZone = NULL; + CCShakyTiles3D* pCopy = NULL; + if(pZone && pZone->m_pCopyObject) + { + //in case of being called at sub class + pCopy = (CCShakyTiles3D*)(pZone->m_pCopyObject); + } + else + { + pCopy = new CCShakyTiles3D(); + pZone = pNewZone = new CCZone(pCopy); + } + + CCTiledGrid3DAction::copyWithZone(pZone); + + pCopy->initWithRange(m_nRandrange, m_bShakeZ, m_sGridSize, m_fDuration); + + CC_SAFE_DELETE(pNewZone); + return pCopy; + } + + void CCShakyTiles3D::update(cocos2d::ccTime time) + { + int i, j; + + for (i = 0; i < m_sGridSize.x; ++i) + { + for (j = 0; j < m_sGridSize.y; ++j) + { + ccQuad3 coords = originalTile(ccg(i, j)); + + // X + coords.bl.x += ( rand() % (m_nRandrange*2) ) - m_nRandrange; + coords.br.x += ( rand() % (m_nRandrange*2) ) - m_nRandrange; + coords.tl.x += ( rand() % (m_nRandrange*2) ) - m_nRandrange; + coords.tr.x += ( rand() % (m_nRandrange*2) ) - m_nRandrange; + + // Y + coords.bl.y += ( rand() % (m_nRandrange*2) ) - m_nRandrange; + coords.br.y += ( rand() % (m_nRandrange*2) ) - m_nRandrange; + coords.tl.y += ( rand() % (m_nRandrange*2) ) - m_nRandrange; + coords.tr.y += ( rand() % (m_nRandrange*2) ) - m_nRandrange; + + if (m_bShakeZ) + { + coords.bl.z += ( rand() % (m_nRandrange*2) ) - m_nRandrange; + coords.br.z += ( rand() % (m_nRandrange*2) ) - m_nRandrange; + coords.tl.z += ( rand() % (m_nRandrange*2) ) - m_nRandrange; + coords.tr.z += ( rand() % (m_nRandrange*2) ) - m_nRandrange; + } + + setTile(ccg(i, j), coords); + } + } + } + + // implementation of CCShatteredTiles3D + + CCShatteredTiles3D* CCShatteredTiles3D::actionWithRange(int nRange, bool bShatterZ, cocos2d::ccGridSize gridSize, cocos2d::ccTime duration) + { + CCShatteredTiles3D *pAction = new CCShatteredTiles3D(); + + if (pAction) + { + if (pAction->initWithRange(nRange, bShatterZ, gridSize, duration)) + { + pAction->autorelease(); + } + else + { + CC_SAFE_RELEASE_NULL(pAction); + } + } + + return pAction; + } + + bool CCShatteredTiles3D::initWithRange(int nRange, bool bShatterZ, cocos2d::ccGridSize gridSize, cocos2d::ccTime duration) + { + if (CCTiledGrid3DAction::initWithSize(gridSize, duration)) + { + m_bOnce = false; + m_nRandrange = nRange; + m_bShatterZ = bShatterZ; + + return true; + } + + return false; + } + + CCObject* CCShatteredTiles3D::copyWithZone(cocos2d::CCZone *pZone) + { + CCZone* pNewZone = NULL; + CCShatteredTiles3D* pCopy = NULL; + if(pZone && pZone->m_pCopyObject) + { + pCopy = (CCShatteredTiles3D*)(pZone->m_pCopyObject); + } + else + { + pCopy = new CCShatteredTiles3D(); + pZone = pNewZone = new CCZone(pCopy); + } + + //copy super class's member + CCTiledGrid3DAction::copyWithZone(pZone); + + pCopy->initWithRange(m_nRandrange, m_bShatterZ, m_sGridSize, m_fDuration); + + CC_SAFE_DELETE(pNewZone); + return pCopy; + } + + void CCShatteredTiles3D::update(cocos2d::ccTime time) + { + int i, j; + + if (m_bOnce == false) + { + for (i = 0; i < m_sGridSize.x; ++i) + { + for (j = 0; j < m_sGridSize.y; ++j) + { + ccQuad3 coords = originalTile(ccg(i ,j)); + + // X + coords.bl.x += ( rand() % (m_nRandrange*2) ) - m_nRandrange; + coords.br.x += ( rand() % (m_nRandrange*2) ) - m_nRandrange; + coords.tl.x += ( rand() % (m_nRandrange*2) ) - m_nRandrange; + coords.tr.x += ( rand() % (m_nRandrange*2) ) - m_nRandrange; + + // Y + coords.bl.y += ( rand() % (m_nRandrange*2) ) - m_nRandrange; + coords.br.y += ( rand() % (m_nRandrange*2) ) - m_nRandrange; + coords.tl.y += ( rand() % (m_nRandrange*2) ) - m_nRandrange; + coords.tr.y += ( rand() % (m_nRandrange*2) ) - m_nRandrange; + + if (m_bShatterZ) + { + coords.bl.z += ( rand() % (m_nRandrange*2) ) - m_nRandrange; + coords.br.z += ( rand() % (m_nRandrange*2) ) - m_nRandrange; + coords.tl.z += ( rand() % (m_nRandrange*2) ) - m_nRandrange; + coords.tr.z += ( rand() % (m_nRandrange*2) ) - m_nRandrange; + } + + setTile(ccg(i, j), coords); + } + } + + m_bOnce = true; + } + } + + // implementation of CCShuffleTiles + + CCShuffleTiles* CCShuffleTiles::actionWithSeed(int s, cocos2d::ccGridSize gridSize, cocos2d::ccTime duration) + { + CCShuffleTiles *pAction = new CCShuffleTiles(); + + if (pAction) + { + if (pAction->initWithSeed(s, gridSize, duration)) + { + pAction->autorelease(); + } + else + { + CC_SAFE_RELEASE_NULL(pAction); + } + } + + return pAction; + } + + bool CCShuffleTiles::initWithSeed(int s, cocos2d::ccGridSize gridSize, cocos2d::ccTime duration) + { + if (CCTiledGrid3DAction::initWithSize(gridSize, duration)) + { + m_nSeed = s; + m_pTilesOrder = NULL; + m_pTiles = NULL; + + return true; + } + + return false; + } + + CCObject* CCShuffleTiles::copyWithZone(cocos2d::CCZone *pZone) + { + CCZone* pNewZone = NULL; + CCShuffleTiles* pCopy = NULL; + if(pZone && pZone->m_pCopyObject) + { + pCopy = (CCShuffleTiles*)(pZone->m_pCopyObject); + } + else + { + pCopy = new CCShuffleTiles(); + pZone = pNewZone = new CCZone(pCopy); + } + + CCTiledGrid3DAction::copyWithZone(pZone); + + pCopy->initWithSeed(m_nSeed, m_sGridSize, m_fDuration); + + CC_SAFE_DELETE(pNewZone); + return pCopy; + } + + CCShuffleTiles::~CCShuffleTiles(void) + { + CC_SAFE_DELETE_ARRAY(m_pTilesOrder); + CC_SAFE_DELETE_ARRAY(m_pTiles); + } + + void CCShuffleTiles::shuffle(int *pArray, int nLen) + { + int i; + for( i = nLen - 1; i >= 0; i-- ) + { + int j = rand() % (i+1); + int v = pArray[i]; + pArray[i] = pArray[j]; + pArray[j] = v; + } + } + + ccGridSize CCShuffleTiles::getDelta(cocos2d::ccGridSize pos) + { + CCPoint pos2; + + int idx = pos.x * m_sGridSize.y + pos.y; + + pos2.x = (float)(m_pTilesOrder[idx] / (int)m_sGridSize.y); + pos2.y = (float)(m_pTilesOrder[idx] % (int)m_sGridSize.y); + + return ccg((int)(pos2.x - pos.x), (int)(pos2.y - pos.y)); + } + + void CCShuffleTiles::placeTile(ccGridSize pos, Tile *t) + { + ccQuad3 coords = originalTile(pos); + + CCPoint step = m_pTarget->getGrid()->getStep(); + coords.bl.x += (int)(t->position.x * step.x); + coords.bl.y += (int)(t->position.y * step.y); + + coords.br.x += (int)(t->position.x * step.x); + coords.br.y += (int)(t->position.y * step.y); + + coords.tl.x += (int)(t->position.x * step.x); + coords.tl.y += (int)(t->position.y * step.y); + + coords.tr.x += (int)(t->position.x * step.x); + coords.tr.y += (int)(t->position.y * step.y); + + setTile(pos, coords); + } + + void CCShuffleTiles::startWithTarget(CCNode *pTarget) + { + CCTiledGrid3DAction::startWithTarget(pTarget); + + if (m_nSeed != -1) + { + srand(m_nSeed); + } + + m_nTilesCount = m_sGridSize.x * m_sGridSize.y; + m_pTilesOrder = new int[m_nTilesCount]; + int i, j; + + for (i = 0; i < m_nTilesCount; ++i) + { + m_pTilesOrder[i] = i; + } + + shuffle(m_pTilesOrder, m_nTilesCount); + + m_pTiles = (struct Tile *)new Tile[m_nTilesCount]; + Tile *tileArray = (Tile*) m_pTiles; + + for (i = 0; i < m_sGridSize.x; ++i) + { + for (j = 0; j < m_sGridSize.y; ++j) + { + tileArray->position = ccp((float)i, (float)j); + tileArray->startPosition = ccp((float)i, (float)j); + tileArray->delta = getDelta(ccg(i, j)); + ++tileArray; + } + } + } + + void CCShuffleTiles::update(cocos2d::ccTime time) + { + int i, j; + + Tile *tileArray = (Tile*)m_pTiles; + + for (i = 0; i < m_sGridSize.x; ++i) + { + for (j = 0; j < m_sGridSize.y; ++j) + { + tileArray->position = ccpMult(ccp((float)tileArray->delta.x, (float)tileArray->delta.y), time); + placeTile(ccg(i, j), tileArray); + ++tileArray; + } + } + } + + // implementation of CCFadeOutTRTiles + + CCFadeOutTRTiles* CCFadeOutTRTiles::actionWithSize(cocos2d::ccGridSize gridSize, cocos2d::ccTime time) + { + CCFadeOutTRTiles *pAction = new CCFadeOutTRTiles(); + + if (pAction) + { + if (pAction->initWithSize(gridSize, time)) + { + pAction->autorelease(); + } + else + { + CC_SAFE_RELEASE_NULL(pAction); + } + } + + return pAction; + } + + float CCFadeOutTRTiles::testFunc(cocos2d::ccGridSize pos, cocos2d::ccTime time) + { + CCPoint n = ccpMult(ccp((float)m_sGridSize.x, (float)m_sGridSize.y), time); + if ((n.x + n.y) == 0.0f) + { + return 1.0f; + } + + return powf((pos.x + pos.y) / (n.x + n.y), 6); + } + + void CCFadeOutTRTiles::turnOnTile(cocos2d::ccGridSize pos) + { + setTile(pos, originalTile(pos)); + } + + void CCFadeOutTRTiles::turnOffTile(cocos2d::ccGridSize pos) + { + ccQuad3 coords; + memset(&coords, 0, sizeof(ccQuad3)); + setTile(pos, coords); + } + + void CCFadeOutTRTiles::transformTile(cocos2d::ccGridSize pos, float distance) + { + ccQuad3 coords = originalTile(pos); + CCPoint step = m_pTarget->getGrid()->getStep(); + + coords.bl.x += (step.x / 2) * (1.0f - distance); + coords.bl.y += (step.y / 2) * (1.0f - distance); + + coords.br.x -= (step.x / 2) * (1.0f - distance); + coords.br.y += (step.y / 2) * (1.0f - distance); + + coords.tl.x += (step.x / 2) * (1.0f - distance); + coords.tl.y -= (step.y / 2) * (1.0f - distance); + + coords.tr.x -= (step.x / 2) * (1.0f - distance); + coords.tr.y -= (step.y / 2) * (1.0f - distance); + + setTile(pos, coords); + } + + void CCFadeOutTRTiles::update(cocos2d::ccTime time) + { + int i, j; + + for (i = 0; i < m_sGridSize.x; ++i) + { + for (j = 0; j < m_sGridSize.y; ++j) + { + float distance = testFunc(ccg(i, j), time); + if ( distance == 0 ) + { + turnOffTile(ccg(i, j)); + } else + if (distance < 1) + { + transformTile(ccg(i, j), distance); + } + else + { + turnOnTile(ccg(i, j)); + } + } + } + } + + // implementation of CCFadeOutBLTiles + CCFadeOutBLTiles* CCFadeOutBLTiles::actionWithSize(cocos2d::ccGridSize gridSize, cocos2d::ccTime time) + { + CCFadeOutBLTiles *pAction = new CCFadeOutBLTiles(); + + if (pAction) + { + if (pAction->initWithSize(gridSize, time)) + { + pAction->autorelease(); + } + else + { + CC_SAFE_RELEASE_NULL(pAction); + } + } + + return pAction; + } + + float CCFadeOutBLTiles::testFunc(cocos2d::ccGridSize pos, cocos2d::ccTime time) + { + CCPoint n = ccpMult(ccp((float)m_sGridSize.x, (float)m_sGridSize.y), (1.0f - time)); + if ((pos.x + pos.y) == 0) + { + return 1.0f; + } + + return powf((n.x + n.y) / (pos.x + pos.y), 6); + } + + // implementation of CCFadeOutUpTiles + + CCFadeOutUpTiles* CCFadeOutUpTiles::actionWithSize(cocos2d::ccGridSize gridSize, cocos2d::ccTime time) + { + CCFadeOutUpTiles *pAction = new CCFadeOutUpTiles(); + + if (pAction) + { + if (pAction->initWithSize(gridSize, time)) + { + pAction->autorelease(); + } + else + { + CC_SAFE_RELEASE_NULL(pAction); + } + } + + return pAction; + } + + float CCFadeOutUpTiles::testFunc(cocos2d::ccGridSize pos, cocos2d::ccTime time) + { + CCPoint n = ccpMult(ccp((float)m_sGridSize.x, (float)m_sGridSize.y), time); + if (n.y == 0.0f) + { + return 1.0f; + } + + return powf(pos.y / n.y, 6); + } + + void CCFadeOutUpTiles::transformTile(cocos2d::ccGridSize pos, float distance) + { + ccQuad3 coords = originalTile(pos); + CCPoint step = m_pTarget->getGrid()->getStep(); + + coords.bl.y += (step.y / 2) * (1.0f - distance); + coords.br.y += (step.y / 2) * (1.0f - distance); + coords.tl.y -= (step.y / 2) * (1.0f - distance); + coords.tr.y -= (step.y / 2) * (1.0f - distance); + + setTile(pos, coords); + } + + // implementation of CCFadeOutDownTiles + CCFadeOutDownTiles* CCFadeOutDownTiles::actionWithSize(cocos2d::ccGridSize gridSize, cocos2d::ccTime time) + { + CCFadeOutDownTiles *pAction = new CCFadeOutDownTiles(); + + if (pAction) + { + if (pAction->initWithSize(gridSize, time)) + { + pAction->autorelease(); + } + else + { + CC_SAFE_RELEASE_NULL(pAction); + } + } + + return pAction; + } + + float CCFadeOutDownTiles::testFunc(cocos2d::ccGridSize pos, cocos2d::ccTime time) + { + CCPoint n = ccpMult(ccp((float)m_sGridSize.x, (float)m_sGridSize.y), (1.0f - time)); + if (pos.y == 0) + { + return 1.0f; + } + + return powf(n.y / pos.y, 6); + } + + // implementation of TurnOffTiles + CCTurnOffTiles* CCTurnOffTiles::actionWithSize(ccGridSize size, ccTime d) + { + CCTurnOffTiles* pAction = new CCTurnOffTiles(); + if (pAction->initWithSize(size, d)) + { + pAction->autorelease(); + } + else + { + CC_SAFE_RELEASE_NULL(pAction); + } + return pAction; + } + + CCTurnOffTiles* CCTurnOffTiles::actionWithSeed(int s, cocos2d::ccGridSize gridSize, cocos2d::ccTime duration) + { + CCTurnOffTiles *pAction = new CCTurnOffTiles(); + + if (pAction) + { + if (pAction->initWithSeed(s, gridSize, duration)) + { + pAction->autorelease(); + } + else + { + CC_SAFE_RELEASE_NULL(pAction); + } + } + + return pAction; + } + + bool CCTurnOffTiles::initWithSeed(int s, cocos2d::ccGridSize gridSize, cocos2d::ccTime duration) + { + if (CCTiledGrid3DAction::initWithSize(gridSize, duration)) + { + m_nSeed = s; + m_pTilesOrder = NULL; + + return true; + } + + return false; + } + + CCObject* CCTurnOffTiles::copyWithZone(cocos2d::CCZone *pZone) + { + CCZone* pNewZone = NULL; + CCTurnOffTiles* pCopy = NULL; + if(pZone && pZone->m_pCopyObject) + { + pCopy = (CCTurnOffTiles*)(pZone->m_pCopyObject); + } + else + { + pCopy = new CCTurnOffTiles(); + pZone = pNewZone = new CCZone(pCopy); + } + + CCTiledGrid3DAction::copyWithZone(pZone); + + pCopy->initWithSeed(m_nSeed, m_sGridSize, m_fDuration); + + CC_SAFE_DELETE(pNewZone); + return pCopy; + } + + CCTurnOffTiles::~CCTurnOffTiles(void) + { + CC_SAFE_DELETE_ARRAY(m_pTilesOrder); + } + + void CCTurnOffTiles::shuffle(int *pArray, int nLen) + { + int i; + for (i = nLen - 1; i >= 0; i--) + { + int j = rand() % (i+1); + int v = pArray[i]; + pArray[i] = pArray[j]; + pArray[j] = v; + } + } + + void CCTurnOffTiles::turnOnTile(cocos2d::ccGridSize pos) + { + setTile(pos, originalTile(pos)); + } + + void CCTurnOffTiles::turnOffTile(cocos2d::ccGridSize pos) + { + ccQuad3 coords; + + memset(&coords, 0, sizeof(ccQuad3)); + setTile(pos, coords); + } + + void CCTurnOffTiles::startWithTarget(CCNode *pTarget) + { + int i; + + CCTiledGrid3DAction::startWithTarget(pTarget); + + if (m_nSeed != -1) + { + srand(m_nSeed); + } + + m_nTilesCount = m_sGridSize.x * m_sGridSize.y; + m_pTilesOrder = new int[m_nTilesCount]; + + for ( i = 0; i < m_nTilesCount; ++i) + { + m_pTilesOrder[i] = i; + } + + shuffle(m_pTilesOrder, m_nTilesCount); + } + + void CCTurnOffTiles::update(cocos2d::ccTime time) + { + int i, l, t; + + l = (int)(time * (float)m_nTilesCount); + + for( i = 0; i < m_nTilesCount; i++ ) + { + t = m_pTilesOrder[i]; + ccGridSize tilePos = ccg( t / m_sGridSize.y, t % m_sGridSize.y ); + + if ( i < l ) + { + turnOffTile(tilePos); + } + else + { + turnOnTile(tilePos); + } + } + } + + // implementation of CCWavesTiles3D + + CCWavesTiles3D* CCWavesTiles3D::actionWithWaves(int wav, float amp, cocos2d::ccGridSize gridSize, cocos2d::ccTime duration) + { + CCWavesTiles3D *pAction = new CCWavesTiles3D(); + + if (pAction) + { + if (pAction->initWithWaves(wav, amp, gridSize, duration)) + { + pAction->autorelease(); + } + else + { + CC_SAFE_RELEASE_NULL(pAction); + } + } + + return pAction; + } + + bool CCWavesTiles3D::initWithWaves(int wav, float amp, cocos2d::ccGridSize gridSize, cocos2d::ccTime duration) + { + if (CCTiledGrid3DAction::initWithSize(gridSize, duration)) + { + m_nWaves = wav; + m_fAmplitude = amp; + m_fAmplitudeRate = 1.0f; + + return true; + } + + return false; + } + + CCObject* CCWavesTiles3D::copyWithZone(cocos2d::CCZone *pZone) + { + CCZone* pNewZone = NULL; + CCWavesTiles3D* pCopy = NULL; + if(pZone && pZone->m_pCopyObject) + { + pCopy = (CCWavesTiles3D*)(pZone->m_pCopyObject); + } + else + { + pCopy = new CCWavesTiles3D(); + pZone = pNewZone = new CCZone(pCopy); + } + + CCTiledGrid3DAction::copyWithZone(pZone); + + pCopy->initWithWaves(m_nWaves, m_fAmplitude, m_sGridSize, m_fDuration); + + CC_SAFE_DELETE(pNewZone); + return pCopy; + } + + void CCWavesTiles3D::update(cocos2d::ccTime time) + { + int i, j; + + for( i = 0; i < m_sGridSize.x; i++ ) + { + for( j = 0; j < m_sGridSize.y; j++ ) + { + ccQuad3 coords = originalTile(ccg(i, j)); + + coords.bl.z = (sinf(time * (CGFloat)M_PI *m_nWaves * 2 + + (coords.bl.y+coords.bl.x) * .01f) * m_fAmplitude * m_fAmplitudeRate ); + coords.br.z = coords.bl.z; + coords.tl.z = coords.bl.z; + coords.tr.z = coords.bl.z; + + setTile(ccg(i, j), coords); + } + } + } + + // implementation of CCJumpTiles3D + + CCJumpTiles3D* CCJumpTiles3D::actionWithJumps(int j, float amp, cocos2d::ccGridSize gridSize, cocos2d::ccTime duration) + { + CCJumpTiles3D *pAction = new CCJumpTiles3D(); + + if (pAction) + { + if (pAction->initWithJumps(j, amp, gridSize, duration)) + { + pAction->autorelease(); + } + else + { + CC_SAFE_RELEASE_NULL(pAction); + } + } + + return pAction; + } + + bool CCJumpTiles3D::initWithJumps(int j, float amp, cocos2d::ccGridSize gridSize, cocos2d::ccTime duration) + { + if (CCTiledGrid3DAction::initWithSize(gridSize, duration)) + { + m_nJumps = j; + m_fAmplitude = amp; + m_fAmplitudeRate = 1.0f; + + return true; + } + + return false; + } + + CCObject* CCJumpTiles3D::copyWithZone(cocos2d::CCZone *pZone) + { + CCZone* pNewZone = NULL; + CCJumpTiles3D* pCopy = NULL; + if(pZone && pZone->m_pCopyObject) + { + pCopy = (CCJumpTiles3D*)(pZone->m_pCopyObject); + } + else + { + pCopy = new CCJumpTiles3D(); + pZone = pNewZone = new CCZone(pCopy); + } + + CCTiledGrid3DAction::copyWithZone(pZone); + pCopy->initWithJumps(m_nJumps, m_fAmplitude, m_sGridSize, m_fDuration); + + CC_SAFE_DELETE(pNewZone); + return pCopy; + } + + void CCJumpTiles3D::update(cocos2d::ccTime time) + { + int i, j; + + float sinz = (sinf((CGFloat)M_PI * time * m_nJumps * 2) * m_fAmplitude * m_fAmplitudeRate ); + float sinz2 = (sinf((CGFloat)M_PI * (time * m_nJumps * 2 + 1)) * m_fAmplitude * m_fAmplitudeRate ); + + for( i = 0; i < m_sGridSize.x; i++ ) + { + for( j = 0; j < m_sGridSize.y; j++ ) + { + ccQuad3 coords = originalTile(ccg(i, j)); + + if ( ((i+j) % 2) == 0 ) + { + coords.bl.z += sinz; + coords.br.z += sinz; + coords.tl.z += sinz; + coords.tr.z += sinz; + } + else + { + coords.bl.z += sinz2; + coords.br.z += sinz2; + coords.tl.z += sinz2; + coords.tr.z += sinz2; + } + + setTile(ccg(i, j), coords); + } + } + } + + // implementation of CCSplitRows + + CCSplitRows* CCSplitRows::actionWithRows(int nRows, cocos2d::ccTime duration) + { + CCSplitRows *pAction = new CCSplitRows(); + + if (pAction) + { + if (pAction->initWithRows(nRows, duration)) + { + pAction->autorelease(); + } + else + { + CC_SAFE_RELEASE_NULL(pAction); + } + } + + return pAction; + } + + bool CCSplitRows::initWithRows(int nRows, cocos2d::ccTime duration) + { + m_nRows = nRows; + + return CCTiledGrid3DAction::initWithSize(ccg(1, nRows), duration); + } + + CCObject* CCSplitRows::copyWithZone(cocos2d::CCZone *pZone) + { + CCZone* pNewZone = NULL; + CCSplitRows* pCopy = NULL; + if(pZone && pZone->m_pCopyObject) + { + pCopy = (CCSplitRows*)(pZone->m_pCopyObject); + } + else + { + pCopy = new CCSplitRows(); + pZone = pNewZone = new CCZone(pCopy); + } + + CCTiledGrid3DAction::copyWithZone(pZone); + + pCopy->initWithRows(m_nRows, m_fDuration); + + CC_SAFE_DELETE(pNewZone); + return pCopy; + } + + void CCSplitRows::startWithTarget(CCNode *pTarget) + { + CCTiledGrid3DAction::startWithTarget(pTarget); + m_winSize = CCDirector::sharedDirector()->getWinSizeInPixels(); + } + + void CCSplitRows::update(cocos2d::ccTime time) + { + int j; + + for (j = 0; j < m_sGridSize.y; ++j) + { + ccQuad3 coords = originalTile(ccg(0, j)); + float direction = 1; + + if ( (j % 2 ) == 0 ) + { + direction = -1; + } + + coords.bl.x += direction * m_winSize.width * time; + coords.br.x += direction * m_winSize.width * time; + coords.tl.x += direction * m_winSize.width * time; + coords.tr.x += direction * m_winSize.width * time; + + setTile(ccg(0, j), coords); + } + } + + // implementation of CCSplitCols + + CCSplitCols* CCSplitCols::actionWithCols(int nCols, cocos2d::ccTime duration) + { + CCSplitCols *pAction = new CCSplitCols(); + + if (pAction) + { + if (pAction->initWithCols(nCols, duration)) + { + pAction->autorelease(); + } + else + { + CC_SAFE_RELEASE_NULL(pAction); + } + } + + return pAction; + } + + bool CCSplitCols::initWithCols(int nCols, cocos2d::ccTime duration) + { + m_nCols = nCols; + return CCTiledGrid3DAction::initWithSize(ccg(nCols, 1), duration); + } + + CCObject* CCSplitCols::copyWithZone(cocos2d::CCZone *pZone) + { + CCZone* pNewZone = NULL; + CCSplitCols* pCopy = NULL; + if(pZone && pZone->m_pCopyObject) + { + pCopy = (CCSplitCols*)(pZone->m_pCopyObject); + } + else + { + pCopy = new CCSplitCols(); + pZone = pNewZone = new CCZone(pCopy); + } + + CCTiledGrid3DAction::copyWithZone(pZone); + pCopy->initWithCols(m_nCols, m_fDuration); + + CC_SAFE_DELETE(pNewZone); + return pCopy; + } + + void CCSplitCols::startWithTarget(CCNode *pTarget) + { + CCTiledGrid3DAction::startWithTarget(pTarget); + m_winSize = CCDirector::sharedDirector()->getWinSizeInPixels(); + } + + void CCSplitCols::update(cocos2d::ccTime time) + { + int i; + + for (i = 0; i < m_sGridSize.x; ++i) + { + ccQuad3 coords = originalTile(ccg(i, 0)); + float direction = 1; + + if ( (i % 2 ) == 0 ) + { + direction = -1; + } + + coords.bl.y += direction * m_winSize.height * time; + coords.br.y += direction * m_winSize.height * time; + coords.tl.y += direction * m_winSize.height * time; + coords.tr.y += direction * m_winSize.height * time; + + setTile(ccg(i, 0), coords); + } + } + + +} // end of namespace cocos2d diff --git a/cocos2dx/event_dispatcher/CCEventDispatcher.cpp b/cocos2dx/event_dispatcher/CCEventDispatcher.cpp deleted file mode 100644 index d2869c2b64..0000000000 --- a/cocos2dx/event_dispatcher/CCEventDispatcher.cpp +++ /dev/null @@ -1,740 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010-2011 cocos2d-x.org -Copyright (c) 2010 Ricardo Quesada - -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 "ccMacros.h" -#include "CCEventDispatcher.h" -#include "../support/data_support/uthash.h" // hack: uthash needs to be imported before utlist to prevent warning -#include "../support/data_support/utlist.h" - -namespace cocos2d { - -static CCEventDispatcher *s_pEventDispatcher = NULL; - -typedef struct _listEntry -{ - struct _listEntry *prev; - struct _listEntry *next; - CCObject* pHandle; - int priority; -} tListEntry; - - -#if CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD - - #define QUEUE_EVENT_MAX 128 - struct _eventQueue { - SEL_EventHandler selector; - CCEvent *pEvent; - }; - - static struct _eventQueue eventQueue[QUEUE_EVENT_MAX]; - static int s_nEventQueueCount = 0; - -#endif // CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD - -CCEventDispatcher* CCEventDispatcher::sharedDispatcher(void) -{ - // synchronized ?? - if (s_pEventDispatcher == NULL) - { - s_pEventDispatcher = new CCEventDispatcher(); - s_pEventDispatcher->init(); - } - - return s_pEventDispatcher; -} - -bool CCEventDispatcher::init() -{ - m_bDispatchEvents = true; - - m_pKeyboardDelegates = NULL; - m_pMouseDelegates = NULL; - -#if CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD - s_nEventQueueCount = 0; -#endif - - return true; -} - -void CCEventDispatcher::addMouseDelegate(CCMouseEventDelegate* pDelegate, int priority) -{ - if (!pDelegate) - { - return; - } - - CCMouseEventHandle* pHandle = CCMouseEventHandle::handlerWithDelegate(pDelegate); - addDelegate(pHandle, priority, &m_pMouseDelegates); -} - -/** removes a mouse delegate */ -void CCEventDispatcher::removeMouseDelegate(CCMouseEventDelegate* pDelegate) -{ - if (!pDelegate) - { - return; - } - - tListEntry *entry, *tmp; - DL_FOREACH_SAFE(m_pMouseDelegates, entry, tmp ) - { - if (!(entry->pHandle)) - { - continue; - } - - CCMouseEventHandle* pHandle = (CCMouseEventHandle*) entry->pHandle; - if (pHandle->getDelegate() == pDelegate) - { - DL_DELETE(m_pMouseDelegates, entry ); - pHandle->release(); - free(entry); - break; - } - } -} - -/** Removes all mouse delegates, releasing all the delegates */ -void CCEventDispatcher::removeAllMouseDelegates() -{ - removeAllDelegatesFromList(&m_pMouseDelegates); -} - -void CCEventDispatcher::addKeyboardDelegate(CCKeyboardEventDelegate* pDelegate, int priority) -{ - if (!pDelegate) - { - return; - } - - CCKeyboardEventHandle* pHandle = CCKeyboardEventHandle::handlerWithDelegate(pDelegate); - addDelegate(pHandle, priority, &m_pKeyboardDelegates); -} - -/** removes a mouse delegate */ -void CCEventDispatcher::removeKeyboardDelegate(CCKeyboardEventDelegate* pDelegate) -{ - if (!pDelegate) - { - return; - } - - tListEntry *entry, *tmp; - DL_FOREACH_SAFE(m_pKeyboardDelegates, entry, tmp ) - { - if (!(entry->pHandle)) - { - continue; - } - - CCKeyboardEventHandle* pHandle = (CCKeyboardEventHandle*) entry->pHandle; - if (pHandle->getDelegate() == pDelegate) - { - DL_DELETE(m_pKeyboardDelegates, entry ); - pHandle->release(); - free(entry); - break; - } - } -} - -/** Removes all mouse delegates, releasing all the delegates */ -void CCEventDispatcher::removeAllKeyboardDelegates() -{ - removeAllDelegatesFromList(&m_pKeyboardDelegates); -} - -void CCEventDispatcher::addDelegate(CCObject* pHandle, int priority, _listEntry** pList) -{ - if (! pHandle) - { - return; - } - - tListEntry *listElement = (tListEntry*) malloc( sizeof(*listElement) ); - - pHandle->retain(); - listElement->pHandle = pHandle; - listElement->priority = priority; - listElement->next = listElement->prev = NULL; - - // empty list ? - if( ! *pList ) - { - DL_APPEND( *pList, listElement ); - - } - else - { - bool added = false; - - for( tListEntry *elem = *pList; elem ; elem = elem->next ) - { - if( priority < elem->priority ) - { - if( elem == *pList ) - { - DL_PREPEND(*pList, listElement); - } - else - { - listElement->next = elem; - listElement->prev = elem->prev; - - elem->prev->next = listElement; - elem->prev = listElement; - } - - added = true; - break; - } - } - - // Not added? priority has the higher value. Append it. - if( !added ) - { - DL_APPEND(*pList, listElement); - } - } -} - -void CCEventDispatcher::removeAllDelegatesFromList(_listEntry** pList) -{ - tListEntry *entry, *tmp; - - DL_FOREACH_SAFE( *pList, entry, tmp ) - { - DL_DELETE( *pList, entry ); - free(entry); - } -} - -bool CCEventDispatcher::getIsDispatchEvents() -{ - return m_bDispatchEvents; -} - -void CCEventDispatcher::setIsDispatchEvents(bool bDispatch) -{ - m_bDispatchEvents = bDispatch; -} - -// -// Mouse events -// - -// -// Left -// -void CCEventDispatcher::mouseDown(CCEvent *pEvent) -{ - if(m_bDispatchEvents) - { - tListEntry *entry, *tmp; - - DL_FOREACH_SAFE( m_pMouseDelegates, entry, tmp ) - { - CCMouseEventHandle* pHandle = (CCMouseEventHandle*) entry->pHandle; - if (!pHandle) - { - continue; - } - CCMouseEventDelegate* pDelegate = pHandle->getDelegate(); - if (!pDelegate) - { - continue; - } - - bool bSwallows = pDelegate->ccMouseDown(pEvent); - if(bSwallows) - break; - } - } -} - -void CCEventDispatcher::mouseMoved(CCEvent *pEvent) -{ - if(m_bDispatchEvents) - { - tListEntry *entry, *tmp; - - DL_FOREACH_SAFE( m_pMouseDelegates, entry, tmp ) - { - CCMouseEventHandle* pHandle = (CCMouseEventHandle*) entry->pHandle; - if (!pHandle) - { - continue; - } - CCMouseEventDelegate* pDelegate = pHandle->getDelegate(); - if (!pDelegate) - { - continue; - } - - bool bSwallows = pDelegate->ccMouseMoved(pEvent); - if(bSwallows) - break; - } - } -} - -void CCEventDispatcher::mouseDragged(CCEvent *pEvent) -{ - if(m_bDispatchEvents) - { - tListEntry *entry, *tmp; - - DL_FOREACH_SAFE( m_pMouseDelegates, entry, tmp ) - { - CCMouseEventHandle* pHandle = (CCMouseEventHandle*) entry->pHandle; - if (!pHandle) - { - continue; - } - CCMouseEventDelegate* pDelegate = pHandle->getDelegate(); - if (!pDelegate) - { - continue; - } - - bool bSwallows = pDelegate->ccMouseDragged(pEvent); - if(bSwallows) - break; - } - } -} - -void CCEventDispatcher::mouseUp(CCEvent *pEvent) -{ - if(m_bDispatchEvents) - { - tListEntry *entry, *tmp; - - DL_FOREACH_SAFE( m_pMouseDelegates, entry, tmp ) - { - CCMouseEventHandle* pHandle = (CCMouseEventHandle*) entry->pHandle; - if (!pHandle) - { - continue; - } - CCMouseEventDelegate* pDelegate = pHandle->getDelegate(); - if (!pDelegate) - { - continue; - } - - bool bSwallows = pDelegate->ccMouseUp(pEvent); - if(bSwallows) - break; - } - } -} - -// -// Mouse Right -// -void CCEventDispatcher::rightMouseDown(CCEvent *pEvent) -{ - if(m_bDispatchEvents) - { - tListEntry *entry, *tmp; - - DL_FOREACH_SAFE( m_pMouseDelegates, entry, tmp ) - { - CCMouseEventHandle* pHandle = (CCMouseEventHandle*) entry->pHandle; - if (!pHandle) - { - continue; - } - CCMouseEventDelegate* pDelegate = pHandle->getDelegate(); - if (!pDelegate) - { - continue; - } - - bool bSwallows = pDelegate->ccRightMouseDown(pEvent); - if(bSwallows) - break; - } - } -} - -void CCEventDispatcher::rightMouseDragged(CCEvent *pEvent) -{ - if(m_bDispatchEvents) - { - tListEntry *entry, *tmp; - - DL_FOREACH_SAFE( m_pMouseDelegates, entry, tmp ) - { - CCMouseEventHandle* pHandle = (CCMouseEventHandle*) entry->pHandle; - if (!pHandle) - { - continue; - } - CCMouseEventDelegate* pDelegate = pHandle->getDelegate(); - if (!pDelegate) - { - continue; - } - - bool bSwallows = pDelegate->ccRightMouseDragged(pEvent); - if(bSwallows) - break; - } - } -} - -void CCEventDispatcher::rightMouseUp(CCEvent * pEvent) -{ - if(m_bDispatchEvents) - { - tListEntry *entry, *tmp; - - DL_FOREACH_SAFE( m_pMouseDelegates, entry, tmp ) - { - CCMouseEventHandle* pHandle = (CCMouseEventHandle*) entry->pHandle; - if (!pHandle) - { - continue; - } - CCMouseEventDelegate* pDelegate = pHandle->getDelegate(); - if (!pDelegate) - { - continue; - } - - bool bSwallows = pDelegate->ccRightMouseUp(pEvent); - if(bSwallows) - break; - } - } -} - -// -// Mouse Other -// -void CCEventDispatcher::otherMouseDown(CCEvent *pEvent) -{ - if(m_bDispatchEvents) - { - tListEntry *entry, *tmp; - - DL_FOREACH_SAFE( m_pMouseDelegates, entry, tmp ) - { - CCMouseEventHandle* pHandle = (CCMouseEventHandle*) entry->pHandle; - if (!pHandle) - { - continue; - } - CCMouseEventDelegate* pDelegate = pHandle->getDelegate(); - if (!pDelegate) - { - continue; - } - - bool bSwallows = pDelegate->ccOtherMouseDown(pEvent); - if(bSwallows) - break; - } - } -} - -void CCEventDispatcher::otherMouseDragged(CCEvent *pEvent) -{ - if(m_bDispatchEvents) - { - tListEntry *entry, *tmp; - - DL_FOREACH_SAFE( m_pMouseDelegates, entry, tmp ) - { - CCMouseEventHandle* pHandle = (CCMouseEventHandle*) entry->pHandle; - if (!pHandle) - { - continue; - } - CCMouseEventDelegate* pDelegate = pHandle->getDelegate(); - if (!pDelegate) - { - continue; - } - - bool bSwallows = pDelegate->ccOtherMouseDragged(pEvent); - if(bSwallows) - break; - } - } -} - -void CCEventDispatcher::otherMouseUp(CCEvent *pEvent) -{ - if(m_bDispatchEvents) - { - tListEntry *entry, *tmp; - - DL_FOREACH_SAFE( m_pMouseDelegates, entry, tmp ) - { - CCMouseEventHandle* pHandle = (CCMouseEventHandle*) entry->pHandle; - if (!pHandle) - { - continue; - } - CCMouseEventDelegate* pDelegate = pHandle->getDelegate(); - if (!pDelegate) - { - continue; - } - - bool bSwallows = pDelegate->ccOtherMouseUp(pEvent); - if(bSwallows) - break; - } - } -} - -// -// Scroll Wheel -// -void CCEventDispatcher::scrollWheel(CCEvent *pEvent) -{ - if(m_bDispatchEvents) - { - tListEntry *entry, *tmp; - - DL_FOREACH_SAFE( m_pMouseDelegates, entry, tmp ) - { - CCMouseEventHandle* pHandle = (CCMouseEventHandle*) entry->pHandle; - if (!pHandle) - { - continue; - } - CCMouseEventDelegate* pDelegate = pHandle->getDelegate(); - if (!pDelegate) - { - continue; - } - - bool bSwallows = pDelegate->ccScrollWheel(pEvent); - if(bSwallows) - break; - } - } -} - -// -// Mouse enter / exit -void CCEventDispatcher::mouseExited(CCEvent *pEvent) -{ - if(m_bDispatchEvents) - { - tListEntry *entry, *tmp; - - DL_FOREACH_SAFE( m_pMouseDelegates, entry, tmp ) - { - CCMouseEventHandle* pHandle = (CCMouseEventHandle*) entry->pHandle; - if (!pHandle) - { - continue; - } - CCMouseEventDelegate* pDelegate = pHandle->getDelegate(); - if (!pDelegate) - { - continue; - } - pDelegate->ccMouseEntered(pEvent); - } - } -} - -void CCEventDispatcher::mouseEntered(CCEvent *pEvent) -{ - if(m_bDispatchEvents) - { - tListEntry *entry, *tmp; - - DL_FOREACH_SAFE( m_pMouseDelegates, entry, tmp ) - { - CCMouseEventHandle* pHandle = (CCMouseEventHandle*) entry->pHandle; - if (!pHandle) - { - continue; - } - CCMouseEventDelegate* pDelegate = pHandle->getDelegate(); - if (!pDelegate) - { - continue; - } - pDelegate->ccMouseExited(pEvent); - } - } -} - - -// Keyboard events -void CCEventDispatcher::keyDown(CCEvent *pEvent) -{ - if(m_bDispatchEvents) - { - tListEntry *entry, *tmp; - - DL_FOREACH_SAFE( m_pKeyboardDelegates, entry, tmp ) - { - CCKeyboardEventHandle* pHandle = (CCKeyboardEventHandle*) entry->pHandle; - if (!pHandle) - { - continue; - } - CCKeyboardEventDelegate* pDelegate = pHandle->getDelegate(); - if (!pDelegate) - { - continue; - } - bool bSwallows = pDelegate->ccKeyDown(pEvent); - if (bSwallows) - { - break; - } - } - } -} - -void CCEventDispatcher::keyUp(CCEvent *pEvent) -{ - if(m_bDispatchEvents) - { - tListEntry *entry, *tmp; - - DL_FOREACH_SAFE( m_pKeyboardDelegates, entry, tmp ) - { - CCKeyboardEventHandle* pHandle = (CCKeyboardEventHandle*) entry->pHandle; - if (!pHandle) - { - continue; - } - CCKeyboardEventDelegate* pDelegate = pHandle->getDelegate(); - if (!pDelegate) - { - continue; - } - bool bSwallows = pDelegate->ccKeyUp(pEvent); - if (bSwallows) - { - break; - } - } - } -} - -void CCEventDispatcher::flagsChanged(CCEvent *pEvent) -{ - if(m_bDispatchEvents) - { - tListEntry *entry, *tmp; - - DL_FOREACH_SAFE( m_pKeyboardDelegates, entry, tmp ) - { - CCKeyboardEventHandle* pHandle = (CCKeyboardEventHandle*) entry->pHandle; - if (!pHandle) - { - continue; - } - CCKeyboardEventDelegate* pDelegate = pHandle->getDelegate(); - if (!pDelegate) - { - continue; - } - bool bSwallows = pDelegate->ccFlagsChanged(pEvent); - if (bSwallows) - { - break; - } - } - } -} - -void CCEventDispatcher::touchesBeganWithEvent(CCEvent *pEvent) -{ - if (m_bDispatchEvents ) - { - CCLOG("Touch Events: Not supported yet"); - } -} - -void CCEventDispatcher::touchesMovedWithEvent(CCEvent *pEvent) -{ - if (m_bDispatchEvents ) - { - CCLOG("Touch Events: Not supported yet"); - } -} - -void CCEventDispatcher::touchesEndedWithEvent(CCEvent *pEvent) -{ - if (m_bDispatchEvents ) - { - CCLOG("Touch Events: Not supported yet"); - } -} - -void CCEventDispatcher::touchesCancelledWithEvent(CCEvent *pEvent) -{ - if (m_bDispatchEvents ) - { - CCLOG("Touch Events: Not supported yet"); - } -} - -#if CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD - -void CCEventDispatcher::queueEvent(CCEvent* pEvent, SEL_EventHandler selector) -{ - CCAssert( s_nEventQueueCount < QUEUE_EVENT_MAX, "CCEventDispatcher: recompile. Increment QUEUE_EVENT_MAX value"); - - eventQueue[s_nEventQueueCount].selector = selector; - eventQueue[s_nEventQueueCount].pEvent = (CCEvent*) (pEvent->copy()); - - s_nEventQueueCount++; -} - -void CCEventDispatcher::dispatchQueuedEvents() -{ - for( int i=0; i < s_nEventQueueCount; i++ ) - { - // SEL_EventHandler sel = eventQueue[i].selector; - CCEvent *pEvent = eventQueue[i].pEvent; - - - //[self performSelector:sel withObject:event]; // @todo - pEvent->release(); - } - - s_nEventQueueCount = 0; -} - -#endif // CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD - -} // namespace cocos2d diff --git a/cocos2dx/event_dispatcher/CCKeyboardEventDelegate.cpp b/cocos2dx/event_dispatcher/CCKeyboardEventDelegate.cpp deleted file mode 100644 index 0040e8fd51..0000000000 --- a/cocos2dx/event_dispatcher/CCKeyboardEventDelegate.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org - -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 "CCKeyboardEventDelegate.h" -#include "ccMacros.h" - -namespace cocos2d { - - //------------------------------------------------------------------ - // - // CCKeyboardEventHandle - // - //------------------------------------------------------------------ - CCKeyboardEventDelegate* CCKeyboardEventHandle::getDelegate() - { - return m_pDelegate; - } - - CCKeyboardEventHandle::~CCKeyboardEventHandle() - { - if (m_pDelegate) - { - m_pDelegate->KeyboardDestroy(); - } - } - - void CCKeyboardEventHandle::setDelegate(CCKeyboardEventDelegate *pDelegate) - { - if (pDelegate) - { - pDelegate->KeyboardKeep(); - } - - if (m_pDelegate) - { - m_pDelegate->KeyboardDestroy(); - } - m_pDelegate = pDelegate; - } - - bool CCKeyboardEventHandle::initWithDelegate(CCKeyboardEventDelegate *pDelegate) - { - CCAssert(pDelegate != NULL, "It's a wrong delegate!"); - - m_pDelegate = pDelegate; - pDelegate->KeyboardKeep(); - - return true; - } - - CCKeyboardEventHandle* CCKeyboardEventHandle::handlerWithDelegate(CCKeyboardEventDelegate *pDelegate) - { - CCKeyboardEventHandle* pHandler = new CCKeyboardEventHandle; - - if (pHandler) - { - if (pHandler->initWithDelegate(pDelegate)) - { - pHandler->autorelease(); - } - else - { - CC_SAFE_RELEASE_NULL(pHandler); - } - } - - return pHandler; - } - -} diff --git a/cocos2dx/event_dispatcher/CCMouseEventDelegate.cpp b/cocos2dx/event_dispatcher/CCMouseEventDelegate.cpp deleted file mode 100644 index bb1b9f7d8b..0000000000 --- a/cocos2dx/event_dispatcher/CCMouseEventDelegate.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org - -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 "CCMouseEventDelegate.h" -#include "ccMacros.h" - -namespace cocos2d { - - //------------------------------------------------------------------ - // - // CCMouseEventHandle - // - //------------------------------------------------------------------ - CCMouseEventDelegate* CCMouseEventHandle::getDelegate() - { - return m_pDelegate; - } - - CCMouseEventHandle::~CCMouseEventHandle() - { - if (m_pDelegate) - { - m_pDelegate->MouseDestroy(); - } - } - - void CCMouseEventHandle::setDelegate(CCMouseEventDelegate *pDelegate) - { - if (pDelegate) - { - pDelegate->MouseKeep(); - } - - if (m_pDelegate) - { - m_pDelegate->MouseDestroy(); - } - m_pDelegate = pDelegate; - } - - bool CCMouseEventHandle::initWithDelegate(CCMouseEventDelegate *pDelegate) - { - CCAssert(pDelegate != NULL, "It's a wrong delegate!"); - - m_pDelegate = pDelegate; - pDelegate->MouseKeep(); - - return true; - } - - CCMouseEventHandle* CCMouseEventHandle::handlerWithDelegate(CCMouseEventDelegate *pDelegate) - { - CCMouseEventHandle* pHandler = new CCMouseEventHandle; - - if (pHandler) - { - if (pHandler->initWithDelegate(pDelegate)) - { - pHandler->autorelease(); - } - else - { - CC_SAFE_RELEASE_NULL(pHandler); - } - } - - return pHandler; - } - -} diff --git a/cocos2dx/include/CCEvent.h b/cocos2dx/include/CCEvent.h deleted file mode 100644 index 1fb87b343c..0000000000 --- a/cocos2dx/include/CCEvent.h +++ /dev/null @@ -1,29 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org - -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. -****************************************************************************/ - -#ifndef __CCEvent_H__ -#define __CCEvent_H__ - - -#endif diff --git a/cocos2dx/include/CCEventDispatcher.h b/cocos2dx/include/CCEventDispatcher.h deleted file mode 100644 index eeb2026ec9..0000000000 --- a/cocos2dx/include/CCEventDispatcher.h +++ /dev/null @@ -1,132 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org - -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. -****************************************************************************/ - -#ifndef __CCEVENT_DISPATCHER_H__ -#define __CCEVENT_DISPATCHER_H__ - -#include "CCMouseEventDelegate.h" -#include "CCKeyboardEventDelegate.h" -#include "ccConfig.h" -#include "selector_protocol.h" - -namespace cocos2d { - -struct _listEntry; - -/** CCEventDispatcher - -This is object is responsible for dispatching the events: -- Mouse events -- Keyboard events -- Touch events - -Only available on Mac -*/ -class CCEventDispatcher : public CCObject -{ -public: - static CCEventDispatcher* sharedDispatcher(); - bool init(void); - - /** Adds a mouse delegate to the dispatcher's list. - Delegates with a lower priority value will be called before higher priority values. - All the events will be propgated to all the delegates, unless the one delegate returns YES. - - IMPORTANT: The delegate will be retained. - */ - void addMouseDelegate(CCMouseEventDelegate* pDelegate, int priority); - - /** removes a mouse delegate */ - void removeMouseDelegate(CCMouseEventDelegate* pDelegate); - - /** Removes all mouse delegates, releasing all the delegates */ - void removeAllMouseDelegates(); - - /** Adds a Keyboard delegate to the dispatcher's list. - Delegates with a lower priority value will be called before higher priority values. - All the events will be propgated to all the delegates, unless the one delegate returns YES. - - IMPORTANT: The delegate will be retained. - */ - void addKeyboardDelegate(CCKeyboardEventDelegate* pDelegate, int priority); - - /** removes a mouse delegate */ - void removeKeyboardDelegate(CCKeyboardEventDelegate* pDelegate); - - /** Removes all mouse delegates, releasing all the delegates */ - void removeAllKeyboardDelegates(); - - /** Mouse events */ - // left - void mouseDown(CCEvent *pEvent); - void mouseMoved(CCEvent *pEvent); - void mouseDragged(CCEvent *pEvent); - void mouseUp(CCEvent *pEvent); - - // right - void rightMouseDown(CCEvent *pEvent); - void rightMouseDragged(CCEvent *pEvent); - void rightMouseUp(CCEvent *pEvent); - - // other - void otherMouseDown(CCEvent *pEvent); - void otherMouseDragged(CCEvent *pEvent); - void otherMouseUp(CCEvent *pEvent); - - // scroll Wheel - void scrollWheel(CCEvent *pEvent); - - // Mouse enter / exit - void mouseExited(CCEvent *pEvent); - void mouseEntered(CCEvent *pEvent); - - /** keyboard events */ - void keyDown(CCEvent *pEvent); - void keyUp(CCEvent *pEvent); - void flagsChanged(CCEvent *pEvent); - - void touchesBeganWithEvent(CCEvent *pEvent); - void touchesMovedWithEvent(CCEvent *pEvent); - void touchesEndedWithEvent(CCEvent *pEvent); - void touchesCancelledWithEvent(CCEvent *pEvent); - -#if CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD - void dispatchQueuedEvents(); - void queueEvent(CCEvent* pEvent, SEL_EventHandler selector); -#endif - - CC_PROPERTY(bool, m_bDispatchEvents, IsDispatchEvents) - -protected: - void addDelegate(CCObject* pHandle, int priority, _listEntry** pList); - void removeAllDelegatesFromList(_listEntry** pList); - -protected: - struct _listEntry* m_pKeyboardDelegates; - struct _listEntry* m_pMouseDelegates; -}; - -} //namespace cocos2d - -#endif // __CCEVENT_DISPATCHER_H__ diff --git a/cocos2dx/include/CCKeyboardEventDelegate.h b/cocos2dx/include/CCKeyboardEventDelegate.h deleted file mode 100644 index 517c4da835..0000000000 --- a/cocos2dx/include/CCKeyboardEventDelegate.h +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org - -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. -****************************************************************************/ - -#ifndef __CCKEYBOARD_EVENT_DELEGATE_H__ -#define __CCKEYBOARD_EVENT_DELEGATE_H__ - -#include "CCTouch.h" -#include "CCObject.h" - -namespace cocos2d { - -class CC_DLL CCKeyboardEventDelegate -{ -public: - //! call the release() in child layer - virtual void KeyboardDestroy() {} - //! call the retain() in child layer - virtual void KeyboardKeep() {} - - /** called when the "keyUp" event is received. - Return YES to avoid propagating the event to other delegates. - */ - virtual bool ccKeyUp(CCEvent* pEvent) { return false; } - - /** called when the "keyDown" event is received. - Return YES to avoid propagating the event to other delegates. - */ - virtual bool ccKeyDown(CCEvent* pEvent) { return false; } - - /** called when the "flagsChanged" event is received. - Return YES to avoid propagating the event to other delegates. - */ - virtual bool ccFlagsChanged(CCEvent* pEvent) { return false; } -}; - -class CC_DLL CCKeyboardEventHandle : public CCObject -{ -public: - virtual ~CCKeyboardEventHandle(void); - - /** delegate */ - CCKeyboardEventDelegate* getDelegate(); - void setDelegate(CCKeyboardEventDelegate *pDelegate); - - /** initializes a CCKeyboardEventHandle with a delegate */ - virtual bool initWithDelegate(CCKeyboardEventDelegate *pDelegate); - -public: - /** allocates a CCKeyboardEventHandle with a delegate */ - static CCKeyboardEventHandle* handlerWithDelegate(CCKeyboardEventDelegate *pDelegate); - -protected: - CCKeyboardEventDelegate* m_pDelegate; -}; - -} - -#endif diff --git a/cocos2dx/include/CCLayer.h b/cocos2dx/include/CCLayer.h index 2b25a9a670..12f9feb1f0 100644 --- a/cocos2dx/include/CCLayer.h +++ b/cocos2dx/include/CCLayer.h @@ -31,8 +31,6 @@ THE SOFTWARE. #include "CCTouchDelegateProtocol.h" #include "CCAccelerometerDelegate.h" #include "CCKeypadDelegate.h" -#include "CCMouseEventDelegate.h" -#include "CCKeyboardEventDelegate.h" namespace cocos2d { @@ -45,7 +43,7 @@ All features from CCNode are valid, plus the following new features: - It can receive iPhone Touches - It can receive Accelerometer input */ -class CC_DLL CCLayer : public CCNode, public CCTouchDelegate, public CCAccelerometerDelegate, public CCKeypadDelegate, public CCKeyboardEventDelegate, public CCMouseEventDelegate +class CC_DLL CCLayer : public CCNode, public CCTouchDelegate, public CCAccelerometerDelegate, public CCKeypadDelegate { public: CCLayer(); @@ -67,12 +65,6 @@ public: virtual void KeypadDestroy(); virtual void KeypadKeep(); - virtual void KeyboardDestroy(void); - virtual void KeyboardKeep(void); - - virtual void MouseDestroy(); - virtual void MouseKeep(); - /** If isTouchEnabled, this method is called onEnter. Override it to change the way CCLayer receives touch events. ( Default: CCTouchDispatcher::sharedDispatcher()->addStandardDelegate(this,0); ) @@ -85,20 +77,6 @@ public: */ virtual void registerWithTouchDispatcher(void); - /** priority of the mouse event delegate. - Default 0. - Override this method to set another priority. - @since v0.99.5 - */ - virtual int mouseDelegatePriority() { return 0; } - - /** priority of the keyboard event delegate. - Default 0. - Override this method to set another priority. - @since v0.99.5 - */ - virtual int keyboardDelegatePriority() { return 0; } - /** whether or not it will receive Touch events. You can enable / disable touch events with this property. Only the touches of this node will be affected. This "method" is not propagated to it's children. @@ -110,16 +88,6 @@ public: @since v0.8.1 */ CC_PROPERTY(bool, m_bIsAccelerometerEnabled, IsAccelerometerEnabled) - /** whether or not it will receive Keyboard events - You can enable / disable Keyboard events with this property. - @since v0.99.5 - */ - CC_PROPERTY(bool, m_bIsKeyboardEnabled, IsKeyboardEnabled) - /** whether or not it will receive mouse events - You can enable / disable mouse events with this property. - @since v0.99.5 - */ - CC_PROPERTY(bool, m_bIsMouseEnabled, IsMouseEnabled) /** whether or not it will receive keypad events You can enable / disable accelerometer events with this property. it's new in cocos2d-x diff --git a/cocos2dx/include/CCMenu.h b/cocos2dx/include/CCMenu.h index 1c63cde01c..d689eea284 100644 --- a/cocos2dx/include/CCMenu.h +++ b/cocos2dx/include/CCMenu.h @@ -96,16 +96,6 @@ namespace cocos2d{ virtual void ccTouchCancelled(CCTouch *touch, CCEvent* event); virtual void ccTouchMoved(CCTouch* touch, CCEvent* event); - /** - @brief For PC event handle functions - @since v0.99.5 - */ - virtual int mouseDelegatePriority(); - virtual CCMenuItem* itemForMouseEvent(CCEvent * pEvent); - virtual bool ccMouseDown(CCEvent * pEvent); - virtual bool ccMouseDragged(CCEvent * pEvent); - virtual bool ccMouseUp(CCEvent * pEvent); - virtual void destroy(void); virtual void keep(void); diff --git a/cocos2dx/include/CCMouseEventDelegate.h b/cocos2dx/include/CCMouseEventDelegate.h deleted file mode 100644 index e1eedf2a46..0000000000 --- a/cocos2dx/include/CCMouseEventDelegate.h +++ /dev/null @@ -1,151 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org - -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. -****************************************************************************/ - -#ifndef __CCMOUSE_EVENT_DELEGATE_H__ -#define __CCMOUSE_EVENT_DELEGATE_H__ - -#include "CCTouch.h" -#include "CCObject.h" - -namespace cocos2d { - -class CC_DLL CCMouseEventDelegate -{ -public: - //! call the release() in child layer - virtual void MouseDestroy() {} - //! call the retain() in child layer - virtual void MouseKeep() {} - - // - // left - // - /** called when the "mouseDown" event is received. - Return YES to avoid propagating the event to other delegates. - */ - virtual bool ccMouseDown(CCEvent* pEvent) { return false; } - - /** called when the "mouseDragged" event is received. - Return YES to avoid propagating the event to other delegates. - */ - virtual bool ccMouseDragged(CCEvent* pEvent) { return false; } - - /** called when the "mouseMoved" event is received. - Return YES to avoid propagating the event to other delegates. - By default, "mouseMoved" is disabled. To enable it, send the "setAcceptsMouseMovedEvents:YES" message to the main window. - */ - virtual bool ccMouseMoved(CCEvent* pEvent) { return false; } - - /** called when the "mouseUp" event is received. - Return YES to avoid propagating the event to other delegates. - */ - virtual bool ccMouseUp(CCEvent* pEvent) { return false; } - - - // - // right - // - - /** called when the "rightMouseDown" event is received. - Return YES to avoid propagating the event to other delegates. - */ - virtual bool ccRightMouseDown(CCEvent* pEvent) { return false; } - - /** called when the "rightMouseDragged" event is received. - Return YES to avoid propagating the event to other delegates. - */ - virtual bool ccRightMouseDragged(CCEvent* pEvent) { return false; } - - /** called when the "rightMouseUp" event is received. - Return YES to avoid propagating the event to other delegates. - */ - virtual bool ccRightMouseUp(CCEvent* pEvent) { return false; } - - // - // other - // - - /** called when the "otherMouseDown" event is received. - Return YES to avoid propagating the event to other delegates. - */ - virtual bool ccOtherMouseDown(CCEvent* pEvent) { return false; } - - /** called when the "otherMouseDragged" event is received. - Return YES to avoid propagating the event to other delegates. - */ - virtual bool ccOtherMouseDragged(CCEvent* pEvent) { return false; } - - /** called when the "otherMouseUp" event is received. - Return YES to avoid propagating the event to other delegates. - */ - virtual bool ccOtherMouseUp(CCEvent* pEvent) { return false; } - - // - // scroll wheel - // - - /** called when the "scrollWheel" event is received. - Return YES to avoid propagating the event to other delegates. - */ - virtual bool ccScrollWheel(CCEvent *pEvent) { return false; } - - - // - // enter / exit - // - - /** called when the "mouseEntered" event is received. - Return YES to avoid propagating the event to other delegates. - */ - virtual void ccMouseEntered(CCEvent *pEvent) {} - - /** called when the "mouseExited" event is received. - Return YES to avoid propagating the event to other delegates. - */ - virtual void ccMouseExited(CCEvent *pEvent) {} -}; - -class CC_DLL CCMouseEventHandle : public CCObject -{ -public: - virtual ~CCMouseEventHandle(void); - - /** delegate */ - CCMouseEventDelegate* getDelegate(); - void setDelegate(CCMouseEventDelegate *pDelegate); - - /** initializes a CCMouseEventHandle with a delegate */ - virtual bool initWithDelegate(CCMouseEventDelegate *pDelegate); - -public: - /** allocates a CCMouseEventHandle with a delegate */ - static CCMouseEventHandle* handlerWithDelegate(CCMouseEventDelegate *pDelegate); - -protected: - CCMouseEventDelegate* m_pDelegate; -}; - -} //namespace cocos2d - -#endif // __CCMOUSE_EVENT_DELEGATE_H__ diff --git a/cocos2dx/include/CCParticleSystemPoint.h b/cocos2dx/include/CCParticleSystemPoint.h index 5519ea1f11..9006a38b55 100644 --- a/cocos2dx/include/CCParticleSystemPoint.h +++ b/cocos2dx/include/CCParticleSystemPoint.h @@ -22,9 +22,55 @@ 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. ****************************************************************************/ -#ifndef __CC_PARTICLE_SYSTEM_POINT_H__ -#define __CC_PARTICLE_SYSTEM_POINT_H__ +#ifndef __CC_PARTICLE_SYSTEM_POINT_MOBILE_H__ +#define __CC_PARTICLE_SYSTEM_POINT_MOBILE_H__ -#include "platform/CCParticleSystemPoint_platform.h" +/*#include "Availability.h"*/ +#include "CCParticleSystem.h" -#endif //__CC_PARTICLE_SYSTEM_POINT_H__ +namespace cocos2d { + +#define CC_MAX_PARTICLE_SIZE 64 + +/** @brief CCParticleSystemPoint is a subclass of CCParticleSystem +Attributes of a Particle System: +* All the attributes of Particle System + +Features: +* consumes small memory: uses 1 vertex (x,y) per particle, no need to assign tex coordinates +* size can't be bigger than 64 +* the system can't be scaled since the particles are rendered using GL_POINT_SPRITE + +Limitations: +* On 3rd gen iPhone devices and iPads, this node performs MUCH slower than CCParticleSystemQuad. +*/ +class CC_DLL CCParticleSystemPoint : public CCParticleSystem +{ +public: + CCParticleSystemPoint() + :m_pVertices(NULL) + {} + virtual ~CCParticleSystemPoint(); + // super methods + virtual bool initWithTotalParticles(int numberOfParticles); + virtual void updateQuadWithParticle(tCCParticle* particle, CCPoint newPosition); + virtual void postStep(); + virtual void draw(); + virtual void setStartSpin(float var); + virtual void setStartSpinVar(float var); + virtual void setEndSpin(float var); + virtual void setEndSpinVar(float var); + virtual void setStartSize(float var); + virtual void setEndSize(float var); +protected: + //! Array of (x,y,size) + ccPointSprite *m_pVertices; + //! vertices buffer id +# if CC_USES_VBO + GLuint m_uVerticesID; +#endif +}; + +}// namespace cocos2d + +#endif //__CC_PARTICLE_SYSTEM_POINT_MOBILE_H__ diff --git a/cocos2dx/platform/CCLayer_mobile.cpp b/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp similarity index 95% rename from cocos2dx/platform/CCLayer_mobile.cpp rename to cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp index e2a1811c31..3437735041 100644 --- a/cocos2dx/platform/CCLayer_mobile.cpp +++ b/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp @@ -37,8 +37,6 @@ CCLayer::CCLayer() :m_bIsTouchEnabled(false) ,m_bIsAccelerometerEnabled(false) ,m_bIsKeypadEnabled(false) -,m_bIsMouseEnabled(false) -,m_bIsKeyboardEnabled(false) { m_eTouchDelegateType = ccTouchDeletateAllBit; m_tAnchorPoint = ccp(0.5f, 0.5f); @@ -115,47 +113,6 @@ void CCLayer::KeypadKeep() this->retain(); } -void CCLayer::KeyboardDestroy(void) -{ - this->release(); -} - -void CCLayer::KeyboardKeep(void) -{ - this->retain(); -} - -void CCLayer::MouseDestroy() -{ - this->release(); -} - -void CCLayer::MouseKeep() -{ - this->retain(); -} - - -bool CCLayer::getIsMouseEnabled() -{ - return m_bIsMouseEnabled; -} - -void CCLayer::setIsMouseEnabled(bool enabled) -{ - CCLOG("cocos2d: CCLayer: unsupportted!"); -} - -bool CCLayer::getIsKeyboardEnabled() -{ - return m_bIsKeyboardEnabled; -} - -void CCLayer::setIsKeyboardEnabled(bool enabled) -{ - CCLOG("cocos2d: CCLayer: unsupportted!"); -} - /// isTouchEnabled getter bool CCLayer::getIsTouchEnabled() { @@ -234,7 +191,6 @@ void CCLayer::setIsKeypadEnabled(bool enabled) } } - /// Callbacks void CCLayer::onEnter() { diff --git a/cocos2dx/platform/CCMenu_mobile.cpp b/cocos2dx/menu_nodes/CCMenu.cpp similarity index 94% rename from cocos2dx/platform/CCMenu_mobile.cpp rename to cocos2dx/menu_nodes/CCMenu.cpp index e60d932dc7..db152c5f69 100644 --- a/cocos2dx/platform/CCMenu_mobile.cpp +++ b/cocos2dx/menu_nodes/CCMenu.cpp @@ -199,36 +199,6 @@ namespace cocos2d{ } } - int CCMenu::mouseDelegatePriority() - { - CCLOG("cocos2d: CCMenu: unsupported"); - return -1;/** @todo upto-0.99.5 use NSIntegerMin+1 instead*/ - } - - CCMenuItem* CCMenu::itemForMouseEvent(CCEvent * pEvent) - { - CCLOG("cocos2d: CCMenu: unsupported"); - return NULL; - } - - bool CCMenu::ccMouseUp(CCEvent * pEvent) - { - CCLOG("cocos2d: CCMenu: unsupported"); - return false; - } - - bool CCMenu::ccMouseDown(CCEvent * pEvent) - { - CCLOG("cocos2d: CCMenu: unsupported"); - return false; - } - - bool CCMenu::ccMouseDragged(CCEvent * pEvent) - { - CCLOG("cocos2d: CCMenu: unsupported"); - return false; - } - void CCMenu::destroy(void) { release(); diff --git a/cocos2dx/platform/CCParticleSystemPoint_mobile.cpp b/cocos2dx/particle_nodes/CCParticleSystemPoint.cpp similarity index 100% rename from cocos2dx/platform/CCParticleSystemPoint_mobile.cpp rename to cocos2dx/particle_nodes/CCParticleSystemPoint.cpp diff --git a/cocos2dx/platform/CCArchOptimalParticleSystem.h b/cocos2dx/platform/CCArchOptimalParticleSystem.h index c7a626532d..bf60e97752 100644 --- a/cocos2dx/platform/CCArchOptimalParticleSystem.h +++ b/cocos2dx/platform/CCArchOptimalParticleSystem.h @@ -30,7 +30,6 @@ // ARMv7, Mac or Simulator use "Quad" particle #if defined(__ARM_NEON__) || \ (CC_TARGET_PLATFORM == CC_PLATFORM_AIRPLAY) || \ - (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || \ (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || \ (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || \ (CC_TARGET_PLATFORM == CC_PLATFORM_WOPHONE) || \ diff --git a/cocos2dx/platform/CCGL.cpp b/cocos2dx/platform/CCGL.cpp index b50eaf176d..85145e935e 100644 --- a/cocos2dx/platform/CCGL.cpp +++ b/cocos2dx/platform/CCGL.cpp @@ -23,9 +23,6 @@ THE SOFTWARE. ****************************************************************************/ #include "CCGL.h" - -#if defined(CC_PLATFORM_MOBILE) - #include "CCStdC.h" NS_CC_BEGIN; @@ -129,5 +126,3 @@ void gluLookAt(float fEyeX, float fEyeY, float fEyeZ, } NS_CC_END; - -#endif // CC_PLATFORM_MOBILE diff --git a/cocos2dx/platform/CCGL.h b/cocos2dx/platform/CCGL.h index ada9697502..2352994a6e 100644 --- a/cocos2dx/platform/CCGL.h +++ b/cocos2dx/platform/CCGL.h @@ -31,43 +31,21 @@ THE SOFTWARE. #include "CCEGLView.h" -// iOS -#if defined(CC_PLATFORM_MOBILE) - #define CC_GLVIEW cocos2d::CCEGLView - #define ccglOrtho glOrthof - #define ccglClearDepth glClearDepthf - #define ccglGenerateMipmap glGenerateMipmapOES - #define ccglGenFramebuffers glGenFramebuffersOES - #define ccglBindFramebuffer glBindFramebufferOES - #define ccglFramebufferTexture2D glFramebufferTexture2DOES - #define ccglDeleteFramebuffers glDeleteFramebuffersOES - #define ccglCheckFramebufferStatus glCheckFramebufferStatusOES - #define ccglTranslate glTranslatef +#define CC_GLVIEW cocos2d::CCEGLView +#define ccglOrtho glOrthof +#define ccglClearDepth glClearDepthf +#define ccglGenerateMipmap glGenerateMipmapOES +#define ccglGenFramebuffers glGenFramebuffersOES +#define ccglBindFramebuffer glBindFramebufferOES +#define ccglFramebufferTexture2D glFramebufferTexture2DOES +#define ccglDeleteFramebuffers glDeleteFramebuffersOES +#define ccglCheckFramebufferStatus glCheckFramebufferStatusOES +#define ccglTranslate glTranslatef - #define CC_GL_FRAMEBUFFER GL_FRAMEBUFFER_OES - #define CC_GL_FRAMEBUFFER_BINDING GL_FRAMEBUFFER_BINDING_OES - #define CC_GL_COLOR_ATTACHMENT0 GL_COLOR_ATTACHMENT0_OES - #define CC_GL_FRAMEBUFFER_COMPLETE GL_FRAMEBUFFER_COMPLETE_OES - -// Mac -#elif defined(CC_PLATFORM_PC) - #define CC_GLVIEW MacGLView - #define ccglOrtho glOrtho - #define ccglClearDepth glClearDepth - #define ccglGenerateMipmap glGenerateMipmap - #define ccglGenFramebuffers glGenFramebuffers - #define ccglBindFramebuffer glBindFramebuffer - #define ccglFramebufferTexture2D glFramebufferTexture2D - #define ccglDeleteFramebuffers glDeleteFramebuffers - #define ccglCheckFramebufferStatus glCheckFramebufferStatus - #define ccglTranslate glTranslated - - #define CC_GL_FRAMEBUFFER GL_FRAMEBUFFER - #define CC_GL_FRAMEBUFFER_BINDING GL_FRAMEBUFFER_BINDING - #define CC_GL_COLOR_ATTACHMENT0 GL_COLOR_ATTACHMENT0 - #define CC_GL_FRAMEBUFFER_COMPLETE GL_FRAMEBUFFER_COMPLETE - -#endif +#define CC_GL_FRAMEBUFFER GL_FRAMEBUFFER_OES +#define CC_GL_FRAMEBUFFER_BINDING GL_FRAMEBUFFER_BINDING_OES +#define CC_GL_COLOR_ATTACHMENT0 GL_COLOR_ATTACHMENT0_OES +#define CC_GL_FRAMEBUFFER_COMPLETE GL_FRAMEBUFFER_COMPLETE_OES #include "CCCommon.h" @@ -76,11 +54,6 @@ THE SOFTWARE. #include "OpenGLES/ES1/glext.h" #endif -#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) -#include -#include -#endif - #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) #include #include @@ -100,8 +73,6 @@ THE SOFTWARE. #include #endif -#if defined(CC_PLATFORM_MOBILE) - NS_CC_BEGIN; /* @@ -118,6 +89,4 @@ void CC_DLL gluPerspective(GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat NS_CC_END; -#endif - #endif // __PLATFOMR_CCGL_H__ diff --git a/cocos2dx/platform/CCParticleSystemPoint_mobile.h b/cocos2dx/platform/CCParticleSystemPoint_mobile.h deleted file mode 100644 index 98d8dd3beb..0000000000 --- a/cocos2dx/platform/CCParticleSystemPoint_mobile.h +++ /dev/null @@ -1,75 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org - -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. -****************************************************************************/ -#ifndef __CC_PARTICLE_SYSTEM_POINT_MOBILE_H__ -#define __CC_PARTICLE_SYSTEM_POINT_MOBILE_H__ - -/*#include "Availability.h"*/ -#include "CCParticleSystem.h" - -namespace cocos2d { - -#define CC_MAX_PARTICLE_SIZE 64 - -/** @brief CCParticleSystemPoint is a subclass of CCParticleSystem -Attributes of a Particle System: -* All the attributes of Particle System - -Features: -* consumes small memory: uses 1 vertex (x,y) per particle, no need to assign tex coordinates -* size can't be bigger than 64 -* the system can't be scaled since the particles are rendered using GL_POINT_SPRITE - -Limitations: -* On 3rd gen iPhone devices and iPads, this node performs MUCH slower than CCParticleSystemQuad. -*/ -class CC_DLL CCParticleSystemPoint : public CCParticleSystem -{ -public: - CCParticleSystemPoint() - :m_pVertices(NULL) - {} - virtual ~CCParticleSystemPoint(); - // super methods - virtual bool initWithTotalParticles(int numberOfParticles); - virtual void updateQuadWithParticle(tCCParticle* particle, CCPoint newPosition); - virtual void postStep(); - virtual void draw(); - virtual void setStartSpin(float var); - virtual void setStartSpinVar(float var); - virtual void setEndSpin(float var); - virtual void setEndSpinVar(float var); - virtual void setStartSize(float var); - virtual void setEndSize(float var); -protected: - //! Array of (x,y,size) - ccPointSprite *m_pVertices; - //! vertices buffer id -# if CC_USES_VBO - GLuint m_uVerticesID; -#endif -}; - -}// namespace cocos2d - -#endif //__CC_PARTICLE_SYSTEM_POINT_MOBILE_H__ diff --git a/cocos2dx/platform/CCParticleSystemPoint_platform.h b/cocos2dx/platform/CCParticleSystemPoint_platform.h deleted file mode 100644 index b8d69cd356..0000000000 --- a/cocos2dx/platform/CCParticleSystemPoint_platform.h +++ /dev/null @@ -1,36 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org - -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. -****************************************************************************/ -#ifndef __CC_PARTICLE_SYSTEM_POINT_PLATFORM_H__ -#define __CC_PARTICLE_SYSTEM_POINT_PLATFORM_H__ - -#include "CCPlatformConfig.h" - -#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) -#error -//#include "mac/CCParticleSystemPoint_mac.h" -#else -#include "CCParticleSystemPoint_mobile.h" -#endif - -#endif //__CC_PARTICLE_SYSTEM_POINT_PLATFORM_H__ diff --git a/cocos2dx/platform/CCPlatformConfig.h b/cocos2dx/platform/CCPlatformConfig.h index ef65ba89a5..f13a62c77a 100644 --- a/cocos2dx/platform/CCPlatformConfig.h +++ b/cocos2dx/platform/CCPlatformConfig.h @@ -40,11 +40,10 @@ There are config below: // define supported target platform macro which CC uses. #define CC_PLATFORM_UNKNOWN 0 #define CC_PLATFORM_IOS 1 -#define CC_PLATFORM_MAC 2 -#define CC_PLATFORM_ANDROID 3 -#define CC_PLATFORM_WOPHONE 4 -#define CC_PLATFORM_WIN32 5 -#define CC_PLATFORM_AIRPLAY 6 +#define CC_PLATFORM_ANDROID 2 +#define CC_PLATFORM_WOPHONE 3 +#define CC_PLATFORM_WIN32 4 +#define CC_PLATFORM_AIRPLAY 5 // Determine tartet platform by compile environment macro. #define CC_TARGET_PLATFORM CC_PLATFORM_UNKNOWN @@ -57,12 +56,6 @@ There are config below: #define CC_SUPPORT_UNICODE 0 #endif -// mac -#if ! CC_TARGET_PLATFORM && defined(TARGET_OS_MAC) - #undef CC_TARGET_PLATFORM - #define CC_TARGET_PLATFORM CC_PLATFORM_MAC -#endif - // android #if ! CC_TARGET_PLATFORM && defined(ANDROID) #undef CC_TARGET_PLATFORM @@ -102,11 +95,6 @@ There are config below: #define CC_TARGET_PLATFORM CC_PLATFORM_IOS #endif -#if defined(CC_UNDER_MAC) - #undef CC_TARGET_PLATFORM - #define CC_TARGET_PLATFORM CC_PLATFORM_MAC -#endif - #if defined(CC_UNDER_ANDROID) #undef CC_TARGET_PLATFORM #define CC_TARGET_PLATFORM CC_PLATFORM_ANDROID @@ -153,13 +141,6 @@ There are config below: #error "Can not recognize the target platform, compling under a unsupported platform?" #endif -// distinguish mobile platforms and pc platforms -#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) - #define CC_PLATFORM_PC -#else - #define CC_PLATFORM_MOBILE -#endif - // cocos2d-x havn't support multi-thread yet #undef CC_SUPPORT_MULTITHREAD #define CC_SUPPORT_MULTITHREAD 0 @@ -173,9 +154,5 @@ There are config below: #endif // CC_PLATFORM_WIN32 -#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) -#error cofnig -#endif // CC_PLATFORM_MAC - #endif // __CC_PLATFORM_CONFIG_H__ diff --git a/cocos2dx/platform/CCPlatformMacros.h b/cocos2dx/platform/CCPlatformMacros.h index 3b11eb44d7..eaf61e208f 100644 --- a/cocos2dx/platform/CCPlatformMacros.h +++ b/cocos2dx/platform/CCPlatformMacros.h @@ -30,12 +30,8 @@ #include "ccConfig.h" #include "CCPlatformConfig.h" -#if defined(CC_PLATFORM_MOBILE) - #define MacGLView void - #define NSWindow void -#elif defined(CC_PLATFORM_PC) - #include "platform/MacGLView.h" -#endif +#define MacGLView void +#define NSWindow void /** @def CC_ENABLE_CACHE_TEXTTURE_DATA Enable it if you want to cache the texture data. diff --git a/cocos2dx/platform/mac/CCDirectorDisplayLinkMacWrapper.h b/cocos2dx/platform/mac/CCDirectorDisplayLinkMacWrapper.h deleted file mode 100644 index 3ced9abd9d..0000000000 --- a/cocos2dx/platform/mac/CCDirectorDisplayLinkMacWrapper.h +++ /dev/null @@ -1,44 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org - -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. -****************************************************************************/ - -#ifndef __PLATFORM_MAC_CCDIRECTOR_DISPLAYLINK_MAC_WRAPPER -#define __PLATFORM_MAC_CCDIRECTOR_DISPLAYLINK_MAC_WRAPPER - -#import - -@interface CCDirectorDisplayLinkMacWrapper -{ - CVDisplayLinkRef displayLink; - NSThread *runningThread_; -} - -@property(nonatomic, readonly)NSThread *runningThread_; - -+(CCDirectorDisplayLinkMacWrapper*)sharedDisplayLinkMacWrapper; --(void)startAnimation; --(void)stopAnimation; - -@end - -#endif // __PLATFORM_MAC_CCDIRECTOR_DISPLAYLINK_MAC_WRAPPER diff --git a/cocos2dx/platform/mac/CCDirectorDisplayLinkMacWrapper.mm b/cocos2dx/platform/mac/CCDirectorDisplayLinkMacWrapper.mm deleted file mode 100644 index 629667e6e3..0000000000 --- a/cocos2dx/platform/mac/CCDirectorDisplayLinkMacWrapper.mm +++ /dev/null @@ -1,141 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org - -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. -****************************************************************************/ -#import "CCDirectorDisplayLinkMacWrapper.h" -#import "ccConfig.h" - -@implementation CCDirectorDisplayLinkMacWrapper - -static CCDirectorDisplayLinkMacWrapper* sharedDisplayLinkMacWrapper; - -@synthesize runningThread = runningThread_; - -+(CCDirectorDisplayLinkMacWrapper*)sharedDisplayLinkMacWrapper -{ - if (! sharedDisplayLinkMacWrapper) - { - sharedDiplayLinkMacWrapper = [CCDirectorDisplayLinkMacWrapper new]; - } - - return sharedDiplayLinkMacWrapper; -} - -- (void) init -{ - runningThread_ = nil; - displayLink = nil; -} - -- (CVReturn) getFrameForTime:(const CVTimeStamp*)outputTime -{ -#if CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD - if( ! runningThread_ ) - runningThread_ = [NSThread currentThread]; - - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - [self drawScene]; - [[CCEventDispatcher sharedDispatcher] dispatchQueuedEvents]; - - [[NSRunLoop currentRunLoop] run]; - - [pool release]; - -#else - [self performSelector:@selector(drawScene) onThread:runningThread_ withObject:nil waitUntilDone:YES]; -#endif - - return kCVReturnSuccess; -} - -// This is the renderer output callback function -static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeStamp* now, const CVTimeStamp* outputTime, CVOptionFlags flagsIn, CVOptionFlags* flagsOut, void* displayLinkContext) -{ - CVReturn result = [(CCDirectorDisplayLinkMacWrapper*)displayLinkContext getFrameForTime:outputTime]; - return result; -} - -- (void) startAnimation -{ -#if ! CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD - runningThread_ = [[NSThread alloc] initWithTarget:self selector:@selector(mainLoop) object:nil]; - [runningThread_ start]; -#endif - - // Create a display link capable of being used with all active displays - CVDisplayLinkCreateWithActiveCGDisplays(&displayLink); - - // Set the renderer output callback function - CVDisplayLinkSetOutputCallback(displayLink, &MyDisplayLinkCallback, self); - - // Set the display link for the current renderer - CGLContextObj cglContext = [[openGLView_ openGLContext] CGLContextObj]; - CGLPixelFormatObj cglPixelFormat = [[openGLView_ pixelFormat] CGLPixelFormatObj]; - CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(displayLink, cglContext, cglPixelFormat); - - // Activate the display link - CVDisplayLinkStart(displayLink); -} - -- (void) mainLoop -{ - cocos2d::CCDirector::sharedDirector()->mainLoop(); -} - -- (void) stopAnimation -{ - if( displayLink ) { - CVDisplayLinkStop(displayLink); - CVDisplayLinkRelease(displayLink); - displayLink = NULL; - -#if ! CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD - [runningThread_ cancel]; - [runningThread_ release]; - runningThread_ = nil; -#endif - } -} - --(void) dealloc -{ - if( displayLink ) - { - CVDisplayLinkStop(displayLink); - CVDisplayLinkRelease(displayLink); - } - - sharedDisplayLinkMacWrapper = nil; - - [super dealloc]; -} - -// -// Draw the Scene -// -- (void) drawScene -{ - cocos2d::CCDirector::sharedDirector()->drawScene(); -} - -@end \ No newline at end of file diff --git a/cocos2dx/platform/mac/CCDirector_mac.mm b/cocos2dx/platform/mac/CCDirector_mac.mm deleted file mode 100644 index 3d0b59b65f..0000000000 --- a/cocos2dx/platform/mac/CCDirector_mac.mm +++ /dev/null @@ -1,923 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org - -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 "CCDirector.h" -#include "CCScene.h" -#include "NSMutableArray.h" -#include "CCScheduler.h" -#include "ccMacros.h" -#include "CCXCocos2dDefine.h" -#include "CCTouchDispatcher.h" -#include "support/opengl_support/glu.h" -#include "CGPointExtension.h" -#include "CCTransition.h" -#include "CCTextureCache.h" -#include "CCTransition.h" -#include "CCSpriteFrameCache.h" -#include "NSAutoreleasePool.h" -#include "platform/platform.h" -#include "CCXApplication.h" -#include "CCLabelBMFont.h" -#include "CCActionManager.h" -#include "CCLabelTTF.h" -#include "CCConfiguration.h" -#include "CCKeypadDispatcher.h" -#include "CCGL.h" -#include "CCDirectorDisplayLinkMacWrapper.h" - -#if CC_ENABLE_PROFILERS -#include "support/CCProfiling.h" -#endif // CC_ENABLE_PROFILERS - -#include - -using namespace std; -using namespace cocos2d; -namespace cocos2d -{ - -// singleton stuff -static CCDisplayLinkDirector s_sharedDirector; -static bool s_bFirstRun = true; - -#define kDefaultFPS 60 // 60 frames per second -extern const char* cocos2dVersion(void); - -CCDirector* CCDirector::sharedDirector(void) -{ - if (s_bFirstRun) - { - s_sharedDirector.init(); - s_bFirstRun = false; - } - - return &s_sharedDirector; -} - -bool CCDirector::init(void) -{ - CCLOG("cocos2d: %s", cocos2dVersion()); - - CCLOG("cocos2d: Using Director Type: CCDirectorDisplayLink"); - - // scenes - m_pRunningScene = NULL; - m_pNextScene = NULL; - - m_pNotificationNode = NULL; - - m_dOldAnimationInterval = m_dAnimationInterval = 1.0 / kDefaultFPS; - m_pobScenesStack = new NSMutableArray(); - - // Set default projection (3D) - m_eProjection = kCCDirectorProjectionDefault; - - // projection delegate if "Custom" projection is used - m_pProjectionDelegate = NULL; - - // FPS - m_bDisplayFPS = false; - m_nFrames = 0; - m_pszFPS = new char[10]; - m_pLastUpdate = new struct cc_timeval(); - - // paused ? - m_bPaused = false; - - m_obWinSizeInPixels = m_obWinSizeInPoints = CGSizeZero; - - m_pobOpenGLView = NULL; - - m_bIsFullScreen = false; - m_nResizeMode = kCCDirectorResize_AutoScale; - - m_pFullScreenGLView = NULL; - m_pFullScreenWindow = NULL; - m_pWindowGLView = NULL; - m_winOffset = CGPointZero; - - // create autorelease pool - NSPoolManager::getInstance()->push(); - - return true; -} - -CCDirector::~CCDirector(void) -{ - CCLOGINFO("cocos2d: deallocing %p", this); - -#if CC_DIRECTOR_FAST_FPS - CCX_SAFE_RELEASE(m_pFPSLabel); -#endif - - CCX_SAFE_RELEASE(m_pRunningScene); - CCX_SAFE_RELEASE(m_pNotificationNode); - CCX_SAFE_RELEASE(m_pobScenesStack); - - // pop the autorelease pool - NSPoolManager::getInstance()->pop(); - - // delete m_pLastUpdate - CCX_SAFE_DELETE(m_pLastUpdate); - - // delete last compute time - CCX_SAFE_DELETE(m_pLastComputeFrameRate); - - CCKeypadDispatcher::purgeSharedDispatcher(); - - // delete fps string - delete []m_pszFPS; - - [m_pFullScreenGLView release]; - [m_pFullScreenWindow release]; - [m_pWindowGLView release]; - [[CCDirectorDisplayLinkMacWrapper sharedDisplayLinkMacWrapper] release]; -} - -void CCDirector::setGLDefaultValues(void) -{ - // This method SHOULD be called only after openGLView_ was initialized - assert(m_pobOpenGLView); - - setAlphaBlending(true); - setDepthTest(true); - setProjection(m_eProjection); - - // set other opengl default values - glClearColor(0.0f, 0.0f, 0.0f, 1.0f); - -#if CC_DIRECTOR_FAST_FPS - if (! m_pFPSLabel) - { - m_pFPSLabel = CCLabelTTF::labelWithString("00.0", "Arial", 24); - m_pFPSLabel->retain(); - } -#endif -} - -// Draw the SCene -void CCDirector::drawScene(void) -{ - // calculate "global" dt - calculateDeltaTime(); - - //tick before glClear: issue #533 - if (! m_bPaused) - { - CCScheduler::sharedScheduler()->tick(m_fDeltaTime); - } - - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - /* to avoid flickr, nextScene MUST be here: after tick and before draw. - XXX: Which bug is this one. It seems that it can't be reproduced with v0.9 */ - if (m_pNextScene) - { - setNextScene(); - } - - glPushMatrix(); - - // By default enable VertexArray, ColorArray, TextureCoordArray and Texture2D - CC_ENABLE_DEFAULT_GL_STATES(); - - // draw the scene - if (m_pRunningScene) - { - m_pRunningScene->visit(); - } - - // draw the notifications node - if (m_pNotificationNode) - { - m_pNotificationNode->visit(); - } - - if (m_bDisplayFPS) - { - showFPS(); - } - -#if CC_ENABLE_PROFILERS - showProfilers(); -#endif - - CC_DISABLE_DEFAULT_GL_STATES(); - - glPopMatrix(); - - // swap buffers - if (m_pobOpenGLView) - { - m_pobOpenGLView->swapBuffers(); - } -} - -void CCDirector::calculateDeltaTime(void) -{ - struct cc_timeval now; - - if (CCTime::gettimeofdayCocos2d(&now, NULL) != 0) - { - CCLOG("error in gettimeofday"); - m_fDeltaTime = 0; - return; - } - - // new delta time - if (m_bNextDeltaTimeZero) - { - m_fDeltaTime = 0; - m_bNextDeltaTimeZero = false; - } - else - { - m_fDeltaTime = (now.tv_sec - m_pLastUpdate->tv_sec) + (now.tv_usec - m_pLastUpdate->tv_usec) / 1000000.0f; - m_fDeltaTime = MAX(0, m_fDeltaTime); - } - - *m_pLastUpdate = now; -} - - -// m_dAnimationInterval -void CCDirector::setAnimationInterval(double dValue) -{ - CCLOG("cocos2d: Director#setAnimationInterval. Overrride me"); - assert(0); -} - - -// m_pobOpenGLView - -void CCDirector::setOpenGLView(CC_GLVIEW *pobOpenGLView) -{ - assert(pobOpenGLView); - - if (m_pobOpenGLView != pobOpenGLView) - { - [m_pobOpenGLView release]; - m_pobOpenGLView = [pobOpenGLView retain]; - - - - // set size - m_obWinSizeInPixels = m_obWinSizeInPoints = NSSizeToCGSize([pobOpenGLView bounds].size); - - setGLDefaultValues(); - - // cache the NSWindow and NSOpgenGLView created from the NIB - if (!m_bIsFullScreen && !m_pWindowGLView) - { - m_pWindowGLView = [pobOpenGLView retain]; - m_originalWinSize = m_obWinSizeInPixels; - } - - // for DirectorDisplayLink, because the it doesn't override setOpenGLView - - CCEventDispatcher *eventDispatcher = [CCEventDispatcher sharedDispatcher]; - [m_pobOpenGLView setEventDelegate: eventDispatcher]; - [eventDispatcher setDispatchEvents: YES]; - - // Enable Touches. Default no. - [pobOpenGLView setAcceptsTouchEvents:NO]; - // [view setAcceptsTouchEvents:YES]; - - - // Synchronize buffer swaps with vertical refresh rate - [[pobOpenGLView openGLContext] makeCurrentContext]; - GLint swapInt = 1; - [[pobOpenGLView openGLContext] setValues:&swapInt forParameter:NSOpenGLCPSwapInterval]; - } -} - -void CCDirector::setNextDeltaTimeZero(bool bNextDeltaTimeZero) -{ - m_bNextDeltaTimeZero = bNextDeltaTimeZero; -} - -void CCDirector::setProjection(ccDirectorProjection kProjection) -{ - CGSize size = m_obWinSizeInPixels; - - CGPoint offset = CGPointZero; - float widthAspect = size.width; - float heightAspect = size.height; - - if( m_nResizeMode == kCCDirectorResize_AutoScale && ! CGSizeEqualToSize(m_originalWinSize, CGSizeZero ) ) - { - size = m_originalWinSize; - - float aspect = m_originalWinSize.width / m_originalWinSize.height; - widthAspect = m_obWinSizeInPixels.width; - heightAspect = m_obWinSizeInPixels.width / aspect; - - if( heightAspect > m_obWinSizeInPixels.height ) - { - widthAspect = m_obWinSizeInPixels.height * aspect; - heightAspect = m_obWinSizeInPixels.height; - } - - m_winOffset.x = (m_obWinSizeInPixels.width - widthAspect) / 2; - m_winOffset.y = (m_obWinSizeInPixels.height - heightAspect) / 2; - - offset = m_winOffset; - } - - switch (kProjection) { - case kCCDirectorProjection2D: - glViewport(offset.x, offset.y, widthAspect, heightAspect); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - ccglOrtho(0, size.width, 0, size.height, -1024, 1024); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - break; - - case kCCDirectorProjection3D: - glViewport(offset.x, offset.y, widthAspect, heightAspect); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - gluPerspective(60, (GLfloat)widthAspect/heightAspect, 0.1f, 1500.0f); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - - float eyeZ = size.height * getZEye() / m_obWinSizeInPixels.height; - - gluLookAt( size.width/2, size.height/2, eyeZ, - size.width/2, size.height/2, 0, - 0.0f, 1.0f, 0.0f); - break; - - case kCCDirectorProjectionCustom: - if(m_pProjectionDelegate) - { - m_pProjectionDelegate->updateProjection(); - } - break; - - default: - CCLOG("cocos2d: Director: unrecognized projecgtion"); - break; - } - - m_eProjection = kProjection; -} - -void CCDirector::purgeCachedData(void) -{ - CCLabelBMFont::purgeCachedData(); - CCTextureCache::purgeSharedTextureCache(); -} - -float CCDirector::getZEye(void) -{ - return (m_obWinSizeInPixels.height / 1.1566f); -} - -void CCDirector::setAlphaBlending(bool bOn) -{ - if (bOn) - { - glEnable(GL_BLEND); - glBlendFunc(CC_BLEND_SRC, CC_BLEND_DST); - } - else - { - glDisable(GL_BLEND); - } -} - -void CCDirector::setDepthTest(bool bOn) -{ - if (bOn) - { - ccglClearDepth(1.0f); - glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_LEQUAL); - glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); - } - else - { - glDisable(GL_DEPTH_TEST); - } -} - -CGPoint CCDirector::convertToGL(CGPoint obPoint) -{ - assert(0); - return CGPointZero; -} - -CGPoint CCDirector::convertToUI(CGPoint obPoint) -{ - assert(0); - return CGPointZero; -} - -CGSize CCDirector::getWinSize(void) -{ - if (m_nResizeMode == kCCDirectorResize_AutoScale) - { - return m_originalWinSize; - } - - return m_obWinSizeInPixels; -} - -CGSize CCDirector::getWinSizeInPixels() -{ - return getWinSize(); -} - -// return the current frame size -CGSize CCDirector::getDisplaySizeInPixels(void) -{ - return m_obWinSizeInPixels; -} - -void CCDirector::reshapeProjection(CGSize newWindowSize) -{ - m_obWinSizeInPixels = m_originalWinSize = newWindowSize; - setProjection(m_eProjection); -} - -// scene management - -void CCDirector::runWithScene(CCScene *pScene) -{ - assert(pScene != NULL); - assert(m_pRunningScene == NULL); - - pushScene(pScene); - startAnimation(); -} - -void CCDirector::replaceScene(CCScene *pScene) -{ - assert(pScene != NULL); - - unsigned int index = m_pobScenesStack->count(); - - m_bSendCleanupToScene = true; - m_pobScenesStack->replaceObjectAtIndex(index - 1, pScene); - - m_pNextScene = pScene; -} - -void CCDirector::pushScene(CCScene *pScene) -{ - assert(pScene); - - m_bSendCleanupToScene = false; - - m_pobScenesStack->addObject(pScene); - m_pNextScene = pScene; -} - -void CCDirector::popScene(void) -{ - assert(m_pRunningScene != NULL); - - m_pobScenesStack->removeLastObject(); - unsigned int c = m_pobScenesStack->count(); - - if (c == 0) - { - end(); - } - else - { - m_bSendCleanupToScene = true; - m_pNextScene = m_pobScenesStack->getObjectAtIndex(c - 1); - } -} - -void CCDirector::end(void) -{ - // don't release the event handlers - // They are needed in case the director is run again - CCTouchDispatcher::sharedDispatcher()->removeAllDelegates(); - - m_pRunningScene->onExit(); - m_pRunningScene->cleanup(); - m_pRunningScene->release(); - - m_pRunningScene = NULL; - m_pNextScene = NULL; - - // remove all objects, but don't release it. - // runWithScene might be executed after 'end'. - m_pobScenesStack->removeAllObjects(); - - stopAnimation(); - -#if CC_DIRECTOR_FAST_FPS - CCX_SAFE_RELEASE_NULL(m_pFPSLabel); -#endif - - CCX_SAFE_RELEASE_NULL(m_pProjectionDelegate); - - // purge bitmap cache - CCLabelBMFont::purgeCachedData(); - - // purge all managers - CCAnimationCache::purgeSharedAnimationCache(); - CCSpriteFrameCache::purgeSharedSpriteFrameCache(); - CCActionManager::sharedManager()->purgeSharedManager(); - CCScheduler::purgeSharedScheduler(); - CCTextureCache::purgeSharedTextureCache(); - - // OpenGL view - [m_pobOpenGLView release]; - m_pobOpenGLView = NULL; -} - -void CCDirector::setNextScene(void) -{ - ccSceneFlag runningSceneType = ccNormalScene; - ccSceneFlag newSceneType = m_pNextScene->getSceneType(); - - if (m_pRunningScene) - { - runningSceneType = m_pRunningScene->getSceneType(); - } - - // If it is not a transition, call onExit/cleanup - /*if (! newIsTransition)*/ - if (! (newSceneType & ccTransitionScene)) - { - if (m_pRunningScene) - { - m_pRunningScene->onExit(); - } - - // issue #709. the root node (scene) should receive the cleanup message too - // otherwise it might be leaked. - if (m_bSendCleanupToScene && m_pRunningScene) - { - m_pRunningScene->cleanup(); - } - } - - if (m_pRunningScene) - { - m_pRunningScene->release(); - } - m_pRunningScene = m_pNextScene; - m_pNextScene->retain(); - m_pNextScene = NULL; - - if (! (runningSceneType & ccTransitionScene) && m_pRunningScene) - { - m_pRunningScene->onEnter(); - m_pRunningScene->onEnterTransitionDidFinish(); - } -} - -void CCDirector::pause(void) -{ - if (m_bPaused) - { - return; - } - - m_dOldAnimationInterval = m_dAnimationInterval; - - // when paused, don't consume CPU - setAnimationInterval(1 / 4.0); - m_bPaused = true; -} - -void CCDirector::resume(void) -{ - if (! m_bPaused) - { - return; - } - - setAnimationInterval(m_dOldAnimationInterval); - - if (CCTime::gettimeofdayCocos2d(m_pLastUpdate, NULL) != 0) - { - CCLOG("cocos2d: Director: Error in gettimeofday"); - } - - m_bPaused = false; - m_fDeltaTime = 0; -} - -void CCDirector::startAnimation(void) -{ - CCLOG("cocos2d: Director#startAnimation. Overrride me"); - assert(0); -} - -void CCDirector::stopAnimation(void) -{ - CCLOG("cocos2d: Director#stopAnimation. Overrride me"); - assert(0); -} - -void CCDirector::mainLoop(void) -{ - CCLOG("cocos2d: Director#preMainLoop. Overrride me"); - assert(0); -} - -#if CC_DIRECTOR_FAST_FPS -// display the FPS using a LabelAtlas -// updates the FPS every frame -void CCDirector::showFPS(void) -{ - m_nFrames++; - m_fAccumDt += m_fDeltaTime; - - if (m_fAccumDt > CC_DIRECTOR_FPS_INTERVAL) - { - m_fFrameRate = m_nFrames / m_fAccumDt; - m_nFrames = 0; - m_fAccumDt = 0; - - sprintf(m_pszFPS, "%.1f", m_fFrameRate); - m_pFPSLabel->setString(m_pszFPS); - } - - m_pFPSLabel->draw(); -} -#endif // CC_DIRECTOR_FAST_FPS - -void CCDirector::showProfilers() -{ -#if CC_ENABLE_PROFILERS - m_fAccumDtForProfiler += m_fDeltaTime; - if (m_fAccumDtForProfiler > 1.0f) - { - m_fAccumDtForProfiler = 0; - CCProfiler::sharedProfiler()->displayTimers(); - } -#endif -} - -/*************************************************** -* mobile platforms specific functions -**************************************************/ - -// is the view currently attached -bool CCDirector::isOpenGLAttached(void) -{ - assert(false); - return false; -} - -void CCDirector::updateContentScaleFactor() -{ - assert(0); -} - -// detach or attach to a view or a window -bool CCDirector::detach(void) -{ - assert(false); - return false; -} - -void CCDirector::setDepthBufferFormat(tDepthBufferFormat kDepthBufferFormat) -{ - assert(false); -} - -void CCDirector::setPixelFormat(tPixelFormat kPixelFormat) -{ - assert(false); -} - -tPixelFormat CCDirector::getPiexFormat(void) -{ - assert(false); - return m_ePixelFormat; -} - -bool CCDirector::setDirectorType(ccDirectorType obDirectorType) -{ - // we only support CCDisplayLinkDirector - CCDirector::sharedDirector(); - - return true; -} - -bool CCDirector::enableRetinaDisplay(bool enabled) -{ - assert(false); - return false; -} - -CGFloat CCDirector::getContentScaleFactor(void) -{ - assert(false); - return m_fContentScaleFactor; -} - -void CCDirector::setContentScaleFactor(CGFloat scaleFactor) -{ - assert(false); -} - -void CCDirector::applyOrientation(void) -{ - assert(false); -} - -ccDeviceOrientation CCDirector::getDeviceOrientation(void) -{ - assert(false); - return m_eDeviceOrientation; -} - -void CCDirector::setDeviceOrientation(ccDeviceOrientation kDeviceOrientation) -{ - assert(false); -} - -/*************************************************** -* PC platforms specific functions, such as mac -**************************************************/ - -CGPoint CCDirector::convertEventToGL(NSEvent *event); -{ - ///@todo NSEvent have not implemented - return CGPointZero; -} - -bool CCDirector::isFullScreen(void) -{ - return m_bIsFullScreen; -} - -void CCDirector::setResizeMode(int resizeMode) -{ - assert("not supported."); -} - -int CCDirector::getResizeMode(void); -{ - assert("not supported."); - return -1; -} - -void CCDirector::setFullScreen(bool fullscreen) -{ - // Mac OS X 10.6 and later offer a simplified mechanism to create full-screen contexts -#if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5 - - if( m_bIsFullScreen != fullscreen ) - { - m_bIsFullScreen = fullscreen; - - if( fullscreen ) - { - // create the fullscreen view/window - NSRect mainDisplayRect, viewRect; - - // Create a screen-sized window on the display you want to take over - // Note, mainDisplayRect has a non-zero origin if the key window is on a secondary display - mainDisplayRect = [[NSScreen mainScreen] frame]; - m_pFullScreenWindow = [[NSWindow alloc] initWithContentRect:mainDisplayRect - styleMask:NSBorderlessWindowMask - backing:NSBackingStoreBuffered - defer:YES]; - - // Set the window level to be above the menu bar - [m_pFullScreenWindow setLevel:NSMainMenuWindowLevel+1]; - - // Perform any other window configuration you desire - [m_pFullScreenWindow setOpaque:YES]; - [m_pFullScreenWindow setHidesOnDeactivate:YES]; - - // Create a view with a double-buffered OpenGL context and attach it to the window - // By specifying the non-fullscreen context as the shareContext, we automatically inherit the OpenGL objects (textures, etc) it has defined - viewRect = NSMakeRect(0.0, 0.0, mainDisplayRect.size.width, mainDisplayRect.size.height); - - m_pFullScreenGLView = [[MacGLView alloc] initWithFrame:viewRect shareContext:[m_pobOpenGLView openGLContext]]; - - [m_pFullScreenWindow setContentView:m_pFullScreenGLView]; - - // Show the window - [m_pFullScreenWindow makeKeyAndOrderFront:self]; - - [self setOpenGLView:fullScreenGLView_]; - - } - else - { - [m_pFullScreenWindow release]; - [m_pFullScreenGLView release]; - m_pFullScreenWindow = nil; - m_pFullScreenGLView = nil; - - [[m_pFullScreenGLView openGLContext] makeCurrentContext]; - setOpenGLView(m_pFullScreenGLView); - } - - [m_pobOpenGLView setNeedsDisplay:YES]; - } -#else -#error Full screen is not supported for Mac OS 10.5 or older yet -#error If you don't want FullScreen support, you can safely remove these 2 lines -#endif -} - -CGPoint CCDirector::convertToLogicalCoordinates(CGPoint coordinates) -{ - CGPoint ret; - - if( m_nResizeMode == kCCDirectorResize_NoScale ) - { - ret = coordinates; - } - else - { - float x_diff = m_originalWinSize.width / (m_obWinSizeInPixels.width - m_winOffset.x * 2); - float y_diff = m_originalWinSize.height / (m_obWinSizeInPixels.height - m_winOffset.y * 2); - - float adjust_x = (m_obWinSizeInPixels.width * x_diff - m_originalWinSize.width ) / 2; - float adjust_y = (m_obWinSizeInPixels.height * y_diff - m_originalWinSize.height ) / 2; - - ret = CGPointMake( (x_diff * coordinates.x) - adjust_x, ( y_diff * coordinates.y ) - adjust_y ); - } - - return ret; -} - - -/*************************************************** -* implementation of DisplayLinkDirector -**************************************************/ - -// should we afford 4 types of director ?? -// I think DisplayLinkDirector is enough -// so we now only support DisplayLinkDirector -void CCDisplayLinkDirector::startAnimation(void) -{ - if (CCTime::gettimeofdayCocos2d(m_pLastUpdate, NULL) != 0) - { - CCLOG("cocos2d: DisplayLinkDirector: Error on gettimeofday"); - } - - m_bInvalid = false; - - [[CCDirectorDisplayLinkMacWrapper sharedDisplayLinkMacWrapper] startAnimation]; -} - -void CCDisplayLinkDirector::mainLoop(void) -{ - if (! m_bInvalid) - { - drawScene(); - - // release the objects - NSPoolManager::getInstance()->pop(); - } -} - -void CCDisplayLinkDirector::stopAnimation(void) -{ - m_bInvalid = true; - - [[CCDirectorDisplayLinkMacWrapper sharedDisplayLinkMacWrapper] stopAnimation]; -} - -void CCDisplayLinkDirector::setAnimationInterval(double dValue) -{ - m_dAnimationInterval = dValue; - m_fExpectedFrameRate = (ccTime)(1 / m_dAnimationInterval); - if (! m_bInvalid) - { - stopAnimation(); - startAnimation(); - } -} - -} //namespace cocos2d diff --git a/cocos2dx/platform/mac/CCEventDispatcher.h b/cocos2dx/platform/mac/CCEventDispatcher.h deleted file mode 100644 index b52f8d1c59..0000000000 --- a/cocos2dx/platform/mac/CCEventDispatcher.h +++ /dev/null @@ -1,233 +0,0 @@ -/* - * cocos2d for iPhone: http://www.cocos2d-iphone.org - * - * Copyright (c) 2010 Ricardo Quesada - * - * 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. - */ - -// Only compile this code on Mac. These files should not be included on your iOS project. -// But in case they are included, it won't be compiled. -#import -#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED -#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) - -#import - -#import "MacGLView.h" -#import "../../Support/uthash.h" // hack: uthash needs to be imported before utlist to prevent warning -#import "../../Support/utlist.h" -#import "../../ccConfig.h" - -#pragma mark - -#pragma mark CCMouseEventDelegate - -/** CCMouseEventDelegate protocol. - Implement it in your node to receive any of mouse events - */ -@protocol CCMouseEventDelegate -@optional - -// -// left -// -/** called when the "mouseDown" event is received. - Return YES to avoid propagating the event to other delegates. - */ --(BOOL) ccMouseDown:(NSEvent*)event; - -/** called when the "mouseDragged" event is received. - Return YES to avoid propagating the event to other delegates. - */ --(BOOL) ccMouseDragged:(NSEvent*)event; - -/** called when the "mouseMoved" event is received. - Return YES to avoid propagating the event to other delegates. - By default, "mouseMoved" is disabled. To enable it, send the "setAcceptsMouseMovedEvents:YES" message to the main window. - */ --(BOOL) ccMouseMoved:(NSEvent*)event; - -/** called when the "mouseUp" event is received. - Return YES to avoid propagating the event to other delegates. - */ --(BOOL) ccMouseUp:(NSEvent*)event; - - -// -// right -// - -/** called when the "rightMouseDown" event is received. - Return YES to avoid propagating the event to other delegates. - */ --(BOOL) ccRightMouseDown:(NSEvent*)event; - -/** called when the "rightMouseDragged" event is received. - Return YES to avoid propagating the event to other delegates. - */ --(BOOL) ccRightMouseDragged:(NSEvent*)event; - -/** called when the "rightMouseUp" event is received. - Return YES to avoid propagating the event to other delegates. - */ --(BOOL) ccRightMouseUp:(NSEvent*)event; - -// -// other -// - -/** called when the "otherMouseDown" event is received. - Return YES to avoid propagating the event to other delegates. - */ --(BOOL) ccOtherMouseDown:(NSEvent*)event; - -/** called when the "otherMouseDragged" event is received. - Return YES to avoid propagating the event to other delegates. - */ --(BOOL) ccOtherMouseDragged:(NSEvent*)event; - -/** called when the "otherMouseUp" event is received. - Return YES to avoid propagating the event to other delegates. - */ --(BOOL) ccOtherMouseUp:(NSEvent*)event; - -// -// scroll wheel -// - -/** called when the "scrollWheel" event is received. - Return YES to avoid propagating the event to other delegates. - */ -- (BOOL)ccScrollWheel:(NSEvent *)theEvent; - - -// -// enter / exit -// - -/** called when the "mouseEntered" event is received. - Return YES to avoid propagating the event to other delegates. - */ -- (void)ccMouseEntered:(NSEvent *)theEvent; - -/** called when the "mouseExited" event is received. - Return YES to avoid propagating the event to other delegates. - */ -- (void)ccMouseExited:(NSEvent *)theEvent; - -@end - -#pragma mark - -#pragma mark CCKeyboardEventDelegate - -/** CCKeyboardEventDelegate protocol. - Implement it in your node to receive any of keyboard events - */ -@protocol CCKeyboardEventDelegate -@optional -/** called when the "keyUp" event is received. - Return YES to avoid propagating the event to other delegates. - */ --(BOOL) ccKeyUp:(NSEvent*)event; - -/** called when the "keyDown" event is received. - Return YES to avoid propagating the event to other delegates. - */ --(BOOL) ccKeyDown:(NSEvent*)event; -/** called when the "flagsChanged" event is received. - Return YES to avoid propagating the event to other delegates. - */ --(BOOL) ccFlagsChanged:(NSEvent*)event; -@end - - -#pragma mark - -#pragma mark CCEventDispatcher - -struct _listEntry; - -/** CCEventDispatcher - - This is object is responsible for dispatching the events: - - Mouse events - - Keyboard events - - Touch events - - Only available on Mac - */ -@interface CCEventDispatcher : NSObject { - - BOOL dispatchEvents_; - - struct _listEntry *keyboardDelegates_; - struct _listEntry *mouseDelegates_; -} - -@property (nonatomic, readwrite) BOOL dispatchEvents; - - -/** CCEventDispatcher singleton */ -+(CCEventDispatcher*) sharedDispatcher; - -#pragma mark CCEventDispatcher - Mouse - -/** Adds a mouse delegate to the dispatcher's list. - Delegates with a lower priority value will be called before higher priority values. - All the events will be propgated to all the delegates, unless the one delegate returns YES. - - IMPORTANT: The delegate will be retained. - */ --(void) addMouseDelegate:(id) delegate priority:(NSInteger)priority; - -/** removes a mouse delegate */ --(void) removeMouseDelegate:(id) delegate; - -/** Removes all mouse delegates, releasing all the delegates */ --(void) removeAllMouseDelegates; - -#pragma mark CCEventDispatcher - Keyboard - -/** Adds a Keyboard delegate to the dispatcher's list. - Delegates with a lower priority value will be called before higher priority values. - All the events will be propgated to all the delegates, unless the one delegate returns YES. - - IMPORTANT: The delegate will be retained. - */ --(void) addKeyboardDelegate:(id) delegate priority:(NSInteger)priority; - -/** removes a mouse delegate */ --(void) removeKeyboardDelegate:(id) delegate; - -/** Removes all mouse delegates, releasing all the delegates */ --(void) removeAllKeyboardDelegates; - -#pragma mark CCEventDispatcher - Touches - -// XXX - -#pragma mark CCEventDispatcher - Dispatch Events - -#if CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD --(void) dispatchQueuedEvents; -#endif - -@end - - -#endif // __MAC_OS_X_VERSION_MAX_ALLOWED diff --git a/cocos2dx/platform/mac/CCEventDispatcher.m b/cocos2dx/platform/mac/CCEventDispatcher.m deleted file mode 100644 index b7266651ac..0000000000 --- a/cocos2dx/platform/mac/CCEventDispatcher.m +++ /dev/null @@ -1,578 +0,0 @@ -/* - * cocos2d for iPhone: http://www.cocos2d-iphone.org - * - * Copyright (c) 2010 Ricardo Quesada - * - * 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. - */ - -// Only compile this code on Mac. These files should not be included on your iOS project. -// But in case they are included, it won't be compiled. -#import -#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED -#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) - -#import "CCEventDispatcher.h" -#import "../../ccConfig.h" - -static CCEventDispatcher *sharedDispatcher = nil; - -enum { - // mouse - kCCImplementsMouseDown = 1 << 0, - kCCImplementsMouseMoved = 1 << 1, - kCCImplementsMouseDragged = 1 << 2, - kCCImplementsMouseUp = 1 << 3, - kCCImplementsRightMouseDown = 1 << 4, - kCCImplementsRightMouseDragged = 1 << 5, - kCCImplementsRightMouseUp = 1 << 6, - kCCImplementsOtherMouseDown = 1 << 7, - kCCImplementsOtherMouseDragged = 1 << 8, - kCCImplementsOtherMouseUp = 1 << 9, - kCCImplementsScrollWheel = 1 << 10, - kCCImplementsMouseEntered = 1 << 11, - kCCImplementsMouseExited = 1 << 12, - - // keyboard - kCCImplementsKeyUp = 1 << 0, - kCCImplementsKeyDown = 1 << 1, - kCCImplementsFlagsChanged = 1 << 2, -}; - - -typedef struct _listEntry -{ - struct _listEntry *prev, *next; - id delegate; - NSInteger priority; - NSUInteger flags; -} tListEntry; - - -#if CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD - -#define QUEUE_EVENT_MAX 128 -struct _eventQueue { - SEL selector; - NSEvent *event; -}; - -static struct _eventQueue eventQueue[QUEUE_EVENT_MAX]; -static int eventQueueCount; - -#endif // CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD - - -@implementation CCEventDispatcher - -@synthesize dispatchEvents=dispatchEvents_; - - -+(CCEventDispatcher*) sharedDispatcher -{ - @synchronized(self) { - if (sharedDispatcher == nil) - sharedDispatcher = [[self alloc] init]; // assignment not done here - } - return sharedDispatcher; -} - -+(id) allocWithZone:(NSZone *)zone -{ - @synchronized(self) { - NSAssert(sharedDispatcher == nil, @"Attempted to allocate a second instance of a singleton."); - return [super allocWithZone:zone]; - } - return nil; // on subsequent allocation attempts return nil -} - --(id) init -{ - if( (self = [super init]) ) - { - // events enabled by default - dispatchEvents_ = YES; - - // delegates - keyboardDelegates_ = NULL; - mouseDelegates_ = NULL; - -#if CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD - eventQueueCount = 0; -#endif - } - - return self; -} - -- (void) dealloc -{ - [super dealloc]; -} - -#pragma mark CCEventDispatcher - add / remove delegates - --(void) addDelegate:(id)delegate priority:(NSInteger)priority flags:(NSUInteger)flags list:(tListEntry**)list -{ - tListEntry *listElement = malloc( sizeof(*listElement) ); - - listElement->delegate = [delegate retain]; - listElement->priority = priority; - listElement->flags = flags; - listElement->next = listElement->prev = NULL; - - // empty list ? - if( ! *list ) { - DL_APPEND( *list, listElement ); - - } else { - BOOL added = NO; - - for( tListEntry *elem = *list; elem ; elem = elem->next ) { - if( priority < elem->priority ) { - - if( elem == *list ) - DL_PREPEND(*list, listElement); - else { - listElement->next = elem; - listElement->prev = elem->prev; - - elem->prev->next = listElement; - elem->prev = listElement; - } - - added = YES; - break; - } - } - - // Not added? priority has the higher value. Append it. - if( !added ) - DL_APPEND(*list, listElement); - } -} - --(void) removeDelegate:(id)delegate fromList:(tListEntry**)list -{ - tListEntry *entry, *tmp; - - // updates with priority < 0 - DL_FOREACH_SAFE( *list, entry, tmp ) { - if( entry->delegate == delegate ) { - DL_DELETE( *list, entry ); - [delegate release]; - free(entry); - break; - } - } -} - --(void) removeAllDelegatesFromList:(tListEntry**)list -{ - tListEntry *entry, *tmp; - - DL_FOREACH_SAFE( *list, entry, tmp ) { - DL_DELETE( *list, entry ); - free(entry); - } -} - - --(void) addMouseDelegate:(id) delegate priority:(NSInteger)priority -{ - NSUInteger flags = 0; - - flags |= ( [delegate respondsToSelector:@selector(ccMouseDown:)] ? kCCImplementsMouseDown : 0 ); - flags |= ( [delegate respondsToSelector:@selector(ccMouseDragged:)] ? kCCImplementsMouseDragged : 0 ); - flags |= ( [delegate respondsToSelector:@selector(ccMouseMoved:)] ? kCCImplementsMouseMoved : 0 ); - flags |= ( [delegate respondsToSelector:@selector(ccMouseUp:)] ? kCCImplementsMouseUp : 0 ); - - flags |= ( [delegate respondsToSelector:@selector(ccRightMouseDown:)] ? kCCImplementsRightMouseDown : 0 ); - flags |= ( [delegate respondsToSelector:@selector(ccRightMouseDragged:)] ? kCCImplementsRightMouseDragged : 0 ); - flags |= ( [delegate respondsToSelector:@selector(ccRightMouseUp:)] ? kCCImplementsRightMouseUp : 0 ); - - flags |= ( [delegate respondsToSelector:@selector(ccOtherMouseDown:)] ? kCCImplementsOtherMouseDown : 0 ); - flags |= ( [delegate respondsToSelector:@selector(ccOtherMouseDragged:)] ? kCCImplementsOtherMouseDragged : 0 ); - flags |= ( [delegate respondsToSelector:@selector(ccOtherMouseUp:)] ? kCCImplementsOtherMouseUp : 0 ); - - flags |= ( [delegate respondsToSelector:@selector(ccMouseEntered:)] ? kCCImplementsMouseEntered : 0 ); - flags |= ( [delegate respondsToSelector:@selector(ccMouseExited:)] ? kCCImplementsMouseExited : 0 ); - - flags |= ( [delegate respondsToSelector:@selector(ccScrollWheel:)] ? kCCImplementsScrollWheel : 0 ); - - [self addDelegate:delegate priority:priority flags:flags list:&mouseDelegates_]; -} - --(void) removeMouseDelegate:(id) delegate -{ - [self removeDelegate:delegate fromList:&mouseDelegates_]; -} - --(void) removeAllMouseDelegates -{ - [self removeAllDelegatesFromList:&mouseDelegates_]; -} - --(void) addKeyboardDelegate:(id) delegate priority:(NSInteger)priority -{ - NSUInteger flags = 0; - - flags |= ( [delegate respondsToSelector:@selector(ccKeyUp:)] ? kCCImplementsKeyUp : 0 ); - flags |= ( [delegate respondsToSelector:@selector(ccKeyDown:)] ? kCCImplementsKeyDown : 0 ); - flags |= ( [delegate respondsToSelector:@selector(ccFlagsChanged:)] ? kCCImplementsFlagsChanged : 0 ); - - [self addDelegate:delegate priority:priority flags:flags list:&keyboardDelegates_]; -} - --(void) removeKeyboardDelegate:(id) delegate -{ - [self removeDelegate:delegate fromList:&keyboardDelegates_]; -} - --(void) removeAllKeyboardDelegates -{ - [self removeAllDelegatesFromList:&keyboardDelegates_]; -} - -#pragma mark CCEventDispatcher - Mouse events -// -// Mouse events -// - -// -// Left -// -- (void)mouseDown:(NSEvent *)event -{ - if( dispatchEvents_ ) { - tListEntry *entry, *tmp; - - DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) { - if ( entry->flags & kCCImplementsMouseDown ) { - void *swallows = [entry->delegate performSelector:@selector(ccMouseDown:) withObject:event]; - if( swallows ) - break; - } - } - } -} - -- (void)mouseMoved:(NSEvent *)event -{ - if( dispatchEvents_ ) { - tListEntry *entry, *tmp; - - DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) { - if ( entry->flags & kCCImplementsMouseMoved ) { - void *swallows = [entry->delegate performSelector:@selector(ccMouseMoved:) withObject:event]; - if( swallows ) - break; - } - } - } -} - -- (void)mouseDragged:(NSEvent *)event -{ - if( dispatchEvents_ ) { - tListEntry *entry, *tmp; - - DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) { - if ( entry->flags & kCCImplementsMouseDragged ) { - void *swallows = [entry->delegate performSelector:@selector(ccMouseDragged:) withObject:event]; - if( swallows ) - break; - } - } - } -} - -- (void)mouseUp:(NSEvent *)event -{ - if( dispatchEvents_ ) { - tListEntry *entry, *tmp; - - DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) { - if ( entry->flags & kCCImplementsMouseUp ) { - void *swallows = [entry->delegate performSelector:@selector(ccMouseUp:) withObject:event]; - if( swallows ) - break; - } - } - } -} - -// -// Mouse Right -// -- (void)rightMouseDown:(NSEvent *)event -{ - if( dispatchEvents_ ) { - tListEntry *entry, *tmp; - - DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) { - if ( entry->flags & kCCImplementsRightMouseDown ) { - void *swallows = [entry->delegate performSelector:@selector(ccRightMouseDown:) withObject:event]; - if( swallows ) - break; - } - } - } -} - -- (void)rightMouseDragged:(NSEvent *)event -{ - if( dispatchEvents_ ) { - tListEntry *entry, *tmp; - - DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) { - if ( entry->flags & kCCImplementsRightMouseDragged ) { - void *swallows = [entry->delegate performSelector:@selector(ccRightMouseDragged:) withObject:event]; - if( swallows ) - break; - } - } - } -} - -- (void)rightMouseUp:(NSEvent *)event -{ - if( dispatchEvents_ ) { - tListEntry *entry, *tmp; - - DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) { - if ( entry->flags & kCCImplementsRightMouseUp ) { - void *swallows = [entry->delegate performSelector:@selector(ccRightMouseUp:) withObject:event]; - if( swallows ) - break; - } - } - } -} - -// -// Mouse Other -// -- (void)otherMouseDown:(NSEvent *)event -{ - if( dispatchEvents_ ) { - tListEntry *entry, *tmp; - - DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) { - if ( entry->flags & kCCImplementsOtherMouseDown ) { - void *swallows = [entry->delegate performSelector:@selector(ccOtherMouseDown:) withObject:event]; - if( swallows ) - break; - } - } - } -} - -- (void)otherMouseDragged:(NSEvent *)event -{ - if( dispatchEvents_ ) { - tListEntry *entry, *tmp; - - DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) { - if ( entry->flags & kCCImplementsOtherMouseDragged ) { - void *swallows = [entry->delegate performSelector:@selector(ccOtherMouseDragged:) withObject:event]; - if( swallows ) - break; - } - } - } -} - -- (void)otherMouseUp:(NSEvent *)event -{ - if( dispatchEvents_ ) { - tListEntry *entry, *tmp; - - DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) { - if ( entry->flags & kCCImplementsOtherMouseUp ) { - void *swallows = [entry->delegate performSelector:@selector(ccOtherMouseUp:) withObject:event]; - if( swallows ) - break; - } - } - } -} - -// -// Scroll Wheel -// -- (void)scrollWheel:(NSEvent *)event -{ - if( dispatchEvents_ ) { - tListEntry *entry, *tmp; - - DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) { - if ( entry->flags & kCCImplementsScrollWheel ) { - void *swallows = [entry->delegate performSelector:@selector(ccScrollWheel:) withObject:event]; - if( swallows ) - break; - } - } - } -} - -// -// Mouse enter / exit -- (void)mouseExited:(NSEvent *)event -{ - if( dispatchEvents_ ) { - tListEntry *entry, *tmp; - - DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) { - if ( entry->flags & kCCImplementsMouseEntered ) { - void *swallows = [entry->delegate performSelector:@selector(ccMouseEntered:) withObject:event]; - if( swallows ) - break; - } - } - } -} - -- (void)mouseEntered:(NSEvent *)event -{ - if( dispatchEvents_ ) { - tListEntry *entry, *tmp; - - DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) { - if ( entry->flags & kCCImplementsMouseExited) { - void *swallows = [entry->delegate performSelector:@selector(ccMouseExited:) withObject:event]; - if( swallows ) - break; - } - } - } -} - - -#pragma mark CCEventDispatcher - Keyboard events - -// Keyboard events -- (void)keyDown:(NSEvent *)event -{ - if( dispatchEvents_ ) { - tListEntry *entry, *tmp; - - DL_FOREACH_SAFE( keyboardDelegates_, entry, tmp ) { - if ( entry->flags & kCCImplementsKeyDown ) { - void *swallows = [entry->delegate performSelector:@selector(ccKeyDown:) withObject:event]; - if( swallows ) - break; - } - } - } -} - -- (void)keyUp:(NSEvent *)event -{ - if( dispatchEvents_ ) { - tListEntry *entry, *tmp; - - DL_FOREACH_SAFE( keyboardDelegates_, entry, tmp ) { - if ( entry->flags & kCCImplementsKeyUp ) { - void *swallows = [entry->delegate performSelector:@selector(ccKeyUp:) withObject:event]; - if( swallows ) - break; - } - } - } -} - -- (void)flagsChanged:(NSEvent *)event -{ - if( dispatchEvents_ ) { - tListEntry *entry, *tmp; - - DL_FOREACH_SAFE( keyboardDelegates_, entry, tmp ) { - if ( entry->flags & kCCImplementsKeyUp ) { - void *swallows = [entry->delegate performSelector:@selector(ccFlagsChanged:) withObject:event]; - if( swallows ) - break; - } - } - } -} - - -#pragma mark CCEventDispatcher - Touch events - -- (void)touchesBeganWithEvent:(NSEvent *)event -{ - if (dispatchEvents_ ) { - NSLog(@"Touch Events: Not supported yet"); - } -} - -- (void)touchesMovedWithEvent:(NSEvent *)event -{ - if (dispatchEvents_ ) { - NSLog(@"Touch Events: Not supported yet"); - } -} - -- (void)touchesEndedWithEvent:(NSEvent *)event -{ - if (dispatchEvents_ ) { - NSLog(@"Touch Events: Not supported yet"); - } -} - -- (void)touchesCancelledWithEvent:(NSEvent *)event -{ - if (dispatchEvents_ ) { - NSLog(@"Touch Events: Not supported yet"); - } -} - -#pragma mark CCEventDispatcher - queue events - -#if CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD --(void) queueEvent:(NSEvent*)event selector:(SEL)selector -{ - NSAssert( eventQueueCount < QUEUE_EVENT_MAX, @"CCEventDispatcher: recompile. Increment QUEUE_EVENT_MAX value"); - - eventQueue[eventQueueCount].selector = selector; - eventQueue[eventQueueCount].event = [event copy]; - - eventQueueCount++; -} - --(void) dispatchQueuedEvents -{ - for( int i=0; i < eventQueueCount; i++ ) { - SEL sel = eventQueue[i].selector; - NSEvent *event = eventQueue[i].event; - - [self performSelector:sel withObject:event]; - - [event release]; - } - - eventQueueCount = 0; -} -#endif // CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD - - -@end - -#endif // __MAC_OS_X_VERSION_MAX_ALLOWED \ No newline at end of file diff --git a/cocos2dx/platform/mac/CCGrid_mac.cpp b/cocos2dx/platform/mac/CCGrid_mac.cpp deleted file mode 100644 index 5070acbb9e..0000000000 --- a/cocos2dx/platform/mac/CCGrid_mac.cpp +++ /dev/null @@ -1,613 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org - -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 "ccMacros.h" -#include "effects/CCGrid.h" -#include "CCDirector.h" -#include "effects/CCGrabber.h" -#include "support/ccUtils.h" - -#include "CCGL.h" -#include "CGPointExtension.h" - -namespace cocos2d -{ - // implementation of CCGridBase - - CCGridBase* CCGridBase::gridWithSize(cocos2d::ccGridSize gridSize) - { - CCGridBase *pGridBase = new CCGridBase(); - - if (pGridBase) - { - if (pGridBase->initWithSize(gridSize)) - { - pGridBase->autorelease(); - } - else - { - CCX_SAFE_RELEASE_NULL(pGridBase); - } - } - - return pGridBase; - } - - CCGridBase* CCGridBase::gridWithSize(ccGridSize gridSize, CCTexture2D *texture, bool flipped) - { - CCGridBase *pGridBase = new CCGridBase(); - - if (pGridBase) - { - if (pGridBase->initWithSize(gridSize, texture, flipped)) - { - pGridBase->autorelease(); - } - else - { - CCX_SAFE_RELEASE_NULL(pGridBase); - } - } - - return pGridBase; - } - - bool CCGridBase::initWithSize(ccGridSize gridSize, CCTexture2D *pTexture, bool bFlipped) - { - bool bRet = true; - - m_bActive = false; - m_nReuseGrid = 0; - m_sGridSize = gridSize; - - m_pTexture = pTexture; - CCX_SAFE_RETAIN(m_pTexture); - m_bIsTextureFlipped = bFlipped; - - CGSize texSize = m_pTexture->getContentSizeInPixels(); - m_obStep.x = texSize.width / m_sGridSize.x; - m_obStep.y = texSize.height / m_sGridSize.y; - - m_pGrabber = new CCGrabber(); - if (m_pGrabber) - { - m_pGrabber->grab(m_pTexture); - } - else - { - bRet = false; - } - - - calculateVertexPoints(); - - return bRet; - } - - bool CCGridBase::initWithSize(ccGridSize gridSize) - { - CCDirector *pDirector = CCDirector::sharedDirector(); - CGSize s = pDirector->getWinSizeInPixels(); - - unsigned int POTWide = ccNextPOT((unsigned int)s.width); - unsigned int POTHigh = ccNextPOT((unsigned int)s.height); - - // on mac, it use kCCTexture2DPixelFormat_RGBA8888 - CCTexture2DPixelFormat format = kCCTexture2DPixelFormat_RGBA8888; - - void *data = calloc((int)(POTWide * POTHigh * 4), 1); - if (! data) - { - CCLOG("cocos2d: CCGrid: not enough memory."); - this->release(); - return false; - } - - CCTexture2D *pTexture = new CCTexture2D(); - pTexture->initWithData(data, format, POTWide, POTHigh, s); - - free(data); - - if (! pTexture) - { - CCLOG("cocos2d: CCGrid: error creating texture"); - delete this; - return false; - } - - initWithSize(gridSize, pTexture, false); - - pTexture->release(); - - return true; - } - - CCGridBase::~CCGridBase(void) - { - CCLOGINFO("cocos2d: deallocing %p", this); - - setActive(false); - CCX_SAFE_RELEASE(m_pTexture); - CCX_SAFE_RELEASE(m_pGrabber); - } - - // properties - void CCGridBase::setActive(bool bActive) - { - m_bActive = bActive; - if (! bActive) - { - CCDirector *pDirector = CCDirector::sharedDirector(); - ccDirectorProjection proj = pDirector->getProjection(); - pDirector->setProjection(proj); - } - } - - void CCGridBase::setIsTextureFlipped(bool bFlipped) - { - if (m_bIsTextureFlipped != bFlipped) - { - m_bIsTextureFlipped = bFlipped; - calculateVertexPoints(); - } - } - - // mac can not applay land space - void CCGridBase::applyLandscape(void) - { - CCLOG("unsupported"); - } - - void CCGridBase::set2DProjection() - { - CGSize winSize = CCDirector::sharedDirector()->getWinSizeInPixels(); - - glLoadIdentity(); - glViewport((GLsizei)0, (GLsizei)0, (GLsizei)winSize.width, (GLsizei)winSize.height); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - ccglOrtho(0, winSize.width, 0, winSize.height, -1024, 1024); - glMatrixMode(GL_MODELVIEW); - } - - // This routine can be merged with Director - void CCGridBase::set3DProjection() - { - CGSize winSize = CCDirector::sharedDirector()->getDisplaySizeInPixels(); - - glViewport(0, 0, (GLsizei)winSize.width, (GLsizei)winSize.height); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - gluPerspective(60, (GLfloat)winSize.width/winSize.height, 0.5f, 1500.0f); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - gluLookAt( winSize.width/2, winSize.height/2, CCDirector::sharedDirector()->getZEye(), - winSize.width/2, winSize.height/2, 0, - 0.0f, 1.0f, 0.0f - ); - } - - void CCGridBase::beforeDraw(void) - { - set2DProjection(); - m_pGrabber->beforeRender(m_pTexture); - } - - void CCGridBase::afterDraw(cocos2d::CCNode *pTarget) - { - m_pGrabber->afterRender(m_pTexture); - - set3DProjection(); - // mac can not applay land space - //applyLandscape(); - - if (pTarget->getCamera()->getDirty()) - { - CGPoint offset = pTarget->getAnchorPointInPixels(); - - // - // XXX: Camera should be applied in the AnchorPoint - // - ccglTranslate(offset.x, offset.y, 0); - pTarget->getCamera()->locate(); - ccglTranslate(-offset.x, -offset.y, 0); - } - - glBindTexture(GL_TEXTURE_2D, m_pTexture->getName()); - - blit(); - } - - void CCGridBase::blit(void) - { - assert(0); - } - - void CCGridBase::reuse(void) - { - assert(0); - } - - void CCGridBase::calculateVertexPoints(void) - { - assert(0); - } - - // implementation of CCGrid3D - - CCGrid3D* CCGrid3D::gridWithSize(ccGridSize gridSize, CCTexture2D *pTexture, bool bFlipped) - { - CCGrid3D *pRet= new CCGrid3D(); - - if (pRet) - { - if (pRet->initWithSize(gridSize, pTexture, bFlipped)) - { - pRet->autorelease(); - } - else - { - delete pRet; - pRet = NULL; - } - } - - return pRet; - } - - CCGrid3D* CCGrid3D::gridWithSize(ccGridSize gridSize) - { - CCGrid3D *pRet= new CCGrid3D(); - - if (pRet) - { - if (pRet->initWithSize(gridSize)) - { - pRet->autorelease(); - } - else - { - delete pRet; - pRet = NULL; - } - } - - return pRet; - } - - CCGrid3D::~CCGrid3D(void) - { - free(m_pTexCoordinates); - free(m_pVertices); - free(m_pIndices); - free(m_pOriginalVertices); - } - - void CCGrid3D::blit(void) - { - int n = m_sGridSize.x * m_sGridSize.y; - - // Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY - // Needed states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_TEXTURE_COORD_ARRAY - // Unneeded states: GL_COLOR_ARRAY - glDisableClientState(GL_COLOR_ARRAY); - - glVertexPointer(3, GL_FLOAT, 0, m_pVertices); - glTexCoordPointer(2, GL_FLOAT, 0, m_pTexCoordinates); - glDrawElements(GL_TRIANGLES, n * 6, GL_UNSIGNED_SHORT, m_pIndices); - - // restore GL default state - glEnableClientState(GL_COLOR_ARRAY); - } - - void CCGrid3D::calculateVertexPoints(void) - { - float width = (float)m_pTexture->getPixelsWide(); - float height = (float)m_pTexture->getPixelsHigh(); - float imageH = m_pTexture->getContentSizeInPixels().height; - - int x, y, i; - - m_pVertices = malloc((m_sGridSize.x+1) * (m_sGridSize.y+1) * sizeof(ccVertex3F)); - m_pOriginalVertices = malloc((m_sGridSize.x+1) * (m_sGridSize.y+1) * sizeof(ccVertex3F)); - m_pTexCoordinates = malloc((m_sGridSize.x+1) * (m_sGridSize.y+1) * sizeof(CGPoint)); - m_pIndices = (GLushort*)malloc(m_sGridSize.x * m_sGridSize.y * sizeof(GLushort) * 6); - - float *vertArray = (float*)m_pVertices; - float *texArray = (float*)m_pTexCoordinates; - GLushort *idxArray = m_pIndices; - - for (x = 0; x < m_sGridSize.x; ++x) - { - for (y = 0; y < m_sGridSize.y; ++y) - { - int idx = (y * m_sGridSize.x) + x; - - float x1 = x * m_obStep.x; - float x2 = x1 + m_obStep.x; - float y1 = y * m_obStep.y; - float y2= y1 + m_obStep.y; - - GLushort a = x * (m_sGridSize.y + 1) + y; - GLushort b = (x + 1) * (m_sGridSize.y + 1) + y; - GLushort c = (x + 1) * (m_sGridSize.y + 1) + (y + 1); - GLushort d = x * (m_sGridSize.y + 1) + (y + 1); - - GLushort tempidx[6] = {a, b, d, b, c, d}; - - memcpy(&idxArray[6*idx], tempidx, 6*sizeof(GLushort)); - - int l1[4] = {a*3, b*3, c*3, d*3}; - ccVertex3F e = {x1, y1, 0}; - ccVertex3F f = {x2, y1, 0}; - ccVertex3F g = {x2, y2, 0}; - ccVertex3F h = {x1, y2, 0}; - - ccVertex3F l2[4] = {e, f, g, h}; - - int tex1[4] = {a*2, b*2, c*2, d*2}; - CGPoint tex2[4] = {ccp(x1, y1), ccp(x2, y1), ccp(x2, y2), ccp(x1, y2)}; - - for (i = 0; i < 4; ++i) - { - vertArray[l1[i]] = l2[i].x; - vertArray[l1[i] + 1] = l2[i].y; - vertArray[l1[i] + 2] = l2[i].z; - - texArray[tex1[i]] = tex2[i].x / width; - if (m_bIsTextureFlipped) - { - texArray[tex1[i] + 1] = (imageH - tex2[i].y) / height; - } - else - { - texArray[tex1[i] + 1] = tex2[i].y / height; - } - } - } - } - - memcpy(m_pOriginalVertices, m_pVertices, (m_sGridSize.x+1) * (m_sGridSize.y+1) * sizeof(ccVertex3F)); - } - - ccVertex3F CCGrid3D::vertex(ccGridSize pos) - { - int index = (pos.x * (m_sGridSize.y+1) + pos.y) * 3; - float *vertArray = (float*)m_pVertices; - - ccVertex3F vert = {vertArray[index], vertArray[index+1], vertArray[index+2]}; - - return vert; - } - - ccVertex3F CCGrid3D::originalVertex(cocos2d::ccGridSize pos) - { - int index = (pos.x * (m_sGridSize.y+1) + pos.y) * 3; - float *vertArray = (float*)m_pOriginalVertices; - - ccVertex3F vert = {vertArray[index], vertArray[index+1], vertArray[index+2]}; - - return vert; - } - - void CCGrid3D::setVertex(ccGridSize pos, ccVertex3F vertex) - { - int index = (pos.x * (m_sGridSize.y + 1) + pos.y) * 3; - float *vertArray = (float*)m_pVertices; - vertArray[index] = vertex.x; - vertArray[index+1] = vertex.y; - vertArray[index+2] = vertex.z; - } - - void CCGrid3D::reuse(void) - { - if (m_nReuseGrid > 0) - { - memcpy(m_pOriginalVertices, m_pVertices, (m_sGridSize.x+1) * (m_sGridSize.y+1) * sizeof(ccVertex3F)); - --m_nReuseGrid; - } - } - - // implementation of CCTiledGrid3D - - CCTiledGrid3D::~CCTiledGrid3D(void) - { - free(m_pTexCoordinates); - free(m_pVertices); - free(m_pOriginalVertices); - free(m_pIndices); - } - - CCTiledGrid3D* CCTiledGrid3D::gridWithSize(cocos2d::ccGridSize gridSize, cocos2d::CCTexture2D *pTexture, bool bFlipped) - { - CCTiledGrid3D *pRet= new CCTiledGrid3D(); - - if (pRet) - { - if (pRet->initWithSize(gridSize, pTexture, bFlipped)) - { - pRet->autorelease(); - } - else - { - delete pRet; - pRet = NULL; - } - } - - return pRet; - } - - CCTiledGrid3D* CCTiledGrid3D::gridWithSize(cocos2d::ccGridSize gridSize) - { - CCTiledGrid3D *pRet= new CCTiledGrid3D(); - - if (pRet) - { - if (pRet->initWithSize(gridSize)) - { - pRet->autorelease(); - } - else - { - delete pRet; - pRet = NULL; - } - } - - return pRet; - } - - void CCTiledGrid3D::blit(void) - { - int n = m_sGridSize.x * m_sGridSize.y; - - // Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY - // Needed states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_TEXTURE_COORD_ARRAY - // Unneeded states: GL_COLOR_ARRAY - glDisableClientState(GL_COLOR_ARRAY); - - glVertexPointer(3, GL_FLOAT, 0, m_pVertices); - glTexCoordPointer(2, GL_FLOAT, 0, m_pTexCoordinates); - glDrawElements(GL_TRIANGLES, n*6, GL_UNSIGNED_SHORT, m_pIndices); - - // restore default GL state - glEnableClientState(GL_COLOR_ARRAY); - } - - void CCTiledGrid3D::calculateVertexPoints(void) - { - float width = (float)m_pTexture->getPixelsWide(); - float height = (float)m_pTexture->getPixelsHigh(); - float imageH = m_pTexture->getContentSizeInPixels().height; - - int numQuads = m_sGridSize.x * m_sGridSize.y; - - m_pVertices = malloc(numQuads * 12 * sizeof(GLfloat)); - m_pOriginalVertices = malloc(numQuads * 12 * sizeof(GLfloat)); - m_pTexCoordinates = malloc(numQuads * 8 * sizeof(GLfloat)); - m_pIndices = (GLushort *)malloc(numQuads * 6 * sizeof(GLushort)); - - float *vertArray = (float*)m_pVertices; - float *texArray = (float*)m_pTexCoordinates; - GLushort *idxArray = m_pIndices; - - int x, y; - - for( x = 0; x < m_sGridSize.x; x++ ) - { - for( y = 0; y < m_sGridSize.y; y++ ) - { - float x1 = x * m_obStep.x; - float x2 = x1 + m_obStep.x; - float y1 = y * m_obStep.y; - float y2 = y1 + m_obStep.y; - - *vertArray++ = x1; - *vertArray++ = y1; - *vertArray++ = 0; - *vertArray++ = x2; - *vertArray++ = y1; - *vertArray++ = 0; - *vertArray++ = x1; - *vertArray++ = y2; - *vertArray++ = 0; - *vertArray++ = x2; - *vertArray++ = y2; - *vertArray++ = 0; - - float newY1 = y1; - float newY2 = y2; - - if (m_bIsTextureFlipped) - { - newY1 = imageH - y1; - newY2 = imageH - y2; - } - - *texArray++ = x1 / width; - *texArray++ = newY1 / height; - *texArray++ = x2 / width; - *texArray++ = newY1 / height; - *texArray++ = x1 / width; - *texArray++ = newY2 / height; - *texArray++ = x2 / width; - *texArray++ = newY2 / height; - } - } - - for (x = 0; x < numQuads; x++) - { - idxArray[x*6+0] = x * 4 + 0; - idxArray[x*6+1] = x * 4 + 1; - idxArray[x*6+2] = x * 4 + 2; - - idxArray[x*6+3] = x * 4 + 1; - idxArray[x*6+4] = x * 4 + 2; - idxArray[x*6+5] = x * 4 + 3; - } - - memcpy(m_pOriginalVertices, m_pVertices, numQuads * 12 * sizeof(GLfloat)); - } - - void CCTiledGrid3D::setTile(cocos2d::ccGridSize pos, cocos2d::ccQuad3 coords) - { - int idx = (m_sGridSize.y * pos.x + pos.y) * 4 * 3; - float *vertArray = (float*)m_pVertices; - memcpy(&vertArray[idx], &coords, sizeof(ccQuad3)); - } - - ccQuad3 CCTiledGrid3D::originalTile(ccGridSize pos) - { - int idx = (m_sGridSize.y * pos.x + pos.y) * 4 * 3; - float *vertArray = (float*)m_pOriginalVertices; - - ccQuad3 ret; - memcpy(&ret, &vertArray[idx], sizeof(ccQuad3)); - - return ret; - } - - ccQuad3 CCTiledGrid3D::tile(cocos2d::ccGridSize pos) - { - int idx = (m_sGridSize.y * pos.x + pos.y) * 4 * 3; - float *vertArray = (float*)m_pVertices; - - ccQuad3 ret; - memcpy(&ret, &vertArray[idx], sizeof(ccQuad3)); - - return ret; - } - - void CCTiledGrid3D::reuse(void) - { - if (m_nReuseGrid > 0) - { - int numQuads = m_sGridSize.x * m_sGridSize.y; - - memcpy(m_pOriginalVertices, m_pVertices, numQuads * 12 * sizeof(GLfloat)); - --m_nReuseGrid; - } - } -} // end of namespace cocos2d diff --git a/cocos2dx/platform/mac/CCLayer_mac.cpp b/cocos2dx/platform/mac/CCLayer_mac.cpp deleted file mode 100644 index 2aad320dcd..0000000000 --- a/cocos2dx/platform/mac/CCLayer_mac.cpp +++ /dev/null @@ -1,678 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org - -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 -#include "CCLayer.h" -#include "CCEventDispatcher.h" -#include "CCKeypadDispatcher.h" -#include "CCDirector.h" -#include "CGPointExtension.h" -namespace cocos2d { - -// CCLayer -CCLayer::CCLayer() -:m_bIsTouchEnabled(false) -,m_bIsAccelerometerEnabled(false) -,m_bIsKeypadEnabled(false) -,m_bIsMouseEnabled(false) -,m_bIsKeyboardEnabled(false) -{ - m_eTouchDelegateType = ccTouchDeletateAllBit; - m_tAnchorPoint = ccp(0.5f, 0.5f); - m_bIsRelativeAnchorPoint = false; -} - -CCLayer::~CCLayer() -{ -} - -bool CCLayer::init() -{ - bool bRet = false; - do - { - CCDirector * pDirector; - CCX_BREAK_IF( ! (pDirector = CCDirector::sharedDirector()) ); - this->setContentSize(pDirector->getWinSize()); - // success - bRet = true; - } while (0); - return bRet; -} - -CCLayer *CCLayer::node() -{ - CCLayer *pRet = new CCLayer(); - if (pRet && pRet->init()) - { - pRet->autorelease(); - return pRet; - } - else - { - CCX_SAFE_DELETE(pRet) - return NULL; - } -} - -/// Touch and Accelerometer related - -void CCLayer::registerWithTouchDispatcher() -{ - CCLOG("cocos2d: CCLayer: unsupported!"); -} - -void CCLayer::destroy(void) -{ - this->release(); -} - -void CCLayer::keep(void) -{ - this->retain(); -} - -void CCLayer::AccelerometerDestroy(void) -{ - this->release(); -} - -void CCLayer::AccelerometerKeep(void) -{ - this->retain(); -} - -void CCLayer::KeypadDestroy() -{ - this->release(); -} - -void CCLayer::KeypadKeep() -{ - this->retain(); -} - -void CCLayer::KeyboardDestroy(void) -{ - this->release(); -} - -void CCLayer::KeyboardKeep(void) -{ - this->retain(); -} - -void CCLayer::MouseDestroy() -{ - this->release(); -} - -void CCLayer::MouseKeep() -{ - this->retain(); -} - -bool CCLayer::getIsMouseEnabled() -{ - return m_bIsMouseEnabled; -} - -void CCLayer::setIsMouseEnabled(bool enabled) -{ - if( m_bIsMouseEnabled != enabled ) - { - m_bIsMouseEnabled = enabled; - - if( m_bIsRunning ) - { - if( enabled ) - { - CCEventDispatcher::sharedDispatcher()->addMouseDelegate(this, mouseDelegatePriority()); - } - else - { - CCEventDispatcher::sharedDispatcher()->removeMouseDelegate(this); - } - } - } -} - -bool CCLayer::getIsKeyboardEnabled() -{ - return m_bIsKeyboardEnabled; -} - -void CCLayer::setIsKeyboardEnabled(bool enabled) -{ - if( m_bIsKeyboardEnabled != enabled ) - { - m_bIsKeyboardEnabled = enabled; - - if( m_bIsRunning ) - { - if( enabled ) - { - CCEventDispatcher::sharedDispatcher()->addKeyboardDelegate(this, keyboardDelegatePriority()); - } - else - { - CCEventDispatcher::sharedDispatcher()->removeKeyboardDelegate(this); - } - } - } -} - -/// isTouchEnabled getter -bool CCLayer::getIsTouchEnabled() -{ - return m_bIsTouchEnabled; -} -/// isTouchEnabled setter -void CCLayer::setIsTouchEnabled(bool enabled) -{ - CCLOG("cocos2d: CCLayer: unsupported!"); -} - -/// isAccelerometerEnabled getter -bool CCLayer::getIsAccelerometerEnabled() -{ - return m_bIsAccelerometerEnabled; -} -/// isAccelerometerEnabled setter -void CCLayer::setIsAccelerometerEnabled(bool enabled) -{ - CCLOG("cocos2d: CCLayer: unsupported!"); -} - -/// isKeypadEnabled getter -bool CCLayer::getIsKeypadEnabled() -{ - return m_bIsKeypadEnabled; -} -/// isKeypadEnabled setter -void CCLayer::setIsKeypadEnabled(bool enabled) -{ - if (enabled != m_bIsKeypadEnabled) - { - m_bIsKeypadEnabled = enabled; - - if (m_bIsRunning) - { - if (enabled) - { - CCKeypadDispatcher::sharedDispatcher()->addDelegate(this); - } - else - { - CCKeypadDispatcher::sharedDispatcher()->removeDelegate(this); - } - } - } -} - - -/// Callbacks -void CCLayer::onEnter() -{ - if(m_bIsMouseEnabled) - { - CCEventDispatcher::sharedDispatcher()->addMouseDelegate(this, mouseDelegatePriority()); - } - - if( m_bIsKeyboardEnabled) - { - CCEventDispatcher::sharedDispatcher()->addKeyboardDelegate(this, keyboardDelegatePriority()); - } - - // then iterate over all the children - CCNode::onEnter(); - - // add this layer to concern the kaypad msg - if (m_bIsKeypadEnabled) - { - CCKeypadDispatcher::sharedDispatcher()->addDelegate(this); - } -} - -void CCLayer::onExit() -{ - if(m_bIsMouseEnabled) - { - CCEventDispatcher::sharedDispatcher()->removeMouseDelegate(this, mouseDelegatePriority()); - } - - if( m_bIsKeyboardEnabled) - { - CCEventDispatcher::sharedDispatcher()->removeKeyboardDelegate(this, keyboardDelegatePriority()); - } - - // remove this layer from the delegates who concern the kaypad msg - if (m_bIsKeypadEnabled) - { - CCKeypadDispatcher::sharedDispatcher()->removeDelegate(this); - } - - CCNode::onExit(); -} - -void CCLayer::onEnterTransitionDidFinish() -{ - CCNode::onEnterTransitionDidFinish(); -} - -bool CCLayer::ccTouchBegan(CCTouch *pTouch, UIEvent *pEvent) -{ - CCLOG("cocos2d: CCLayer: unsupported!"); - return false; -} - -// -// ColorLayer -// -CCLayerColor::CCLayerColor() -{ -} -CCLayerColor::~CCLayerColor() -{ -} - -// Opacity and RGB color protocol -/// opacity getter -GLubyte CCLayerColor::getOpacity() -{ - return m_cOpacity; -} -/// opacity setter -void CCLayerColor::setOpacity(GLubyte var) -{ - m_cOpacity = var; - updateColor(); -} - -/// color getter -ccColor3B CCLayerColor::getColor() -{ - return m_tColor; -} - -/// color setter -void CCLayerColor::setColor(ccColor3B var) -{ - m_tColor = var; - updateColor(); -} - - -/// blendFunc getter -ccBlendFunc CCLayerColor::getBlendFunc() -{ - return m_tBlendFunc; -} -/// blendFunc setter -void CCLayerColor::setBlendFunc(ccBlendFunc var) -{ - m_tBlendFunc = var; -} - - -CCLayerColor * CCLayerColor::layerWithColorWidthHeight(ccColor4B color, GLfloat width, GLfloat height) -{ - CCLayerColor * pLayer = new CCLayerColor(); - if( pLayer && pLayer->initWithColorWidthHeight(color,width,height)) - { - pLayer->autorelease(); - return pLayer; - } - CCX_SAFE_DELETE(pLayer); - return NULL; -} -CCLayerColor * CCLayerColor::layerWithColor(ccColor4B color) -{ - CCLayerColor * pLayer = new CCLayerColor(); - if(pLayer && pLayer->initWithColor(color)) - { - pLayer->autorelease(); - return pLayer; - } - CCX_SAFE_DELETE(pLayer); - return NULL; -} - -bool CCLayerColor::initWithColorWidthHeight(ccColor4B color, GLfloat width, GLfloat height) -{ - // default blend function - m_tBlendFunc.src = CC_BLEND_SRC; - m_tBlendFunc.dst = CC_BLEND_DST; - - m_tColor.r = color.r; - m_tColor.g = color.g; - m_tColor.b = color.b; - m_cOpacity = color.a; - - for (unsigned int i=0; iupdateColor(); - this->setContentSize(CGSizeMake(width,height)); - return true; -} - -bool CCLayerColor::initWithColor(ccColor4B color) -{ - CGSize s = CCDirector::sharedDirector()->getWinSize(); - this->initWithColorWidthHeight(color, s.width, s.height); - return true; -} - -/// override contentSize -void CCLayerColor::setContentSize(CGSize size) -{ - m_pSquareVertices[2] = size.width * CC_CONTENT_SCALE_FACTOR(); - m_pSquareVertices[5] = size.height * CC_CONTENT_SCALE_FACTOR(); - m_pSquareVertices[6] = size.width * CC_CONTENT_SCALE_FACTOR(); - m_pSquareVertices[7] = size.height * CC_CONTENT_SCALE_FACTOR(); - - CCLayer::setContentSize(size); -} - -void CCLayerColor::changeWidthAndHeight(GLfloat w ,GLfloat h) -{ - this->setContentSize(CGSizeMake(w, h)); -} - -void CCLayerColor::changeWidth(GLfloat w) -{ - this->setContentSize(CGSizeMake(w, m_tContentSize.height)); -} - -void CCLayerColor::changeHeight(GLfloat h) -{ - this->setContentSize(CGSizeMake(m_tContentSize.width, h)); -} - -void CCLayerColor::updateColor() -{ - for( unsigned int i=0; i < 4; i++ ) - { - m_pSquareColors[i * 4] = m_tColor.r; - m_pSquareColors[i * 4 + 1] = m_tColor.g; - m_pSquareColors[i * 4 + 2] = m_tColor.b; - m_pSquareColors[i * 4 + 3] = m_cOpacity; - } -} - -void CCLayerColor::draw() -{ - // Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY - // Needed states: GL_VERTEX_ARRAY, GL_COLOR_ARRAY - // Unneeded states: GL_TEXTURE_2D, GL_TEXTURE_COORD_ARRAY - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glDisable(GL_TEXTURE_2D); - - glVertexPointer(2, GL_FLOAT, 0, m_pSquareVertices); - glColorPointer(4, GL_UNSIGNED_BYTE, 0, m_pSquareColors); - - bool newBlend = false; - if( m_tBlendFunc.src != CC_BLEND_SRC || m_tBlendFunc.dst != CC_BLEND_DST ) { - newBlend = true; - glBlendFunc(m_tBlendFunc.src, m_tBlendFunc.dst); - } - else if( m_cOpacity != 255 ) { - newBlend = true; - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - } - - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - - if( newBlend ) - glBlendFunc(CC_BLEND_SRC, CC_BLEND_DST); - - // restore default GL state - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glEnable(GL_TEXTURE_2D); -} - -// -// CCLayerGradient -// -CCLayerGradient* CCLayerGradient::layerWithColor(ccColor4B start, ccColor4B end) -{ - CCLayerGradient * pLayer = new CCLayerGradient(); - if( pLayer && pLayer->initWithColor(start, end)) - { - pLayer->autorelease(); - return pLayer; - } - CCX_SAFE_DELETE(pLayer); - return NULL; -} - -CCLayerGradient* CCLayerGradient::layerWithColor(ccColor4B start, ccColor4B end, CGPoint v) -{ - CCLayerGradient * pLayer = new CCLayerGradient(); - if( pLayer && pLayer->initWithColor(start, end, v)) - { - pLayer->autorelease(); - return pLayer; - } - CCX_SAFE_DELETE(pLayer); - return NULL; -} - -bool CCLayerGradient::initWithColor(ccColor4B start, ccColor4B end) -{ - return initWithColor(start, end, ccp(0, -1)); -} - -bool CCLayerGradient::initWithColor(ccColor4B start, ccColor4B end, CGPoint v) -{ - m_endColor.r = end.r; - m_endColor.g = end.g; - m_endColor.b = end.b; - - m_cEndOpacity = end.a; - m_cStartOpacity = start.a; - m_AlongVector = v; - - start.a = 255; - return CCLayerColor::initWithColor(start); -} - -void CCLayerGradient::updateColor() -{ - CCLayerColor::updateColor(); - - float h = sqrtf(m_AlongVector.x * m_AlongVector.x + m_AlongVector.y * m_AlongVector.y); - if (h == 0) - return; - - double c = sqrt(2.0); - CGPoint u = ccp(m_AlongVector.x / h, m_AlongVector.y / h); - - float opacityf = (float)m_cOpacity / 255.0f; - - ccColor4B S = { - (unsigned char) m_tColor.r, - (unsigned char) m_tColor.g, - (unsigned char) m_tColor.b, - (unsigned char) (m_cStartOpacity * opacityf) - }; - - ccColor4B E = { - (unsigned char) m_endColor.r, - (unsigned char) m_endColor.g, - (unsigned char) m_endColor.b, - (unsigned char) (m_cEndOpacity * opacityf) - }; - - // (-1, -1) - m_pSquareColors[0] = (GLubyte) (E.r + (S.r - E.r) * ((c + u.x + u.y) / (2.0f * c))); - m_pSquareColors[1] = (GLubyte) (E.g + (S.g - E.g) * ((c + u.x + u.y) / (2.0f * c))); - m_pSquareColors[2] = (GLubyte) (E.b + (S.b - E.b) * ((c + u.x + u.y) / (2.0f * c))); - m_pSquareColors[3] = (GLubyte) (E.a + (S.a - E.a) * ((c + u.x + u.y) / (2.0f * c))); - // (1, -1) - m_pSquareColors[4] = (GLubyte) (E.r + (S.r - E.r) * ((c - u.x + u.y) / (2.0f * c))); - m_pSquareColors[5] = (GLubyte) (E.g + (S.g - E.g) * ((c - u.x + u.y) / (2.0f * c))); - m_pSquareColors[6] = (GLubyte) (E.b + (S.b - E.b) * ((c - u.x + u.y) / (2.0f * c))); - m_pSquareColors[7] = (GLubyte) (E.a + (S.a - E.a) * ((c - u.x + u.y) / (2.0f * c))); - // (-1, 1) - m_pSquareColors[8] = (GLubyte) (E.r + (S.r - E.r) * ((c + u.x - u.y) / (2.0f * c))); - m_pSquareColors[9] = (GLubyte) (E.g + (S.g - E.g) * ((c + u.x - u.y) / (2.0f * c))); - m_pSquareColors[10] = (GLubyte) (E.b + (S.b - E.b) * ((c + u.x - u.y) / (2.0f * c))); - m_pSquareColors[11] = (GLubyte) (E.a + (S.a - E.a) * ((c + u.x - u.y) / (2.0f * c))); - // (1, 1) - m_pSquareColors[12] = (GLubyte) (E.r + (S.r - E.r) * ((c - u.x - u.y) / (2.0f * c))); - m_pSquareColors[13] = (GLubyte) (E.g + (S.g - E.g) * ((c - u.x - u.y) / (2.0f * c))); - m_pSquareColors[14] = (GLubyte) (E.b + (S.b - E.b) * ((c - u.x - u.y) / (2.0f * c))); - m_pSquareColors[15] = (GLubyte) (E.a + (S.a - E.a) * ((c - u.x - u.y) / (2.0f * c))); -} - -ccColor3B CCLayerGradient::getStartColor() -{ - return m_tColor; -} - -void CCLayerGradient::setStartColor(ccColor3B colors) -{ - setColor(colors); -} - -void CCLayerGradient::setEndColor(ccColor3B colors) -{ - m_endColor = colors; - updateColor(); -} - -ccColor3B CCLayerGradient::getEndColor() -{ - return m_endColor; -} - -void CCLayerGradient::setStartOpacity(GLubyte o) -{ - m_cStartOpacity = o; - updateColor(); -} - -GLubyte CCLayerGradient::getStartOpacity() -{ - return m_cStartOpacity; -} - -void CCLayerGradient::setEndOpacity(GLubyte o) -{ - m_cEndOpacity = o; - updateColor(); -} - -GLubyte CCLayerGradient::getEndOpacity() -{ - return m_cEndOpacity; -} - -void CCLayerGradient::setAlongVector(CGPoint var) -{ - m_AlongVector = var; - updateColor(); -} - -CGPoint CCLayerGradient::getAlongVector() -{ - return m_AlongVector; -} - -/// MultiplexLayer - -CCMultiplexLayer::CCMultiplexLayer() -{ -} -CCMultiplexLayer::~CCMultiplexLayer() -{ - m_pLayers->release(); -} - -CCMultiplexLayer * CCMultiplexLayer::layerWithLayers(CCLayer * layer, ...) -{ - va_list args; - va_start(args,layer); - - CCMultiplexLayer * pMultiplexLayer = new CCMultiplexLayer(); - if(pMultiplexLayer && pMultiplexLayer->initWithLayers(layer, args)) - { - pMultiplexLayer->autorelease(); - va_end(args); - return pMultiplexLayer; - } - va_end(args); - CCX_SAFE_DELETE(pMultiplexLayer); - return NULL; -} - -bool CCMultiplexLayer::initWithLayers(CCLayer *layer, va_list params) -{ - m_pLayers = new NSMutableArray(5); - //m_pLayers->retain(); - - m_pLayers->addObject(layer); - - CCLayer *l = va_arg(params,CCLayer*); - while( l ) { - m_pLayers->addObject(l); - l = va_arg(params,CCLayer*); - } - - m_nEnabledLayer = 0; - this->addChild(m_pLayers->getObjectAtIndex(m_nEnabledLayer)); - - return true; -} - - -void CCMultiplexLayer::switchTo(unsigned int n) -{ - NSAssert( n < m_pLayers->count(), "Invalid index in MultiplexLayer switchTo message" ); - - this->removeChild(m_pLayers->getObjectAtIndex(m_nEnabledLayer), true); - - m_nEnabledLayer = n; - - this->addChild(m_pLayers->getObjectAtIndex(n)); -} - -void CCMultiplexLayer::switchToAndReleaseMe(unsigned int n) -{ - NSAssert( n < m_pLayers->count(), "Invalid index in MultiplexLayer switchTo message" ); - - this->removeChild(m_pLayers->getObjectAtIndex(m_nEnabledLayer), true); - - //[layers replaceObjectAtIndex:enabledLayer withObject:[NSNull null]]; - m_pLayers->replaceObjectAtIndex(m_nEnabledLayer, NULL); - - m_nEnabledLayer = n; - - this->addChild(m_pLayers->getObjectAtIndex(n)); -} -}//namespace cocos2d diff --git a/cocos2dx/platform/mac/CCMenu_mac.cpp b/cocos2dx/platform/mac/CCMenu_mac.cpp deleted file mode 100644 index 3c253e2d71..0000000000 --- a/cocos2dx/platform/mac/CCMenu_mac.cpp +++ /dev/null @@ -1,627 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org - -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 "CCMenu.h" -#include "CCDirector.h" -#include "CCXApplication.h" -#include "CGPointExtension.h" -#include "CCTouchDispatcher.h" -#include "CCTouch.h" -#include "platform/CCXMath.h" - -#include -#include -using namespace std; - -namespace cocos2d{ - - enum - { - kDefaultPadding = 5, - }; - - // - //CCMenu - // - CCMenu * CCMenu::menuWithItems(CCMenuItem* item, ...) - { - va_list args; - va_start(args,item); - CCMenu *pRet = new CCMenu(); - if (pRet && pRet->initWithItems(item, args)) - { - pRet->autorelease(); - va_end(args); - return pRet; - } - va_end(args); - CCX_SAFE_DELETE(pRet) - return NULL; - } - - bool CCMenu::initWithItems(CCMenuItem* item, va_list args) - { - if (CCLayer::init()) - { - this->m_bIsMouseEnabled = true; - - // menu in the center of the screen - CGSize s = CCDirector::sharedDirector()->getWinSize(); - - this->m_bIsRelativeAnchorPoint = false; - m_tAnchorPoint = ccp(0.5f, 0.5f); - this->setContentSize(s); - - // XXX: in v0.7, winSize should return the visible size - // XXX: so the bar calculation should be done there - setPosition(ccp(s.width/2, s.height/2)); - - int z=0; - - if (item) - { - this->addChild(item, z); - CCMenuItem *i = va_arg(args, CCMenuItem*); - while (i) - { - z++; - this->addChild(i, z); - i = va_arg(args, CCMenuItem*); - } - } - // [self alignItemsVertically]; - - m_pSelectedItem = NULL; - m_eState = kCCMenuStateWaiting; - return true; - } - - return false; - } - - /* - * override add: - */ - CCNode * CCMenu::addChild(CCNode * child, int zOrder) - { - return CCLayer::addChild(child, zOrder); - } - - CCNode * CCMenu::addChild(CCNode * child, int zOrder, int tag) - { - // we can not use RTTI, so we do not known the type of object - /*NSAssert( dynamic_cast(child) != NULL, L"Menu only supports MenuItem objects as children");*/ - return CCLayer::addChild(child, zOrder, tag); - } - - void CCMenu::onExit() - { - if (m_eState == kCCMenuStateTrackingTouch) - { - m_pSelectedItem->unselected(); - m_eState = kCCMenuStateWaiting; - m_pSelectedItem = NULL; - } - - CCLayer::onExit(); - } - - void CCMenu::registerWithTouchDispatcher() - { - CCLOG("cocos2d: CCMenu: unsupported"); - } - - CCMenuItem* CCMenu::itemForTouch(CCTouch * touch) - { - CCLOG("cocos2d: CCMenu: unsupported"); - return NULL; - } - - bool CCMenu::ccTouchBegan(CCTouch* touch, UIEvent* event) - { - CCLOG("cocos2d: CCMenu: unsupported"); - return false; - } - - void CCMenu::ccTouchEnded(CCTouch* touch, UIEvent* event) - { - CCLOG("cocos2d: CCMenu: unsupported"); - } - - void CCMenu::ccTouchCancelled(CCTouch *touch, UIEvent* event) - { - CCLOG("cocos2d: CCMenu: unsupported"); - } - - void CCMenu::ccTouchMoved(CCTouch* touch, UIEvent* event) - { - CCLOG("cocos2d: CCMenu: unsupported"); - } - - //Menu - Events - int CCMenu::mouseDelegatePriority() - { - return -1;/** @todo upto-0.99.5 use NSIntegerMin+1 instead*/ - } - - CCMenuItem* CCMenu::itemForMouseEvent(NSEvent * pEvent) - { - CGPoint touchLocation = CCDirector::sharedDirector()->convertEventToGL(pEvent); - - if (m_pChildren && m_pChildren->count() > 0) - { - NSMutableArray::NSMutableArrayIterator it; - for (it = m_pChildren->begin(); it != m_pChildren->end(); ++it) - { - if (! *it) - { - break; - } - - if ((*it)->getIsVisible() && ((CCMenuItem*)(*it))->getIsEnabled()) - { - CGPoint local = (*it)->convertToNodeSpace(touchLocation); - - CGRect r = ((CCMenuItem*)(*it))->rect(); - r.origin = CGPointZero; - - if (CGRect::CGRectContainsPoint(r, local)) - { - return (CCMenuItem*)(*it); - } - } - } - } - - return NULL; - } - - bool CCMenu::ccMouseUp(NSEvent * pEvent) - { - if (m_pSelectedItem) - { - m_pSelectedItem->unselected(); - m_pSelectedItem->activate(); - - m_eState = kCCMenuStateWaiting; - return true; - } - - return false; - } - - bool CCMenu::ccMouseDown(NSEvent * pEvent) - { - if (! getIsVisible()) - { - return false; - } - - m_pSelectedItem = itemForMouseEvent(pEvent); - m_pSelectedItem->selected(); - - if (m_pSelectedItem) - { - m_eState = kCCMenuStateTrackingTouch; - return true; - } - - return false; - } - - bool CCMenu::ccMouseDragged(NSEvent * pEvent) - { - CCMenuItem* currentItem = itemForMouseEvent(pEvent); - - if (currentItem && currentItem != m_pSelectedItem) - { - if (m_pSelectedItem) - { - m_pSelectedItem->unselected(); - } - - m_pSelectedItem = currentItem; - m_pSelectedItem->selected(); - } - - if (currentItem && m_eState == kCCMenuStateTrackingTouch) - { - return true; - } - - return false; - } - - void CCMenu::destroy(void) - { - release(); - } - - void CCMenu::keep(void) - { - retain(); - } - - //Menu - Alignment - void CCMenu::alignItemsVertically() - { - return this->alignItemsVerticallyWithPadding(kDefaultPadding); - } - - void CCMenu::alignItemsVerticallyWithPadding(float padding) - { - float height = -padding; - if (m_pChildren && m_pChildren->count() > 0) - { - NSMutableArray::NSMutableArrayIterator it; - for (it = m_pChildren->begin(); it != m_pChildren->end(); ++it) - { - if (!(*it)) - { - break; - } - - height += (*it)->getContentSize().height * (*it)->getScaleY() + padding; - } - } - - float y = height / 2.0f; - if (m_pChildren && m_pChildren->count() > 0) - { - NSMutableArray::NSMutableArrayIterator it; - for (it = m_pChildren->begin(); it != m_pChildren->end(); ++it) - { - if (!(*it)) - { - break; - } - - (*it)->setPosition(ccp(0, y - (*it)->getContentSize().height * (*it)->getScaleY() / 2.0f)); - y -= (*it)->getContentSize().height * (*it)->getScaleY() + padding; - } - } - } - - void CCMenu::alignItemsHorizontally(void) - { - return this->alignItemsHorizontallyWithPadding(kDefaultPadding); - } - - void CCMenu::alignItemsHorizontallyWithPadding(float padding) - { - - float width = -padding; - if (m_pChildren && m_pChildren->count() > 0) - { - NSMutableArray::NSMutableArrayIterator it; - for (it = m_pChildren->begin(); it != m_pChildren->end(); ++it) - { - if (!(*it)) - { - break; - } - - width += (*it)->getContentSize().width * (*it)->getScaleX() + padding; - } - } - - float x = -width / 2.0f; - if (m_pChildren && m_pChildren->count() > 0) - { - NSMutableArray::NSMutableArrayIterator it; - for (it = m_pChildren->begin(); it != m_pChildren->end(); ++it) - { - if (!(*it)) - { - break; - } - - (*it)->setPosition(ccp(x + (*it)->getContentSize().width * (*it)->getScaleX() / 2.0f, 0)); - x += (*it)->getContentSize().width * (*it)->getScaleX() + padding; - } - } - } - - void CCMenu::alignItemsInColumns(unsigned int columns, ...) - { - va_list args; - va_start(args, columns); - - this->alignItemsInColumns(columns, args); - - va_end(args); - } - - void CCMenu::alignItemsInColumns(unsigned int columns, va_list args) - { - vector rows; - while (columns) - { - rows.push_back(columns); - columns = va_arg(args, unsigned int); - } - - int height = -5; - unsigned int row = 0; - unsigned int rowHeight = 0; - unsigned int columnsOccupied = 0; - unsigned int rowColumns; - - if (m_pChildren && m_pChildren->count() > 0) - { - NSMutableArray::NSMutableArrayIterator it; - for (it = m_pChildren->begin(); it != m_pChildren->end(); ++it) - { - // if it has no value, break - if (! *it) - { - break; - } - - assert(row < rows.size()); - - rowColumns = rows[row]; - // can not have zero columns on a row - assert(rowColumns); - - float tmp = (*it)->getContentSize().height; - rowHeight = (unsigned int)((rowHeight >= tmp || CCXMath::isnanCocos2d(tmp)) ? rowHeight : tmp); - - ++columnsOccupied; - if (columnsOccupied >= rowColumns) - { - height += rowHeight + 5; - - columnsOccupied = 0; - rowHeight = 0; - ++row; - } - } - } - - // check if too many rows/columns for available menu items - assert(! columnsOccupied); - - CGSize winSize = CCDirector::sharedDirector()->getWinSize(); - - row = 0; - rowHeight = 0; - rowColumns = 0; - float w; - float x; - float y = (float)(height / 2); - - if (m_pChildren && m_pChildren->count() > 0) - { - NSMutableArray::NSMutableArrayIterator it; - for (it = m_pChildren->begin(); it != m_pChildren->end(); ++it) - { - if (! *it) - { - break; - } - - if (rowColumns == 0) - { - rowColumns = rows[row]; - w = winSize.width / (1 + rowColumns); - x = w; - } - - float tmp = (*it)->getContentSize().height; - rowHeight = (unsigned int)((rowHeight >= tmp || CCXMath::isnanCocos2d(tmp)) ? rowHeight : tmp); - - (*it)->setPosition(ccp(x - winSize.width / 2, - y - (*it)->getContentSize().height / 2)); - - x += w + 10; - ++columnsOccupied; - - if (columnsOccupied >= rowColumns) - { - y -= rowHeight + 5; - - columnsOccupied = 0; - rowColumns = 0; - rowHeight = 0; - ++row; - } - } - } - } - - void CCMenu::alignItemsInRows(unsigned int rows, ...) - { - va_list args; - va_start(args, rows); - - this->alignItemsInColumns(rows, args); - - va_end(args); - } - - void CCMenu::alignItemsInRows(unsigned int rows, va_list args) - { - vector columns; - while (rows) - { - columns.push_back(rows); - rows = va_arg(args, unsigned int); - } - - vector columnWidths; - vector columnHeights; - - int width = -10; - int columnHeight = -5; - unsigned int column = 0; - unsigned int columnWidth = 0; - unsigned int rowsOccupied = 0; - unsigned int columnRows; - - if (m_pChildren && m_pChildren->count() > 0) - { - NSMutableArray::NSMutableArrayIterator it; - for (it = m_pChildren->begin(); it != m_pChildren->end(); ++it) - { - if (! *it) - { - break; - } - - // check if too many menu items for the amount of rows/columns - assert(column < columns.size()); - - columnRows = columns[column]; - // can't have zero rows on a column - assert(columnRows); - - // columnWidth = fmaxf(columnWidth, [item contentSize].width); - float tmp = (*it)->getContentSize().width; - columnWidth = (unsigned int)((columnWidth >= tmp || CCXMath::isnanCocos2d(tmp)) ? columnWidth : tmp); - - columnHeight += (int)((*it)->getContentSize().height + 5); - ++rowsOccupied; - - if (rowsOccupied >= columnRows) - { - columnWidths.push_back(columnWidth); - columnHeights.push_back(columnHeight); - width += columnWidth + 10; - - rowsOccupied = 0; - columnWidth = 0; - columnHeight = -5; - ++column; - } - } - } - - // check if too many rows/columns for available menu items. - assert(! rowsOccupied); - - CGSize winSize = CCDirector::sharedDirector()->getWinSize(); - - column = 0; - columnWidth = 0; - columnRows = 0; - float x = (float)(-width / 2); - float y; - - if (m_pChildren && m_pChildren->count() > 0) - { - NSMutableArray::NSMutableArrayIterator it; - for (it = m_pChildren->begin(); it != m_pChildren->end(); ++it) - { - if (! *it) - { - break; - } - - if (columnRows == 0) - { - columnRows = columns[column]; - y = (float) columnHeights[column]; - } - - // columnWidth = fmaxf(columnWidth, [item contentSize].width); - float tmp = (*it)->getContentSize().width; - columnWidth = (unsigned int)((columnWidth >= tmp || CCXMath::isnanCocos2d(tmp)) ? columnWidth : tmp); - - (*it)->setPosition(ccp(x + columnWidths[column] / 2, - y - winSize.height / 2)); - - y -= (*it)->getContentSize().height + 10; - ++rowsOccupied; - - if (rowsOccupied >= columnRows) - { - x += columnWidth + 5; - rowsOccupied = 0; - columnRows = 0; - columnWidth = 0; - ++column; - } - } - } - } - - // Opacity Protocol - - /** Override synthesized setOpacity to recurse items */ - void CCMenu::setOpacity(GLubyte var) - { - m_cOpacity = var; - - if (m_pChildren && m_pChildren->count() > 0) - { - NSMutableArray::NSMutableArrayIterator it; - for (it = m_pChildren->begin(); it != m_pChildren->end(); ++it) - { - if (! *it) - { - break; - } - - CCRGBAProtocol *pRGBAProtocol = (*it)->convertToRGBAProtocol(); - if (pRGBAProtocol) - { - pRGBAProtocol->setOpacity(m_cOpacity); - } - } - } - } - - GLubyte CCMenu::getOpacity(void) - { - return m_cOpacity; - } - - void CCMenu::setColor(cocos2d::ccColor3B var) - { - m_tColor = var; - - if (m_pChildren && m_pChildren->count() > 0) - { - NSMutableArray::NSMutableArrayIterator it; - for (it = m_pChildren->begin(); it != m_pChildren->end(); ++it) - { - if (! *it) - { - break; - } - - CCRGBAProtocol *pRGBAProtocol = (*it)->convertToRGBAProtocol(); - if (pRGBAProtocol) - { - pRGBAProtocol->setColor(m_tColor); - } - } - } - } - - ccColor3B CCMenu::getColor(void) - { - return m_tColor; - } -} diff --git a/cocos2dx/platform/mac/CCNS_mac.mm b/cocos2dx/platform/mac/CCNS_mac.mm deleted file mode 100644 index 4f78ebb88c..0000000000 --- a/cocos2dx/platform/mac/CCNS_mac.mm +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org - -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 "platform/CCNS.h" -#import -#import - -static cocos2d::CGRect static_CCRectFromString(const char* pszContent) -{ - CGRect rect = NSRectToCGRect(NSRectFromString([NSString stringWithUTF8String: pszContent])); - cocos2d::CGRect ret(rect.x, rect.y, rect.width, rect.height); - - return ret; -} - -static cocos2d::CGPoint static_CCPointFromString(const char* pszContent) -{ - CGPoint point = NSPointToCGPoint(NSPointFromString([NSString stringWithUTF8String: pszContent])); - cocos2d::CGPoint ret(point.x, point.y); - - return ret; -} - -static cocos2d::CGSize static_CCSizeFromString(const char* pszContent) -{ - CGSize size = NSSizeToCGSize(NSSizeFromString([NSString stringWithUTF8String: pszContent])); - cocos2d::CGSize ret(size.width, size.height); - - return ret; -} - -///@todo implement the functions -namespace cocos2d -{ - CGRect CCRectFromString(const char* pszContent) - { - return static_CCRectFromString(pszContent); - } - - CGPoint CCPointFromString(const char* pszContent) - { - return static_CCPointFromString(pszContent); - } - - CGSize CCSizeFromString(const char* pszContent) - { - return static_CCSizeFromString(pszContent); - } -} \ No newline at end of file diff --git a/cocos2dx/platform/mac/CCNode_mac.cpp b/cocos2dx/platform/mac/CCNode_mac.cpp deleted file mode 100644 index cdc110c4d1..0000000000 --- a/cocos2dx/platform/mac/CCNode_mac.cpp +++ /dev/null @@ -1,1084 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org - -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 "CCNode.h" -#include "CCGrid.h" -#include "CGPointExtension.h" -#include "support/TransformUtils.h" -#include "CCCamera.h" -#include "effects/CCGrid.h" -#include "CCDirector.h" -#include "CCScheduler.h" -#include "CCTouch.h" -#include "CCActionManager.h" - -#if CC_COCOSNODE_RENDER_SUBPIXEL -#define RENDER_IN_SUBPIXEL -#else -#define RENDER_IN_SUBPIXEL (int) -#endif - -namespace cocos2d { - -CCNode::CCNode(void) -:m_bIsRunning(false) -,m_fRotation(0.0f) -,m_fScaleX(1.0f) -,m_fScaleY(1.0f) -,m_tPosition(CGPointZero) -,m_tPositionInPixels(CGPointZero) -,m_tAnchorPointInPixels(CGPointZero) -,m_tAnchorPoint(CGPointZero) -,m_tContentSize(CGSizeZero) -,m_tAnchorPointInPixels(CGSizeZero) -// "whole screen" objects. like Scenes and Layers, should set isRelativeAnchorPoint to false -,m_bIsRelativeAnchorPoint(true) -,m_bIsTransformDirty(true) -,m_bIsInverseDirty(true) -#ifdef CC_NODE_TRANSFORM_USING_AFFINE_MATRIX -,m_bIsTransformGLDirty(true) -#endif -,m_fVertexZ(0.0f) -,m_pGrid(NULL) -,m_bIsVisible(true) -,m_nTag(kCCNodeTagInvalid) -,m_nZOrder(0) -// lazy alloc -,m_pCamera(NULL) -// children (lazy allocs) -,m_pChildren(NULL) -// userData is always inited as nil -,m_pUserData(NULL) -,m_pParent(NULL) -{ - // nothing -} -CCNode::~CCNode() -{ - CCLOGINFO( "cocos2d: deallocing" ); - - // attributes - CCX_SAFE_RELEASE(m_pCamera); - - CCX_SAFE_RELEASE(m_pGrid); - - - if(m_pChildren && m_pChildren->count() > 0) - { - NSMutableArray::NSMutableArrayIterator it; - for( it = m_pChildren->begin(); it != m_pChildren->end(); ++it) - { - if (*it) - { - (*it)->m_pParent = NULL; - } - } - } - - // children - CCX_SAFE_RELEASE(m_pChildren); - -} - -void CCNode::arrayMakeObjectsPerformSelector(NSMutableArray * pArray, callbackFunc func) -{ - if(pArray && pArray->count() > 0) - { - CCNode* pNode; - NSMutableArray::NSMutableArrayIterator it; - for( it = pArray->begin(); it != pArray->end(); it++) - { - pNode = (*it); - - if(pNode && func) - { - (pNode->*func)(); - } - } - } -} - -/// zOrder getter -int CCNode::getZOrder() -{ - return m_nZOrder; -} - -/// zOrder setter : private method -/// used internally to alter the zOrder variable. DON'T call this method manually -void CCNode::setZOrder(int z) -{ - m_nZOrder = z; -} - -/// ertexZ getter -float CCNode::getVertexZ() -{ - return m_fVertexZ; -} - - -/// vertexZ setter -void CCNode::setVertexZ(float var) -{ - m_fVertexZ = var * CC_CONTENT_SCALE_FACTOR(); -} - - -/// rotation getter -float CCNode::getRotation() -{ - return m_fRotation; -} - -/// rotation setter -void CCNode::setRotation(float newRotation) -{ - m_fRotation = newRotation; - m_bIsTransformDirty = m_bIsInverseDirty = true; -#ifdef CC_NODE_TRANSFORM_USING_AFFINE_MATRIX - m_bIsTransformGLDirty = true; -#endif -} - - -/// scale getter -float CCNode::getScale(void) -{ - NSAssert( m_fScaleX == m_fScaleY, "CCNode#scale. ScaleX != ScaleY. Don't know which one to return"); - return m_fScaleX; -} - -/// scale setter -void CCNode::setScale(float scale) -{ - m_fScaleX = m_fScaleY = scale; - m_bIsTransformDirty = m_bIsInverseDirty = true; -#ifdef CC_NODE_TRANSFORM_USING_AFFINE_MATRIX - m_bIsTransformGLDirty = true; -#endif -} - -/// scaleX getter -float CCNode::getScaleX() -{ - return m_fScaleX; -} - -/// scaleX setter -void CCNode::setScaleX(float newScaleX) -{ - m_fScaleX = newScaleX; - m_bIsTransformDirty = m_bIsInverseDirty = true; -#ifdef CC_NODE_TRANSFORM_USING_AFFINE_MATRIX - m_bIsTransformGLDirty = true; -#endif -} - -/// scaleY getter -float CCNode::getScaleY() -{ - return m_fScaleY; -} - -/// scaleY setter -void CCNode::setScaleY(float newScaleY) -{ - m_fScaleY = newScaleY; - m_bIsTransformDirty = m_bIsInverseDirty = true; -#ifdef CC_NODE_TRANSFORM_USING_AFFINE_MATRIX - m_bIsTransformGLDirty = true; -#endif -} - -/// position getter -CGPoint CCNode::getPosition() -{ - return m_tPosition; -} - -/// position setter -void CCNode::setPosition(CGPoint newPosition) -{ - m_tPosition = newPosition; - if (CC_CONTENT_SCALE_FACTOR() == 1) - { - m_tPositionInPixels = m_tPosition - } - else - { - m_tPositionInPixels = ccpMult(newPosition, CC_CONTENT_SCALE_FACTOR()); - } - - m_bIsTransformDirty = m_bIsInverseDirty = true; -#ifdef CC_NODE_TRANSFORM_USING_AFFINE_MATRIX - m_bIsTransformGLDirty = true; -#endif -} - -void CCNode::setPositionInPixels(CGPoint newPosition) -{ - m_tPositionInPixels = newPosition; - - if ( CC_CONTENT_SCALE_FACTOR() == 1) - { - m_tPosition = m_tPositionInPixels; - } - else - { - m_tPosition = ccpMult(newPosition, 1/CC_CONTENT_SCALE_FACTOR()); - } - - m_bIsTransformDirty = m_bIsInverseDirty = true; - -#if CC_NODE_TRANSFORM_USING_AFFINE_MATRIX - m_bIsTransformGLDirty = true; -#endif // CC_NODE_TRANSFORM_USING_AFFINE_MATRIX -} - -/// children getter -NSMutableArray * CCNode::getChildren() -{ - return m_pChildren; -} - -/// camera getter: lazy alloc -CCCamera* CCNode::getCamera() -{ - if (!m_pCamera) - { - m_pCamera = new CCCamera(); - } - - return m_pCamera; -} - - -/// grid getter -CCGridBase* CCNode::getGrid() -{ - return m_pGrid; -} - -/// grid setter -void CCNode::setGrid(CCGridBase* pGrid) -{ - CCX_SAFE_RETAIN(pGrid); - CCX_SAFE_RELEASE(m_pGrid); - m_pGrid = pGrid; -} - - -/// isVisible getter -bool CCNode::getIsVisible() -{ - return m_bIsVisible; -} - -/// isVisible setter -void CCNode::setIsVisible(bool var) -{ - m_bIsVisible = var; -} - - -/// anchorPoint getter -CGPoint CCNode::getAnchorPoint() -{ - return m_tAnchorPoint; -} - -void CCNode::setAnchorPoint(CGPoint point) -{ - if( ! CGPoint::CGPointEqualToPoint(point, m_tAnchorPoint) ) - { - m_tAnchorPoint = point; - m_tAnchorPointInPixels = ccp( m_tContentSizeInPixels.width * m_tAnchorPoint.x, m_tContentSizeInPixels.height * m_tAnchorPoint.y ); - m_bIsTransformDirty = m_bIsInverseDirty = true; -#ifdef CC_NODE_TRANSFORM_USING_AFFINE_MATRIX - m_bIsTransformGLDirty = true; -#endif - } -} - -/// anchorPointInPixels getter -CGPoint CCNode::getAnchorPointInPixels() -{ - return m_tAnchorPointInPixels; -} - -/// contentSize getter -CGSize CCNode::getContentSize() -{ - return m_tContentSize; -} - -void CCNode::setContentSize(CGSize size) -{ - if( ! CGSize::CGSizeEqualToSize(size, m_tContentSize) ) - { - m_tContentSize = size; - m_tAnchorPointInPixels = ccp( m_tContentSize.width * m_tAnchorPoint.x, m_tContentSize.height * m_tAnchorPoint.y ); - m_bIsTransformDirty = m_bIsInverseDirty = true; -#ifdef CC_NODE_TRANSFORM_USING_AFFINE_MATRIX - m_bIsTransformGLDirty = true; -#endif - } -} - -void CCNode::setContentSizeInPixels(CGSize size) -{ - if (! CGSize::CGSizeEqualToSize(size, m_tContentSizeInPixels)) - { - m_tContentSizeInPixels = size; - - if (CC_CONTENT_SCALE_FACTOR() == 1) - { - m_tContentSize = m_tContentSizeInPixels; - } - else - { - m_tContentSize = CGSizeMake(size.width / CC_CONTENT_SCALE_FACTOR(), size.height / CC_CONTENT_SCALE_FACTOR()); - } - - m_tAnchorPointInPixels = ccp(m_tContentSizeInPixels.width * m_tAnchorPoint.x, m_tContentSizeInPixels.height * m_tAnchorPoint.y); - m_bIsTransformDirty = m_bIsInverseDirty = true; - -#if CC_NODE_TRANSFORM_USING_AFFINE_MATRIX - m_bIsTransformGLDirty = true; -#endif // CC_NODE_TRANSFORM_USING_AFFINE_MATRIX - } -} - - -/// isRunning getter -bool CCNode::getIsRunning() -{ - return m_bIsRunning; -} - - -/// parent getter -CCNode * CCNode::getParent() -{ - return m_pParent; -} -/// parent setter -void CCNode::setParent(CCNode * var) -{ - m_pParent = var; -} - -/// isRelativeAnchorPoint getter -bool CCNode::getIsRelativeAnchorPoint() -{ - return m_bIsRelativeAnchorPoint; -} -/// isRelativeAnchorPoint setter -void CCNode::setIsRelativeAnchorPoint(bool newValue) -{ - m_bIsRelativeAnchorPoint = newValue; - m_bIsTransformDirty = m_bIsInverseDirty = true; -#ifdef CC_NODE_TRANSFORM_USING_AFFINE_MATRIX - m_bIsTransformGLDirty = true; -#endif -} - -/// tag getter -int CCNode::getTag() -{ - return m_nTag; -} - -/// tag setter -void CCNode::setTag(int var) -{ - m_nTag = var; -} - -/// userData getter -void * CCNode::getUserData() -{ - return m_pUserData; -} - -/// userData setter -void CCNode::setUserData(void *var) -{ - m_pUserData = var; -} - - -CGRect CCNode::boundingBox() -{ - CGRect ret = boundingBoxInPixels(); - return CC_RECT_PIXELS_TO_POINTS(ret); -} - -CGRect CCNode::boundingBoxInPixels() -{ - CGRect rect = CGRectMake(0, 0, m_tContentSizeInPixels.width, m_tContentSizeInPixels.height); - return CGRectApplyAffineTransform(rect, nodeToParentTransform()); -} - - -CCNode * CCNode::node(void) -{ - CCNode * pRet = new CCNode(); - pRet->autorelease(); - return pRet; -} - - -void CCNode::cleanup() -{ - // actions - this->stopAllActions(); - this->unscheduleAllSelectors(); - - // timers - arrayMakeObjectsPerformSelector(m_pChildren, &CCNode::cleanup); -} - - -char * CCNode::description() -{ - char *ret = new char[100] ; - sprintf(ret, "", m_nTag); - return ret; -} - -// lazy allocs -void CCNode::childrenAlloc(void) -{ - m_pChildren = new NSMutableArray(4); -} - -CCNode* CCNode::getChildByTag(int aTag) -{ - NSAssert( aTag != kCCNodeTagInvalid, "Invalid tag"); - - if(m_pChildren && m_pChildren->count() > 0) - { - CCNode* pNode; - NSMutableArray::NSMutableArrayIterator it; - for( it = m_pChildren->begin(); it != m_pChildren->end(); it++) - { - pNode = (*it); - if(pNode && pNode->m_nTag == aTag) - return pNode; - } - } - return NULL; -} - -/* "add" logic MUST only be on this method -* If a class want's to extend the 'addChild' behaviour it only needs -* to override this method -*/ -void CCNode::addChild(CCNode *child, int zOrder, int tag) -{ - NSAssert( child != NULL, "Argument must be non-nil"); - NSAssert( child->m_pParent == NULL, "child already added. It can't be added again"); - - if( ! m_pChildren ) - { - this->childrenAlloc(); - } - - this->insertChild(child, zOrder); - - child->m_nTag = tag; - - child->setParent(this); - - if( m_bIsRunning ) - { - child->onEnter(); - child->onEnterTransitionDidFinish(); - } -} - -void CCNode::addChild(CCNode *child, int zOrder) -{ - NSAssert( child != NULL, "Argument must be non-nil"); - this->addChild(child, zOrder, child->m_nTag); -} - -void CCNode::addChild(CCNode *child) -{ - NSAssert( child != NULL, "Argument must be non-nil"); - this->addChild(child, child->m_nZOrder, child->m_nTag); -} - -void CCNode::removeFromParentAndCleanup(bool cleanup) -{ - this->m_pParent->removeChild(this,cleanup); -} - -/* "remove" logic MUST only be on this method -* If a class want's to extend the 'removeChild' behavior it only needs -* to override this method -*/ -void CCNode::removeChild(CCNode* child, bool cleanup) -{ - // explicit nil handling - if (m_pChildren == NULL) - { - return; - } - - if ( m_pChildren->containsObject(child) ) - { - this->detachChild(child,cleanup); - } -} - -void CCNode::removeChildByTag(int tag, bool cleanup) -{ - NSAssert( tag != kCCNodeTagInvalid, "Invalid tag"); - - CCNode *child = this->getChildByTag(tag); - - if (child == NULL) - { - CCLOG("cocos2d: removeChildByTag: child not found!"); - } - else - { - this->removeChild(child, cleanup); - } -} - -void CCNode::removeAllChildrenWithCleanup(bool cleanup) -{ - // not using detachChild improves speed here - if ( m_pChildren && m_pChildren->count() > 0 ) - { - CCNode * pNode; - NSMutableArray::NSMutableArrayIterator it; - for ( it = m_pChildren->begin(); it!= m_pChildren->end(); it++ ) - { - pNode = *it; - if (pNode) - { - // IMPORTANT: - // -1st do onExit - // -2nd cleanup - if(m_bIsRunning) - { - pNode->onExit(); - } - - if (cleanup) - { - pNode->cleanup(); - } - // set parent nil at the end - pNode->setParent(NULL); - } - } - - m_pChildren->removeAllObjects(); - } - -} - -void CCNode::detachChild(CCNode *child, bool doCleanup) -{ - // IMPORTANT: - // -1st do onExit - // -2nd cleanup - if (m_bIsRunning) - { - child->onExit(); - } - - // If you don't do cleanup, the child's actions will not get removed and the - // its scheduledSelectors_ dict will not get released! - if (doCleanup) - { - child->cleanup(); - } - - // set parent nil at the end - child->setParent(NULL); - - m_pChildren->removeObject(child); -} - - -// helper used by reorderChild & add -void CCNode::insertChild(CCNode* child, int z) -{ - unsigned int index=0; - - if(m_pChildren && m_pChildren->count() > 0) - { - CCNode* pNode = m_pChildren->getLastObject(); - - // // quick comparison to improve performance - if (! pNode || pNode->getZOrder() <= z) - { - m_pChildren->addObject(child); - } - else - { - NSMutableArray::NSMutableArrayIterator it; - for( it = m_pChildren->begin(); it != m_pChildren->end(); it++) - { - pNode = (*it); - - if ( pNode && pNode->m_nZOrder > z ) - { - added = true; - m_pChildren->insertObjectAtIndex(child, index); - break; - } - index++; - } - } - } - - child->setZOrder(z); -} - -void CCNode::reorderChild(CCNode *child, int zOrder) -{ - NSAssert( child != NULL, "Child must be non-nil"); - - child->retain(); - m_pChildren->removeObject(child); - - insertChild(child, zOrder); - child->release(); -} - - void CCNode::draw() - { - //assert(0); - // override me - // Only use- this function to draw your staff. - // DON'T draw your stuff outside this method - } - -void CCNode::visit() -{ - // quick return if not visible - if (!m_bIsVisible) - { - return; - } - glPushMatrix(); - - if (m_pGrid && m_pGrid->isActive()) - { - m_pGrid->beforeDraw(); - this->transformAncestors(); - } - - this->transform(); - - CCNode* pNode; - NSMutableArray::NSMutableArrayIterator it; - - if(m_pChildren && m_pChildren->count() > 0) - { - // draw children zOrder < 0 - for( it = m_pChildren->begin(); it != m_pChildren->end(); it++) - { - pNode = (*it); - - if ( pNode && pNode->m_nZOrder < 0 ) - { - pNode->visit(); - } - else - { - break; - } - } - } - - // self draw - this->draw(); - - // draw children zOrder >= 0 - if (m_pChildren && m_pChildren->count() > 0) - { - for ( ; it!=m_pChildren->end(); it++ ) - { - pNode = (*it); - if (pNode) - { - pNode->visit(); - } - } - } - - if (m_pGrid && m_pGrid->isActive()) - { - m_pGrid->afterDraw(this); - } - - glPopMatrix(); -} - -void CCNode::transformAncestors() -{ - if( m_pParent != NULL ) - { - m_pParent->transformAncestors(); - m_pParent->transform(); - } -} - -void CCNode::transform() -{ - // transformations - -#if CC_NODE_TRANSFORM_USING_AFFINE_MATRIX - // BEGIN alternative -- using cached transform - // - if( m_bIsTransformGLDirty ) { - CGAffineTransform t = this->nodeToParentTransform(); - CGAffineToGL(&t, m_pTransformGL); - m_bIsTransformGLDirty = false; - } - - glMultMatrixf(m_pTransformGL); - if( m_fVertexZ ) - { - glTranslatef(0, 0, m_fVertexZ); - } - - // XXX: Expensive calls. Camera should be integrated into the cached affine matrix - if (m_pCamera && !(m_pGrid && m_pGrid->isActive())) { - bool translate = (m_tAnchorPointInPixels.x != 0.0f || m_tAnchorPointInPixels.y != 0.0f); - - if( translate ) - { - ccglTranslate(RENDER_IN_SUBPIXEL(m_tAnchorPointInPixels.x), RENDER_IN_SUBPIXEL(m_tAnchorPointInPixels.y), 0); - } - - m_pCamera->locate(); - - if( translate ) - { - ccglTranslate(RENDER_IN_SUBPIXEL(-m_tAnchorPointInPixels.x), RENDER_IN_SUBPIXEL(-m_tAnchorPointInPixels.y), 0); - } - } - - - // END alternative - -#else - // BEGIN original implementation - // - // translate - if ( m_bIsRelativeAnchorPoint && (m_tAnchorPointInPixels.x != 0 || m_tAnchorPointInPixels.y != 0 ) ) - glTranslatef( RENDER_IN_SUBPIXEL(-m_tAnchorPointInPixels.x), RENDER_IN_SUBPIXEL(-m_tAnchorPointInPixels.y), 0); - - if (m_tAnchorPointInPixels.x != 0 || m_tAnchorPointInPixels.y != 0) - glTranslatef( RENDER_IN_SUBPIXEL(m_tPositionInPixels.x + m_tAnchorPointInPixels.x), RENDER_IN_SUBPIXEL(m_tPositionInPixels.y + m_tAnchorPointInPixels.y), m_fVertexZ); - else if ( m_tPositionInPixels.x !=0 || m_tPositionInPixels.y !=0 || m_fVertexZ != 0) - glTranslatef( RENDER_IN_SUBPIXEL(m_tPositionInPixels.x), RENDER_IN_SUBPIXEL(m_tPositionInPixels.y), m_fVertexZ ); - - // rotate - if (m_fRotation != 0.0f ) - glRotatef( -m_fRotation, 0.0f, 0.0f, 1.0f ); - - // scale - if (m_fScaleX != 1.0f || m_fScaleY != 1.0f) - glScalef( m_fScaleX, m_fScaleY, 1.0f ); - - if ( m_pCamera && !(m_pGrid && m_pGrid->isActive()) ) - m_pCamera->locate(); - - // restore and re-position point - if (m_tAnchorPointInPixels.x != 0.0f || m_tAnchorPointInPixels.y != 0.0f) - glTranslatef(RENDER_IN_SUBPIXEL(-m_tAnchorPointInPixels.x), RENDER_IN_SUBPIXEL(-m_tAnchorPointInPixels.y), 0); - - // - // END original implementation -#endif - -} - - -void CCNode::onEnter() -{ - arrayMakeObjectsPerformSelector(m_pChildren, &CCNode::onEnter); - - this->resumeSchedulerAndActions(); - - m_bIsRunning = true; -} - -void CCNode::onEnterTransitionDidFinish() -{ - arrayMakeObjectsPerformSelector(m_pChildren, &CCNode::onEnterTransitionDidFinish); -} - -void CCNode::onExit() -{ - this->pauseSchedulerAndActions(); - - m_bIsRunning = false; - - arrayMakeObjectsPerformSelector(m_pChildren, &CCNode::onExit); -} -CCAction * CCNode::runAction(CCAction* action) -{ - NSAssert( action != NULL, "Argument must be non-nil"); - CCActionManager::sharedManager()->addAction(action, this, !m_bIsRunning); - return action; -} - -void CCNode::stopAllActions() -{ - CCActionManager::sharedManager()->removeAllActionsFromTarget(this); -} - -void CCNode::stopAction(CCAction* action) -{ - CCActionManager::sharedManager()->removeAction(action); -} - -void CCNode::stopActionByTag(int tag) -{ - NSAssert( tag != kCCActionTagInvalid, "Invalid tag"); - CCActionManager::sharedManager()->removeActionByTag(tag, this); -} - -CCAction * CCNode::getActionByTag(int tag) -{ - NSAssert( tag != kCCActionTagInvalid, "Invalid tag"); - return CCActionManager::sharedManager()->getActionByTag(tag, this); -} - -int CCNode::numberOfRunningActions() -{ - return CCActionManager::sharedManager()->numberOfRunningActionsInTarget(this); -} - -// CCNode - Callbacks - -void CCNode::scheduleUpdate() -{ - scheduleUpdateWithPriority(0); -} - -void CCNode::scheduleUpdateWithPriority(int priority) -{ - CCScheduler::sharedScheduler()->scheduleUpdateForTarget(this, priority, !m_bIsRunning); -} - -void CCNode::unscheduleUpdate() -{ - CCScheduler::sharedScheduler()->unscheduleUpdateForTarget(this); -} - -void CCNode::schedule(SEL_SCHEDULE selector) -{ - this->schedule(selector, 0); -} - -void CCNode::schedule(SEL_SCHEDULE selector, ccTime interval) -{ - NSAssert( selector != NULL, "Argument must be non-nil"); - NSAssert( interval >=0, "Argument must be positive"); - - CCScheduler::sharedScheduler()->scheduleSelector(selector, this, interval, !m_bIsRunning); -} - -void CCNode::unschedule(SEL_SCHEDULE selector) -{ - // explicit nil handling - if (selector == 0) - return; - - CCScheduler::sharedScheduler()->unscheduleSelector(selector, this); -} - -void CCNode::unscheduleAllSelectors() -{ - CCScheduler::sharedScheduler()->unscheduleAllSelectorsForTarget(this); -} - -void CCNode::resumeSchedulerAndActions() -{ - CCScheduler::sharedScheduler()->resumeTarget(this); - CCActionManager::sharedManager()->resumeTarget(this); -} - -void CCNode::pauseSchedulerAndActions() -{ - CCScheduler::sharedScheduler()->pauseTarget(this); - CCActionManager::sharedManager()->pauseTarget(this); -} - -void CCNode::selectorProtocolRetain(void) -{ - retain(); -} - -void CCNode::selectorProtocolRelease(void) -{ - release(); -} - -CGAffineTransform CCNode::nodeToParentTransform(void) -{ - if ( m_bIsTransformDirty ) { - - m_tTransform = CGAffineTransformIdentity; - - if( ! m_bIsRelativeAnchorPoint && ! CGPoint::CGPointEqualToPoint(m_tAnchorPointInPixels, CGPointZero) ) - m_tTransform = CGAffineTransformTranslate(m_tTransform, m_tAnchorPointInPixels.x, m_tAnchorPointInPixels.y); - - if( ! CGPoint::CGPointEqualToPoint(m_tPositionInPixels, CGPointZero) ) - m_tTransform = CGAffineTransformTranslate(m_tTransform, m_tPositionInPixels.x, m_tPosition.y); - if( m_fRotation != 0 ) - m_tTransform = CGAffineTransformRotate(m_tTransform, -CC_DEGREES_TO_RADIANS(m_fRotation)); - if( ! (m_fScaleX == 1 && m_fScaleY == 1) ) - m_tTransform = CGAffineTransformScale(m_tTransform, m_fScaleX, m_fScaleY); - - if( ! CGPoint::CGPointEqualToPoint(m_tAnchorPointInPixels, CGPointZero) ) - m_tTransform = CGAffineTransformTranslate(m_tTransform, -m_tAnchorPointInPixels.x, -m_tAnchorPointInPixels.y); - - m_bIsTransformDirty = false; - } - - return m_tTransform; -} - -CGAffineTransform CCNode::parentToNodeTransform(void) -{ - if ( m_bIsInverseDirty ) { - m_tInverse = CGAffineTransformInvert(this->nodeToParentTransform()); - m_bIsInverseDirty = false; - } - - return m_tInverse; -} - -CGAffineTransform CCNode::nodeToWorldTransform() -{ - CGAffineTransform t = this->nodeToParentTransform(); - - for (CCNode *p = m_pParent; p != NULL; p = p->getParent()) - t = CGAffineTransformConcat(t, p->nodeToParentTransform()); - - return t; -} - -CGAffineTransform CCNode::worldToNodeTransform(void) -{ - return CGAffineTransformInvert(this->nodeToWorldTransform()); -} - -CGPoint CCNode::convertToNodeSpace(CGPoint worldPoint) -{ - CGPoint ret; - if(CC_CONTENT_SCALE_FACTOR() == 1) - { - ret = CGPointApplyAffineTransform(worldPoint, worldToNodeTransform()); - } - else - { - ret = ccpMult(worldPoint, CC_CONTENT_SCALE_FACTOR()); - ret = CGPointApplyAffineTransform(ret, worldToNodeTransform()); - ret = ccpMult(ret, 1/CC_CONTENT_SCALE_FACTOR()); - } - - return ret; -} - -CGPoint CCNode::convertToWorldSpace(CGPoint nodePoint) -{ - CGPoint ret; - if(CC_CONTENT_SCALE_FACTOR() == 1) - { - ret = CGPointApplyAffineTransform(nodePoint, nodeToWorldTransform()); - } - else - { - ret = ccpMult( nodePoint, CC_CONTENT_SCALE_FACTOR() ); - ret = CGPointApplyAffineTransform(ret, nodeToWorldTransform()); - ret = ccpMult( ret, 1/CC_CONTENT_SCALE_FACTOR() ); - } - - return ret; -} - -CGPoint CCNode::convertToNodeSpaceAR(CGPoint worldPoint) -{ - CGPoint nodePoint = convertToNodeSpace(worldPoint); - CGPoint anchorInPoints; - if( CC_CONTENT_SCALE_FACTOR() == 1 ) - { - anchorInPoints = m_tAnchorPointInPixels; - } - else - { - anchorInPoints = ccpMult( m_tAnchorPointInPixels, 1/CC_CONTENT_SCALE_FACTOR() ); - } - - return ccpSub(nodePoint, anchorInPoints); -} - -CGPoint CCNode::convertToWorldSpaceAR(CGPoint nodePoint) -{ - CGPoint anchorInPoints; - if( CC_CONTENT_SCALE_FACTOR() == 1 ) - { - anchorInPoints = m_tAnchorPointInPixels; - } - else - { - anchorInPoints = ccpMult( m_tAnchorPointInPixels, 1/CC_CONTENT_SCALE_FACTOR() ); - } - - nodePoint = ccpAdd(nodePoint, anchorInPoints); - return convertToWorldSpace(nodePoint); -} -CGPoint CCNode::convertToWindowSpace(CGPoint nodePoint) -{ - CGPoint worldPoint = this->convertToWorldSpace(nodePoint); - return CCDirector::sharedDirector()->convertToUI(worldPoint); -} - -// The functions are compatable with mobile platform, -// not supported in mac -CGPoint CCNode::convertTouchToNodeSpace(CCTouch *touch) -{ - CCLOG("cocos2d: CCNode: unsupported"); -} -CGPoint CCNode::convertTouchToNodeSpaceAR(CCTouch *touch) -{ - CCLOG("cocos2d: CCNode: unsupported"); -} - -}//namespace cocos2d diff --git a/cocos2dx/platform/mac/CCParticleSystemPoint_mac.cpp b/cocos2dx/platform/mac/CCParticleSystemPoint_mac.cpp deleted file mode 100644 index 933f8af73c..0000000000 --- a/cocos2dx/platform/mac/CCParticleSystemPoint_mac.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org - -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. -****************************************************************************/ - -namespace cocos2d { - - -}// namespace cocos2d diff --git a/cocos2dx/platform/mac/CCParticleSystemPoint_mac.h b/cocos2dx/platform/mac/CCParticleSystemPoint_mac.h deleted file mode 100644 index 1d8353b96b..0000000000 --- a/cocos2dx/platform/mac/CCParticleSystemPoint_mac.h +++ /dev/null @@ -1,37 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org - -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. -****************************************************************************/ -#ifndef __CC_PARTICLE_SYSTEM_POINT_MAC_H__ -#define __CC_PARTICLE_SYSTEM_POINT_MAC_H__ - -#include "CCParticleSystem.h" - -namespace cocos2d { - -class CCX_DLL CCParticleSystemPoint : public CCParticleSystem -{ -public: - static CCParticleSystemPoint * particleWithFile(const char *plistFile) { retur 0; } -}; - -#endif //__CC_PARTICLE_SYSTEM_POINT_MAC_H__ diff --git a/cocos2dx/platform/mac/CCTransition_mac.cpp b/cocos2dx/platform/mac/CCTransition_mac.cpp deleted file mode 100644 index 923f2ee0fd..0000000000 --- a/cocos2dx/platform/mac/CCTransition_mac.cpp +++ /dev/null @@ -1,1408 +0,0 @@ -/**************************************************************************** -Copyright (c) 2010 cocos2d-x.org - -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 "CCTransition.h" -#include "CCCamera.h" -#include "CGPointExtension.h" -#include "CCDirector.h" -#include "CCTouchDispatcher.h" -#include "CCActionInterval.h" -#include "CCActionInstant.h" -#include "CCActionEase.h" -#include "CCActionCamera.h" -#include "CCLayer.h" -#include "CCActionGrid.h" -#include "CCRenderTexture.h" -#include "CCActionTiledGrid.h" -namespace cocos2d { - -enum { - kSceneFade = 0xFADEFADE, -}; - -#define IMPLEMENT_TRANSITIONWITHDURATION(_Type)\ - _Type* _Type::transitionWithDuration(ccTime t, CCScene* scene)\ -{\ - _Type* pScene = new _Type();\ - if(pScene && pScene->initWithDuration(t, scene)){\ - pScene->autorelease();\ - return pScene;}\ - CCX_SAFE_DELETE(pScene);\ - return NULL;\ -} - - - -CCTransitionScene::CCTransitionScene() -{ -} -CCTransitionScene::~CCTransitionScene() -{ - m_pInScene->release(); - m_pOutScene->release(); -} - -CCTransitionScene * CCTransitionScene::transitionWithDuration(ccTime t, CCScene *scene) -{ - CCTransitionScene * pScene = new CCTransitionScene(); - if(pScene && pScene->initWithDuration(t,scene)) - { - pScene->autorelease(); - return pScene; - } - CCX_SAFE_DELETE(pScene); - return NULL; -} - -bool CCTransitionScene::initWithDuration(ccTime t, CCScene *scene) -{ - NSAssert( scene != NULL, "Argument scene must be non-nil"); - - if (CCScene::init()) - { - m_fDuration = t; - - // retain - m_pInScene = scene; - m_pInScene->retain(); - m_pOutScene = CCDirector::sharedDirector()->getRunningScene(); - m_pOutScene->retain(); - m_eSceneType = ccTransitionScene; - - NSAssert( m_pInScene != m_pOutScene, "Incoming scene must be different from the outgoing scene" ); - - // disable events while transitions - CCEventDispatcher::sharedDispatcher()->setDispatchEvents(false); - this->sceneOrder(); - - return true; - } - else - { - return false; - } -} - -void CCTransitionScene::sceneOrder() -{ - m_bIsInSceneOnTop = true; -} - -void CCTransitionScene::draw() -{ - if( m_bIsInSceneOnTop ) { - m_pOutScene->visit(); - m_pInScene->visit(); - } else { - m_pInScene->visit(); - m_pOutScene->visit(); - } -} - -void CCTransitionScene::finish() -{ - // clean up - m_pInScene->setIsVisible(true); - m_pInScene->setPosition(ccp(0,0)); - m_pInScene->setScale(1.0f); - m_pInScene->setRotation(0.0f); - m_pInScene->getCamera()->restore(); - - m_pOutScene->setIsVisible(false); - m_pOutScene->setPosition(ccp(0,0)); - m_pOutScene->setScale(1.0f); - m_pOutScene->setRotation(0.0f); - m_pOutScene->getCamera()->restore(); - - //[self schedule:@selector(setNewScene:) interval:0]; - this->schedule(schedule_selector(CCTransitionScene::setNewScene), 0); - -} - -void CCTransitionScene::setNewScene(ccTime dt) -{ - // [self unschedule:_cmd]; - // "_cmd" is a local variable automatically defined in a method - // that contains the selector for the method - this->unschedule(schedule_selector(CCTransitionScene::setNewScene)); - CCDirector *director = CCDirector::sharedDirector(); - // Before replacing, save the "send cleanup to scene" - m_bIsSendCleanupToScene = director->isSendCleanupToScene(); - director->replaceScene(m_pInScene); - // enable events while transitions - CCEventDispatcher::sharedDispatcher()->setDispatchEvents(true); - // issue #267 - m_pOutScene->setIsVisible(true); -} - -void CCTransitionScene::hideOutShowIn() -{ - m_pInScene->setIsVisible(true); - m_pOutScene->setIsVisible(false); -} - - -// custom onEnter -void CCTransitionScene::onEnter() -{ - CCScene::onEnter(); - m_pInScene->onEnter(); - // outScene should not receive the onEnter callback -} - -// custom onExit -void CCTransitionScene::onExit() -{ - CCScene::onExit(); - m_pOutScene->onExit(); - - // inScene should not receive the onExit callback - // only the onEnterTransitionDidFinish - m_pInScene->onEnterTransitionDidFinish(); -} - -// custom cleanup -void CCTransitionScene::cleanup() -{ - CCScene::cleanup(); - - if( m_bIsSendCleanupToScene ) - m_pOutScene->cleanup(); -} - -// -// Oriented Transition -// -CCTransitionSceneOriented::CCTransitionSceneOriented() -{ -} -CCTransitionSceneOriented::~CCTransitionSceneOriented() -{ -} - -CCTransitionSceneOriented * CCTransitionSceneOriented::transitionWithDuration(ccTime t, CCScene *scene, tOrientation orientation) -{ - CCTransitionSceneOriented * pScene = new CCTransitionSceneOriented(); - pScene->initWithDuration(t,scene,orientation); - pScene->autorelease(); - return pScene; -} - -bool CCTransitionSceneOriented::initWithDuration(ccTime t, CCScene *scene, tOrientation orientation) -{ - if ( CCTransitionScene::initWithDuration(t, scene) ) - { - m_eOrientation = orientation; - } - return true; -} - -// -// RotoZoom -// -CCTransitionRotoZoom::CCTransitionRotoZoom() -{ -} -CCTransitionRotoZoom::~CCTransitionRotoZoom() -{ -} - -void CCTransitionRotoZoom:: onEnter() -{ - CCTransitionScene::onEnter(); - - m_pInScene->setScale(0.001f); - m_pOutScene->setScale(1.0f); - - m_pInScene->setAnchorPoint(ccp(0.5f, 0.5f)); - m_pOutScene->setAnchorPoint(ccp(0.5f, 0.5f)); - - CCActionInterval *rotozoom = (CCActionInterval*)(CCSequence::actions - ( - CCSpawn::actions - ( - CCScaleBy::actionWithDuration(m_fDuration/2, 0.001f), - CCRotateBy::actionWithDuration(m_fDuration/2, 360 * 2), - NULL - ), - CCDelayTime::actionWithDuration(m_fDuration/2), - NULL - )); - - m_pOutScene->runAction(rotozoom); - m_pInScene->runAction - ( - CCSequence::actions - ( - rotozoom->reverse(), - CCCallFunc::actionWithTarget(this, callfunc_selector(CCTransitionScene::finish)), - NULL - ) - ); -} - -IMPLEMENT_TRANSITIONWITHDURATION(CCTransitionRotoZoom) - - -// -// JumpZoom -// -CCTransitionJumpZoom::CCTransitionJumpZoom() -{ -} -CCTransitionJumpZoom::~CCTransitionJumpZoom() -{ -} - -void CCTransitionJumpZoom::onEnter() -{ - CCTransitionScene::onEnter(); - CGSize s = CCDirector::sharedDirector()->getWinSize(); - - m_pInScene->setScale(0.5f); - m_pInScene->setPosition(ccp(s.width, 0)); - m_pInScene->setAnchorPoint(ccp(0.5f, 0.5f)); - m_pOutScene->setAnchorPoint(ccp(0.5f, 0.5f)); - - CCActionInterval *jump = CCJumpBy::actionWithDuration(m_fDuration/4, ccp(-s.width,0), s.width/4, 2); - CCActionInterval *scaleIn = CCScaleTo::actionWithDuration(m_fDuration/4, 1.0f); - CCActionInterval *scaleOut = CCScaleTo::actionWithDuration(m_fDuration/4, 0.5f); - - CCActionInterval *jumpZoomOut = (CCActionInterval*)(CCSequence::actions(scaleOut, jump, NULL)); - CCActionInterval *jumpZoomIn = (CCActionInterval*)(CCSequence::actions(jump, scaleIn, NULL)); - - CCActionInterval *delay = CCDelayTime::actionWithDuration(m_fDuration/2); - - m_pOutScene->runAction(jumpZoomOut); - m_pInScene->runAction - ( - CCSequence::actions - ( - delay, - jumpZoomIn, - CCCallFunc::actionWithTarget(this, callfunc_selector(CCTransitionScene::finish)), - NULL - ) - ); -} - -IMPLEMENT_TRANSITIONWITHDURATION(CCTransitionJumpZoom) - -// -// MoveInL -// -CCTransitionMoveInL::CCTransitionMoveInL() -{ -} -CCTransitionMoveInL::~CCTransitionMoveInL() -{ -} - -void CCTransitionMoveInL::onEnter() -{ - CCTransitionScene::onEnter(); - this->initScenes(); - - CCActionInterval *a = this->action(); - - m_pInScene->runAction - ( - CCSequence::actions - ( - this->easeActionWithAction(a), - CCCallFunc::actionWithTarget(this, callfunc_selector(CCTransitionScene::finish)), - NULL - ) - ); -} - -CCActionInterval* CCTransitionMoveInL::action() -{ - return CCMoveTo::actionWithDuration(m_fDuration, ccp(0,0)); -} - -CCActionInterval* CCTransitionMoveInL::easeActionWithAction(CCActionInterval* action) -{ - return CCEaseOut::actionWithAction(action, 2.0f); -// return [EaseElasticOut actionWithAction:action period:0.4f]; -} - -void CCTransitionMoveInL::initScenes() -{ - CGSize s = CCDirector::sharedDirector()->getWinSize(); - m_pInScene->setPosition( ccp(-s.width,0) ); -} - -IMPLEMENT_TRANSITIONWITHDURATION(CCTransitionMoveInL) - -// -// MoveInR -// -CCTransitionMoveInR::CCTransitionMoveInR() -{ -} -CCTransitionMoveInR::~CCTransitionMoveInR() -{ -} - -void CCTransitionMoveInR::initScenes() -{ - CGSize s = CCDirector::sharedDirector()->getWinSize(); - m_pInScene->setPosition( ccp(s.width,0) ); -} - -IMPLEMENT_TRANSITIONWITHDURATION(CCTransitionMoveInR) - -// -// MoveInT -// -CCTransitionMoveInT::CCTransitionMoveInT() -{ -} -CCTransitionMoveInT::~CCTransitionMoveInT() -{ -} - -void CCTransitionMoveInT::initScenes() -{ - CGSize s = CCDirector::sharedDirector()->getWinSize(); - m_pInScene->setPosition( ccp(0,s.height) ); -} - -IMPLEMENT_TRANSITIONWITHDURATION(CCTransitionMoveInT) - -// -// MoveInB -// -CCTransitionMoveInB::CCTransitionMoveInB() -{ -} -CCTransitionMoveInB::~CCTransitionMoveInB() -{ -} - -void CCTransitionMoveInB::initScenes() -{ - CGSize s = CCDirector::sharedDirector()->getWinSize(); - m_pInScene->setPosition( ccp(0,-s.height) ); -} - -IMPLEMENT_TRANSITIONWITHDURATION(CCTransitionMoveInB) - - -// -// SlideInL -// - -// The adjust factor is needed to prevent issue #442 -// One solution is to use DONT_RENDER_IN_SUBPIXELS images, but NO -// The other issue is that in some transitions (and I don't know why) -// the order should be reversed (In in top of Out or vice-versa). -#define ADJUST_FACTOR 0.5f -CCTransitionSlideInL::CCTransitionSlideInL() -{ -} -CCTransitionSlideInL::~CCTransitionSlideInL() -{ -} - -void CCTransitionSlideInL::onEnter() -{ - CCTransitionScene::onEnter(); - this->initScenes(); - - CCActionInterval *in = this->action(); - CCActionInterval *out = this->action(); - - CCActionInterval* inAction = easeActionWithAction(in); - CCActionInterval* outAction = (CCActionInterval*)CCSequence::actions - ( - easeActionWithAction(out), - CCCallFunc::actionWithTarget(this, callfunc_selector(CCTransitionScene::finish)), - NULL - ); - m_pInScene->runAction(inAction); - m_pOutScene->runAction(outAction); -} - -void CCTransitionSlideInL::sceneOrder() -{ - m_bIsInSceneOnTop = false; -} - -void CCTransitionSlideInL:: initScenes() -{ - CGSize s = CCDirector::sharedDirector()->getWinSize(); - m_pInScene->setPosition( ccp(-(s.width-ADJUST_FACTOR),0) ); -} - -CCActionInterval* CCTransitionSlideInL::action() -{ - CGSize s = CCDirector::sharedDirector()->getWinSize(); - return CCMoveBy::actionWithDuration(m_fDuration, ccp(s.width-ADJUST_FACTOR,0)); -} - -CCActionInterval* CCTransitionSlideInL::easeActionWithAction(CCActionInterval* action) -{ - return CCEaseOut::actionWithAction(action, 2.0f); -// return [EaseElasticOut actionWithAction:action period:0.4f]; -} - -IMPLEMENT_TRANSITIONWITHDURATION(CCTransitionSlideInL) - - -// -// SlideInR -// -CCTransitionSlideInR::CCTransitionSlideInR() -{ -} -CCTransitionSlideInR::~CCTransitionSlideInR() -{ -} - -void CCTransitionSlideInR::sceneOrder() -{ - m_bIsInSceneOnTop = true; -} - -void CCTransitionSlideInR::initScenes() -{ - CGSize s = CCDirector::sharedDirector()->getWinSize(); - m_pInScene->setPosition( ccp(s.width-ADJUST_FACTOR,0) ); -} - - -CCActionInterval* CCTransitionSlideInR:: action() -{ - CGSize s = CCDirector::sharedDirector()->getWinSize(); - return CCMoveBy::actionWithDuration(m_fDuration, ccp(-(s.width-ADJUST_FACTOR),0)); -} - -IMPLEMENT_TRANSITIONWITHDURATION(CCTransitionSlideInR) - - -// -// SlideInT -// -CCTransitionSlideInT::CCTransitionSlideInT() -{ -} -CCTransitionSlideInT::~CCTransitionSlideInT() -{ -} - -void CCTransitionSlideInT::sceneOrder() -{ - m_bIsInSceneOnTop = false; -} - -void CCTransitionSlideInT::initScenes() -{ - CGSize s = CCDirector::sharedDirector()->getWinSize(); - m_pInScene->setPosition( ccp(0,s.height-ADJUST_FACTOR) ); -} - - -CCActionInterval* CCTransitionSlideInT::action() -{ - CGSize s = CCDirector::sharedDirector()->getWinSize(); - return CCMoveBy::actionWithDuration(m_fDuration, ccp(0,-(s.height-ADJUST_FACTOR))); -} - -IMPLEMENT_TRANSITIONWITHDURATION(CCTransitionSlideInT) - -// -// SlideInB -// -CCTransitionSlideInB::CCTransitionSlideInB() -{ -} -CCTransitionSlideInB::~CCTransitionSlideInB() -{ -} - -void CCTransitionSlideInB::sceneOrder() -{ - m_bIsInSceneOnTop = true; -} - -void CCTransitionSlideInB:: initScenes() -{ - CGSize s = CCDirector::sharedDirector()->getWinSize(); - m_pInScene->setPosition( ccp(0,-(s.height-ADJUST_FACTOR)) ); -} - - -CCActionInterval* CCTransitionSlideInB:: action() -{ - CGSize s = CCDirector::sharedDirector()->getWinSize(); - return CCMoveBy::actionWithDuration(m_fDuration, ccp(0,s.height-ADJUST_FACTOR)); -} - -IMPLEMENT_TRANSITIONWITHDURATION(CCTransitionSlideInB) - -// -// ShrinkGrow Transition -// -CCTransitionShrinkGrow::CCTransitionShrinkGrow() -{ -} -CCTransitionShrinkGrow::~CCTransitionShrinkGrow() -{ -} - -void CCTransitionShrinkGrow::onEnter() -{ - CCTransitionScene::onEnter(); - - m_pInScene->setScale(0.001f); - m_pOutScene->setScale(1.0f); - - m_pInScene->setAnchorPoint(ccp(2/3.0f,0.5f)); - m_pOutScene->setAnchorPoint(ccp(1/3.0f,0.5f)); - - CCActionInterval* scaleOut = CCScaleTo::actionWithDuration(m_fDuration, 0.01f); - CCActionInterval* scaleIn = CCScaleTo::actionWithDuration(m_fDuration, 1.0f); - - m_pInScene->runAction(this->easeActionWithAction(scaleIn)); - m_pOutScene->runAction - ( - CCSequence::actions - ( - this->easeActionWithAction(scaleOut), - CCCallFunc::actionWithTarget(this, callfunc_selector(CCTransitionScene::finish)), - NULL - ) - ); -} -CCActionInterval* CCTransitionShrinkGrow:: easeActionWithAction(CCActionInterval* action) -{ - return CCEaseOut::actionWithAction(action, 2.0f); -// return [EaseElasticOut actionWithAction:action period:0.3f]; -} - -IMPLEMENT_TRANSITIONWITHDURATION(CCTransitionShrinkGrow) - -// -// FlipX Transition -// -CCTransitionFlipX::CCTransitionFlipX() -{ -} -CCTransitionFlipX::~CCTransitionFlipX() -{ -} - -void CCTransitionFlipX::onEnter() -{ - CCTransitionSceneOriented::onEnter(); - - CCActionInterval *inA, *outA; - m_pInScene->setIsVisible(false); - - float inDeltaZ, inAngleZ; - float outDeltaZ, outAngleZ; - - if( m_eOrientation == kOrientationRightOver ) - { - inDeltaZ = 90; - inAngleZ = 270; - outDeltaZ = 90; - outAngleZ = 0; - } - else - { - inDeltaZ = -90; - inAngleZ = 90; - outDeltaZ = -90; - outAngleZ = 0; - } - - inA = (CCActionInterval*)CCSequence::actions - ( - CCDelayTime::actionWithDuration(m_fDuration/2), - CCShow::action(), - CCOrbitCamera::actionWithDuration(m_fDuration/2, 1, 0, inAngleZ, inDeltaZ, 0, 0), - CCCallFunc::actionWithTarget(this, callfunc_selector(CCTransitionScene::finish)), - NULL - ); - - outA = (CCActionInterval *)CCSequence::actions - ( - CCOrbitCamera::actionWithDuration(m_fDuration/2, 1, 0, outAngleZ, outDeltaZ, 0, 0), - CCHide::action(), - CCDelayTime::actionWithDuration(m_fDuration/2), - NULL - ); - - m_pInScene->runAction(inA); - m_pOutScene->runAction(outA); -} - -CCTransitionFlipX* CCTransitionFlipX::transitionWithDuration(ccTime t, CCScene* s, tOrientation o) -{ - CCTransitionFlipX* pScene = new CCTransitionFlipX(); - pScene->initWithDuration(t, s, o); - pScene->autorelease(); - - return pScene; -} - -// -// FlipY Transition -// -CCTransitionFlipY::CCTransitionFlipY() -{ -} -CCTransitionFlipY::~CCTransitionFlipY() -{ -} - -void CCTransitionFlipY::onEnter() -{ - CCTransitionSceneOriented::onEnter(); - - CCActionInterval *inA, *outA; - m_pInScene->setIsVisible(false); - - float inDeltaZ, inAngleZ; - float outDeltaZ, outAngleZ; - - if( m_eOrientation == kOrientationUpOver ) - { - inDeltaZ = 90; - inAngleZ = 270; - outDeltaZ = 90; - outAngleZ = 0; - } - else - { - inDeltaZ = -90; - inAngleZ = 90; - outDeltaZ = -90; - outAngleZ = 0; - } - - inA = (CCActionInterval*)CCSequence::actions - ( - CCDelayTime::actionWithDuration(m_fDuration/2), - CCShow::action(), - CCOrbitCamera::actionWithDuration(m_fDuration/2, 1, 0, inAngleZ, inDeltaZ, 90, 0), - CCCallFunc::actionWithTarget(this, callfunc_selector(CCTransitionScene::finish)), - NULL - ); - outA = (CCActionInterval*)CCSequence::actions - ( - CCOrbitCamera::actionWithDuration(m_fDuration/2, 1, 0, outAngleZ, outDeltaZ, 90, 0), - CCHide::action(), - CCDelayTime::actionWithDuration(m_fDuration/2), - NULL - ); - - m_pInScene->runAction(inA); - m_pOutScene->runAction(outA); - -} - -CCTransitionFlipY* CCTransitionFlipY::transitionWithDuration(ccTime t, CCScene* s, tOrientation o) -{ - CCTransitionFlipY* pScene = new CCTransitionFlipY(); - pScene->initWithDuration(t, s, o); - pScene->autorelease(); - - return pScene; -} - -// -// FlipAngular Transition -// -CCTransitionFlipAngular::CCTransitionFlipAngular() -{ -} -CCTransitionFlipAngular::~CCTransitionFlipAngular() -{ -} - -void CCTransitionFlipAngular::onEnter() -{ - CCTransitionSceneOriented::onEnter(); - - CCActionInterval *inA, *outA; - m_pInScene->setIsVisible(false); - - float inDeltaZ, inAngleZ; - float outDeltaZ, outAngleZ; - - if( m_eOrientation == kOrientationRightOver ) - { - inDeltaZ = 90; - inAngleZ = 270; - outDeltaZ = 90; - outAngleZ = 0; - } - else - { - inDeltaZ = -90; - inAngleZ = 90; - outDeltaZ = -90; - outAngleZ = 0; - } - - inA = (CCActionInterval *)CCSequence::actions - ( - CCDelayTime::actionWithDuration(m_fDuration/2), - CCShow::action(), - CCOrbitCamera::actionWithDuration(m_fDuration/2, 1, 0, inAngleZ, inDeltaZ, -45, 0), - CCCallFunc::actionWithTarget(this, callfunc_selector(CCTransitionScene::finish)), - NULL - ); - outA = (CCActionInterval *)CCSequence::actions - ( - CCOrbitCamera::actionWithDuration(m_fDuration/2, 1, 0, outAngleZ, outDeltaZ, 45, 0), - CCHide::action(), - CCDelayTime::actionWithDuration(m_fDuration/2), - NULL - ); - - m_pInScene->runAction(inA); - m_pOutScene->runAction(outA); -} - -CCTransitionFlipAngular* CCTransitionFlipAngular::transitionWithDuration(ccTime t, CCScene* s, tOrientation o) -{ - CCTransitionFlipAngular* pScene = new CCTransitionFlipAngular(); - pScene->initWithDuration(t, s, o); - pScene->autorelease(); - - return pScene; -} - -// -// ZoomFlipX Transition -// -CCTransitionZoomFlipX::CCTransitionZoomFlipX() -{ -} -CCTransitionZoomFlipX::~CCTransitionZoomFlipX() -{ -} - -void CCTransitionZoomFlipX::onEnter() -{ - CCTransitionSceneOriented::onEnter(); - - CCActionInterval *inA, *outA; - m_pInScene->setIsVisible(false); - - float inDeltaZ, inAngleZ; - float outDeltaZ, outAngleZ; - - if( m_eOrientation == kOrientationRightOver ) { - inDeltaZ = 90; - inAngleZ = 270; - outDeltaZ = 90; - outAngleZ = 0; - } - else - { - inDeltaZ = -90; - inAngleZ = 90; - outDeltaZ = -90; - outAngleZ = 0; - } - inA = (CCActionInterval *)CCSequence::actions - ( - CCDelayTime::actionWithDuration(m_fDuration/2), - CCSpawn::actions - ( - CCOrbitCamera::actionWithDuration(m_fDuration/2, 1, 0, inAngleZ, inDeltaZ, 0, 0), - CCScaleTo::actionWithDuration(m_fDuration/2, 1), - CCShow::action(), - NULL - ), - CCCallFunc::actionWithTarget(this, callfunc_selector(CCTransitionScene::finish)), - NULL - ); - outA = (CCActionInterval *)CCSequence::actions - ( - CCSpawn::actions - ( - CCOrbitCamera::actionWithDuration(m_fDuration/2, 1, 0, outAngleZ, outDeltaZ, 0, 0), - CCScaleTo::actionWithDuration(m_fDuration/2, 0.5f), - NULL - ), - CCHide::action(), - CCDelayTime::actionWithDuration(m_fDuration/2), - NULL - ); - - m_pInScene->setScale(0.5f); - m_pInScene->runAction(inA); - m_pOutScene->runAction(outA); -} - -CCTransitionZoomFlipX* CCTransitionZoomFlipX::transitionWithDuration(ccTime t, CCScene* s, tOrientation o) -{ - CCTransitionZoomFlipX* pScene = new CCTransitionZoomFlipX(); - pScene->initWithDuration(t, s, o); - pScene->autorelease(); - - return pScene; -} - -// -// ZoomFlipY Transition -// -CCTransitionZoomFlipY::CCTransitionZoomFlipY() -{ -} -CCTransitionZoomFlipY::~CCTransitionZoomFlipY() -{ -} - -void CCTransitionZoomFlipY::onEnter() -{ - CCTransitionSceneOriented::onEnter(); - - CCActionInterval *inA, *outA; - m_pInScene->setIsVisible(false); - - float inDeltaZ, inAngleZ; - float outDeltaZ, outAngleZ; - - if( m_eOrientation== kOrientationUpOver ) { - inDeltaZ = 90; - inAngleZ = 270; - outDeltaZ = 90; - outAngleZ = 0; - } else { - inDeltaZ = -90; - inAngleZ = 90; - outDeltaZ = -90; - outAngleZ = 0; - } - - inA = (CCActionInterval *)CCSequence::actions - ( - CCDelayTime::actionWithDuration(m_fDuration/2), - CCSpawn::actions - ( - CCOrbitCamera::actionWithDuration(m_fDuration/2, 1, 0, inAngleZ, inDeltaZ, 90, 0), - CCScaleTo::actionWithDuration(m_fDuration/2, 1), - CCShow::action(), - NULL - ), - CCCallFunc::actionWithTarget(this, callfunc_selector(CCTransitionScene::finish)), - NULL - ); - - outA = (CCActionInterval *)CCSequence::actions - ( - CCSpawn::actions - ( - CCOrbitCamera::actionWithDuration(m_fDuration/2, 1, 0, outAngleZ, outDeltaZ, 90, 0), - CCScaleTo::actionWithDuration(m_fDuration/2, 0.5f), - NULL - ), - CCHide::action(), - CCDelayTime::actionWithDuration(m_fDuration/2), - NULL - ); - - m_pInScene->setScale(0.5f); - m_pInScene->runAction(inA); - m_pOutScene->runAction(outA); -} - -CCTransitionZoomFlipY* CCTransitionZoomFlipY::transitionWithDuration(ccTime t, CCScene* s, tOrientation o) -{ - CCTransitionZoomFlipY* pScene = new CCTransitionZoomFlipY(); - pScene->initWithDuration(t, s, o); - pScene->autorelease(); - - return pScene; -} - -// -// ZoomFlipAngular Transition -// -CCTransitionZoomFlipAngular::CCTransitionZoomFlipAngular() -{ -} -CCTransitionZoomFlipAngular::~CCTransitionZoomFlipAngular() -{ -} - - -void CCTransitionZoomFlipAngular::onEnter() -{ - CCTransitionSceneOriented::onEnter(); - - CCActionInterval *inA, *outA; - m_pInScene->setIsVisible(false); - - float inDeltaZ, inAngleZ; - float outDeltaZ, outAngleZ; - - if( m_eOrientation == kOrientationRightOver ) { - inDeltaZ = 90; - inAngleZ = 270; - outDeltaZ = 90; - outAngleZ = 0; - } - else - { - inDeltaZ = -90; - inAngleZ = 90; - outDeltaZ = -90; - outAngleZ = 0; - } - - inA = (CCActionInterval *)CCSequence::actions - ( - CCDelayTime::actionWithDuration(m_fDuration/2), - CCSpawn::actions - ( - CCOrbitCamera::actionWithDuration(m_fDuration/2, 1, 0, inAngleZ, inDeltaZ, -45, 0), - CCScaleTo::actionWithDuration(m_fDuration/2, 1), - CCShow::action(), - NULL - ), - CCShow::action(), - CCCallFunc::actionWithTarget(this, callfunc_selector(CCTransitionScene::finish)), - NULL - ); - outA = (CCActionInterval *)CCSequence::actions - ( - CCSpawn::actions - ( - CCOrbitCamera::actionWithDuration(m_fDuration/2, 1, 0 , outAngleZ, outDeltaZ, 45, 0), - CCScaleTo::actionWithDuration(m_fDuration/2, 0.5f), - NULL - ), - CCHide::action(), - CCDelayTime::actionWithDuration(m_fDuration/2), - NULL - ); - - m_pInScene->setScale(0.5f); - m_pInScene->runAction(inA); - m_pOutScene->runAction(outA); -} - -CCTransitionZoomFlipAngular* CCTransitionZoomFlipAngular::transitionWithDuration(ccTime t, CCScene* s, tOrientation o) -{ - CCTransitionZoomFlipAngular* pScene = new CCTransitionZoomFlipAngular(); - pScene->initWithDuration(t, s, o); - pScene->autorelease(); - - return pScene; -} - -// -// Fade Transition -// -CCTransitionFade::CCTransitionFade() -{ -} -CCTransitionFade::~CCTransitionFade() -{ -} - - -CCTransitionFade * CCTransitionFade::transitionWithDuration(ccTime duration, CCScene *scene, ccColor3B color) -{ - CCTransitionFade * pTransition = new CCTransitionFade(); - pTransition->initWithDuration(duration, scene, color); - pTransition->autorelease(); - return pTransition; -} - -bool CCTransitionFade::initWithDuration(ccTime duration, CCScene *scene, ccColor3B color) -{ - if (CCTransitionScene::initWithDuration(duration, scene)) - { - m_tColor.r = color.r; - m_tColor.g = color.g; - m_tColor.b = color.b; - } - return true; -} - -bool CCTransitionFade::initWithDuration(ccTime t, CCScene *scene) -{ - this->initWithDuration(t, scene, ccBLACK); - return true; -} - -void CCTransitionFade :: onEnter() -{ - CCTransitionScene::onEnter(); - - CCColorLayer* l = CCColorLayer::layerWithColor(m_tColor); - m_pInScene->setIsVisible(false); - - addChild(l, 2, kSceneFade); - CCNode* f = getChildByTag(kSceneFade); - - CCActionInterval* a = (CCActionInterval *)CCSequence::actions - ( - CCFadeIn::actionWithDuration(m_fDuration/2), - CCCallFunc::actionWithTarget(this, callfunc_selector(CCTransitionScene::hideOutShowIn)),//CCCallFunc::actionWithTarget:self selector:@selector(hideOutShowIn)], - CCFadeOut::actionWithDuration(m_fDuration/2), - CCCallFunc::actionWithTarget(this, callfunc_selector(CCTransitionScene::finish)), //:self selector:@selector(finish)], - NULL - ); - f->runAction(a); -} - -void CCTransitionFade::onExit() -{ - CCTransitionScene::onExit(); - this->removeChildByTag(kSceneFade, false); -} - -// -// Cross Fade Transition -// -CCTransitionCrossFade::CCTransitionCrossFade() -{ -} -CCTransitionCrossFade::~CCTransitionCrossFade() -{ -} - - -void CCTransitionCrossFade:: draw() -{ - // override draw since both scenes (textures) are rendered in 1 scene -} - -void CCTransitionCrossFade::onEnter() -{ - CCTransitionScene::onEnter(); - - // create a transparent color layer - // in which we are going to add our rendertextures - ccColor4B color = {0,0,0,0}; - CGSize size = CCDirector::sharedDirector()->getWinSize(); - CCColorLayer* layer = CCColorLayer::layerWithColor(color); - - // create the first render texture for inScene - CCRenderTexture* inTexture = CCRenderTexture::renderTextureWithWidthAndHeight((int)size.width, (int)size.height); - inTexture->getSprite()->setAnchorPoint( ccp(0.5f,0.5f) ); - inTexture->setPosition( ccp(size.width/2, size.height/2) ); - inTexture->setAnchorPoint( ccp(0.5f,0.5f) ); - - // render inScene to its texturebuffer - inTexture->begin(); - m_pInScene->visit(); - inTexture->end(); - - // create the second render texture for outScene - CCRenderTexture* outTexture = CCRenderTexture::renderTextureWithWidthAndHeight((int)size.width, (int)size.height); - outTexture->getSprite()->setAnchorPoint( ccp(0.5f,0.5f) ); - outTexture->setPosition( ccp(size.width/2, size.height/2) ); - outTexture->setAnchorPoint( ccp(0.5f,0.5f) ); - - // render outScene to its texturebuffer - outTexture->begin(); - m_pOutScene->visit(); - outTexture->end(); - - // create blend functions - - ccBlendFunc blend1 = {GL_ONE, GL_ONE}; // inScene will lay on background and will not be used with alpha - ccBlendFunc blend2 = {GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA}; // we are going to blend outScene via alpha - - // set blendfunctions - inTexture->getSprite()->setBlendFunc(blend1); - outTexture->getSprite()->setBlendFunc(blend2); - - // add render textures to the layer - layer->addChild(inTexture); - layer->addChild(outTexture); - - // initial opacity: - inTexture->getSprite()->setOpacity(255); - outTexture->getSprite()->setOpacity(255); - - // create the blend action - CCAction* layerAction = CCSequence::actions - ( - CCFadeTo::actionWithDuration(m_fDuration, 0), - CCCallFunc::actionWithTarget(this, callfunc_selector(CCTransitionScene::hideOutShowIn)), - CCCallFunc::actionWithTarget(this, callfunc_selector(CCTransitionScene::finish)), - NULL - ); - - - // run the blend action - outTexture->getSprite()->runAction( layerAction ); - - // add the layer (which contains our two rendertextures) to the scene - addChild(layer, 2, kSceneFade); -} - -// clean up on exit -void CCTransitionCrossFade::onExit() -{ - // remove our layer and release all containing objects - this->removeChildByTag(kSceneFade, false); - CCTransitionScene::onExit(); -} - -CCTransitionCrossFade* CCTransitionCrossFade::transitionWithDuration(ccTime d, CCScene* s) -{ - CCTransitionCrossFade* Transition = new CCTransitionCrossFade(); - Transition->initWithDuration(d, s); - Transition->autorelease(); - - return Transition; -} - -// -// TurnOffTilesTransition -// -CCTransitionTurnOffTiles::CCTransitionTurnOffTiles() -{ -} -CCTransitionTurnOffTiles::~CCTransitionTurnOffTiles() -{ -} - - -// override addScenes, and change the order -void CCTransitionTurnOffTiles::sceneOrder() -{ - m_bIsInSceneOnTop = false; -} - -void CCTransitionTurnOffTiles::onEnter() -{ - CCTransitionScene::onEnter(); - CGSize s = CCDirector::sharedDirector()->getWinSize(); - float aspect = s.width / s.height; - int x = (int)(12 * aspect); - int y = 12; - - CCTurnOffTiles* toff = CCTurnOffTiles::actionWithSize( ccg(x,y), m_fDuration); - CCActionInterval* action = easeActionWithAction(toff); - m_pOutScene->runAction - ( - CCSequence::actions - ( - action, - CCCallFunc::actionWithTarget(this, callfunc_selector(CCTransitionScene::finish)), - CCStopGrid::action(), - NULL - ) - ); -} - - -CCActionInterval* CCTransitionTurnOffTiles:: easeActionWithAction(CCActionInterval* action) -{ - return action; -} - -IMPLEMENT_TRANSITIONWITHDURATION(CCTransitionTurnOffTiles) - -// -// SplitCols Transition -// -CCTransitionSplitCols::CCTransitionSplitCols() -{ -} -CCTransitionSplitCols::~CCTransitionSplitCols() -{ -} - - -void CCTransitionSplitCols::onEnter() -{ - CCTransitionScene::onEnter(); - m_pInScene->setIsVisible(false); - - CCActionInterval* split = action(); - CCActionInterval* seq = (CCActionInterval*)CCSequence::actions - ( - split, - CCCallFunc::actionWithTarget(this, callfunc_selector(CCTransitionScene::hideOutShowIn)), - split->reverse(), - NULL - ); - - this->runAction - ( - CCSequence::actions - ( - easeActionWithAction(seq), - CCCallFunc::actionWithTarget(this, callfunc_selector(CCTransitionScene::finish)), - CCStopGrid::action(), - NULL - ) - ); -} - - -CCActionInterval* CCTransitionSplitCols:: action() -{ - return CCSplitCols::actionWithCols(3, m_fDuration/2.0f); -} - - -CCActionInterval* CCTransitionSplitCols::easeActionWithAction(CCActionInterval * action) -{ - return CCEaseInOut::actionWithAction(action, 3.0f); -} - -IMPLEMENT_TRANSITIONWITHDURATION(CCTransitionSplitCols) - - -// -// SplitRows Transition -// -CCTransitionSplitRows::CCTransitionSplitRows() -{ -} -CCTransitionSplitRows::~CCTransitionSplitRows() -{ -} - - -CCActionInterval* CCTransitionSplitRows::action() -{ - return CCSplitRows::actionWithRows(3, m_fDuration/2.0f); -} - -IMPLEMENT_TRANSITIONWITHDURATION(CCTransitionSplitRows) - -// -// FadeTR Transition -// -CCTransitionFadeTR::CCTransitionFadeTR() -{ -} -CCTransitionFadeTR::~CCTransitionFadeTR() -{ -} - - -void CCTransitionFadeTR::sceneOrder() -{ - m_bIsInSceneOnTop = false; -} - -void CCTransitionFadeTR::onEnter() -{ - CCTransitionScene::onEnter(); - - CGSize s = CCDirector::sharedDirector()->getWinSize(); - float aspect = s.width / s.height; - int x = (int)(12 * aspect); - int y = 12; - - CCActionInterval* action = actionWithSize(ccg(x,y)); - - m_pOutScene->runAction - ( - CCSequence::actions - ( - easeActionWithAction(action), - CCCallFunc::actionWithTarget(this, callfunc_selector(CCTransitionScene::finish)), - CCStopGrid::action(), - NULL - ) - ); -} - - -CCActionInterval* CCTransitionFadeTR::actionWithSize(ccGridSize size) -{ - return CCFadeOutTRTiles::actionWithSize(size, m_fDuration); -} - -CCActionInterval* CCTransitionFadeTR:: easeActionWithAction(CCActionInterval* action) -{ - return action; -} - -IMPLEMENT_TRANSITIONWITHDURATION(CCTransitionFadeTR) - - -// -// FadeBL Transition -// - -CCTransitionFadeBL::CCTransitionFadeBL() -{ -} -CCTransitionFadeBL::~CCTransitionFadeBL() -{ -} - -CCActionInterval* CCTransitionFadeBL::actionWithSize(ccGridSize size) -{ - return CCFadeOutBLTiles::actionWithSize(size, m_fDuration); -} - -IMPLEMENT_TRANSITIONWITHDURATION(CCTransitionFadeBL) - -// -// FadeUp Transition -// -CCTransitionFadeUp::CCTransitionFadeUp() -{ -} -CCTransitionFadeUp::~CCTransitionFadeUp() -{ -} - -CCActionInterval* CCTransitionFadeUp::actionWithSize(ccGridSize size) -{ - return CCFadeOutUpTiles::actionWithSize(size, m_fDuration); -} - -IMPLEMENT_TRANSITIONWITHDURATION(CCTransitionFadeUp) - -// -// FadeDown Transition -// -CCTransitionFadeDown::CCTransitionFadeDown() -{ -} -CCTransitionFadeDown::~CCTransitionFadeDown() -{ -} - -CCActionInterval* CCTransitionFadeDown::actionWithSize(ccGridSize size) -{ - return CCFadeOutDownTiles::actionWithSize(size, m_fDuration); -} - -IMPLEMENT_TRANSITIONWITHDURATION(CCTransitionFadeDown) - -}//namespace cocos2d diff --git a/cocos2dx/platform/mac/MacGLView.h b/cocos2dx/platform/mac/MacGLView.h deleted file mode 100644 index de31c6ad46..0000000000 --- a/cocos2dx/platform/mac/MacGLView.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * cocos2d for iPhone: http://www.cocos2d-iphone.org - * - * Copyright (c) 2010 Ricardo Quesada - * - * 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. - */ - -// Only compile this code on Mac. These files should not be included on your iOS project. -// But in case they are included, it won't be compiled. -#import -#import - -#import "ccConfig.h" - -//PROTOCOLS: - -@protocol MacEventDelegate -// Mouse -- (void)mouseDown:(NSEvent *)theEvent; -- (void)mouseUp:(NSEvent *)theEvent; -- (void)mouseMoved:(NSEvent *)theEvent; -- (void)mouseDragged:(NSEvent *)theEvent; -- (void)rightMouseDown:(NSEvent*)event; -- (void)rightMouseDragged:(NSEvent*)event; -- (void)rightMouseUp:(NSEvent*)event; -- (void)otherMouseDown:(NSEvent*)event; -- (void)otherMouseDragged:(NSEvent*)event; -- (void)otherMouseUp:(NSEvent*)event; -- (void)scrollWheel:(NSEvent *)theEvent; -- (void)mouseEntered:(NSEvent *)theEvent; -- (void)mouseExited:(NSEvent *)theEvent; - - -// Keyboard -- (void)keyDown:(NSEvent *)theEvent; -- (void)keyUp:(NSEvent *)theEvent; -- (void)flagsChanged:(NSEvent *)theEvent; - -// Touches -- (void)touchesBeganWithEvent:(NSEvent *)event; -- (void)touchesMovedWithEvent:(NSEvent *)event; -- (void)touchesEndedWithEvent:(NSEvent *)event; -- (void)touchesCancelledWithEvent:(NSEvent *)event; - -#if CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD -- (void)queueEvent:(NSEvent*)event selector:(SEL)selector; -#endif - -@end - -/** MacGLView - - Only available for Mac OS X - */ -@interface MacGLView : NSOpenGLView { - id eventDelegate_; -} - -@property (nonatomic, readwrite, assign) id eventDelegate; - -// initializes the MacGLView with a frame rect and an OpenGL context -- (id) initWithFrame:(NSRect)frameRect shareContext:(NSOpenGLContext*)context; - -// private -+(void) load_; -@end diff --git a/cocos2dx/platform/mac/MacGLView.mm b/cocos2dx/platform/mac/MacGLView.mm deleted file mode 100644 index 722fc33895..0000000000 --- a/cocos2dx/platform/mac/MacGLView.mm +++ /dev/null @@ -1,241 +0,0 @@ -/* - * cocos2d for iPhone: http://www.cocos2d-iphone.org - * - * Copyright (c) 2010 Ricardo Quesada - * - * 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. - */ - -/* - * Idea of subclassing NSOpenGLView was taken from "TextureUpload" Apple's sample - */ - -// Only compile this code on Mac. These files should not be included on your iOS project. -// But in case they are included, it won't be compiled. -#import -#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED -#elif defined(__MAC_OS_X_VERSION_MAX_ALLOWED) - -#import "MacGLView.h" -#import - -#import "CCDirectorMac.h" -#import "ccConfig.h" - - -@implementation MacGLView - -@synthesize eventDelegate = eventDelegate_; - -+(void) load_ -{ - NSLog(@"%@ loaded", self); -} - -- (id) initWithFrame:(NSRect)frameRect -{ - self = [self initWithFrame:frameRect shareContext:nil]; - return self; -} - -- (id) initWithFrame:(NSRect)frameRect shareContext:(NSOpenGLContext*)context -{ - NSOpenGLPixelFormatAttribute attribs[] = - { - NSOpenGLPFAAccelerated, - NSOpenGLPFANoRecovery, - NSOpenGLPFADoubleBuffer, - NSOpenGLPFADepthSize, 24, - - 0 - }; - - NSOpenGLPixelFormat *pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs]; - - if (!pixelFormat) - NSLog(@"No OpenGL pixel format"); - - if (self = [super initWithFrame:frameRect pixelFormat:[pixelFormat autorelease]]) { - - if( context ) - [self setOpenGLContext:context]; - - // Synchronize buffer swaps with vertical refresh rate - GLint swapInt = 1; - [[self openGLContext] setValues:&swapInt forParameter:NSOpenGLCPSwapInterval]; - -// GLint order = -1; -// [[self openGLContext] setValues:&order forParameter:NSOpenGLCPSurfaceOrder]; - - // event delegate - eventDelegate_ = nil; - } - - return self; -} - -- (void) reshape -{ - // We draw on a secondary thread through the display link - // When resizing the view, -reshape is called automatically on the main thread - // Add a mutex around to avoid the threads accessing the context simultaneously when resizing - CGLLockContext([[self openGLContext] CGLContextObj]); - - NSRect rect = [self bounds]; - - CCDirector *director = cocos2d::CCDirector::sharedDirector(); - director->reshapeProjection(NSSizeToCGSize(rect.size)); - - // avoid flicker - director->drawScene(); -// [self setNeedsDisplay:YES]; - - CGLUnlockContext([[self openGLContext] CGLContextObj]); -} - -- (void) dealloc -{ - - [super dealloc]; -} - -#if CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD -#define DISPATCH_EVENT(__event__, __selector__) [eventDelegate_ queueEvent:__event__ selector:__selector__]; -#else -#define DISPATCH_EVENT(__event__, __selector__) \ - id obj = eventDelegate_; \ - [obj performSelector:__selector__ \ - onThread:[[CCDirectorDisplayLinkMacWrapper sharedDisplayLinkMacWrapper] runningThread] \ - withObject:__event__ \ - waitUntilDone:NO]; -#endif - -#pragma mark MacGLView - Mouse events -- (void)mouseDown:(NSEvent *)theEvent -{ - DISPATCH_EVENT(theEvent, _cmd); -} - -- (void)mouseMoved:(NSEvent *)theEvent -{ - DISPATCH_EVENT(theEvent, _cmd); -} - -- (void)mouseDragged:(NSEvent *)theEvent -{ - DISPATCH_EVENT(theEvent, _cmd); -} - -- (void)mouseUp:(NSEvent *)theEvent -{ - DISPATCH_EVENT(theEvent, _cmd); -} - -- (void)rightMouseDown:(NSEvent *)theEvent { - DISPATCH_EVENT(theEvent, _cmd); -} - -- (void)rightMouseDragged:(NSEvent *)theEvent { - DISPATCH_EVENT(theEvent, _cmd); -} - -- (void)rightMouseUp:(NSEvent *)theEvent { - DISPATCH_EVENT(theEvent, _cmd); -} - -- (void)otherMouseDown:(NSEvent *)theEvent { - DISPATCH_EVENT(theEvent, _cmd); -} - -- (void)otherMouseDragged:(NSEvent *)theEvent { - DISPATCH_EVENT(theEvent, _cmd); -} - -- (void)otherMouseUp:(NSEvent *)theEvent { - DISPATCH_EVENT(theEvent, _cmd); -} - -- (void)mouseEntered:(NSEvent *)theEvent { - DISPATCH_EVENT(theEvent, _cmd); -} - -- (void)mouseExited:(NSEvent *)theEvent { - DISPATCH_EVENT(theEvent, _cmd); -} - --(void) scrollWheel:(NSEvent *)theEvent { - DISPATCH_EVENT(theEvent, _cmd); -} - -#pragma mark MacGLView - Key events - --(BOOL) becomeFirstResponder -{ - return YES; -} - --(BOOL) acceptsFirstResponder -{ - return YES; -} - --(BOOL) resignFirstResponder -{ - return YES; -} - -- (void)keyDown:(NSEvent *)theEvent -{ - DISPATCH_EVENT(theEvent, _cmd); -} - -- (void)keyUp:(NSEvent *)theEvent -{ - DISPATCH_EVENT(theEvent, _cmd); -} - -- (void)flagsChanged:(NSEvent *)theEvent -{ - DISPATCH_EVENT(theEvent, _cmd); -} - -#pragma mark MacGLView - Touch events -- (void)touchesBeganWithEvent:(NSEvent *)theEvent -{ - DISPATCH_EVENT(theEvent, _cmd); -} - -- (void)touchesMovedWithEvent:(NSEvent *)theEvent -{ - DISPATCH_EVENT(theEvent, _cmd); -} - -- (void)touchesEndedWithEvent:(NSEvent *)theEvent -{ - DISPATCH_EVENT(theEvent, _cmd); -} - -- (void)touchesCancelledWithEvent:(NSEvent *)theEvent -{ - DISPATCH_EVENT(theEvent, _cmd); -} - -@end - -#endif // __MAC_OS_X_VERSION_MAX_ALLOWED \ No newline at end of file diff --git a/cocos2dx/proj.win32/cocos2d-win32.vcproj b/cocos2dx/proj.win32/cocos2d-win32.vcproj index 108b0db099..5726547c69 100644 --- a/cocos2dx/proj.win32/cocos2d-win32.vcproj +++ b/cocos2dx/proj.win32/cocos2d-win32.vcproj @@ -399,14 +399,6 @@ RelativePath="..\include\CCEGLView.h" > - - - - @@ -415,10 +407,6 @@ RelativePath="..\include\CCGL.h" > - - @@ -459,10 +447,6 @@ RelativePath="..\include\CCMotionStreak.h" > - - @@ -651,6 +635,10 @@ + + @@ -667,6 +655,10 @@ + + @@ -703,6 +695,10 @@ RelativePath="..\particle_nodes\CCParticleSystem.cpp" > + + @@ -767,34 +763,14 @@ RelativePath="..\platform\CCImage.h" > - - - - - - - - - - @@ -1068,22 +1044,6 @@ > - - - - - - - - diff --git a/cocos2dx/proj.wophone/Makefile.ARM b/cocos2dx/proj.wophone/Makefile.ARM index ba721c87b3..5c702e3982 100644 --- a/cocos2dx/proj.wophone/Makefile.ARM +++ b/cocos2dx/proj.wophone/Makefile.ARM @@ -58,17 +58,16 @@ OBJECTS = \ $(OBJECTS_DIR)/CCSet.o \ $(OBJECTS_DIR)/CCZone.o \ $(OBJECTS_DIR)/CCGrabber.o \ - $(OBJECTS_DIR)/CCEventDispatcher.o \ - $(OBJECTS_DIR)/CCKeyboardEventDelegate.o \ - $(OBJECTS_DIR)/CCMouseEventDelegate.o \ $(OBJECTS_DIR)/CCKeypadDelegate.o \ $(OBJECTS_DIR)/CCKeypadDispatcher.o \ $(OBJECTS_DIR)/CCLabelAtlas.o \ $(OBJECTS_DIR)/CCLabelBMFont.o \ $(OBJECTS_DIR)/CCLabelTTF.o \ + $(OBJECTS_DIR)/CCLayer.o \ $(OBJECTS_DIR)/CCScene.o \ $(OBJECTS_DIR)/CCTransitionPageTurn.o \ $(OBJECTS_DIR)/CCTransitionRadial.o \ + $(OBJECTS_DIR)/CCMenu.o \ $(OBJECTS_DIR)/CCMenuItem.o \ $(OBJECTS_DIR)/CCMotionStreak.o \ $(OBJECTS_DIR)/CCProgressTimer.o \ @@ -76,6 +75,7 @@ OBJECTS = \ $(OBJECTS_DIR)/CCRibbon.o \ $(OBJECTS_DIR)/CCParticleExamples.o \ $(OBJECTS_DIR)/CCParticleSystem.o \ + $(OBJECTS_DIR)/CCParticleSystemPoint.o \ $(OBJECTS_DIR)/CCParticleSystemQuad.o \ $(OBJECTS_DIR)/CCCommon.o \ $(OBJECTS_DIR)/CCDirector_mobile.o \ @@ -83,10 +83,7 @@ OBJECTS = \ $(OBJECTS_DIR)/CCGL.o \ $(OBJECTS_DIR)/CCGrid_mobile.o \ $(OBJECTS_DIR)/CCImage.o \ - $(OBJECTS_DIR)/CCLayer_mobile.o \ - $(OBJECTS_DIR)/CCMenu_mobile.o \ $(OBJECTS_DIR)/CCNode_mobile.o \ - $(OBJECTS_DIR)/CCParticleSystemPoint_mobile.o \ $(OBJECTS_DIR)/CCSAXParser.o \ $(OBJECTS_DIR)/CCStdC.o \ $(OBJECTS_DIR)/CCThread.o \ @@ -219,15 +216,6 @@ $(OBJECTS_DIR)/CCZone.o : ../cocoa/CCZone.cpp $(OBJECTS_DIR)/CCGrabber.o : ../effects/CCGrabber.cpp $(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/CCGrabber.o ../effects/CCGrabber.cpp -$(OBJECTS_DIR)/CCEventDispatcher.o : ../event_dispatcher/CCEventDispatcher.cpp - $(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/CCEventDispatcher.o ../event_dispatcher/CCEventDispatcher.cpp - -$(OBJECTS_DIR)/CCKeyboardEventDelegate.o : ../event_dispatcher/CCKeyboardEventDelegate.cpp - $(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/CCKeyboardEventDelegate.o ../event_dispatcher/CCKeyboardEventDelegate.cpp - -$(OBJECTS_DIR)/CCMouseEventDelegate.o : ../event_dispatcher/CCMouseEventDelegate.cpp - $(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/CCMouseEventDelegate.o ../event_dispatcher/CCMouseEventDelegate.cpp - $(OBJECTS_DIR)/CCKeypadDelegate.o : ../keypad_dispatcher/CCKeypadDelegate.cpp $(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/CCKeypadDelegate.o ../keypad_dispatcher/CCKeypadDelegate.cpp @@ -243,6 +231,9 @@ $(OBJECTS_DIR)/CCLabelBMFont.o : ../label_nodes/CCLabelBMFont.cpp $(OBJECTS_DIR)/CCLabelTTF.o : ../label_nodes/CCLabelTTF.cpp $(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/CCLabelTTF.o ../label_nodes/CCLabelTTF.cpp +$(OBJECTS_DIR)/CCLayer.o : ../layers_scenes_transitions_nodes/CCLayer.cpp + $(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/CCLayer.o ../layers_scenes_transitions_nodes/CCLayer.cpp + $(OBJECTS_DIR)/CCScene.o : ../layers_scenes_transitions_nodes/CCScene.cpp $(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/CCScene.o ../layers_scenes_transitions_nodes/CCScene.cpp @@ -252,6 +243,9 @@ $(OBJECTS_DIR)/CCTransitionPageTurn.o : ../layers_scenes_transitions_nodes/CCTra $(OBJECTS_DIR)/CCTransitionRadial.o : ../layers_scenes_transitions_nodes/CCTransitionRadial.cpp $(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/CCTransitionRadial.o ../layers_scenes_transitions_nodes/CCTransitionRadial.cpp +$(OBJECTS_DIR)/CCMenu.o : ../menu_nodes/CCMenu.cpp + $(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/CCMenu.o ../menu_nodes/CCMenu.cpp + $(OBJECTS_DIR)/CCMenuItem.o : ../menu_nodes/CCMenuItem.cpp $(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/CCMenuItem.o ../menu_nodes/CCMenuItem.cpp @@ -273,6 +267,9 @@ $(OBJECTS_DIR)/CCParticleExamples.o : ../particle_nodes/CCParticleExamples.cpp $(OBJECTS_DIR)/CCParticleSystem.o : ../particle_nodes/CCParticleSystem.cpp $(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/CCParticleSystem.o ../particle_nodes/CCParticleSystem.cpp +$(OBJECTS_DIR)/CCParticleSystemPoint.o : ../particle_nodes/CCParticleSystemPoint.cpp + $(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/CCParticleSystemPoint.o ../particle_nodes/CCParticleSystemPoint.cpp + $(OBJECTS_DIR)/CCParticleSystemQuad.o : ../particle_nodes/CCParticleSystemQuad.cpp $(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/CCParticleSystemQuad.o ../particle_nodes/CCParticleSystemQuad.cpp @@ -294,24 +291,15 @@ $(OBJECTS_DIR)/CCGrid_mobile.o : ../platform/CCGrid_mobile.cpp $(OBJECTS_DIR)/CCImage.o : ../platform/CCImage.cpp $(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/CCImage.o ../platform/CCImage.cpp -$(OBJECTS_DIR)/CCLayer_mobile.o : ../platform/CCLayer_mobile.cpp - $(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/CCLayer_mobile.o ../platform/CCLayer_mobile.cpp - -$(OBJECTS_DIR)/CCMenu_mobile.o : ../platform/CCMenu_mobile.cpp - $(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/CCMenu_mobile.o ../platform/CCMenu_mobile.cpp - $(OBJECTS_DIR)/CCNode_mobile.o : ../platform/CCNode_mobile.cpp $(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/CCNode_mobile.o ../platform/CCNode_mobile.cpp -$(OBJECTS_DIR)/CCParticleSystemPoint_mobile.o : ../platform/CCParticleSystemPoint_mobile.cpp - $(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/CCParticleSystemPoint_mobile.o ../platform/CCParticleSystemPoint_mobile.cpp +$(OBJECTS_DIR)/CCSAXParser.o : ../platform/CCSAXParser.cpp + $(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/CCSAXParser.o ../platform/CCSAXParser.cpp $(OBJECTS_DIR)/CCStdC.o : ../platform/CCStdC.cpp $(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/CCStdC.o ../platform/CCStdC.cpp -$(OBJECTS_DIR)/CCSAXParser.o : ../platform/CCSAXParser.cpp - $(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/CCSAXParser.o ../platform/CCSAXParser.cpp - $(OBJECTS_DIR)/CCThread.o : ../platform/CCThread.cpp $(CXX) -c $(CXX_FLAGS) $(INCLUDE_PATH) $(LAST_INCLUDE_PATH) -o $(OBJECTS_DIR)/CCThread.o ../platform/CCThread.cpp diff --git a/cocos2dx/proj.wophone/cocos2d-wophone.vcproj b/cocos2dx/proj.wophone/cocos2d-wophone.vcproj index e70096bdff..aec5e194c7 100644 --- a/cocos2dx/proj.wophone/cocos2d-wophone.vcproj +++ b/cocos2dx/proj.wophone/cocos2d-wophone.vcproj @@ -360,14 +360,6 @@ RelativePath="..\include\CCEGLView.h" > - - - - @@ -376,10 +368,6 @@ RelativePath="..\include\CCGL.h" > - - @@ -420,10 +408,6 @@ RelativePath="..\include\CCMotionStreak.h" > - - @@ -612,6 +596,10 @@ + + @@ -628,6 +616,10 @@ + + @@ -665,7 +657,7 @@ > - - - - - - - - @@ -1089,22 +1065,6 @@ > - - - - - - - -