void UpdateIncomingMouse(int id, ref CCPoint position, CCMouseButton buttons = CCMouseButton.None)
 {
     lock (mouseLock)
     {
         CCEventMouse existingMouse;
         if (mouseMap.TryGetValue(id, out existingMouse))
         {
             existingMouse.MouseEventType = CCMouseEventType.MOUSE_MOVE;
             existingMouse.MouseButton    = buttons;
             existingMouse.CursorOnScreen = position;
             incomingMoveMouse.Add(existingMouse);
         }
     }
 }
 void AddIncomingMouse(int id, ref CCPoint position, CCMouseButton buttons = CCMouseButton.None)
 {
     lock (mouseLock)
     {
         if (!mouseMap.ContainsKey(id))
         {
             var mouse = new CCEventMouse(((buttons == CCMouseButton.None) ? CCMouseEventType.MOUSE_MOVE : CCMouseEventType.MOUSE_DOWN),
                                          id, position, gameTime.ElapsedGameTime);
             mouse.MouseButton = buttons;
             incomingNewMouse.Add(mouse);
             mouseMap.Add(id, mouse);
         }
     }
 }
        void UpdateIncomingReleaseMouse(int id, CCMouseButton buttons = CCMouseButton.None)
        {
            lock (mouseLock)
            {
                CCEventMouse existingMouse;
                if (mouseMap.TryGetValue(id, out existingMouse))
                {
                    existingMouse.MouseEventType = CCMouseEventType.MOUSE_UP;
                    existingMouse.MouseButton    = buttons;

                    incomingReleaseMouse.Add(existingMouse);
                    mouseMap.Remove(id);
                }
            }
        }
        void MousePressed(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;

                buttons  = CCMouseButton.None;
                buttons |= state.IsLeftButtonPressed ? CCMouseButton.LeftButton : CCMouseButton.None;
                buttons |= state.IsRightButtonPressed ? CCMouseButton.RightButton : CCMouseButton.None;
                buttons |= state.IsMiddleButtonPressed ? CCMouseButton.MiddleButton : CCMouseButton.None;

                AddIncomingMouse((int)pointerPoint.PointerId, ref pos, buttons);
                args.Handled = true;
            }
        }
        void MouseMoved(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;

                if (mouseMap.ContainsKey((int)pointerPoint.PointerId))
                {
                    UpdateIncomingMouse((int)pointerPoint.PointerId, ref pos, buttons);
                }
                else
                {
                    buttons = CCMouseButton.None;
                    AddIncomingMouse((int)pointerPoint.PointerId, ref pos);
                }

                args.Handled = true;
            }
        }
示例#6
0
 public bool IsMousePressed(CCMouseButton mouse)
 {
     return(m_inputsMouse.Contains(mouse));
 }
示例#7
0
 public void OnMouseRelease(CCMouseButton mouse)
 {
     m_inputsMouse.Remove(mouse);
 }
示例#8
0
 public void OnMousePress(CCMouseButton mouse)
 {
     m_inputsMouse.Add(mouse);
 }
示例#9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="button"></param>
 /// <returns></returns>
 public bool IsMouseDown(CCMouseButton button) => InputHelper.Instance.IsMousePressed(button);
示例#10
0
 public static bool IsMousePressed(CCMouseButton mouse) {
     return InputsMouse.Contains(mouse);
 }
示例#11
0
 public static void OnMouseRelease(CCMouseButton mouse) {
     InputsMouse.Remove(mouse);
 }
示例#12
0
 public static void OnMousePress(CCMouseButton mouse) {
     InputsMouse.Add(mouse);
 }
示例#13
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;
                }
            }
        }
