Skip to content

Commit 428390e

Browse files
chore: edit svg path element
1 parent 8f3549c commit 428390e

9 files changed

Lines changed: 505 additions & 55 deletions

File tree

FreeFrame/Components/Shapes/Path/DrawAttribute.cs

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public abstract class DrawAttribute
3838
/// <returns>array of vertices position. x, y, x, y, ... (clockwise)</returns>
3939
public abstract float[] GetVertices();
4040
public abstract uint[] GetVerticesIndexes();
41+
public abstract void MoveDelta(Vector2i deltaPosition);
42+
public abstract void ResizeDelta(Vector2i size);
4143

4244
public abstract List<Vector2i> GetSelectablePoints();
4345

@@ -100,6 +102,16 @@ public override uint[] GetVerticesIndexes()
100102
public override string ToString() => String.Format("{0} {1},{2}", IsRelative ? 'm' : 'M', X, Y);
101103

102104
public override List<Vector2i> GetSelectablePoints() => new List<Vector2i>();
105+
106+
public override void MoveDelta(Vector2i deltaPosition)
107+
{
108+
//throw new NotImplementedException();
109+
}
110+
111+
public override void ResizeDelta(Vector2i size)
112+
{
113+
//throw new NotImplementedException();
114+
}
103115
}
104116
/// <summary>
105117
/// LineTo, L or l.
@@ -175,6 +187,18 @@ public override List<Vector2i> GetSelectablePoints()
175187
}
176188
return points;
177189
}
190+
191+
public override void MoveDelta(Vector2i deltaPosition)
192+
{
193+
X += deltaPosition.X;
194+
Y += deltaPosition.Y;
195+
}
196+
197+
public override void ResizeDelta(Vector2i deltaSize)
198+
{
199+
X += deltaSize.X;
200+
Y += deltaSize.Y;
201+
}
178202
}
179203
/// <summary>
180204
/// HorizontalLineTo, H or h.
@@ -246,6 +270,18 @@ public override List<Vector2i> GetSelectablePoints()
246270
}
247271
return points;
248272
}
273+
274+
public override void MoveDelta(Vector2i deltaPosition)
275+
{
276+
X += deltaPosition.X;
277+
//LastY += deltaPosition.Y;
278+
}
279+
280+
public override void ResizeDelta(Vector2i size)
281+
{
282+
X += size.X;
283+
//LastY += size.Y;
284+
}
249285
}
250286
/// <summary>
251287
/// VerticalLineTo, V or v.
@@ -311,6 +347,16 @@ public override List<Vector2i> GetSelectablePoints()
311347
}
312348

313349
public override string ToString() => String.Format("{0} {1}", _isRelative ? 'v' : 'V', _y);
350+
351+
public override void MoveDelta(Vector2i deltaPosition)
352+
{
353+
throw new NotImplementedException();
354+
}
355+
356+
public override void ResizeDelta(Vector2i size)
357+
{
358+
throw new NotImplementedException();
359+
}
314360
}
315361
/// <summary>
316362
/// CurveTo, Cubic Bézier Curve, C or c.
@@ -439,6 +485,26 @@ public override List<Vector2i> GetSelectablePoints()
439485
}
440486

441487
public override string ToString() => String.Format("{0} {1},{2} {3},{4} {5},{6}", _isRelative ? 'c' : 'C', X1, Y1, X2, Y2, X, Y);
488+
489+
public override void MoveDelta(Vector2i deltaPosition)
490+
{
491+
X1 += deltaPosition.X;
492+
Y1 += deltaPosition.Y;
493+
X2 += deltaPosition.X;
494+
Y2 += deltaPosition.Y;
495+
X += deltaPosition.X;
496+
Y += deltaPosition.Y;
497+
}
498+
499+
public override void ResizeDelta(Vector2i size)
500+
{
501+
X1 += size.X;
502+
Y1 += size.Y;
503+
X2 += size.X;
504+
Y2 += size.Y;
505+
X += size.X;
506+
Y += size.Y;
507+
}
442508
}
443509
/// <summary>
444510
/// SmoothCurveTo, Smooth Cubic Bézier Curbe, S or s.
@@ -559,6 +625,15 @@ public override List<Vector2i> GetSelectablePoints()
559625

560626
public override string ToString() => String.Format("{0} {1},{2} {3},{4}", IsRelative ? 's' : 'S', X2, Y2, X, Y);
561627

628+
public override void MoveDelta(Vector2i deltaPosition)
629+
{
630+
throw new NotImplementedException();
631+
}
632+
633+
public override void ResizeDelta(Vector2i size)
634+
{
635+
throw new NotImplementedException();
636+
}
562637
}
563638
/// <summary>
564639
/// QuadraticBezierCurveTo, Q, q.
@@ -677,6 +752,15 @@ public override List<Vector2i> GetSelectablePoints()
677752

678753
public override string ToString() => String.Format("{0} {1},{2} {3},{4}", IsRelative ? 'q' : 'Q', X1, Y1, X, Y);
679754

755+
public override void MoveDelta(Vector2i deltaPosition)
756+
{
757+
throw new NotImplementedException();
758+
}
759+
760+
public override void ResizeDelta(Vector2i size)
761+
{
762+
throw new NotImplementedException();
763+
}
680764
}
681765
/// <summary>
682766
/// SmoothQuadraticBezierCurveTo, T, t.
@@ -781,6 +865,16 @@ public override List<Vector2i> GetSelectablePoints()
781865
}
782866

