Ejemplo n.º 1
0
 public RotationAnchorResetButton()
 {
     base.Drawing = new ResetButtonDrawing();
     ClickDragBehavior.SetIsEnabled(this, true);
     ClickDragBehavior.SetAllowDrag(this, false);
     ClickDragBehavior.AddIsPressedChangedHandler(this, new RoutedEventHandler(this.OnClickDragBehaviorIsPressedChanged));
 }
Ejemplo n.º 2
0
        private void EnsureShapePropertyControlUpdated(object propertyName)
        {
            PaintDotNet.UI.FrameworkElement element;
            Property property = this.TryGetChanges().ShapePropertySchema[propertyName];

            if (!(property is DoubleVectorProperty))
            {
                throw new InternalErrorException();
            }
            if (!this.propertyNameToControlMap.TryGetValue(propertyName, out element))
            {
                CircleHandleDrawing drawing       = new CircleHandleDrawing();
                HandleElement       handleElement = new HandleElement(drawing);
                handleElement.SetBinding(DrawingElement.ScaleProperty, this, PropertyPathUtil.Combine(ToolUICanvas.CanvasViewProperty, CanvasView.CanvasHairWidthProperty), BindingMode.OneWay);
                handleElement.SetBinding <double, PaintDotNet.UI.Thickness>(DrawingElement.PaddingProperty, this, PropertyPathUtil.Combine(ToolUICanvas.CanvasViewProperty, CanvasView.CanvasHairWidthProperty), BindingMode.OneWay, new Func <double, PaintDotNet.UI.Thickness>(ShapesToolUI.GetHandlePadding));
                handleElement.SetBinding <bool, Cursor>(PaintDotNet.UI.FrameworkElement.CursorProperty, this, new PaintDotNet.ObjectModel.PropertyPath(UIElement.IsMouseCaptureWithinProperty), BindingMode.OneWay, delegate(bool imcw) {
                    if (!imcw)
                    {
                        return(this.handCursor);
                    }
                    return(this.handMouseDownCursor);
                });
                DependencyFunc <ShapesToolChanges, SizeDouble, PointDouble> func = new DependencyFunc <ShapesToolChanges, SizeDouble, PointDouble>((stc, actsz) => GetShapePropertyControlCanvasOffset(propertyName, stc, actsz));
                func.SetArgInput <ShapesToolChanges>(1, this.toolChanges);
                func.SetArgInput(2, handleElement, new PaintDotNet.ObjectModel.PropertyPath(PaintDotNet.UI.FrameworkElement.ActualSizeProperty));
                handleElement.SetBinding(PaintDotNet.UI.Controls.Canvas.LeftProperty, func, new PaintDotNet.ObjectModel.PropertyPath(func.GetValueProperty().Name + ".X", Array.Empty <object>()), BindingMode.OneWay);
                handleElement.SetBinding(PaintDotNet.UI.Controls.Canvas.TopProperty, func, new PaintDotNet.ObjectModel.PropertyPath(func.GetValueProperty().Name + ".Y", Array.Empty <object>()), BindingMode.OneWay);
                DependencyObjectTagger.Set <DependencyFunc <ShapesToolChanges, SizeDouble, PointDouble> >(handleElement, shapePropertyControlCanvasOffsetTagKey, func);
                AnimationStateHelper helper = new AnimationStateHelper {
                    Element = handleElement
                };
                helper.EnableAnimations += delegate(object <sender>, EventArgs <e>) {
                    AnimatedDouble sourceObject = new AnimatedDouble(1.0);
                    handleElement.SetBinding(UIElement.OpacityProperty, sourceObject, new PaintDotNet.ObjectModel.PropertyPath(AnimatedValue <double> .ValuePropertyName, Array.Empty <object>()), BindingMode.OneWay);
                    sourceObject.AnimateRawValue((s, v) => InitializeHandleOpacityStoryboard(s, v, 0.5), null);
                    DependencyObjectTagger.Set <AnimatedDouble>(handleElement, shapePropertyControlOpacityAnimationTagKey, sourceObject);
                };
                helper.DisableAnimations += delegate(object <sender>, EventArgs <e>) {
                    AnimatedDouble num;
                    handleElement.ClearBinding(UIElement.OpacityProperty);
                    if (DependencyObjectTagger.TryGet <AnimatedDouble>(handleElement, shapePropertyControlOpacityAnimationTagKey, out num))
                    {
                        num.StopAnimation();
                        num.Dispose();
                        DependencyObjectTagger.Remove(handleElement, shapePropertyControlOpacityAnimationTagKey);
                    }
                };
                DependencyObjectTagger.Set <AnimationStateHelper>(handleElement, shapePropertyControlOpacityAnimationStateHelperTagKey, helper);
                ClickDragBehavior.SetAllowClick(handleElement, false);
                ClickDragBehavior.SetAllowDoubleClick(handleElement, false);
                ClickDragBehavior.SetAllowDrag(handleElement, true);
                ClickDragBehavior.SetIsEnabled(handleElement, true);
                SetShapePropertyName(handleElement, propertyName);
                SetHandleType(handleElement, ShapesToolHandleType.ShapeProperty);
                base.AddVisualChild(handleElement);
                element = handleElement;
                this.propertyNameToControlMap.Add(propertyName, element);
            }
        }
