Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove bindable from CircularProgress #6199

Merged
merged 1 commit into from
Feb 27, 2024
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
4 changes: 2 additions & 2 deletions osu.Framework.Tests/Visual/Graphics/TestSceneStencil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private void load(TextureStore textures)
Size = new Vector2(circle_radius),
RelativePositionAxes = Axes.Both,
Position = new Vector2(xPos, yPos),
Current = { Value = 1 }
Progress = 1
});

circlesContainerBuffered.Add(new CircularProgress
Expand All @@ -91,7 +91,7 @@ private void load(TextureStore textures)
Size = new Vector2(circle_radius),
RelativePositionAxes = Axes.Both,
Position = new Vector2(xPos, yPos),
Current = { Value = 1 }
Progress = 1
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ protected override void Update()
base.Update();

foreach (var p in Flow.OfType<CircularProgress>())
p.Current.Value = (p.Current.Value + (Time.Elapsed * RNG.NextSingle()) / 1000) % 1;
p.Progress = (p.Progress + (Time.Elapsed * RNG.NextSingle()) / 1000) % 1;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,23 +145,23 @@ protected override void Update()
switch (rotateMode)
{
case 0:
clock.Current.Value = Time.Current % (period * 2) / period - 1;
clock.Progress = Time.Current % (period * 2) / period - 1;
break;

case 1:
clock.Current.Value = Time.Current % period / period;
clock.Progress = Time.Current % period / period;
break;

case 2:
clock.Current.Value = Time.Current % period / period - 1;
clock.Progress = Time.Current % period / period - 1;
break;

case 3:
clock.Current.Value = Time.Current % transition_period / transition_period / 5 - 0.1f;
clock.Progress = Time.Current % transition_period / transition_period / 5 - 0.1f;
break;

case 4:
clock.Current.Value = (Time.Current % transition_period / transition_period / 5 - 0.1f + 2) % 2 - 1;
clock.Progress = (Time.Current % transition_period / transition_period / 5 - 0.1f + 2) % 2 - 1;
break;
}
}
Expand Down Expand Up @@ -245,19 +245,19 @@ private void transform(int tf)
switch (tf)
{
case 0:
clock.FillTo(0).Then().FillTo(1, 1000).Loop();
clock.ProgressTo(0).Then().ProgressTo(1, 1000).Loop();
break;

case 1:
clock.FillTo(1).Then().FillTo(0, 1000).Loop();
clock.ProgressTo(1).Then().ProgressTo(0, 1000).Loop();
break;

case 2:
clock.FillTo(0, 1000).Then().FillTo(1, 1000).Loop();
clock.ProgressTo(0, 1000).Then().ProgressTo(1, 1000).Loop();
break;

case 3:
clock.FillTo(0).Then().FillTo(1, 1000, Easing.InOutQuart).Loop();
clock.ProgressTo(0).Then().ProgressTo(1, 1000, Easing.InOutQuart).Loop();
break;
}
}
Expand Down
6 changes: 3 additions & 3 deletions osu.Framework/Graphics/Cursor/CursorContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ public override void BeginAnimation(double duration)
progress.FadeColour(Color4.SkyBlue)
.TransformTo(nameof(progress.InnerRadius), 0.2f)
.TransformTo(nameof(progress.InnerRadius), 0.3f, 150, Easing.OutQuint)
.TransformBindableTo(progress.Current, 0)
.TransformBindableTo(progress.Current, 1, duration / 3 * 2);
.ProgressTo(0)
.ProgressTo(1, duration / 3 * 2);

using (BeginDelayedSequence(duration / 3 * 2))
{
Expand All @@ -165,7 +165,7 @@ public override void CancelAnimation()
{
this.FadeOut(400, Easing.OutQuint);

progress.TransformBindableTo(progress.Current, 0, 400, Easing.OutQuint)
progress.ProgressTo(0, 400, Easing.OutQuint)
.TransformTo(nameof(progress.InnerRadius), 0.2f, 50, Easing.OutQuint);
}
}
Expand Down
54 changes: 26 additions & 28 deletions osu.Framework/Graphics/UserInterface/CircularProgress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System;
using System.Runtime.InteropServices;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics.Rendering;
using osu.Framework.Graphics.Shaders;
using osu.Framework.Graphics.Shaders.Types;
Expand All @@ -15,14 +14,26 @@

