Ejemplo n.º 1
0
        private void ApplyTouch(List <TouchLocation> state, TouchLocation touch)
        {
            if (touch.State == TouchLocationState.Pressed)
            {
                state.Add(touch);
                return;
            }

            // Find the matching touch
            for (int i = 0; i < state.Count; i += 1)
            {
                TouchLocation existingTouch = state[i];
                if (existingTouch.Id == touch.Id)
                {
                    /* If we are moving straight from Pressed to Released,
                     * that means we've never been seen, so just get rid of us.
                     */
                    if (existingTouch.State == TouchLocationState.Pressed &&
                        touch.State == TouchLocationState.Released)
                    {
                        state.RemoveAt(i);
                    }
                    else
                    {
                        // Otherwise, update the touch based on the new one
                        existingTouch.UpdateState(touch);
                        state[i] = existingTouch;
                    }
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        private static bool RefreshState(bool consumeState, List <TouchLocation> state, List <TouchLocation> events)
        {
            bool flag1 = false;

            for (int index1 = 0; index1 < state.Count; ++index1)
            {
                TouchLocation touchLocation = state[index1];
                if (consumeState || touchLocation.State == TouchLocationState.Moved)
                {
                    if (consumeState && touchLocation.State == TouchLocationState.Released)
                    {
                        state.RemoveAt(index1);
                        --index1;
                    }
                    else
                    {
                        bool flag2 = false;
                        for (int index2 = 0; index2 < events.Count; ++index2)
                        {
                            TouchLocation touchEvent = events[index2];
                            if ((consumeState || touchEvent.State != TouchLocationState.Released) && touchEvent.Id == touchLocation.Id)
                            {
                                flag1 = flag1 | touchLocation.UpdateState(touchEvent);
                                flag2 = true;
                                events.RemoveAt(index2);
                                break;
                            }
                        }
                        if (flag2)
                        {
                            state[index1] = touchLocation;
                        }
                        else if (consumeState)
                        {
                            state[index1] = touchLocation.AsMovedState();
                        }
                    }
                }
            }
            int index = 0;

            while (index < events.Count)
            {
                TouchLocation touchLocation = events[index];
                if (touchLocation.State == TouchLocationState.Pressed)
                {
                    state.Add(touchLocation);
                    events.RemoveAt(index);
                    flag1 = true;
                }
                else
                {
                    ++index;
                }
            }
            return(flag1);
        }
Ejemplo n.º 3
0
        internal bool Refresh(
            bool consumeState,
            List <TouchLocation> state,
            List <TouchLocation> events
            )
        {
            bool stateChanged = false;

            // Update the existing touch locations.
            for (int i = 0; i < state.Count; i += 1)
            {
                // Get the next touch location for update.
                TouchLocation touch = state[i];

                // If this location isn't in the move state yet then skip it.
                if (!consumeState && touch.State != TouchLocationState.Moved)
                {
                    continue;
                }

                /* If the touch state has been consumed then we can
                 * remove old release locations.
                 */
                if (consumeState && touch.State == TouchLocationState.Released)
                {
                    state.RemoveAt(i);
                    i -= 1;
                    continue;
                }

                bool foundEvent = false;

                /* Remove the next pending event with the
                 * same id and make it the new touch state.
                 */
                for (int j = 0; j < events.Count; j += 1)
                {
                    TouchLocation newTouch = events[j];

                    /* Don't let a release event occur until we're
                     * ready to consume state again.
                     */
                    if (!consumeState && newTouch.State == TouchLocationState.Released)
                    {
                        continue;
                    }

                    if (newTouch.Id == touch.Id)
                    {
                        stateChanged |= touch.UpdateState(newTouch);
                        foundEvent    = true;
                        events.RemoveAt(j);
                        j -= 1;

                        // Consume unchanged events.
                        if (!stateChanged)
                        {
                            continue;
                        }
                        break;
                    }
                }

                // If a new event was found then store it.
                if (foundEvent)
                {
                    state[i] = touch;
                }

                /* Else if no event has come in then promote it to
                 * the moved state, but only when we're consuming state.
                 */
                else if (consumeState)
                {
                    state[i] = touch.AsMovedState();
                }
            }

            /* We add new pressed events last so they are not
             * consumed before the touch state is returned.
             */
            for (int i = 0; i < events.Count;)
            {
                TouchLocation loc = events[i];

                if (loc.State == TouchLocationState.Pressed)
                {
                    state.Add(loc);
                    events.RemoveAt(i);
                    stateChanged = true;
                    continue;
                }

                i += 1;
            }

            return(stateChanged);
        }