1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-27 13:53:10 +08:00
osu-lazer/osu.Game/Graphics/UserInterfaceV2/OsuHSVColourPicker.cs

130 lines
4.4 KiB
C#
Raw Normal View History

2021-06-06 19:05:26 +08:00
// 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.
2022-06-17 15:37:17 +08:00
#nullable disable
2021-06-06 19:05:26 +08:00
using JetBrains.Annotations;
using osu.Framework.Allocation;
2021-07-02 07:02:36 +08:00
using osu.Framework.Bindables;
2021-06-06 19:05:26 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Overlays;
using osuTK;
namespace osu.Game.Graphics.UserInterfaceV2
{
public class OsuHSVColourPicker : HSVColourPicker
{
2021-07-02 07:02:36 +08:00
private const float spacing = 10;
private const float corner_radius = 10;
private const float control_border_thickness = 3;
2021-06-06 19:05:26 +08:00
protected override HueSelector CreateHueSelector() => new OsuHueSelector();
protected override SaturationValueSelector CreateSaturationValueSelector() => new OsuSaturationValueSelector();
[BackgroundDependencyLoader(true)]
private void load([CanBeNull] OverlayColourProvider colourProvider, OsuColour osuColour)
{
Background.Colour = colourProvider?.Dark5 ?? osuColour.GreySeaFoamDark;
2021-06-06 19:05:26 +08:00
2021-07-02 07:02:36 +08:00
Content.Padding = new MarginPadding(spacing);
Content.Spacing = new Vector2(0, spacing);
2021-06-06 19:05:26 +08:00
}
2021-07-02 07:02:36 +08:00
private static EdgeEffectParameters createShadowParameters() => new EdgeEffectParameters
{
Type = EdgeEffectType.Shadow,
Offset = new Vector2(0, 1),
Radius = 3,
Colour = Colour4.Black.Opacity(0.3f)
};
2021-06-06 19:05:26 +08:00
private class OsuHueSelector : HueSelector
{
public OsuHueSelector()
{
2021-07-02 07:02:36 +08:00
SliderBar.CornerRadius = corner_radius;
2021-06-06 19:05:26 +08:00
SliderBar.Masking = true;
}
2021-07-02 07:02:36 +08:00
protected override Drawable CreateSliderNub() => new SliderNub(this);
2021-06-06 19:05:26 +08:00
private class SliderNub : CompositeDrawable
{
2021-07-02 07:02:36 +08:00
private readonly Bindable<float> hue;
private readonly Box fill;
public SliderNub(OsuHueSelector osuHueSelector)
2021-06-06 19:05:26 +08:00
{
2021-07-02 07:02:36 +08:00
hue = osuHueSelector.Hue.GetBoundCopy();
InternalChild = new CircularContainer
2021-06-06 19:05:26 +08:00
{
2021-07-02 07:02:36 +08:00
Height = 35,
Width = 10,
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Masking = true,
BorderColour = Colour4.White,
BorderThickness = control_border_thickness,
EdgeEffect = createShadowParameters(),
Child = fill = new Box
{
RelativeSizeAxes = Axes.Both
}
2021-06-06 19:05:26 +08:00
};
}
2021-07-02 07:02:36 +08:00
protected override void LoadComplete()
{
hue.BindValueChanged(h => fill.Colour = Colour4.FromHSV(h.NewValue, 1, 1), true);
}
2021-06-06 19:05:26 +08:00
}
}
private class OsuSaturationValueSelector : SaturationValueSelector
{
public OsuSaturationValueSelector()
{
2021-07-02 07:02:36 +08:00
SelectionArea.CornerRadius = corner_radius;
2021-06-06 19:05:26 +08:00
SelectionArea.Masking = true;
}
protected override Marker CreateMarker() => new OsuMarker();
private class OsuMarker : Marker
{
private readonly Box previewBox;
public OsuMarker()
{
AutoSizeAxes = Axes.Both;
InternalChild = new CircularContainer
{
Size = new Vector2(20),
Masking = true,
BorderColour = Colour4.White,
2021-07-02 07:02:36 +08:00
BorderThickness = control_border_thickness,
EdgeEffect = createShadowParameters(),
2021-06-06 19:05:26 +08:00
Child = previewBox = new Box
{
RelativeSizeAxes = Axes.Both
}
};
}
protected override void LoadComplete()
{
base.LoadComplete();
Current.BindValueChanged(colour => previewBox.Colour = colour.NewValue, true);
}
}
}
}
}