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

Add visual effect for slider bar focus state #30410

Closed
wants to merge 1 commit into from
Closed
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
40 changes: 25 additions & 15 deletions osu.Game/Graphics/UserInterface/Nub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,30 +77,40 @@ protected override void LoadComplete()
Current.BindValueChanged(onCurrentValueChanged, true);
}

private bool glowing;
private int glow;

public bool Glowing
public int Glow
{
get => glowing;
get => glow;
set
{
glowing = value;

if (value)
if (value > 0)
{
main.FadeColour(GlowingAccentColour.Lighten(0.5f), 40, Easing.OutQuint)
.Then()
.FadeColour(GlowingAccentColour, 800, Easing.OutQuint);
float extraGlow = (value - 1) * 0.10f;

if (value > glow)
{
main.FadeColour(GlowingAccentColour.Lighten(0.5f), 40, Easing.OutQuint)
.Then()
.FadeColour(GlowingAccentColour.Lighten(extraGlow), 800, Easing.OutQuint);

main.FadeEdgeEffectTo(Color4.White.Opacity(0.1f), 40, Easing.OutQuint)
.Then()
.FadeEdgeEffectTo(GlowColour.Opacity(0.1f), 800, Easing.OutQuint);
main.FadeEdgeEffectTo(Color4.White.Opacity(0.1f), 40, Easing.OutQuint)
.Then()
.FadeEdgeEffectTo(GlowColour.Lighten(extraGlow).Opacity(0.1f), 800, Easing.OutQuint);
}
else
{
main.FadeColour(GlowingAccentColour.Lighten(extraGlow), 800, Easing.OutQuint);
main.FadeEdgeEffectTo(GlowColour.Lighten(extraGlow).Opacity(0.1f), 800, Easing.OutQuint);
}
}
else
{
main.FadeEdgeEffectTo(GlowColour.Opacity(0), 800, Easing.OutQuint);
main.FadeColour(AccentColour, 800, Easing.OutQuint);
}

glow = value;
}
}

Expand All @@ -126,7 +136,7 @@ public Color4 AccentColour
set
{
accentColour = value;
if (!Glowing)
if (Glow == 0)
main.Colour = value;
}
}
Expand All @@ -139,7 +149,7 @@ public Color4 GlowingAccentColour
set
{
glowingAccentColour = value;
if (Glowing)
if (Glow > 0)
main.Colour = value;
}
}
Expand All @@ -154,7 +164,7 @@ public Color4 GlowColour
glowColour = value;

var effect = main.EdgeEffect;
effect.Colour = Glowing ? value : value.Opacity(0);
effect.Colour = Glow > 0 ? value : value.Opacity(0);
main.EdgeEffect = effect;
}
}
Expand Down
4 changes: 2 additions & 2 deletions osu.Game/Graphics/UserInterface/OsuCheckbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ private void load(AudioManager audio)

protected override bool OnHover(HoverEvent e)
{
Nub.Glowing = true;
Nub.Glow = 1;
return base.OnHover(e);
}

protected override void OnHoverLost(HoverLostEvent e)
{
Nub.Glowing = false;
Nub.Glow = 0;
base.OnHoverLost(e);
}

Expand Down
24 changes: 23 additions & 1 deletion osu.Game/Graphics/UserInterface/RoundedSliderBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,31 @@ protected override void OnDragEnd(DragEndEvent e)
base.OnDragEnd(e);
}

protected override void OnFocus(FocusEvent e)
{
updateGlow();
base.OnFocus(e);
}

protected override void OnFocusLost(FocusLostEvent e)
{
updateGlow();
base.OnFocusLost(e);
}

private void updateGlow()
{
Nub.Glowing = !Current.Disabled && (IsHovered || IsDragged);
int glow = 0;

if (!Current.Disabled)
{
if (IsHovered || IsDragged)
glow++;
if (HasFocus)
glow++;
}

Nub.Glow = glow;
}

protected override void UpdateAfterChildren()
Expand Down
23 changes: 21 additions & 2 deletions osu.Game/Graphics/UserInterfaceV2/FormSliderBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,30 @@ protected override void OnHoverLost(HoverLostEvent e)
base.OnHoverLost(e);
}

protected override void OnFocus(FocusEvent e)
{
updateState();
base.OnFocus(e);
}

protected override void OnFocusLost(FocusLostEvent e)
{
updateState();
base.OnFocusLost(e);
}

private void updateState()
{
int glow = 0;

if (IsHovered || IsDragged)
glow++;
if (HasFocus)
glow++;

rightBox.Colour = colourProvider.Background6;
leftBox.Colour = IsHovered || IsDragged ? colourProvider.Highlight1.Opacity(0.5f) : colourProvider.Dark2;
nub.Colour = IsHovered || IsDragged ? colourProvider.Highlight1 : colourProvider.Light4;
leftBox.Colour = glow >= 2 ? colourProvider.Highlight1.Opacity(0.5f) : glow >= 1 ? colourProvider.Colour2.Opacity(0.5f) : colourProvider.Dark2;
nub.Colour = glow >= 2 ? colourProvider.Highlight1 : glow >= 1 ? colourProvider.Colour2 : colourProvider.Light4;
}

protected override void UpdateValue(float value)
Expand Down
Loading