Exemple #1
0
        // CheckJumpCursor() returns TRUE, ONLY if the cursor is "stuck". By "stuck" we
        // specifically mean that the user is trying to move the mouse beyond the boundaries of
        // the screen currently containing the cursor. This is determined when the *current*
        // cursor position does not equal the *previous* mouse position. If there is another
        // adjacent screen (or a "wrap around" screen), then we can consider moving the mouse
        // onto that screen.
        //
        // Note that this is ENTIRELY a *GEOMETRIC* method. Screens are "rectangles", and the
        // cursor and mouse are "points." The mouse/cursor hardware interaction (obtaining
        // current mouse and cursor information) is handled in routines further below, and any
        // Screen changes are handled by the DisplaySettingsChanged event. There are no
        // hardware or OS/Win32 references or interactions here.
        bool CheckJumpCursor(Point mouse, Point cursor, out Point NewCursor)
        {
            NewCursor = cursor; // Default is to not move cursor.

            // Gather pertinent information about cursor, mouse, screens.
            Point      Dir            = Direction(cursor, mouse);
            SnagScreen cursorScreen   = SnagScreen.WhichScreen(cursor);
            SnagScreen mouseScreen    = SnagScreen.WhichScreen(mouse);
            bool       IsStuck        = (cursor != LastMouse) && (mouseScreen != cursorScreen);
            Point      StuckDirection = OutsideDirection(cursorScreen.R, mouse);

            string StuckString = IsStuck ? "--STUCK--" : "         ";

            //        Console.Write ($" FarOut{StuckDirection}/{OutsideDis//tance(cursorScreen.R, mouse)} " +
            //            $"mouse:{mouse}  cursor:{cursor} (OnMon#{cursorScreen}/{mouseScreen}) last:{LastMouse}  " +
            //            $"#UnSnags {NJumps}   {StuckString}        \r");

            Console.Write($" StuckDirection/Distance{StuckDirection}/{OutsideDistance(cursorScreen.R, mouse)} " +
                          $"cur_mouse:{mouse}  prev_mouse:{LastMouse} ==? cursor:{cursor} (OnMon#{cursorScreen}/{mouseScreen})  " +
                          $"#UnSnags {NJumps}   {StuckString}   \r");

            LastMouse = mouse;

            // Let caller know we did NOT jump the cursor.
            if (!IsStuck)
            {
                return(false);
            }

            SnagScreen jumpScreen = SnagScreen.ScreenInDirection(StuckDirection, cursorScreen.R);

            // If the mouse "location" (which can take on a value beyond the current
            // cursor screen) has a value, then it is "within" another valid screen
            // bounds, so just jump to it!
            if (EnableWrap && mouseScreen != null)
            {
                NewCursor = mouse;
            }
            else if (jumpScreen != null)
            {
                NewCursor = jumpScreen.R.ClosestBoundaryPoint(cursor);
            }
            else if (EnableWrap && StuckDirection.X != 0)
            {
                NewCursor = SnagScreen.WrapPoint(StuckDirection, cursor);
            }
            else
            {
                return(false);
            }

            ++NJumps;
            Console.Write($"\n -- JUMPED!!! --\n");
            return(true);
        }
Exemple #2
0
        // CheckJumpCursor() returns TRUE, ONLY if the cursor is "stuck". By "stuck" we
        // specifically mean that the user is trying to move the mouse beyond the boundaries of
        // the screen currently containing the cursor. This is determined when the *current*
        // cursor position does not equal the *previous* mouse position. If there is another
        // adjacent screen (or a "wrap around" screen), then we can consider moving the mouse
        // onto that screen.
        //
        // Note that this is ENTIRELY a *GEOMETRIC* method. Screens are "rectangles", and the
        // cursor and mouse are "points." The mouse/cursor hardware interaction (obtaining
        // current mouse and cursor information) is handled in routines further below, and any
        // Screen changes are handled by the DisplaySettingsChanged event. There are no
        // hardware or OS/Win32 references or interactions here.
        bool CheckJumpCursor(Point mouse, Point cursor, out Point NewCursor)
        {
            NewCursor = cursor; // Default is to not move cursor.

            // Gather pertinent information about cursor, mouse, screens.
            SnagScreen cursorScreen = SnagScreen.WhichScreen(cursor);
            SnagScreen mouseScreen  = SnagScreen.WhichScreen(mouse);

            // If the screen hasn't changed then we don't need to do anything
            if (mouseScreen == cursorScreen)
            {
                return(false);
            }

            // If the mouse "location" (which can take on a value beyond the current
            // cursor screen) has a value, then it is "within" another valid screen
            // bounds, so just jump to it!
            Point StuckDirection = Point.Empty;

            if (mouseScreen == null)
            {
                mouseScreen = SnagScreen.ScreenInDirection(
                    mouse,
                    cursorScreen.R,
                    out StuckDirection
                    );
            }

            // If the screen is stuck in a direction off the screen we'll need to check the
            // config for if the user wants to wrap it in that direction
            if (
                mouseScreen == null &&
                StuckDirection.X != 0 &&
                bool.TryParse(Config.Read(Config.CONFIG_HORIZONTAL_WRAP), out bool hWrap) &&
                hWrap
                )
            {
                mouse       = SnagScreen.WrapPoint(StuckDirection, cursor);
                mouseScreen = SnagScreen.WhichScreen(NewCursor);
            }
            else if (
                mouseScreen == null &&
                StuckDirection.Y != 0 &&
                bool.TryParse(Config.Read(Config.CONFIG_VERTICAL_WRAP), out bool vWrap) &&
                vWrap
                )
            {
                mouse       = SnagScreen.WrapPoint(StuckDirection, cursor);
                mouseScreen = SnagScreen.WhichScreen(NewCursor);
            }
            else if (
                mouseScreen == null
                )
            {
                return(false);
            }

            // We'll move the curesor smoothly between screens of different resolution
            int scaledCursorX = mouse.X, scaledCursorY = mouse.Y;

            if (
                cursorScreen.ToLeft.Contains(mouseScreen) ||
                cursorScreen.ToRight.Contains(mouseScreen)
                )
            {
                scaledCursorY = (int)(((double)(cursor.Y - cursorScreen.R.Top) * mouseScreen.R.Height / cursorScreen.R.Height) + mouseScreen.R.Top);
            }

            if (
                cursorScreen.Above.Contains(mouseScreen) ||
                cursorScreen.Below.Contains(mouseScreen)
                )
            {
                scaledCursorX = (int)(((double)(cursor.X - cursorScreen.R.Left) * mouseScreen.R.Width / cursorScreen.R.Width) + mouseScreen.R.Left);
            }

            NewCursor = new Point(scaledCursorX, scaledCursorY);

            return(true);
        }