mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-03 00:00:57 +08:00
画板基础基本完成
This commit is contained in:
@@ -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