Exemple #1
0
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _canvas = GetTemplateChild <Canvas>(CanvasName);
            _image  = GetTemplateChild <Image>(ImageName);

            // Add manipulation event handlers
            _canvas.ManipulationMode =
                ManipulationModes.Scale | ManipulationModes.ScaleInertia |
                ManipulationModes.TranslateX | ManipulationModes.TranslateY | ManipulationModes.TranslateInertia;
            _canvas.ManipulationStarting        += OnManipulationStarting;
            _canvas.ManipulationStarted         += OnManipulationStarted;
            _canvas.ManipulationDelta           += OnManipulationDelta;
            _canvas.ManipulationCompleted       += OnManipulationCompleted;
            _canvas.ManipulationInertiaStarting += OnManipulationInertiaStarting;

            // CAUTION: this needs to not happen in design mode, as it causes a problem there
            // Window.Current.CoreWindow.PointerWheelChanged += OnPointerWheelChanged;

            FrameworkElementExtensions.SetCursor(this, new CoreCursor(CoreCursorType.Arrow, 0));
            _canvas.PointerMoved += OnPointerMoved;

            _cropLeft = _cropRight = _cropTop = _cropBottom = 50;

            // Set image to a zero size until it's properly loaded
            // This handily avoids some crashes, and some visual issues
            SetWidthHeight(_image, 0, 0);

            _isTemplateApplied = true;

            Setup();
        }
Exemple #2
0
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            Thumb volSliderThumb = FrameworkElementExtensions.FindChildOfType <Thumb>(positionSlider);

            if (volSliderThumb != null)
            {
                volSliderThumb.DragCompleted += VolSliderThumb_DragCompleted;
                volSliderThumb.DragStarted   += VolSliderThumb_DragStarted;
            }
            Window.Current.CoreWindow.PointerPressed += (ea, a) =>
            {
                if (positionSlider.GetBoundingRect().Contains(a.CurrentPoint.Position))
                {
                    isPressed = true;
                    ShellVM.DontUpdatePosition = true;
                }
            };

            Window.Current.CoreWindow.PointerReleased += (ea, a) =>
            {
                if (isPressed)
                {
                    UpdatePosition(true); isPressed = false;
                }
            };
        }
Exemple #3
0
        private Point SetCursorForPosition(Point position)
        {
            DragMode dragMode = CalculateDragMode(position);

            CoreCursorType cursorType;

            if (dragMode == DragMode.Full)
            {
                cursorType = CoreCursorType.Hand;
            }
            else if (dragMode == DragMode.TopLeft || dragMode == DragMode.BottomRight)
            {
                cursorType = CoreCursorType.SizeNorthwestSoutheast;
            }
            else if (dragMode == DragMode.TopRight || dragMode == DragMode.BottomLeft)
            {
                cursorType = CoreCursorType.SizeNortheastSouthwest;
            }
            else if (dragMode == DragMode.Top || dragMode == DragMode.Bottom)
            {
                cursorType = CoreCursorType.SizeNorthSouth;
            }
            else if (dragMode == DragMode.Left || dragMode == DragMode.Right)
            {
                cursorType = CoreCursorType.SizeWestEast;
            }
            else
            {
                cursorType = CoreCursorType.Arrow;
            }

            FrameworkElementExtensions.SetCursor(this, new CoreCursor(cursorType, (uint)cursorType));
            return(position);
        }
Exemple #4
0
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            Thumb volSliderThumb = FrameworkElementExtensions.FindChildOfType <Thumb>(positionSlider);

            volSliderThumb.DragCompleted += VolSliderThumb_DragCompleted;
            volSliderThumb.DragStarted   += VolSliderThumb_DragStarted;

            Player.MediaStateChanged += Player_MediaStateChanged;
        }
Exemple #5
0
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            Thumb volSliderThumb = FrameworkElementExtensions.FindChildOfType <Thumb>(positionSlider);

            if (volSliderThumb != null)
            {
                volSliderThumb.DragCompleted += VolSliderThumb_DragCompleted;
                volSliderThumb.DragStarted   += VolSliderThumb_DragStarted;
            }
        }
