Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/SwitchifyPc.Tests/CursorOverlayClickFeedbackTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,23 @@ public void StaticFeedbackUsesFixedVisibilityDurations()
}

[Theory]
[InlineData(1, 48, 88, 3, 2)]
[InlineData(1.5, 72, 132, 4.5, 3)]
[InlineData(2, 96, 176, 6, 4)]
[InlineData(1, 33.6, 36.95, 3, 2)]
[InlineData(1.5, 50.4, 55.425, 4.5, 3)]
[InlineData(2, 67.2, 73.9, 6, 4)]
public void LandingGeometryScalesWithMonitorDpi(
double scale,
float expectedCore,
float expectedHalo,
float expectedHaloRadius,
float expectedStroke,
float expectedShadow)
{
CursorOverlayVisualTokens tokens = CursorOverlayVisualTokens.Create(128, scale);

Assert.Equal(expectedCore, tokens.LandingCoreDiameter);
Assert.Equal(expectedHalo, tokens.LandingHaloDiameter);
Assert.InRange(
CursorOverlayStaticFeedback.ResolveLandingHaloRadius(tokens),
expectedHaloRadius - 0.001f,
expectedHaloRadius + 0.001f);
Assert.Equal(expectedStroke, tokens.LandingHaloStroke);
Assert.Equal(expectedShadow, tokens.ShadowOffset);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ internal sealed record CursorOverlayVisualTokens(
float GlowStroke,
int CrosshairThickness,
float LandingCoreDiameter,
float LandingHaloStartDiameter,
float LandingHaloDiameter,
float LandingHaloStroke,
float ShadowOffset,
Expand All @@ -31,7 +32,8 @@ public static CursorOverlayVisualTokens Create(int logicalWindowSize, double sca
RingStroke: (float)Math.Max(4 * scale, normalizedLogicalSize * 0.039 * scale),
GlowStroke: (float)Math.Max(18 * scale, normalizedLogicalSize * 0.1875 * scale),
CrosshairThickness: Math.Max(1, Scale(2, scale)),
LandingCoreDiameter: (float)(normalizedLogicalSize * 0.375 * scale),
LandingCoreDiameter: (float)(normalizedLogicalSize * 0.2625 * scale),
LandingHaloStartDiameter: (float)(normalizedLogicalSize * 0.375 * scale),
LandingHaloDiameter: (float)(normalizedLogicalSize * 0.6875 * scale),
LandingHaloStroke: (float)Math.Max(2 * scale, normalizedLogicalSize * 0.0234375 * scale),
ShadowOffset: (float)Math.Max(1, 2 * scale),
Expand Down Expand Up @@ -67,6 +69,13 @@ internal static class CursorOverlayFeedbackTiming
internal static class CursorOverlayStaticFeedback
{
public const float LandingHaloProgress = 0.7f;

public static float ResolveLandingHaloRadius(CursorOverlayVisualTokens tokens)
{
float startRadius = tokens.LandingHaloStartDiameter / 2;
float maxRadius = (tokens.LandingHaloDiameter - tokens.LandingHaloStroke) / 2;
return startRadius + ((maxRadius - startRadius) * LandingHaloProgress);
}
}

internal sealed class CursorOverlayRenderFailureGuard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -718,9 +718,7 @@ private void DrawLanding(Graphics graphics)
float centerY = cursorCenter.Y;
float coreDiameter = visualTokens.LandingCoreDiameter;
float coreRadius = coreDiameter / 2;
float maxHaloRadius = (visualTokens.LandingHaloDiameter - visualTokens.LandingHaloStroke) / 2;
float haloRadius = visualTokens.LandingCoreDiameter / 2 +
((maxHaloRadius - visualTokens.LandingCoreDiameter / 2) * CursorOverlayStaticFeedback.LandingHaloProgress);
float haloRadius = CursorOverlayStaticFeedback.ResolveLandingHaloRadius(visualTokens);

using Pen halo = new(
Color.FromArgb(180, overlayColor.R, overlayColor.G, overlayColor.B),
Expand Down