Skip to content

Commit

Permalink
Resolve #110 Add resizeable timer
Browse files Browse the repository at this point in the history
  • Loading branch information
GrimMaple committed Sep 17, 2024
1 parent 3410189 commit 664b278
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 9 deletions.
12 changes: 11 additions & 1 deletion SpeedTool/Platform/Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,16 @@ public void Close()
window.Close();
}

public void Resize(Sizes size)
{
window.Size = size;
}

public void SetBorder(WindowBorder border)
{
window.WindowBorder = border;
}

public GL Gl
{
get
Expand Down Expand Up @@ -266,4 +276,4 @@ public ImFontPtr GetFont(string name)
Vector2D<int> sizes;

private const string ICON_RESOURCE_NAME = "SpeedTool.Resources.icon.png";
}
}
29 changes: 22 additions & 7 deletions SpeedTool/Windows/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using SpeedTool.Splits;
using System.Runtime.InteropServices;
using SpeedTool.Platform.Linux;
using System.Diagnostics.CodeAnalysis;

namespace SpeedTool.Windows;

Expand All @@ -22,7 +23,7 @@ class MainWindow : SPWindow
platform = Platform.Platform.SharedPlatform;
drw = new TimerDrawable(Gl);
config = Configuration.GetSection<GeneralConfiguration>()!;
ui = SelectUI();
LoadUI();
}

protected override void OnConfigUpdated(object? sender, IConfigurationSection? section)
Expand Down Expand Up @@ -115,15 +116,11 @@ protected override void OnUI(double dt)
{
if(ImGui.MenuItem("SpeedTool"))
{
config.TimerUI = "SpeedTool";
Configuration.SetSection(config);
ui = SelectUI();
SetUI("SpeedTool");
}
if(ImGui.MenuItem("Classic"))
{
config.TimerUI = "Classic";
Configuration.SetSection(config);
ui = SelectUI();
SetUI("Classic");
}
ImGui.EndMenu();
}
Expand Down Expand Up @@ -208,6 +205,24 @@ private TimerUIBase SelectUI()
}
}

private void SetUI(string display)
{
if(config.TimerUI == display)
return;

config.TimerUI = display;
Configuration.SetSection(config);
LoadUI();
}

[MemberNotNull(nameof(ui))]
private void LoadUI()
{
ui = SelectUI();
SetBorder(ui.DesiredBorder);
Resize(new Vector2D<int>((int)ui.DesiredSize.X, (int)ui.DesiredSize.Y));
}

bool hasError = false;
string errorMessage = "";
TimerDrawable drw;
Expand Down
5 changes: 4 additions & 1 deletion SpeedTool/Windows/TimerUI/Classic.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Numerics;
using ImGuiNET;
using Silk.NET.Windowing;
using SpeedTool.Global;
using SpeedTool.Global.Definitions;
using SpeedTool.Splits;
Expand All @@ -21,7 +22,9 @@ public ClassicTimerUI()
{

}


public override WindowBorder DesiredBorder => WindowBorder.Resizable;

public override void ReloadConfig(object? sender, IConfigurationSection? section)
{
if((section as ColorSettings) != null)
Expand Down
3 changes: 3 additions & 0 deletions SpeedTool/Windows/TimerUI/SpeedTool.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Numerics;
using ImGuiNET;
using Silk.NET.OpenGL;
using Silk.NET.Windowing;
using SpeedTool.Global;
using SpeedTool.Global.Definitions;
using SpeedTool.Splits;
Expand All @@ -24,6 +25,8 @@ public SpeedToolTimerUI(GL gl)
drw = new TimerDrawable(gl);
}

public override WindowBorder DesiredBorder => WindowBorder.Fixed;

private ColorSettings colorsConfig { get; set; } =
Configuration.GetSection<ColorSettings>() ?? throw new Exception();

Expand Down
11 changes: 11 additions & 0 deletions SpeedTool/Windows/TimerUI/TimerUI.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Numerics;
using Silk.NET.Windowing;
using SpeedTool.Global;
using SpeedTool.Splits;
using SpeedTool.Timer;
Expand All @@ -11,6 +13,15 @@ abstract class TimerUIBase

public virtual void ReloadConfig(object? sender, IConfigurationSection? section) { }

public abstract WindowBorder DesiredBorder { get; }
public virtual Vector2 DesiredSize
{
get
{
return new Vector2(500, 550);
}
}

protected TimingMethod DisplayTimingMethod
{
get
Expand Down

0 comments on commit 664b278

Please sign in to comment.