1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 00:45:43 +08:00
osu-lazer/osu.Game/Graphics/UserInterface/IconButton.cs

100 lines
2.6 KiB
C#
Raw Normal View History

2018-04-13 17:19:50 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Graphics;
2018-07-21 10:38:28 +08:00
using osu.Framework.Input.States;
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 { return iconColour ?? Color4.White; }
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 { return iconHoverColour ?? IconColour; }
set { iconHoverColour = value; }
}
/// <summary>
/// The icon.
/// </summary>
public FontAwesome Icon
{
get { return icon.Icon; }
set { icon.Icon = value; }
}
/// <summary>
/// The icon scale. This does not affect <see cref="IconButton.Scale"/>.
/// </summary>
public Vector2 IconScale
{
get { return icon.Scale; }
set { icon.Scale = value; }
}
/// <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;
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
}
protected override bool OnHover(InputState state)
{
icon.FadeColour(IconHoverColour, 500, Easing.OutQuint);
return base.OnHover(state);
}
protected override void OnHoverLost(InputState state)
{
icon.FadeColour(IconColour, 500, Easing.OutQuint);
base.OnHoverLost(state);
}
}
}