1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 04:07:25 +08:00
osu-lazer/osu.Game/Graphics/UserInterface/IconButton.cs

102 lines
2.6 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 17:19:50 +08:00
2018-11-20 15:51:59 +08:00
using osuTK;
using osuTK.Graphics;
2018-04-13 17:19:50 +08:00
using osu.Framework.Graphics;
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
namespace osu.Game.Graphics.UserInterface
{
2018-07-13 15:28:18 +08:00
public class IconButton : OsuAnimatedButton
2018-04-13 17:19:50 +08:00
{
public const float BUTTON_SIZE = 30;
private Color4? iconColour;
2018-07-13 15:28:18 +08:00
2018-04-13 17:19:50 +08:00
/// <summary>
/// The icon colour. This does not affect <see cref="IconButton.Colour"/>.
/// </summary>
public Color4 IconColour
{
get => iconColour ?? Color4.White;
2018-04-13 17:19:50 +08:00
set
{
iconColour = value;
icon.Colour = value;
}
}
private Color4? iconHoverColour;
2018-07-13 15:28:18 +08:00
2018-04-13 17:19:50 +08:00
/// <summary>
/// The icon colour while the <see cref="IconButton"/> is hovered.
/// </summary>
public Color4 IconHoverColour
{
get => iconHoverColour ?? IconColour;
set => iconHoverColour = value;
2018-04-13 17:19:50 +08:00
}
/// <summary>
/// The icon.
/// </summary>
public IconUsage Icon
2018-04-13 17:19:50 +08:00
{
get => icon.Icon;
set => icon.Icon = value;
2018-04-13 17:19:50 +08:00
}
/// <summary>
/// The icon scale. This does not affect <see cref="IconButton.Scale"/>.
/// </summary>
public Vector2 IconScale
{
get => icon.Scale;
set => icon.Scale = value;
2018-04-13 17:19:50 +08:00
}
/// <summary>
/// The size of the <see cref="IconButton"/> while it is not being pressed.
/// </summary>
public Vector2 ButtonSize
{
2018-07-13 15:28:18 +08:00
get => Content.Size;
set
{
Content.RelativeSizeAxes = Axes.None;
2019-06-03 15:33:45 +08:00
Content.AutoSizeAxes = Axes.None;
2018-07-13 15:28:18 +08:00
Content.Size = value;
}
2018-04-13 17:19:50 +08:00
}
private readonly SpriteIcon icon;
public IconButton()
{
AutoSizeAxes = Axes.Both;
2018-07-13 15:28:18 +08:00
ButtonSize = new Vector2(BUTTON_SIZE);
2018-04-13 17:19:50 +08:00
2018-07-13 15:28:18 +08:00
Add(icon = new SpriteIcon
2018-04-13 17:19:50 +08:00
{
2018-07-13 15:28:18 +08:00
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Size = new Vector2(18),
});
2018-04-13 17:19:50 +08:00
}
2018-10-02 11:02:47 +08:00
protected override bool OnHover(HoverEvent e)
2018-04-13 17:19:50 +08:00
{
icon.FadeColour(IconHoverColour, 500, Easing.OutQuint);
2018-10-02 11:02:47 +08:00
return base.OnHover(e);
2018-04-13 17:19:50 +08:00
}
2018-10-02 11:02:47 +08:00
protected override void OnHoverLost(HoverLostEvent e)
2018-04-13 17:19:50 +08:00
{
icon.FadeColour(IconColour, 500, Easing.OutQuint);
2018-10-02 11:02:47 +08:00
base.OnHoverLost(e);
2018-04-13 17:19:50 +08:00
}
}
}