Пример #1
0
 private HIPoint ConfineMouseToWindow(IntPtr window, HIPoint client)
 {
     if ((double)client.X < 0.0)
     {
         client.X = 0.0f;
     }
     if ((double)client.X >= (double)this.Width)
     {
         client.X = (float)(this.Width - 1);
     }
     if ((double)client.Y < 0.0)
     {
         client.Y = 0.0f;
     }
     if ((double)client.Y >= (double)this.Height)
     {
         client.Y = (float)(this.Height - 1);
     }
     return(client);
 }
Пример #2
0
        // Point in client (window) coordinates
        private HIPoint ConfineMouseToWindow(IntPtr window, HIPoint client)
        {
            if (client.X < 0)
            {
                client.X = 0;
            }
            if (client.X >= Width)
            {
                client.X = Width - 1;
            }
            if (client.Y < 0)
            {
                client.Y = 0;
            }
            if (client.Y >= Height)
            {
                client.Y = Height - 1;
            }

            return(client);
        }
Пример #3
0
        protected OSStatus ProcessMouseEvent(IntPtr inCaller, IntPtr inEvent, EventInfo evt, IntPtr userData)
        {
            System.Diagnostics.Debug.Assert(evt.EventClass == EventClass.Mouse);
            MouseButton button    = MouseButton.Primary;
            HIPoint     pt        = new HIPoint();
            HIPoint     screenLoc = new HIPoint();
            OSStatus    err       = API.GetEventMouseLocation(inEvent, out screenLoc);

            if (this.windowState == WindowState.Fullscreen)
            {
                pt = screenLoc;
            }
            else
            {
                err = API.GetEventWindowMouseLocation(inEvent, out pt);
            }

            if (err != OSStatus.NoError)
            {
                // this error comes up from the application event handler.
                if (err != OSStatus.EventParameterNotFound)
                {
                    throw new MacOSException(err);
                }
            }

            Point mousePosInClient = new Point((int)pt.X, (int)pt.Y);

            if (this.windowState != WindowState.Fullscreen)
            {
                mousePosInClient.Y -= mTitlebarHeight;
            }

            // check for enter/leave events
            IntPtr thisEventWindow;

            API.GetEventWindowRef(inEvent, out thisEventWindow);
            CheckEnterLeaveEvents(thisEventWindow, mousePosInClient);
            switch (evt.MouseEventKind)
            {
            case MouseEventKind.MouseDown:
                button = API.GetEventMouseButton(inEvent);
                switch (button)
                {
                case MouseButton.Primary:
                    InputDriver.Mouse[0][OpenTK.Input.MouseButton.Left] = true;
                    break;

                case MouseButton.Secondary:
                    InputDriver.Mouse[0][OpenTK.Input.MouseButton.Right] = true;
                    break;

                case MouseButton.Tertiary:
                    InputDriver.Mouse[0][OpenTK.Input.MouseButton.Middle] = true;
                    break;
                }


                return(OSStatus.NoError);

            case MouseEventKind.MouseUp:
                button = API.GetEventMouseButton(inEvent);
                switch (button)
                {
                case MouseButton.Primary:
                    InputDriver.Mouse[0][OpenTK.Input.MouseButton.Left] = false;
                    break;

                case MouseButton.Secondary:
                    InputDriver.Mouse[0][OpenTK.Input.MouseButton.Right] = false;
                    break;

                case MouseButton.Tertiary:
                    InputDriver.Mouse[0][OpenTK.Input.MouseButton.Middle] = false;
                    break;
                }

                button = API.GetEventMouseButton(inEvent);
                return(OSStatus.NoError);

            case MouseEventKind.WheelMoved:

                int delta = API.GetEventMouseWheelDelta(inEvent) / 3;
                InputDriver.Mouse[0].Wheel += delta;
                return(OSStatus.NoError);

            case MouseEventKind.MouseMoved:
            case MouseEventKind.MouseDragged:

                //Debug.Print("Mouse Location: {0}, {1}", pt.X, pt.Y);

                if (this.windowState == WindowState.Fullscreen)
                {
                    if (mousePosInClient.X != InputDriver.Mouse[0].X ||
                        mousePosInClient.Y != InputDriver.Mouse[0].Y)
                    {
                        InputDriver.Mouse[0].Position = mousePosInClient;
                    }
                }
                else
                {
                    // ignore clicks in the title bar
                    if (pt.Y < 0)
                    {
                        return(OSStatus.EventNotHandled);
                    }
                    if (mousePosInClient.X != InputDriver.Mouse[0].X ||
                        mousePosInClient.Y != InputDriver.Mouse[0].Y)
                    {
                        InputDriver.Mouse[0].Position = mousePosInClient;
                    }
                }

                return(OSStatus.EventNotHandled);

            default:
                Debug.Print("{0}", evt);
                return(OSStatus.EventNotHandled);
            }
        }
