/// <summary>
        /// Converts relative coordinates in the window to new absolute coordinates
        /// based on the specified reference size.
        /// Note: TT Rewritten scales its window contents accounting for the aspect ratio
        /// (at least if the width is greater than from the 4:3 resolution). Therefore
        /// we use the given VerticalScaleAlignment to correctly calculate the
        /// X coordinate (note that we require the aspect ratio to be ≥ 4:3).
        /// </summary>
        /// <param name="pos"></param>
        /// <param name="coords">The coordinates to scale.</param>
        /// <param name="referenceSize">The size which was used to create the coordinates.
        /// This size is interpreted as being a scaled 4:3 window without retaining
        /// aspect ratio.</param>
        /// <param name="valign"></param>
        /// <returns></returns>
        public static Coordinates ScaleCoordinates(
            this WindowPosition pos,
            Coordinates coords,
            Size referenceSize,
            VerticalScaleAlignment valign = VerticalScaleAlignment.Center)
        {
            double aspectWidth     = pos.Size.Height / 3d * 4d;
            double widthDifference = pos.Size.Width - aspectWidth;

            int newX;

            if (valign == VerticalScaleAlignment.NoAspectRatio)
            {
                newX = (int)Math.Round((double)coords.X / referenceSize.Width * pos.Size.Width);
            }
            else
            {
                newX = (int)Math.Round((double)coords.X / referenceSize.Width * aspectWidth
                                       + (valign == VerticalScaleAlignment.Left ? 0 :
                                          valign == VerticalScaleAlignment.Center ? widthDifference / 2 : widthDifference));
            }

            return(new Coordinates()
            {
                X = newX,
                Y = (int)Math.Round((double)coords.Y / referenceSize.Height * pos.Size.Height)
            });
        }
예제 #2
0
        public static async Task DoSimpleMouseClickAsync(IInteractionProvider provider,
            Coordinates coords, VerticalScaleAlignment valign = VerticalScaleAlignment.Center,
            int buttonDownTimeout = 200)
        {
            var pos = provider.GetCurrentWindowPosition();
            coords = pos.RelativeToAbsoluteCoordinates(pos.ScaleCoordinates(coords,
                ReferenceWindowSize, valign));

            provider.MoveMouse(coords);
            provider.PressMouseButton();
            await provider.WaitAsync(buttonDownTimeout);
            provider.ReleaseMouseButton();
        }
예제 #3
0
        public static async Task DoSimpleMouseClickAsync(IInteractionProvider provider,
                                                         Coordinates coords, VerticalScaleAlignment valign = VerticalScaleAlignment.Center,
                                                         int buttonDownTimeout = 150)
        {
            var pos = provider.GetCurrentWindowPosition();

            coords = pos.ScaleCoordinates(coords,
                                          ReferenceWindowSize, valign);

            provider.MoveMouse(coords);
            provider.PressMouseButton();
            await provider.WaitAsync(buttonDownTimeout);

            provider.ReleaseMouseButton();
        }
        /// <summary>
        /// Converts relative coordinates in the window to new absolute coordinates
        /// based on the specified reference size.
        /// Note: TT Rewritten scales its window contents accounting for the aspect ratio
        /// (at least if the width is greater than from the 4:3 resolution). Therefore
        /// we use the given VerticalScaleAlignment to correctly calculate the
        /// X coordinate (note that we require the aspect ratio to be ≥ 4:3).
        /// </summary>
        /// <param name="pos"></param>
        /// <param name="coords">The coordinates to scale.</param>
        /// <param name="referenceSize">The size which was used to create the coordinates.
        /// This size is interpreted as being a scaled 4:3 window without retaining
        /// aspect ratio.</param>
        /// <param name="valign"></param>
        /// <returns></returns>
        public static Coordinates ScaleCoordinates(this WindowPosition pos, Coordinates coords, 
            Size referenceSize, VerticalScaleAlignment valign = VerticalScaleAlignment.Center)
        {
            double aspectWidth = pos.Size.Height / 3d * 4d;
            double widthDifference = pos.Size.Width - aspectWidth;

            int newX;
            if (valign == VerticalScaleAlignment.NoAspectRatio)
            {
                newX = (int)Math.Round((double)coords.X / referenceSize.Width * pos.Size.Width);
            }
            else
            {
                newX = (int)Math.Round((double)coords.X / referenceSize.Width * aspectWidth
                    + (valign == VerticalScaleAlignment.Left ? 0 : 
                    valign == VerticalScaleAlignment.Center ? widthDifference / 2 : widthDifference));
            }

            return new Coordinates()
            {
                X = newX,
                Y = (int)Math.Round((double)coords.Y / referenceSize.Height * pos.Size.Height)
            };
        }