Ejemplo n.º 3
0
        public MoveToolUI()
        {
            ClickDragBehavior.SetIsEnabled(this, true);
            ClickDragBehavior.SetAllowClick(this, false);
            this.transformControl = new TransformControl();
            this.transformControl.HitTestPadding   = 8.0;
            this.transformControl.BackgroundCursor = Cursors.SizeAll;
            this.transformControl.SetBinding <SizeDouble, double>(FrameworkElement.WidthProperty, this, PropertyPathUtil.Combine(ToolUICanvas.CanvasViewProperty, CanvasView.CanvasSizeProperty), BindingMode.OneWay, s => s.Width);
            this.transformControl.SetBinding <SizeDouble, double>(FrameworkElement.HeightProperty, this, PropertyPathUtil.Combine(ToolUICanvas.CanvasViewProperty, CanvasView.CanvasSizeProperty), BindingMode.OneWay, s => s.Height);
            PropertyPath sourcePath = PropertyPathUtil.Combine(ToolUICanvas.CanvasViewProperty, CanvasView.CanvasHairWidthProperty);

            this.transformControl.SetBinding(TransformControl.HairWidthProperty, this, sourcePath, BindingMode.OneWay);
            this.transformControlVisibility = new DependencyFunc <TransactedToolState, RectDouble, Visibility>(new Func <TransactedToolState, RectDouble, Visibility>(MoveToolUI.GetTransformControlVisibility));
            this.transformControlVisibility.SetArgInput(1, this, new PropertyPath(ToolUICanvas.ToolProperty.Name + ".State", Array.Empty <object>()));
            this.transformControlVisibility.SetArgInput(2, this.transformControl, new PropertyPath(TransformControl.BaseBoundsProperty));
            this.transformControl.SetBinding(UIElement.VisibilityProperty, this.transformControlVisibility, new PropertyPath(this.transformControlVisibility.GetValueProperty().Name, Array.Empty <object>()), BindingMode.OneWay);
            base.Children.Add(this.transformControl);
            this.transformControl.EditingBegin     += new TransformEditingBeginEventHandler(this.OnTransformControlEditingBegin);
            this.transformControl.EditingCancelled += new RoutedEventHandler(this.OnTransformControlEditingCancelled);
            this.transformControl.EditChanged      += new RoutedEventHandler(this.OnTransformControlEditChanged);
            this.transformControl.EditingFinished  += new RoutedEventHandler(this.OnTransformControlEditingFinished);
            base.Loaded += new EventHandler(this.OnLoaded);
        }
Ejemplo n.º 4
0
 public BrushToolUIBase(string canvasMouseCursorUpResName)
 {
     ClickDragBehavior.SetIsEnabled(this, true);
     ClickDragBehavior.SetAllowClick(this, false);
     this.canvasMouseUpCursor = CursorUtil.LoadResource(canvasMouseCursorUpResName);
     this.mouseCenterPt       = new DependencyValue <PointDouble>();
     this.toolState           = new DependencyValue <TransactedToolState>();
     this.toolState.SetBinding(this.toolState.GetValueProperty(), this, new PaintDotNet.ObjectModel.PropertyPath(ToolUICanvas.ToolProperty.Name + ".State", Array.Empty <object>()), BindingMode.OneWay);
     this.toolState.ValueChanged += new ValueChangedEventHandler <TransactedToolState>(this.OnToolStateChanged);
     this.brushPreviewDrawing     = new CircleHandleDrawing();
     this.brushPreviewDrawing.AutoScaleWithDpi = false;
     this.brushPreviewElement = new HandleElement(this.brushPreviewDrawing);
     this.brushPreviewElement.IsHitTestVisible = false;
     this.brushPreviewElement.IsHotOnMouseOver = false;
     this.brushPreviewElementCanvasOffset      = new DependencyFunc <PointDouble, SizeDouble, PointDouble>(new Func <PointDouble, SizeDouble, PointDouble>(BrushToolUIBase <TDerived, TTool, TChanges> .GetHandleCanvasOffset));
     this.brushPreviewElementCanvasOffset.SetArgInput <PointDouble>(1, this.mouseCenterPt);
     this.brushPreviewElementCanvasOffset.SetArgInput(2, this.brushPreviewElement, new PaintDotNet.ObjectModel.PropertyPath(PaintDotNet.UI.FrameworkElement.ActualSizeProperty));
     this.brushPreviewElement.SetBinding(PaintDotNet.UI.Controls.Canvas.LeftProperty, this.brushPreviewElementCanvasOffset, new PaintDotNet.ObjectModel.PropertyPath("Value.X", Array.Empty <object>()), BindingMode.OneWay);
     this.brushPreviewElement.SetBinding(PaintDotNet.UI.Controls.Canvas.TopProperty, this.brushPreviewElementCanvasOffset, new PaintDotNet.ObjectModel.PropertyPath("Value.Y", Array.Empty <object>()), BindingMode.OneWay);
     this.brushPreviewElement.SetBinding(DrawingElement.ScaleProperty, this, PropertyPathUtil.Combine(ToolUICanvas.CanvasViewProperty, CanvasView.CanvasHairWidthProperty), BindingMode.OneWay);
     base.Children.Add(this.brushPreviewElement);
     base.Loaded   += new EventHandler(this.OnLoaded);
     base.Unloaded += new EventHandler(this.OnUnloaded);
 }
Ejemplo n.º 5
0
 public PencilToolUI()
 {
     ClickDragBehavior.SetIsEnabled(this, true);
     ClickDragBehavior.SetAllowClick(this, false);
     base.Cursor = CursorUtil.LoadResource("Cursors.PencilToolCursor.cur");
 }
