Ejemplo n.º 1
0
        public static Point ScreenToClient(FrameworkElement element, IntPoint point)
        {
            PresentationSource source = PresentationSource.FromVisual(element);

            Win32Point winPt = new Win32Point(point.X, point.Y);
            NativeMethods.ScreenToClient(((HwndSource)source).Handle, ref winPt);

            Point offset = source.CompositionTarget.TransformFromDevice.Transform(new Point(winPt.x, winPt.y));

            return source.RootVisual.TransformToDescendant(element).Transform(offset);
        }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
0
 public static IntRect ExpandPoint(IntPoint position)
 {
     ScreenShot screenshot = new ScreenShot();
     return ScreenCoordinates.ExpandPoint(position, screenshot);
 }
Ejemplo n.º 4
0
 public bool Equals(IntPoint value)
 {
     return this.X == value.X && this.Y == value.Y;
 }
Ejemplo n.º 5
0
 public static void SetCursorPos(IntPoint point)
 {
     NativeMethods.SetCursorPos(point.X, point.Y);
 }
Ejemplo n.º 6
0
 private void SetBasePointExecuted(object sender, ExecutedRoutedEventArgs e)
 {
     this.basePoint = NativeMethods.GetCursorPos();
 }
Ejemplo n.º 7
0
        private void HandleTick(object sender, EventArgs e)
        {
            IntPoint mousePoint = NativeMethods.GetCursorPos();

            if (mousePoint == this.lastMousePoint && DateTime.Now - this.lastCapture < TimeSpan.FromSeconds(.2)) {
                return;
            }

            this.lastCapture = DateTime.Now;
            this.lastMousePoint = mousePoint;

            this.MouseX.Text = string.Format(@"X: {0}", mousePoint.X - this.basePoint.X);
            this.MouseY.Text = string.Format(@"Y: {0}", mousePoint.Y - this.basePoint.Y);

            if (this.isPaused)
                return;

            double width = this.Image.ActualWidth / this.Scale;
            double height = this.Image.ActualHeight / this.Scale;

            double left = (mousePoint.X - width / 2).Clamp(ScreenShot.FullScreenBounds.Left, ScreenShot.FullScreenBounds.Width - width);
            double top = (mousePoint.Y - height / 2).Clamp(ScreenShot.FullScreenBounds.Top, ScreenShot.FullScreenBounds.Height - height);

            double deltaX = left - (mousePoint.X - width / 2);
            double deltaY = top - (mousePoint.Y - height / 2);

            if (deltaX != 0)
                this.CenterX.Width = new GridLength((this.Image.ActualWidth / 2 - deltaX * this.Scale) + 2 * this.Scale);
            else
                this.CenterX.Width = new GridLength(this.Image.ActualWidth / 2 + 8);

            if (deltaY != 0)
                this.CenterY.Height = new GridLength((this.Image.ActualHeight / 2 - deltaY * this.Scale) + 2 * this.Scale);
            else
                this.CenterY.Height = new GridLength(this.Image.ActualHeight / 2 + 8);

            IntRect rect = new IntRect((int)left, (int)top, (int)width, (int)height);

            ScreenShot screenShot = new ScreenShot(rect);

            FormatConvertedBitmap newFormatedBitmapSource = new FormatConvertedBitmap();
            newFormatedBitmapSource.BeginInit();
            newFormatedBitmapSource.Source = screenShot.Image;
            newFormatedBitmapSource.DestinationFormat = PixelFormats.Rgb24;
            newFormatedBitmapSource.EndInit();

            this.Image.Source = newFormatedBitmapSource;

            if (width == 0 || height == 0)
                return;

            uint centerPixel = (uint)screenShot.GetScreenPixel((int)mousePoint.X, (int)mousePoint.Y);
            centerPixel = centerPixel | 0xFF000000;
            byte r = (byte)((centerPixel >> 16) & 0xFF);
            byte g = (byte)((centerPixel >> 8) & 0xFF);
            byte b = (byte)((centerPixel >> 0) & 0xFF);

            Brush brush = new SolidColorBrush(Color.FromRgb(r, g, b));
            this.ColorSwatch.Fill = brush;

            this.PixelColor.Text = string.Format(@"#{0:X8}", centerPixel);
        }
Ejemplo n.º 8
0
 public static void SetCursorPos(IntPoint point)
 {
     NativeMethods.SetCursorPos(point.X, point.Y);
 }