mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-05 08:46:34 +08:00
画板基础基本完成
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="Images\color-picker.cur" />
|
||||
<None Remove="Images\file.png" />
|
||||
<None Remove="Images\FormatPainter.cur" />
|
||||
<None Include="A.png">
|
||||
@@ -41,6 +42,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Resource Include="Images\color-picker.cur" />
|
||||
<Resource Include="Images\file.png" />
|
||||
<Resource Include="Images\FormatPainter.cur" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -50,7 +50,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private DrawingDesignerItemViewModelBase _drawingDesignerItem;
|
||||
public DrawingRubberbandAdorner(DesignerCanvas designerCanvas, Point dragStartPoint)
|
||||
: base(designerCanvas)
|
||||
@@ -72,7 +71,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
_rubberbandBrush = null;
|
||||
_rubberbandPen = new Pen(new SolidColorBrush(Colors.Red) { Opacity = 0.5 }, _drawingDesignerItem.ColorViewModel.LineWidth);
|
||||
}
|
||||
else if (DrawMode >= DrawMode.ErasableLine && DrawMode <= DrawMode.ErasableDirectLine)
|
||||
else if (DrawMode >= DrawMode.ColorPicker && DrawMode <= DrawMode.ErasableDirectLine)
|
||||
{
|
||||
if (DrawMode == DrawMode.ErasableLine)
|
||||
{
|
||||
@@ -98,9 +97,17 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
_drawingDesignerItem = new DirectLineDrawingDesignerItemViewModel(_viewModel, dragStartPoint, true);
|
||||
}
|
||||
else if (DrawMode == DrawMode.ErasableText)
|
||||
{
|
||||
_drawingDesignerItem = new TextDrawingDesignerItemViewModel(_viewModel, dragStartPoint, true);
|
||||
}
|
||||
else if (DrawMode == DrawMode.ColorPicker)
|
||||
{
|
||||
_drawingDesignerItem = new ColorPickerDrawingDesignerItemViewModel(_viewModel, dragStartPoint, true);
|
||||
}
|
||||
|
||||
_rubberbandBrush = null;//ColorObject.ToBrush(_drawingDesignerItem.ColorViewModel.FillColor);
|
||||
_rubberbandPen = new Pen(ColorObject.ToBrush(_drawingDesignerItem.ColorViewModel.LineColor), _drawingDesignerItem.ColorViewModel.LineWidth);
|
||||
_rubberbandPen = new Pen(_drawingDesignerItem.ColorViewModel.LineColor.ToBrush(), _drawingDesignerItem.ColorViewModel.LineWidth);
|
||||
_rubberbandPen.DashStyle = new DashStyle(StrokeDashArray.Dash[(int)_drawingDesignerItem.ColorViewModel.LineDashStyle], 1);
|
||||
}
|
||||
else if (DrawMode >= DrawMode.Line && DrawMode <= DrawMode.DirectLine)
|
||||
@@ -130,15 +137,20 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
_drawingDesignerItem = new DirectLineDrawingDesignerItemViewModel(_viewModel, dragStartPoint, false);
|
||||
}
|
||||
|
||||
_rubberbandBrush = ColorObject.ToBrush(_drawingDesignerItem.ColorViewModel.FillColor);
|
||||
_rubberbandPen = new Pen(ColorObject.ToBrush(_drawingDesignerItem.ColorViewModel.LineColor), _drawingDesignerItem.ColorViewModel.LineWidth);
|
||||
_rubberbandBrush = _drawingDesignerItem.ColorViewModel.FillColor.ToBrush();
|
||||
_rubberbandPen = new Pen(_drawingDesignerItem.ColorViewModel.LineColor.ToBrush(), _drawingDesignerItem.ColorViewModel.LineWidth);
|
||||
_rubberbandPen.DashStyle = new DashStyle(StrokeDashArray.Dash[(int)_drawingDesignerItem.ColorViewModel.LineDashStyle], 1);
|
||||
}
|
||||
|
||||
if (_drawingDesignerItem == null)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseMove(System.Windows.Input.MouseEventArgs e)
|
||||
{
|
||||
if (_drawingDesignerItem.OnMouseMove(this, e) == true)
|
||||
if (_drawingDesignerItem?.OnMouseMove(this, e) == true)
|
||||
{
|
||||
if (!this.IsMouseCaptured)
|
||||
this.CaptureMouse();
|
||||
@@ -155,7 +167,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
protected override void OnMouseUp(System.Windows.Input.MouseButtonEventArgs e)
|
||||
{
|
||||
if (_drawingDesignerItem.OnMouseUp(this, e) == false)
|
||||
if (_drawingDesignerItem?.OnMouseUp(this, e) == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -168,17 +180,18 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
if (adornerLayer != null)
|
||||
adornerLayer.Remove(this);
|
||||
|
||||
if (_drawingDesignerItem.IsFinish == true)
|
||||
if (_drawingDesignerItem?.IsFinish == true)
|
||||
{
|
||||
_viewModel.AddItemCommand.Execute(_drawingDesignerItem);
|
||||
}
|
||||
|
||||
this._service.DrawModeViewModel.ResetDrawMode();
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
protected override void OnMouseDown(MouseButtonEventArgs e)
|
||||
{
|
||||
_drawingDesignerItem.OnMouseDown(this, e);
|
||||
_drawingDesignerItem?.OnMouseDown(this, e);
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
@@ -192,7 +205,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
// the ConnectionAdorner does.
|
||||
dc.DrawRectangle(Brushes.Transparent, null, new Rect(RenderSize));
|
||||
|
||||
dc.DrawGeometry(_rubberbandBrush, _rubberbandPen, _drawingDesignerItem.Geometry);
|
||||
dc.DrawGeometry(_rubberbandBrush, _rubberbandPen, _drawingDesignerItem?.Geometry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
Rect rubberBand = new Rect(startPoint.Value, endPoint.Value);
|
||||
ItemsControl itemsControl = GetParent<ItemsControl>(typeof(ItemsControl), _designerCanvas);
|
||||
|
||||
foreach (SelectableDesignerItemViewModelBase item in vm.Items)
|
||||
foreach (SelectableDesignerItemViewModelBase item in vm.Items.ToList())
|
||||
{
|
||||
if (item is SelectableDesignerItemViewModelBase)
|
||||
{
|
||||
|
||||
@@ -98,11 +98,11 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
if (_viewModel.DrawModeViewModel != null)
|
||||
{
|
||||
return _viewModel.DrawModeViewModel.LineDrawMode;
|
||||
return _viewModel.DrawModeViewModel.GetDrawMode();
|
||||
}
|
||||
else
|
||||
{
|
||||
return _service.DrawModeViewModel.LineDrawMode;
|
||||
return _service.DrawModeViewModel.GetDrawMode();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -271,6 +271,14 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
EnterMove();
|
||||
}
|
||||
else if (_service.DrawModeViewModel.CursorMode == CursorMode.ColorPicker)
|
||||
{
|
||||
EnterColorPicker();
|
||||
}
|
||||
else if (_service.DrawModeViewModel.CursorMode == CursorMode.Exit)
|
||||
{
|
||||
ExitCursor();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -295,6 +303,23 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
private void EnterColorPicker()
|
||||
{
|
||||
|
||||
// create rubberband adorner
|
||||
AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(this);
|
||||
if (adornerLayer != null)
|
||||
{
|
||||
DrawingRubberbandAdorner adorner = new DrawingRubberbandAdorner(this, new Point());
|
||||
if (adorner != null)
|
||||
{
|
||||
adornerLayer.Add(adorner);
|
||||
StreamResourceInfo sri = Application.GetResourceStream(new Uri("pack://application:,,,/AIStudio.Wpf.DiagramDesigner;component/Images/color-picker.cur", UriKind.RelativeOrAbsolute));
|
||||
adorner.Cursor = new Cursor(sri.Stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ExitCursor()
|
||||
{
|
||||
this.Cursor = Cursors.Arrow;
|
||||
@@ -361,7 +386,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
SourceConnector = new Connector() { Content = new PartCreatedConnectorInfo(currentPoint.X, currentPoint.Y), Tag = "虚拟的连接点" };
|
||||
}
|
||||
}
|
||||
else if (_service.DrawModeViewModel.DrawingDrawModeSelected)
|
||||
else if (_service.DrawModeViewModel.SharpDrawModeSelected || _service.DrawModeViewModel.DrawingDrawModeSelected)
|
||||
{
|
||||
// create rubberband adorner
|
||||
AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(this);
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
else if (value is ColorObject colorObject)
|
||||
{
|
||||
brush = ColorObject.ToBrush(colorObject);
|
||||
brush = colorObject.ToBrush();
|
||||
}
|
||||
else if (value is ObservableCollection<GradientStop> gradientStop)
|
||||
{
|
||||
|
||||
@@ -9,5 +9,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
Normal = 0,
|
||||
Format = 1,
|
||||
Move = 2,
|
||||
ColorPicker = 3,
|
||||
Exit = 4,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,25 +11,44 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
ConnectingLineStraight = 11,
|
||||
ConnectingLineCorner = 12,
|
||||
ConnectingLineBoundary = 13,
|
||||
//101-110为可部分擦除的形状
|
||||
Eraser = 100,
|
||||
EraserPreview = 101,
|
||||
ErasableLine = 110,
|
||||
ErasableRectangle = 111,
|
||||
ErasableEllipse = 112,
|
||||
ErasablePolyline = 113,
|
||||
ErasablePolygon = 114,
|
||||
ErasableDirectLine = 115,
|
||||
|
||||
Text = 200,
|
||||
Line = 210,
|
||||
Rectangle = 211,
|
||||
Ellipse = 212,
|
||||
Polyline = 213,
|
||||
Polygon = 214,
|
||||
DirectLine = 215,
|
||||
|
||||
|
||||
|
||||
//实心图使用
|
||||
Text = 119,
|
||||
Line = 120,
|
||||
Rectangle = 121,
|
||||
Ellipse = 122,
|
||||
Polyline = 123,
|
||||
Polygon = 124,
|
||||
DirectLine = 125,
|
||||
//200-300为可部分擦除的形状
|
||||
Select = 200,
|
||||
Eraser = 201,
|
||||
EraserPreview = 202,
|
||||
//画笔使用
|
||||
Pen1 = 210,
|
||||
Pen2 = 211,
|
||||
Pen3 = 212,
|
||||
ColorPicker = 213,
|
||||
ErasableText = 219,
|
||||
ErasableLine = 220,
|
||||
ErasableRectangle = 221,
|
||||
ErasableEllipse = 222,
|
||||
ErasablePolyline = 223,
|
||||
ErasablePolygon = 224,
|
||||
ErasableDirectLine = 225,
|
||||
ErasableTriangle = 226, //三角形
|
||||
ErasableRhombus = 227, //菱形
|
||||
ErasableHexagon = 228,//六边形
|
||||
ErasablePentagram = 229,//五角星
|
||||
ErasableStarFour = 230,//四角星
|
||||
ErasableStarThree = 231,//三角星
|
||||
ErasableChat = 232,//对话框
|
||||
ErasableComment = 233,//评论
|
||||
ErasableCloud = 234,//云
|
||||
ErasableArrowRight = 235,
|
||||
ErasableArrowLeft = 236,
|
||||
ErasableCamera = 237,
|
||||
ErasableCheck = 238,
|
||||
ErasableClose = 239,
|
||||
ErasableHeart = 240,
|
||||
}
|
||||
}
|
||||
|
||||
BIN
AIStudio.Wpf.DiagramDesigner/Images/color-picker.cur
Normal file
BIN
AIStudio.Wpf.DiagramDesigner/Images/color-picker.cur
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Xml.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class DrawingDesignerItemBase : DesignerItemBase
|
||||
{
|
||||
public DrawingDesignerItemBase()
|
||||
{
|
||||
|
||||
}
|
||||
public DrawingDesignerItemBase(DrawingDesignerItemViewModelBase item) : base(item)
|
||||
{
|
||||
this.Erasable = item.Erasable;
|
||||
this.Geometry = item.Geometry.ToString();
|
||||
this.Points = item.Points;
|
||||
this.DrawMode = item.DrawMode;
|
||||
}
|
||||
|
||||
[XmlAttribute]
|
||||
public bool Erasable
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
[XmlAttribute]
|
||||
public string Geometry
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
[XmlIgnore]
|
||||
public List<Point> Points
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
[XmlElement("Points")]
|
||||
public string XmlPoints
|
||||
{
|
||||
get
|
||||
{
|
||||
return SerializeHelper.SerializePointList(Points);
|
||||
}
|
||||
set
|
||||
{
|
||||
Points = SerializeHelper.DeserializePointList(value);
|
||||
}
|
||||
}
|
||||
|
||||
[XmlAttribute]
|
||||
public DrawMode DrawMode
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -865,7 +865,10 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
get; set;
|
||||
}
|
||||
|
||||
|
||||
public Brush ToBrush()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public class SharpPathItem : ISharpPath
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
<dd:ColorBrushConverter x:Key="ColorBrushConverter" />
|
||||
<dd:ClipConverter x:Key="ClipConverter"/>
|
||||
<dd:NegativeConverter x:Key="NegativeConverter"/>
|
||||
<dd:LineDashConverter x:Key="LineDashConverter"/>
|
||||
<dd:DoubleToThickness x:Key="DoubleToThickness"/>
|
||||
|
||||
<DataTemplate DataType="{x:Type dd:DefaultDesignerItemViewModel}">
|
||||
<Grid IsHitTestVisible="False">
|
||||
@@ -26,6 +28,18 @@
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type dd:TextAutoDesignerItemViewModel}">
|
||||
<Grid >
|
||||
<Border BorderThickness="{Binding ColorViewModel.LineWidth,Converter={StaticResource DoubleToThickness}}"
|
||||
BorderBrush="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}"
|
||||
Background="{Binding ColorViewModel.FillColor,Converter={StaticResource ColorBrushConverter}}"
|
||||
IsHitTestVisible="False"/>
|
||||
<Grid Margin="1">
|
||||
<dd:TextControl />
|
||||
</Grid>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type dd:DrawingDesignerItemViewModelBase}">
|
||||
<Grid IsHitTestVisible="False">
|
||||
<Control x:Name="control" />
|
||||
@@ -49,7 +63,7 @@
|
||||
<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}}"
|
||||
Fill="{Binding ColorViewModel.FillColor,Converter={StaticResource ColorBrushConverter}}"
|
||||
Data="{Binding Geometry}">
|
||||
</Path>
|
||||
</ControlTemplate>
|
||||
|
||||
@@ -360,6 +360,10 @@
|
||||
Value="{Binding ItemWidth}" />
|
||||
<Setter Property="Height"
|
||||
Value="{Binding ItemHeight}" />
|
||||
<Setter Property="MinWidth"
|
||||
Value="{Binding MinItemWidth}" />
|
||||
<Setter Property="MinHeight"
|
||||
Value="{Binding MinItemHeight}" />
|
||||
<Setter Property="SnapsToDevicePixels"
|
||||
Value="True" />
|
||||
<Setter Property="ContentTemplate">
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
<Canvas x:Name="rootCanvas">
|
||||
<Path x:Name="line" StrokeThickness="{Binding ColorViewModel.LineWidth}"
|
||||
StrokeDashArray="{Binding ColorViewModel.LineDashStyle,Converter={StaticResource LineDashConverter}}"
|
||||
Stroke="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}"
|
||||
Stroke="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}"
|
||||
StrokeLineJoin="Round"
|
||||
StrokeStartLineCap="Round"
|
||||
StrokeEndLineCap="Round">
|
||||
|
||||
@@ -107,7 +107,27 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnPreviewKeyDown(KeyEventArgs e)
|
||||
{
|
||||
if (AcceptsReturn == false && e.Key == Key.Enter)
|
||||
{
|
||||
if (this.DataContext is DesignerItemViewModelBase designitem)
|
||||
{
|
||||
designitem.ExitEditCommand.Execute(null);
|
||||
}
|
||||
}
|
||||
base.OnPreviewKeyDown(e);
|
||||
}
|
||||
|
||||
protected override void OnLostFocus(RoutedEventArgs e)
|
||||
{
|
||||
if (this.DataContext is ISelectable selectable)
|
||||
{
|
||||
selectable.IsSelected = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ControlAttachProperty
|
||||
|
||||
@@ -20,6 +20,12 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
public static Color[] LineColors { get; } = new Color[] { Colors.Red, Colors.Green, Colors.Blue, Colors.White, Colors.Black, Colors.Purple };
|
||||
#endregion
|
||||
|
||||
public ColorViewModel(Color linecolor, Color fillcolor)
|
||||
{
|
||||
LineColor = new ColorObject() { Color = linecolor };
|
||||
FillColor = new ColorObject() { Color = fillcolor };
|
||||
}
|
||||
|
||||
public ColorViewModel()
|
||||
{
|
||||
LineColor = new ColorObject() { Color = Colors.Gray };
|
||||
@@ -409,54 +415,54 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
public static Brush ToBrush(IColorObject colorObject)
|
||||
public Brush ToBrush()
|
||||
{
|
||||
Brush brush = null;
|
||||
|
||||
if (colorObject.BrushType == BrushType.None)
|
||||
if (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)
|
||||
else if (BrushType == BrushType.SolidColorBrush)
|
||||
brush = new SolidColorBrush(Color);
|
||||
else if (BrushType == BrushType.LinearGradientBrush)
|
||||
{
|
||||
Point startPoint;
|
||||
Point endPoint;
|
||||
if (colorObject.LinearOrientation == LinearOrientation.LeftToRight)
|
||||
if (LinearOrientation == LinearOrientation.LeftToRight)
|
||||
{
|
||||
startPoint = new Point(0, 0.5);
|
||||
endPoint = new Point(1, 0.5);
|
||||
}
|
||||
else if (colorObject.LinearOrientation == LinearOrientation.LeftTopToRightBottom)
|
||||
else if (LinearOrientation == LinearOrientation.LeftTopToRightBottom)
|
||||
{
|
||||
startPoint = new Point(0, 0);
|
||||
endPoint = new Point(1, 1);
|
||||
}
|
||||
else if (colorObject.LinearOrientation == LinearOrientation.TopToBottom)
|
||||
else if (LinearOrientation == LinearOrientation.TopToBottom)
|
||||
{
|
||||
startPoint = new Point(0.5, 0);
|
||||
endPoint = new Point(0.5, 1);
|
||||
}
|
||||
else if (colorObject.LinearOrientation == LinearOrientation.RightTopToLeftBottom)
|
||||
else if (LinearOrientation == LinearOrientation.RightTopToLeftBottom)
|
||||
{
|
||||
startPoint = new Point(1, 0);
|
||||
endPoint = new Point(0, 1);
|
||||
}
|
||||
else if (colorObject.LinearOrientation == LinearOrientation.RightToLeft)
|
||||
else if (LinearOrientation == LinearOrientation.RightToLeft)
|
||||
{
|
||||
startPoint = new Point(1, 0.5);
|
||||
endPoint = new Point(0, 0.5);
|
||||
}
|
||||
else if (colorObject.LinearOrientation == LinearOrientation.RightBottomToLeftTop)
|
||||
else if (LinearOrientation == LinearOrientation.RightBottomToLeftTop)
|
||||
{
|
||||
startPoint = new Point(1, 1);
|
||||
endPoint = new Point(0, 0);
|
||||
}
|
||||
else if (colorObject.LinearOrientation == LinearOrientation.BottomToTop)
|
||||
else if (LinearOrientation == LinearOrientation.BottomToTop)
|
||||
{
|
||||
startPoint = new Point(0.5, 1);
|
||||
endPoint = new Point(0.5, 0);
|
||||
}
|
||||
else if (colorObject.LinearOrientation == LinearOrientation.LeftBottomToRightTop)
|
||||
else if (LinearOrientation == LinearOrientation.LeftBottomToRightTop)
|
||||
{
|
||||
startPoint = new Point(0, 1);
|
||||
endPoint = new Point(1, 0);
|
||||
@@ -470,47 +476,47 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
LinearGradientBrush myBrush = new LinearGradientBrush();
|
||||
myBrush.StartPoint = startPoint;
|
||||
myBrush.EndPoint = endPoint;
|
||||
if (colorObject.GradientStop != null)
|
||||
if (GradientStop != null)
|
||||
{
|
||||
foreach (var stop in colorObject.GradientStop)
|
||||
foreach (var stop in 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);
|
||||
RotateTransform rotateTransform = new RotateTransform(Angle, 0.5, 0.5);
|
||||
myBrush.RelativeTransform = rotateTransform;
|
||||
}
|
||||
else if (colorObject.BrushType == BrushType.RadialGradientBrush)
|
||||
else if (BrushType == BrushType.RadialGradientBrush)
|
||||
{
|
||||
Point center;
|
||||
Point gradientOrigin;
|
||||
double radiusX;
|
||||
double radiusY;
|
||||
|
||||
if (colorObject.RadialOrientation == RadialOrientation.LeftTop)
|
||||
if (RadialOrientation == RadialOrientation.LeftTop)
|
||||
{
|
||||
center = new Point(0, 0);
|
||||
gradientOrigin = center;
|
||||
radiusX = 1;
|
||||
radiusY = 1;
|
||||
}
|
||||
else if (colorObject.RadialOrientation == RadialOrientation.RightTop)
|
||||
else if (RadialOrientation == RadialOrientation.RightTop)
|
||||
{
|
||||
center = new Point(1, 0);
|
||||
gradientOrigin = center;
|
||||
radiusX = 1;
|
||||
radiusY = 1;
|
||||
}
|
||||
else if (colorObject.RadialOrientation == RadialOrientation.RightBottom)
|
||||
else if (RadialOrientation == RadialOrientation.RightBottom)
|
||||
{
|
||||
center = new Point(1, 1);
|
||||
gradientOrigin = center;
|
||||
radiusX = 1;
|
||||
radiusY = 1;
|
||||
}
|
||||
else if (colorObject.RadialOrientation == RadialOrientation.LeftBottom)
|
||||
else if (RadialOrientation == RadialOrientation.LeftBottom)
|
||||
{
|
||||
center = new Point(0, 1);
|
||||
gradientOrigin = center;
|
||||
@@ -530,25 +536,25 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
myBrush.GradientOrigin = gradientOrigin;
|
||||
myBrush.RadiusX = radiusX;
|
||||
myBrush.RadiusY = radiusY;
|
||||
if (colorObject.GradientStop != null)
|
||||
if (GradientStop != null)
|
||||
{
|
||||
foreach (var stop in colorObject.GradientStop)
|
||||
foreach (var stop in 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);
|
||||
RotateTransform rotateTransform = new RotateTransform(Angle, 0.5, 0.5);
|
||||
myBrush.RelativeTransform = rotateTransform;
|
||||
}
|
||||
else if (colorObject.BrushType == BrushType.ImageBrush)
|
||||
else if (BrushType == BrushType.ImageBrush)
|
||||
{
|
||||
ImageBrush myBrush = new ImageBrush();
|
||||
myBrush.ImageSource = new BitmapImage(new Uri(colorObject.Image, UriKind.Absolute));
|
||||
myBrush.ImageSource = new BitmapImage(new Uri(Image, UriKind.Absolute));
|
||||
brush = myBrush;
|
||||
}
|
||||
else if (colorObject.BrushType == BrushType.DrawingBrush)
|
||||
else if (BrushType == BrushType.DrawingBrush)
|
||||
{
|
||||
DrawingBrush myBrush = new DrawingBrush();
|
||||
|
||||
@@ -580,7 +586,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
if (brush != null)
|
||||
{
|
||||
brush.Opacity = colorObject.Opacity;
|
||||
brush.Opacity = Opacity;
|
||||
}
|
||||
|
||||
return brush;
|
||||
@@ -633,6 +639,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
Brush ToBrush();
|
||||
}
|
||||
|
||||
public class GradientStop : BindableBase
|
||||
|
||||
@@ -1,14 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class DrawModeViewModel : BindableBase, IDrawModeViewModel
|
||||
{
|
||||
public DrawMode GetDrawMode()
|
||||
public DrawModeViewModel()
|
||||
{
|
||||
if (CursorDrawModeSelected)
|
||||
DrawingColorViewModel1 = new ColorViewModel(Color.FromRgb(0x19, 0x19, 0x1a), Colors.Transparent) { LineWidth = 1 };
|
||||
DrawingColorViewModel2 = new ColorViewModel(Color.FromRgb(0xf5, 0xdc, 0x4e), Colors.Transparent) { LineWidth = 4 };
|
||||
DrawingColorViewModel3 = new ColorViewModel(Color.FromRgb(0xf2, 0x69, 0x57), Colors.Transparent) { LineWidth = 8 };
|
||||
}
|
||||
|
||||
public DrawMode GetDrawMode()
|
||||
{
|
||||
if (DrawingDrawModeSelected)
|
||||
{
|
||||
return DrawingDrawMode;
|
||||
}
|
||||
else if (CursorDrawModeSelected)
|
||||
{
|
||||
return CursorDrawMode;
|
||||
}
|
||||
@@ -16,9 +28,9 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
return LineDrawMode;
|
||||
}
|
||||
else if (DrawingDrawModeSelected)
|
||||
else if (SharpDrawModeSelected)
|
||||
{
|
||||
return DrawingDrawMode;
|
||||
return SharpDrawMode;
|
||||
}
|
||||
else if (TextDrawModeSelected)
|
||||
{
|
||||
@@ -30,8 +42,18 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
public void ResetDrawMode()
|
||||
{
|
||||
CursorDrawModeSelected = true;
|
||||
CursorDrawMode = DrawMode.Normal;
|
||||
var drawingDrawMode = GetOldValue<DrawMode>(nameof(DrawingDrawMode));
|
||||
if (drawingDrawMode != default(DrawMode))
|
||||
{
|
||||
ClearOldValue<DrawMode>(nameof(DrawingDrawMode));
|
||||
DrawingDrawMode = drawingDrawMode;
|
||||
CursorMode = CursorMode.Normal;
|
||||
}
|
||||
else
|
||||
{
|
||||
CursorDrawModeSelected = true;
|
||||
CursorDrawMode = DrawMode.Normal;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetDrawMode(DrawMode drawMode)
|
||||
@@ -52,59 +74,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
private bool _lineDrawModeSelected;
|
||||
public bool LineDrawModeSelected
|
||||
{
|
||||
get
|
||||
{
|
||||
return _lineDrawModeSelected;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _lineDrawModeSelected, value);
|
||||
}
|
||||
}
|
||||
|
||||
//界面还未使用到
|
||||
private bool _vectorRouterModeSelected;
|
||||
public bool LineRouterModeSelected
|
||||
{
|
||||
get
|
||||
{
|
||||
return _vectorRouterModeSelected;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _vectorRouterModeSelected, value);
|
||||
}
|
||||
}
|
||||
|
||||
private bool _shapeDrawModeSelected;
|
||||
public bool DrawingDrawModeSelected
|
||||
{
|
||||
get
|
||||
{
|
||||
return _shapeDrawModeSelected;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _shapeDrawModeSelected, value);
|
||||
}
|
||||
}
|
||||
|
||||
private bool _textDrawModeSelected;
|
||||
public bool TextDrawModeSelected
|
||||
{
|
||||
get
|
||||
{
|
||||
return _textDrawModeSelected;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _textDrawModeSelected, value);
|
||||
}
|
||||
}
|
||||
|
||||
private DrawMode _cursordrawMode = DrawMode.Normal;
|
||||
public DrawMode CursorDrawMode
|
||||
{
|
||||
@@ -119,6 +88,19 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
private bool _lineDrawModeSelected;
|
||||
public bool LineDrawModeSelected
|
||||
{
|
||||
get
|
||||
{
|
||||
return _lineDrawModeSelected;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _lineDrawModeSelected, value);
|
||||
}
|
||||
}
|
||||
|
||||
private DrawMode _lineDrawMode = DrawMode.ConnectingLineSmooth;
|
||||
public DrawMode LineDrawMode
|
||||
{
|
||||
@@ -133,6 +115,21 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
#region 界面还未使用到
|
||||
private bool _vectorRouterModeSelected;
|
||||
public bool LineRouterModeSelected
|
||||
{
|
||||
get
|
||||
{
|
||||
return _vectorRouterModeSelected;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _vectorRouterModeSelected, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private RouterMode _lineRouterMode = RouterMode.RouterNormal;
|
||||
public RouterMode LineRouterMode
|
||||
{
|
||||
@@ -145,18 +142,78 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
SetProperty(ref _lineRouterMode, value);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
private DrawMode _shapeDrawMode = DrawMode.ErasableRectangle;
|
||||
private bool _shapeDrawModeSelected;
|
||||
public bool SharpDrawModeSelected
|
||||
{
|
||||
get
|
||||
{
|
||||
return _shapeDrawModeSelected;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _shapeDrawModeSelected, value);
|
||||
}
|
||||
}
|
||||
|
||||
private DrawMode _sharpDrawMode = DrawMode.Rectangle;
|
||||
public DrawMode SharpDrawMode
|
||||
{
|
||||
get
|
||||
{
|
||||
return _sharpDrawMode;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _sharpDrawMode, value);
|
||||
SharpDrawModeSelected = true;
|
||||
}
|
||||
}
|
||||
|
||||
private bool _drawingDrawModeSelected;
|
||||
public bool DrawingDrawModeSelected
|
||||
{
|
||||
get
|
||||
{
|
||||
return _drawingDrawModeSelected;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _drawingDrawModeSelected, value);
|
||||
}
|
||||
}
|
||||
|
||||
private DrawMode _drawingDrawMode = DrawMode.ErasableLine;
|
||||
public DrawMode DrawingDrawMode
|
||||
{
|
||||
get
|
||||
{
|
||||
return _shapeDrawMode;
|
||||
return _drawingDrawMode;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _shapeDrawMode, value);
|
||||
var oldvalue = _drawingDrawMode;
|
||||
SetProperty(ref _drawingDrawMode, value);
|
||||
DrawingDrawModeSelected = true;
|
||||
if (value == DrawMode.ColorPicker)
|
||||
{
|
||||
SetOldValue(oldvalue, nameof(DrawingDrawMode));
|
||||
CursorMode = CursorMode.ColorPicker;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool _textDrawModeSelected;
|
||||
public bool TextDrawModeSelected
|
||||
{
|
||||
get
|
||||
{
|
||||
return _textDrawModeSelected;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _textDrawModeSelected, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,7 +242,83 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
SetProperty(ref _cursorMode, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region 画笔使用
|
||||
private DrawMode _drawingPenDrawMode = DrawMode.Pen1;
|
||||
public DrawMode DrawingPenDrawMode
|
||||
{
|
||||
get
|
||||
{
|
||||
return _drawingPenDrawMode;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _drawingPenDrawMode, value);
|
||||
}
|
||||
}
|
||||
|
||||
public IColorViewModel DrawingColorViewModel
|
||||
{
|
||||
get
|
||||
{
|
||||
if (DrawingPenDrawMode == DrawMode.Pen1)
|
||||
{
|
||||
return DrawingColorViewModel1;
|
||||
}
|
||||
else if (DrawingPenDrawMode == DrawMode.Pen2)
|
||||
{
|
||||
return DrawingColorViewModel2;
|
||||
}
|
||||
else if (DrawingPenDrawMode == DrawMode.Pen3)
|
||||
{
|
||||
return DrawingColorViewModel3;
|
||||
}
|
||||
else
|
||||
{
|
||||
return DrawingColorViewModel1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IColorViewModel _drawingColorViewModel1;
|
||||
public IColorViewModel DrawingColorViewModel1
|
||||
{
|
||||
get
|
||||
{
|
||||
return _drawingColorViewModel1;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _drawingColorViewModel1, value);
|
||||
}
|
||||
}
|
||||
|
||||
private IColorViewModel _drawingColorViewModel2;
|
||||
public IColorViewModel DrawingColorViewModel2
|
||||
{
|
||||
get
|
||||
{
|
||||
return _drawingColorViewModel2;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _drawingColorViewModel2, value);
|
||||
}
|
||||
}
|
||||
|
||||
private IColorViewModel _drawingColorViewModel3;
|
||||
public IColorViewModel DrawingColorViewModel3
|
||||
{
|
||||
get
|
||||
{
|
||||
return _drawingColorViewModel3;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _drawingColorViewModel3, value);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,14 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
bool SharpDrawModeSelected
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
DrawMode SharpDrawMode
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
bool DrawingDrawModeSelected
|
||||
{
|
||||
get; set;
|
||||
@@ -49,6 +57,10 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
IColorViewModel DrawingColorViewModel
|
||||
{
|
||||
get;
|
||||
}
|
||||
event PropertyChangedEventHandler PropertyChanged;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -523,6 +523,32 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
private double _minItemWidth;
|
||||
public double MinItemWidth
|
||||
{
|
||||
get
|
||||
{
|
||||
return _minItemWidth;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _minItemWidth, value);
|
||||
}
|
||||
}
|
||||
|
||||
private double _minItemHeight;
|
||||
public double MinItemHeight
|
||||
{
|
||||
get
|
||||
{
|
||||
return _minItemHeight;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _minItemHeight, value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 连接点是否可以按偏移自定义
|
||||
/// </summary>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner.ViewModels.BaseViewModel
|
||||
{
|
||||
@@ -14,7 +15,7 @@ namespace AIStudio.Wpf.DiagramDesigner.ViewModels.BaseViewModel
|
||||
ColorViewModel = new ColorViewModel();
|
||||
FontViewModel = new FontViewModel();
|
||||
ShapeViewModel = new ShapeViewModel();
|
||||
AnimationViewModel= new AnimationViewModel();
|
||||
AnimationViewModel = new AnimationViewModel();
|
||||
LockObjectViewModel = new LockObjectViewModel();
|
||||
|
||||
_drawModeViewModel = new DrawModeViewModel();
|
||||
@@ -72,6 +73,8 @@ namespace AIStudio.Wpf.DiagramDesigner.ViewModels.BaseViewModel
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private IFontViewModel _fontViewModel;
|
||||
public IFontViewModel FontViewModel
|
||||
{
|
||||
@@ -80,7 +83,7 @@ namespace AIStudio.Wpf.DiagramDesigner.ViewModels.BaseViewModel
|
||||
return _fontViewModel;
|
||||
}
|
||||
set
|
||||
{
|
||||
{
|
||||
SetProperty(ref _fontViewModel, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -316,6 +316,10 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (DisableSelected == true)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return _isHitTestVisible;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class TextAutoDesignerItemViewModel : TextDesignerItemViewModel
|
||||
{
|
||||
public TextAutoDesignerItemViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
public TextAutoDesignerItemViewModel(IDiagramViewModel root) : base(root)
|
||||
{
|
||||
}
|
||||
|
||||
public TextAutoDesignerItemViewModel(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
||||
{
|
||||
}
|
||||
|
||||
public TextAutoDesignerItemViewModel(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Init(IDiagramViewModel root, bool initNew)
|
||||
{
|
||||
base.Init(root, initNew);
|
||||
|
||||
CustomText = true;
|
||||
}
|
||||
|
||||
protected override void InitNew()
|
||||
{
|
||||
base.InitNew();
|
||||
this.ItemWidth = double.NaN;
|
||||
this.ItemHeight = double.NaN;
|
||||
this.MinItemWidth = this.MinItemHeight = FontViewModel.FontSize * 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class ColorPickerDrawingDesignerItemViewModel : DrawingDesignerItemViewModelBase
|
||||
{
|
||||
public ColorPickerDrawingDesignerItemViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
public ColorPickerDrawingDesignerItemViewModel(IDiagramViewModel root, Point startPoint, bool erasable) : base(root, DrawMode.ErasableLine, startPoint, erasable)
|
||||
{
|
||||
}
|
||||
|
||||
public ColorPickerDrawingDesignerItemViewModel(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public ColorPickerDrawingDesignerItemViewModel(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override bool OnMouseMove(IInputElement sender, MouseEventArgs e)
|
||||
{
|
||||
var point = CursorPointManager.GetCursorPosition();
|
||||
Root.CurrentColor = ColorPickerManager.GetColor(point.X, point.Y);
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool OnMouseDown(IInputElement sender, MouseButtonEventArgs e)
|
||||
{
|
||||
_service.DrawModeViewModel.DrawingColorViewModel.LineColor.Color = Root.CurrentColor;
|
||||
_service.DrawModeViewModel.ResetDrawMode();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool OnMouseUp(IInputElement sender, MouseButtonEventArgs e)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Media3D;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
@@ -16,16 +17,18 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
}
|
||||
|
||||
public DirectLineDrawingDesignerItemViewModel(IDiagramViewModel root) : base(root)
|
||||
{
|
||||
}
|
||||
|
||||
public DirectLineDrawingDesignerItemViewModel(IDiagramViewModel root, Point startPoint, bool erasable) : base(root, DrawMode.ErasableDirectLine, startPoint, erasable)
|
||||
{
|
||||
}
|
||||
|
||||
public DirectLineDrawingDesignerItemViewModel(IDiagramViewModel root, List<Point> points, bool erasable) : base(root, DrawMode.ErasableDirectLine, points, erasable)
|
||||
public DirectLineDrawingDesignerItemViewModel(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public DirectLineDrawingDesignerItemViewModel(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override bool OnMouseMove(IInputElement sender, MouseEventArgs e)
|
||||
|
||||
@@ -9,32 +9,73 @@ using System.Windows.Media;
|
||||
using System.Windows.Media.Media3D;
|
||||
using System.Windows.Shapes;
|
||||
using System.Windows.Controls;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class DrawingDesignerItemViewModelBase : DesignerItemViewModelBase
|
||||
{
|
||||
public DrawingDesignerItemViewModelBase() : this(null)
|
||||
public DrawingDesignerItemViewModelBase() : base()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
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)
|
||||
public DrawingDesignerItemViewModelBase(IDiagramViewModel root, DrawMode drawMode, Point startPoint, bool erasable) : base(root)
|
||||
{
|
||||
DrawMode = drawMode;
|
||||
Points = points;
|
||||
Points = new List<Point> { startPoint };
|
||||
Erasable = erasable;
|
||||
DisableSelected = Erasable;
|
||||
if (Erasable)
|
||||
{
|
||||
if (Root?.DrawModeViewModel != null)
|
||||
{
|
||||
this.ColorViewModel = CopyHelper.Mapper(Root.DrawModeViewModel.DrawingColorViewModel);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.ColorViewModel = CopyHelper.Mapper(_service.DrawModeViewModel.DrawingColorViewModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public DrawingDesignerItemViewModelBase(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public DrawingDesignerItemViewModelBase(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override SelectableItemBase GetSerializableObject()
|
||||
{
|
||||
return new DrawingDesignerItemBase(this);
|
||||
}
|
||||
|
||||
protected override void Init(IDiagramViewModel root, bool initNew)
|
||||
{
|
||||
base.Init(root, initNew);
|
||||
}
|
||||
|
||||
protected override void InitNew()
|
||||
{
|
||||
ClearConnectors();
|
||||
}
|
||||
|
||||
protected override void LoadDesignerItemViewModel(SelectableItemBase designerbase)
|
||||
{
|
||||
base.LoadDesignerItemViewModel(designerbase);
|
||||
|
||||
if (designerbase is DrawingDesignerItemBase designer)
|
||||
{
|
||||
this.Erasable = designer.Erasable;
|
||||
this.Geometry = Geometry.Parse(designer.Geometry).GetFlattenedPathGeometry();
|
||||
this.Points = designer.Points;
|
||||
this.DrawMode = designer.DrawMode;
|
||||
this.DisableSelected = Erasable;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool OnMouseMove(IInputElement sender, MouseEventArgs e)
|
||||
@@ -53,14 +94,17 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
UpdateLocation();
|
||||
|
||||
Geometry.Transform = new TranslateTransform(0 - Left, 0 - Top);
|
||||
|
||||
if (Erasable)
|
||||
if (Geometry != null)
|
||||
{
|
||||
var aPen = new Pen(ColorObject.ToBrush(ColorViewModel.LineColor), ColorViewModel.LineWidth);
|
||||
Geometry = Geometry.GetWidenedPathGeometry(aPen); //可擦除,需要把Geometry转成几何图像,所以不能有填充色
|
||||
}
|
||||
Geometry.Transform = new TranslateTransform(0 - Left, 0 - Top);
|
||||
|
||||
if (Erasable)
|
||||
{
|
||||
var aPen = new Pen(ColorViewModel.LineColor.ToBrush(), ColorViewModel.LineWidth);
|
||||
aPen.DashStyle = new DashStyle(StrokeDashArray.Dash[(int)ColorViewModel.LineDashStyle], 1);
|
||||
Geometry = Geometry.GetWidenedPathGeometry(aPen); //可擦除,需要把Geometry转成几何图像,所以不能有填充色
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -120,6 +164,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
SetProperty(ref _points, value);
|
||||
}
|
||||
}
|
||||
|
||||
public DrawMode DrawMode
|
||||
{
|
||||
get; set;
|
||||
@@ -127,21 +172,11 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
public void UpdateLocation()
|
||||
{
|
||||
ItemWidth = Geometry.Bounds.Width + ColorViewModel.LineWidth;
|
||||
ItemHeight = Geometry.Bounds.Height + ColorViewModel.LineWidth;
|
||||
ItemWidth = Geometry.Bounds.Width + ColorViewModel.LineWidth * 2;
|
||||
ItemHeight = Geometry.Bounds.Height + ColorViewModel.LineWidth * 2;
|
||||
Left = Geometry.Bounds.Left;
|
||||
Top = Geometry.Bounds.Top;
|
||||
}
|
||||
|
||||
protected override void Init(IDiagramViewModel root, bool initNew)
|
||||
{
|
||||
base.Init(root, initNew);
|
||||
}
|
||||
|
||||
protected override void InitNew()
|
||||
{
|
||||
ClearConnectors();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
@@ -15,16 +16,18 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
}
|
||||
|
||||
public EllipseDrawingDesignerItemViewModel(IDiagramViewModel root) : base(root)
|
||||
{
|
||||
}
|
||||
|
||||
public EllipseDrawingDesignerItemViewModel(IDiagramViewModel root, Point startPoint, bool erasable) : base(root, DrawMode.ErasableRectangle, startPoint, erasable)
|
||||
{
|
||||
}
|
||||
|
||||
public EllipseDrawingDesignerItemViewModel(IDiagramViewModel root, List<Point> points, bool erasable) : base(root, DrawMode.ErasableRectangle, points, erasable)
|
||||
public EllipseDrawingDesignerItemViewModel(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public EllipseDrawingDesignerItemViewModel(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override bool OnMouseMove(IInputElement sender, MouseEventArgs e)
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.Windows;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
using SvgPathProperties;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
@@ -17,16 +18,18 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
}
|
||||
|
||||
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 EraserDrawingDesignerItemViewModel(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public EraserDrawingDesignerItemViewModel(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override bool OnMouseMove(IInputElement sender, MouseEventArgs e)
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.Windows;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
using SvgPathProperties;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
@@ -17,16 +18,18 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
}
|
||||
|
||||
public EraserPreviewDrawingDesignerItemViewModel(IDiagramViewModel root) : base(root)
|
||||
{
|
||||
}
|
||||
|
||||
public EraserPreviewDrawingDesignerItemViewModel(IDiagramViewModel root, Point startPoint) : base(root, DrawMode.Eraser, startPoint, true)
|
||||
{
|
||||
}
|
||||
|
||||
public EraserPreviewDrawingDesignerItemViewModel(IDiagramViewModel root, List<Point> points) : base(root, DrawMode.Eraser, points, true)
|
||||
public EraserPreviewDrawingDesignerItemViewModel(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public EraserPreviewDrawingDesignerItemViewModel(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override bool OnMouseMove(IInputElement sender, MouseEventArgs e)
|
||||
@@ -88,7 +91,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
List<DrawingDesignerItemViewModelBase> deleteDrawGeometries = new List<DrawingDesignerItemViewModelBase>();
|
||||
foreach (var g in this.Root.Items.OfType<DrawingDesignerItemViewModelBase>())
|
||||
{
|
||||
if (g.Erase(geometry.GetWidenedPathGeometry(new Pen(ColorObject.ToBrush(ColorViewModel.LineColor), ColorViewModel.LineWidth))))
|
||||
if (g.Erase(geometry.GetWidenedPathGeometry(new Pen(ColorViewModel.LineColor.ToBrush(), ColorViewModel.LineWidth))))
|
||||
deleteDrawGeometries.Add(g);
|
||||
else
|
||||
empty = false;
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
@@ -16,15 +17,16 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
}
|
||||
|
||||
public LineDrawingDesignerItemViewModel(IDiagramViewModel root) : base(root)
|
||||
{
|
||||
}
|
||||
|
||||
public LineDrawingDesignerItemViewModel(IDiagramViewModel root, Point startPoint, bool erasable) : base(root, DrawMode.ErasableLine, startPoint, erasable)
|
||||
{
|
||||
}
|
||||
|
||||
public LineDrawingDesignerItemViewModel(IDiagramViewModel root, List<Point> points, bool erasable) : base(root, DrawMode.ErasableLine, points, erasable)
|
||||
public LineDrawingDesignerItemViewModel(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public LineDrawingDesignerItemViewModel(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
@@ -12,15 +13,16 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
}
|
||||
|
||||
public PolygonDrawingDesignerItemViewModel(IDiagramViewModel root) : base(root)
|
||||
{
|
||||
}
|
||||
|
||||
public PolygonDrawingDesignerItemViewModel(IDiagramViewModel root, Point startPoint, bool erasable) : base(root, DrawMode.ErasableLine, startPoint, erasable)
|
||||
{
|
||||
}
|
||||
|
||||
public PolygonDrawingDesignerItemViewModel(IDiagramViewModel root, List<Point> points, bool erasable) : base(root, DrawMode.ErasableLine, points, erasable)
|
||||
public PolygonDrawingDesignerItemViewModel(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public PolygonDrawingDesignerItemViewModel(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ using System.Windows;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
@@ -17,15 +18,16 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
}
|
||||
|
||||
public PolylineDrawingDesignerItemViewModel(IDiagramViewModel root) : base(root)
|
||||
{
|
||||
}
|
||||
|
||||
public PolylineDrawingDesignerItemViewModel(IDiagramViewModel root, Point startPoint, bool erasable) : base(root, DrawMode.ErasableLine, startPoint, erasable)
|
||||
{
|
||||
}
|
||||
|
||||
public PolylineDrawingDesignerItemViewModel(IDiagramViewModel root, List<Point> points, bool erasable) : base(root, DrawMode.ErasableLine, points, erasable)
|
||||
public PolylineDrawingDesignerItemViewModel(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public PolylineDrawingDesignerItemViewModel(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
@@ -15,16 +16,18 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
}
|
||||
|
||||
public RectangleDrawingDesignerItemViewModel(IDiagramViewModel root) : base(root)
|
||||
{
|
||||
}
|
||||
|
||||
public RectangleDrawingDesignerItemViewModel(IDiagramViewModel root, Point startPoint, bool erasable) : base(root, DrawMode.ErasableRectangle, startPoint, erasable)
|
||||
{
|
||||
}
|
||||
|
||||
public RectangleDrawingDesignerItemViewModel(IDiagramViewModel root, List<Point> points, bool erasable) : base(root, DrawMode.ErasableRectangle, points, erasable)
|
||||
public RectangleDrawingDesignerItemViewModel(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public RectangleDrawingDesignerItemViewModel(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override bool OnMouseMove(IInputElement sender, MouseEventArgs e)
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class TextDrawingDesignerItemViewModel : DrawingDesignerItemViewModelBase
|
||||
{
|
||||
public TextDrawingDesignerItemViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
public TextDrawingDesignerItemViewModel(IDiagramViewModel root, Point startPoint, bool erasable) : base(root, DrawMode.ErasableRectangle, startPoint, erasable)
|
||||
{
|
||||
AddTextBox();
|
||||
}
|
||||
|
||||
public TextDrawingDesignerItemViewModel(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public TextDrawingDesignerItemViewModel(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override bool OnMouseMove(IInputElement sender, MouseEventArgs e)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool OnMouseDown(IInputElement sender, MouseButtonEventArgs e)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool OnMouseUp(IInputElement sender, MouseButtonEventArgs e)
|
||||
{
|
||||
return base.OnMouseUp(sender, e);
|
||||
}
|
||||
|
||||
protected override void Init(IDiagramViewModel root, bool initNew)
|
||||
{
|
||||
base.Init(root, initNew);
|
||||
|
||||
CustomText = true;
|
||||
}
|
||||
|
||||
TextDesignerItemViewModel _previewTextDesign;
|
||||
public void AddTextBox()
|
||||
{
|
||||
_previewTextDesign = new TextAutoDesignerItemViewModel(this.Root);
|
||||
_previewTextDesign.FontViewModel = CopyHelper.Mapper(this.FontViewModel);
|
||||
_previewTextDesign.FontViewModel.FontColor = this.ColorViewModel.LineColor.Color;
|
||||
_previewTextDesign.FontViewModel.HorizontalAlignment = HorizontalAlignment.Left;
|
||||
_previewTextDesign.FontViewModel.VerticalAlignment = VerticalAlignment.Top;
|
||||
_previewTextDesign.Left = Points[0].X;
|
||||
_previewTextDesign.Top = Points[0].Y;
|
||||
Root?.Add(_previewTextDesign, true);
|
||||
_previewTextDesign.PropertyChanged += _previewTextDesign_PropertyChanged;
|
||||
}
|
||||
|
||||
private void _previewTextDesign_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName== nameof(IsEditing) && _previewTextDesign.IsEditing == false)
|
||||
{
|
||||
_previewTextDesign.PropertyChanged -= _previewTextDesign_PropertyChanged;
|
||||
Root?.Remove(_previewTextDesign);
|
||||
|
||||
Text = _previewTextDesign?.Text;
|
||||
if (!string.IsNullOrEmpty(Text))
|
||||
{
|
||||
var typeface = new Typeface(new FontFamily(FontViewModel.FontFamily), FontViewModel.FontStyle, FontViewModel.FontWeight, FontViewModel.FontStretch);
|
||||
var formattedText = new FormattedText(_previewTextDesign?.Text,
|
||||
System.Globalization.CultureInfo.InvariantCulture,
|
||||
FlowDirection.LeftToRight,
|
||||
typeface,
|
||||
FontViewModel.FontSize,
|
||||
new SolidColorBrush(FontViewModel.FontColor));
|
||||
|
||||
Geometry = formattedText.BuildGeometry(new Point()).GetFlattenedPathGeometry();
|
||||
IsFinish = true;
|
||||
|
||||
this.ItemWidth = _previewTextDesign.ItemWidth;
|
||||
this.ItemHeight = _previewTextDesign.ItemHeight;
|
||||
this.Left = _previewTextDesign.Left + 2 + Geometry.Bounds.Left;
|
||||
this.Top = _previewTextDesign.Top + 2 + Geometry.Bounds.Top;
|
||||
this.Root?.AddItemCommand.Execute(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user