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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user