void MouseReleased(object sender, PointerRoutedEventArgs args)
        {
            var pointerPoint = args.GetCurrentPoint(this);

            if (pointerPoint.PointerDevice.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Mouse)
            {
                var pos = new CCPoint((float)pointerPoint.Position.X * ScaleFactor, (float)pointerPoint.Position.Y * ScaleFactor);

                var state = pointerPoint.Properties;

                var buttonsReleased = CCMouseButton.None;
                if (buttons.HasFlag(CCMouseButton.LeftButton) && !state.IsLeftButtonPressed)
                {
                    buttonsReleased = CCMouseButton.LeftButton;
                }
                if (buttons.HasFlag(CCMouseButton.RightButton) && !state.IsRightButtonPressed)
                {
                    buttonsReleased |= CCMouseButton.RightButton;
                }
                if (buttons.HasFlag(CCMouseButton.MiddleButton) && !state.IsMiddleButtonPressed)
                {
                    buttonsReleased |= CCMouseButton.MiddleButton;
                }
                UpdateIncomingReleaseMouse((int)pointerPoint.PointerId, buttonsReleased);

                args.Handled = true;
            }
        }
Beispiel #2
0
        void UpdateMousePosition(NSEvent theEvent)
        {
            var location = ConvertPointFromView(theEvent.LocationInWindow, null);

            if (!IsFlipped)
            {
                location.Y = Frame.Size.Height - location.Y;
            }

            var position = new CCPoint((float)location.X, (float)location.Y);
            var id       = theEvent.EventNumber;

            if (TouchEnabled)
            {
                switch (touchPhase)
                {
                case NSTouchPhase.Began:
                    AddIncomingNewTouch(id, ref position);
                    break;

                case NSTouchPhase.Moved:
                    UpdateIncomingMoveTouch(id, ref position);
                    break;

                case NSTouchPhase.Ended:
                case NSTouchPhase.Cancelled:
                    UpdateIncomingReleaseTouch(id);
                    break;

                default:
                    break;
                }
            }

            if (MouseEnabled)
            {
                switch (touchPhase)
                {
                case NSTouchPhase.Began:
                    buttons  = CCMouseButton.None;
                    buttons |= IsLeftButtonPressed ? CCMouseButton.LeftButton : CCMouseButton.None;
                    buttons |= IsRightButtonPressed ? CCMouseButton.RightButton : CCMouseButton.None;
                    AddIncomingMouse(id, ref position, buttons);
                    break;

                case NSTouchPhase.Moved:
                    UpdateIncomingMouse(id, ref position, buttons);
                    break;

                case NSTouchPhase.Ended:
                case NSTouchPhase.Cancelled:
                    var buttonsReleased = CCMouseButton.None;
                    if (buttons.HasFlag(CCMouseButton.LeftButton) && !IsLeftButtonPressed)
                    {
                        buttonsReleased = CCMouseButton.LeftButton;
                    }
                    if (buttons.HasFlag(CCMouseButton.RightButton) && !IsRightButtonPressed)
                    {
                        buttonsReleased |= CCMouseButton.RightButton;
                    }
                    UpdateIncomingReleaseMouse(id, buttons);
                    break;

                default:
                    break;
                }
            }
        }