2019-01-24 16:43:03 +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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2017-05-17 15:36:24 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2019-03-27 18:29:27 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2018-10-02 11:02:47 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-05-17 15:36:24 +08:00
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
|
{
|
2018-07-13 15:28:18 +08:00
|
|
|
|
public class IconButton : OsuAnimatedButton
|
2017-05-17 15:36:24 +08:00
|
|
|
|
{
|
2019-06-14 12:40:32 +08:00
|
|
|
|
public const float DEFAULT_BUTTON_SIZE = 30;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-10-12 17:17:23 +08:00
|
|
|
|
private Color4? iconColour;
|
2018-07-13 15:28:18 +08:00
|
|
|
|
|
2017-10-10 16:25:39 +08:00
|
|
|
|
/// <summary>
|
2019-11-18 15:29:18 +08:00
|
|
|
|
/// The icon colour. This does not affect <see cref="Drawable.Colour">Colour</see>.
|
2017-10-10 16:25:39 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
public Color4 IconColour
|
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
get => iconColour ?? Color4.White;
|
2017-10-12 17:17:23 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
iconColour = value;
|
2020-09-02 21:02:50 +08:00
|
|
|
|
icon.FadeColour(value);
|
2017-10-12 17:17:23 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-10-12 17:17:23 +08:00
|
|
|
|
private Color4? iconHoverColour;
|
2018-07-13 15:28:18 +08:00
|
|
|
|
|
2017-10-12 17:17:23 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The icon colour while the <see cref="IconButton"/> is hovered.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Color4 IconHoverColour
|
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
get => iconHoverColour ?? IconColour;
|
|
|
|
|
set => iconHoverColour = value;
|
2017-10-10 16:25:39 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-10-10 16:25:39 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The icon.
|
|
|
|
|
/// </summary>
|
2019-03-27 18:29:27 +08:00
|
|
|
|
public IconUsage Icon
|
2017-05-17 15:36:24 +08:00
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
get => icon.Icon;
|
|
|
|
|
set => icon.Icon = value;
|
2017-05-17 15:36:24 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-10-10 16:25:39 +08:00
|
|
|
|
/// <summary>
|
2019-11-18 15:29:18 +08:00
|
|
|
|
/// The icon scale. This does not affect <see cref="Drawable.Scale">Scale</see>.
|
2017-10-10 16:25:39 +08:00
|
|
|
|
/// </summary>
|
2017-05-17 15:36:24 +08:00
|
|
|
|
public Vector2 IconScale
|
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
get => icon.Scale;
|
|
|
|
|
set => icon.Scale = value;
|
2017-05-17 15:36:24 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-10-10 16:20:23 +08:00
|
|
|
|
private readonly SpriteIcon icon;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-05-30 17:23:53 +08:00
|
|
|
|
public IconButton()
|
2017-05-17 15:36:24 +08:00
|
|
|
|
{
|
2019-06-14 12:40:32 +08:00
|
|
|
|
Size = new Vector2(DEFAULT_BUTTON_SIZE);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-07-13 15:28:18 +08:00
|
|
|
|
Add(icon = new SpriteIcon
|
2017-05-17 15:36:24 +08:00
|
|
|
|
{
|
2018-07-13 15:28:18 +08:00
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Size = new Vector2(18),
|
|
|
|
|
});
|
2017-05-17 15:36:24 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
2017-05-17 15:36:24 +08:00
|
|
|
|
{
|
2017-10-12 17:17:23 +08:00
|
|
|
|
icon.FadeColour(IconHoverColour, 500, Easing.OutQuint);
|
2018-10-02 11:02:47 +08:00
|
|
|
|
return base.OnHover(e);
|
2017-05-17 15:36:24 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
2017-05-17 15:36:24 +08:00
|
|
|
|
{
|
2017-10-12 17:17:23 +08:00
|
|
|
|
icon.FadeColour(IconColour, 500, Easing.OutQuint);
|
2018-10-02 11:02:47 +08:00
|
|
|
|
base.OnHoverLost(e);
|
2017-05-17 15:36:24 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|