// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using osuTK; using osuTK.Graphics; using osu.Framework.Graphics; using osu.Framework.Input.Events; namespace osu.Game.Graphics.UserInterface { public class IconButton : OsuAnimatedButton { public const float BUTTON_SIZE = 30; private Color4? iconColour; /// /// The icon colour. This does not affect . /// public Color4 IconColour { get { return iconColour ?? Color4.White; } set { iconColour = value; icon.Colour = value; } } private Color4? iconHoverColour; /// /// The icon colour while the is hovered. /// public Color4 IconHoverColour { get { return iconHoverColour ?? IconColour; } set { iconHoverColour = value; } } /// /// The icon. /// public FontAwesome Icon { get { return icon.Icon; } set { icon.Icon = value; } } /// /// The icon scale. This does not affect . /// public Vector2 IconScale { get { return icon.Scale; } set { icon.Scale = value; } } /// /// The size of the while it is not being pressed. /// public Vector2 ButtonSize { get => Content.Size; set { Content.RelativeSizeAxes = Axes.None; Content.Size = value; } } private readonly SpriteIcon icon; public IconButton() { AutoSizeAxes = Axes.Both; ButtonSize = new Vector2(BUTTON_SIZE); Add(icon = new SpriteIcon { Origin = Anchor.Centre, Anchor = Anchor.Centre, Size = new Vector2(18), }); } protected override bool OnHover(HoverEvent e) { icon.FadeColour(IconHoverColour, 500, Easing.OutQuint); return base.OnHover(e); } protected override void OnHoverLost(HoverLostEvent e) { icon.FadeColour(IconColour, 500, Easing.OutQuint); base.OnHoverLost(e); } } }