Cocos2dx Click Event Analysis (5)

Source: Internet
Author: User

Cocos2dx Click Event Analysis (5)

All the following functions in CCTouchDispatcher are processed by the worker, handleTouchesMove, worker, and handleTouchesCancel of CCEGLViewProtocol, and touches is called. Let's analyze touches function void CCTouchDispatcher :: touchesBegan (CCSet * touches, CCEvent * pEvent) {if (when) {this-> touches (touches, pEvent, CCTOUCHBEGAN);} void vertex: touchesMoved (CCSet * touches, CCEvent * pEvent) {if (m_bDispatchEvents) {this -> Touches (touches, pEvent, CCTOUCHMOVED) ;}} void endpoints: touchesEnded (CCSet * touches, CCEvent * pEvent) {if (parameters) {this-> touches (touches, pEvent, CCTOUCHENDED) ;}} void CCTouchDispatcher: touchesCancelled (CCSet * touches, CCEvent * pEvent) {if (vertex) {this-> touches (touches, pEvent, CCTOUCHCANCELLED) ;}}/// dispatch events distribution of touch events /// CCSet * pTouches all touch point information // * pE Vent NULL // uIndex touch type: CCTOUCHBEGAN, CCTOUCHCANCELLED .... void CCTouchDispatcher: touches (CCSet * pTouches, CCEvent * pEvent, unsigned int uIndex) {CCAssert (uIndex> = 0 & uIndex <4, ""); CCSet * pMutableTouches; m_bLocked = true; // optimization to prevent a mutable copy when it is not necessary // determine whether to copy unsigned int uTargetedHandlersCount = m_pTargetedHandlers-> count (); unsigned int uStandardHa NdlersCount = m_pStandardHandlers-> count (); bool bNeedsMutableSet = (uTargetedHandlersCount & uStandardHandlersCount); pMutableTouches = (bNeedsMutableSet? PTouches-> mutableCopy (): pTouches); struct ccTouchHandlerHelperData sHelper = m_sHandlerHelperData [uIndex]; /// process the target handlers 1st // process the target touch event first if (uTargetedHandlersCount> 0) {CCTouch * pTouch; CCSetIterator setIter; // because the touch behavior of a few fingers may be sent at the same time, I have analyzed CCTOUCHBEGAN and CCTOUCHENDED. Each time, only one or more fingers can be passed and cannot be pressed at the same time, there are always orders for (setIter = pTouches-> begin (); setIter! = PTouches-> end (); ++ setIter) {pTouch = (CCTouch *) (* setIter); CCTargetedTouchHandler * pHandler = NULL; CCObject * pObj = NULL; // traverse all TargetedHandler CCARRAY_FOREACH (m_pTargetedHandlers, pObj) {pHandler = (CCTargetedTouchHandler *) (pObj); if (! PHandler) {break;} // any touch event starts with CCTOUCHBEGAN. It makes no sense to move or end after the event, are you interested in touch events? That is, return true when the ccTouchBegan event is processed, indicating that the // control is interested in this event, claimed (claim, claim meaning). If you are not interested in begin, then move and end will not be sent to you. Bool bClaimed = false; if (uIndex = CCTOUCHBEGAN) {bClaimed = pHandler-> getDelegate ()-> ccTouchBegan (pTouch, pEvent); if (bClaimed) {pHandler-> getClaimedTouches ()-> addObject (pTouch);} else if (pHandler-> getClaimedTouches ()-> containsObject (pTouch )) {// moved ended canceled bClaimed = true; switch (sHelper. m_type) {case CCTOUCHMOVED: pHandler-> getDelegate ()-> ccTouchMoved (pTouch, pEvent); brea K; case CCTOUCHENDED: pHandler-> getDelegate ()-> ccTouchEnded (pTouch, pEvent); pHandler-> getClaimedTouches ()-> removeObject (pTouch); break; case CCTOUCHCANCELLED: pHandler-> getDelegate ()-> ccTouchCancelled (pTouch, pEvent); pHandler-> getClaimedTouches ()-> removeObject (pTouch); break ;}} // m_pTargetedHandlers linked list has a high to low priority and is swallowed up. // if a high-priority control processes the CCTOUCHBEGAN event with one click, // If Swallow is set for this control, the lower-priority control cannot handle the touch at this time. And the touch event will be removed from the pMutableTouches multi-point touch. If (bClaimed & pHandler-> isSwallowsTouches () {if (bNeedsMutableSet) {pMutableTouches-> removeObject (pTouch) ;} break ;}}}} //// process standard handlers 2nd // standard touch events also have a priority, but are not swallowed up. // All instances can receive if (uStandardHandlersCount> 0 & pMutableTouches-> count ()> 0) {CCStandardTouchHandler * pHandler = NULL; CCObject * pObj = NULL; CCARRAY_FOREACH (forward, pObj) {pHandler = (CCStandardTouchHandler *) (pObj); if (! PHandler) {break;} switch (sHelper. m_type) {case CCTOUCHBEGAN: pHandler-> getDelegate ()-> aggregate (pMutableTouches, pEvent); break; case CCTOUCHMOVED: pHandler-> getDelegate ()-> aggregate (pMutableTouches, pEvent); break; case CCTOUCHENDED: pHandler-> getDelegate ()-> decrypt (signature, pEvent); break; case when: pHandler-> getDelegate ()-> ccTouchesCancelled (pMutableTo Uches, pEvent); break ;}} if (bNeedsMutableSet) {pMutableTouches-> release () ;}/// Optimization. to prevent a [handlers copy] which is expensive // the add/removes/quit is done after the iterations // for those that were not removed because of m_bLocked at the time, added to the event processing linked list. // M_bLocked = false; if (m_bToRemove) {m_bToRemove = false; for (unsigned int I = 0; I <m_pHandlersToRemove-> num; ++ I) {trim (CCTouchDelegate *) m_pHandlersToRemove-> arr [I]);} trim (m_pHandlersToRemove);} if (m_bToAdd) {m_bToAdd = false; CCTouchHandler * pHandler = NULL; CCObject * pObj = NULL; CCARRAY_FOREACH (m_pHandlersToAdd, pObj) {pHandler = (CCTouchHandler *) PObj; if (! PHandler) {break;} if (dynamic_cast
 
  
(PHandler )! = NULL) {response (pHandler, callback) ;}else {forceAddHandler (pHandler, callback) ;}m_phandlerstoadd-> removeAllObjects () ;}if (m_bToQuit) {m_bToQuit = false; forceRemoveAllDelegates ();}}
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.