Skip to content

Commit 432cd5f

Browse files
refactor: timeline
1 parent 1963b2b commit 432cd5f

3 files changed

Lines changed: 29 additions & 42 deletions

File tree

FreeFrame/Components/Shapes/Shape.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ public abstract class Shape : IDrawable
1919
#endregion
2020

2121
private List<Renderer> vaos;
22-
public virtual int X { get => _x; set => _x = value; }
23-
public virtual int Y { get => _y; set => _y = value; }
24-
public virtual int Width { get => _width; set => _width = value; }
25-
public virtual int Height { get => _height; set => _height = value; }
22+
public int X { get => _x; set => _x = value; }
23+
public int Y { get => _y; set => _y = value; }
24+
public int Width { get => _width; set => _width = Math.Max(0, value); }
25+
public int Height { get => _height; set => _height = Math.Max(0, value); }
2626
public Color4 Color { get => _color; set => _color = value; }
27+
public int Angle { get => _angle; set => _angle = value; }
2728
public bool IsMoveable { get => _isMoveable; protected set => _isMoveable = value; }
2829
public bool IsResizeable { get => _isResizeable; protected set => _isResizeable = value; }
29-
public int Angle { get => _angle; set => _angle = value; }
3030
public bool IsAngleChangeable { get => _isAngleChangeable; set => _isAngleChangeable = value; }
3131
public bool IsCornerRadiusChangeable { get => _isCornerRadiusChangeable; set => _isCornerRadiusChangeable = value; }
3232
public int CornerRadius { get => _cornerRadius; set => _cornerRadius = value; }

FreeFrame/Timeline.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ namespace FreeFrame
1212
{
1313
public class Timeline
1414
{
15-
const int DEFAULT_FPS = 24;
16-
const int MIN_FPS = 1;
17-
const int MAX_FPS = 120;
18-
const int MIN_TIMELINE = 1;
19-
const int MAX_TIMELINE = 100;
15+
public const int DEFAULT_FPS = 24;
16+
public const int MIN_FPS = 1;
17+
public const int MAX_FPS = 120;
18+
public const int MIN_TIMELINE = 1;
19+
public const int MAX_TIMELINE = 100;
2020

2121
private int _ioTimeline;
2222
private int _ioFps;

FreeFrame/Window.cs

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ enum CreateMode
5555
int _ioWidth;
5656
int _ioHeight;
5757
System.Numerics.Vector4 _ioColor;
58+
59+
System.Numerics.Vector3 _ioBgColor;
5860
bool _dialogFilePicker = false;
5961
bool _dialogCompatibility = false;
6062

@@ -88,8 +90,9 @@ protected override void OnLoad()
8890
base.OnLoad();
8991

9092
//Helper.EnableDebugMode();
93+
_ioBgColor = new System.Numerics.Vector3(0.1f, 0.1f, 0.1f);
94+
GL.ClearColor(_ioBgColor.X, _ioBgColor.Y, _ioBgColor.Z, 1.0f);
9195

92-
GL.ClearColor(0.1f, 0.1f, 0.1f, 1.0f); // TODO: Magic value
9396
GL.Enable(EnableCap.Multisample);
9497

9598
_userMode = UserMode.Idle;
@@ -138,7 +141,6 @@ protected override void OnUpdateFrame(FrameEventArgs e)
138141
x = _mouseOriginalState.X;
139142
}
140143
Title += String.Format(" (delta x: {0} delta y: {1})", x - _mouseOriginalState.X, y - _mouseOriginalState.Y);
141-
142144
}
143145

144146
// Update title based on current context
@@ -161,26 +163,6 @@ protected override void OnRenderFrame(FrameEventArgs e)
161163

162164
_timeline.OnRenderFrame(e, this);
163165

