osu/osu.Game/Graphics/UserInterface/IconButton.cs

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

87 lines
2.3 KiB
C#
Raw Normal View History

// 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;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
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
{
2018-07-13 07:28:18 +00:00
public partial class IconButton : OsuAnimatedButton
{
public const float DEFAULT_BUTTON_SIZE = 30;
2018-04-13 09:19:50 +00:00
private Color4? iconColour;
2018-07-13 07:28:18 +00:00
2017-10-10 08:25:39 +00:00
/// <summary>
/// The icon colour. This does not affect <see cref="Drawable.Colour">Colour</see>.
2017-10-10 08:25:39 +00:00
/// </summary>
public Color4 IconColour
{
get => iconColour ?? Color4.White;
set
{
iconColour = value;
icon.FadeColour(value);
}
}
2018-04-13 09:19:50 +00:00
private Color4? iconHoverColour;
2018-07-13 07:28:18 +00:00
/// <summary>
/// The icon colour while the <see cref="IconButton"/> is hovered.
/// </summary>
public Color4 IconHoverColour
{
get => iconHoverColour ?? IconColour;
set => iconHoverColour = value;
2017-10-10 08:25:39 +00:00
}
2018-04-13 09:19:50 +00:00
2017-10-10 08:25:39 +00:00
/// <summary>
/// The icon.
/// </summary>
public IconUsage Icon
{
get => icon.Icon;
set => icon.Icon = value;
}
2018-04-13 09:19:50 +00:00
2017-10-10 08:25:39 +00:00
/// <summary>
/// The icon scale. This does not affect <see cref="Drawable.Scale">Scale</see>.
2017-10-10 08:25:39 +00:00
/// </summary>
public Vector2 IconScale
{
get => icon.Scale;
set => icon.Scale = value;
}
2018-04-13 09:19:50 +00:00
2017-10-10 08:20:23 +00:00
private readonly SpriteIcon icon;
2018-04-13 09:19:50 +00:00
2017-05-30 09:23:53 +00:00
public IconButton()
{
Size = new Vector2(DEFAULT_BUTTON_SIZE);
2018-04-13 09:19:50 +00:00
2018-07-13 07:28:18 +00:00
Add(icon = new SpriteIcon
{
2018-07-13 07:28:18 +00:00
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Size = new Vector2(18),
});
}
2018-04-13 09:19:50 +00:00
2018-10-02 03:02:47 +00:00
protected override bool OnHover(HoverEvent e)
{
icon.FadeColour(IconHoverColour, 500, Easing.OutQuint);
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)
{
icon.FadeColour(IconColour, 500, Easing.OutQuint);
2018-10-02 03:02:47 +00:00
base.OnHoverLost(e);
}
}
}