Пример #4
0
        OSStatus ProcessMouseEvent(IntPtr inCaller, IntPtr inEvent, EventInfo evt, IntPtr userData)
        {
            MacOSMouseButton button;
            HIPoint          pt        = new HIPoint();
            HIPoint          screenLoc = new HIPoint();

            OSStatus err = API.GetEventMouseLocation(inEvent, out screenLoc);

            if (windowState == WindowState.Fullscreen)
            {
                pt = screenLoc;
            }
            else
            {
                err = API.GetEventWindowMouseLocation(inEvent, out pt);
            }

            if (err != OSStatus.NoError)
            {
                // this error comes up from the application event handler.
                if (err != OSStatus.EventParameterNotFound)
                {
                    throw new MacOSException(err);
                }
            }

            Point mousePosInClient = new Point((int)pt.X, (int)pt.Y);

            if (windowState != WindowState.Fullscreen)
            {
                mousePosInClient.Y -= mTitlebarHeight;
            }

            switch ((MouseEventKind)evt.EventKind)
            {
            case MouseEventKind.MouseDown:
                button = API.GetEventMouseButton(inEvent);

                switch (button)
                {
                case MacOSMouseButton.Primary:
                    Mouse.Set(MouseButton.Left, true); break;

                case MacOSMouseButton.Secondary:
                    Mouse.Set(MouseButton.Right, true); break;

                case MacOSMouseButton.Tertiary:
                    Mouse.Set(MouseButton.Middle, true); break;
                }
                return(OSStatus.NoError);

            case MouseEventKind.MouseUp:
                button = API.GetEventMouseButton(inEvent);

                switch (button)
                {
                case MacOSMouseButton.Primary:
                    Mouse.Set(MouseButton.Left, false); break;

                case MacOSMouseButton.Secondary:
                    Mouse.Set(MouseButton.Right, false); break;

                case MacOSMouseButton.Tertiary:
                    Mouse.Set(MouseButton.Middle, false); break;
                }
                return(OSStatus.NoError);

            case MouseEventKind.WheelMoved:
                Mouse.SetWheel(Mouse.Wheel + API.GetEventMouseWheelDelta(inEvent));
                return(OSStatus.NoError);

            case MouseEventKind.MouseMoved:
            case MouseEventKind.MouseDragged:

                //Debug.Print("Mouse Location: {0}, {1}", pt.X, pt.Y);

                if (windowState == WindowState.Fullscreen)
                {
                    if (mousePosInClient.X != Mouse.X || mousePosInClient.Y != Mouse.Y)
                    {
                        Mouse.SetPos(mousePosInClient.X, mousePosInClient.Y);
                    }
                }
                else
                {
                    // ignore clicks in the title bar
                    if (pt.Y < 0)
                    {
                        return(OSStatus.EventNotHandled);
                    }

                    if (mousePosInClient.X != Mouse.X || mousePosInClient.Y != Mouse.Y)
                    {
                        Mouse.SetPos(mousePosInClient.X, mousePosInClient.Y);
                    }
                }
                return(OSStatus.EventNotHandled);
            }
            return(OSStatus.EventNotHandled);
        }
