1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 07:47:25 +08:00
osu-lazer/osu.Game/Graphics/UserInterface/OsuTabControlCheckBox.cs

141 lines
4.2 KiB
C#
Raw Normal View History

2017-03-23 11:22:31 +08:00
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Transforms;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input;
using osu.Game.Graphics.Sprites;
namespace osu.Game.Graphics.UserInterface
{
/// <summary>
2017-03-23 12:35:55 +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>
public class OsuTabControlCheckBox : CheckBox
{
2017-03-23 11:29:28 +08:00
private Box box;
private SpriteText text;
private TextAwesome icon;
2017-03-23 11:22:31 +08:00
public event EventHandler<CheckBoxState> Action;
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-03-23 11:29:28 +08:00
if (State != CheckBoxState.Checked)
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; }
}
protected override void OnChecked()
{
fadeIn();
icon.Icon = FontAwesome.fa_check_circle_o;
Action?.Invoke(this, State);
}
protected override void OnUnchecked()
{
fadeOut();
icon.Icon = FontAwesome.fa_circle_o;
Action?.Invoke(this, State);
}
2017-03-23 11:29:28 +08:00
private const float transition_length = 500;
private void fadeIn()
{
box.FadeIn(transition_length, EasingTypes.OutQuint);
text.FadeColour(Color4.White, transition_length, EasingTypes.OutQuint);
}
private void fadeOut()
{
box.FadeOut(transition_length, EasingTypes.OutQuint);
text.FadeColour(AccentColour, transition_length, EasingTypes.OutQuint);
}
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)
{
if (State == CheckBoxState.Unchecked)
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-23 11:22:31 +08:00
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[]
{
text = new OsuSpriteText
{
TextSize = 14,
Font = @"Exo2.0-Bold",
},
icon = new TextAwesome
{
TextSize = 14,
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,
}
};
}
}
}