164-
if (KeyboardState.IsKeyDown(Keys.Q))
165-
{
166-
////Console.WriteLine("Draw me please");
167-
//foreach (KeyValuePair<int, List<Shape>> shapes in thetimeline)
168-
//{
169-
// foreach (Shape shape in shapes.Value)
170-
// {
171-
// shape.ImplementObject();
172-
// shape.Draw(ClientSize);
173-
// }
174-
//}
175-
//if (_selectedShape != null)
176-
// _selectedShape.ImplementObject(); // Reset VAOS for selected shape
177-
}
178-
179-
//if (KeyboardState.IsKeyDown(Keys.Space))
180-
// _userMode = UserMode.Move;
181-
//else if (KeyboardState.WasKeyDown(Keys.Space) && KeyboardState.IsKeyDown(Keys.Space) == false)
182-
// _userMode = UserMode.Idle;
183-
184166
if (KeyboardState.IsKeyDown(Keys.Escape))
185167
ResetSelection();
186168

@@ -639,17 +621,23 @@ public void ShowUI()
639621
ImGui.EndTable();
640622
}
641623

642-
ImGui.Spacing();
643-
ImGui.Separator();
644624
ImGui.Spacing();
645625

646-
ImGui.Text("Color");
647-
ImGui.Spacing();
648626
if (SelectedShape == null)
649627
ImGui.BeginDisabled();
650-
ImGui.ColorEdit4("Color", ref _ioColor);
628+
ImGui.Text("Color");
629+
ImGui.ColorEdit4("##Color", ref _ioColor);
651630
if (SelectedShape == null)
652631
ImGui.EndDisabled();
632+
633+
ImGui.Spacing();
634+
ImGui.Separator();
635+
ImGui.Spacing();
636+
637+
ImGui.Text("Background Color");
638+
ImGui.Spacing();
639+
if (ImGui.ColorEdit3("##BgColor", ref _ioBgColor))
640+
GL.ClearColor(_ioBgColor.X, _ioBgColor.Y, _ioBgColor.Z, 1.0f);
653641
ImGui.End();
654642

655643
// Tree view side
@@ -782,8 +770,6 @@ public void ShowUI()
782770
if (picker.Draw())
783771
{
784772
ResetSelection();
785-
_timeline.ResetTimeline();
786-
//ResetTimeline();
787773
bool compatibilityFlag;
788774

789775
switch (_importMode)
@@ -795,6 +781,7 @@ public void ShowUI()
795781
case ImportMode.Override:
796782
default:
797783
(Shapes, compatibilityFlag) = Importer.ImportFromFile(picker.SelectedFile);
784+
_timeline.ResetTimeline();
798785
break;
799786
}
800787
FilePicker.RemoveFilePicker(this);
@@ -850,8 +837,8 @@ static void HelpMarker(string desc)
850837

851838
public void SaveCurrentScreenToMP4()
852839
{
853-
using VideoWriter w = new VideoWriter("output.mp4", 12, new System.Drawing.Size(ClientSize.X, ClientSize.Y), true);
854-
for (int i = 0; i <= 100; i++) // TODO: please dont hardcode this
840+
using VideoWriter w = new VideoWriter("output.mp4", _timeline.IoFps, new System.Drawing.Size(ClientSize.X, ClientSize.Y), true);
841+
for (int i = Timeline.MIN_TIMELINE; i <= Timeline.MAX_TIMELINE; i++) // TODO: please dont hardcode this
855842
{
856843
RenderFrameBySecondIndex(i);
857844
w.Write(TakeSnap().ToMat());
@@ -861,7 +848,7 @@ public void SaveCurrentScreenToGIF()
861848
{
862849
using (var gif = AnimatedGif.AnimatedGif.Create("output.gif", 1000 / _timeline.IoFps))
863850
{
864-
for (int i = 0; i < 100; i++) // TODO: please dont hardcode this
851+
for (int i = Timeline.MIN_TIMELINE; i <= Timeline.MAX_TIMELINE; i++) // TODO: please dont hardcode this
865852
{
866853
RenderFrameBySecondIndex(i);
867854
gif.AddFrame(TakeSnap(), delay: -1, quality: GifQuality.Bit8);

0 commit comments

Comments
 (0)