Example #1
0
        void UpdateTouch()
        {
            var touch = TouchPanel.GetState().FirstOrDefault();

            if (touch != null)
            {
                switch (touch.State)
                {
                case TouchLocationState.Pressed:
                {
                    this.touchIsPressed = true;
                    if (!this.touchIsPressedEvent)
                    {
                        this.touchIsPressedEvent = true;

                        if (this.PressedTouch != null)
                        {
                            DeviceEventArgs e = new DeviceEventArgs();

                            e.X = touch.Position.X;
                            e.Y = touch.Position.Y;

                            this.touchXPressed = (int)e.X;
                            this.touchYPressed = (int)e.Y;

                            this.PressedTouch(this, e);
                        }
                    }
                    else
                    {
                        if (this.touchIsPressed)
                        {
                            if (this.ClickMoveTouch != null)
                            {
                                DeviceEventArgs e = new DeviceEventArgs();

                                e.X2 = touch.Position.X;
                                e.Y2 = touch.Position.Y;

                                if ((e.X2 != this.touchXClickMove) && (e.Y2 != this.touchYClickMove))
                                {
                                    e.X = this.touchXPressed;
                                    e.Y = this.touchYPressed;

                                    this.touchXClickMove = (int)e.X2;
                                    this.touchYClickMove = (int)e.Y2;

                                    this.ClickMoveTouch.Invoke(this, e);
                                }
                            }
                        }
                    }
                }
                break;

                case TouchLocationState.Released:
                {
                    if (this.touchIsPressed)
                    {
                        this.touchIsPressed      = false;
                        this.touchIsPressedEvent = false;

                        int x = (int)touch.Position.X;
                        int y = (int)touch.Position.Y;

                        DeviceEventArgs e = new DeviceEventArgs();
                        e.Device = TypeInputDevice.Touch;

                        int dX = Math.Abs(this.touchXPressed - x);
                        int dY = Math.Abs(this.touchYPressed - y);
                        if ((dX > Input.TouchScatter) || (dY > Input.TouchScatter))
                        {
                            if (this.Swype != null)
                            {
                                e.X  = this.touchXPressed;
                                e.Y  = this.touchYPressed;
                                e.X2 = x;
                                e.Y2 = y;

                                this.MoveTouch?.Invoke(this, e);

                                var dsX = e.X2 - e.X;
                                var dsY = e.Y2 - e.Y;

                                bool isRight      = dsX > 0;
                                bool isDown       = dsY > 0;
                                bool isHorizontal = Math.Abs(dsX) > Math.Abs(dsY);

                                e.Swype = isHorizontal ? (isRight ? TypeSwype.Right : TypeSwype.Left) : (isDown ? TypeSwype.Down : TypeSwype.Up);

                                if (dX > SwypeScatterX && dY < SwypeScatterY)
                                {
                                    this.Swype(this, e);
                                }
                            }
                        }
                        else if (this.ClickTouch != null)
                        {
                            e.X = x;
                            e.Y = y;
                            this.ClickTouch?.Invoke(this, e);
                        }
                    }
                }
                break;

                default: break;
                }
            }
        }
Example #2
0
        void UpdateMouse()
        {
            switch (Mouse.GetState().LeftButton)
            {
            case ButtonState.Pressed:
            {
                this.mouseIsPressed = true;
                if (!this.mouseIsPressedEvent)
                {
                    this.mouseIsPressedEvent = true;
                    if (this.PressedMouse != null)
                    {
                        DeviceEventArgs e = new DeviceEventArgs();
                        e.X = Mouse.GetState().X;
                        e.Y = Mouse.GetState().Y;

                        this.mouseXPressed = (int)e.X;
                        this.mouseYPressed = (int)e.Y;

                        this.PressedMouse(this, e);
                    }
                }
                else
                {
                    if (this.mouseIsPressed)
                    {
                        if (this.ClickMoveMouse != null)
                        {
                            DeviceEventArgs e = new DeviceEventArgs();
                            e.X2 = Mouse.GetState().X;
                            e.Y2 = Mouse.GetState().Y;

                            if ((e.X2 != this.mouseXClickMove) && (e.Y2 != this.mouseYClickMove))
                            {
                                e.X = this.mouseXPressed;
                                e.Y = this.mouseYPressed;

                                this.mouseXClickMove = (int)e.X2;
                                this.mouseYClickMove = (int)e.Y2;

                                this.ClickMoveMouse.Invoke(this, e);
                            }
                        }
                    }
                }
            }
            break;

            case ButtonState.Released:
            {
                if (this.mouseIsPressed)
                {
                    this.mouseIsPressed      = false;
                    this.mouseIsPressedEvent = false;

                    int x = Mouse.GetState().X;
                    int y = Mouse.GetState().Y;

                    DeviceEventArgs e = new DeviceEventArgs();
                    e.Device = TypeInputDevice.Mouse;

                    int dX = Math.Abs(this.mouseXPressed - x);
                    int dY = Math.Abs(this.mouseYPressed - y);
                    if ((dX > Input.TouchScatter) || (dY > Input.TouchScatter))
                    {
                        if (this.Swype != null)
                        {
                            e.X  = this.mouseXPressed;
                            e.Y  = this.mouseYPressed;
                            e.X2 = x;
                            e.Y2 = y;

                            if (this.MoveMouse != null)
                            {
                                this.MoveMouse(this, e);
                            }

                            var dsX = e.X2 - e.X;
                            var dsY = e.Y2 - e.Y;

                            bool isRight      = dsX > 0;
                            bool isDown       = dsY > 0;
                            bool isHorizontal = Math.Abs(dsX) > Math.Abs(dsY);

                            e.Swype = isHorizontal ? (isRight ? TypeSwype.Right : TypeSwype.Left) : (isDown ? TypeSwype.Down : TypeSwype.Up);

                            if (dX > SwypeScatterX && dY < SwypeScatterY)
                            {
                                this.Swype(this, e);
                            }
                        }
                    }
                    else if (this.ClickMouse != null)
                    {
                        e.X = x;
                        e.Y = y;
                        this.ClickMouse(this, e);
                    }
                }
            }
            break;

            default: break;
            }

            int mx = Mouse.GetState().X;
            int my = Mouse.GetState().Y;

            if ((lastX != mx) || (lastY != my))
            {
                if (this.PositionChangedMouse != null)
                {
                    lastX = mx;
                    lastY = my;
                    DeviceEventArgs e = new DeviceEventArgs();
                    e.X = lastX;
                    e.Y = lastY;

                    this.PositionChangedMouse(this, e);
                }
            }

            var scroll = Mouse.GetState().ScrollWheelValue;

            if (lastScrollMouse != scroll)
            {
                if (this.ScrollingMouse != null)
                {
                    DeviceEventArgs e = new DeviceEventArgs();
                    e.ScrollValue   = scroll - lastScrollMouse;
                    lastScrollMouse = scroll;

                    this.ScrollingMouse(this, e);
                }
            }
        }