mirror of
https://github.com/ppy/osu
synced 2025-01-10 16:19:47 +00:00
Merge pull request #16371 from bdach/angle-of-rotation-display
Add tooltip with relative rotation in degrees to rotation handles
This commit is contained in:
commit
e333831c45
@ -15,6 +15,7 @@ using osuTK.Input;
|
||||
|
||||
namespace osu.Game.Screens.Edit.Compose.Components
|
||||
{
|
||||
[Cached]
|
||||
public class SelectionBox : CompositeDrawable
|
||||
{
|
||||
public const float BORDER_RADIUS = 3;
|
||||
@ -306,7 +307,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
var handle = new SelectionBoxScaleHandle
|
||||
{
|
||||
Anchor = anchor,
|
||||
HandleDrag = e => OnScale?.Invoke(e.Delta, anchor)
|
||||
HandleScale = (delta, a) => OnScale?.Invoke(delta, a)
|
||||
};
|
||||
|
||||
handle.OperationStarted += operationStarted;
|
||||
@ -319,7 +320,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
var handle = new SelectionBoxRotationHandle
|
||||
{
|
||||
Anchor = anchor,
|
||||
HandleDrag = e => OnRotation?.Invoke(convertDragEventToAngleOfRotation(e))
|
||||
HandleRotate = angle => OnRotation?.Invoke(angle)
|
||||
};
|
||||
|
||||
handle.OperationStarted += operationStarted;
|
||||
|
@ -8,20 +8,12 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
{
|
||||
public abstract class SelectionBoxDragHandle : SelectionBoxControl
|
||||
{
|
||||
public Action<DragEvent> HandleDrag { get; set; }
|
||||
|
||||
protected override bool OnDragStart(DragStartEvent e)
|
||||
{
|
||||
TriggerOperationStarted();
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void OnDrag(DragEvent e)
|
||||
{
|
||||
HandleDrag?.Invoke(e);
|
||||
base.OnDrag(e);
|
||||
}
|
||||
|
||||
protected override void OnDragEnd(DragEndEvent e)
|
||||
{
|
||||
TriggerOperationEnded();
|
||||
|
@ -1,19 +1,34 @@
|
||||
// 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.Bindables;
|
||||
using osu.Framework.Extensions.EnumExtensions;
|
||||
using osu.Framework.Extensions.LocalisationExtensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Cursor;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Framework.Localisation;
|
||||
using osuTK;
|
||||
using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Screens.Edit.Compose.Components
|
||||
{
|
||||
public class SelectionBoxRotationHandle : SelectionBoxDragHandle
|
||||
public class SelectionBoxRotationHandle : SelectionBoxDragHandle, IHasTooltip
|
||||
{
|
||||
public Action<float> HandleRotate { get; set; }
|
||||
|
||||
public LocalisableString TooltipText { get; private set; }
|
||||
|
||||
private SpriteIcon icon;
|
||||
|
||||
private readonly Bindable<float?> cumulativeRotation = new Bindable<float?>();
|
||||
|
||||
[Resolved]
|
||||
private SelectionBox selectionBox { get; set; }
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
@ -33,10 +48,59 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
});
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
cumulativeRotation.BindValueChanged(_ => updateTooltipText(), true);
|
||||
}
|
||||
|
||||
protected override void UpdateHoverState()
|
||||
{
|
||||
base.UpdateHoverState();
|
||||
icon.FadeColour(!IsHeld && IsHovered ? Color4.White : Color4.Black, TRANSFORM_DURATION, Easing.OutQuint);
|
||||
}
|
||||
|
||||
protected override bool OnDragStart(DragStartEvent e)
|
||||
{
|
||||
bool handle = base.OnDragStart(e);
|
||||
if (handle)
|
||||
cumulativeRotation.Value = 0;
|
||||
return handle;
|
||||
}
|
||||
|
||||
protected override void OnDrag(DragEvent e)
|
||||
{
|
||||
base.OnDrag(e);
|
||||
|
||||
float instantaneousAngle = convertDragEventToAngleOfRotation(e);
|
||||
cumulativeRotation.Value += instantaneousAngle;
|
||||
|
||||
if (cumulativeRotation.Value < -180)
|
||||
cumulativeRotation.Value += 360;
|
||||
else if (cumulativeRotation.Value > 180)
|
||||
cumulativeRotation.Value -= 360;
|
||||
|
||||
HandleRotate?.Invoke(instantaneousAngle);
|
||||
}
|
||||
|
||||
protected override void OnDragEnd(DragEndEvent e)
|
||||
{
|
||||
base.OnDragEnd(e);
|
||||
cumulativeRotation.Value = null;
|
||||
}
|
||||
|
||||
private float convertDragEventToAngleOfRotation(DragEvent e)
|
||||
{
|
||||
// Adjust coordinate system to the center of SelectionBox
|
||||
float startAngle = MathF.Atan2(e.LastMousePosition.Y - selectionBox.DrawHeight / 2, e.LastMousePosition.X - selectionBox.DrawWidth / 2);
|
||||
float endAngle = MathF.Atan2(e.MousePosition.Y - selectionBox.DrawHeight / 2, e.MousePosition.X - selectionBox.DrawWidth / 2);
|
||||
|
||||
return (endAngle - startAngle) * 180 / MathF.PI;
|
||||
}
|
||||
|
||||
private void updateTooltipText()
|
||||
{
|
||||
TooltipText = cumulativeRotation.Value?.ToLocalisableString("0.0°") ?? default(LocalisableString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,28 @@
|
||||
// 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.Input.Events;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Screens.Edit.Compose.Components
|
||||
{
|
||||
public class SelectionBoxScaleHandle : SelectionBoxDragHandle
|
||||
{
|
||||
public Action<Vector2, Anchor> HandleScale { get; set; }
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
Size = new Vector2(10);
|
||||
}
|
||||
|
||||
protected override void OnDrag(DragEvent e)
|
||||
{
|
||||
HandleScale?.Invoke(e.Delta, Anchor);
|
||||
base.OnDrag(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user