Exemplo n.º 1
0
        private void CacheImage(UnsafeNativeMethods.Win32Point start, UnsafeNativeMethods.Win32Point end)
        {
            int xSrc = Math.Min(start.x, end.x);
            int ySrc = Math.Min(start.y, end.y);
            int num1 = Math.Abs(start.x - end.x) + 1;
            int num2 = Math.Abs(start.y - end.y) + 1;

            this.cachedImage = (BitmapSource)null;
            if (num1 <= 0 || num2 <= 0)
            {
                return;
            }
            IntPtr dc = UnsafeNativeMethods.CreateDC("Display", (string)null, (string)null, IntPtr.Zero);

            if (!(dc != IntPtr.Zero))
            {
                return;
            }
            IntPtr compatibleDc = UnsafeNativeMethods.CreateCompatibleDC(dc);

            if (compatibleDc != IntPtr.Zero)
            {
                IntPtr compatibleBitmap = UnsafeNativeMethods.CreateCompatibleBitmap(dc, num1, num2);
                if (compatibleBitmap != IntPtr.Zero)
                {
                    IntPtr hgdiobj = UnsafeNativeMethods.SelectObject(compatibleDc, compatibleBitmap);
                    UnsafeNativeMethods.BitBlt(compatibleDc, 0, 0, num1, num2, dc, xSrc, ySrc, 13369376);
                    this.cachedImage = Imaging.CreateBitmapSourceFromHBitmap(compatibleBitmap, IntPtr.Zero, new Int32Rect(0, 0, num1, num2), (BitmapSizeOptions)null);
                    UnsafeNativeMethods.SelectObject(compatibleDc, hgdiobj);
                    UnsafeNativeMethods.DeleteObject(compatibleBitmap);
                }
                UnsafeNativeMethods.DeleteDC(compatibleDc);
            }
            UnsafeNativeMethods.DeleteDC(dc);
        }
Exemplo n.º 2
0
        private void SetFeedbackLine(UnsafeNativeMethods.Win32Point p1, UnsafeNativeMethods.Win32Point p2)
        {
            Line createFeedbackLine = this.GetOrCreateFeedbackLine();

            if (createFeedbackLine == null)
            {
                return;
            }
            double num1 = this.FeedbackWindow.Left = SystemParameters.VirtualScreenLeft;
            double num2 = this.FeedbackWindow.Top = SystemParameters.VirtualScreenTop;

            createFeedbackLine.X1 = (double)p1.x * DpiHelper.DeviceToLogicalUnitsScalingFactorX - num1;
            createFeedbackLine.Y1 = (double)p1.y * DpiHelper.DeviceToLogicalUnitsScalingFactorY - num2;
            createFeedbackLine.X2 = (double)p2.x * DpiHelper.DeviceToLogicalUnitsScalingFactorX - num1;
            createFeedbackLine.Y2 = (double)p2.y * DpiHelper.DeviceToLogicalUnitsScalingFactorY - num2;
            double num3 = Math.Max(createFeedbackLine.X1, createFeedbackLine.X2);
            double num4 = Math.Max(createFeedbackLine.Y1, createFeedbackLine.Y2);
            double num5 = 64.0;
            double num6 = Math.Ceiling(num3 / num5 + 1.0) * num5;
            double num7 = Math.Ceiling(num4 / num5 + 1.0) * num5;

            if (this.FeedbackWindow.Width < num6)
            {
                this.FeedbackWindow.Width = num6;
            }
            if (this.FeedbackWindow.Height >= num7)
            {
                return;
            }
            this.FeedbackWindow.Height = num7;
        }
Exemplo n.º 3
0
 private void MoveFeedbackWindow()
 {
     if (this.FeedbackWindow != null && this.CenterFeedbackWindow)
     {
         UnsafeNativeMethods.Win32Point cursorPosition = UnsafeNativeMethods.GetCursorPosition();
         double deviceToLogicalUnitsScalingFactorX     = (double)cursorPosition.x * DpiHelper.DeviceToLogicalUnitsScalingFactorX;
         double deviceToLogicalUnitsScalingFactorY     = (double)cursorPosition.y * DpiHelper.DeviceToLogicalUnitsScalingFactorY;
         this.FeedbackWindow.Left = deviceToLogicalUnitsScalingFactorX - this.FeedbackWindow.Width / 2;
         this.FeedbackWindow.Top  = deviceToLogicalUnitsScalingFactorY - this.FeedbackWindow.Height / 2;
     }
 }
Exemplo n.º 4
0
        private Color GetPixelColorInternal(UnsafeNativeMethods.Win32Point point, BitmapSource cachedImage)
        {
            uint[] numArray = new uint[1];
            int    x        = point.x;
            int    y        = point.y;

            cachedImage.CopyPixels(new Int32Rect(x, y, 1, 1), (Array)numArray, 4, 0);
            uint num = numArray[0];

            return(Color.FromArgb(byte.MaxValue, (byte)((num & 16711680U) >> 16), (byte)((num & 65280U) >> 8), (byte)(num & (uint)byte.MaxValue)));
        }
Exemplo n.º 5
0
 private void UpdateOnMouseEvent()
 {
     this.endPoint = this.GetPosition();
     if (this.lastPoint.x == this.endPoint.x && this.lastPoint.y == this.endPoint.y)
     {
         return;
     }
     this.lastPoint = this.endPoint;
     if (!this.isDragging)
     {
         this.StartUpdateColor(this.endPoint.x, this.endPoint.y);
     }
     else
     {
         if (this.FeedbackWindow == null)
         {
             return;
         }
         this.SetFeedbackLine(this.startPoint, this.endPoint);
     }
 }