示例#14
0
        void ProcessMouse(CCWindow window)
        {
            // Read the current Mouse state
            MouseState currentMouseState = Mouse.GetState();

            var dispatcher = window.EventDispatcher;

            if (currentMouseState == priorMouseState || !dispatcher.IsEventListenersFor(CCEventListenerMouse.LISTENER_ID))
            {
                priorMouseState = currentMouseState;
                return;
            }

            CCPoint pos;

#if NETFX_CORE
            //Because MonoGame and CocosSharp uses different Y axis, we need to convert the coordinate here
            pos = TransformPoint(priorMouseState.X, Game.Window.ClientBounds.Height - priorMouseState.Y);
#else
            //Because MonoGame and CocosSharp uses different Y axis, we need to convert the coordinate here
            pos = new CCPoint(priorMouseState.X, Game.Window.ClientBounds.Height - priorMouseState.Y);
#endif


            var mouseEvent = new CCEventMouse(CCMouseEventType.MOUSE_MOVE);
            mouseEvent.CursorX = pos.X;
            mouseEvent.CursorY = pos.Y;

            dispatcher.DispatchEvent(mouseEvent);

            CCMouseButton mouseButton = CCMouseButton.None;
            if (priorMouseState.LeftButton == ButtonState.Released && currentMouseState.LeftButton == ButtonState.Pressed)
            {
                mouseButton |= CCMouseButton.LeftButton;
            }
            if (priorMouseState.RightButton == ButtonState.Released && currentMouseState.RightButton == ButtonState.Pressed)
            {
                mouseButton |= CCMouseButton.RightButton;
            }
            if (priorMouseState.MiddleButton == ButtonState.Released && currentMouseState.MiddleButton == ButtonState.Pressed)
            {
                mouseButton |= CCMouseButton.MiddleButton;
            }
            if (priorMouseState.XButton1 == ButtonState.Released && currentMouseState.XButton1 == ButtonState.Pressed)
            {
                mouseButton |= CCMouseButton.ExtraButton1;
            }
            if (priorMouseState.XButton2 == ButtonState.Released && currentMouseState.XButton2 == ButtonState.Pressed)
            {
                mouseButton |= CCMouseButton.ExtraButton1;
            }

            if (mouseButton > 0)
            {
                mouseEvent.MouseEventType = CCMouseEventType.MOUSE_DOWN;
                mouseEvent.MouseButton    = mouseButton;
                dispatcher.DispatchEvent(mouseEvent);
            }

            mouseButton = CCMouseButton.None;
            if (priorMouseState.LeftButton == ButtonState.Pressed && currentMouseState.LeftButton == ButtonState.Released)
            {
                mouseButton |= CCMouseButton.LeftButton;
            }
            if (priorMouseState.RightButton == ButtonState.Pressed && currentMouseState.RightButton == ButtonState.Released)
            {
                mouseButton |= CCMouseButton.RightButton;
            }
            if (priorMouseState.MiddleButton == ButtonState.Pressed && currentMouseState.MiddleButton == ButtonState.Released)
            {
                mouseButton |= CCMouseButton.MiddleButton;
            }
            if (priorMouseState.XButton1 == ButtonState.Pressed && currentMouseState.XButton1 == ButtonState.Released)
            {
                mouseButton |= CCMouseButton.ExtraButton1;
            }
            if (priorMouseState.XButton2 == ButtonState.Pressed && currentMouseState.XButton2 == ButtonState.Released)
            {
                mouseButton |= CCMouseButton.ExtraButton1;
            }
            if (mouseButton > 0)
            {
                mouseEvent.MouseEventType = CCMouseEventType.MOUSE_UP;
                mouseEvent.MouseButton    = mouseButton;
                dispatcher.DispatchEvent(mouseEvent);
            }

            if (priorMouseState.ScrollWheelValue != currentMouseState.ScrollWheelValue)
            {
                var delta = priorMouseState.ScrollWheelValue - currentMouseState.ScrollWheelValue;
                if (delta != 0)
                {
                    mouseEvent.MouseEventType = CCMouseEventType.MOUSE_SCROLL;
                    mouseEvent.ScrollX        = 0;
                    mouseEvent.ScrollY        = delta;
                    dispatcher.DispatchEvent(mouseEvent);
                    //Console.WriteLine ("mouse scroll: " + mouseEvent.ScrollY);
                }
            }
            // Store the state for the next loop
            priorMouseState = currentMouseState;
        }