After Cceglviewprotocol's handletouchesbegin,handletouchesmove,handletouchesend,handletouchescancel treatment, will be cctouchdispatcher in the following functions, and will call touches, then we analyze touches this function void Cctouchdispatcher::touchesbegan (Ccset *touches , Ccevent *pevent) {if (m_bdispatchevents) {this->touches (touches, pevent, Cctouchbegan); }}void cctouchdispatcher::touchesmoved (Ccset *touches, ccevent *pevent) {if (m_bdispatchevents) {this->to Uches (Touches, pevent, cctouchmoved); }}void cctouchdispatcher::touchesended (Ccset *touches, ccevent *pevent) {if (m_bdispatchevents) {this->to Uches (Touches, pevent, cctouchended); }}void cctouchdispatcher::touchescancelled (Ccset *touches, ccevent *pevent) {if (m_bdispatchevents) {THIS-&G T;touches (Touches, pevent, cctouchcancelled); }}////Dispatch Events Distributing touch events////ccset *ptouches All touch point information//*pevent 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's not necessary//determine if copy unsigned int is required Utargetedhandlerscount = M_ptargetedhandlers->count (); unsigned int ustandardhandlerscount = M_pstandardhandlers->count (); BOOL Bneedsmutableset = (Utargetedhandlerscount && ustandardhandlerscount); Pmutabletouches = (bneedsmutableset? ptouches->mutablecopy (): ptouches); struct Cctouchhandlerhelperdata shelper = M_shandlerhelperdata[uindex]; Process the target handlers 1st//Handle Target Touch event first (Utargetedhandlerscount > 0) {cctouch *pto Uch Ccsetiterator setiter;//Because here may also send a few finger touch behavior, previously analyzed Cctouchbegan and cctouchended each time will only pass one//multiple fingers can not be pressed at the same time, always have 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 = (Cctar Getedtouchhandler *) (POBJ); if (! Phandler) {break; }//any touch event starts from Cctouchbegan, how does it not begin, the move,end in the back and so on is meaningless//So how do you show interest in touch events? is to return true at Cctouchbegan, that is, when the begin event is processed, then the//control is interested in this event, claimed (claim, declared meaning), if it is not interested in the begin, then the move,end in the back will//not be sent to you. BOOL bclaimed = false; if (UIndex = = Cctouchbegan) {bclaimed = Phandler->getdelegate ()->cctouchbegan (pTo Uch, 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->get Delegate ()->cctouchmoved (Ptouch, pevent); Break Case Cctouchended:phandler->getdelegate ()->cctouchended (Ptouch, pevent); Phandler->getclaimedtouches ()->removeobject (Ptouch); Break Case Cctouchcancelled:phandler->getdelegate ()->cctouchcancelled (Ptouch, pevent); Phandler->getclaimedtouches ()->removeobject (Ptouch); Break The}//m_ptargetedhandlers list is prioritized from high to low, and has phagocytosis,//That is, if a high-priority control handles a finger-click Cctouchbegan event, and,//This control is set to swallow, the lower priority -level controls cannot handle the touch event at this time//and will also remove this touch event from the Pmutabletouches multi-touch. if (bclaimed && phandler->isswallowstouches ()) {if (bneedsmutableset) {Pmutabletouches->re Moveobject (Ptouch); } break; }}}}////process standard handlers 2nd//STD Touch event, also has priority, but no engulfing ability. All can receive if (Ustandardhandlerscount > 0 && pmutabletouches->count () > 0) {Ccstandardtouch Handler *phandler = NULL; ccobject* POBJ = NULL; Ccarray_foreach (M_pstandardhandlers, pObj) {Phandler = (ccstandardtouchhandler*) (POBJ); if (! Phandler) {break; } switch (shelper.m_type) {case cctouchbegan:phandler->getdelegate ()- >cctouchesbegan (Pmutabletouches, pevent); Break Case Cctouchmoved:phandler->getdelegate ()->cctouchesmoved (pmutabletouches, pevent); Break Case Cctouchended:phandler->getdelegate ()->cctouchesended (pmutabletouches, pevent); Break Case Cctouchcancelled:phandler->getdelegate ()->cctouchescancelled (pmutabletouches, pEvent); Break }}} if (Bneedsmutableset) {pmutabletouches->release (); }////optimization. To prevent a [handlers copy] which are expensive//the add/removes/quit is doing after the iterations//For those at that time because M_blo Cked and not removed, the addition is added to the event-handling list. m_blocked = false; if (m_btoremove) {m_btoremove = false; for (unsigned int i = 0; i < m_phandlerstoremove->num; ++i) {forceremovedelegate (cctouchdelegate *) m_phandlerstoremove->arr[i]); } cccarrayremoveallvalues (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<cctargetedtouchhandler*> (phandler) = NULL) { Forceaddhandler (Phandler, m_ptargetedhandlers); } else {Forceaddhandler (Phandler, m_pstandardhandlers); }} m_phandlerstoadd->removeallobjects (); } if (m_btoquit) {m_btoquit = false; Forceremovealldelegates (); }}
COCOS2DX Click event Analysis (5)