2021-04-24 12:44:33 +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.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Edit.Compose.Components
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Represents the base appearance for UI controls of the <see cref="SelectionBox"/>,
|
|
|
|
/// such as scale handles, rotation handles, buttons, etc...
|
|
|
|
/// </summary>
|
2021-04-26 00:58:50 +08:00
|
|
|
public abstract class SelectionBoxControl : VisibilityContainer
|
2021-04-24 12:44:33 +08:00
|
|
|
{
|
2021-04-26 00:58:50 +08:00
|
|
|
protected const double TRANSFORM_DURATION = 100;
|
2021-04-25 12:43:56 +08:00
|
|
|
|
2021-04-24 12:44:33 +08:00
|
|
|
public event Action OperationStarted;
|
|
|
|
public event Action OperationEnded;
|
|
|
|
|
|
|
|
internal event Action HoverGained;
|
|
|
|
internal event Action HoverLost;
|
|
|
|
|
|
|
|
private Circle circle;
|
|
|
|
|
2021-04-25 12:49:31 +08:00
|
|
|
/// <summary>
|
2021-04-26 00:26:53 +08:00
|
|
|
/// Whether this control is currently being operated on by the user.
|
2021-04-25 12:49:31 +08:00
|
|
|
/// </summary>
|
|
|
|
public bool InOperation { get; private set; }
|
|
|
|
|
2021-04-24 12:44:33 +08:00
|
|
|
[Resolved]
|
|
|
|
protected OsuColour Colours { get; private set; }
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
Origin = Anchor.Centre;
|
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
circle = new Circle
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
UpdateHoverState();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
{
|
|
|
|
UpdateHoverState();
|
|
|
|
HoverGained?.Invoke();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
{
|
|
|
|
base.OnHoverLost(e);
|
|
|
|
HoverLost?.Invoke();
|
|
|
|
UpdateHoverState();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Whether this control is currently handling mouse down input.
|
|
|
|
/// </summary>
|
|
|
|
protected bool HandlingMouse { get; set; }
|
|
|
|
|
|
|
|
protected override bool OnMouseDown(MouseDownEvent e)
|
|
|
|
{
|
|
|
|
HandlingMouse = true;
|
|
|
|
UpdateHoverState();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnMouseUp(MouseUpEvent e)
|
|
|
|
{
|
|
|
|
HandlingMouse = false;
|
|
|
|
UpdateHoverState();
|
|
|
|
base.OnMouseUp(e);
|
|
|
|
}
|
|
|
|
|
2021-04-26 00:58:50 +08:00
|
|
|
protected override void PopIn() => this.FadeIn(TRANSFORM_DURATION, Easing.OutQuint);
|
|
|
|
|
|
|
|
protected override void PopOut() => this.FadeOut(TRANSFORM_DURATION, Easing.OutQuint);
|
|
|
|
|
2021-04-24 12:44:33 +08:00
|
|
|
protected virtual void UpdateHoverState()
|
|
|
|
{
|
2021-04-25 12:43:56 +08:00
|
|
|
if (HandlingMouse)
|
|
|
|
circle.FadeColour(Colours.GrayF, TRANSFORM_DURATION, Easing.OutQuint);
|
|
|
|
else
|
|
|
|
circle.FadeColour(IsHovered ? Colours.Red : Colours.YellowDark, TRANSFORM_DURATION, Easing.OutQuint);
|
|
|
|
|
|
|
|
this.ScaleTo(HandlingMouse || IsHovered ? 1.5f : 1, TRANSFORM_DURATION, Easing.OutQuint);
|
2021-04-24 12:44:33 +08:00
|
|
|
}
|
|
|
|
|
2021-04-25 12:49:31 +08:00
|
|
|
protected void OnOperationStarted()
|
|
|
|
{
|
|
|
|
InOperation = true;
|
|
|
|
OperationStarted?.Invoke();
|
|
|
|
}
|
2021-04-24 12:44:33 +08:00
|
|
|
|
2021-04-25 12:49:31 +08:00
|
|
|
protected void OnOperationEnded()
|
|
|
|
{
|
|
|
|
InOperation = false;
|
|
|
|
OperationEnded?.Invoke();
|
|
|
|
}
|
2021-04-24 12:44:33 +08:00
|
|
|
}
|
|
|
|
}
|