mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
feat(ComponentDemo): Add easings demo
This commit is contained in:
parent
85b19cafbc
commit
d7f3cef4ab
1 changed files with 71 additions and 0 deletions
|
|
@ -2,6 +2,8 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
|
|
||||||
|
using Dalamud.Interface.Animation;
|
||||||
|
using Dalamud.Interface.Animation.EasingFunctions;
|
||||||
using Dalamud.Interface.Colors;
|
using Dalamud.Interface.Colors;
|
||||||
using Dalamud.Interface.Components;
|
using Dalamud.Interface.Components;
|
||||||
using Dalamud.Interface.Windowing;
|
using Dalamud.Interface.Windowing;
|
||||||
|
|
@ -14,7 +16,19 @@ namespace Dalamud.Interface.Internal.Windows
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal sealed class ComponentDemoWindow : Window
|
internal sealed class ComponentDemoWindow : Window
|
||||||
{
|
{
|
||||||
|
private static readonly TimeSpan DefaultEasingTime = new(0, 0, 0, 1700);
|
||||||
|
|
||||||
private readonly List<(string Name, Action Demo)> componentDemos;
|
private readonly List<(string Name, Action Demo)> componentDemos;
|
||||||
|
private readonly IReadOnlyList<Easing> easings = new Easing[]
|
||||||
|
{
|
||||||
|
new InSine(DefaultEasingTime), new OutSine(DefaultEasingTime), new InOutSine(DefaultEasingTime),
|
||||||
|
new InCubic(DefaultEasingTime), new OutCubic(DefaultEasingTime), new InOutCubic(DefaultEasingTime),
|
||||||
|
new InQuint(DefaultEasingTime), new OutQuint(DefaultEasingTime), new InOutQuint(DefaultEasingTime),
|
||||||
|
new InCirc(DefaultEasingTime), new OutCirc(DefaultEasingTime), new InOutCirc(DefaultEasingTime),
|
||||||
|
new InElastic(DefaultEasingTime), new OutElastic(DefaultEasingTime), new InOutElastic(DefaultEasingTime),
|
||||||
|
};
|
||||||
|
|
||||||
|
private int animationTimeMs = (int)DefaultEasingTime.TotalMilliseconds;
|
||||||
private Vector4 defaultColor = ImGuiColors.DalamudOrange;
|
private Vector4 defaultColor = ImGuiColors.DalamudOrange;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -36,6 +50,24 @@ namespace Dalamud.Interface.Internal.Windows
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public override void OnOpen()
|
||||||
|
{
|
||||||
|
foreach (var easing in this.easings)
|
||||||
|
{
|
||||||
|
easing.Restart();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public override void OnClose()
|
||||||
|
{
|
||||||
|
foreach (var easing in this.easings)
|
||||||
|
{
|
||||||
|
easing.Stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override void Draw()
|
public override void Draw()
|
||||||
{
|
{
|
||||||
|
|
@ -50,6 +82,11 @@ namespace Dalamud.Interface.Internal.Windows
|
||||||
componentDemo.Demo();
|
componentDemo.Demo();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ImGui.CollapsingHeader("Easing animations"))
|
||||||
|
{
|
||||||
|
this.EasingsDemo();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void HelpMarkerDemo()
|
private static void HelpMarkerDemo()
|
||||||
|
|
@ -79,6 +116,40 @@ namespace Dalamud.Interface.Internal.Windows
|
||||||
ImGuiComponents.TextWithLabel("Label", "Hover to see more", "more");
|
ImGuiComponents.TextWithLabel("Label", "Hover to see more", "more");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void EasingsDemo()
|
||||||
|
{
|
||||||
|
ImGui.SliderInt("Speed in MS", ref this.animationTimeMs, 200, 5000);
|
||||||
|
|
||||||
|
foreach (var easing in this.easings)
|
||||||
|
{
|
||||||
|
easing.Duration = new TimeSpan(0, 0, 0, 0, this.animationTimeMs);
|
||||||
|
|
||||||
|
if (!easing.IsRunning)
|
||||||
|
{
|
||||||
|
easing.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
var cursor = ImGui.GetCursorPos();
|
||||||
|
var p1 = new Vector2(cursor.X + 5, cursor.Y);
|
||||||
|
var p2 = p1 + new Vector2(45, 0);
|
||||||
|
easing.Point1 = p1;
|
||||||
|
easing.Point2 = p2;
|
||||||
|
easing.Update();
|
||||||
|
|
||||||
|
if (easing.IsDone)
|
||||||
|
{
|
||||||
|
easing.Restart();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui.SetCursorPos(easing.EasedPoint);
|
||||||
|
ImGui.Bullet();
|
||||||
|
|
||||||
|
ImGui.SetCursorPos(cursor + new Vector2(0, 10));
|
||||||
|
ImGui.Text($"{easing.GetType().Name} ({easing.Value})");
|
||||||
|
ImGuiHelpers.ScaledDummy(5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void ColorPickerWithPaletteDemo()
|
private void ColorPickerWithPaletteDemo()
|
||||||
{
|
{
|
||||||
ImGui.Text("Click on the color button to use the picker.");
|
ImGui.Text("Click on the color button to use the picker.");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue