void CCDirector::setOpenGLView(CC_GLVIEW *pobOpenGLView) { CCAssert(pobOpenGLView, "opengl view should not be null"); if (m_pobOpenGLView != pobOpenGLView) { // because EAGLView is not kind of CCObject delete m_pobOpenGLView; // [openGLView_ release] m_pobOpenGLView = pobOpenGLView; // set size m_obWinSizeInPoints = m_pobOpenGLView->getSize(); m_obWinSizeInPixels = CCSizeMake(m_obWinSizeInPoints.width * m_fContentScaleFactor, m_obWinSizeInPoints.height * m_fContentScaleFactor); setGLDefaultValues(); if (m_fContentScaleFactor != 1) { updateContentScaleFactor(); } CCTouchDispatcher *pTouchDispatcher = CCTouchDispatcher::sharedDispatcher(); m_pobOpenGLView->setTouchDelegate(pTouchDispatcher); pTouchDispatcher->setDispatchEvents(true); } }
KDvoid CCScrollLayer::claimTouch ( CCTouch* pTouch ) { CCTouchDispatcher* pDispatcher = CCDirector::sharedDirector ( )->getTouchDispatcher ( ); CCArray* pTargetedHandlers = pDispatcher->getTargetedHandlers ( ); // Enumerate through all targeted handlers. CCObject* pObject; CCARRAY_FOREACH ( pTargetedHandlers, pObject ) { CCTargetedTouchHandler* pHandler = (CCTargetedTouchHandler*) pObject; // Only our handler should claim the touch. if ( pHandler->getDelegate ( ) == this ) { if ( !pHandler->getClaimedTouches ( )->containsObject ( pTouch ) ) { pHandler->getClaimedTouches ( )->addObject ( pTouch ); } } else { // Steal touch from other targeted delegates, if they claimed it. if ( pHandler->getClaimedTouches ( )->containsObject ( pTouch ) ) { if ( pHandler->getDelegate ( ) ) { pHandler->getDelegate ( )->ccTouchEnded ( pTouch, KD_NULL ); } pHandler->getClaimedTouches ( )->removeObject ( pTouch ); } } }
void CardSprite::touchDelegateRelease() { CCTouchDispatcher* pDispatcher = CCDirector::sharedDirector()->getTouchDispatcher(); pDispatcher->removeDelegate(this); this->release(); }
void TapSprite::onExit() { CCSprite::onExit(); CCTouchDispatcher* dispatcher = CCDirector::sharedDirector()->getTouchDispatcher(); dispatcher->removeDelegate(this); }
void TapSprite::onEnter() { CCSprite::onEnter(); CCTouchDispatcher* dispatcher = CCDirector::sharedDirector()->getTouchDispatcher(); dispatcher->addTargetedDelegate(this, 0, true); }
void CCLayer::registerWithTouchDispatcher() { CCTouchDispatcher* pDispatcher = CCDirector::sharedDirector()->getTouchDispatcher(); // Using LuaBindings if (m_pScriptTouchHandlerEntry) { if (m_pScriptTouchHandlerEntry->isMultiTouches()) { pDispatcher->addStandardDelegate(this, 0); LUALOG("[LUA] Add multi-touches event handler: %d", m_pScriptTouchHandlerEntry->getHandler()); } else { pDispatcher->addTargetedDelegate(this, m_pScriptTouchHandlerEntry->getPriority(), m_pScriptTouchHandlerEntry->getSwallowsTouches()); LUALOG("[LUA] Add touch event handler: %d", m_pScriptTouchHandlerEntry->getHandler()); } } else { if( m_eTouchMode == kCCTouchesAllAtOnce ) { pDispatcher->addStandardDelegate(this, 0); } else { pDispatcher->addTargetedDelegate(this, m_nTouchPriority, true); } } }
HelloWorld::~HelloWorld() { //remove it CCTouchDispatcher* pDispatcher = CCDirector::sharedDirector()->getTouchDispatcher(); pDispatcher->removeDelegate(m_pGUI); //release m_pGUI->release(); }
void CCLayer::registerWithTouchDispatcher() { CCTouchDispatcher* pDispatcher = CCDirector::sharedDirector()->getTouchDispatcher(); if( m_eTouchMode == kCCTouchesAllAtOnce ) { pDispatcher->addStandardDelegate(this, 0); } else { pDispatcher->addTargetedDelegate(this, m_nTouchPriority, m_bSwallowTouch); } }
void CWidgetLayout::setTouchPriority(int nTouchPriority) { if( m_nTouchPriority != nTouchPriority ) { m_nTouchPriority = nTouchPriority; if( m_bTouchEnabled && m_bRunning ) { CCTouchDispatcher* pDispatcher = CCDirector::sharedDirector()->getTouchDispatcher(); pDispatcher->setPriority(nTouchPriority, this); } } }
void TouchComponent::registerWithTouchDispatcher( ) { CCTouchDispatcher *pDispatcher = CCDirector::sharedDirector( )->getTouchDispatcher( ); if ( _touchMode == ALL_AT_ONCE ) { pDispatcher->addStandardDelegate( this, 0 ); } else { pDispatcher->addTargetedDelegate( this, _touchPriority, _swallowsTouches ); } }
void CCTouchInjector::cleanup() { if (m_Enabled) { CCTouchDispatcher* td = CCTouchDispatcher::sharedDispatcher(); td->injectTouches(m_Touches, CCTOUCHCANCELLED); td->unholdUserTouch(); m_Enabled = false; } setEnabled(false); CCNode::cleanup(); }
void CCTouchInjector::setEnabled(bool flag) { if (m_Enabled == flag) return; CCTouchDispatcher* td = CCTouchDispatcher::sharedDispatcher(); if (flag) { td->holdUserTouch(); td->injectTouches(m_Touches, CCTOUCHBEGAN); } else { td->injectTouches(m_Touches, CCTOUCHENDED); td->unholdUserTouch(); } }
/** Hackish stuff - stole touches from other CCTouchDispatcher targeted delegates. Used to claim touch without receiving ccTouchBegan. */ void UIScrollLayer::claimTouch(CCTouch* pTouch) { CCTouchDispatcher* pDispatcher = CCDirector::sharedDirector()->getTouchDispatcher(); CCTargetedTouchHandler* handler = (CCTargetedTouchHandler*)pDispatcher->findHandler(this); if (handler) { CCSet* claimedTouches = handler->getClaimedTouches(); if (!claimedTouches->containsObject(pTouch)) { claimedTouches->addObject(pTouch); } else { CCLOGERROR("CCScrollLayer::claimTouch is already claimed!"); } } }
void TouchGrabber::update(float delta) { mPlayDeltaTime += delta; if (bPlaying == false) return; if (mTouchVecIndice >= mTouchesRecVector.size()) { stop(); return; } TouchRecord rec = mTouchesRecVector.at(mTouchVecIndice); ///CCLOG("rec time: %f play dt: %f",rec.time / 1000.f, mPlayDeltaTime); if (rec.time / 1000.f > mPlayDeltaTime) return; CCTouchDispatcher *dispatcher = CCDirector::sharedDirector()->getTouchDispatcher(); CCSet set; switch (rec.event) { case kTouchBegan: mTouch = new CCTouch(); /// Touch will be destroyed when ended/cancelled mTouch->setTouchInfo(0, rec.x, rec.y); set.addObject(mTouch); dispatcher->touchesBegan(&set, NULL); break; case kTouchMoved: mTouch->setTouchInfo(0, rec.x, rec.y); set.addObject(mTouch); dispatcher->touchesMoved(&set, NULL); break; case kTouchEnded: mTouch->setTouchInfo(0, rec.x, rec.y); set.addObject(mTouch); dispatcher->touchesEnded(&set, NULL); break; case kTouchCancelled: mTouch->setTouchInfo(0, rec.x, rec.y); set.addObject(mTouch); dispatcher->touchesCancelled(&set, NULL); break; default: CCAssert(false, "Unknown touch event."); break; } mTouchVecIndice++; }
void CCLayer::registerWithTouchDispatcher() { CCTouchDispatcher* pDispatcher = CCDirector::sharedDirector()->getTouchDispatcher(); if (m_pScriptHandlerEntry) { if (m_pScriptHandlerEntry->isMultiTouches()) { pDispatcher->addStandardDelegate(this,0); LUALOG("[LUA] Add multi-touches event handler: %d", m_pScriptHandlerEntry->getHandler()); } else { pDispatcher->addTargetedDelegate(this, m_pScriptHandlerEntry->getPriority(), m_pScriptHandlerEntry->getSwallowsTouches()); LUALOG("[LUA] Add touch event handler: %d", m_pScriptHandlerEntry->getHandler()); } return; } pDispatcher->addStandardDelegate(this,0); }
void CCtrlPage::onEnter( void ) { CCLayer::onEnter(); CCDirector* pDirector = CCDirector::sharedDirector(); if (NULL == pDirector) { return; } // 强行修改ScrollView的touch Priority=CtrlPage,后加入的CtrlPage会先响应才能吃掉TouchEnd CCTouchDispatcher* pDispatcher = CCDirector::sharedDirector()->getTouchDispatcher(); if (m_pScrollView && pDispatcher) { // 系统bug,setPriority不会寻找等待加入的Touch Handle // pDispatcher->setPriority(getTouchPriority(), m_pScrollView); pDispatcher->removeDelegate(m_pScrollView); pDispatcher->addTargetedDelegate(m_pScrollView, getTouchPriority(), false); } pDispatcher->removeDelegate(this); pDispatcher->addTargetedDelegate(this, getTouchPriority(), false); }
void CCLayer::onExit() { CCTouchDispatcher* pDispatcher = CCDirector::sharedDirector()->getTouchDispatcher(); if( m_bTouchEnabled ) { pDispatcher->removeDelegate(this); unregisterScriptTouchHandler(); } // remove this layer from the delegates who concern Accelerometer Sensor if (m_bIsAccelerometerEnabled) { CCAccelerometer::sharedAccelerometer()->setDelegate(NULL); } // remove this layer from the delegates who concern the kaypad msg if (m_bIsKeypadEnabled) { CCKeypadDispatcher::sharedDispatcher()->removeDelegate(this); } CCNode::onExit(); }
void CCLayer::setModal(bool flag, bool recursive /*= true*/) { CCTouchDispatcher* td = CCTouchDispatcher::sharedDispatcher(); td->Channel()->send(EVT::CC_TOUCH_MODAL, new CCTouchModalEvent(this, flag)); if (flag) td->AddModal(this); else td->RemoveModal(this); if (!recursive) return; if (m_pChildren) { CCObject* child; CCARRAY_FOREACH(m_pChildren, child) { if (dynamic_cast<CCLayer*>(child)) { static_cast<CCLayer*>(child)->setModal(flag, recursive); } else { CCTouchDelegate* delegate = dynamic_cast<CCTouchDelegate*>(child); if (delegate) { if (flag) td->AddModal(delegate); else td->RemoveModal(delegate); } } } } }
void Palette::setTouchPriority(int newVal) { CCTouchDispatcher* pDispatcher = CCDirector::sharedDirector()->getTouchDispatcher(); pDispatcher->setPriority(newVal, this); }
void Props::setHandlerPriority(int newPriority) { CCTouchDispatcher* pDispatcher = CCDirector::sharedDirector()->getTouchDispatcher(); pDispatcher->setPriority(newPriority, this); }
void AchieveLayer::enableTouch(){ DialogLayer::enableTouch(); CCTouchDispatcher* pDispatcher = CCDirector::sharedDirector()->getTouchDispatcher(); pDispatcher->setPriority(this->getDelegate()->topHandlerPriority()-1, m_pTableView); }
void BBAbstractSceneView::registerWithTouchDispatcher() { CCTouchDispatcher* pDispatcher = CCDirector::sharedDirector()->getTouchDispatcher(); pDispatcher->addStandardDelegate(this, m_nTouchPriority); }
void Troop::onExit() { CCDirector* director = CCDirector::sharedDirector(); CCTouchDispatcher* dispatcher = director->getTouchDispatcher(); dispatcher->removeDelegate(this); }
void HelloWorld::registerWithTouchDispatcher(void) { CCTouchDispatcher* pDispatcher = CCDirector::sharedDirector()->getTouchDispatcher(); pDispatcher->addTargetedDelegate(m_pGUI, INT_MIN + 1, false); }
void UIModelLayerBase::registerWithTouchDispatcher() { CCTouchDispatcher* pDispatcher = CCDirector::sharedDirector()->getTouchDispatcher(); pDispatcher->addTargetedDelegate(this, MODEL_LAYER_PRIORITY, true); }
void SJLayerColor:: onExit() { CCTouchDispatcher * pTarget = CCDirector::sharedDirector()->getTouchDispatcher(); pTarget->removeDelegate(this); }
void SJLayerColor::onEnter() { CCTouchDispatcher * pTarget = CCDirector::sharedDirector()->getTouchDispatcher(); pTarget->addTargetedDelegate(this,0,true); }
void MessageTableLayer::enableTouch(){ DialogLayer::enableTouch(); CCTouchDispatcher* pDispatcher = S_DR->getTouchDispatcher(); pDispatcher->setPriority(this->getDelegate()->topHandlerPriority()-1, m_pTableView); }
void Loading::registerWithTouchDispatcher() { CCTouchDispatcher* pDispatcher = CCDirector::sharedDirector()->getTouchDispatcher(); pDispatcher->addTargetedDelegate(this, kCCMenuHandlerPriority - 1, true); CCLayer::registerWithTouchDispatcher(); }
void Troop::onEnter() { CCLayer::onEnter(); CCDirector* director = CCDirector::sharedDirector(); CCTouchDispatcher* dispatcher = director->getTouchDispatcher(); dispatcher->addTargetedDelegate(this, 0, true); }