Beispiel #1
0
        private static IntPoint FindNearestX(int xStart, int yStart, int yEnd, int xIncrement, IScreenShot screenshot)
        {
            yStart = Math.Max(screenshot.Top, yStart);
            yEnd = Math.Min(screenshot.Bottom, yEnd);

            int xEdge = xIncrement < 0 ? int.MinValue : int.MaxValue;
            int yEdge = yStart;

            for (int y = yStart; y < yEnd; ++y) {
                int startPixel = screenshot.GetScreenPixel(xStart, y);

                for (int x = xStart; x >= screenshot.Left && x <= screenshot.Right; x += xIncrement) {
                    if (!ScreenCoordinates.IsPixelClose(screenshot.GetScreenPixel(x, y), startPixel)) {
                        if (xIncrement > 0 && xEdge > x) {
                            xEdge = x;
                            yEdge = y;
                        }
                        else if (xIncrement < 0 && xEdge < x) {
                            xEdge = x;
                            yEdge = y;
                        }
                        break;
                    }
                    startPixel = screenshot.GetScreenPixel(x, y);
                }
            }

            xEdge =  xEdge.Clamp(screenshot.Left, screenshot.Right);

            return new IntPoint(xEdge, yEdge);
        }
        public DistanceTool(StretchMode stretch, IScreenServiceHost host) : base(host)
        {
            this.StretchMode = stretch;

            this.screenshot = this.Host.CurrentScreen;

            this.InitializeComponent();

            if (this.StretchMode == StretchMode.EastWest)
            {
                this.N.Visibility = Visibility.Collapsed;
                this.S.Visibility = Visibility.Collapsed;
            }
            else if (this.StretchMode == StretchMode.NorthSouth)
            {
                this.E.Visibility = Visibility.Collapsed;
                this.W.Visibility = Visibility.Collapsed;
            }
#if !DEBUG
			this.Cursor = Cursors.None;
#endif

            this.Dimensions.CloseClicked += delegate
            {
                this.CloseService();
            };

            this.Loaded += delegate
            {
                this.Update();
            };
        }
Beispiel #3
0
        public DistanceTool(StretchMode stretch, IScreenServiceHost host) : base(host)
        {
            StretchMode = stretch;

            screenshot = Host.CurrentScreen;

            InitializeComponent();

            if (StretchMode == StretchMode.EastWest)
            {
                N.Visibility = Visibility.Collapsed;
                S.Visibility = Visibility.Collapsed;
            }
            else if (StretchMode == StretchMode.NorthSouth)
            {
                E.Visibility = Visibility.Collapsed;
                W.Visibility = Visibility.Collapsed;
            }
#if !DEBUG
            this.Cursor = Cursors.None;
#endif

            Dimensions.CloseClicked += delegate
            {
                CloseService();
                OnDimensionsCloseClicked(new EventArgs());
            };

            Loaded += delegate
            {
                Update();
            };
        }
Beispiel #4
0
        public static IntRect Collapse(IntRect rect, IScreenShot screenshot)
        {
            int left = ScreenCoordinates.FindNearestX(rect.Left, rect.Top, rect.Bottom, 1, screenshot).X;
            int right = ScreenCoordinates.FindNearestX(rect.Right, rect.Top, rect.Bottom, -1, screenshot).X + 1;

            int top = ScreenCoordinates.FindNearestY(rect.Left, rect.Right, rect.Top, 1, screenshot).Y - 1;
            int bottom = ScreenCoordinates.FindNearestY(rect.Left, rect.Right, rect.Bottom, -1, screenshot).Y;

            if (right > left && bottom > top)
                return new IntRect(left, top + 1, right - left, bottom - top);
            return IntRect.Empty;
        }
Beispiel #5
0
        public static IntRect Collapse(IntRect rect, IScreenShot screenshot)
        {
            int left  = ScreenCoordinates.FindNearestX(rect.Left, rect.Top, rect.Bottom, 1, screenshot).X;
            int right = ScreenCoordinates.FindNearestX(rect.Right, rect.Top, rect.Bottom, -1, screenshot).X + 1;

            int top    = ScreenCoordinates.FindNearestY(rect.Left, rect.Right, rect.Top, 1, screenshot).Y - 1;
            int bottom = ScreenCoordinates.FindNearestY(rect.Left, rect.Right, rect.Bottom, -1, screenshot).Y;

            if (right > left && bottom > top)
            {
                return(new IntRect(left, top + 1, right - left, bottom - top));
            }
            return(IntRect.Empty);
        }
Beispiel #6
0
        public static IntRect ExpandPoint(IntPoint position, IScreenShot screenshot)
        {
            int x = position.X;
            int y = position.Y;

            int left = ScreenCoordinates.FindNearestX(x, y - 5, y + 5, -1, screenshot).X + 1;
            int right = ScreenCoordinates.FindNearestX(x, y - 5, y + 5, 1, screenshot).X;
            int top = ScreenCoordinates.FindNearestY(x - 5, x + 5, y, -1, screenshot).Y + 1;
            int bottom = ScreenCoordinates.FindNearestY(x - 5, x + 5, y, 1, screenshot).Y;

            if (right > left && bottom > top)
                return new IntRect(left, top, right - left, bottom - top);
            return IntRect.Empty;
        }
