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 06:41:36 +08:00
|
|
|
public abstract class SelectionBoxControl : CompositeDrawable
|
2021-04-24 12:44:33 +08:00
|
|
|
{
|
2021-04-26 06:41:36 +08:00
|
|
|
public 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;
|
|
|
|
|
|
|
|
private Circle circle;
|
|
|
|
|
2021-04-25 12:49:31 +08:00
|
|
|
/// <summary>
|
2021-05-04 11:40:43 +08:00
|
|
|
/// Whether the user is currently holding the control with mouse.
|
2021-04-25 12:49:31 +08:00
|
|
|
/// </summary>
|
2021-05-04 11:40:43 +08:00
|
|
|
public bool IsHeld { get; private set; }
|
2021-04-25 12:49:31 +08:00
|
|
|
|
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();
|
2021-05-03 17:19:34 +08:00
|
|
|
|
2021-04-24 12:44:33 +08:00
|
|
|
UpdateHoverState();
|
2021-05-03 17:19:34 +08:00
|
|
|
FinishTransforms(true);
|
2021-04-24 12:44:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
{
|
|
|
|
UpdateHoverState();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
{
|
|
|
|
UpdateHoverState();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnMouseDown(MouseDownEvent e)
|
|
|
|
{
|
2021-05-04 11:40:43 +08:00
|
|
|
IsHeld = true;
|
2021-04-24 12:44:33 +08:00
|
|
|
UpdateHoverState();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnMouseUp(MouseUpEvent e)
|
|
|
|
{
|
2021-05-04 11:40:43 +08:00
|
|
|
IsHeld = false;
|
2021-04-24 12:44:33 +08:00
|
|
|
UpdateHoverState();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual void UpdateHoverState()
|
|
|
|
{
|
2021-05-04 11:40:43 +08:00
|
|
|
if (IsHeld)
|
2021-04-25 12:43:56 +08:00
|
|
|
circle.FadeColour(Colours.GrayF, TRANSFORM_DURATION, Easing.OutQuint);
|
|
|
|
else
|
|
|
|
circle.FadeColour(IsHovered ? Colours.Red : Colours.YellowDark, TRANSFORM_DURATION, Easing.OutQuint);
|
|
|
|
|
2021-05-04 11:40:43 +08:00
|
|
|
this.ScaleTo(IsHeld || IsHovered ? 1.5f : 1, TRANSFORM_DURATION, Easing.OutQuint);
|
2021-04-24 12:44:33 +08:00
|
|
|
}
|
|
|
|
|
2021-05-06 02:50:11 +08:00
|
|
|
protected void TriggerOperationStarted() => OperationStarted?.Invoke();
|
2021-04-24 12:44:33 +08:00
|
|
|
|
2021-05-06 02:50:11 +08:00
|
|
|
protected void TriggerOperatoinEnded() => OperationEnded?.Invoke();
|
2021-04-24 12:44:33 +08:00
|
|
|
}
|
|
|
|
}
|