Esempio n. 1
0
        private void InitializeComponents()
        {
            this.ReciprocalScale = new ScaleTransform(Scale, Scale);

            AdornedElement.SetDesignMinWidth(5);
            AdornedElement.SetDesignMinHeight(5);

            GripLayer.InitializeComponents();

            #region < Add Move Thumb >
            Add(moveThumb = new LayerMoveThumb(this));

            moveThumb.DragStarted   += MoveThumb_DragStarted;
            moveThumb.DragCompleted += MoveThumb_DragCompleted;
            moveThumb.Moved         += MoveThumb_Moved;

            // Selection
            moveThumb.PreviewMouseLeftButtonDown += MoveThumb_PreviewMouseLeftButtonDown;
            moveThumb.PreviewMouseLeftButtonUp   += MoveThumb_PreviewMouseLeftButtonUp;
            #endregion

            #region < Binding >
            var reciprocalConverter = new ReciprocalConverter();

            // ParentScale X -> scale X
            BindingHelper.SetBinding(
                Zoom, ZoomPanel.ScaleProperty,
                ReciprocalScale, ScaleTransform.ScaleXProperty,
                converter: reciprocalConverter);

            // ParentScale Y -> scale Y
            BindingHelper.SetBinding(
                Zoom, ZoomPanel.ScaleProperty,
                ReciprocalScale, ScaleTransform.ScaleYProperty,
                converter: reciprocalConverter);
            #endregion
        }
Esempio n. 2
0
        protected override void OnVisualParentChanged(DependencyObject oldParent)
        {
            base.OnVisualParentChanged(oldParent);

            if (this.Parent is ZoomPanel zoomPanel)
            {
                this.ZoomPanel = zoomPanel;

                scaleConverter = new ReciprocalConverter();
                scaleTransform = new ScaleTransform();

                // ParentScale X -> scale X
                BindingHelper.SetBinding(
                    ZoomPanel, ZoomPanel.ScaleProperty,
                    scaleTransform, ScaleTransform.ScaleXProperty,
                    converter: scaleConverter);

                // ParentScale Y -> scale Y
                BindingHelper.SetBinding(
                    ZoomPanel, ZoomPanel.ScaleProperty,
                    scaleTransform, ScaleTransform.ScaleYProperty,
                    converter: scaleConverter);
            }
        }
