Skip to content

Commit 548a88d

Browse files
chore: change timeline logic
1 parent 1e79797 commit 548a88d

10 files changed

Lines changed: 354 additions & 175 deletions

File tree

FreeFrame/Components/Importer.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Threading.Tasks;
66
using System.Xml;
77
using FreeFrame.Components.Shapes;
8+
using OpenTK.Mathematics;
89

910
namespace FreeFrame.Components
1011
{
@@ -66,5 +67,28 @@ static public (List<Shape>, bool) ImportFromString(string pString)
6667

6768
return ImportFromStream(new MemoryStream(byteArray));
6869
}
70+
71+
static public void ExportToFile(List<Shape> shapes, Vector2i clientSize)
72+
{
73+
74+
using (FileStream fs = new FileStream("output.svg", FileMode.Create))
75+
{
76+
byte[] bytes = Encoding.ASCII.GetBytes($@"<?xml version=""1.0"" encoding=""utf-8"" ?>
77+
<svg xmlns=""http://www.w3.org/2000/svg"" version=""1.1"" width=""{clientSize.X}"" height=""{clientSize.Y}"" >" + Environment.NewLine);
78+
79+
for (int i = 0; i < bytes.Length; i++)
80+
fs.WriteByte(bytes[i]);
81+
82+
foreach (Shape shape in shapes)
83+
{
84+
bytes = Encoding.ASCII.GetBytes(shape.ToString() + Environment.NewLine);
85+
for (int i = 0; i < bytes.Length; i++)
86+
fs.WriteByte(bytes[i]);
87+
}
88+
bytes = Encoding.ASCII.GetBytes("</svg>");
89+
for (int i = 0; i < bytes.Length; i++)
90+
fs.WriteByte(bytes[i]);
91+
}
92+
}
6993
}
7094
}

FreeFrame/Components/Shapes/SVGCircle.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public SVGCircle(int r, int cx, int cy)
2727
ImplementObject();
2828
}
2929

30-
public override string ToString() => $"cx: {X + Width / 2}, cy: {Y + Height / 2}, r: {Width / 2}";
30+
public override string ToString() => $"<circle cx=\"{X + Width / 2}\" cy=\"{Y + Height / 2}\" r=\"{Width / 2}\" fill=\"{ColorToHexadecimal(Color)}\"/>";
3131

3232
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)
3333
public override uint[] GetVerticesIndexes() => new uint[] { 0, 1, 2, 0, 2, 3 }; // TODO: please dont hardcode

FreeFrame/Components/Shapes/SVGLine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public SVGLine(int x1, int y1, int x2, int y2)
3939
}
4040
public override float[] GetVertices() => new float[] { X, Y, Width + X, Height + Y }; // x, y, x, y, x, y, ... (clockwise)
4141
public override uint[] GetVerticesIndexes() => new uint[] { 0, 1 }; // TODO: please dont hardcode
42-
public override string ToString() => $"x1: {X}, y1: {Y}, x2: {Width + X}, y2: {Height + Y}";
42+
public override string ToString() => $"<line x1=\"{X}\" y1=\"{Y}\" x2=\"{Width + X}\" y2=\"{Height + Y}\" fill=\"{ColorToHexadecimal(Color)}\"/>";
4343
public override List<Vector2i> GetSelectablePoints()
4444
{
4545
List<Vector2i> points = new();

FreeFrame/Components/Shapes/SVGPath.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ public override List<Vector2i> GetSelectablePoints()
186186

187187
public override string ToString()
188188
{
189-
string output = "d: ";
189+
string output = "<path d=\"";
190190
DrawAttributes.ForEach(d => output += d.ToString() + " ");
191-
return output.Trim();
191+
return output.Trim() + $"\" fill=\"{ColorToHexadecimal(Color)}\"/>";
192192
}
193193
}
194194
}

FreeFrame/Components/Shapes/SVGRectangle.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,12 @@ public override void ImplementObject()
5050
}
5151
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)
5252
public override uint[] GetVerticesIndexes() => new uint[] { 0, 1, 2, 0, 2, 3 }; // TODO: please dont hardcode
53+
public override string ToString()
54+
{
55+
return $"<rect x=\"{X}\" y=\"{Y}\" width=\"{Width}\" height=\"{Height}\" rx=\"{CornerRadius}\" ry=\"{CornerRadius}\" fill=\"{ColorToHexadecimal(Color)}\"/>";
56+
}
57+
5358

54-
public override string ToString() => $"x: {X}, y: {Y}, width: {Width}, height: {Height}, rx: {CornerRadius}, ry: {CornerRadius}";
5559

5660
public override List<Vector2i> GetSelectablePoints()
5761
{

FreeFrame/Components/Shapes/Shape.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ public void DeleteObjects()
7676
public abstract void Move(Vector2i position);
7777
public abstract void Resize(Vector2i size);
7878
public abstract override string ToString();
79+
80+
public static string ColorToHexadecimal(Color4 color)
81+
{
82+
int r, g, b, a;
83+
r = (int)(color.R * 255);
84+
g = (int)(color.G * 255);
85+
b = (int)(color.B * 255);
86+
a = (int)(color.A * 255);
87+
return '#' + r.ToString("X2") + g.ToString("X2") + b.ToString("X2") + a.ToString("X2");
88+
}
7989
}
8090

8191
}

FreeFrame/FreeFrame.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,17 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11+
<PackageReference Include="AnimatedGif" Version="1.0.5" />
1112
<PackageReference Include="Delaunator" Version="1.0.9" />
13+
<PackageReference Include="Emgu.CV" Version="4.5.5.4823" />
14+
<PackageReference Include="Emgu.CV.Bitmap" Version="4.5.5.4823" />
15+
<PackageReference Include="Emgu.CV.runtime.ubuntu.20.04-x64" Version="4.5.5.4823" />
16+
<PackageReference Include="Emgu.CV.runtime.windows" Version="4.5.5.4823" />
17+
<PackageReference Include="GifMotion" Version="1.0.4" />
1218
<PackageReference Include="ImGui.NET" Version="1.87.3" />
1319
<PackageReference Include="MathNet.Numerics" Version="5.0.0" />
1420
<PackageReference Include="OpenTK" Version="4.7.1" />
21+
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.1" />
1522
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
1623
</ItemGroup>
1724

FreeFrame/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ static void Main()
1515
NativeWindowSettings nativeWindowSettings = new()
1616
{
1717
Size = new Vector2i(800, 600),
18-
Title = "FreeFrame"
18+
Title = "FreeFrame",
19+
NumberOfSamples = 8,
1920
};
2021
using Window window = new(GameWindowSettings.Default, nativeWindowSettings); // Create window context (GLFW, OpenGL)
2122

0 commit comments

Comments
 (0)