Ejemplo n.º 6
0
        public FloodFillToolUIBase()
        {
            this.handCursor          = CursorUtil.LoadResource("Cursors.PanToolCursor.cur");
            this.handMouseDownCursor = CursorUtil.LoadResource("Cursors.PanToolCursorMouseDown.cur");
            this.toolState           = new DependencyValue <TransactedToolState>();
            this.toolState.SetBinding(this.toolState.GetValueProperty(), this, new PaintDotNet.ObjectModel.PropertyPath(ToolUICanvas.ToolProperty.Name + ".State", Array.Empty <object>()), BindingMode.OneWay);
            this.toolState.ValueChanged += new ValueChangedEventHandler <TransactedToolState>(this.OnToolStateChanged);
            this.canvasHandle            = new HandleElement();
            this.canvasHandle.Focusable  = true;
            FloodFillToolUIBase <TTool, TChanges> .SetHandleType(this.canvasHandle, FloodFillToolHandleType.Canvas);

            this.canvasHandle.ClipToBounds = false;
            ClickDragBehavior.SetAllowClick(this.canvasHandle, false);
            ClickDragBehavior.SetAllowDrag(this.canvasHandle, true);
            ClickDragBehavior.SetIsEnabled(this.canvasHandle, true);
            this.canvasHandle.SetBinding(PaintDotNet.UI.FrameworkElement.CursorProperty, this, new PaintDotNet.ObjectModel.PropertyPath(FloodFillToolUIBase <TTool, TChanges> .CanvasCursorProperty), BindingMode.OneWay);
            base.Children.Add(this.canvasHandle);
            this.originHandle = new HandleElement();
            FloodFillToolUIBase <TTool, TChanges> .SetHandleType(this.originHandle, FloodFillToolHandleType.Origin);

            ClickDragBehavior.SetAllowClick(this.originHandle, true);
            ClickDragBehavior.SetAllowDrag(this.originHandle, true);
            ClickDragBehavior.SetIsEnabled(this.originHandle, true);
            this.originHandle.SetBinding <TransactedToolState, Visibility>(UIElement.VisibilityProperty, this, new PaintDotNet.ObjectModel.PropertyPath("Tool.State", Array.Empty <object>()), BindingMode.OneWay, new Func <TransactedToolState, Visibility>(FloodFillToolUIBase <TTool, TChanges> .GetHandleVisibility));
            this.originDrawing = new SquareHandleDrawing();
            this.originDrawing.SetBinding <double, double>(HandleDrawing.RadiusProperty, this, PropertyPathUtil.Combine(ToolUICanvas.CanvasViewProperty, CanvasView.CanvasHairWidthProperty), BindingMode.OneWay, hw => (1.0 / hw) / 2.0);
            this.originHandle.Drawing     = this.originDrawing;
            this.originHandleCanvasOffset = new DependencyFunc <PointInt32, SizeDouble, PointDouble>(new Func <PointInt32, SizeDouble, PointDouble>(FloodFillToolUIBase <TTool, TChanges> .GetHandleCanvasOffset));
            this.originHandleCanvasOffset.SetArgInput(1, this, new PaintDotNet.ObjectModel.PropertyPath("Tool.Changes.OriginPointInt32", Array.Empty <object>()));
            this.originHandleCanvasOffset.SetArgInput(2, this.originHandle, new PaintDotNet.ObjectModel.PropertyPath(PaintDotNet.UI.FrameworkElement.ActualSizeProperty.Name, Array.Empty <object>()));
            this.originHandle.SetBinding(PaintDotNet.UI.Controls.Canvas.LeftProperty, this.originHandleCanvasOffset, new PaintDotNet.ObjectModel.PropertyPath("Value.X", Array.Empty <object>()), BindingMode.OneWay);
            this.originHandle.SetBinding(PaintDotNet.UI.Controls.Canvas.TopProperty, this.originHandleCanvasOffset, new PaintDotNet.ObjectModel.PropertyPath("Value.Y", Array.Empty <object>()), BindingMode.OneWay);
            this.originHandle.SetBinding(DrawingElement.ScaleProperty, this, PropertyPathUtil.Combine(ToolUICanvas.CanvasViewProperty, CanvasView.CanvasHairWidthProperty), BindingMode.OneWay);
            this.originHandle.SetBinding <double, PaintDotNet.UI.Thickness>(DrawingElement.PaddingProperty, this, PropertyPathUtil.Combine(ToolUICanvas.CanvasViewProperty, CanvasView.CanvasHairWidthProperty), BindingMode.OneWay, new Func <double, PaintDotNet.UI.Thickness>(FloodFillToolUIBase <TTool, TChanges> .GetHandlePadding));
            this.originHandle.SetBinding <TransactedToolState, Cursor>(PaintDotNet.UI.FrameworkElement.CursorProperty, this, new PaintDotNet.ObjectModel.PropertyPath("Tool.State", Array.Empty <object>()), BindingMode.OneWay, new Func <TransactedToolState, Cursor>(this.GetHandleCursor));
            base.Children.Add(this.originHandle);
            this.moveHandle = new HandleElement(new CompassHandleDrawing());
            FloodFillToolUIBase <TTool, TChanges> .SetHandleType(this.moveHandle, FloodFillToolHandleType.Move);

            ClickDragBehavior.SetAllowClick(this.moveHandle, true);
            ClickDragBehavior.SetAllowDrag(this.moveHandle, true);
            ClickDragBehavior.SetIsEnabled(this.moveHandle, true);
            this.moveHandle.SetBinding <TransactedToolState, Visibility>(UIElement.VisibilityProperty, this, new PaintDotNet.ObjectModel.PropertyPath("Tool.State", Array.Empty <object>()), BindingMode.OneWay, new Func <TransactedToolState, Visibility>(FloodFillToolUIBase <TTool, TChanges> .GetHandleVisibility));
            this.moveHandle.RenderTransformOrigin = new PointDouble(0.5, 0.5);
            this.moveHandleCanvasOffset           = new DependencyFunc <PointInt32, double, SizeDouble, PointDouble>(new Func <PointInt32, double, SizeDouble, PointDouble>(FloodFillToolUIBase <TTool, TChanges> .GetMoveHandleCanvasOffset));
            this.moveHandleCanvasOffset.SetArgInput(1, this, new PaintDotNet.ObjectModel.PropertyPath("Tool.Changes.OriginPointInt32", Array.Empty <object>()));
            this.moveHandleCanvasOffset.SetArgInput(2, this, PropertyPathUtil.Combine(ToolUICanvas.CanvasViewProperty, CanvasView.CanvasHairWidthProperty));
            this.moveHandleCanvasOffset.SetArgInput(3, this.moveHandle, new PaintDotNet.ObjectModel.PropertyPath(PaintDotNet.UI.FrameworkElement.ActualSizeProperty.Name, Array.Empty <object>()));
            this.moveHandle.SetBinding(PaintDotNet.UI.Controls.Canvas.LeftProperty, this.moveHandleCanvasOffset, new PaintDotNet.ObjectModel.PropertyPath("Value.X", Array.Empty <object>()), BindingMode.OneWay);
            this.moveHandle.SetBinding(PaintDotNet.UI.Controls.Canvas.TopProperty, this.moveHandleCanvasOffset, new PaintDotNet.ObjectModel.PropertyPath("Value.Y", Array.Empty <object>()), BindingMode.OneWay);
            this.moveHandle.SetBinding(DrawingElement.ScaleProperty, this, PropertyPathUtil.Combine(ToolUICanvas.CanvasViewProperty, CanvasView.CanvasHairWidthProperty), BindingMode.OneWay);
            this.moveHandle.SetBinding <double, PaintDotNet.UI.Thickness>(DrawingElement.PaddingProperty, this, PropertyPathUtil.Combine(ToolUICanvas.CanvasViewProperty, CanvasView.CanvasHairWidthProperty), BindingMode.OneWay, new Func <double, PaintDotNet.UI.Thickness>(FloodFillToolUIBase <TTool, TChanges> .GetHandlePadding));
            this.moveHandle.SetBinding <TransactedToolState, Cursor>(PaintDotNet.UI.FrameworkElement.CursorProperty, this, new PaintDotNet.ObjectModel.PropertyPath("Tool.State", Array.Empty <object>()), BindingMode.OneWay, new Func <TransactedToolState, Cursor>(this.GetHandleCursor));
            this.moveHandleOpacityHelper                   = new AnimationStateHelper();
            this.moveHandleOpacityHelper.Element           = this.moveHandle;
            this.moveHandleOpacityHelper.EnableAnimations += delegate(object <sender>, EventArgs <e>) {
                base.moveHandleOpacity = new AnimatedDouble(1.0);
                base.moveHandle.SetBinding(UIElement.OpacityProperty, base.moveHandleOpacity, new PaintDotNet.ObjectModel.PropertyPath(AnimatedValue <double> .ValuePropertyName, Array.Empty <object>()), BindingMode.OneWay);
                base.moveHandleOpacity.AnimateRawValue((s, v) => FloodFillToolUIBase <TTool, TChanges> .InitializeHandleOpacityStoryboard(s, v, 0.33333333333333331), null);
            };
            this.moveHandleOpacityHelper.DisableAnimations += delegate(object <sender>, EventArgs <e>) {
                base.moveHandle.ClearBinding(UIElement.OpacityProperty);
                DisposableUtil.Free <AnimatedDouble>(ref this.moveHandleOpacity);
            };
            base.Children.Add(this.moveHandle);
            base.Loaded += new EventHandler(this.OnLoaded);
        }
