2020-10-01 15:34:34 +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.
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Edit.Compose.Components
|
|
|
|
{
|
2021-04-24 12:46:38 +08:00
|
|
|
public sealed class SelectionBoxButton : SelectionBoxControl, IHasTooltip
|
2020-10-01 15:34:34 +08:00
|
|
|
{
|
|
|
|
private SpriteIcon icon;
|
|
|
|
|
|
|
|
private readonly IconUsage iconUsage;
|
|
|
|
|
|
|
|
public Action Action;
|
|
|
|
|
2021-04-24 12:46:38 +08:00
|
|
|
public SelectionBoxButton(IconUsage iconUsage, string tooltip)
|
2020-10-01 15:34:34 +08:00
|
|
|
{
|
|
|
|
this.iconUsage = iconUsage;
|
|
|
|
|
|
|
|
TooltipText = tooltip;
|
|
|
|
|
|
|
|
Anchor = Anchor.Centre;
|
|
|
|
Origin = Anchor.Centre;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2021-04-24 12:46:38 +08:00
|
|
|
Size = new Vector2(20);
|
2020-10-01 15:34:34 +08:00
|
|
|
AddInternal(icon = new SpriteIcon
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Size = new Vector2(0.5f),
|
|
|
|
Icon = iconUsage,
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnClick(ClickEvent e)
|
|
|
|
{
|
2021-04-24 12:46:38 +08:00
|
|
|
OnOperationStarted();
|
2020-10-01 15:34:34 +08:00
|
|
|
Action?.Invoke();
|
2021-04-24 12:46:38 +08:00
|
|
|
OnOperationEnded();
|
2020-10-01 15:34:34 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void UpdateHoverState()
|
|
|
|
{
|
|
|
|
base.UpdateHoverState();
|
2021-04-25 12:43:56 +08:00
|
|
|
icon.FadeColour(!HandlingMouse && IsHovered ? Color4.White : Color4.Black, TRANSFORM_DURATION, Easing.OutQuint);
|
2020-10-01 15:34:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public string TooltipText { get; }
|
|
|
|
}
|
|
|
|
}
|