Пример #5
0
        protected OSStatus ProcessMouseEvent(IntPtr inCaller, IntPtr inEvent, EventInfo evt, IntPtr userData)
        {
            HIPoint  pt1 = new HIPoint();
            HIPoint  pt2 = new HIPoint();
            IntPtr   windowRef;
            int      num       = (int)API.GetEventWindowRef(inEvent, out windowRef);
            OSStatus errorCode = API.GetEventMouseLocation(inEvent, out pt2);

            if (this.windowState == WindowState.Fullscreen)
            {
                pt1 = pt2;
            }
            else if (this.CursorVisible)
            {
                errorCode = API.GetEventWindowMouseLocation(inEvent, out pt1);
                pt1.Y    -= (float)this.mTitlebarHeight;
            }
            else
            {
                errorCode = API.GetEventMouseDelta(inEvent, out pt1);
                pt1.X    += this.mouse_rel_x;
                pt1.Y    += this.mouse_rel_y;
                pt1       = this.ConfineMouseToWindow(windowRef, pt1);
                this.ResetMouseToWindowCenter();
                this.mouse_rel_x = pt1.X;
                this.mouse_rel_y = pt1.Y;
            }
            if (errorCode != OSStatus.NoError && errorCode != OSStatus.EventParameterNotFound)
            {
                throw new MacOSException(errorCode);
            }
            Point pt3 = new Point((int)pt1.X, (int)pt1.Y);

            this.CheckEnterLeaveEvents(windowRef, pt3);
            switch (evt.MouseEventKind)
            {
            case MouseEventKind.MouseDown:
            case MouseEventKind.MouseUp:
                OpenTK.Platform.MacOS.Carbon.MouseButton eventMouseButton = API.GetEventMouseButton(inEvent);
                bool flag = evt.MouseEventKind == MouseEventKind.MouseDown;
                switch (eventMouseButton)
                {
                case OpenTK.Platform.MacOS.Carbon.MouseButton.Primary:
                    this.InputDriver.Mouse[0][OpenTK.Input.MouseButton.Left] = flag;
                    break;

                case OpenTK.Platform.MacOS.Carbon.MouseButton.Secondary:
                    this.InputDriver.Mouse[0][OpenTK.Input.MouseButton.Right] = flag;
                    break;

                case OpenTK.Platform.MacOS.Carbon.MouseButton.Tertiary:
                    this.InputDriver.Mouse[0][OpenTK.Input.MouseButton.Middle] = flag;
                    break;
                }
                return(OSStatus.NoError);

            case MouseEventKind.MouseMoved:
            case MouseEventKind.MouseDragged:
                if (this.windowState == WindowState.Fullscreen)
                {
                    if (pt3.X != this.InputDriver.Mouse[0].X || pt3.Y != this.InputDriver.Mouse[0].Y)
                    {
                        this.InputDriver.Mouse[0].Position = pt3;
                    }
                }
                else
                {
                    if ((double)pt1.Y < 0.0 || pt3.X == this.InputDriver.Mouse[0].X && pt3.Y == this.InputDriver.Mouse[0].Y)
                    {
                        return(OSStatus.EventNotHandled);
                    }
                    this.InputDriver.Mouse[0].Position = pt3;
                }
                return(OSStatus.EventNotHandled);

            case MouseEventKind.WheelMoved:
                this.InputDriver.Mouse[0].WheelPrecise += (float)API.GetEventMouseWheelDelta(inEvent);
                return(OSStatus.NoError);

            default:
                return(OSStatus.EventNotHandled);
            }
        }
Пример #6
0
        protected OSStatus ProcessMouseEvent(IntPtr inCaller, IntPtr inEvent, EventInfo evt, IntPtr userData)
        {
            System.Diagnostics.Debug.Assert(evt.EventClass == EventClass.Mouse);
            MouseButton button = MouseButton.Primary;
            HIPoint     pt     = new HIPoint();

            OSStatus err;

            if (this.windowState == WindowState.Fullscreen)
            {
                err = API.GetEventMouseLocation(inEvent, out pt);
            }
            else
            {
                err = API.GetEventWindowMouseLocation(inEvent, out pt);
            }

            if (err != OSStatus.NoError)
            {
                // this error comes up from the application event handler.
                if (err != OSStatus.EventParameterNotFound)
                {
                    throw new MacOSException(err);
                }
            }


            if (this.windowState == WindowState.Fullscreen)
            {
                InputDriver.Mouse[0].Position =
                    new System.Drawing.Point(
                        (int)pt.X,
                        (int)pt.Y);
            }
            else
            {
                // ignore clicks in the title bar
                if (pt.Y < mTitlebarHeight)
                {
                    return(OSStatus.EventNotHandled);
                }

                InputDriver.Mouse[0].Position =
                    new System.Drawing.Point(
                        (int)pt.X,
                        (int)(pt.Y - mTitlebarHeight));
            }

            switch (evt.MouseEventKind)
            {
            case MouseEventKind.MouseDown:
                button = API.GetEventMouseButton(inEvent);

                switch (button)
                {
                case MouseButton.Primary:
                    InputDriver.Mouse[0][OpenTK.Input.MouseButton.Left] = true;
                    break;

                case MouseButton.Secondary:
                    InputDriver.Mouse[0][OpenTK.Input.MouseButton.Right] = true;
                    break;

                case MouseButton.Tertiary:
                    InputDriver.Mouse[0][OpenTK.Input.MouseButton.Middle] = true;
                    break;
                }


                break;

            case MouseEventKind.MouseUp:
                switch (button)
                {
                case MouseButton.Primary:
                    InputDriver.Mouse[0][OpenTK.Input.MouseButton.Left] = false;
                    break;

                case MouseButton.Secondary:
                    InputDriver.Mouse[0][OpenTK.Input.MouseButton.Right] = false;
                    break;

                case MouseButton.Tertiary:
                    InputDriver.Mouse[0][OpenTK.Input.MouseButton.Middle] = false;
                    break;
                }

                button = API.GetEventMouseButton(inEvent);

                break;

            case MouseEventKind.MouseMoved:
            case MouseEventKind.MouseDragged:

                //Debug.Print("MouseMoved: {0}", InputDriver.Mouse[0].Position);

                return(OSStatus.EventNotHandled);

            default:
                Debug.Print("{0}", evt);

                return(OSStatus.EventNotHandled);
            }

            return(OSStatus.EventNotHandled);
        }