Ejemplo n.º 7
0
 public ShapesToolUI()
 {
     this.toolChanges.ValueChanged += new ValueChangedEventHandler <ShapesToolChanges>(this.OnToolChangesChanged);
     this.toolChanges.SetBinding(this.toolChanges.GetValueProperty(), this, new PaintDotNet.ObjectModel.PropertyPath(ToolUICanvas.ToolProperty.Name + ".Changes", Array.Empty <object>()), BindingMode.OneWay);
     this.canvasHandle = new HandleElement();
     SetHandleType(this.canvasHandle, ShapesToolHandleType.Canvas);
     this.canvasHandle.Focusable    = true;
     this.canvasHandle.ClipToBounds = false;
     ClickDragBehavior.SetAllowClick(this.canvasHandle, false);
     ClickDragBehavior.SetAllowDrag(this.canvasHandle, true);
     ClickDragBehavior.SetIsEnabled(this.canvasHandle, true);
     this.canvasHandle.SetBinding <bool, Cursor>(PaintDotNet.UI.FrameworkElement.CursorProperty, this, new PaintDotNet.ObjectModel.PropertyPath(UIElement.IsMouseCaptureWithinProperty), BindingMode.OneWay, delegate(bool imcw) {
         if (!imcw)
         {
             return(this.canvasMouseUpCursor);
         }
         return(this.canvasMouseDownCursor);
     });
     this.transformControl = new TransformControl();
     this.transformControl.HitTestPadding = 8.0;
     this.transformControl.SetBinding <TransactedToolState, bool>(TransformControl.AllowBackgroundClickProperty, this, new PaintDotNet.ObjectModel.PropertyPath(ToolUICanvas.ToolProperty.Name + ".State", Array.Empty <object>()), BindingMode.OneWay, new Func <TransactedToolState, bool>(ShapesToolUI.GetTransformControlAllowBackgroundClick));
     this.transformControl.SetBinding <bool, Cursor>(TransformControl.BackgroundCursorProperty, this, new PaintDotNet.ObjectModel.PropertyPath(UIElement.IsMouseCaptureWithinProperty), BindingMode.OneWay, delegate(bool imcw) {
         if (!imcw)
         {
             return(this.canvasMouseUpCursor);
         }
         return(this.canvasMouseDownCursor);
     });
     this.transformControl.SetBinding <SizeDouble, double>(PaintDotNet.UI.FrameworkElement.WidthProperty, this, PropertyPathUtil.Combine(ToolUICanvas.CanvasViewProperty, CanvasView.CanvasSizeProperty), BindingMode.OneWay, s => s.Width);
     this.transformControl.SetBinding <SizeDouble, double>(PaintDotNet.UI.FrameworkElement.HeightProperty, this, PropertyPathUtil.Combine(ToolUICanvas.CanvasViewProperty, CanvasView.CanvasSizeProperty), BindingMode.OneWay, s => s.Height);
     this.transformControl.SetBinding(TransformControl.HairWidthProperty, this, PropertyPathUtil.Combine(ToolUICanvas.CanvasViewProperty, CanvasView.CanvasHairWidthProperty), BindingMode.OneWay);
     this.transformControlVisibility = new DependencyFunc <TransactedToolState, ShapesToolChanges, Visibility>(new Func <TransactedToolState, ShapesToolChanges, Visibility>(ShapesToolUI.GetTransformControlVisibility));
     this.transformControlVisibility.SetArgInput(1, this, new PaintDotNet.ObjectModel.PropertyPath(ToolUICanvas.ToolProperty.Name + ".State", Array.Empty <object>()));
     this.transformControlVisibility.SetArgInput(2, this, new PaintDotNet.ObjectModel.PropertyPath(ToolUICanvas.ToolProperty.Name + ".Changes", Array.Empty <object>()));
     this.transformControl.SetBinding(UIElement.VisibilityProperty, this.transformControlVisibility, new PaintDotNet.ObjectModel.PropertyPath(this.transformControlVisibility.GetValueProperty()), BindingMode.OneWay);
     this.transformControlAreScaleHandlesVisible = new DependencyFunc <TransactedToolState, ShapesToolChanges, bool>(new Func <TransactedToolState, ShapesToolChanges, bool>(ShapesToolUI.GetTransformControlAreScaleHandlesVisible));
     this.transformControlAreScaleHandlesVisible.SetArgInput(1, this, new PaintDotNet.ObjectModel.PropertyPath(ToolUICanvas.ToolProperty.Name + ".State", Array.Empty <object>()));
     this.transformControlAreScaleHandlesVisible.SetArgInput(2, this, new PaintDotNet.ObjectModel.PropertyPath(ToolUICanvas.ToolProperty.Name + ".Changes", Array.Empty <object>()));
     this.transformControl.SetBinding(TransformControl.AreScaleHandlesVisibleProperty, this.transformControlAreScaleHandlesVisible, new PaintDotNet.ObjectModel.PropertyPath(this.transformControlAreScaleHandlesVisible.GetValueProperty()), BindingMode.OneWay);
     this.transformControl.EditingBegin     += new TransformEditingBeginEventHandler(this.OnTransformControlEditingBegin);
     this.transformControl.EditingCancelled += new RoutedEventHandler(this.OnTransformControlEditingCancelled);
     this.transformControl.EditChanged      += new RoutedEventHandler(this.OnTransformControlEditChanged);
     this.transformControl.EditingFinished  += new RoutedEventHandler(this.OnTransformControlEditingFinished);
     this.startEndPointHandleVisibility      = new DependencyFunc <TransactedToolState, ShapesToolChanges, Visibility>(new Func <TransactedToolState, ShapesToolChanges, Visibility>(ShapesToolUI.GetStartEndPointHandleVisibility));
     this.startEndPointHandleVisibility.SetArgInput(1, this, new PaintDotNet.ObjectModel.PropertyPath(ToolUICanvas.ToolProperty.Name + ".State", Array.Empty <object>()));
     this.startEndPointHandleVisibility.SetArgInput(2, this, new PaintDotNet.ObjectModel.PropertyPath(ToolUICanvas.ToolProperty.Name + ".Changes", Array.Empty <object>()));
     this.startPointHandle = new HandleElement(new CircleHandleDrawing());
     ClickDragBehavior.SetAllowClick(this.startPointHandle, false);
     ClickDragBehavior.SetAllowDrag(this.startPointHandle, true);
     ClickDragBehavior.SetIsEnabled(this.startPointHandle, true);
     SetHandleType(this.startPointHandle, ShapesToolHandleType.StartPoint);
     this.startPointHandle.SetBinding(UIElement.VisibilityProperty, this.startEndPointHandleVisibility, new PaintDotNet.ObjectModel.PropertyPath(this.startEndPointHandleVisibility.GetValueProperty()), BindingMode.OneWay);
     this.startPointHandle.SetBinding <bool, Cursor>(PaintDotNet.UI.FrameworkElement.CursorProperty, this, new PaintDotNet.ObjectModel.PropertyPath(UIElement.IsMouseCaptureWithinProperty), BindingMode.OneWay, delegate(bool imcw) {
         if (!imcw)
         {
             return(this.handCursor);
         }
         return(this.handMouseDownCursor);
     });
     this.startPointCanvasOffset = new DependencyFunc <ShapesToolChanges, SizeDouble, PointDouble>((ch, actsz) => GetStartEndPointHandleCanvasOffset(ShapesToolHandleType.StartPoint, ch, actsz));
     this.startPointCanvasOffset.SetArgInput <ShapesToolChanges>(1, this.toolChanges);
     this.startPointCanvasOffset.SetArgInput(2, this.startPointHandle, new PaintDotNet.ObjectModel.PropertyPath(PaintDotNet.UI.FrameworkElement.ActualSizeProperty));
     this.startPointHandle.SetBinding(PaintDotNet.UI.Controls.Canvas.LeftProperty, this.startPointCanvasOffset, new PaintDotNet.ObjectModel.PropertyPath(this.startPointCanvasOffset.GetValueProperty().Name + ".X", Array.Empty <object>()), BindingMode.OneWay);
     this.startPointHandle.SetBinding(PaintDotNet.UI.Controls.Canvas.TopProperty, this.startPointCanvasOffset, new PaintDotNet.ObjectModel.PropertyPath(this.startPointCanvasOffset.GetValueProperty().Name + ".Y", Array.Empty <object>()), BindingMode.OneWay);
     this.startPointHandle.SetBinding(DrawingElement.ScaleProperty, this, PropertyPathUtil.Combine(ToolUICanvas.CanvasViewProperty, CanvasView.CanvasHairWidthProperty), BindingMode.OneWay);
     this.startPointHandle.SetBinding <double, PaintDotNet.UI.Thickness>(DrawingElement.PaddingProperty, this, PropertyPathUtil.Combine(ToolUICanvas.CanvasViewProperty, CanvasView.CanvasHairWidthProperty), BindingMode.OneWay, new Func <double, PaintDotNet.UI.Thickness>(ShapesToolUI.GetHandlePadding));
     this.startPointAnimationHelper                   = new AnimationStateHelper();
     this.startPointAnimationHelper.Element           = this.startPointHandle;
     this.startPointAnimationHelper.EnableAnimations += delegate(object <sender>, EventArgs <e>) {
         this.startPointOpacity = new AnimatedDouble(1.0);
         this.startPointHandle.SetBinding(UIElement.OpacityProperty, this.startPointOpacity, new PaintDotNet.ObjectModel.PropertyPath(AnimatedValue <double> .ValuePropertyName, Array.Empty <object>()), BindingMode.OneWay);
         this.startPointOpacity.AnimateRawValue((s, v) => InitializeHandleOpacityStoryboard(s, v, 0.0), null);
     };
     this.startPointAnimationHelper.DisableAnimations += delegate(object <sender>, EventArgs <e>) {
         this.startPointHandle.ClearBinding(UIElement.OpacityProperty);
         DisposableUtil.Free <AnimatedDouble>(ref this.startPointOpacity);
     };
     this.endPointHandle = new HandleElement(new CircleHandleDrawing());
     ClickDragBehavior.SetAllowClick(this.endPointHandle, false);
     ClickDragBehavior.SetAllowDrag(this.endPointHandle, true);
     ClickDragBehavior.SetIsEnabled(this.endPointHandle, true);
     SetHandleType(this.endPointHandle, ShapesToolHandleType.EndPoint);
     this.endPointHandle.SetBinding(UIElement.VisibilityProperty, this.startEndPointHandleVisibility, new PaintDotNet.ObjectModel.PropertyPath(this.startEndPointHandleVisibility.GetValueProperty()), BindingMode.OneWay);
     this.endPointHandle.SetBinding <bool, Cursor>(PaintDotNet.UI.FrameworkElement.CursorProperty, this, new PaintDotNet.ObjectModel.PropertyPath(UIElement.IsMouseCaptureWithinProperty), BindingMode.OneWay, delegate(bool imcw) {
         if (!imcw)
         {
             return(this.handCursor);
         }
         return(this.handMouseDownCursor);
     });
     this.endPointCanvasOffset = new DependencyFunc <ShapesToolChanges, SizeDouble, PointDouble>((ch, actsz) => GetStartEndPointHandleCanvasOffset(ShapesToolHandleType.EndPoint, ch, actsz));
     this.endPointCanvasOffset.SetArgInput <ShapesToolChanges>(1, this.toolChanges);
     this.endPointCanvasOffset.SetArgInput(2, this.endPointHandle, new PaintDotNet.ObjectModel.PropertyPath(PaintDotNet.UI.FrameworkElement.ActualSizeProperty));
     this.endPointHandle.SetBinding(PaintDotNet.UI.Controls.Canvas.LeftProperty, this.endPointCanvasOffset, new PaintDotNet.ObjectModel.PropertyPath(this.endPointCanvasOffset.GetValueProperty().Name + ".X", Array.Empty <object>()), BindingMode.OneWay);
     this.endPointHandle.SetBinding(PaintDotNet.UI.Controls.Canvas.TopProperty, this.endPointCanvasOffset, new PaintDotNet.ObjectModel.PropertyPath(this.endPointCanvasOffset.GetValueProperty().Name + ".Y", Array.Empty <object>()), BindingMode.OneWay);
     this.endPointHandle.SetBinding(DrawingElement.ScaleProperty, this, PropertyPathUtil.Combine(ToolUICanvas.CanvasViewProperty, CanvasView.CanvasHairWidthProperty), BindingMode.OneWay);
     this.endPointHandle.SetBinding <double, PaintDotNet.UI.Thickness>(DrawingElement.PaddingProperty, this, PropertyPathUtil.Combine(ToolUICanvas.CanvasViewProperty, CanvasView.CanvasHairWidthProperty), BindingMode.OneWay, new Func <double, PaintDotNet.UI.Thickness>(ShapesToolUI.GetHandlePadding));
     this.endPointAnimationHelper                   = new AnimationStateHelper();
     this.endPointAnimationHelper.Element           = this.endPointHandle;
     this.endPointAnimationHelper.EnableAnimations += delegate(object <sender>, EventArgs <e>) {
         this.endPointOpacity = new AnimatedDouble(1.0);
         this.endPointHandle.SetBinding(UIElement.OpacityProperty, this.endPointOpacity, new PaintDotNet.ObjectModel.PropertyPath(AnimatedValue <double> .ValuePropertyName, Array.Empty <object>()), BindingMode.OneWay);
         this.endPointOpacity.AnimateRawValue((s, v) => InitializeHandleOpacityStoryboard(s, v, 0.5), null);
     };
     this.endPointAnimationHelper.DisableAnimations += delegate(object <sender>, EventArgs <e>) {
         this.endPointHandle.ClearBinding(UIElement.OpacityProperty);
         DisposableUtil.Free <AnimatedDouble>(ref this.endPointOpacity);
     };
     base.Children.Add(this.canvasHandle);
     base.Children.Add(this.transformControl);
     base.Children.Add(this.startPointHandle);
     base.Children.Add(this.endPointHandle);
     base.Loaded   += new EventHandler(this.OnLoaded);
     base.Unloaded += new EventHandler(this.OnUnloaded);
 }
