Skip to content

Commit

Permalink
clamp value of all easings by default
Browse files Browse the repository at this point in the history
  • Loading branch information
goaaats committed Dec 29, 2024
1 parent 2e77e90 commit 1aada98
Show file tree
Hide file tree
Showing 17 changed files with 41 additions and 35 deletions.
10 changes: 8 additions & 2 deletions Dalamud/Interface/Animation/Easing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,15 @@ protected Easing(TimeSpan duration)
public bool IsInverse { get; set; }

/// <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>
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
{
Expand Down
2 changes: 1 addition & 1 deletion Dalamud/Interface/Animation/EasingFunctions/InCirc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ public InCirc(TimeSpan duration)
public override void Update()
{
var p = this.Progress;
this.Value = 1 - Math.Sqrt(1 - Math.Pow(p, 2));
this.ValueUnclamped = 1 - Math.Sqrt(1 - Math.Pow(p, 2));
}
}
2 changes: 1 addition & 1 deletion Dalamud/Interface/Animation/EasingFunctions/InCubic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ public InCubic(TimeSpan duration)
public override void Update()
{
var p = this.Progress;
this.Value = p * p * p;
this.ValueUnclamped = p * p * p;
}
}
10 changes: 5 additions & 5 deletions Dalamud/Interface/Animation/EasingFunctions/InElastic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ public InElastic(TimeSpan duration)
public override void Update()
{
var p = this.Progress;
this.Value = p == 0
? 0
: p == 1
? 1
: -Math.Pow(2, (10 * p) - 10) * Math.Sin(((p * 10) - 10.75) * Constant);
this.ValueUnclamped = p == 0
? 0
: p == 1
? 1
: -Math.Pow(2, (10 * p) - 10) * Math.Sin(((p * 10) - 10.75) * Constant);
}
}
6 changes: 3 additions & 3 deletions Dalamud/Interface/Animation/EasingFunctions/InOutCirc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public InOutCirc(TimeSpan duration)
public override void Update()
{
var p = this.Progress;
this.Value = p < 0.5
? (1 - Math.Sqrt(1 - Math.Pow(2 * p, 2))) / 2
: (Math.Sqrt(1 - Math.Pow((-2 * p) + 2, 2)) + 1) / 2;
this.ValueUnclamped = p < 0.5
? (1 - Math.Sqrt(1 - Math.Pow(2 * p, 2))) / 2
: (Math.Sqrt(1 - Math.Pow((-2 * p) + 2, 2)) + 1) / 2;
}
}
2 changes: 1 addition & 1 deletion Dalamud/Interface/Animation/EasingFunctions/InOutCubic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ public InOutCubic(TimeSpan duration)
public override void Update()
{
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);
}
}
14 changes: 7 additions & 7 deletions Dalamud/Interface/Animation/EasingFunctions/InOutElastic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public InOutElastic(TimeSpan duration)
public override void Update()
{
var p = this.Progress;
this.Value = p == 0
? 0
: p == 1
? 1
: p < 0.5
? -(Math.Pow(2, (20 * p) - 10) * Math.Sin(((20 * p) - 11.125) * Constant)) / 2
: (Math.Pow(2, (-20 * p) + 10) * Math.Sin(((20 * p) - 11.125) * Constant) / 2) + 1;
this.ValueUnclamped = p == 0
? 0
: p == 1
? 1
: p < 0.5
? -(Math.Pow(2, (20 * p) - 10) * Math.Sin(((20 * p) - 11.125) * Constant)) / 2
: (Math.Pow(2, (-20 * p) + 10) * Math.Sin(((20 * p) - 11.125) * Constant) / 2) + 1;
}
}
2 changes: 1 addition & 1 deletion Dalamud/Interface/Animation/EasingFunctions/InOutQuint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ public InOutQuint(TimeSpan duration)
public override void Update()
{
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);
}
}
2 changes: 1 addition & 1 deletion Dalamud/Interface/Animation/EasingFunctions/InOutSine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ public InOutSine(TimeSpan duration)
public override void Update()
{
var p = this.Progress;
this.Value = -(Math.Cos(Math.PI * p) - 1) / 2;
this.ValueUnclamped = -(Math.Cos(Math.PI * p) - 1) / 2;
}
}
2 changes: 1 addition & 1 deletion Dalamud/Interface/Animation/EasingFunctions/InQuint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ public InQuint(TimeSpan duration)
public override void Update()
{
var p = this.Progress;
this.Value = p * p * p * p * p;
this.ValueUnclamped = p * p * p * p * p;
}
}
2 changes: 1 addition & 1 deletion Dalamud/Interface/Animation/EasingFunctions/InSine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ public InSine(TimeSpan duration)
public override void Update()
{
var p = this.Progress;
this.Value = 1 - Math.Cos((p * Math.PI) / 2);
this.ValueUnclamped = 1 - Math.Cos((p * Math.PI) / 2);
}
}
2 changes: 1 addition & 1 deletion Dalamud/Interface/Animation/EasingFunctions/OutCirc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ public OutCirc(TimeSpan duration)
public override void Update()
{
var p = this.Progress;
this.Value = Math.Sqrt(1 - Math.Pow(p - 1, 2));
this.ValueUnclamped = Math.Sqrt(1 - Math.Pow(p - 1, 2));
}
}
2 changes: 1 addition & 1 deletion Dalamud/Interface/Animation/EasingFunctions/OutCubic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ public OutCubic(TimeSpan duration)
public override void Update()
{
var p = this.Progress;
this.Value = 1 - Math.Pow(1 - p, 3);
this.ValueUnclamped = 1 - Math.Pow(1 - p, 3);
}
}
10 changes: 5 additions & 5 deletions Dalamud/Interface/Animation/EasingFunctions/OutElastic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ public OutElastic(TimeSpan duration)
public override void Update()
{
var p = this.Progress;
this.Value = p == 0
? 0
: p == 1
? 1
: (Math.Pow(2, -10 * p) * Math.Sin(((p * 10) - 0.75) * Constant)) + 1;
this.ValueUnclamped = p == 0
? 0
: p == 1
? 1
: (Math.Pow(2, -10 * p) * Math.Sin(((p * 10) - 0.75) * Constant)) + 1;
}
}
2 changes: 1 addition & 1 deletion Dalamud/Interface/Animation/EasingFunctions/OutQuint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ public OutQuint(TimeSpan duration)
public override void Update()
{
var p = this.Progress;
this.Value = 1 - Math.Pow(1 - p, 5);
this.ValueUnclamped = 1 - Math.Pow(1 - p, 5);
}
}
2 changes: 1 addition & 1 deletion Dalamud/Interface/Animation/EasingFunctions/OutSine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ public OutSine(TimeSpan duration)
public override void Update()
{
var p = this.Progress;
this.Value = Math.Sin((p * Math.PI) / 2);
this.ValueUnclamped = Math.Sin((p * Math.PI) / 2);
}
}
4 changes: 2 additions & 2 deletions Dalamud/Interface/Internal/Windows/TitleScreenMenuWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public override void Draw()

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;
foreach (var entry in entries)
Expand Down Expand Up @@ -393,7 +393,7 @@ private bool DrawEntry(

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
Expand Down

0 comments on commit 1aada98

Please sign in to comment.