783867
public override string ToString() => String.Format("{0} {1},{2}", _isRelative ? 't' : 'T', _x, _y);
868+
869+
public override void MoveDelta(Vector2i deltaPosition)
870+
{
871+
throw new NotImplementedException();
872+
}
873+
874+
public override void ResizeDelta(Vector2i size)
875+
{
876+
throw new NotImplementedException();
877+
}
784878
}
785879

786880
/// <summary>
@@ -848,6 +942,16 @@ public override uint[] GetVerticesIndexes()
848942
throw new NotImplementedException();
849943
}
850944

945+
public override void MoveDelta(Vector2i deltaPosition)
946+
{
947+
throw new NotImplementedException();
948+
}
949+
950+
public override void ResizeDelta(Vector2i size)
951+
{
952+
throw new NotImplementedException();
953+
}
954+
851955
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);
852956
}
853957
/// <summary>
@@ -876,6 +980,16 @@ public override uint[] GetVerticesIndexes()
876980
throw new NotImplementedException();
877981
}
878982

983+
public override void MoveDelta(Vector2i deltaPosition)
984+
{
985+
throw new NotImplementedException();
986+
}
987+
988+
public override void ResizeDelta(Vector2i size)
989+
{
990+
throw new NotImplementedException();
991+
}
992+
879993
public override string ToString() => "z";
880994
}
881995
}

FreeFrame/Components/Shapes/SVGCircle.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,15 @@ public override void ImplementObject()
5353
{
5454
throw new NotImplementedException();
5555
}
56+
57+
public override void Move(Vector2i position)
58+
{
59+
throw new NotImplementedException();
60+
}
61+
62+
public override void Resize(Vector2i size)
63+
{
64+
throw new NotImplementedException();
65+
}
5666
}
5767
}

FreeFrame/Components/Shapes/SVGLine.cs

Lines changed: 77 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using OpenTK.Mathematics;
1+
using OpenTK.Graphics.OpenGL4;
2+
using OpenTK.Mathematics;
23
using System;
34
using System.Collections.Generic;
45
using System.Linq;
@@ -43,35 +44,105 @@ public SVGLine(int x1, int y1, int x2, int y2)
4344
Y1 = y1;
4445
X2 = x2;
4546
Y2 = y2;
47+
48+
Properties = new DefaultProperties()
49+
{
50+
x = X1,
51+
y = Y1,
52+
width = X2 - X1,
53+
height = Y2 - Y1,
54+
color = Properties.color
55+
};
56+
57+
ImplementObject();
4658
}
4759
public override float[] GetVertices() => new float[] { X1, Y1, X2, Y2 }; // x, y, x, y, x, y, ... (clockwise)
4860
public override uint[] GetVerticesIndexes() => new uint[] { 0, 1 }; // TODO: please dont hardcode
4961

50-
public override void Draw(Vector2i clientSize) => throw new NotImplementedException();
62+
public override void Draw(Vector2i clientSize)
63+
{
64+
foreach (VertexArrayObject vao in _vaos)
65+
vao.Draw(clientSize, Properties.color); // Because that color doesnt depend of the shape TODO: Make it dependend
66+
}
5167
public override string ToString() => $"x1: {X1}, y1: {Y1}, x2: {X2}, y2: {Y2}";
5268

5369
public override Hitbox Hitbox()
5470
{
5571
Hitbox hitbox = new Hitbox();
5672

57-
hitbox.Areas.Add(new Hitbox.Area(0, 0, 0, 0)); // TODO: please dont hardcode
73+
hitbox.Areas.Add(new Hitbox.Area(X1, Y1, X2, Y2));
5874

5975
return hitbox;
6076
}
6177

6278
public override List<Vector2i> GetSelectablePoints()
6379
{
64-
throw new NotImplementedException();
80+
List<Vector2i> points = new();
81+
points.Add(new Vector2i(X1, Y1));
82+
points.Add(new Vector2i(X2, Y2));
83+
return points;
6584
}
6685

6786
public override void UpdateProperties(DefaultProperties properties)
6887
{
69-
throw new NotImplementedException();
88+
X1 = Properties.x;
89+
Y1 = Properties.y;
90+
X2 = X1 + Properties.width;
91+
Y2 = Y1 + Properties.height;
92+
93+
Properties = properties;
94+
95+
ImplementObject();
7096
}
7197

7298
public override void ImplementObject()
7399
{
74-
throw new NotImplementedException();
100+
foreach (VertexArrayObject vao in _vaos)
101+
vao.DeleteObjects();
102+
_vaos.Clear();
103+
104+
_vaos.Add(new VertexArrayObject(GetVertices(), GetVerticesIndexes(), PrimitiveType.Lines));
105+
}
106+
107+
public override void Move(Vector2i position)
108+
{
109+
int width = X2 - X1;
110+
int height = Y2 - Y1;
111+
112+
X1 = position.X;
113+
Y1 = position.Y;
114+
115+
X2 = position.X + width;
116+
Y2 = position.Y + height;
117+
118+
119+
Properties = new DefaultProperties()
120+
{
121+
x = X1,
122+
y = Y1,
123+
width = width,
124+
height = height,
125+
color = Properties.color
126+
};
127+
128+
ImplementObject();
129+
}
130+
131+
public override void Resize(Vector2i size)
132+
{
133+
X2 = X1 + size.X;
134+
Y2 = Y1 + size.Y;
135+
136+
Properties = new DefaultProperties()
137+
{
138+
x = X1,
139+
y = Y1,
140+
width = X2 - X1,
141+
height = Y2 - Y1,
142+
color = Properties.color
143+
};
144+
145+
ImplementObject();
75146
}
76147
}
77148
}

0 commit comments

Comments
 (0)