画板基础基本完成

This commit is contained in:
艾竹
2023-05-14 00:31:25 +08:00
parent 147a84cf91
commit 8003cebf99
40 changed files with 3198 additions and 374 deletions

View File

@@ -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