2018-01-05 19:21:19 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
2017-03-23 11:22:31 +08:00
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-06-20 13:54:23 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2017-03-23 11:22:31 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
|
|
|
|
using osu.Framework.Input;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2017-03-31 16:38:33 +08:00
|
|
|
|
/// A Checkbox styled to be placed in line with an <see cref="OsuTabControl{T}"/>
|
2017-03-23 11:22:31 +08:00
|
|
|
|
/// </summary>
|
2017-03-31 16:38:33 +08:00
|
|
|
|
public class OsuTabControlCheckbox : Checkbox
|
2017-03-23 11:22:31 +08:00
|
|
|
|
{
|
2017-03-23 13:47:27 +08:00
|
|
|
|
private readonly Box box;
|
|
|
|
|
private readonly SpriteText text;
|
2017-08-03 13:36:21 +08:00
|
|
|
|
private readonly SpriteIcon icon;
|
2017-03-23 11:22:31 +08:00
|
|
|
|
|
2017-03-23 11:29:28 +08:00
|
|
|
|
private Color4? accentColour;
|
2017-03-23 11:22:31 +08:00
|
|
|
|
public Color4 AccentColour
|
|
|
|
|
{
|
2017-03-23 11:29:28 +08:00
|
|
|
|
get { return accentColour.GetValueOrDefault(); }
|
2017-03-23 11:22:31 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
accentColour = value;
|
|
|
|
|
|
2017-04-10 13:31:08 +08:00
|
|
|
|
if (Current)
|
2017-03-23 11:22:31 +08:00
|
|
|
|
{
|
2017-03-23 11:29:28 +08:00
|
|
|
|
text.Colour = AccentColour;
|
|
|
|
|
icon.Colour = AccentColour;
|
2017-03-23 11:22:31 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Text
|
|
|
|
|
{
|
|
|
|
|
get { return text.Text; }
|
|
|
|
|
set { text.Text = value; }
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-23 11:29:28 +08:00
|
|
|
|
private const float transition_length = 500;
|
|
|
|
|
|
|
|
|
|
private void fadeIn()
|
|
|
|
|
{
|
2017-07-23 02:50:25 +08:00
|
|
|
|
box.FadeIn(transition_length, Easing.OutQuint);
|
|
|
|
|
text.FadeColour(Color4.White, transition_length, Easing.OutQuint);
|
2017-03-23 11:29:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void fadeOut()
|
|
|
|
|
{
|
2017-07-23 02:50:25 +08:00
|
|
|
|
box.FadeOut(transition_length, Easing.OutQuint);
|
|
|
|
|
text.FadeColour(AccentColour, transition_length, Easing.OutQuint);
|
2017-03-23 11:29:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-23 11:22:31 +08:00
|
|
|
|
protected override bool OnHover(InputState state)
|
|
|
|
|
{
|
|
|
|
|
fadeIn();
|
|
|
|
|
return base.OnHover(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHoverLost(InputState state)
|
|
|
|
|
{
|
2017-04-10 13:31:08 +08:00
|
|
|
|
if (!Current)
|
2017-03-23 11:22:31 +08:00
|
|
|
|
fadeOut();
|
|
|
|
|
|
|
|
|
|
base.OnHoverLost(state);
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-23 11:29:28 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
if (accentColour == null)
|
|
|
|
|
AccentColour = colours.Blue;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-31 16:38:33 +08:00
|
|
|
|
public OsuTabControlCheckbox()
|
2017-03-23 11:22:31 +08:00
|
|
|
|
{
|
|
|
|
|
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[]
|
|
|
|
|
{
|
|
|
|
|
text = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
TextSize = 14,
|
|
|
|
|
Font = @"Exo2.0-Bold",
|
|
|
|
|
},
|
2017-08-03 13:36:21 +08:00
|
|
|
|
icon = new SpriteIcon
|
2017-03-23 11:22:31 +08:00
|
|
|
|
{
|
2017-08-03 13:36:21 +08:00
|
|
|
|
Size = new Vector2(14),
|
2017-03-23 11:22:31 +08:00
|
|
|
|
Icon = FontAwesome.fa_circle_o,
|
|
|
|
|
Shadow = true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
box = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Height = 1,
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
Colour = Color4.White,
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
}
|
|
|
|
|
};
|
2017-04-10 13:31:08 +08:00
|
|
|
|
|
|
|
|
|
Current.ValueChanged += v =>
|
|
|
|
|
{
|
|
|
|
|
if (v)
|
|
|
|
|
{
|
|
|
|
|
fadeIn();
|
|
|
|
|
icon.Icon = FontAwesome.fa_check_circle_o;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fadeOut();
|
|
|
|
|
icon.Icon = FontAwesome.fa_circle_o;
|
|
|
|
|
}
|
|
|
|
|
};
|
2017-03-23 11:22:31 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|