Beispiel #7
0
        public BoundsTool(IScreenServiceHost host) : base(host)
        {
            this.screenshot = this.Host.CurrentScreen;

            InitializeComponent();

            this.BoundsWidth.Width     = new GridLength(0, GridUnitType.Pixel);
            this.BoundsHeight.Height   = new GridLength(0, GridUnitType.Pixel);
            this.Dimensions.Visibility = Visibility.Collapsed;

            this.Dimensions.CloseClicked += delegate {
                this.CloseService();
            };
        }
Beispiel #8
0
        public static IntRect ExpandPoint(IntPoint position, IScreenShot screenshot)
        {
            int x = position.X;
            int y = position.Y;

            int left   = ScreenCoordinates.FindNearestX(x, y - 5, y + 5, -1, screenshot).X + 1;
            int right  = ScreenCoordinates.FindNearestX(x, y - 5, y + 5, 1, screenshot).X;
            int top    = ScreenCoordinates.FindNearestY(x - 5, x + 5, y, -1, screenshot).Y + 1;
            int bottom = ScreenCoordinates.FindNearestY(x - 5, x + 5, y, 1, screenshot).Y;

            if (right > left && bottom > top)
            {
                return(new IntRect(left, top, right - left, bottom - top));
            }
            return(IntRect.Empty);
        }
Beispiel #9
0
        private static IntPoint FindNearestY(int xStart, int xEnd, int yStart, int yIncrement, IScreenShot screenshot)
        {
            xStart = Math.Max(screenshot.Left, xStart);
            xEnd   = Math.Min(screenshot.Right, xEnd);

            int xEdge = xStart;
            int yEdge = yIncrement < 0 ? int.MinValue : int.MaxValue;

            for (int x = xStart; x < xEnd; ++x)
            {
                int startPixel = screenshot.GetScreenPixel(x, yStart);

                for (int y = yStart; y >= screenshot.Top && y <= screenshot.Bottom; y += yIncrement)
                {
                    if (!ScreenCoordinates.IsPixelClose(screenshot.GetScreenPixel(x, y), startPixel))
                    {
                        if (yIncrement > 0 && yEdge > y)
                        {
                            xEdge = x;
                            yEdge = y;
                        }
                        else if (yIncrement < 0 && yEdge < y)
                        {
                            xEdge = x;
                            yEdge = y;
                        }
                        break;
                    }
                    startPixel = screenshot.GetScreenPixel(x, y);
                }
            }

            yEdge = yEdge.Clamp(screenshot.Top, screenshot.Bottom);

            return(new IntPoint(xEdge, yEdge));
        }
Beispiel #10
0
        private static IntPoint FindNearestX(int xStart, int yStart, int yEnd, int xIncrement, IScreenShot screenshot)
        {
            yStart = Math.Max(screenshot.Top, yStart);
            yEnd   = Math.Min(screenshot.Bottom, yEnd);

            int xEdge = xIncrement < 0 ? int.MinValue : int.MaxValue;
            int yEdge = yStart;

            for (int y = yStart; y < yEnd; ++y)
            {
                int startPixel = screenshot.GetScreenPixel(xStart, y);

                for (int x = xStart; x >= screenshot.Left && x <= screenshot.Right; x += xIncrement)
                {
                    if (!ScreenCoordinates.IsPixelClose(screenshot.GetScreenPixel(x, y), startPixel))
                    {
                        if (xIncrement > 0 && xEdge > x)
                        {
                            xEdge = x;
                            yEdge = y;
                        }
                        else if (xIncrement < 0 && xEdge < x)
                        {
                            xEdge = x;
                            yEdge = y;
                        }
                        break;
                    }
                    startPixel = screenshot.GetScreenPixel(x, y);
                }
            }

            xEdge = xEdge.Clamp(screenshot.Left, screenshot.Right);

            return(new IntPoint(xEdge, yEdge));
        }
Beispiel #11
0
        private static IntPoint FindNearestY(int xStart, int xEnd, int yStart, int yIncrement, IScreenShot screenshot)
        {
            xStart = Math.Max(screenshot.Left, xStart);
            xEnd = Math.Min(screenshot.Right, xEnd);

            int xEdge = xStart;
            int yEdge = yIncrement < 0 ? int.MinValue : int.MaxValue;

            for (int x = xStart; x < xEnd; ++x) {
                int startPixel = screenshot.GetScreenPixel(x, yStart);

                for (int y = yStart; y >= screenshot.Top && y <= screenshot.Bottom; y += yIncrement) {
                    if (!ScreenCoordinates.IsPixelClose(screenshot.GetScreenPixel(x, y), startPixel)) {
                        if (yIncrement > 0 && yEdge > y) {
                            xEdge = x;
                            yEdge = y;
                        }
                        else if (yIncrement < 0 && yEdge < y) {
                            xEdge = x;
                            yEdge = y;
                        }
                        break;
                    }
                    startPixel = screenshot.GetScreenPixel(x, y);
                }
            }

            yEdge = yEdge.Clamp(screenshot.Top, screenshot.Bottom);

            return new IntPoint(xEdge, yEdge);
        }