forked from ppy/osu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArgonSpinnerProgressArc.cs
More file actions
187 lines (153 loc) · 6.74 KB
/
Copy pathArgonSpinnerProgressArc.cs
File metadata and controls
187 lines (153 loc) · 6.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Runtime.InteropServices;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Rendering;
using osu.Framework.Graphics.Shaders;
using osu.Framework.Graphics.Shaders.Types;
using osu.Framework.Graphics.Textures;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Utils;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Osu.Objects.Drawables;
namespace osu.Game.Rulesets.Osu.Skinning.Argon
{
public partial class ArgonSpinnerProgressArc : CompositeDrawable
{
private const float arc_fill = 0.15f;
private const float arc_radius = 0.12f;
private ProgressFill fill = null!;
private DrawableSpinner spinner = null!;
private CircularProgress background = null!;
[BackgroundDependencyLoader]
private void load(DrawableHitObject drawableHitObject)
{
RelativeSizeAxes = Axes.Both;
spinner = (DrawableSpinner)drawableHitObject;
InternalChildren = new Drawable[]
{
background = new CircularProgress
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Colour = Colour4.White.Opacity(0.25f),
RelativeSizeAxes = Axes.Both,
Progress = arc_fill,
Rotation = 90 - arc_fill * 180,
InnerRadius = arc_radius,
RoundedCaps = true,
},
fill = new ProgressFill
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
InnerRadius = arc_radius,
RoundedCaps = true,
GlowColour = new Colour4(171, 255, 255, 180)
}
};
}
protected override void Update()
{
base.Update();
background.Alpha = spinner.Progress >= 1 ? 0 : 1;
fill.Alpha = (float)Interpolation.DampContinuously(fill.Alpha, spinner.Progress > 0 && spinner.Progress < 1 ? 1 : 0, 40f, MathF.Abs((float)Time.Elapsed));
fill.Progress = (float)Interpolation.DampContinuously(fill.Progress, spinner.Progress >= 1 ? 0 : arc_fill * spinner.Progress, 40f, MathF.Abs((float)Time.Elapsed));
fill.Rotation = (float)(90 - fill.Progress * 180);
}
private partial class ProgressFill : CircularProgress
{
private Colour4 glowColour = Colour4.White;
public Colour4 GlowColour
{
get => glowColour;
set
{
glowColour = value;
Invalidate(Invalidation.DrawNode);
}
}
private Texture glowTexture = null!;
private IShader glowShader = null!;
private float glowSize;
[BackgroundDependencyLoader]
private void load(TextureStore textures, ShaderManager shaders)
{
glowTexture = textures.Get("Gameplay/osu/spinner-glow");
glowShader = shaders.Load(VertexShaderDescriptor.TEXTURE_2, "SpinnerGlow");
glowSize = Blur.KernelSize(50); // Half of the maximum blur sigma in the design (which is 100)
}
protected override DrawNode CreateDrawNode() => new ProgressFillDrawNode(this);
private class ProgressFillDrawNode : CircularProgressDrawNode
{
protected new ProgressFill Source => (ProgressFill)base.Source;
public ProgressFillDrawNode(CircularProgress source)
: base(source)
{
}
private Texture glowTexture = null!;
private IShader glowShader = null!;
private Quad glowQuad;
private float relativeGlowSize;
private Colour4 glowColour;
public override void ApplyState()
{
base.ApplyState();
glowTexture = Source.glowTexture;
glowShader = Source.glowShader;
glowColour = Source.glowColour;
// Inflated draw quad by the size of the blur.
glowQuad = Source.ToScreenSpace(DrawRectangle.Inflate(Source.glowSize));
relativeGlowSize = Source.glowSize / Source.DrawSize.X;
}
protected override void Draw(IRenderer renderer)
{
base.Draw(renderer);
drawGlow(renderer);
}
private void drawGlow(IRenderer renderer)
{
renderer.SetBlend(BlendingParameters.Additive);
glowShader.Bind();
bindGlowUniformResources(glowShader, renderer);
ColourInfo col = DrawColourInfo.Colour;
col.ApplyChild(glowColour);
renderer.DrawQuad(glowTexture, glowQuad, col);
glowShader.Unbind();
}
private IUniformBuffer<ProgressGlowParameters>? progressGlowParametersBuffer;
private void bindGlowUniformResources(IShader shader, IRenderer renderer)
{
progressGlowParametersBuffer ??= renderer.CreateUniformBuffer<ProgressGlowParameters>();
progressGlowParametersBuffer.Data = new ProgressGlowParameters
{
InnerRadius = InnerRadius,
Progress = Progress,
TexelSize = TexelSize,
GlowSize = relativeGlowSize
};
shader.BindUniformBlock("m_ProgressGlowParameters", progressGlowParametersBuffer);
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
progressGlowParametersBuffer?.Dispose();
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
private record struct ProgressGlowParameters
{
public UniformFloat InnerRadius;
public UniformFloat Progress;
public UniformFloat TexelSize;
public UniformFloat GlowSize;
}
}
}
}
}