clamp value of all easings by default

This commit is contained in:
goat 2024-12-29 16:53:16 +01:00
parent 2e77e90532
commit 1aada98393
17 changed files with 41 additions and 35 deletions

View file

@ -43,9 +43,15 @@ public abstract class Easing
public bool IsInverse { get; set; } public bool IsInverse { get; set; }
/// <summary> /// <summary>
/// Gets or sets the current value of the animation, from 0 to 1. /// Gets the current value of the animation, from 0 to 1.
/// </summary> /// </summary>
public double Value public double Value => Math.Clamp(this.ValueUnclamped, 0, 1);
/// <summary>
/// Gets or sets the current value of the animation, not limited to a range of 0 to 1.
/// Will return numbers outside of this range if accessed beyond animation time.
/// </summary>
public double ValueUnclamped
{ {
get get
{ {

View file

@ -19,6 +19,6 @@ public class InCirc : Easing
public override void Update() public override void Update()
{ {
var p = this.Progress; var p = this.Progress;
this.Value = 1 - Math.Sqrt(1 - Math.Pow(p, 2)); this.ValueUnclamped = 1 - Math.Sqrt(1 - Math.Pow(p, 2));
} }
} }

View file

@ -19,6 +19,6 @@ public class InCubic : Easing
public override void Update() public override void Update()
{ {
var p = this.Progress; var p = this.Progress;
this.Value = p * p * p; this.ValueUnclamped = p * p * p;
} }
} }

View file

@ -21,7 +21,7 @@ public class InElastic : Easing
public override void Update() public override void Update()
{ {
var p = this.Progress; var p = this.Progress;
this.Value = p == 0 this.ValueUnclamped = p == 0
? 0 ? 0
: p == 1 : p == 1
? 1 ? 1

View file

@ -19,7 +19,7 @@ public class InOutCirc : Easing
public override void Update() public override void Update()
{ {
var p = this.Progress; var p = this.Progress;
this.Value = p < 0.5 this.ValueUnclamped = p < 0.5
? (1 - Math.Sqrt(1 - Math.Pow(2 * p, 2))) / 2 ? (1 - Math.Sqrt(1 - Math.Pow(2 * p, 2))) / 2
: (Math.Sqrt(1 - Math.Pow((-2 * p) + 2, 2)) + 1) / 2; : (Math.Sqrt(1 - Math.Pow((-2 * p) + 2, 2)) + 1) / 2;
} }

View file

@ -19,6 +19,6 @@ public class InOutCubic : Easing
public override void Update() public override void Update()
{ {
var p = this.Progress; var p = this.Progress;
this.Value = p < 0.5 ? 4 * p * p * p : 1 - (Math.Pow((-2 * p) + 2, 3) / 2); this.ValueUnclamped = p < 0.5 ? 4 * p * p * p : 1 - (Math.Pow((-2 * p) + 2, 3) / 2);
} }
} }

View file

@ -21,7 +21,7 @@ public class InOutElastic : Easing
public override void Update() public override void Update()
{ {
var p = this.Progress; var p = this.Progress;
this.Value = p == 0 this.ValueUnclamped = p == 0
? 0 ? 0
: p == 1 : p == 1
? 1 ? 1

View file

@ -19,6 +19,6 @@ public class InOutQuint : Easing
public override void Update() public override void Update()
{ {
var p = this.Progress; var p = this.Progress;
this.Value = p < 0.5 ? 16 * p * p * p * p * p : 1 - (Math.Pow((-2 * p) + 2, 5) / 2); this.ValueUnclamped = p < 0.5 ? 16 * p * p * p * p * p : 1 - (Math.Pow((-2 * p) + 2, 5) / 2);
} }
} }

View file

@ -19,6 +19,6 @@ public class InOutSine : Easing
public override void Update() public override void Update()
{ {
var p = this.Progress; var p = this.Progress;
this.Value = -(Math.Cos(Math.PI * p) - 1) / 2; this.ValueUnclamped = -(Math.Cos(Math.PI * p) - 1) / 2;
} }
} }

View file

@ -19,6 +19,6 @@ public class InQuint : Easing
public override void Update() public override void Update()
{ {
var p = this.Progress; var p = this.Progress;
this.Value = p * p * p * p * p; this.ValueUnclamped = p * p * p * p * p;
} }
} }

View file

@ -19,6 +19,6 @@ public class InSine : Easing
public override void Update() public override void Update()
{ {
var p = this.Progress; var p = this.Progress;
this.Value = 1 - Math.Cos((p * Math.PI) / 2); this.ValueUnclamped = 1 - Math.Cos((p * Math.PI) / 2);
} }
} }

View file

@ -19,6 +19,6 @@ public class OutCirc : Easing
public override void Update() public override void Update()
{ {
var p = this.Progress; var p = this.Progress;
this.Value = Math.Sqrt(1 - Math.Pow(p - 1, 2)); this.ValueUnclamped = Math.Sqrt(1 - Math.Pow(p - 1, 2));
} }
} }

View file

@ -19,6 +19,6 @@ public class OutCubic : Easing
public override void Update() public override void Update()
{ {
var p = this.Progress; var p = this.Progress;
this.Value = 1 - Math.Pow(1 - p, 3); this.ValueUnclamped = 1 - Math.Pow(1 - p, 3);
} }
} }

View file

@ -21,7 +21,7 @@ public class OutElastic : Easing
public override void Update() public override void Update()
{ {
var p = this.Progress; var p = this.Progress;
this.Value = p == 0 this.ValueUnclamped = p == 0
? 0 ? 0
: p == 1 : p == 1
? 1 ? 1

View file

@ -19,6 +19,6 @@ public class OutQuint : Easing
public override void Update() public override void Update()
{ {
var p = this.Progress; var p = this.Progress;
this.Value = 1 - Math.Pow(1 - p, 5); this.ValueUnclamped = 1 - Math.Pow(1 - p, 5);
} }
} }

View file

@ -19,6 +19,6 @@ public class OutSine : Easing
public override void Update() public override void Update()
{ {
var p = this.Progress; var p = this.Progress;
this.Value = Math.Sin((p * Math.PI) / 2); this.ValueUnclamped = Math.Sin((p * Math.PI) / 2);
} }
} }

View file

@ -252,7 +252,7 @@ internal class TitleScreenMenuWindow : Window, IDisposable
this.fadeOutEasing.Update(); this.fadeOutEasing.Update();
using (ImRaii.PushStyle(ImGuiStyleVar.Alpha, (float)Math.Max(this.fadeOutEasing.Value, 0))) using (ImRaii.PushStyle(ImGuiStyleVar.Alpha, (float)this.fadeOutEasing.Value))
{ {
var i = 0; var i = 0;
foreach (var entry in entries) foreach (var entry in entries)
@ -393,7 +393,7 @@ internal class TitleScreenMenuWindow : Window, IDisposable
if (overrideAlpha) if (overrideAlpha)
{ {
ImGui.PushStyleVar(ImGuiStyleVar.Alpha, showText ? (float)Math.Min(logoEasing.Value, 1) : 0f); ImGui.PushStyleVar(ImGuiStyleVar.Alpha, showText ? (float)logoEasing.Value : 0f);
} }
// Drop shadow // Drop shadow