Ejemplo n.º 1
0
        public void touches(List <CCTouch> pTouches, CCEvent pEvent, int uIndex)
        {
            List <CCTouch> pMutableTouches;

            m_bLocked = true;

            // optimization to prevent a mutable copy when it is not necessary
            int  uTargetedHandlersCount = m_pTargetedHandlers.Count;
            int  uStandardHandlersCount = m_pStandardHandlers.Count;
            bool bNeedsMutableSet       = (uTargetedHandlersCount > 0 && uStandardHandlersCount > 0);

            if (bNeedsMutableSet)
            {
                CCTouch[] tempArray = pTouches.ToArray();
                pMutableTouches = tempArray.ToList();
            }
            else
            {
                pMutableTouches = pTouches;
            }

            CCTouchType sHelper = (CCTouchType)uIndex;

            // process the target handlers 1st
            if (uTargetedHandlersCount > 0)
            {
                #region CCTargetedTouchHandler

                foreach (CCTouch pTouch in pTouches)
                {
                    foreach (CCTargetedTouchHandler pHandler in m_pTargetedHandlers)
                    {
                        ICCTargetedTouchDelegate pDelegate = (ICCTargetedTouchDelegate)(pHandler.Delegate);

                        bool bClaimed = false;
                        if (sHelper == CCTouchType.CCTOUCHBEGAN)
                        {
                            bClaimed = pDelegate.ccTouchBegan(pTouch, pEvent);

                            if (bClaimed)
                            {
                                pHandler.ClaimedTouches.Add(pTouch);
                            }
                        }
                        else
                        {
                            if (pHandler.ClaimedTouches.Contains(pTouch))
                            {
                                // moved ended cancelled
                                bClaimed = true;

                                switch (sHelper)
                                {
                                case CCTouchType.CCTOUCHMOVED:
                                    pDelegate.ccTouchMoved(pTouch, pEvent);
                                    break;

                                case CCTouchType.CCTOUCHENDED:
                                    pDelegate.ccTouchEnded(pTouch, pEvent);
                                    pHandler.ClaimedTouches.Remove(pTouch);
                                    break;

                                case CCTouchType.CCTOUCHCANCELLED:
                                    pDelegate.ccTouchCancelled(pTouch, pEvent);
                                    pHandler.ClaimedTouches.Remove(pTouch);
                                    break;
                                }
                            }
                        }

                        if (bClaimed && pHandler.IsSwallowsTouches)
                        {
                            if (bNeedsMutableSet)
                            {
                                pMutableTouches.Remove(pTouch);
                            }

                            break;
                        }
                    }
                }

                #endregion
            }

            // process standard handlers 2nd
            if (uStandardHandlersCount > 0 && pMutableTouches.Count > 0)
            {
                #region CCStandardTouchHandler
                foreach (CCStandardTouchHandler pHandler in m_pStandardHandlers)
                {
                    ICCStandardTouchDelegate pDelegate = (ICCStandardTouchDelegate)pHandler.Delegate;
                    switch (sHelper)
                    {
                    case CCTouchType.CCTOUCHBEGAN:
                        pDelegate.ccTouchesBegan(pMutableTouches, pEvent);
                        break;

                    case CCTouchType.CCTOUCHMOVED:
                        pDelegate.ccTouchesMoved(pMutableTouches, pEvent);
                        break;

                    case CCTouchType.CCTOUCHENDED:
                        pDelegate.ccTouchesEnded(pMutableTouches, pEvent);
                        break;

                    case CCTouchType.CCTOUCHCANCELLED:
                        pDelegate.ccTouchesCancelled(pMutableTouches, pEvent);
                        break;
                    }
                }
                #endregion
            }

            if (bNeedsMutableSet)
            {
                pMutableTouches = null;
            }

            //
            // Optimization. To prevent a [handlers copy] which is expensive
            // the add/removes/quit is done after the iterations
            //
            m_bLocked = false;
            if (m_bToRemove)
            {
                m_bToRemove = false;
                for (int i = 0; i < m_pHandlersToRemove.Count; ++i)
                {
                    forceRemoveDelegate((ICCTouchDelegate)m_pHandlersToRemove[i]);
                }
                m_pHandlersToRemove.Clear();
            }

            if (m_bToAdd)
            {
                m_bToAdd = false;
                foreach (CCTouchHandler pHandler in m_pHandlersToAdd)
                {
                    if (pHandler is CCTargetedTouchHandler && pHandler.Delegate is ICCTargetedTouchDelegate)
                    {
                        forceAddHandler(pHandler, m_pTargetedHandlers);
                    }
                    else if (pHandler is CCStandardTouchHandler && pHandler.Delegate is ICCStandardTouchDelegate)
                    {
                        forceAddHandler(pHandler, m_pStandardHandlers);
                    }
                    else
                    {
                        CCLog.Log("ERROR: inconsistent touch handler and delegate found in m_pHandlersToAdd of CCTouchDispatcher");
                    }
                }

                m_pHandlersToAdd.Clear();
            }

            if (m_bToQuit)
            {
                m_bToQuit = false;
                forceRemoveAllDelegates();
            }
        }