Пример #7
0
        protected OSStatus ProcessMouseEvent(IntPtr inCaller, IntPtr inEvent, EventInfo evt, IntPtr userData)
        {
            System.Diagnostics.Debug.Assert(evt.EventClass == EventClass.Mouse);
            MouseButton button    = MouseButton.Primary;
            HIPoint     pt        = new HIPoint();
            HIPoint     screenLoc = new HIPoint();

            IntPtr thisEventWindow;

            API.GetEventWindowRef(inEvent, out thisEventWindow);

            OSStatus err = API.GetEventMouseLocation(inEvent, out screenLoc);

            if (this.windowState == WindowState.Fullscreen)
            {
                pt = screenLoc;
            }
            else if (CursorVisible)
            {
                err   = API.GetEventWindowMouseLocation(inEvent, out pt);
                pt.Y -= mTitlebarHeight;
            }
            else
            {
                err   = API.GetEventMouseDelta(inEvent, out pt);
                pt.X += mouse_rel_x;
                pt.Y += mouse_rel_y;
                pt    = ConfineMouseToWindow(thisEventWindow, pt);
                ResetMouseToWindowCenter();
                mouse_rel_x = pt.X;
                mouse_rel_y = pt.Y;
            }

            if (err != OSStatus.NoError && err != OSStatus.EventParameterNotFound)
            {
                // this error comes up from the application event handler.
                throw new MacOSException(err);
            }

            Point mousePosInClient = new Point((int)pt.X, (int)pt.Y);

            CheckEnterLeaveEvents(thisEventWindow, mousePosInClient);

            switch (evt.MouseEventKind)
            {
            case MouseEventKind.MouseDown:
            case MouseEventKind.MouseUp:
                button = API.GetEventMouseButton(inEvent);
                bool pressed = evt.MouseEventKind == MouseEventKind.MouseDown;

                switch (button)
                {
                case MouseButton.Primary:
                    InputDriver.Mouse[0][OpenTK.Input.MouseButton.Left] = pressed;
                    break;

                case MouseButton.Secondary:
                    InputDriver.Mouse[0][OpenTK.Input.MouseButton.Right] = pressed;
                    break;

                case MouseButton.Tertiary:
                    InputDriver.Mouse[0][OpenTK.Input.MouseButton.Middle] = pressed;
                    break;
                }
                return(OSStatus.NoError);

            case MouseEventKind.WheelMoved:        // older, integer resolution only
            {
                // this is really an int, we use a float to avoid clipping the wheel value
                float delta = API.GetEventMouseWheelDelta(inEvent);
                InputDriver.Mouse[0].WheelPrecise += delta;
            }
                return(OSStatus.NoError);

            case MouseEventKind.WheelScroll:       // newer, more precise X and Y scroll
            {
                API.ScrollDelta delta = API.GetEventWheelScroll(inEvent);
                InputDriver.Mouse[0].WheelPrecise += delta.deltaY;
            }
                return(OSStatus.NoError);

            case MouseEventKind.MouseMoved:
            case MouseEventKind.MouseDragged:
                if (this.windowState == WindowState.Fullscreen)
                {
                    if (mousePosInClient.X != InputDriver.Mouse[0].X || mousePosInClient.Y != InputDriver.Mouse[0].Y)
                    {
                        InputDriver.Mouse[0].Position = mousePosInClient;
                    }
                }
                else
                {
                    // ignore clicks in the title bar
                    if (pt.Y < 0)
                    {
                        return(OSStatus.EventNotHandled);
                    }

                    if (mousePosInClient.X != InputDriver.Mouse[0].X || mousePosInClient.Y != InputDriver.Mouse[0].Y)
                    {
                        InputDriver.Mouse[0].Position = mousePosInClient;
                    }
                }
                return(OSStatus.EventNotHandled);

            default:
                Debug.Print("{0}", evt);
                return(OSStatus.EventNotHandled);
            }
        }
Пример #8
0
 internal static extern CGError WarpMouseCursorPosition(HIPoint newCursorPosition);
Пример #9
0
 public unsafe static extern IntPtr HIGetMousePosition(HICoordinateSpace space, IntPtr obj, ref HIPoint point);
Пример #10
0
 internal static extern int CGDisplayMoveCursorToPoint(IntPtr display, HIPoint point);