Exemplo n.º 6
0
 protected override void OnMouseDown(MouseButtonEventArgs e)
 {
     if (e.ChangedButton == MouseButton.Left)
     {
         if (this.isEditing)
         {
             this.isButtonDown = true;
             this.startPoint   = this.GetPosition();
         }
         else
         {
             this.BeginEditing();
         }
         e.Handled = true;
     }
     else if (e.ChangedButton == MouseButton.Right && this.isEditing)
     {
         this.CancelEditing();
         e.Handled = true;
     }
     base.OnMouseDown(e);
 }
Exemplo n.º 7
0
        private List <UnsafeNativeMethods.Win32Point> GeneratePoints(UnsafeNativeMethods.Win32Point start, UnsafeNativeMethods.Win32Point end)
        {
            int num1 = Math.Abs(end.x - start.x);
            int num2 = Math.Abs(end.y - start.y);
            List <UnsafeNativeMethods.Win32Point> list;

            if (num2 <= num1)
            {
                int    num3 = Math.Sign(end.x - start.x);
                double num4 = (double)num3 * ((double)(end.y - start.y) / (double)(end.x - start.x));
                double a    = (double)start.y;
                list = new List <UnsafeNativeMethods.Win32Point>(num1 + 1);
                int x = start.x;
                while (x != end.x)
                {
                    list.Add(new UnsafeNativeMethods.Win32Point(x, (int)Math.Round(a)));
                    a += num4;
                    x += num3;
                }
                list.Add(end);
            }
            else
            {
                int    num3 = Math.Sign(end.y - start.y);
                double num4 = (double)num3 * ((double)(end.x - start.x) / (double)(end.y - start.y));
                double a    = (double)start.x;
                list = new List <UnsafeNativeMethods.Win32Point>(num2 + 1);
                int y = start.y;
                while (y != end.y)
                {
                    list.Add(new UnsafeNativeMethods.Win32Point((int)Math.Round(a), y));
                    a += num4;
                    y += num3;
                }
                list.Add(end);
            }
            return(list);
        }
Exemplo n.º 8
0
        private void UpdateGradient(UnsafeNativeMethods.Win32Point start, UnsafeNativeMethods.Win32Point end)
        {
            if (start.x == end.x && start.y == end.y)
            {
                return;
            }
            List <UnsafeNativeMethods.Win32Point> list = this.GeneratePoints(start, end);
            List <Color>  colors = new List <Color>(list.Count);
            List <double> accumulatedDistances = new List <double>(list.Count);
            double        num1 = 0.0;

            this.CacheImage(start, end);
            if (this.cachedImage == null)
            {
                return;
            }
            int num2 = Math.Min(start.x, end.x);
            int num3 = Math.Min(start.y, end.y);

            for (int index = 0; index < list.Count; ++index)
            {
                UnsafeNativeMethods.Win32Point point = list[index];
                point.x -= num2;
                point.y -= num3;
                colors.Add(this.GetPixelColorInternal(point, this.cachedImage));
                if (index > 0)
                {
                    num1 += this.L2(list[index], list[index - 1]);
                }
                accumulatedDistances.Add(num1);
            }
            this.cachedImage = (BitmapSource)null;
            ICollection <GradientEyedropper.GradientInterval> intervals = this.GenerateMinimalIntervalSet(colors, accumulatedDistances);

            this.RawGradient = this.ReconstructGradient(colors, accumulatedDistances, intervals);
        }
Exemplo n.º 9
0
        private void Current_PostNotifyInput(object sender, NotifyInputEventArgs e)
        {
            KeyEventArgs keyEventArgs = e.StagingItem.Input as KeyEventArgs;

            if (keyEventArgs != null && keyEventArgs.Key == Key.Escape && this.isCapturing)
            {
                this.CancelEditing();
            }
            else
            {
                if (!(e.StagingItem.Input is MouseEventArgs))
                {
                    return;
                }
                UnsafeNativeMethods.Win32Point cursorPosition = UnsafeNativeMethods.GetCursorPosition();
                if (this.lastX == cursorPosition.x && this.lastY == cursorPosition.y)
                {
                    return;
                }
                this.lastX = cursorPosition.x;
                this.lastY = cursorPosition.y;
                this.StartUpdateColor(cursorPosition.x, cursorPosition.y);
            }
        }
Exemplo n.º 10
0
 protected void StartUpdateColor(int screenX, int screenY)
 {
     this.currentPoint = new UnsafeNativeMethods.Win32Point(screenX, screenY);
     this.MoveFeedbackWindow();
     this.UpdateColor();
 }
Exemplo n.º 11
0
 private double L2(UnsafeNativeMethods.Win32Point a, UnsafeNativeMethods.Win32Point b)
 {
     return(Math.Sqrt((double)((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y))));
 }
Exemplo n.º 12
0
 private UnsafeNativeMethods.Win32Point GetPosition()
 {
     UnsafeNativeMethods.Win32Point pt = new UnsafeNativeMethods.Win32Point(0, 0);
     UnsafeNativeMethods.GetCursorPos(ref pt);
     return(pt);
 }