1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-16 14:57:25 +08:00
osu-lazer/osu.Game/Graphics/UserInterfaceV2/OsuHSVColourPicker.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

127 lines
4.3 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.
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 partial 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(OverlayColourProvider? colourProvider, OsuColour osuColour)
2021-06-06 19:05:26 +08:00
{
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 partial 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 partial 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 partial 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 partial 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);
}
}
}
}
}