1
0
mirror of https://github.com/ppy/osu.git synced 2026-06-13 22:14:35 +08:00
Files
osu-lazer/osu.Game/Graphics/UserInterfaceV2/FormControlBackground.cs
T
Denis Titovets 9143e4936c Fix flashes on some form controls going beyond the borders (#37903)
changes can be reviewed commit by commit, explanations are attached

| master | 58c677007e |
2f21914ee2 |
|-|-|-|
| <img width="517" height="86" alt="Снимок экрана 2026-05-23 235003"
src="https://github.com/user-attachments/assets/6c11bdac-118e-4f63-883a-ec6a802b94a9"
/> | <img width="514" height="86" alt="Снимок экрана 2026-05-23 235109"
src="https://github.com/user-attachments/assets/d46aac3e-08d1-4462-b4f6-083c1e321c09"
/> | <img width="516" height="82" alt="Снимок экрана 2026-05-24 142215"
src="https://github.com/user-attachments/assets/063317f2-7643-4fe6-bae8-e8e8c4145641"
/> |
| <img width="521" height="90" alt="Снимок экрана 2026-05-24 142702"
src="https://github.com/user-attachments/assets/5530fd71-a2d8-4700-827d-485ca41bc1a6"
/> | <img width="518" height="90" alt="Снимок экрана 2026-05-24 142552"
src="https://github.com/user-attachments/assets/35865f21-9120-4384-ab32-7dd135dd907e"
/> | <img width="526" height="89" alt="Снимок экрана 2026-05-24 142412"
src="https://github.com/user-attachments/assets/27ea3af6-9b1d-400b-9f02-eee453e23b64"
/> |

master


https://github.com/user-attachments/assets/0d37c1b1-ab1d-4f07-ac3a-024fa4af5fc3

58c677007e


https://github.com/user-attachments/assets/a315a5da-330a-4dec-b323-ac11f081939a

2f21914ee2


https://github.com/user-attachments/assets/b8197983-2be7-478b-b5b1-c554b72d56e2

---------

Co-authored-by: Bartłomiej Dach <dach.bartlomiej@gmail.com>
2026-06-10 14:11:30 +02:00

144 lines
4.2 KiB
C#

// 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 osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays;
using osuTK.Graphics;
namespace osu.Game.Graphics.UserInterfaceV2
{
public partial class FormControlBackground : CompositeDrawable
{
public const float CORNER_EXPONENT = 2.5f;
public const float BORDER_THICKNESS = 2.5f;
private VisualStyle visualStyle;
public VisualStyle VisualStyle
{
get => visualStyle;
set
{
visualStyle = value;
updateStyle();
}
}
[Resolved]
private OverlayColourProvider colourProvider { get; set; } = null!;
private readonly Box box;
private readonly Box flashLayer;
private readonly HoverSounds sounds;
public FormControlBackground()
{
RelativeSizeAxes = Axes.Both;
Masking = true;
CornerRadius = 5;
CornerExponent = 2.5f;
CornerExponent = CORNER_EXPONENT;
BorderThickness = BORDER_THICKNESS;
InternalChildren = new Drawable[]
{
box = new Box
{
Colour = Color4.White,
RelativeSizeAxes = Axes.Both,
},
flashLayer = new Box
{
Colour = Colour4.Transparent,
RelativeSizeAxes = Axes.Both,
},
sounds = new HoverSounds(),
};
}
protected override void LoadComplete()
{
base.LoadComplete();
updateStyle();
FinishTransforms(true);
}
private void flash(Colour4 flashColour, double duration)
{
flashLayer.Colour = ColourInfo.GradientVertical(flashColour.Opacity(0), flashColour);
flashLayer.FadeOutFromOne(duration, Easing.OutQuint);
}
/// <summary>
/// Use when indicating that a change in value or a definitive action has occurred.
/// </summary>
public void FlashOnCommit() => flash(colourProvider.Dark2, 800);
/// <summary>
/// Use when rejecting the user's input as incorrect.
/// </summary>
public void FlashOnInputError() => flash(Colour4.Red, 200);
private void updateStyle()
{
sounds.Enabled.Value = visualStyle != VisualStyle.Disabled;
ColourInfo colour;
ColourInfo borderColour;
bool border = false;
switch (visualStyle)
{
case VisualStyle.Normal:
colour = colourProvider.Background4.Darken(0.1f);
borderColour = colourProvider.Light4;
break;
case VisualStyle.Disabled:
colour = colourProvider.Background4;
borderColour = colourProvider.Dark1;
break;
case VisualStyle.Hovered:
colour = ColourInfo.GradientVertical(colourProvider.Background5, colourProvider.Dark4);
borderColour = colourProvider.Light4;
border = true;
break;
case VisualStyle.Focused:
colour = ColourInfo.GradientVertical(colourProvider.Background5, colourProvider.Dark3);
border = true;
borderColour = colourProvider.Highlight1;
break;
default:
throw new ArgumentOutOfRangeException();
}
this.TransformTo(nameof(BorderColour), border ? borderColour : colour, 250, Easing.OutQuint);
box.FadeColour(colour, 250, Easing.OutQuint);
}
}
public enum VisualStyle
{
Normal,
Disabled,
Hovered,
Focused
}
}