|
@@ -12,6 +12,9 @@ public class RectangleVectorData : ShapeVectorData, IReadOnlyRectangleData
|
|
|
{
|
|
|
public VecD Center { get; set; }
|
|
|
public VecD Size { get; set; }
|
|
|
+ public double CornerRadius { get; set; }
|
|
|
+ public StrokeJoin StrokeLineJoin { get; set; } = StrokeJoin.Round;
|
|
|
+ public StrokeCap StrokeLineCap { get; } = StrokeCap.Butt;
|
|
|
|
|
|
public override RectD GeometryAABB => RectD.FromCenterAndSize(Center, Size);
|
|
|
|
|
@@ -67,7 +70,7 @@ public class RectangleVectorData : ShapeVectorData, IReadOnlyRectangleData
|
|
|
{
|
|
|
paint.SetPaintable(FillPaintable);
|
|
|
paint.Style = PaintStyle.Fill;
|
|
|
- canvas.DrawRect(RectD.FromCenterAndSize(Center, Size), paint);
|
|
|
+ DrawRect(canvas, paint);
|
|
|
}
|
|
|
|
|
|
if (StrokeWidth > 0 && Stroke.AnythingVisible)
|
|
@@ -76,7 +79,10 @@ public class RectangleVectorData : ShapeVectorData, IReadOnlyRectangleData
|
|
|
paint.Style = PaintStyle.Stroke;
|
|
|
|
|
|
paint.StrokeWidth = StrokeWidth;
|
|
|
- canvas.DrawRect(RectD.FromCenterAndSize(Center, Size), paint);
|
|
|
+ paint.StrokeCap = StrokeLineCap;
|
|
|
+ paint.StrokeJoin = StrokeLineJoin;
|
|
|
+
|
|
|
+ DrawRect(canvas, paint);
|
|
|
}
|
|
|
|
|
|
if (applyTransform)
|
|
@@ -85,6 +91,19 @@ public class RectangleVectorData : ShapeVectorData, IReadOnlyRectangleData
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void DrawRect(Canvas canvas, Paint paint)
|
|
|
+ {
|
|
|
+ if (CornerRadius == 0)
|
|
|
+ {
|
|
|
+ canvas.DrawRect(RectD.FromCenterAndSize(Center, Size), paint);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ RectD rect = RectD.FromCenterAndSize(Center, Size);
|
|
|
+ canvas.DrawRoundRect((float)rect.Pos.X, (float)rect.Pos.Y, (float)rect.Width, (float)rect.Height, (float)CornerRadius, (float)CornerRadius, paint);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public override bool IsValid()
|
|
|
{
|
|
|
return Size is { X: > 0, Y: > 0 };
|
|
@@ -92,13 +111,21 @@ public class RectangleVectorData : ShapeVectorData, IReadOnlyRectangleData
|
|
|
|
|
|
protected override int GetSpecificHash()
|
|
|
{
|
|
|
- return HashCode.Combine(Center, Size);
|
|
|
+ return HashCode.Combine(Center, Size, StrokeLineCap, StrokeLineJoin, CornerRadius);
|
|
|
}
|
|
|
|
|
|
public override VectorPath ToPath(bool transformed = false)
|
|
|
{
|
|
|
VectorPath path = new VectorPath();
|
|
|
- path.AddRect(RectD.FromCenterAndSize(Center, Size));
|
|
|
+ if (CornerRadius == 0)
|
|
|
+ {
|
|
|
+ path.AddRect(RectD.FromCenterAndSize(Center, Size));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ path.AddRoundRect(RectD.FromCenterAndSize(Center, Size), new VecD(CornerRadius));
|
|
|
+ }
|
|
|
+
|
|
|
if (transformed)
|
|
|
{
|
|
|
path.Transform(TransformationMatrix);
|
|
@@ -109,7 +136,9 @@ public class RectangleVectorData : ShapeVectorData, IReadOnlyRectangleData
|
|
|
|
|
|
protected bool Equals(RectangleVectorData other)
|
|
|
{
|
|
|
- return base.Equals(other) && Center.Equals(other.Center) && Size.Equals(other.Size);
|
|
|
+ return base.Equals(other) && Center.Equals(other.Center) && Size.Equals(other.Size) &&
|
|
|
+ StrokeLineJoin == other.StrokeLineJoin && StrokeLineCap == other.StrokeLineCap &&
|
|
|
+ CornerRadius.Equals(other.CornerRadius);
|
|
|
}
|
|
|
|
|
|
public override bool Equals(object? obj)
|
|
@@ -134,6 +163,6 @@ public class RectangleVectorData : ShapeVectorData, IReadOnlyRectangleData
|
|
|
|
|
|
public override int GetHashCode()
|
|
|
{
|
|
|
- return HashCode.Combine(base.GetHashCode(), Center, Size);
|
|
|
+ return HashCode.Combine(base.GetHashCode(), Center, Size, StrokeLineJoin, StrokeLineCap, CornerRadius);
|
|
|
}
|
|
|
}
|