Exemple #6
0
        /// <inheritdoc/>
        public override void OnApplyTemplate()
        {
            templateApplied = false;
            base.OnApplyTemplate();

            if (colorPickerRenderSurface != null)
            {
                colorPickerRenderSurface.MouseDown -= OnColorPickerRenderSurfaceMouseDown;
                colorPickerRenderSurface.MouseUp   -= OnColorPickerRenderSurfaceMouseUp;
                colorPickerRenderSurface.MouseMove -= OnColorPickerRenderSurfaceMouseMove;
            }

            if (huePickerRenderSurface != null)
            {
                huePickerRenderSurface.MouseDown -= OnHuePickerRenderSurfaceMouseDown;
                huePickerRenderSurface.MouseUp   -= OnHuePickerRenderSurfaceMouseUp;
                huePickerRenderSurface.MouseMove -= OnHuePickerRenderSurfaceMouseMove;
            }

            colorPickerRenderSurface  = FrameworkElementExtensions.CheckTemplatePart <Rectangle>(GetTemplateChild("PART_ColorPickerRenderSurface"));
            colorPreviewRenderSurface = FrameworkElementExtensions.CheckTemplatePart <Rectangle>(GetTemplateChild("PART_ColorPreviewRenderSurface"));
            colorPickerSelector       = FrameworkElementExtensions.CheckTemplatePart <Canvas>(GetTemplateChild("PART_ColorPickerSelector"));
            huePickerSelector         = FrameworkElementExtensions.CheckTemplatePart <Rectangle>(GetTemplateChild("PART_HuePickerSelector"));
            huePickerRenderSurface    = FrameworkElementExtensions.CheckTemplatePart <FrameworkElement>(GetTemplateChild("PART_HuePickerRenderSurface"));

            if (colorPickerRenderSurface != null)
            {
                colorPickerRenderSurface.MouseDown += OnColorPickerRenderSurfaceMouseDown;
                colorPickerRenderSurface.MouseUp   += OnColorPickerRenderSurfaceMouseUp;
                colorPickerRenderSurface.MouseMove += OnColorPickerRenderSurfaceMouseMove;
            }

            if (huePickerRenderSurface != null)
            {
                huePickerRenderSurface.MouseDown += OnHuePickerRenderSurfaceMouseDown;
                huePickerRenderSurface.MouseUp   += OnHuePickerRenderSurfaceMouseUp;
                huePickerRenderSurface.MouseMove += OnHuePickerRenderSurfaceMouseMove;
            }

            RenderColorPickerSurface();

            if (colorPickerSelector != null && colorPickerRenderSurface != null)
            {
                Canvas.SetLeft(colorPickerSelector, Saturation * colorPickerRenderSurface.Width / 100.0);
                Canvas.SetTop(colorPickerSelector, Brightness * colorPickerRenderSurface.Height / 100.0);
            }
            if (huePickerSelector != null && huePickerRenderSurface != null)
            {
                Canvas.SetLeft(huePickerSelector, Hue * huePickerRenderSurface.Width / 360.0);
            }
            templateApplied = true;
        }
Exemple #7
0
        public RippleAdorner(FrameworkElement frameworkElement) : base(frameworkElement)
        {
            Children = new(this);

            target = new()
            {
                Height  = 0,
                Opacity = 0,
                Stroke  = FrameworkElementExtensions.GetRippleBrush(frameworkElement),
                Width   = 0
            };
            Children.Add(target);
        }
