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); }
public PencilToolUI() { ClickDragBehavior.SetIsEnabled(this, true); ClickDragBehavior.SetAllowClick(this, false); base.Cursor = CursorUtil.LoadResource("Cursors.PencilToolCursor.cur"); }
public PaintBucketToolUI() { base.CanvasCursor = CursorUtil.LoadResource("Cursors.PaintBucketToolCursor.cur"); }
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); }
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)); } }