2019-01-24 08:43:03 +00: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.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2018-10-02 03:02:47 +00:00
|
|
|
|
using osu.Framework.Input.Events;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A Checkbox styled to be placed in line with an <see cref="OsuTabControl{T}"/>
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class OsuTabControlCheckbox : Checkbox
|
|
|
|
|
{
|
|
|
|
|
private readonly Box box;
|
|
|
|
|
private readonly SpriteText text;
|
|
|
|
|
private readonly SpriteIcon icon;
|
|
|
|
|
|
|
|
|
|
private Color4? accentColour;
|
2019-02-28 04:31:40 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
public Color4 AccentColour
|
|
|
|
|
{
|
2019-02-28 04:58:19 +00:00
|
|
|
|
get => accentColour.GetValueOrDefault();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
accentColour = value;
|
|
|
|
|
|
2019-02-21 09:56:34 +00:00
|
|
|
|
if (Current.Value)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
text.Colour = AccentColour;
|
|
|
|
|
icon.Colour = AccentColour;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Text
|
|
|
|
|
{
|
2019-02-28 04:58:19 +00:00
|
|
|
|
get => text.Text;
|
|
|
|
|
set => text.Text = value;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private const float transition_length = 500;
|
|
|
|
|
|
|
|
|
|
private void fadeIn()
|
|
|
|
|
{
|
|
|
|
|
box.FadeIn(transition_length, Easing.OutQuint);
|
|
|
|
|
text.FadeColour(Color4.White, transition_length, Easing.OutQuint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void fadeOut()
|
|
|
|
|
{
|
|
|
|
|
box.FadeOut(transition_length, Easing.OutQuint);
|
|
|
|
|
text.FadeColour(AccentColour, transition_length, Easing.OutQuint);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
fadeIn();
|
2018-10-02 03:02:47 +00:00
|
|
|
|
return base.OnHover(e);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-02-21 09:56:34 +00:00
|
|
|
|
if (!Current.Value)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
fadeOut();
|
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
base.OnHoverLost(e);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
if (accentColour == null)
|
|
|
|
|
AccentColour = colours.Blue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public OsuTabControlCheckbox()
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Margin = new MarginPadding { Top = 5, Bottom = 5, },
|
|
|
|
|
Spacing = new Vector2(5f, 0f),
|
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2019-02-12 04:04:46 +00:00
|
|
|
|
text = new OsuSpriteText { Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold) },
|
2018-04-13 09:19:50 +00:00
|
|
|
|
icon = new SpriteIcon
|
|
|
|
|
{
|
|
|
|
|
Size = new Vector2(14),
|
2019-04-02 10:55:24 +00:00
|
|
|
|
Icon = FontAwesome.Regular.Circle,
|
2018-04-13 09:19:50 +00:00
|
|
|
|
Shadow = true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
box = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Height = 1,
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
Colour = Color4.White,
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2019-02-22 08:51:39 +00:00
|
|
|
|
Current.ValueChanged += selected =>
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-02-22 08:51:39 +00:00
|
|
|
|
if (selected.NewValue)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
fadeIn();
|
2019-04-02 10:55:24 +00:00
|
|
|
|
icon.Icon = FontAwesome.Regular.CheckCircle;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fadeOut();
|
2019-04-02 10:55:24 +00:00
|
|
|
|
icon.Icon = FontAwesome.Regular.Circle;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|