From d7f3cef4ab390564f6bf29babe807b9edd9bfdf1 Mon Sep 17 00:00:00 2001 From: goat <16760685+goaaats@users.noreply.github.com> Date: Mon, 19 Jul 2021 12:17:07 +0200 Subject: [PATCH] feat(ComponentDemo): Add easings demo --- .../Internal/Windows/ComponentDemoWindow.cs | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/Dalamud/Interface/Internal/Windows/ComponentDemoWindow.cs b/Dalamud/Interface/Internal/Windows/ComponentDemoWindow.cs index 814c7abc6..860a2ba15 100644 --- a/Dalamud/Interface/Internal/Windows/ComponentDemoWindow.cs +++ b/Dalamud/Interface/Internal/Windows/ComponentDemoWindow.cs @@ -2,6 +2,8 @@ using System; using System.Collections.Generic; using System.Numerics; +using Dalamud.Interface.Animation; +using Dalamud.Interface.Animation.EasingFunctions; using Dalamud.Interface.Colors; using Dalamud.Interface.Components; using Dalamud.Interface.Windowing; @@ -14,7 +16,19 @@ namespace Dalamud.Interface.Internal.Windows /// 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 IReadOnlyList 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; /// @@ -36,6 +50,24 @@ namespace Dalamud.Interface.Internal.Windows }; } + /// + public override void OnOpen() + { + foreach (var easing in this.easings) + { + easing.Restart(); + } + } + + /// + public override void OnClose() + { + foreach (var easing in this.easings) + { + easing.Stop(); + } + } + /// public override void Draw() { @@ -50,6 +82,11 @@ namespace Dalamud.Interface.Internal.Windows componentDemo.Demo(); } } + + if (ImGui.CollapsingHeader("Easing animations")) + { + this.EasingsDemo(); + } } private static void HelpMarkerDemo() @@ -79,6 +116,40 @@ namespace Dalamud.Interface.Internal.Windows 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() { ImGui.Text("Click on the color button to use the picker.");