Ejemplo n.º 8
0
 public GradientToolUI()
 {
     SetHandleType(this.canvasHandle, GradientToolHandleType.Canvas);
     this.canvasHandle.ClipToBounds = false;
     ClickDragBehavior.SetAllowClick(this.canvasHandle, false);
     this.startHandle = new HandleElement(new CircleHandleDrawing());
     SetHandleType(this.startHandle, GradientToolHandleType.Start);
     this.startHandle.SetBinding <TransactedToolState, Visibility>(UIElement.VisibilityProperty, this, new PaintDotNet.ObjectModel.PropertyPath("Tool.State", Array.Empty <object>()), BindingMode.OneWay, new Func <TransactedToolState, Visibility>(GradientToolUI.GetHandleVisibility));
     this.startHandleCanvasOffset = new DependencyFunc <PointDouble, SizeDouble, PointDouble>(new Func <PointDouble, SizeDouble, PointDouble>(GradientToolUI.GetHandleCanvasOffset));
     this.startHandleCanvasOffset.SetArgInput(1, this, new PaintDotNet.ObjectModel.PropertyPath("Tool.Changes.GradientStartPoint", Array.Empty <object>()));
     this.startHandleCanvasOffset.SetArgInput(2, this.startHandle, new PaintDotNet.ObjectModel.PropertyPath(PaintDotNet.UI.FrameworkElement.ActualSizeProperty.Name, Array.Empty <object>()));
     this.startHandle.SetBinding(PaintDotNet.UI.Controls.Canvas.LeftProperty, this.startHandleCanvasOffset, new PaintDotNet.ObjectModel.PropertyPath("Value.X", Array.Empty <object>()), BindingMode.OneWay);
     this.startHandle.SetBinding(PaintDotNet.UI.Controls.Canvas.TopProperty, this.startHandleCanvasOffset, new PaintDotNet.ObjectModel.PropertyPath("Value.Y", Array.Empty <object>()), BindingMode.OneWay);
     this.startHandle.SetBinding(DrawingElement.ScaleProperty, this, PropertyPathUtil.Combine(ToolUICanvas.CanvasViewProperty, CanvasView.CanvasHairWidthProperty), BindingMode.OneWay);
     this.startHandle.SetBinding <double, PaintDotNet.UI.Thickness>(DrawingElement.PaddingProperty, this, PropertyPathUtil.Combine(ToolUICanvas.CanvasViewProperty, CanvasView.CanvasHairWidthProperty), BindingMode.OneWay, new Func <double, PaintDotNet.UI.Thickness>(GradientToolUI.GetHandlePadding));
     this.startHandleOpacityHelper                   = new AnimationStateHelper();
     this.startHandleOpacityHelper.Element           = this.startHandle;
     this.startHandleOpacityHelper.EnableAnimations += delegate(object <sender>, EventArgs <e>) {
         this.startHandleOpacity = new AnimatedDouble(1.0);
         this.startHandle.SetBinding(UIElement.OpacityProperty, this.startHandleOpacity, new PaintDotNet.ObjectModel.PropertyPath(AnimatedValue <double> .ValuePropertyName, Array.Empty <object>()), BindingMode.OneWay);
         this.startHandleOpacity.AnimateRawValue((s, v) => InitializeHandleOpacityStoryboard(s, v, 0.0), null);
     };
     this.startHandleOpacityHelper.DisableAnimations += delegate(object <sender>, EventArgs <e>) {
         this.startHandle.ClearBinding(UIElement.OpacityProperty);
         DisposableUtil.Free <AnimatedDouble>(ref this.startHandleOpacity);
     };
     this.endHandle = new HandleElement(new CircleHandleDrawing());
     SetHandleType(this.endHandle, GradientToolHandleType.End);
     this.endHandle.SetBinding <TransactedToolState, Visibility>(UIElement.VisibilityProperty, this, new PaintDotNet.ObjectModel.PropertyPath("Tool.State", Array.Empty <object>()), BindingMode.OneWay, new Func <TransactedToolState, Visibility>(GradientToolUI.GetHandleVisibility));
     this.endHandleCanvasOffset = new DependencyFunc <PointDouble, SizeDouble, PointDouble>(new Func <PointDouble, SizeDouble, PointDouble>(GradientToolUI.GetHandleCanvasOffset));
     this.endHandleCanvasOffset.SetArgInput(1, this, new PaintDotNet.ObjectModel.PropertyPath("Tool.Changes.GradientEndPoint", Array.Empty <object>()));
     this.endHandleCanvasOffset.SetArgInput(2, this.endHandle, new PaintDotNet.ObjectModel.PropertyPath(PaintDotNet.UI.FrameworkElement.ActualSizeProperty.Name, Array.Empty <object>()));
     this.endHandle.SetBinding(PaintDotNet.UI.Controls.Canvas.LeftProperty, this.endHandleCanvasOffset, new PaintDotNet.ObjectModel.PropertyPath("Value.X", Array.Empty <object>()), BindingMode.OneWay);
     this.endHandle.SetBinding(PaintDotNet.UI.Controls.Canvas.TopProperty, this.endHandleCanvasOffset, new PaintDotNet.ObjectModel.PropertyPath("Value.Y", Array.Empty <object>()), BindingMode.OneWay);
     this.endHandle.SetBinding(DrawingElement.ScaleProperty, this, PropertyPathUtil.Combine(ToolUICanvas.CanvasViewProperty, CanvasView.CanvasHairWidthProperty), BindingMode.OneWay);
     this.endHandle.SetBinding <double, PaintDotNet.UI.Thickness>(DrawingElement.PaddingProperty, this, PropertyPathUtil.Combine(ToolUICanvas.CanvasViewProperty, CanvasView.CanvasHairWidthProperty), BindingMode.OneWay, new Func <double, PaintDotNet.UI.Thickness>(GradientToolUI.GetHandlePadding));
     this.endHandleOpacityHelper                   = new AnimationStateHelper();
     this.endHandleOpacityHelper.Element           = this.endHandle;
     this.endHandleOpacityHelper.EnableAnimations += delegate(object <sender>, EventArgs <e>) {
         this.endHandleOpacity = new AnimatedDouble(1.0);
         this.endHandle.SetBinding(UIElement.OpacityProperty, this.endHandleOpacity, new PaintDotNet.ObjectModel.PropertyPath(AnimatedValue <double> .ValuePropertyName, Array.Empty <object>()), BindingMode.OneWay);
         this.endHandleOpacity.AnimateRawValue((s, v) => InitializeHandleOpacityStoryboard(s, v, 0.33333333333333331), null);
     };
     this.endHandleOpacityHelper.DisableAnimations += delegate(object <sender>, EventArgs <e>) {
         this.endHandle.ClearBinding(UIElement.OpacityProperty);
         DisposableUtil.Free <AnimatedDouble>(ref this.endHandleOpacity);
     };
     this.moveHandle = new HandleElement(new CompassHandleDrawing());
     SetHandleType(this.moveHandle, GradientToolHandleType.Move);
     this.moveHandle.SetBinding <TransactedToolState, Visibility>(UIElement.VisibilityProperty, this, new PaintDotNet.ObjectModel.PropertyPath("Tool.State", Array.Empty <object>()), BindingMode.OneWay, new Func <TransactedToolState, Visibility>(GradientToolUI.GetHandleVisibility));
     this.moveHandle.RenderTransformOrigin = new PointDouble(0.5, 0.5);
     this.moveHandleCanvasOffset           = new DependencyFunc <PointDouble, PointDouble, double, SizeDouble, PointDouble>(new Func <PointDouble, PointDouble, double, SizeDouble, PointDouble>(GradientToolUI.GetMoveHandleCanvasOffset));
     this.moveHandleCanvasOffset.SetArgInput(1, this, new PaintDotNet.ObjectModel.PropertyPath("Tool.Changes.GradientStartPoint", Array.Empty <object>()));
     this.moveHandleCanvasOffset.SetArgInput(2, this, new PaintDotNet.ObjectModel.PropertyPath("Tool.Changes.GradientEndPoint", Array.Empty <object>()));
     this.moveHandleCanvasOffset.SetArgInput(3, this, PropertyPathUtil.Combine(ToolUICanvas.CanvasViewProperty, CanvasView.CanvasHairWidthProperty));
     this.moveHandleCanvasOffset.SetArgInput(4, this.moveHandle, new PaintDotNet.ObjectModel.PropertyPath(PaintDotNet.UI.FrameworkElement.ActualSizeProperty.Name, Array.Empty <object>()));
     this.moveHandle.SetBinding(PaintDotNet.UI.Controls.Canvas.LeftProperty, this.moveHandleCanvasOffset, new PaintDotNet.ObjectModel.PropertyPath("Value.X", Array.Empty <object>()), BindingMode.OneWay);
     this.moveHandle.SetBinding(PaintDotNet.UI.Controls.Canvas.TopProperty, this.moveHandleCanvasOffset, new PaintDotNet.ObjectModel.PropertyPath("Value.Y", Array.Empty <object>()), BindingMode.OneWay);
     this.moveHandle.SetBinding(DrawingElement.ScaleProperty, this, PropertyPathUtil.Combine(ToolUICanvas.CanvasViewProperty, CanvasView.CanvasHairWidthProperty), BindingMode.OneWay);
     this.moveHandle.SetBinding <double, PaintDotNet.UI.Thickness>(DrawingElement.PaddingProperty, this, PropertyPathUtil.Combine(ToolUICanvas.CanvasViewProperty, CanvasView.CanvasHairWidthProperty), BindingMode.OneWay, new Func <double, PaintDotNet.UI.Thickness>(GradientToolUI.GetHandlePadding));
     this.moveHandleOpacityHelper                   = new AnimationStateHelper();
     this.moveHandleOpacityHelper.Element           = this.moveHandle;
     this.moveHandleOpacityHelper.EnableAnimations += delegate(object <sender>, EventArgs <e>) {
         this.moveHandleOpacity = new AnimatedDouble(1.0);
         this.moveHandle.SetBinding(UIElement.OpacityProperty, this.moveHandleOpacity, new PaintDotNet.ObjectModel.PropertyPath(AnimatedValue <double> .ValuePropertyName, Array.Empty <object>()), BindingMode.OneWay);
         this.moveHandleOpacity.AnimateRawValue((s, v) => InitializeHandleOpacityStoryboard(s, v, 0.66666666666666663), null);
     };
     this.moveHandleOpacityHelper.DisableAnimations += delegate(object <sender>, EventArgs <e>) {
         this.moveHandle.ClearBinding(UIElement.OpacityProperty);
         DisposableUtil.Free <AnimatedDouble>(ref this.moveHandleOpacity);
     };
     this.handles = new HandleElement[] { this.canvasHandle, this.startHandle, this.endHandle, this.moveHandle };
     foreach (HandleElement element in this.handles)
     {
         ClickDragBehavior.SetIsEnabled(element, true);
         base.Children.Add(element);
     }
     this.handCursor               = CursorUtil.LoadResource("Cursors.PanToolCursor.cur");
     this.handMouseDownCursor      = CursorUtil.LoadResource("Cursors.PanToolCursorMouseDown.cur");
     this.crosshairCursor          = CursorUtil.LoadResource("Cursors.GenericToolCursor.cur");
     this.crosshairMouseDownCursor = CursorUtil.LoadResource("Cursors.GenericToolCursorMouseDown.cur");
     this.canvasHandle.Cursor      = this.crosshairCursor;
     for (int i = 1; i < this.handles.Length; i++)
     {
         this.handles[i].SetBinding <TransactedToolState, Cursor>(PaintDotNet.UI.FrameworkElement.CursorProperty, this, new PaintDotNet.ObjectModel.PropertyPath("Tool.State", Array.Empty <object>()), BindingMode.OneWay, new Func <TransactedToolState, Cursor>(this.GetHandleCursor));
     }
 }