mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-23 09:56:36 +08:00
支持画笔及痕迹擦除,为白板做准备
This commit is contained in:
@@ -66,5 +66,9 @@
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="ViewModels\DrawingViewModel\Fillable\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,191 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
using AIStudio.Wpf.DiagramDesigner.ViewModels;
|
||||
using AIStudio.Wpf.DiagramDesigner.ViewModels.BaseViewModel;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class DrawingRubberbandAdorner : Adorner
|
||||
{
|
||||
private Brush _rubberbandBrush;
|
||||
private Pen _rubberbandPen;
|
||||
|
||||
private DesignerCanvas _designerCanvas;
|
||||
|
||||
private IDiagramViewModel _viewModel
|
||||
{
|
||||
get
|
||||
{
|
||||
return _designerCanvas.DataContext as IDiagramViewModel;
|
||||
}
|
||||
}
|
||||
private IDiagramServiceProvider _service
|
||||
{
|
||||
get
|
||||
{
|
||||
return DiagramServicesProvider.Instance.Provider;
|
||||
}
|
||||
}
|
||||
|
||||
private DrawMode DrawMode
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_viewModel.DrawModeViewModel != null)
|
||||
{
|
||||
return _viewModel.DrawModeViewModel.GetDrawMode();
|
||||
}
|
||||
else
|
||||
{
|
||||
return _service.DrawModeViewModel.GetDrawMode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private DrawingDesignerItemViewModelBase _drawingDesignerItem;
|
||||
public DrawingRubberbandAdorner(DesignerCanvas designerCanvas, Point dragStartPoint)
|
||||
: base(designerCanvas)
|
||||
{
|
||||
this._designerCanvas = designerCanvas;
|
||||
this._designerCanvas.Focus();
|
||||
|
||||
if (DrawMode == DrawMode.Eraser)
|
||||
{
|
||||
_drawingDesignerItem = new EraserDrawingDesignerItemViewModel(_viewModel, dragStartPoint);
|
||||
|
||||
_rubberbandBrush = new SolidColorBrush(Colors.Red) { Opacity = 0.5 };
|
||||
_rubberbandPen = new Pen(new SolidColorBrush(Colors.Red) { Opacity = 0.5 }, _drawingDesignerItem.ColorViewModel.LineWidth);
|
||||
}
|
||||
else if (DrawMode >= DrawMode.Line && DrawMode <= DrawMode.DirectLine)
|
||||
{
|
||||
if (DrawMode == DrawMode.Line)
|
||||
{
|
||||
_drawingDesignerItem = new LineDrawingDesignerItemViewModel(_viewModel, dragStartPoint, true);
|
||||
}
|
||||
else if (DrawMode == DrawMode.Rectangle)
|
||||
{
|
||||
_drawingDesignerItem = new RectangleDrawingDesignerItemViewModel(_viewModel, dragStartPoint, true);
|
||||
}
|
||||
else if (DrawMode == DrawMode.Ellipse)
|
||||
{
|
||||
_drawingDesignerItem = new EllipseDrawingDesignerItemViewModel(_viewModel, dragStartPoint, true);
|
||||
}
|
||||
else if (DrawMode == DrawMode.Polyline)
|
||||
{
|
||||
_drawingDesignerItem = new PolylineDrawingDesignerItemViewModel(_viewModel, dragStartPoint, true);
|
||||
}
|
||||
else if (DrawMode == DrawMode.Polygon)
|
||||
{
|
||||
_drawingDesignerItem = new PolygonDrawingDesignerItemViewModel(_viewModel, dragStartPoint, true);
|
||||
}
|
||||
else if (DrawMode == DrawMode.DirectLine)
|
||||
{
|
||||
_drawingDesignerItem = new DirectLineDrawingDesignerItemViewModel(_viewModel, dragStartPoint, true);
|
||||
}
|
||||
|
||||
_rubberbandBrush = null;//ColorObject.ToBrush(_drawingDesignerItem.ColorViewModel.FillColor);
|
||||
_rubberbandPen = new Pen(ColorObject.ToBrush(_drawingDesignerItem.ColorViewModel.LineColor), _drawingDesignerItem.ColorViewModel.LineWidth);
|
||||
_rubberbandPen.DashStyle = new DashStyle(StrokeDashArray.Dash[(int)_drawingDesignerItem.ColorViewModel.LineDashStyle], 1);
|
||||
}
|
||||
else if (DrawMode >= DrawMode.FillableLine && DrawMode <= DrawMode.FillableDirectLine)
|
||||
{
|
||||
if (DrawMode == DrawMode.FillableLine)
|
||||
{
|
||||
_drawingDesignerItem = new LineDrawingDesignerItemViewModel(_viewModel, dragStartPoint, false);
|
||||
}
|
||||
else if (DrawMode == DrawMode.FillableRectangle)
|
||||
{
|
||||
_drawingDesignerItem = new RectangleDrawingDesignerItemViewModel(_viewModel, dragStartPoint, false);
|
||||
}
|
||||
else if (DrawMode == DrawMode.FillableEllipse)
|
||||
{
|
||||
_drawingDesignerItem = new EllipseDrawingDesignerItemViewModel(_viewModel, dragStartPoint, false);
|
||||
}
|
||||
else if (DrawMode == DrawMode.FillablePolyline)
|
||||
{
|
||||
_drawingDesignerItem = new PolylineDrawingDesignerItemViewModel(_viewModel, dragStartPoint, false);
|
||||
}
|
||||
else if (DrawMode == DrawMode.FillablePolygon)
|
||||
{
|
||||
_drawingDesignerItem = new PolygonDrawingDesignerItemViewModel(_viewModel, dragStartPoint, false);
|
||||
}
|
||||
else if (DrawMode == DrawMode.FillableDirectLine)
|
||||
{
|
||||
_drawingDesignerItem = new DirectLineDrawingDesignerItemViewModel(_viewModel, dragStartPoint, false);
|
||||
}
|
||||
|
||||
_rubberbandBrush = ColorObject.ToBrush(_drawingDesignerItem.ColorViewModel.FillColor);
|
||||
_rubberbandPen = new Pen(ColorObject.ToBrush(_drawingDesignerItem.ColorViewModel.LineColor), _drawingDesignerItem.ColorViewModel.LineWidth);
|
||||
_rubberbandPen.DashStyle = new DashStyle(StrokeDashArray.Dash[(int)_drawingDesignerItem.ColorViewModel.LineDashStyle], 1);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseMove(System.Windows.Input.MouseEventArgs e)
|
||||
{
|
||||
if (_drawingDesignerItem.OnMouseMove(this, e) == true)
|
||||
{
|
||||
if (!this.IsMouseCaptured)
|
||||
this.CaptureMouse();
|
||||
|
||||
this.InvalidateVisual();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.IsMouseCaptured) this.ReleaseMouseCapture();
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
protected override void OnMouseUp(System.Windows.Input.MouseButtonEventArgs e)
|
||||
{
|
||||
if (_drawingDesignerItem.OnMouseUp(this, e) == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// release mouse capture
|
||||
if (this.IsMouseCaptured) this.ReleaseMouseCapture();
|
||||
|
||||
// remove this adorner from adorner layer
|
||||
AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(this._designerCanvas);
|
||||
if (adornerLayer != null)
|
||||
adornerLayer.Remove(this);
|
||||
|
||||
if (_drawingDesignerItem.IsFinish == true)
|
||||
{
|
||||
_viewModel.AddItemCommand.Execute(_drawingDesignerItem);
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
protected override void OnMouseDown(MouseButtonEventArgs e)
|
||||
{
|
||||
_drawingDesignerItem.OnMouseDown(this, e);
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
protected override void OnRender(DrawingContext dc)
|
||||
{
|
||||
base.OnRender(dc);
|
||||
|
||||
// without a background the OnMouseMove event would not be fired !
|
||||
// Alternative: implement a Canvas as a child of this adorner, like
|
||||
// the ConnectionAdorner does.
|
||||
dc.DrawRectangle(Brushes.Transparent, null, new Rect(RenderSize));
|
||||
|
||||
dc.DrawGeometry(_rubberbandBrush, _rubberbandPen, _drawingDesignerItem.Geometry);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
using System.Windows;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using AIStudio.Wpf.DiagramDesigner.ViewModels;
|
||||
using AIStudio.Wpf.DiagramDesigner.ViewModels.BaseViewModel;
|
||||
using System.Windows.Threading;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
@@ -16,7 +16,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
private Point? startPoint;
|
||||
private Point? endPoint;
|
||||
private List<Point> pointList = new List<Point>();
|
||||
private List<Point> pointList = new List<Point>();
|
||||
private Pen rubberbandPen;
|
||||
|
||||
private DesignerCanvas _designerCanvas;
|
||||
@@ -43,6 +43,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
this._designerCanvas.Focus();
|
||||
this.startPoint = dragStartPoint;
|
||||
rubberbandPen = new Pen(Brushes.LightSlateGray, 1);
|
||||
|
||||
rubberbandPen.DashStyle = new DashStyle(new double[] { 2 }, 1);
|
||||
}
|
||||
|
||||
@@ -54,33 +55,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
this.CaptureMouse();
|
||||
|
||||
endPoint = e.GetPosition(this);
|
||||
if (this._service.DrawModeViewModel.GetDrawMode() == DrawMode.Polyline)
|
||||
{
|
||||
if (pointList.Count == 0 && this.startPoint.HasValue)
|
||||
{
|
||||
pointList.Add(this.startPoint.Value);
|
||||
}
|
||||
//点不需要保存的太密集了
|
||||
if ((endPoint.Value - pointList.Last()).Length >= 1)
|
||||
{
|
||||
pointList.Add(endPoint.Value);
|
||||
}
|
||||
}
|
||||
|
||||
UpdateSelection();
|
||||
this.InvalidateVisual();
|
||||
}
|
||||
else if (this._service.DrawModeViewModel.GetDrawMode() == DrawMode.DirectLine)
|
||||
{
|
||||
if (!this.IsMouseCaptured)
|
||||
this.CaptureMouse();
|
||||
|
||||
endPoint = e.GetPosition(this);
|
||||
|
||||
if (pointList.Count == 0 && this.startPoint.HasValue)
|
||||
{
|
||||
pointList.Add(this.startPoint.Value);
|
||||
}
|
||||
|
||||
UpdateSelection();
|
||||
this.InvalidateVisual();
|
||||
@@ -95,25 +69,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
protected override void OnMouseUp(System.Windows.Input.MouseButtonEventArgs e)
|
||||
{
|
||||
if (this._service.DrawModeViewModel.GetDrawMode() == DrawMode.DirectLine && e.ChangedButton == MouseButton.Left)
|
||||
{
|
||||
//按着ctrl自动封闭曲线
|
||||
if (Keyboard.IsKeyDown(Key.LeftCtrl) == true || Keyboard.IsKeyDown(Key.RightCtrl) == true)
|
||||
{
|
||||
pointList.Add(this.startPoint.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
endPoint = e.GetPosition(this);
|
||||
pointList.Add(endPoint.Value);
|
||||
|
||||
UpdateSelection();
|
||||
this.InvalidateVisual();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// release mouse capture
|
||||
if (this.IsMouseCaptured) this.ReleaseMouseCapture();
|
||||
|
||||
@@ -122,13 +77,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
if (adornerLayer != null)
|
||||
adornerLayer.Remove(this);
|
||||
|
||||
if (this._service.DrawModeViewModel.GetDrawMode() == DrawMode.Line ||
|
||||
this._service.DrawModeViewModel.GetDrawMode() == DrawMode.Rectangle ||
|
||||
this._service.DrawModeViewModel.GetDrawMode() == DrawMode.Ellipse ||
|
||||
this._service.DrawModeViewModel.GetDrawMode() == DrawMode.Polyline ||
|
||||
this._service.DrawModeViewModel.GetDrawMode() == DrawMode.Polygon ||
|
||||
this._service.DrawModeViewModel.GetDrawMode() == DrawMode.DirectLine ||
|
||||
this._service.DrawModeViewModel.GetDrawMode() == DrawMode.Text)
|
||||
if (this._service.DrawModeViewModel.GetDrawMode() == DrawMode.Text)
|
||||
{
|
||||
if (this.startPoint.HasValue && this.endPoint.HasValue)
|
||||
{
|
||||
@@ -143,18 +92,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
_viewModel.AddItemCommand.Execute(itemBase);
|
||||
}
|
||||
else if (this._service.DrawModeViewModel.GetDrawMode() == DrawMode.Polyline
|
||||
|| this._service.DrawModeViewModel.GetDrawMode() == DrawMode.Polygon
|
||||
|| this._service.DrawModeViewModel.GetDrawMode() == DrawMode.DirectLine)
|
||||
{
|
||||
ShapeDesignerItemViewModel itemBase = new ShapeDesignerItemViewModel(this._service.DrawModeViewModel.GetDrawMode(), pointList);
|
||||
_viewModel.AddItemCommand.Execute(itemBase);
|
||||
}
|
||||
else
|
||||
{
|
||||
ShapeDesignerItemViewModel itemBase = new ShapeDesignerItemViewModel(this._service.DrawModeViewModel.GetDrawMode(), new List<Point> { this.startPoint.Value, this.endPoint.Value });
|
||||
_viewModel.AddItemCommand.Execute(itemBase);
|
||||
}
|
||||
}
|
||||
this._service.DrawModeViewModel.ResetDrawMode();
|
||||
}
|
||||
@@ -173,45 +110,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
if (this.startPoint.HasValue && this.endPoint.HasValue)
|
||||
{
|
||||
if (this._service.DrawModeViewModel.GetDrawMode() == DrawMode.Line)
|
||||
{
|
||||
dc.DrawLine(rubberbandPen, this.startPoint.Value, this.endPoint.Value);
|
||||
}
|
||||
else if (this._service.DrawModeViewModel.GetDrawMode() == DrawMode.Ellipse)
|
||||
{
|
||||
var centerPoint = new Point((this.startPoint.Value.X + this.endPoint.Value.X) / 2, (this.startPoint.Value.Y + this.endPoint.Value.Y) / 2);
|
||||
dc.DrawEllipse(Brushes.Transparent, rubberbandPen, centerPoint, Math.Abs(this.startPoint.Value.X - this.endPoint.Value.X) / 2, Math.Abs(this.startPoint.Value.Y - this.endPoint.Value.Y) / 2);
|
||||
}
|
||||
else if (_service.DrawModeViewModel.GetDrawMode() == DrawMode.Polyline)
|
||||
{
|
||||
var disList = pointList.ToList();
|
||||
for (int i = 1; i < pointList.Count; i++)
|
||||
{
|
||||
dc.DrawLine(rubberbandPen, disList[i - 1], disList[i]);
|
||||
}
|
||||
}
|
||||
else if (_service.DrawModeViewModel.GetDrawMode() == DrawMode.DirectLine)
|
||||
{
|
||||
var disList = pointList.ToList();
|
||||
//按着ctrl自动封闭曲线
|
||||
if (Keyboard.IsKeyDown(Key.LeftCtrl) == true || Keyboard.IsKeyDown(Key.RightCtrl) == true)
|
||||
{
|
||||
disList.Add(this.startPoint.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
disList.Add(this.endPoint.Value);
|
||||
}
|
||||
|
||||
for (int i = 1; i < disList.Count; i++)
|
||||
{
|
||||
dc.DrawLine(rubberbandPen, disList[i - 1], disList[i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dc.DrawRectangle(Brushes.Transparent, rubberbandPen, new Rect(this.startPoint.Value, this.endPoint.Value));
|
||||
}
|
||||
dc.DrawRectangle(Brushes.Transparent, rubberbandPen, new Rect(this.startPoint.Value, this.endPoint.Value));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -121,36 +121,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
private bool EnableSnapping
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_viewModel.DrawModeViewModel != null)
|
||||
{
|
||||
return _viewModel.DrawModeViewModel.EnableSnapping;
|
||||
}
|
||||
else
|
||||
{
|
||||
return _service.DrawModeViewModel.EnableSnapping;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private double SnappingRadius
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_viewModel.DrawModeViewModel != null)
|
||||
{
|
||||
return _viewModel.DrawModeViewModel.SnappingRadius;
|
||||
}
|
||||
else
|
||||
{
|
||||
return _service.DrawModeViewModel.SnappingRadius;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region GridCellSize
|
||||
|
||||
public static readonly DependencyProperty GridCellSizeProperty =
|
||||
@@ -390,6 +360,19 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
SourceConnector = new Connector() { Content = new PartCreatedConnectorInfo(currentPoint.X, currentPoint.Y), Tag = "虚拟的连接点" };
|
||||
}
|
||||
}
|
||||
else if (_service.DrawModeViewModel.DrawingDrawModeSelected)
|
||||
{
|
||||
// create rubberband adorner
|
||||
AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(this);
|
||||
if (adornerLayer != null)
|
||||
{
|
||||
DrawingRubberbandAdorner adorner = new DrawingRubberbandAdorner(this, currentPoint);
|
||||
if (adorner != null)
|
||||
{
|
||||
adornerLayer.Add(adorner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
@@ -433,7 +416,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
SinkConnector.Info.DisableAttachTo = true;
|
||||
}
|
||||
|
||||
if (EnableSnapping)
|
||||
if (_viewModel.DiagramOption.SnappingOption.EnableSnapping)
|
||||
{
|
||||
var nearPort = _viewModel.FindNearPortToAttachTo(partialConnection);
|
||||
if (nearPort != null)
|
||||
@@ -510,10 +493,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
SinkConnector = null;
|
||||
partialConnection = null;
|
||||
|
||||
if (_service.DrawModeViewModel.GetDrawMode() != DrawMode.DirectLine)
|
||||
{
|
||||
_service.DrawModeViewModel.ResetDrawMode();
|
||||
}
|
||||
_service.DrawModeViewModel.ResetDrawMode();
|
||||
}
|
||||
|
||||
protected override void OnPreviewKeyDown(KeyEventArgs e)
|
||||
@@ -657,6 +637,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
e.Handled = true;
|
||||
|
||||
this.Focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,175 +22,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
else if (value is ColorObject colorObject)
|
||||
{
|
||||
if (colorObject.BrushType == BrushType.None)
|
||||
brush = new SolidColorBrush(Colors.Transparent);
|
||||
else if (colorObject.BrushType == BrushType.SolidColorBrush)
|
||||
brush = new SolidColorBrush(colorObject.Color);
|
||||
else if (colorObject.BrushType == BrushType.LinearGradientBrush)
|
||||
{
|
||||
Point startPoint;
|
||||
Point endPoint;
|
||||
if (colorObject.LinearOrientation == LinearOrientation.LeftToRight)
|
||||
{
|
||||
startPoint = new Point(0, 0.5);
|
||||
endPoint = new Point(1, 0.5);
|
||||
}
|
||||
else if (colorObject.LinearOrientation == LinearOrientation.LeftTopToRightBottom)
|
||||
{
|
||||
startPoint = new Point(0, 0);
|
||||
endPoint = new Point(1, 1);
|
||||
}
|
||||
else if (colorObject.LinearOrientation == LinearOrientation.TopToBottom)
|
||||
{
|
||||
startPoint = new Point(0.5, 0);
|
||||
endPoint = new Point(0.5, 1);
|
||||
}
|
||||
else if (colorObject.LinearOrientation == LinearOrientation.RightTopToLeftBottom)
|
||||
{
|
||||
startPoint = new Point(1, 0);
|
||||
endPoint = new Point(0, 1);
|
||||
}
|
||||
else if (colorObject.LinearOrientation == LinearOrientation.RightToLeft)
|
||||
{
|
||||
startPoint = new Point(1, 0.5);
|
||||
endPoint = new Point(0, 0.5);
|
||||
}
|
||||
else if (colorObject.LinearOrientation == LinearOrientation.RightBottomToLeftTop)
|
||||
{
|
||||
startPoint = new Point(1, 1);
|
||||
endPoint = new Point(0, 0);
|
||||
}
|
||||
else if (colorObject.LinearOrientation == LinearOrientation.BottomToTop)
|
||||
{
|
||||
startPoint = new Point(0.5, 1);
|
||||
endPoint = new Point(0.5, 0);
|
||||
}
|
||||
else if (colorObject.LinearOrientation == LinearOrientation.LeftBottomToRightTop)
|
||||
{
|
||||
startPoint = new Point(0, 1);
|
||||
endPoint = new Point(1, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
startPoint = new Point(0, 0.5);
|
||||
endPoint = new Point(1, 0.5);
|
||||
}
|
||||
|
||||
LinearGradientBrush myBrush = new LinearGradientBrush();
|
||||
myBrush.StartPoint = startPoint;
|
||||
myBrush.EndPoint = endPoint;
|
||||
if (colorObject.GradientStop != null)
|
||||
{
|
||||
foreach (var stop in colorObject.GradientStop)
|
||||
{
|
||||
myBrush.GradientStops.Add(new System.Windows.Media.GradientStop(stop.Color, stop.Offset));
|
||||
}
|
||||
}
|
||||
brush = myBrush;
|
||||
|
||||
RotateTransform rotateTransform = new RotateTransform(colorObject.Angle, 0.5, 0.5);
|
||||
myBrush.RelativeTransform = rotateTransform;
|
||||
}
|
||||
else if (colorObject.BrushType == BrushType.RadialGradientBrush)
|
||||
{
|
||||
Point center;
|
||||
Point gradientOrigin;
|
||||
double radiusX;
|
||||
double radiusY;
|
||||
|
||||
if (colorObject.RadialOrientation == RadialOrientation.LeftTop)
|
||||
{
|
||||
center = new Point(0, 0);
|
||||
gradientOrigin = center;
|
||||
radiusX = 1;
|
||||
radiusY = 1;
|
||||
}
|
||||
else if (colorObject.RadialOrientation == RadialOrientation.RightTop)
|
||||
{
|
||||
center = new Point(1, 0);
|
||||
gradientOrigin = center;
|
||||
radiusX = 1;
|
||||
radiusY = 1;
|
||||
}
|
||||
else if (colorObject.RadialOrientation == RadialOrientation.RightBottom)
|
||||
{
|
||||
center = new Point(1, 1);
|
||||
gradientOrigin = center;
|
||||
radiusX = 1;
|
||||
radiusY = 1;
|
||||
}
|
||||
else if (colorObject.RadialOrientation == RadialOrientation.LeftBottom)
|
||||
{
|
||||
center = new Point(0, 1);
|
||||
gradientOrigin = center;
|
||||
radiusX = 1;
|
||||
radiusY = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
center = new Point(0.5, 0.5);
|
||||
gradientOrigin = center;
|
||||
radiusX = 0.5;
|
||||
radiusY = 0.5;
|
||||
}
|
||||
|
||||
RadialGradientBrush myBrush = new RadialGradientBrush();
|
||||
myBrush.Center = center;
|
||||
myBrush.GradientOrigin = gradientOrigin;
|
||||
myBrush.RadiusX = radiusX;
|
||||
myBrush.RadiusY = radiusY;
|
||||
if (colorObject.GradientStop != null)
|
||||
{
|
||||
foreach (var stop in colorObject.GradientStop)
|
||||
{
|
||||
myBrush.GradientStops.Add(new System.Windows.Media.GradientStop(stop.Color, stop.Offset));
|
||||
}
|
||||
}
|
||||
brush = myBrush;
|
||||
|
||||
RotateTransform rotateTransform = new RotateTransform(colorObject.Angle, 0.5, 0.5);
|
||||
myBrush.RelativeTransform = rotateTransform;
|
||||
}
|
||||
else if (colorObject.BrushType == BrushType.ImageBrush)
|
||||
{
|
||||
ImageBrush myBrush = new ImageBrush();
|
||||
myBrush.ImageSource = new BitmapImage(new Uri(colorObject.Image, UriKind.Absolute));
|
||||
brush = myBrush;
|
||||
}
|
||||
else if (colorObject.BrushType == BrushType.DrawingBrush)
|
||||
{
|
||||
DrawingBrush myBrush = new DrawingBrush();
|
||||
|
||||
GeometryDrawing backgroundSquare =
|
||||
new GeometryDrawing(
|
||||
Brushes.White,
|
||||
null,
|
||||
new RectangleGeometry(new Rect(0, 0, 100, 100)));
|
||||
|
||||
GeometryGroup aGeometryGroup = new GeometryGroup();
|
||||
aGeometryGroup.Children.Add(new RectangleGeometry(new Rect(0, 0, 50, 50)));
|
||||
aGeometryGroup.Children.Add(new RectangleGeometry(new Rect(50, 50, 50, 50)));
|
||||
|
||||
LinearGradientBrush checkerBrush = new LinearGradientBrush();
|
||||
checkerBrush.GradientStops.Add(new System.Windows.Media.GradientStop(Colors.Black, 0.0));
|
||||
checkerBrush.GradientStops.Add(new System.Windows.Media.GradientStop(Colors.Gray, 1.0));
|
||||
|
||||
GeometryDrawing checkers = new GeometryDrawing(checkerBrush, null, aGeometryGroup);
|
||||
|
||||
DrawingGroup checkersDrawingGroup = new DrawingGroup();
|
||||
checkersDrawingGroup.Children.Add(backgroundSquare);
|
||||
checkersDrawingGroup.Children.Add(checkers);
|
||||
|
||||
myBrush.Drawing = checkersDrawingGroup;
|
||||
myBrush.Viewport = new Rect(0, 0, 0.25, 0.25);
|
||||
myBrush.TileMode = TileMode.Tile;
|
||||
|
||||
brush = myBrush;
|
||||
}
|
||||
if (brush != null)
|
||||
{
|
||||
brush.Opacity = colorObject.Opacity;
|
||||
}
|
||||
brush = ColorObject.ToBrush(colorObject);
|
||||
}
|
||||
else if (value is ObservableCollection<GradientStop> gradientStop)
|
||||
{
|
||||
|
||||
27
AIStudio.Wpf.DiagramDesigner/Converters/NegativeConverter.cs
Normal file
27
AIStudio.Wpf.DiagramDesigner/Converters/NegativeConverter.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class NegativeConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
if (value is double)
|
||||
{
|
||||
return 0 - (double)value;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,17 +6,26 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public enum DrawMode
|
||||
{
|
||||
Normal = 0,
|
||||
Line = 1,
|
||||
Rectangle = 2,
|
||||
Ellipse = 3,
|
||||
Polyline = 4,
|
||||
Polygon = 5,
|
||||
DirectLine = 6,
|
||||
Normal = 0,
|
||||
ConnectingLineSmooth = 10,
|
||||
ConnectingLineStraight = 11,
|
||||
ConnectingLineCorner = 12,
|
||||
ConnectingLineBoundary = 13,
|
||||
Text = 20,
|
||||
ConnectingLineBoundary = 13,
|
||||
//101-110为可部分擦除的形状
|
||||
Eraser = 100,
|
||||
Line = 101,
|
||||
Rectangle = 102,
|
||||
Ellipse = 103,
|
||||
Polyline = 104,
|
||||
Polygon = 105,
|
||||
DirectLine = 106,
|
||||
//不可部分擦除
|
||||
FillableLine = 111,
|
||||
FillableRectangle = 112,
|
||||
FillableEllipse = 113,
|
||||
FillablePolyline = 114,
|
||||
FillablePolygon = 115,
|
||||
FillableDirectLine = 116,
|
||||
Text = 200,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
|
||||
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
|
||||
<dd:ColorBrushConverter x:Key="ColorBrushConverter" />
|
||||
<dd:ClipConverter x:Key="ClipConverter"/>
|
||||
|
||||
<dd:ClipConverter x:Key="ClipConverter"/>
|
||||
<dd:NegativeConverter x:Key="NegativeConverter"/>
|
||||
|
||||
<DataTemplate DataType="{x:Type dd:DefaultDesignerItemViewModel}">
|
||||
<Grid IsHitTestVisible="False">
|
||||
<Rectangle StrokeThickness="1" Fill="{Binding ColorViewModel.FillColor,Converter={StaticResource ColorBrushConverter}}" Stroke="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}" />
|
||||
@@ -25,102 +26,36 @@
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type dd:ShapeDesignerItemViewModel}">
|
||||
<Grid IsHitTestVisible="False" Background="White">
|
||||
<Grid.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="显示点" IsCheckable="True" IsChecked="{Binding ShowConnectors}" />
|
||||
</ContextMenu>
|
||||
</Grid.ContextMenu>
|
||||
<DataTemplate DataType="{x:Type dd:DrawingDesignerItemViewModelBase}">
|
||||
<Grid IsHitTestVisible="False">
|
||||
<Control x:Name="control" />
|
||||
</Grid>
|
||||
<DataTemplate.Triggers>
|
||||
<DataTrigger Binding="{Binding DrawMode}" Value="Line">
|
||||
<DataTrigger Binding="{Binding Erasable}" Value="True">
|
||||
<Setter TargetName="control" Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate>
|
||||
<Line X1="{Binding ConnectionPoints[0].X}" Y1="{Binding ConnectionPoints[0].Y}"
|
||||
X2="{Binding ConnectionPoints[1].X}" Y2="{Binding ConnectionPoints[1].Y}"
|
||||
Stroke="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}"
|
||||
StrokeThickness="{Binding ColorViewModel.LineWidth}"
|
||||
Stretch="Fill"></Line>
|
||||
<Path Fill="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}"
|
||||
Data="{Binding Geometry}">
|
||||
</Path>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding DrawMode}" Value="Rectangle">
|
||||
<DataTrigger Binding="{Binding Erasable}" Value="False">
|
||||
<Setter TargetName="control" Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate>
|
||||
<Rectangle
|
||||
Stroke="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}"
|
||||
StrokeThickness="{Binding ColorViewModel.LineWidth}"
|
||||
Fill="{Binding ColorViewModel.FillColor,Converter={StaticResource ColorBrushConverter}}"
|
||||
Stretch="Fill"></Rectangle>
|
||||
<Path StrokeThickness="{Binding ColorViewModel.LineWidth}"
|
||||
StrokeDashArray="{Binding ColorViewModel.LineDashStyle,Converter={StaticResource LineDashConverter}}"
|
||||
Stroke="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}"
|
||||
Fill="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}"
|
||||
Data="{Binding Geometry}">
|
||||
</Path>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding DrawMode}" Value="Ellipse">
|
||||
<Setter TargetName="control" Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate>
|
||||
<Ellipse
|
||||
Stroke="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}"
|
||||
StrokeThickness="{Binding ColorViewModel.LineWidth}"
|
||||
Fill="{Binding ColorViewModel.FillColor,Converter={StaticResource ColorBrushConverter}}"
|
||||
Stretch="Fill"></Ellipse>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding DrawMode}" Value="Polyline">
|
||||
<Setter TargetName="control" Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate>
|
||||
<Polyline
|
||||
Points="{Binding ConnectionPoints, Converter={x:Static dd:ConnectionPointConverter.Instance}}"
|
||||
Stroke="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}"
|
||||
StrokeThickness="{Binding ColorViewModel.LineWidth}"
|
||||
Fill="{Binding ColorViewModel.FillColor,Converter={StaticResource ColorBrushConverter}}"
|
||||
FillRule="Nonzero"
|
||||
Stretch="Fill"></Polyline>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding DrawMode}" Value="Polygon">
|
||||
<Setter TargetName="control" Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate>
|
||||
<Polygon
|
||||
Points="{Binding ConnectionPoints, Converter={x:Static dd:ConnectionPointConverter.Instance}}"
|
||||
Stroke="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}"
|
||||
StrokeThickness="{Binding ColorViewModel.LineWidth}"
|
||||
Fill="{Binding ColorViewModel.FillColor,Converter={StaticResource ColorBrushConverter}}"
|
||||
FillRule="Nonzero"
|
||||
Stretch="Fill"></Polygon>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding DrawMode}" Value="DirectLine">
|
||||
<Setter TargetName="control" Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate>
|
||||
<Polyline
|
||||
Points="{Binding ConnectionPoints, Converter={x:Static dd:ConnectionPointConverter.Instance}}"
|
||||
Stroke="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}"
|
||||
StrokeThickness="{Binding ColorViewModel.LineWidth}"
|
||||
Fill="{Binding ColorViewModel.FillColor,Converter={StaticResource ColorBrushConverter}}"
|
||||
FillRule="Nonzero"
|
||||
Stretch="Fill"></Polyline>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</DataTrigger>
|
||||
|
||||
|
||||
</DataTemplate.Triggers>
|
||||
</DataTemplate>
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ using System.Threading;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
@@ -126,7 +127,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
RaisePropertyChanged(nameof(LineWidth));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private LineDashStyle _lineDashStyle = LineDashStyle.None;
|
||||
[CanDo]
|
||||
@@ -221,8 +222,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
set
|
||||
{
|
||||
var xx = this.GetHashCode();
|
||||
var yy = Thread.CurrentThread.ManagedThreadId.ToString();
|
||||
SetProperty(ref _color, value);
|
||||
}
|
||||
}
|
||||
@@ -391,8 +390,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
get
|
||||
{
|
||||
return new SimpleCommand(para =>
|
||||
{
|
||||
return new SimpleCommand(para => {
|
||||
var offset = GradientStop.Skip(GradientStop.Count - 2).Select(p => p.Offset).Average();
|
||||
GradientStop.Add(new GradientStop(Colors.Gray, offset));
|
||||
});
|
||||
@@ -402,8 +400,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
get
|
||||
{
|
||||
return new SimpleCommand(para =>
|
||||
{
|
||||
return new SimpleCommand(para => {
|
||||
if (SelectedGradientStop != null && GradientStop != null && GradientStop.Count > 2)
|
||||
{
|
||||
GradientStop.Remove(SelectedGradientStop);
|
||||
@@ -411,21 +408,231 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static Brush ToBrush(IColorObject colorObject)
|
||||
{
|
||||
Brush brush = null;
|
||||
|
||||
if (colorObject.BrushType == BrushType.None)
|
||||
brush = new SolidColorBrush(Colors.Transparent);
|
||||
else if (colorObject.BrushType == BrushType.SolidColorBrush)
|
||||
brush = new SolidColorBrush(colorObject.Color);
|
||||
else if (colorObject.BrushType == BrushType.LinearGradientBrush)
|
||||
{
|
||||
Point startPoint;
|
||||
Point endPoint;
|
||||
if (colorObject.LinearOrientation == LinearOrientation.LeftToRight)
|
||||
{
|
||||
startPoint = new Point(0, 0.5);
|
||||
endPoint = new Point(1, 0.5);
|
||||
}
|
||||
else if (colorObject.LinearOrientation == LinearOrientation.LeftTopToRightBottom)
|
||||
{
|
||||
startPoint = new Point(0, 0);
|
||||
endPoint = new Point(1, 1);
|
||||
}
|
||||
else if (colorObject.LinearOrientation == LinearOrientation.TopToBottom)
|
||||
{
|
||||
startPoint = new Point(0.5, 0);
|
||||
endPoint = new Point(0.5, 1);
|
||||
}
|
||||
else if (colorObject.LinearOrientation == LinearOrientation.RightTopToLeftBottom)
|
||||
{
|
||||
startPoint = new Point(1, 0);
|
||||
endPoint = new Point(0, 1);
|
||||
}
|
||||
else if (colorObject.LinearOrientation == LinearOrientation.RightToLeft)
|
||||
{
|
||||
startPoint = new Point(1, 0.5);
|
||||
endPoint = new Point(0, 0.5);
|
||||
}
|
||||
else if (colorObject.LinearOrientation == LinearOrientation.RightBottomToLeftTop)
|
||||
{
|
||||
startPoint = new Point(1, 1);
|
||||
endPoint = new Point(0, 0);
|
||||
}
|
||||
else if (colorObject.LinearOrientation == LinearOrientation.BottomToTop)
|
||||
{
|
||||
startPoint = new Point(0.5, 1);
|
||||
endPoint = new Point(0.5, 0);
|
||||
}
|
||||
else if (colorObject.LinearOrientation == LinearOrientation.LeftBottomToRightTop)
|
||||
{
|
||||
startPoint = new Point(0, 1);
|
||||
endPoint = new Point(1, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
startPoint = new Point(0, 0.5);
|
||||
endPoint = new Point(1, 0.5);
|
||||
}
|
||||
|
||||
LinearGradientBrush myBrush = new LinearGradientBrush();
|
||||
myBrush.StartPoint = startPoint;
|
||||
myBrush.EndPoint = endPoint;
|
||||
if (colorObject.GradientStop != null)
|
||||
{
|
||||
foreach (var stop in colorObject.GradientStop)
|
||||
{
|
||||
myBrush.GradientStops.Add(new System.Windows.Media.GradientStop(stop.Color, stop.Offset));
|
||||
}
|
||||
}
|
||||
brush = myBrush;
|
||||
|
||||
RotateTransform rotateTransform = new RotateTransform(colorObject.Angle, 0.5, 0.5);
|
||||
myBrush.RelativeTransform = rotateTransform;
|
||||
}
|
||||
else if (colorObject.BrushType == BrushType.RadialGradientBrush)
|
||||
{
|
||||
Point center;
|
||||
Point gradientOrigin;
|
||||
double radiusX;
|
||||
double radiusY;
|
||||
|
||||
if (colorObject.RadialOrientation == RadialOrientation.LeftTop)
|
||||
{
|
||||
center = new Point(0, 0);
|
||||
gradientOrigin = center;
|
||||
radiusX = 1;
|
||||
radiusY = 1;
|
||||
}
|
||||
else if (colorObject.RadialOrientation == RadialOrientation.RightTop)
|
||||
{
|
||||
center = new Point(1, 0);
|
||||
gradientOrigin = center;
|
||||
radiusX = 1;
|
||||
radiusY = 1;
|
||||
}
|
||||
else if (colorObject.RadialOrientation == RadialOrientation.RightBottom)
|
||||
{
|
||||
center = new Point(1, 1);
|
||||
gradientOrigin = center;
|
||||
radiusX = 1;
|
||||
radiusY = 1;
|
||||
}
|
||||
else if (colorObject.RadialOrientation == RadialOrientation.LeftBottom)
|
||||
{
|
||||
center = new Point(0, 1);
|
||||
gradientOrigin = center;
|
||||
radiusX = 1;
|
||||
radiusY = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
center = new Point(0.5, 0.5);
|
||||
gradientOrigin = center;
|
||||
radiusX = 0.5;
|
||||
radiusY = 0.5;
|
||||
}
|
||||
|
||||
RadialGradientBrush myBrush = new RadialGradientBrush();
|
||||
myBrush.Center = center;
|
||||
myBrush.GradientOrigin = gradientOrigin;
|
||||
myBrush.RadiusX = radiusX;
|
||||
myBrush.RadiusY = radiusY;
|
||||
if (colorObject.GradientStop != null)
|
||||
{
|
||||
foreach (var stop in colorObject.GradientStop)
|
||||
{
|
||||
myBrush.GradientStops.Add(new System.Windows.Media.GradientStop(stop.Color, stop.Offset));
|
||||
}
|
||||
}
|
||||
brush = myBrush;
|
||||
|
||||
RotateTransform rotateTransform = new RotateTransform(colorObject.Angle, 0.5, 0.5);
|
||||
myBrush.RelativeTransform = rotateTransform;
|
||||
}
|
||||
else if (colorObject.BrushType == BrushType.ImageBrush)
|
||||
{
|
||||
ImageBrush myBrush = new ImageBrush();
|
||||
myBrush.ImageSource = new BitmapImage(new Uri(colorObject.Image, UriKind.Absolute));
|
||||
brush = myBrush;
|
||||
}
|
||||
else if (colorObject.BrushType == BrushType.DrawingBrush)
|
||||
{
|
||||
DrawingBrush myBrush = new DrawingBrush();
|
||||
|
||||
GeometryDrawing backgroundSquare =
|
||||
new GeometryDrawing(
|
||||
Brushes.White,
|
||||
null,
|
||||
new RectangleGeometry(new Rect(0, 0, 100, 100)));
|
||||
|
||||
GeometryGroup aGeometryGroup = new GeometryGroup();
|
||||
aGeometryGroup.Children.Add(new RectangleGeometry(new Rect(0, 0, 50, 50)));
|
||||
aGeometryGroup.Children.Add(new RectangleGeometry(new Rect(50, 50, 50, 50)));
|
||||
|
||||
LinearGradientBrush checkerBrush = new LinearGradientBrush();
|
||||
checkerBrush.GradientStops.Add(new System.Windows.Media.GradientStop(Colors.Black, 0.0));
|
||||
checkerBrush.GradientStops.Add(new System.Windows.Media.GradientStop(Colors.Gray, 1.0));
|
||||
|
||||
GeometryDrawing checkers = new GeometryDrawing(checkerBrush, null, aGeometryGroup);
|
||||
|
||||
DrawingGroup checkersDrawingGroup = new DrawingGroup();
|
||||
checkersDrawingGroup.Children.Add(backgroundSquare);
|
||||
checkersDrawingGroup.Children.Add(checkers);
|
||||
|
||||
myBrush.Drawing = checkersDrawingGroup;
|
||||
myBrush.Viewport = new Rect(0, 0, 0.25, 0.25);
|
||||
myBrush.TileMode = TileMode.Tile;
|
||||
|
||||
brush = myBrush;
|
||||
}
|
||||
if (brush != null)
|
||||
{
|
||||
brush.Opacity = colorObject.Opacity;
|
||||
}
|
||||
|
||||
return brush;
|
||||
}
|
||||
}
|
||||
|
||||
public interface IColorObject
|
||||
{
|
||||
BrushType BrushType { get; set; }
|
||||
Color Color { get; set; }
|
||||
ObservableCollection<GradientStop> GradientStop { get; set; }
|
||||
Point StartPoint { get; set; }
|
||||
Point EndPoint { get; set; }
|
||||
double Opacity { get; set; }
|
||||
LinearOrientation LinearOrientation { get; set; }
|
||||
RadialOrientation RadialOrientation { get; set; }
|
||||
int Angle { get; set; }
|
||||
string Image { get; set; }
|
||||
int SubType { get; set; }
|
||||
BrushType BrushType
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
Color Color
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
ObservableCollection<GradientStop> GradientStop
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
Point StartPoint
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
Point EndPoint
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
double Opacity
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
LinearOrientation LinearOrientation
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
RadialOrientation RadialOrientation
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
int Angle
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
string Image
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
int SubType
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
}
|
||||
|
||||
public class GradientStop : BindableBase
|
||||
|
||||
@@ -16,9 +16,9 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
return LineDrawMode;
|
||||
}
|
||||
else if (ShapeDrawModeSelected)
|
||||
else if (DrawingDrawModeSelected)
|
||||
{
|
||||
return ShapeDrawMode;
|
||||
return DrawingDrawMode;
|
||||
}
|
||||
else if (TextDrawModeSelected)
|
||||
{
|
||||
@@ -80,7 +80,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
|
||||
private bool _shapeDrawModeSelected;
|
||||
public bool ShapeDrawModeSelected
|
||||
public bool DrawingDrawModeSelected
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -147,7 +147,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
|
||||
private DrawMode _shapeDrawMode = DrawMode.Rectangle;
|
||||
public DrawMode ShapeDrawMode
|
||||
public DrawMode DrawingDrawMode
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -156,7 +156,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
set
|
||||
{
|
||||
SetProperty(ref _shapeDrawMode, value);
|
||||
ShapeDrawModeSelected = true;
|
||||
DrawingDrawModeSelected = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,33 +185,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
SetProperty(ref _cursorMode, value);
|
||||
}
|
||||
}
|
||||
|
||||
private bool _enableSnapping;
|
||||
public bool EnableSnapping
|
||||
{
|
||||
get
|
||||
{
|
||||
return _enableSnapping;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _enableSnapping, value);
|
||||
}
|
||||
}
|
||||
|
||||
private double _snappingRadius = 50;
|
||||
public double SnappingRadius
|
||||
{
|
||||
get
|
||||
{
|
||||
return _snappingRadius;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _snappingRadius, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,19 +41,11 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
bool ShapeDrawModeSelected
|
||||
bool DrawingDrawModeSelected
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
DrawMode ShapeDrawMode
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
bool EnableSnapping
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
double SnappingRadius
|
||||
DrawMode DrawingDrawMode
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
@@ -148,22 +148,22 @@ namespace AIStudio.Wpf.DiagramDesigner.ViewModels.BaseViewModel
|
||||
get; set;
|
||||
}
|
||||
|
||||
private SelectableDesignerItemViewModelBase _selectedItem;
|
||||
private SelectableDesignerItemViewModelBase _selectedItemViewModel;
|
||||
public SelectableDesignerItemViewModelBase SelectedItemViewModel
|
||||
{
|
||||
get
|
||||
{
|
||||
return _selectedItem;
|
||||
return _selectedItemViewModel;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_selectedItem != null)
|
||||
if (_selectedItemViewModel != null)
|
||||
{
|
||||
_selectedItem.PropertyChanged -= ViewModel_PropertyChanged;
|
||||
_selectedItemViewModel.PropertyChanged -= ViewModel_PropertyChanged;
|
||||
}
|
||||
if (SetProperty(ref _selectedItem, value))
|
||||
if (SetProperty(ref _selectedItemViewModel, value))
|
||||
{
|
||||
if (_selectedItem == null)
|
||||
if (_selectedItemViewModel == null)
|
||||
{
|
||||
ColorViewModel = GetOldValue<ColorViewModel>(nameof(ColorViewModel));
|
||||
FontViewModel = GetOldValue<FontViewModel>(nameof(FontViewModel));
|
||||
@@ -173,16 +173,16 @@ namespace AIStudio.Wpf.DiagramDesigner.ViewModels.BaseViewModel
|
||||
}
|
||||
else
|
||||
{
|
||||
ColorViewModel = _selectedItem.ColorViewModel;
|
||||
FontViewModel = _selectedItem.FontViewModel;
|
||||
ShapeViewModel = _selectedItem.ShapeViewModel;
|
||||
AnimationViewModel = _selectedItem.AnimationViewModel;
|
||||
LockObjectViewModel = _selectedItem.LockObjectViewModel;
|
||||
ColorViewModel = _selectedItemViewModel.ColorViewModel;
|
||||
FontViewModel = _selectedItemViewModel.FontViewModel;
|
||||
ShapeViewModel = _selectedItemViewModel.ShapeViewModel;
|
||||
AnimationViewModel = _selectedItemViewModel.AnimationViewModel;
|
||||
LockObjectViewModel = _selectedItemViewModel.LockObjectViewModel;
|
||||
}
|
||||
}
|
||||
if (_selectedItem != null)
|
||||
if (_selectedItemViewModel != null)
|
||||
{
|
||||
_selectedItem.PropertyChanged += ViewModel_PropertyChanged;
|
||||
_selectedItemViewModel.PropertyChanged += ViewModel_PropertyChanged;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._editCommand ?? (this._editCommand = new SimpleCommand(Command_Enable, ExecuteSelectItemCommand));
|
||||
return this._selectItemCommand ?? (this._selectItemCommand = new SimpleCommand(Command_Enable, ExecuteSelectItemCommand));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -192,6 +192,10 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsHitTestVisible == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return _isSelected;
|
||||
}
|
||||
set
|
||||
|
||||
@@ -1,116 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class ShapeDesignerItemViewModel : DesignerItemViewModelBase
|
||||
{
|
||||
public ShapeDesignerItemViewModel() : this(null)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public ShapeDesignerItemViewModel(IDiagramViewModel root) : base(root)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
public ShapeDesignerItemViewModel(DrawMode drawMode, List<Point> points) : this(null, drawMode, points)
|
||||
{
|
||||
}
|
||||
|
||||
public ShapeDesignerItemViewModel(IDiagramViewModel root, DrawMode drawMode, List<Point> points) : base(root)
|
||||
{
|
||||
DrawMode = drawMode;
|
||||
ConnectionPoints = points;
|
||||
|
||||
ItemWidth = ConnectionPoints.Max(p => p.X) - ConnectionPoints.Min(p => p.X);
|
||||
ItemHeight = ConnectionPoints.Max(p => p.Y) - ConnectionPoints.Min(p => p.Y);
|
||||
Left = ConnectionPoints.Min(p => p.X);
|
||||
Top = ConnectionPoints.Min(p => p.Y);
|
||||
}
|
||||
|
||||
private List<Point> _connectionPoints;
|
||||
public List<Point> ConnectionPoints
|
||||
{
|
||||
get
|
||||
{
|
||||
return _connectionPoints;
|
||||
}
|
||||
private set
|
||||
{
|
||||
SetProperty(ref _connectionPoints, value);
|
||||
}
|
||||
}
|
||||
public DrawMode DrawMode
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
private bool _showConnectors = false;
|
||||
public new bool ShowConnectors
|
||||
{
|
||||
get
|
||||
{
|
||||
return _showConnectors;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _showConnectors, value))
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ICommand MenuItemCommand
|
||||
{
|
||||
get; private set;
|
||||
}
|
||||
|
||||
private void UpdatePoints()
|
||||
{
|
||||
ItemWidth = ConnectionPoints.Max(p => p.X) - ConnectionPoints.Min(p => p.X);
|
||||
ItemHeight = ConnectionPoints.Max(p => p.Y) - ConnectionPoints.Min(p => p.Y);
|
||||
Left = ConnectionPoints.Min(p => p.X);
|
||||
Top = ConnectionPoints.Min(p => p.Y);
|
||||
}
|
||||
|
||||
protected override void Init(IDiagramViewModel root, bool initNew)
|
||||
{
|
||||
MenuItemCommand = new SimpleCommand(Command_Enable, ExecuteMenuItemCommand);
|
||||
base.Init(root, initNew);
|
||||
|
||||
BuildMenuOptions();
|
||||
}
|
||||
|
||||
protected override void InitNew()
|
||||
{
|
||||
this.ClearConnectors();
|
||||
}
|
||||
|
||||
private void ExecuteMenuItemCommand(object obj)
|
||||
{
|
||||
ShowConnectors = (obj as CinchMenuItem).IsChecked;
|
||||
}
|
||||
|
||||
private void BuildMenuOptions()
|
||||
{
|
||||
menuOptions = new ObservableCollection<CinchMenuItem>();
|
||||
CinchMenuItem menuItem = new CinchMenuItem();
|
||||
menuItem.Text = "显示点";
|
||||
menuItem.IsCheckable = true;
|
||||
menuItem.Command = MenuItemCommand;
|
||||
menuItem.CommandParameter = menuItem;
|
||||
menuOptions.Add(menuItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Media3D;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class DirectLineDrawingDesignerItemViewModel : DrawingDesignerItemViewModelBase
|
||||
{
|
||||
public DirectLineDrawingDesignerItemViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
public DirectLineDrawingDesignerItemViewModel(IDiagramViewModel root) : base(root)
|
||||
{
|
||||
}
|
||||
|
||||
public DirectLineDrawingDesignerItemViewModel(IDiagramViewModel root, Point startPoint, bool erasable) : base(root, DrawMode.DirectLine, startPoint, erasable)
|
||||
{
|
||||
}
|
||||
|
||||
public DirectLineDrawingDesignerItemViewModel(IDiagramViewModel root, List<Point> points, bool erasable) : base(root, DrawMode.DirectLine, points, erasable)
|
||||
{
|
||||
}
|
||||
|
||||
public override bool OnMouseMove(IInputElement sender, MouseEventArgs e)
|
||||
{
|
||||
var point = e.GetPosition(sender);
|
||||
if (Points == null || Points.Count == 0)//没有起始点
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((Points.LastOrDefault() - point).Length < ColorViewModel.LineWidth)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//按着LeftShift自动封闭曲线
|
||||
if (Keyboard.IsKeyDown(Key.LeftShift) == true)
|
||||
{
|
||||
point = Points[0];
|
||||
}
|
||||
|
||||
if (Geometry is PathGeometry geometry)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
geometry = new PathGeometry();
|
||||
var figure = new PathFigure { StartPoint = Points[0] };
|
||||
geometry.Figures.Add(figure);
|
||||
}
|
||||
|
||||
LineSegment arc = new LineSegment(point, true);
|
||||
|
||||
var preLine = geometry.Figures[0].Segments.LastOrDefault();
|
||||
if (preLine != _lastLine)
|
||||
{
|
||||
geometry.Figures[0].Segments.Remove(preLine);
|
||||
}
|
||||
geometry.Figures[0].Segments.Add(arc);
|
||||
Geometry = geometry;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private LineSegment _lastLine;
|
||||
public override bool OnMouseDown(IInputElement sender, MouseButtonEventArgs e)
|
||||
{
|
||||
//左键添加点
|
||||
if (e.ChangedButton == MouseButton.Left)
|
||||
{
|
||||
var point = e.GetPosition(sender);
|
||||
if (Points == null || Points.Count == 0)//没有起始点
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((Points.LastOrDefault() - point).Length < ColorViewModel.LineWidth)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
//按着LeftShift自动封闭曲线
|
||||
if (Keyboard.IsKeyDown(Key.LeftShift) == true)
|
||||
{
|
||||
point = Points[0];
|
||||
}
|
||||
Points.Add(point);
|
||||
|
||||
if (Geometry is PathGeometry geometry)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
geometry = new PathGeometry();
|
||||
var figure = new PathFigure { StartPoint = Points[0] };
|
||||
geometry.Figures.Add(figure);
|
||||
}
|
||||
|
||||
var preLine = geometry.Figures[0].Segments.LastOrDefault();
|
||||
if (preLine != _lastLine)
|
||||
{
|
||||
geometry.Figures[0].Segments.Remove(preLine);
|
||||
}
|
||||
|
||||
_lastLine = new LineSegment(point, true);
|
||||
geometry.Figures[0].Segments.Add(_lastLine);
|
||||
Geometry = geometry;
|
||||
|
||||
IsFinish = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool OnMouseUp(IInputElement sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (e.ChangedButton == MouseButton.Left && Keyboard.IsKeyDown(Key.LeftShift) == false)//按着LeftShift自动封闭曲线
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Geometry is PathGeometry geometry)
|
||||
{
|
||||
var preLine = geometry.Figures[0].Segments.LastOrDefault();
|
||||
if (preLine != _lastLine)
|
||||
{
|
||||
geometry.Figures[0].Segments.Remove(preLine);
|
||||
}
|
||||
|
||||
_lastLine = null;
|
||||
Geometry = geometry;
|
||||
}
|
||||
return base.OnMouseUp(sender, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Media3D;
|
||||
using System.Windows.Shapes;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class DrawingDesignerItemViewModelBase : DesignerItemViewModelBase
|
||||
{
|
||||
public DrawingDesignerItemViewModelBase() : this(null)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public DrawingDesignerItemViewModelBase(IDiagramViewModel root) : base(root)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public DrawingDesignerItemViewModelBase(IDiagramViewModel root, DrawMode drawMode, Point startPoint, bool erasable) : this(root, drawMode, new List<Point> { startPoint }, erasable)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public DrawingDesignerItemViewModelBase(IDiagramViewModel root, DrawMode drawMode, List<Point> points, bool erasable) : base(root)
|
||||
{
|
||||
DrawMode = drawMode;
|
||||
Points = points;
|
||||
Erasable = erasable;
|
||||
}
|
||||
|
||||
public virtual bool OnMouseMove(IInputElement sender, MouseEventArgs e)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual bool OnMouseDown(IInputElement sender, MouseButtonEventArgs e)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual bool OnMouseUp(IInputElement sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (IsFinish)
|
||||
{
|
||||
UpdateLocation();
|
||||
|
||||
Geometry.Transform = new TranslateTransform(0 - Left, 0 - Top);
|
||||
|
||||
if (Erasable)
|
||||
{
|
||||
var aPen = new Pen(ColorObject.ToBrush(ColorViewModel.LineColor), ColorViewModel.LineWidth);
|
||||
Geometry = Geometry.GetWidenedPathGeometry(aPen); //可擦除,需要把Geometry转成几何图像,所以不能有填充色
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual bool Erase(Geometry erase)
|
||||
{
|
||||
if (Erasable)
|
||||
{
|
||||
erase.Transform = new TranslateTransform(0 - Left, 0 - Top);
|
||||
Geometry = Geometry.Combine(Geometry, erase, GeometryCombineMode.Exclude, null);
|
||||
|
||||
if (Geometry.IsEmpty())
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//var area = erase.GetArea();
|
||||
//if (area > 10)
|
||||
//{
|
||||
return true;
|
||||
//}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Erasable
|
||||
{
|
||||
get;set;
|
||||
}
|
||||
|
||||
private Geometry _geometry;
|
||||
public Geometry Geometry
|
||||
{
|
||||
get
|
||||
{
|
||||
return _geometry;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _geometry, value);
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsFinish
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
private List<Point> _points;
|
||||
public List<Point> Points
|
||||
{
|
||||
get
|
||||
{
|
||||
return _points;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _points, value);
|
||||
}
|
||||
}
|
||||
public DrawMode DrawMode
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public void UpdateLocation()
|
||||
{
|
||||
ItemWidth = Geometry.Bounds.Width + ColorViewModel.LineWidth;
|
||||
ItemHeight = Geometry.Bounds.Height + ColorViewModel.LineWidth;
|
||||
Left = Geometry.Bounds.Left;
|
||||
Top = Geometry.Bounds.Top;
|
||||
}
|
||||
|
||||
protected override void Init(IDiagramViewModel root, bool initNew)
|
||||
{
|
||||
base.Init(root, initNew);
|
||||
IsHitTestVisible = false;
|
||||
}
|
||||
|
||||
protected override void InitNew()
|
||||
{
|
||||
ClearConnectors();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class EllipseDrawingDesignerItemViewModel : DrawingDesignerItemViewModelBase
|
||||
{
|
||||
public EllipseDrawingDesignerItemViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
public EllipseDrawingDesignerItemViewModel(IDiagramViewModel root) : base(root)
|
||||
{
|
||||
}
|
||||
|
||||
public EllipseDrawingDesignerItemViewModel(IDiagramViewModel root, Point startPoint, bool erasable) : base(root, DrawMode.Rectangle, startPoint, erasable)
|
||||
{
|
||||
}
|
||||
|
||||
public EllipseDrawingDesignerItemViewModel(IDiagramViewModel root, List<Point> points, bool erasable) : base(root, DrawMode.Rectangle, points, erasable)
|
||||
{
|
||||
}
|
||||
|
||||
public override bool OnMouseMove(IInputElement sender, MouseEventArgs e)
|
||||
{
|
||||
if (e.LeftButton == MouseButtonState.Pressed)
|
||||
{
|
||||
var point = e.GetPosition(sender);
|
||||
if (Points == null || Points.Count == 0)//没有起始点
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((Points[0] - point).Length < ColorViewModel.LineWidth)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Keyboard.IsKeyDown(Key.LeftShift))//圆形
|
||||
{
|
||||
var len =Math.Abs(point.X - Points[0].X);//按X轴放大
|
||||
point = new Point(Points[0].X + (point.X > Points[0].X ? len : -len), Points[0].Y + (point.Y > Points[0].Y ? len : -len));
|
||||
}
|
||||
|
||||
if (Points.Count == 2)
|
||||
{
|
||||
Points[1] = point;
|
||||
}
|
||||
else
|
||||
{
|
||||
Points.Add(point);
|
||||
}
|
||||
Geometry = new EllipseGeometry(new Rect(Points[0], Points[1]));
|
||||
IsFinish = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool OnMouseDown(IInputElement sender, MouseButtonEventArgs e)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool OnMouseUp(IInputElement sender, MouseButtonEventArgs e)
|
||||
{
|
||||
return base.OnMouseUp(sender, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using SvgPathProperties;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class EraserDrawingDesignerItemViewModel : DrawingDesignerItemViewModelBase
|
||||
{
|
||||
public EraserDrawingDesignerItemViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
public EraserDrawingDesignerItemViewModel(IDiagramViewModel root) : base(root)
|
||||
{
|
||||
}
|
||||
|
||||
public EraserDrawingDesignerItemViewModel(IDiagramViewModel root, Point startPoint) : base(root, DrawMode.Eraser, startPoint, true)
|
||||
{
|
||||
}
|
||||
|
||||
public EraserDrawingDesignerItemViewModel(IDiagramViewModel root, List<Point> points) : base(root, DrawMode.Eraser, points, true)
|
||||
{
|
||||
}
|
||||
|
||||
public override bool OnMouseMove(IInputElement sender, MouseEventArgs e)
|
||||
{
|
||||
if (e.LeftButton == MouseButtonState.Pressed)
|
||||
{
|
||||
var point = e.GetPosition(sender);
|
||||
if (Points == null || Points.Count == 0)//没有起始点
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if ((Points[0] - point).Length < ColorViewModel.LineWidth)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
PathGeometry geometry;
|
||||
PathFigure figure;
|
||||
if (Keyboard.IsKeyDown(Key.LeftShift) && Geometry != null)//预览模式,一并擦除
|
||||
{
|
||||
geometry = (PathGeometry)Geometry;
|
||||
figure = geometry.Figures[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
geometry = new PathGeometry();
|
||||
figure = new PathFigure { IsClosed = true, IsFilled = true };
|
||||
geometry.Figures.Add(figure);
|
||||
}
|
||||
|
||||
var radius = ColorViewModel.LineWidth / 2;
|
||||
var positiveX = radius * (point.X > Points[0].X ? 1 : -1);
|
||||
var positiveY = radius * (point.Y > Points[0].Y ? 1 : -1);
|
||||
|
||||
figure.StartPoint = new Point( Points[0].X - positiveX, Points[0].Y - positiveY);
|
||||
|
||||
var line = new LineSegment(new Point( Points[0].X + positiveX, Points[0].Y - positiveY), false);
|
||||
figure.Segments.Add(line);
|
||||
|
||||
line = new LineSegment(new Point(point.X + positiveX, point.Y - positiveY), false);
|
||||
figure.Segments.Add(line);
|
||||
|
||||
line = new LineSegment(new Point(point.X + positiveX, point.Y + positiveY), false);
|
||||
figure.Segments.Add(line);
|
||||
|
||||
line = new LineSegment(new Point(point.X - positiveX, point.Y + positiveY), false);
|
||||
figure.Segments.Add(line);
|
||||
|
||||
line = new LineSegment(new Point( Points[0].X - positiveX, Points[0].Y + positiveY), false);
|
||||
figure.Segments.Add(line);
|
||||
|
||||
Points[0] = point;
|
||||
Geometry = geometry;
|
||||
if (Keyboard.IsKeyDown(Key.LeftShift))//预览模式,一并擦除
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Erase(Geometry);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool OnMouseDown(IInputElement sender, MouseButtonEventArgs e)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool OnMouseUp(IInputElement sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (Geometry != null)
|
||||
{
|
||||
Erase(Geometry);
|
||||
}
|
||||
return base.OnMouseUp(sender, e);
|
||||
}
|
||||
|
||||
private new bool Erase(Geometry geometry)
|
||||
{
|
||||
var empty = true;
|
||||
List<DrawingDesignerItemViewModelBase> deleteDrawGeometries = new List<DrawingDesignerItemViewModelBase>();
|
||||
foreach (var g in this.Root.Items.OfType<DrawingDesignerItemViewModelBase>())
|
||||
{
|
||||
if (g.Erase(geometry))
|
||||
deleteDrawGeometries.Add(g);
|
||||
else
|
||||
empty = false;
|
||||
}
|
||||
|
||||
foreach (var g in deleteDrawGeometries)
|
||||
{
|
||||
this.Root.Remove(g);
|
||||
}
|
||||
|
||||
return empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class LineDrawingDesignerItemViewModel : DrawingDesignerItemViewModelBase
|
||||
{
|
||||
public LineDrawingDesignerItemViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
public LineDrawingDesignerItemViewModel(IDiagramViewModel root) : base(root)
|
||||
{
|
||||
}
|
||||
|
||||
public LineDrawingDesignerItemViewModel(IDiagramViewModel root, Point startPoint, bool erasable) : base(root, DrawMode.Line, startPoint, erasable)
|
||||
{
|
||||
}
|
||||
|
||||
public LineDrawingDesignerItemViewModel(IDiagramViewModel root, List<Point> points, bool erasable) : base(root, DrawMode.Line, points, erasable)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override bool OnMouseMove(IInputElement sender, MouseEventArgs e)
|
||||
{
|
||||
if (e.LeftButton == MouseButtonState.Pressed)
|
||||
{
|
||||
var point = e.GetPosition(sender);
|
||||
if (Points == null || Points.Count == 0)//没有起始点
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((Points[0] - point).Length < ColorViewModel.LineWidth)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Points.Count == 2)
|
||||
{
|
||||
Points[1] = point;
|
||||
}
|
||||
else
|
||||
{
|
||||
Points.Add(point);
|
||||
}
|
||||
|
||||
Geometry = new LineGeometry(Points[0], Points[1]);
|
||||
IsFinish = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool OnMouseDown(IInputElement sender, MouseButtonEventArgs e)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool OnMouseUp(IInputElement sender, MouseButtonEventArgs e)
|
||||
{
|
||||
return base.OnMouseUp(sender, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class PolygonDrawingDesignerItemViewModel : DrawingDesignerItemViewModelBase
|
||||
{
|
||||
public PolygonDrawingDesignerItemViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
public PolygonDrawingDesignerItemViewModel(IDiagramViewModel root) : base(root)
|
||||
{
|
||||
}
|
||||
|
||||
public PolygonDrawingDesignerItemViewModel(IDiagramViewModel root, Point startPoint, bool erasable) : base(root, DrawMode.Line, startPoint, erasable)
|
||||
{
|
||||
}
|
||||
|
||||
public PolygonDrawingDesignerItemViewModel(IDiagramViewModel root, List<Point> points, bool erasable) : base(root, DrawMode.Line, points, erasable)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override bool OnMouseMove(IInputElement sender, MouseEventArgs e)
|
||||
{
|
||||
if (e.LeftButton == MouseButtonState.Pressed)
|
||||
{
|
||||
var point = e.GetPosition(sender);
|
||||
if (Points == null || Points.Count == 0)//没有起始点
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((Points.LastOrDefault() - point).Length < ColorViewModel.LineWidth)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Points.Add(point);
|
||||
|
||||
if (Geometry is PathGeometry geometry)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
geometry = new PathGeometry();
|
||||
var figure = new PathFigure { StartPoint = Points[0] };
|
||||
figure.IsClosed = true;
|
||||
geometry.Figures.Add(figure);
|
||||
}
|
||||
|
||||
LineSegment arc = new LineSegment(point, true) { IsSmoothJoin = true };
|
||||
geometry.Figures[0].Segments.Add(arc);
|
||||
Geometry = geometry;
|
||||
|
||||
IsFinish = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool OnMouseDown(IInputElement sender, MouseButtonEventArgs e)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool OnMouseUp(IInputElement sender, MouseButtonEventArgs e)
|
||||
{
|
||||
return base.OnMouseUp(sender, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class PolylineDrawingDesignerItemViewModel : DrawingDesignerItemViewModelBase
|
||||
{
|
||||
public PolylineDrawingDesignerItemViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
public PolylineDrawingDesignerItemViewModel(IDiagramViewModel root) : base(root)
|
||||
{
|
||||
}
|
||||
|
||||
public PolylineDrawingDesignerItemViewModel(IDiagramViewModel root, Point startPoint, bool erasable) : base(root, DrawMode.Line, startPoint, erasable)
|
||||
{
|
||||
}
|
||||
|
||||
public PolylineDrawingDesignerItemViewModel(IDiagramViewModel root, List<Point> points, bool erasable) : base(root, DrawMode.Line, points, erasable)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override bool OnMouseMove(IInputElement sender, MouseEventArgs e)
|
||||
{
|
||||
if (e.LeftButton == MouseButtonState.Pressed)
|
||||
{
|
||||
var point = e.GetPosition(sender);
|
||||
if (Points == null || Points.Count == 0)//没有起始点
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((Points.LastOrDefault() - point).Length < ColorViewModel.LineWidth)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Points.Add(point);
|
||||
|
||||
if (Geometry is PathGeometry geometry)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
geometry = new PathGeometry();
|
||||
var figure = new PathFigure { StartPoint = Points[0] };
|
||||
geometry.Figures.Add(figure);
|
||||
}
|
||||
|
||||
LineSegment arc = new LineSegment(point, true);// { IsSmoothJoin = true };
|
||||
geometry.Figures[0].Segments.Add(arc);
|
||||
Geometry = geometry;
|
||||
|
||||
IsFinish = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool OnMouseDown(IInputElement sender, MouseButtonEventArgs e)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool OnMouseUp(IInputElement sender, MouseButtonEventArgs e)
|
||||
{
|
||||
return base.OnMouseUp(sender, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class RectangleDrawingDesignerItemViewModel : DrawingDesignerItemViewModelBase
|
||||
{
|
||||
public RectangleDrawingDesignerItemViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
public RectangleDrawingDesignerItemViewModel(IDiagramViewModel root) : base(root)
|
||||
{
|
||||
}
|
||||
|
||||
public RectangleDrawingDesignerItemViewModel(IDiagramViewModel root, Point startPoint, bool erasable) : base(root, DrawMode.Rectangle, startPoint, erasable)
|
||||
{
|
||||
}
|
||||
|
||||
public RectangleDrawingDesignerItemViewModel(IDiagramViewModel root, List<Point> points, bool erasable) : base(root, DrawMode.Rectangle, points, erasable)
|
||||
{
|
||||
}
|
||||
|
||||
public override bool OnMouseMove(IInputElement sender, MouseEventArgs e)
|
||||
{
|
||||
if (e.LeftButton == MouseButtonState.Pressed)
|
||||
{
|
||||
var point = e.GetPosition(sender);
|
||||
if (Points == null || Points.Count == 0)//没有起始点
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((Points[0] - point).Length < ColorViewModel.LineWidth)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Keyboard.IsKeyDown(Key.LeftShift))//正方形
|
||||
{
|
||||
var len = Math.Abs(point.X - Points[0].X);//按X轴放大
|
||||
point = new Point(Points[0].X + (point.X > Points[0].X ? len : -len), Points[0].Y + (point.Y > Points[0].Y ? len : -len));
|
||||
}
|
||||
|
||||
if (Points.Count == 2)
|
||||
{
|
||||
Points[1] = point;
|
||||
}
|
||||
else
|
||||
{
|
||||
Points.Add(point);
|
||||
}
|
||||
Geometry = new RectangleGeometry(new Rect(Points[0], Points[1]));
|
||||
IsFinish = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool OnMouseDown(IInputElement sender, MouseButtonEventArgs e)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool OnMouseUp(IInputElement sender, MouseButtonEventArgs e)
|
||||
{
|
||||
return base.OnMouseUp(sender, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user