Exemplo n.º 1
0
            internal void UpdateState()
            {
                VirtualMouse.GetState();
                states       = new Dictionary <ActionKeys, bool>();
                shiftstates  = new Dictionary <ShiftKeys, bool>();
                currentState = InputState.GetState();

                foreach (ActionKeys actionKey in Helpers.EnumExtensions.GetValues <ActionKeys>())
                {
                    states.Add(actionKey, currentState.CheckPressed(actionKey));
                }


                foreach (ShiftKeys actionKey in SingularShiftKeys)
                {
                    shiftstates.Add(actionKey, currentState.CheckShiftPressed(actionKey));
                }


                TouchCollection touchCollection = TouchPanel.GetState();

                if (touchCollection.Count == 1)
                {
                    CurrentTouchLocation = touchCollection[0];
                    switch (touchCollection[0].State)
                    {
                    case TouchLocationState.Moved:
                    {
                        var xp = touchCollection[0].Position;
                        if (xp.X > 0 && xp.Y > 0)
                        {
                            MousePosition = xp;
                        }
                        break;
                    }

                    case TouchLocationState.Pressed:
                    {
                        var xp = touchCollection[0].Position;
                        if (xp.X > 0 && xp.Y > 0)
                        {
                            MousePosition = xp;
                        }

                        break;
                    }
                    }
                }

                if (touchCollection.Count > 2)
                {
                    Vector2 p1 = touchCollection[0].Position;
                    Vector2 p2 = touchCollection[1].Position;

                    Vector2 p3 = Vector2.Lerp(p1, p2, 0.5f);
                    MousePosition = p3;
                    IsTwoFinger   = true;
                }
                else
                {
                    IsTwoFinger = false;
                }

                if (touchCollection.Count == 0)
                {
                    CurrentTouchLocation = null;
                    var xp = currentState.mouseState.Position.ToVector2();

                    if (xp.X > 0 && xp.Y > 0)
                    {
                        MousePosition = xp;
                    }
                }

                if (Math.Abs(MousePosition.X - LastGoodXmouse) > 10 || Math.Abs(MousePosition.Y - LastGoodYmouse) > 10)
                {
                    LastGoodXmouse = (int)MousePosition.X;
                    LastGoodYmouse = (int)MousePosition.Y;
                    mouseActive    = true;
                }

                ScrollPos   = currentState.ScrollPos;
                PressedKeys = currentState.PressedKeys;
            }