Ejemplo n.º 2
0
        public void touches(List <CCTouch> pTouches, CCEvent pEvent, int uIndex)
        {
            List <CCTouch> cCTouches;

            this.m_bLocked = true;
            int  count = this.m_pTargetedHandlers.Count;
            int  num   = this.m_pStandardHandlers.Count;
            bool flag  = (count <= 0 ? false : num > 0);

            cCTouches = (!flag ? pTouches : pTouches.ToArray().ToList <CCTouch>());
            CCTouchType cCTouchType = (CCTouchType)uIndex;

            if (count > 0)
            {
                foreach (CCTouch pTouch in pTouches)
                {
                    foreach (CCTargetedTouchHandler mPTargetedHandler in this.m_pTargetedHandlers)
                    {
                        ICCTargetedTouchDelegate @delegate = (ICCTargetedTouchDelegate)mPTargetedHandler.Delegate;
                        bool flag1 = false;
                        if (cCTouchType == CCTouchType.CCTOUCHBEGAN)
                        {
                            flag1 = @delegate.ccTouchBegan(pTouch, pEvent);
                            if (flag1)
                            {
                                mPTargetedHandler.ClaimedTouches.Add(pTouch);
                            }
                        }
                        else if (mPTargetedHandler.ClaimedTouches.Contains(pTouch))
                        {
                            flag1 = true;
                            switch (cCTouchType)
                            {
                            case CCTouchType.CCTOUCHMOVED:
                            {
                                @delegate.ccTouchMoved(pTouch, pEvent);
                                break;
                            }

                            case CCTouchType.CCTOUCHENDED:
                            {
                                @delegate.ccTouchEnded(pTouch, pEvent);
                                mPTargetedHandler.ClaimedTouches.Remove(pTouch);
                                break;
                            }

                            case CCTouchType.CCTOUCHCANCELLED:
                            {
                                @delegate.ccTouchCancelled(pTouch, pEvent);
                                mPTargetedHandler.ClaimedTouches.Remove(pTouch);
                                break;
                            }
                            }
                        }
                        if (!flag1 || !mPTargetedHandler.IsSwallowsTouches)
                        {
                            continue;
                        }
                        if (!flag)
                        {
                            break;
                        }
                        cCTouches.Remove(pTouch);
                        break;
                    }
                }
            }
            if (num > 0 && cCTouches.Count > 0)
            {
                foreach (CCStandardTouchHandler mPStandardHandler in this.m_pStandardHandlers)
                {
                    ICCStandardTouchDelegate cCStandardTouchDelegate = (ICCStandardTouchDelegate)mPStandardHandler.Delegate;
                    switch (cCTouchType)
                    {
                    case CCTouchType.CCTOUCHBEGAN:
                    {
                        cCStandardTouchDelegate.ccTouchesBegan(cCTouches, pEvent);
                        continue;
                    }

                    case CCTouchType.CCTOUCHMOVED:
                    {
                        cCStandardTouchDelegate.ccTouchesMoved(cCTouches, pEvent);
                        continue;
                    }

                    case CCTouchType.CCTOUCHENDED:
                    {
                        cCStandardTouchDelegate.ccTouchesEnded(cCTouches, pEvent);
                        continue;
                    }

                    case CCTouchType.CCTOUCHCANCELLED:
                    {
                        cCStandardTouchDelegate.ccTouchesCancelled(cCTouches, pEvent);
                        continue;
                    }

                    default:
                    {
                        continue;
                    }
                    }
                }
            }
            if (flag)
            {
                cCTouches = null;
            }
            this.m_bLocked = false;
            if (this.m_bToRemove)
            {
                this.m_bToRemove = false;
                for (int i = 0; i < this.m_pHandlersToRemove.Count; i++)
                {
                    this.forceRemoveDelegate((ICCTouchDelegate)this.m_pHandlersToRemove[i]);
                }
                this.m_pHandlersToRemove.Clear();
            }
            if (this.m_bToAdd)
            {
                this.m_bToAdd = false;
                foreach (CCTouchHandler mPHandlersToAdd in this.m_pHandlersToAdd)
                {
                    if (mPHandlersToAdd is CCTargetedTouchHandler && mPHandlersToAdd.Delegate is ICCTargetedTouchDelegate)
                    {
                        this.forceAddHandler(mPHandlersToAdd, this.m_pTargetedHandlers);
                    }
                    else if (!(mPHandlersToAdd is CCStandardTouchHandler) || !(mPHandlersToAdd.Delegate is ICCStandardTouchDelegate))
                    {
                        CCLog.Log("ERROR: inconsistent touch handler and delegate found in m_pHandlersToAdd of CCTouchDispatcher");
                    }
                    else
                    {
                        this.forceAddHandler(mPHandlersToAdd, this.m_pStandardHandlers);
                    }
                }
                this.m_pHandlersToAdd.Clear();
            }
            if (this.m_bToQuit)
            {
                this.m_bToQuit = false;
                this.forceRemoveAllDelegates();
            }
        }