Skip to content
Prev Previous commit
feat: path is now moveable
  • Loading branch information
JeremyMeissner committed May 4, 2022
commit 14ac31746f2e2ed5e7dc35eebe0f5b0f18f6f1e2
76 changes: 28 additions & 48 deletions FreeFrame/Components/Shapes/Path/DrawAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ namespace FreeFrame.Components.Shapes.Path
public abstract class DrawAttribute
{
int _x, _y, _x1, _y1 = 0;

private bool _isRelative;
public bool IsRelative { get => _isRelative; protected set => _isRelative = value; }
public int Y1 { get => _y1; protected set => _y1 = value; }
public int X1 { get => _x1; protected set => _x1 = value; }
public int X { get => _x; protected set => _x = value; }
public int Y { get => _y; protected set => _y = value; }
public int X { get => _x; set => _x = value; }
public int Y { get => _y; set => _y = value; }


public static (int X, int Y, int X1, int Y1) Last = (0, 0, 0, 0);
Expand All @@ -43,10 +46,6 @@ public abstract class DrawAttribute
/// </summary>
public class MoveTo : DrawAttribute
{
bool _isRelative;

public bool IsRelative { get => _isRelative; private set => _isRelative = value; }

/// <summary>
/// Moving the current point to another point.
/// </summary>
Expand Down Expand Up @@ -106,9 +105,6 @@ public override void MoveDelta(Vector2i deltaPosition)
/// </summary>
public class LineTo : DrawAttribute
{
bool _isRelative;
public bool IsRelative { get => _isRelative; private set => _isRelative = value; }

/// <summary>
/// Use to draw a straight line from the current point to the given point.
/// </summary>
Expand Down Expand Up @@ -158,8 +154,8 @@ public override List<Vector2i> GetSelectablePoints()

if (IsRelative)
{
points.Add(new Vector2i(Last.X - X, Last.Y - Y));
points.Add(new Vector2i(Last.X, Last.Y));
points.Add(new Vector2i(Last.X + X, Last.Y + Y));
}
else
{
Expand All @@ -183,9 +179,6 @@ public override void MoveDelta(Vector2i deltaPosition)
/// </summary>
public class HorizontalLineTo : DrawAttribute
{
bool _isRelative;
public bool IsRelative { get => _isRelative; private set => _isRelative = value; }

/// <summary>
/// Use to draw a horizontal line from the current point to the given point.
/// </summary>
Expand Down Expand Up @@ -256,9 +249,6 @@ public override void MoveDelta(Vector2i deltaPosition)
/// </summary>
public class VerticalLineTo : DrawAttribute
{
bool _isRelative;
public bool IsRelative { get => _isRelative; set => _isRelative = value; }

/// <summary>
/// Use to draw a vertical line from the current point to the given point.
/// </summary>
Expand Down Expand Up @@ -302,7 +292,7 @@ public override List<Vector2i> GetSelectablePoints()
if (IsRelative)
{
points.Add(new Vector2i(Last.X, Last.Y));
points.Add(new Vector2i(Last.X, Last.Y + Y));
points.Add(new Vector2i(Last.X, Last.Y));
}
else
{
Expand Down Expand Up @@ -331,7 +321,6 @@ public override (Vector2i position, Vector2i? controlPosition) Information()
/// </summary>
public class CurveTo : DrawAttribute
{
bool _isRelative;
int _x2;
int _y2;

Expand Down Expand Up @@ -367,7 +356,7 @@ public CurveTo(int x1, int y1, int x2, int y2, int x, int y, bool isRelative = f
Y2 = y2;
X = x;
Y = y;
_isRelative = isRelative;
IsRelative = isRelative;
}
public override float[] GetVertices()
{
Expand All @@ -376,7 +365,7 @@ public override float[] GetVertices()
float x, y;

// Only edges
if (_isRelative)
if (IsRelative)
{
for (int i = 0; i < 100; i++) // TODO: Magic value please dont hard code this
{
Expand Down Expand Up @@ -425,24 +414,24 @@ public override List<Vector2i> GetSelectablePoints()
{
List<Vector2i> points = new List<Vector2i>();

if (_isRelative)
if (IsRelative)
{
//points.Add(new Vector2i(Last.X - X1, Last.Y - Y1));
//points.Add(new Vector2i(Last.X - X2, Last.Y - Y2));
points.Add(new Vector2i(Last.X - X, Last.Y - Y));
points.Add(new Vector2i(Last.X, Last.Y));
points.Add(new Vector2i(Last.X + X1, Last.Y + Y1));
points.Add(new Vector2i(Last.X + X2, Last.Y + X2));
points.Add(new Vector2i(Last.X + X, Last.Y + Y));
}
else
{
points.Add(new Vector2i(Last.X, Last.Y));
points.Add(new Vector2i(X1, Y1));
points.Add(new Vector2i(X2, X2));
//points.Add(new Vector2i(X1, Y1));
//points.Add(new Vector2i(X2, Y2));
points.Add(new Vector2i(X, Y));
}
return points;
}

public override string ToString() => String.Format("{0} {1},{2} {3},{4} {5},{6}", _isRelative ? 'c' : 'C', X1, Y1, X2, Y2, X, Y);
public override string ToString() => String.Format("{0} {1},{2} {3},{4} {5},{6}", IsRelative ? 'c' : 'C', X1, Y1, X2, Y2, X, Y);

public override void MoveDelta(Vector2i deltaPosition)
{
Expand All @@ -467,13 +456,11 @@ public override (Vector2i position, Vector2i? controlPosition) Information()
/// </summary>
public class SmoothCurveTo : DrawAttribute
{
bool _isRelative;
int _x2;
int _y2;

public int X2 { get => _x2; private set => _x2 = value; }
public int Y2 { get => _y2; private set => _y2 = value; }
public bool IsRelative { get => _isRelative; private set => _isRelative = value; }

/// <summary>
/// Use to draw a smooth cubic Bézier curve from the current point to the given point.
Expand Down Expand Up @@ -534,7 +521,7 @@ public override float[] GetVertices()
t = i / 100.0f;

x = (float)(Math.Pow((1 - t), 3) * Last.X + 3 * Math.Pow((1 - t), 2) * t * Last.X1 + 3 * (1 - t) * Math.Pow(t, 2) * X2 + Math.Pow(t, 3) * X);
y = (float)(Math.Pow((1 - t), 3) * Last.Y + 3 * Math.Pow((1 - t), 2) * t * Last.X1 + 3 * (1 - t) * Math.Pow(t, 2) * Y2 + Math.Pow(t, 3) * Y);
y = (float)(Math.Pow((1 - t), 3) * Last.Y + 3 * Math.Pow((1 - t), 2) * t * Last.Y1 + 3 * (1 - t) * Math.Pow(t, 2) * Y2 + Math.Pow(t, 3) * Y);

vertices.AddRange(new float[] { x, y });
}
Expand All @@ -558,16 +545,16 @@ public override List<Vector2i> GetSelectablePoints()

if (IsRelative)
{
points.Add(new Vector2i(Last.X - Last.X1, Last.Y - Last.Y1));
points.Add(new Vector2i(Last.X - X2, Last.Y - Y2));
points.Add(new Vector2i(Last.X - X, Last.Y - Y));
points.Add(new Vector2i(Last.X, Last.Y));
points.Add(new Vector2i(Last.X + Last.X1, Last.Y + Last.Y1));
points.Add(new Vector2i(Last.X + X2, Last.Y + X2));
points.Add(new Vector2i(Last.X + X, Last.Y + Y));
}
else
{
points.Add(new Vector2i(Last.X, Last.Y));
points.Add(new Vector2i(Last.X1, Last.Y1));
points.Add(new Vector2i(X2, X2));
points.Add(new Vector2i(X2, Y2));
points.Add(new Vector2i(X, Y));
}
return points;
Expand All @@ -591,9 +578,6 @@ public override (Vector2i position, Vector2i? controlPosition) Information()
/// </summary>
public class QuadraticBezierCurveTo : DrawAttribute
{
bool _isRelative;
public bool IsRelative { get => _isRelative; set => _isRelative = value; }

/// <summary>
/// Use to draw a quadratic Bézier curve.
/// </summary>
Expand Down Expand Up @@ -627,7 +611,7 @@ public override float[] GetVertices()
float x, y;

// Only edges
if (_isRelative)
if (IsRelative)
{
for (int i = 0; i < 100; i++) // TODO: Magic value please dont hard code this
{
Expand Down Expand Up @@ -678,9 +662,9 @@ public override List<Vector2i> GetSelectablePoints()

if (IsRelative)
{
points.Add(new Vector2i(Last.X - X1, Last.Y - Y1));
points.Add(new Vector2i(Last.X - X, Last.Y - Y));
points.Add(new Vector2i(Last.X, Last.Y));
points.Add(new Vector2i(Last.X + X1, Last.Y + Y1));
points.Add(new Vector2i(Last.X + X, Last.Y + Y));
}
else
{
Expand Down Expand Up @@ -710,9 +694,6 @@ public override (Vector2i position, Vector2i? controlPosition) Information()
/// </summary>
public class SmoothQuadraticBezierCurveTo : DrawAttribute
{
bool _isRelative;
public bool IsRelative { get => _isRelative; set => _isRelative = value; }

/// <summary>
/// Use to draw a smooth quadratic Bézier curve.
/// </summary>
Expand Down Expand Up @@ -791,9 +772,9 @@ public override List<Vector2i> GetSelectablePoints()

if (IsRelative)
{
points.Add(new Vector2i(Last.X - Last.X1, Last.Y - Last.Y1));
points.Add(new Vector2i(Last.X - X, Last.Y - Y));
points.Add(new Vector2i(Last.X, Last.Y));
points.Add(new Vector2i(Last.X + Last.X1, Last.Y + Last.Y1));
points.Add(new Vector2i(Last.X + X, Last.Y + Y));
}
else
{
Expand Down Expand Up @@ -824,7 +805,6 @@ public override (Vector2i position, Vector2i? controlPosition) Information()
/// </summary>
public class EllipticalArc : DrawAttribute
{
bool _isRelative;
int _rx;
int _ry;
int _angle;
Expand Down Expand Up @@ -863,7 +843,7 @@ public EllipticalArc(int rx, int ry, int angle, bool largeArcFlag, bool sweepFla
_sweepFlag = sweepFlag;
X = x;
Y = y;
_isRelative = isRelative;
IsRelative = isRelative;
}

public override List<Vector2i> GetSelectablePoints()
Expand All @@ -888,7 +868,7 @@ public override (Vector2i position, Vector2i? controlPosition) Information()
{
throw new NotImplementedException();
}
public override string ToString() => String.Format("{0} {1} {2} {3} {4} {5} {6},{7}", _isRelative ? 'a' : 'A', _rx, _ry, _angle, Convert.ToInt32(_largeArcFlag), Convert.ToInt32(_sweepFlag), X, Y);
public override string ToString() => String.Format("{0} {1} {2} {3} {4} {5} {6},{7}", IsRelative ? 'a' : 'A', _rx, _ry, _angle, Convert.ToInt32(_largeArcFlag), Convert.ToInt32(_sweepFlag), X, Y);
}
/// <summary>
/// ClosePath, Z or z.
Expand Down
Loading