Exemple #8
0
        public ResizeAdorner(FrameworkElement frameworkElement) : base(frameworkElement)
        {
            Snap
                = FrameworkElementExtensions.GetResizeSnap(frameworkElement);
            ThumbStyle
                = FrameworkElementExtensions.GetResizeThumbStyle(frameworkElement);

            Children
                = new VisualCollection(this);

            BuildThumb(ref top,
                       Cursors.SizeNS);
            BuildThumb(ref left,
                       Cursors.SizeWE);
            BuildThumb(ref right,
                       Cursors.SizeWE);
            BuildThumb(ref bottom,
                       Cursors.SizeNS);
            BuildThumb(ref topLeft,
                       Cursors.SizeNWSE);
            BuildThumb(ref topRight,
                       Cursors.SizeNESW);
            BuildThumb(ref bottomLeft,
                       Cursors.SizeNESW);
            BuildThumb(ref bottomRight,
                       Cursors.SizeNWSE);

            Subscribe();

            /*
             * rotateLine = new System.Windows.Shapes.Rectangle()
             * {
             *  Fill = Brushes.Black,
             *  Height = 20,
             *  Width = 1
             * };
             * visualChildren.Add(rotateLine);
             * rotateSphere = new Thumb()
             * {
             *  Background = Brushes.Black,
             *  Height = 10,
             *  BorderBrush = Brushes.White,
             *  BorderThickness = new Thickness(1),
             *  Style = rotateThumbStyle,
             *  Width = 10
             * };
             * rotateSphere.DragDelta += new DragDeltaEventHandler(OnRotating);
             * rotateSphere.DragStarted += new DragStartedEventHandler(OnRotateStarted);
             * visualChildren.Add(rotateSphere);
             */
        }
        private void DetermineResizeCursor()
        {
            var effectiveResizeDirection =
                this.DetermineEffectiveResizeDirection();

            if (effectiveResizeDirection == GridResizeDirection.Columns)
            {
                FrameworkElementExtensions.SetCursor(this, new CoreCursor(CoreCursorType.SizeWestEast, 1));
            }
            else
            {
                FrameworkElementExtensions.SetCursor(this, new CoreCursor(CoreCursorType.SizeNorthSouth, 1));
            }
        }
Exemple #10
0
        public void FrameworkElementExtensions_ArgumentChecks()
        {
            var element = new Button();

            AssertEx.Throws <ArgumentNullException>(
                () => FrameworkElementExtensions.SetTag(null, 0),
                ex => Assert.AreEqual("view", ex.ParamName));

            AssertEx.Throws <ArgumentNullException>(
                () => FrameworkElementExtensions.SetReactContext(null, null),
                ex => Assert.AreEqual("view", ex.ParamName));

            AssertEx.Throws <ArgumentNullException>(
                () => FrameworkElementExtensions.GetTag(null),
                ex => Assert.AreEqual("view", ex.ParamName));

            AssertEx.Throws <ArgumentNullException>(
                () => FrameworkElementExtensions.GetReactContext(null),
                ex => Assert.AreEqual("view", ex.ParamName));
        }
