Skip to content

Commit

Permalink
Replaced custom structs with ones from System.Drawing (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
flyingpie authored Jul 15, 2024
1 parent ed09ee6 commit eacdd74
Show file tree
Hide file tree
Showing 17 changed files with 69 additions and 319 deletions.
46 changes: 0 additions & 46 deletions src/10-Core/Wtq/Data/WtqBounds.cs

This file was deleted.

13 changes: 0 additions & 13 deletions src/10-Core/Wtq/Data/WtqDataExtensions.cs

This file was deleted.

84 changes: 0 additions & 84 deletions src/10-Core/Wtq/Data/WtqRect.cs

This file was deleted.

40 changes: 0 additions & 40 deletions src/10-Core/Wtq/Data/WtqVec2I.cs

This file was deleted.

1 change: 1 addition & 0 deletions src/10-Core/Wtq/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
global using System.ComponentModel.DataAnnotations;
global using System.Diagnostics;
global using System.Diagnostics.CodeAnalysis;
global using System.Drawing;
global using System.IO;
global using System.Linq;
global using System.Threading;
Expand Down
10 changes: 4 additions & 6 deletions src/10-Core/Wtq/Services/IWtqScreenInfoProvider.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using Wtq.Data;

namespace Wtq.Services;
namespace Wtq.Services;

public interface IWtqScreenInfoProvider
{
Task<WtqRect> GetPrimaryScreenRectAsync();
Task<Rectangle> GetPrimaryScreenRectAsync();

Task<WtqRect[]> GetScreenRectsAsync();
Task<Rectangle[]> GetScreenRectsAsync();

Task<WtqRect> GetScreenWithCursorAsync();
Task<Rectangle> GetScreenWithCursorAsync();
}
20 changes: 9 additions & 11 deletions src/10-Core/Wtq/Services/WtqAppToggleService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Wtq.Data;

namespace Wtq.Services;
namespace Wtq.Services;

/// <inheritdoc cref="IWtqAppToggleService"/>
public class WtqAppToggleService(
Expand Down Expand Up @@ -68,11 +66,11 @@ private int GetDurationMs(WtqApp app, ToggleModifiers mods)
/// <summary>
/// Get the position rect a window should move to when toggling OFF.
/// </summary>
private WtqRect GetToggleOffToWindowRect(WtqRect from1)
private Rectangle GetToggleOffToWindowRect(Rectangle from1)
{
var to = from1 with
{
Y = -from1.Height - 100f,
Y = -from1.Height - 100,
};

return to;
Expand All @@ -81,11 +79,11 @@ private WtqRect GetToggleOffToWindowRect(WtqRect from1)
/// <summary>
/// Get the position rect a window should move to when toggling ON.
/// </summary>
private WtqRect GetToggleOnFromWindowRect(WtqRect to)
private Rectangle GetToggleOnFromWindowRect(Rectangle to)
{
var from = to with
{
Y = -to.Height - 100f,
Y = -to.Height - 100,
};
return from;
}
Expand All @@ -94,7 +92,7 @@ private WtqRect GetToggleOnFromWindowRect(WtqRect to)
/// Returns a rectangle representing the screen we want to toggle the terminal onto.
/// </summary>
/// <param name="app">The app for which we're figuring out the screen bounds.</param>
private async Task<WtqRect> GetToggleOnToScreenRectAsync(WtqApp app)
private async Task<Rectangle> GetToggleOnToScreenRectAsync(WtqApp app)
{
Guard.Against.Null(app);

Expand Down Expand Up @@ -142,9 +140,9 @@ private async Task<WtqRect> GetToggleOnToScreenRectAsync(WtqApp app)
/// <summary>
/// Returns the target bounds of the specified <paramref name="app"/>, within the specified <paramref name="screenBounds"/> when its toggling onto the screen.
/// </summary>
private WtqRect GetToggleOnToWindowRect(
private Rectangle GetToggleOnToWindowRect(
WtqApp app,
WtqRect screenBounds)
Rectangle screenBounds)
{
Guard.Against.Null(app);

Expand All @@ -165,7 +163,7 @@ private WtqRect GetToggleOnToWindowRect(
_ => screenBounds.X + (int)Math.Ceiling((screenBounds.Width / 2f) - (termWidth / 2f)),
};

return new WtqRect()
return new Rectangle()
{
// X, based on the HorizontalAlign and HorizontalScreenCoverage settings
X = x,
Expand Down
10 changes: 4 additions & 6 deletions src/10-Core/Wtq/Utils/IWtqTween.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Wtq.Data;

namespace Wtq.Utils;
namespace Wtq.Utils;

/// <summary>
/// Utils for running animation sequences.
Expand All @@ -13,9 +11,9 @@ public interface IWtqTween
/// The <paramref name="move"/> callback is called with a progressing rectangle (position + size).<br/>
/// </summary>
Task AnimateAsync(
WtqRect src,
WtqRect dst,
Rectangle src,
Rectangle dst,
int durationMs,
AnimationType animType,
Func<WtqRect, Task> move);
Func<Rectangle, Task> move);
}
16 changes: 16 additions & 0 deletions src/10-Core/Wtq/Utils/MathUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace Wtq.Utils;

public static class MathUtils
{
/// <summary>
/// Linear interpolate, returns a <see cref="Rectangle"/> that is between <paramref name="src"/> and <paramref name="dst"/>, at <paramref name="by"/> (value of 0.0f, to 1.0f).
/// </summary>
public static Rectangle Lerp(Rectangle src, Rectangle dst, float by) =>
new()
{
X = (int)float.Lerp(src.X, dst.X, by),
Y = (int)float.Lerp(src.Y, dst.Y, by),
Width = (int)float.Lerp(src.Width, dst.Width, by),
Height = (int)float.Lerp(src.Height, dst.Height, by),
};
}
12 changes: 5 additions & 7 deletions src/10-Core/Wtq/Utils/WtqTween.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Wtq.Data;

namespace Wtq.Utils;
namespace Wtq.Utils;

/// <inheritdoc/>
public sealed class WtqTween : IWtqTween
Expand All @@ -12,11 +10,11 @@ public sealed class WtqTween : IWtqTween

/// <inheritdoc/>
public async Task AnimateAsync(
WtqRect src,
WtqRect dst,
Rectangle src,
Rectangle dst,
int durationMs,
AnimationType animType,
Func<WtqRect, Task> move)
Func<Rectangle, Task> move)
{
Guard.Against.Null(src);
Guard.Against.Null(dst);
Expand Down Expand Up @@ -46,7 +44,7 @@ public async Task AnimateAsync(
var linearProgress = sinceStartMs / durationMs;
var progress = (float)animFunc(linearProgress);

var rect = WtqRect.Lerp(src, dst, progress);
var rect = MathUtils.Lerp(src, dst, progress);

await move(rect).NoCtx();

Expand Down
7 changes: 3 additions & 4 deletions src/10-Core/Wtq/WtqApp.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Wtq.Data;
using Wtq.Services;
using Wtq.Services;

namespace Wtq;

Expand Down Expand Up @@ -119,7 +118,7 @@ public async ValueTask DisposeAsync()
}

[SuppressMessage("Design", "CA1024:Use properties where appropriate", Justification = "MvdO: May throw an exception, which we don't want to do in a property.")]
public WtqRect GetWindowRect()
public Rectangle GetWindowRect()
{
if (Process == null)
{
Expand All @@ -129,7 +128,7 @@ public WtqRect GetWindowRect()
return Process.WindowRect;
}

public async Task MoveWindowAsync(WtqRect rect)
public async Task MoveWindowAsync(Rectangle rect)
{
if (Process == null)
{
Expand Down
Loading

0 comments on commit eacdd74

Please sign in to comment.