Example #1
0
        internal TouchPanel(ScreenView screen)
        {
            this.screen = screen;

            try
            {
                this.caps = XnaTouchPanel.GetCapabilities();
            }
            catch (TypeLoadException)
            {
                this.caps = new TouchPanelCapabilities();
            }

            this.touches    = new List <Touch>(caps.MaximumTouchCount);
            this.newTouches = new List <Touch>(caps.MaximumTouchCount);
        }
Example #2
0
        public void UpdateGestures()
        {
            var samples = new List <Gesture>();

            if (XnaTouchPanel.EnabledGestures == XnaGestureType.None)
            {
                return;
            }

            while (XnaTouchPanel.IsGestureAvailable)
            {
                samples.Add(new Gesture(XnaTouchPanel.ReadGesture()));
            }

            this.GestureListeners.UpdateChanges();
            this.gestures = samples;
        }
Example #3
0
        public void UpdateTouches()
        {
            var xnaTouches = XnaTouchPanel.GetState();

            for (int i = 0; i < xnaTouches.Count; i++)
            {
                Touch prevTouch = touches.Find(s => s.Id == xnaTouches[i].Id);
                Touch thisTouch = prevTouch != null ? prevTouch : new Touch(screen, xnaTouches[i]);

                newTouches.Add(thisTouch);
                DownListeners.ForEach(dl => dl.CheckAndInvoke(thisTouch));

                if (prevTouch == null)
                {
                    // New touch
                    PressListeners.ForEach(dl => dl.CheckAndInvoke(thisTouch));
                }
                else
                {
                    // Existing touch
                    touches.Remove(thisTouch);
                    thisTouch.Update(xnaTouches[i]);
                }
            }

            for (int i = 0; i < touches.Count; i++)
            {
                // Released touch
                ReleaseListeners.ForEach(dl => dl.CheckAndInvoke(touches[i]));
            }

            DownListeners.UpdateChanges();
            PressListeners.UpdateChanges();
            ReleaseListeners.UpdateChanges();

            touches.Clear();
            var empty = touches;

            touches    = newTouches;
            newTouches = empty;
        }