Exemple #11
0
        static Storyboard GetStoryboard(FrameworkElement frameworkElement)
        {
            var result = new Storyboard {
                Duration = FrameworkElementExtensions.GetRippleDuration(frameworkElement)
            };

            var hAnimation = new DoubleAnimationUsingKeyFrames()
            {
                Duration          = FrameworkElementExtensions.GetRippleDuration(frameworkElement),
                AccelerationRatio = FrameworkElementExtensions.GetRippleAcceleration(frameworkElement),
                DecelerationRatio = FrameworkElementExtensions.GetRippleDeceleration(frameworkElement)
            };
            var wAnimation = new DoubleAnimationUsingKeyFrames()
            {
                Duration          = FrameworkElementExtensions.GetRippleDuration(frameworkElement),
                AccelerationRatio = FrameworkElementExtensions.GetRippleAcceleration(frameworkElement),
                DecelerationRatio = FrameworkElementExtensions.GetRippleDeceleration(frameworkElement)
            };
            var tAnimation = new DoubleAnimationUsingKeyFrames()
            {
                Duration          = FrameworkElementExtensions.GetRippleDuration(frameworkElement),
                AccelerationRatio = FrameworkElementExtensions.GetRippleAcceleration(frameworkElement),
                DecelerationRatio = FrameworkElementExtensions.GetRippleDeceleration(frameworkElement)
            };
            var oAnimation = new DoubleAnimationUsingKeyFrames()
            {
                Duration          = FrameworkElementExtensions.GetRippleDuration(frameworkElement),
                AccelerationRatio = FrameworkElementExtensions.GetRippleAcceleration(frameworkElement),
                DecelerationRatio = FrameworkElementExtensions.GetRippleDeceleration(frameworkElement)
            };

            Storyboard.SetTargetProperty(hAnimation,
                                         new PropertyPath(nameof(Ellipse.Height)));
            Storyboard.SetTargetProperty(wAnimation,
                                         new PropertyPath(nameof(Ellipse.Width)));
            Storyboard.SetTargetProperty(oAnimation,
                                         new PropertyPath(nameof(Ellipse.Opacity)));
            Storyboard.SetTargetProperty(tAnimation,
                                         new PropertyPath(nameof(Ellipse.StrokeThickness)));

            hAnimation.KeyFrames.Add(new DiscreteDoubleKeyFrame(0, KeyTime.FromTimeSpan(FrameworkElementExtensions.GetRippleDelay(frameworkElement).TimeSpan)));
            hAnimation.KeyFrames.Add(new LinearDoubleKeyFrame(FrameworkElementExtensions.GetRippleMaximumRadius(frameworkElement), KeyTime.FromTimeSpan(FrameworkElementExtensions.GetRippleDuration(frameworkElement).TimeSpan)));
            hAnimation.KeyFrames.Add(new DiscreteDoubleKeyFrame(0, KeyTime.FromTimeSpan(FrameworkElementExtensions.GetRippleDuration(frameworkElement).TimeSpan)));

            wAnimation.KeyFrames.Add(new DiscreteDoubleKeyFrame(0, KeyTime.FromTimeSpan(FrameworkElementExtensions.GetRippleDelay(frameworkElement).TimeSpan)));
            wAnimation.KeyFrames.Add(new LinearDoubleKeyFrame(FrameworkElementExtensions.GetRippleMaximumRadius(frameworkElement), KeyTime.FromTimeSpan(FrameworkElementExtensions.GetRippleDuration(frameworkElement).TimeSpan)));
            wAnimation.KeyFrames.Add(new DiscreteDoubleKeyFrame(0, KeyTime.FromTimeSpan(FrameworkElementExtensions.GetRippleDuration(frameworkElement).TimeSpan)));

            var offset = (FrameworkElementExtensions.GetRippleDuration(frameworkElement).TimeSpan.Ticks / 4) * 3;

            tAnimation.KeyFrames.Add(new DiscreteDoubleKeyFrame(FrameworkElementExtensions.GetRippleFromStrokeThickness(frameworkElement), KeyTime.FromTimeSpan(FrameworkElementExtensions.GetRippleDelay(frameworkElement).TimeSpan)));
            tAnimation.KeyFrames.Add(new LinearDoubleKeyFrame(FrameworkElementExtensions.GetRippleToStrokeThickness(frameworkElement), KeyTime.FromTimeSpan(FrameworkElementExtensions.GetRippleDuration(frameworkElement).TimeSpan)));

            oAnimation.KeyFrames.Add(new DiscreteDoubleKeyFrame(FrameworkElementExtensions.GetRippleMaximumOpacity(frameworkElement), KeyTime.FromTimeSpan(FrameworkElementExtensions.GetRippleDelay(frameworkElement).TimeSpan)));
            oAnimation.KeyFrames.Add(new LinearDoubleKeyFrame(FrameworkElementExtensions.GetRippleMaximumOpacity(frameworkElement) / 2.0, KeyTime.FromTimeSpan(new TimeSpan(offset))));
            oAnimation.KeyFrames.Add(new LinearDoubleKeyFrame(0.0, KeyTime.FromTimeSpan(FrameworkElementExtensions.GetRippleDuration(frameworkElement).TimeSpan)));

            result.Children.Add(hAnimation);
            result.Children.Add(wAnimation);
            result.Children.Add(oAnimation);
            result.Children.Add(tAnimation);

            if (FrameworkElementExtensions.GetRippleMouseEvent(frameworkElement) == MouseEvent.None)
            {
                result.RepeatBehavior = RepeatBehavior.Forever;
            }

            return(result);
        }