Example #1
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;
        }
Example #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;
        }
Example #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();

            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:
                    float delta = API.GetEventMouseWheelDelta(inEvent);
                    InputDriver.Mouse[0].WheelPrecise += delta;
                    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;
            }
        }
Example #4
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 = new System.Drawing.Point(mousePosInClient.X, mousePosInClient.Y);
                        }
                    }
                    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 = new System.Drawing.Point(mousePosInClient.X, mousePosInClient.Y);
                        }
                    }

                    return OSStatus.EventNotHandled;
                default:
                    Debug.Print("{0}", evt);
                    return OSStatus.EventNotHandled;
            }
        }
Example #5
0
 public HIPoint(double x, double y)
 {
     this = new HIPoint((float)x, (float)y);
 }
Example #6
0
 public HIPoint(double x, double y)
 {
     this = new HIPoint((float) x, (float) y);
 }