Esempio n. 3
0
        private void InitializeComponents()
        {
            AdornedElement.SetDesignMinWidth(5);
            AdornedElement.SetDesignMinHeight(5);

            var scale = new ScaleTransform(Scale, Scale);

            #region < Add Move Thumb >
            Add(moveThumb = new LayerMoveThumb(this));

            moveThumb.DragStarted   += MoveThumb_DragStarted;
            moveThumb.DragCompleted += MoveThumb_DragCompleted;
            moveThumb.Moved         += MoveThumb_Moved;

            // Selection
            moveThumb.PreviewMouseLeftButtonDown += MoveThumb_PreviewMouseLeftButtonDown;
            moveThumb.PreviewMouseLeftButtonUp   += MoveThumb_PreviewMouseLeftButtonUp;
            #endregion

            #region < Add Margin Clips >
            ClipData = new MarginClipHolder();

            Add(clipGrid = new Grid()
            {
                Visibility = Visibility.Collapsed,
                Children   =
                {
                    (ClipData.LeftClip      = new LayerMarginClip
                    {
                        HorizontalAlignment = HorizontalAlignment.Center,
                        VerticalAlignment   = VerticalAlignment.Center,
                        LayoutTransform     = new TransformGroup()
                        {
                            Children        =
                            {
                                scale,
                                new RotateTransform(90)
                            }
                        }
                    }),
                    (ClipData.TopClip       = new LayerMarginClip
                    {
                        HorizontalAlignment = HorizontalAlignment.Center,
                        VerticalAlignment   = VerticalAlignment.Center,
                        LayoutTransform     = scale
                    }),
                    (ClipData.RightClip     = new LayerMarginClip
                    {
                        HorizontalAlignment = HorizontalAlignment.Center,
                        VerticalAlignment   = VerticalAlignment.Center,
                        LayoutTransform     = new TransformGroup()
                        {
                            Children        =
                            {
                                scale,
                                new RotateTransform(90)
                            }
                        }
                    }),
                    (ClipData.BottomClip    = new LayerMarginClip
                    {
                        HorizontalAlignment = HorizontalAlignment.Center,
                        VerticalAlignment   = VerticalAlignment.Center,
                        LayoutTransform     = scale
                    }),
                }
            });
            #endregion

            #region < Add Grips >
            Add(resizeGrid = new Grid()
            {
                Visibility = Visibility.Collapsed,
                Children   =
                {
                    new LayerResizeThumb(this)
                    {
                        Width                 = GripSize,
                        Height                = GripSize,
                        ResizeDirection       = ResizeGripDirection.TopLeft,
                        Cursor                = Cursors.SizeNWSE,
                        Margin                = new Thickness(-GripSize, -GripSize, GripSize, GripSize),
                        HorizontalAlignment   = HorizontalAlignment.Left,
                        VerticalAlignment     = VerticalAlignment.Top,
                        RenderTransform       = scale,
                        RenderTransformOrigin = new Point(1, 1)
                    },
                    new LayerResizeThumb(this)
                    {
                        Width                 = GripSize,
                        Height                = GripSize,
                        ResizeDirection       = ResizeGripDirection.Top,
                        Cursor                = Cursors.SizeNS,
                        Margin                = new Thickness(0, -GripSize, 0, GripSize),
                        HorizontalAlignment   = HorizontalAlignment.Center,
                        VerticalAlignment     = VerticalAlignment.Top,
                        RenderTransform       = scale,
                        RenderTransformOrigin = new Point(0.5, 1)
                    },
                    new LayerResizeThumb(this)
                    {
                        Width                 = GripSize,
                        Height                = GripSize,
                        ResizeDirection       = ResizeGripDirection.TopRight,
                        Cursor                = Cursors.SizeNESW,
                        Margin                = new Thickness(GripSize, -GripSize, -GripSize, GripSize),
                        HorizontalAlignment   = HorizontalAlignment.Right,
                        VerticalAlignment     = VerticalAlignment.Top,
                        RenderTransform       = scale,
                        RenderTransformOrigin = new Point(0, 1)
                    },
                    new LayerResizeThumb(this)
                    {
                        Width                 = GripSize,
                        Height                = GripSize,
                        ResizeDirection       = ResizeGripDirection.Left,
                        Cursor                = Cursors.SizeWE,
                        Margin                = new Thickness(-GripSize, 0, GripSize, 0),
                        HorizontalAlignment   = HorizontalAlignment.Left,
                        VerticalAlignment     = VerticalAlignment.Center,
                        RenderTransform       = scale,
                        RenderTransformOrigin = new Point(1, 0.5)
                    },
                    new LayerResizeThumb(this)
                    {
                        Width                 = GripSize,
                        Height                = GripSize,
                        ResizeDirection       = ResizeGripDirection.Right,
                        Cursor                = Cursors.SizeWE,
                        Margin                = new Thickness(GripSize, 0, -GripSize, 0),
                        HorizontalAlignment   = HorizontalAlignment.Right,
                        VerticalAlignment     = VerticalAlignment.Center,
                        RenderTransform       = scale,
                        RenderTransformOrigin = new Point(0, 0.5)
                    },
                    new LayerResizeThumb(this)
                    {
                        Width                 = GripSize, Height = GripSize,
                        ResizeDirection       = ResizeGripDirection.BottomLeft,
                        Cursor                = Cursors.SizeNESW,
                        Margin                = new Thickness(-GripSize, GripSize, GripSize, -GripSize),
                        HorizontalAlignment   = HorizontalAlignment.Left,
                        VerticalAlignment     = VerticalAlignment.Bottom,
                        RenderTransform       = scale,
                        RenderTransformOrigin = new Point(1, 0)
                    },
                    new LayerResizeThumb(this)
                    {
                        Width                 = GripSize, Height = GripSize,
                        ResizeDirection       = ResizeGripDirection.Bottom,
                        Cursor                = Cursors.SizeNS,
                        Margin                = new Thickness(0, GripSize, 0, -GripSize),
                        HorizontalAlignment   = HorizontalAlignment.Center,
                        VerticalAlignment     = VerticalAlignment.Bottom,
                        RenderTransform       = scale,
                        RenderTransformOrigin = new Point(0.5, 0)
                    },
                    new LayerResizeThumb(this)
                    {
                        Width               = GripSize, Height = GripSize,
                        ResizeDirection     = ResizeGripDirection.BottomRight,
                        Cursor              = Cursors.SizeNWSE,
                        Margin              = new Thickness(GripSize, GripSize, -GripSize, -GripSize),
                        HorizontalAlignment = HorizontalAlignment.Right,
                        VerticalAlignment   = VerticalAlignment.Bottom,
                        RenderTransform     = scale
                    }
                }
            });
            #endregion

            #region < Add Event Trigger Button >
            Add(TriggerButton = new LayerEventTriggerButton(this)
            {
                Visibility            = Visibility.Collapsed,
                Margin                = new Thickness(10, 0, -10, 0),
                HorizontalAlignment   = HorizontalAlignment.Right,
                VerticalAlignment     = VerticalAlignment.Center,
                RenderTransformOrigin = new Point(0, 0.5),
                RenderTransform       = scale
            });
            #endregion

            #region < Binding >
            var reciprocalConverter = new ReciprocalConverter();

            // ParentScale X -> scale X
            BindingHelper.SetBinding(
                Zoom, ZoomPanel.ScaleProperty,
                scale, ScaleTransform.ScaleXProperty,
                converter: reciprocalConverter);

            // ParentScale Y -> scale Y
            BindingHelper.SetBinding(
                Zoom, ZoomPanel.ScaleProperty,
                scale, ScaleTransform.ScaleYProperty,
                converter: reciprocalConverter);

            // SelectionBrush -> triggerButton Background
            BindingHelper.SetBinding(
                this, SelectionBrushProperty,
                TriggerButton, Control.BackgroundProperty);

            var reverseConverter = new MultiplayConverter()
            {
                Value = -1
            };

            foreach (LayerResizeThumb thumb in resizeGrid.Children)
            {
                // SelectionBrush -> thumb Stroke
                BindingHelper.SetBinding(
                    this, SelectionBrushProperty,
                    thumb, LayerResizeThumb.StrokeProperty);

                thumb.DragStarted   += ThumbOnDragStarted;
                thumb.DragCompleted += ThumbOnDragCompleted;
            }

            // caching
            UpdateMarginClips();

            foreach (LayerMarginClip clip in clipGrid.Children)
            {
                ToggleButton.IsCheckedProperty.AddValueChanged(clip, ClipChanged);
            }
            #endregion
        }