Skip to content

Commit bedd28c

Browse files
Merge pull request #18 from JeremyMeissner/3-primitive-shapes-tool
Primitive shapes tool
2 parents b43de41 + 01e6e65 commit bedd28c

16 files changed

Lines changed: 675 additions & 655 deletions

FreeFrame/Components/Shapes/Path/DrawAttribute.cs

Lines changed: 180 additions & 122 deletions
Large diffs are not rendered by default.
Lines changed: 28 additions & 21 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.Drawing;
@@ -9,11 +10,6 @@ namespace FreeFrame.Components.Shapes
910
{
1011
public class SVGCircle : Shape
1112
{
12-
#region Geometry properties
13-
private int _cx;
14-
private int _cy;
15-
private int _r;
16-
#endregion
1713
public SVGCircle(XmlReader reader) : this(
1814
Convert.ToInt32(reader["r"]),
1915
Convert.ToInt32(reader["cx"]),
@@ -22,41 +18,52 @@ public SVGCircle(XmlReader reader) : this(
2218
public SVGCircle() : this(0, 0, 0) { }
2319
public SVGCircle(int r, int cx, int cy)
2420
{
25-
_cx = cx;
26-
_cy = cy;
27-
_r = r;
28-
}
29-
public override void Draw(Vector2i clientSize) => throw new NotImplementedException();
21+
IsCornerRadiusChangeable = false;
22+
X = cx - r;
23+
Y = cy - r;
24+
Height = r*2;
25+
Width = Height;
3026

31-
public override string ToString() => $"cx: {_cx}, cy: {_cy}, r: {_r}";
27+
ImplementObject();
28+
}
3229

33-
public override float[] GetVertices() => new float[] { _cx - _r, _cy - _r, _cx + _r, _cy - _r, _cx + _r, _cy + _r, _cx - _r, _cy + _r }; // x, y, x, y, x, y, ... (clockwise)
30+
public override string ToString() => $"cx: {X + Width / 2}, cy: {Y + Height / 2}, r: {Width / 2}";
3431

32+
public override float[] GetVertices() => new float[] { X, Y, X + Width, Y, X + Width, Y + Height, X, Y + Height }; // x, y, x, y, x, y, ... (clockwise)
3533
public override uint[] GetVerticesIndexes() => new uint[] { 0, 1, 2, 0, 2, 3 }; // TODO: please dont hardcode
3634

37-
public override Hitbox Hitbox()
38-
{
39-
throw new NotImplementedException();
40-
}
4135

4236
public override List<Vector2i> GetSelectablePoints()
4337
{
44-
throw new NotImplementedException();
38+
List<Vector2i> points = new();
39+
points.Add(new Vector2i(X, Y));
40+
points.Add(new Vector2i(X + Width, Y));
41+
points.Add(new Vector2i(X + Width, Y + Height));
42+
points.Add(new Vector2i(X, Y + Height));
43+
return points;
4544
}
4645

4746
public override void ImplementObject()
4847
{
49-
throw new NotImplementedException();
48+
foreach (VertexArrayObject vao in _vaos)
49+
vao.DeleteObjects();
50+
_vaos.Clear();
51+
52+
_vaos.Add(new VertexArrayObject(GetVertices(), GetVerticesIndexes(), PrimitiveType.Triangles, this));
5053
}
5154

5255
public override void Move(Vector2i position)
5356
{
54-
throw new NotImplementedException();
57+
X = position.X;
58+
Y = position.Y;
59+
ImplementObject();
5560
}
5661

5762
public override void Resize(Vector2i size)
5863
{
59-
throw new NotImplementedException();
64+
Width = size.X;
65+
Height = size.Y;
66+
ImplementObject();
6067
}
6168
}
6269
}

FreeFrame/Components/Shapes/SVGLine.cs

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ internal class SVGLine : Shape
1818
const int DefaultY2 = 0;
1919
#endregion
2020

21-
#region Geometry properties
22-
#endregion
23-
2421
public SVGLine(XmlReader reader) : this(
2522
Convert.ToInt32(reader["x1"]),
2623
Convert.ToInt32(reader["y1"]),
@@ -31,6 +28,8 @@ public SVGLine(XmlReader reader) : this(
3128
public SVGLine() : this(DefaultX1, DefaultY1, DefaultX2, DefaultY2) { }
3229
public SVGLine(int x1, int y1, int x2, int y2)
3330
{
31+
IsCornerRadiusChangeable = false;
32+
3433
X = x1;
3534
Y = y1;
3635
Width = x2 - X;
@@ -40,49 +39,29 @@ public SVGLine(int x1, int y1, int x2, int y2)
4039
}
4140
public override float[] GetVertices() => new float[] { X, Y, Width + X, Height + Y }; // x, y, x, y, x, y, ... (clockwise)
4241
public override uint[] GetVerticesIndexes() => new uint[] { 0, 1 }; // TODO: please dont hardcode
43-
44-
public override void Draw(Vector2i clientSize)
45-
{
46-
foreach (VertexArrayObject vao in _vaos)
47-
vao.Draw(clientSize, Color); // Because that color doesnt depend of the shape TODO: Make it dependend
48-
}
4942
public override string ToString() => $"x1: {X}, y1: {Y}, x2: {Width + X}, y2: {Height + Y}";
50-
51-
public override Hitbox Hitbox()
52-
{
53-
Hitbox hitbox = new Hitbox();
54-
55-
//hitbox.Areas.Add(new Hitbox.Area(X, Y, X2, Y2));
56-
57-
return hitbox;
58-
}
59-
6043
public override List<Vector2i> GetSelectablePoints()
6144
{
6245
List<Vector2i> points = new();
6346
points.Add(new Vector2i(X, Y));
6447
points.Add(new Vector2i(Width + X, Height + Y));
6548
return points;
6649
}
67-
68-
6950
public override void ImplementObject()
7051
{
7152
foreach (VertexArrayObject vao in _vaos)
7253
vao.DeleteObjects();
7354
_vaos.Clear();
7455

75-
_vaos.Add(new VertexArrayObject(GetVertices(), GetVerticesIndexes(), PrimitiveType.Lines));
56+
_vaos.Add(new VertexArrayObject(GetVertices(), GetVerticesIndexes(), PrimitiveType.Lines, this ));
7657
}
77-
7858
public override void Move(Vector2i position)
7959
{
8060
X = position.X;
8161
Y = position.Y;
8262

8363
ImplementObject();
8464
}
85-
8665
public override void Resize(Vector2i size)
8766
{
8867
Width = size.X;

0 commit comments

Comments
 (0)