コード例 #1
0
        public static void SetPosition(double x, double y)
        {
            var pt = window.PointToScreen(new System.Drawing.Point((int)x, (int)y));

            x -= (int)x;
            y -= (int)y;
            OpenTK.Input.Mouse.SetPosition(pt.X + x, pt.Y + y);
        }
コード例 #2
0
        /// <summary>
        /// Sets mouse cursor's relative position to game-window.
        /// </summary>
        /// <param name="x">Relative horizontal position of the cursor.</param>
        /// <param name="y">Relative vertical position of the cursor.</param>
        public static void SetPosition(int x, int y)
        {
            UpdateStatePosition(x, y);

#if (WINDOWS && (OPENGL || DIRECTX)) || LINUX
            // correcting the coordinate system
            // Only way to set the mouse position !!!
            var pt = Window.PointToScreen(new System.Drawing.Point(x, y));
#elif WINDOWS
            var pt = new System.Drawing.Point(0, 0);
#endif

#if WINDOWS
            SetCursorPos(pt.X, pt.Y);
#elif LINUX
            OpenTK.Input.Mouse.SetPosition(pt.X, pt.Y);
#elif MONOMAC
            var      mousePt       = NSEvent.CurrentMouseLocation;
            NSScreen currentScreen = null;
            foreach (var screen in NSScreen.Screens)
            {
                if (screen.Frame.Contains(mousePt))
                {
                    currentScreen = screen;
                    break;
                }
            }

            var point     = new PointF(x, Window.ClientBounds.Height - y);
            var windowPt  = Window.ConvertPointToView(point, null);
            var screenPt  = Window.Window.ConvertBaseToScreen(windowPt);
            var flippedPt = new PointF(screenPt.X, currentScreen.Frame.Size.Height - screenPt.Y);
            flippedPt.Y += currentScreen.Frame.Location.Y;


            CGSetLocalEventsSuppressionInterval(0.0);
            CGWarpMouseCursorPosition(flippedPt);
            CGSetLocalEventsSuppressionInterval(0.25);
#endif
        }