namespace osu.Framework.Graphics.UserInterface
{
public partial class CircularProgress : Sprite, IHasCurrentValue<double>
public partial class CircularProgress : Sprite
{
private readonly BindableWithCurrent<double> current = new BindableWithCurrent<double>();
private double progress;

public Bindable<double> Current
public double Progress
{
get => current.Current;
set => current.Current = value;
get => progress;
set
{
if (!double.IsFinite(value))
throw new ArgumentException($"{nameof(Progress)} must be finite, but is {value}.");

if (progress == value)
return;

progress = value;

if (IsLoaded)
Invalidate(Invalidation.DrawNode);
}
}

[BackgroundDependencyLoader]
Expand All @@ -32,27 +43,14 @@ private void load(ShaderManager shaders, IRenderer renderer)
TextureShader = shaders.Load(VertexShaderDescriptor.TEXTURE_2, "CircularProgress");
}

protected override void LoadComplete()
{
base.LoadComplete();

Current.BindValueChanged(c =>
{
if (!double.IsFinite(c.NewValue))
throw new ArgumentException($"{nameof(Current)} must be finite, but is {c.NewValue}.");

Invalidate(Invalidation.DrawNode);
}, true);
}

protected override DrawNode CreateDrawNode() => new CircularProgressDrawNode(this);

public TransformSequence<CircularProgress> FillTo(double newValue, double duration = 0, Easing easing = Easing.None)
=> FillTo(newValue, duration, new DefaultEasingFunction(easing));
public TransformSequence<CircularProgress> ProgressTo(double newValue, double duration = 0, Easing easing = Easing.None)
=> ProgressTo(newValue, duration, new DefaultEasingFunction(easing));

public TransformSequence<CircularProgress> FillTo<TEasing>(double newValue, double duration, in TEasing easing)
public TransformSequence<CircularProgress> ProgressTo<TEasing>(double newValue, double duration, in TEasing easing)
where TEasing : IEasingFunction
=> this.TransformBindableTo(Current, newValue, duration, easing);
=> this.TransformTo(nameof(Progress), newValue, duration, easing);

private float innerRadius = 1;

Expand Down Expand Up @@ -108,7 +106,7 @@ public override void ApplyState()
base.ApplyState();

InnerRadius = Source.innerRadius;
Progress = Math.Abs((float)Source.current.Value);
Progress = Math.Abs((float)Source.progress);
RoundedCaps = Source.roundedCaps;

// smoothstep looks too sharp with 1px, let's give it a bit more
Expand Down Expand Up @@ -162,11 +160,11 @@ private record struct CircularProgressParameters

public static class CircularProgressTransformSequenceExtensions
{
public static TransformSequence<CircularProgress> FillTo(this TransformSequence<CircularProgress> t, double newValue, double duration = 0, Easing easing = Easing.None)
=> t.FillTo(newValue, duration, new DefaultEasingFunction(easing));
public static TransformSequence<CircularProgress> ProgressTo(this TransformSequence<CircularProgress> t, double newValue, double duration = 0, Easing easing = Easing.None)
=> t.ProgressTo(newValue, duration, new DefaultEasingFunction(easing));

public static TransformSequence<CircularProgress> FillTo<TEasing>(this TransformSequence<CircularProgress> t, double newValue, double duration, TEasing easing)
public static TransformSequence<CircularProgress> ProgressTo<TEasing>(this TransformSequence<CircularProgress> t, double newValue, double duration, TEasing easing)
where TEasing : IEasingFunction
=> t.Append(cp => cp.FillTo(newValue, duration, easing));
=> t.Append(cp => cp.ProgressTo(newValue, duration, easing));
}
}
Loading