2018-01-05 19:21:19 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
2017-12-18 20:51:00 +08:00
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Primitives;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osu.Framework.Input;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Edit.Layers.Selection
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Represents a marker visible on the border of a <see cref="HandleContainer"/> which exposes
|
2018-02-12 15:03:59 +08:00
|
|
|
|
/// properties that are used to resize a <see cref="SelectionDragger"/>.
|
2017-12-18 20:51:00 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
public class Handle : CompositeDrawable
|
|
|
|
|
{
|
|
|
|
|
private const float marker_size = 10;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Invoked when this <see cref="Handle"/> requires the current drag rectangle.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Func<RectangleF> GetDragRectangle;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Invoked when this <see cref="Handle"/> wants to update the drag rectangle.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Action<RectangleF> UpdateDragRectangle;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Invoked when this <see cref="Handle"/> has finished updates to the drag rectangle.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Action FinishDrag;
|
|
|
|
|
|
|
|
|
|
private Color4 normalColour;
|
|
|
|
|
private Color4 hoverColour;
|
|
|
|
|
|
|
|
|
|
public Handle()
|
|
|
|
|
{
|
|
|
|
|
Size = new Vector2(marker_size);
|
|
|
|
|
|
|
|
|
|
InternalChild = new CircularContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Masking = true,
|
|
|
|
|
Child = new Box { RelativeSizeAxes = Axes.Both }
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
Colour = normalColour = colours.Yellow;
|
|
|
|
|
hoverColour = colours.YellowDarker;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnDragStart(InputState state) => true;
|
|
|
|
|
|
|
|
|
|
protected override bool OnDrag(InputState state)
|
|
|
|
|
{
|
|
|
|
|
var currentRectangle = GetDragRectangle();
|
|
|
|
|
|
|
|
|
|
float left = currentRectangle.Left;
|
|
|
|
|
float right = currentRectangle.Right;
|
|
|
|
|
float top = currentRectangle.Top;
|
|
|
|
|
float bottom = currentRectangle.Bottom;
|
|
|
|
|
|
|
|
|
|
// Apply modifications to the capture rectangle
|
|
|
|
|
if ((Anchor & Anchor.y0) > 0)
|
|
|
|
|
top += state.Mouse.Delta.Y;
|
|
|
|
|
else if ((Anchor & Anchor.y2) > 0)
|
|
|
|
|
bottom += state.Mouse.Delta.Y;
|
|
|
|
|
|
|
|
|
|
if ((Anchor & Anchor.x0) > 0)
|
|
|
|
|
left += state.Mouse.Delta.X;
|
|
|
|
|
else if ((Anchor & Anchor.x2) > 0)
|
|
|
|
|
right += state.Mouse.Delta.X;
|
|
|
|
|
|
|
|
|
|
UpdateDragRectangle(RectangleF.FromLTRB(left, top, right, bottom));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnDragEnd(InputState state)
|
|
|
|
|
{
|
|
|
|
|
FinishDrag();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnHover(InputState state)
|
|
|
|
|
{
|
|
|
|
|
this.FadeColour(hoverColour, 100);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHoverLost(InputState state)
|
|
|
|
|
{
|
|
|
|
|
this.FadeColour(normalColour, 100);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|