Ejemplo n.º 1
0
        private static Vector DraggedDelta(InputDevice inputDevice, Window window, UIElement relativeTo)
        {
            // get the current position
            Point currentPosition = inputDevice.GetPosition(window);

            // get the down state
            if (!deviceStateDictionary.ContainsKey(inputDevice))
            {
                return ZeroVector;
            }

            // translate to the relativeTo elementToDrag
            Point downPosition = deviceStateDictionary[inputDevice].Position;

            if (relativeTo != window)
            {
                currentPosition = window.TranslatePoint(currentPosition, relativeTo);
                downPosition = window.TranslatePoint(downPosition, relativeTo);
            }

            return (currentPosition - downPosition);
        }
Ejemplo n.º 2
0
        private System.Windows.Media.Color GetPixelColor(InputDevice inputDevice)
        {
            // Translate the input point to bitmap coordinates
            double transformFactor = ColorWheel.Source.Width / ColorWheel.ActualWidth;
            Point inputPoint = inputDevice.GetPosition(ColorWheel);
            Point bitmapPoint = new Point(inputPoint.X * transformFactor, inputPoint.Y * transformFactor);

            // The point is outside the color wheel. Return black.
            if (bitmapPoint.X < 0 || bitmapPoint.X >= ColorWheel.Source.Width ||
                bitmapPoint.Y < 0 || bitmapPoint.Y >= ColorWheel.Source.Height)
            {
                return Colors.Black;
            }

            // The point is inside the color wheel. Find the color at the point.
            CroppedBitmap cb = new CroppedBitmap(ColorWheel.Source as BitmapSource, new Int32Rect((int)bitmapPoint.X, (int)bitmapPoint.Y, 1, 1));
            byte[] pixels = new byte[4];
            cb.CopyPixels(pixels, 4, 0);
            return Color.FromRgb(pixels[2], pixels[1], pixels[0]);
        }
Ejemplo n.º 3
0
        public static void InitializeDeviceState(InputDevice inputDevice)
        {
            if (inputDevice == null || deviceStateDictionary.ContainsKey(inputDevice))
            {
                return;
            }

            Window window = inputDevice.ActiveSource.RootVisual as Window;
            if (window == null)
            {
                return;
            }

            Point position = inputDevice.GetPosition(window);

            DependencyObject directlyOver = inputDevice.GetDirectlyOver() as DependencyObject;

            deviceStateDictionary.Add(inputDevice, new DragState(position, directlyOver));
        }