mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 16:29:58 +09:00
Remove intermediate Screens namespace
This commit is contained in:
91
osu.Game/Screens/Edit/Compose/Components/DragBox.cs
Normal file
91
osu.Game/Screens/Edit/Compose/Components/DragBox.cs
Normal file
@ -0,0 +1,91 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// 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.Events;
|
||||
using OpenTK.Graphics;
|
||||
|
||||
namespace osu.Game.Screens.Edit.Compose.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// A box that displays the drag selection and provides selection events for users to handle.
|
||||
/// </summary>
|
||||
public class DragBox : CompositeDrawable
|
||||
{
|
||||
private readonly Action<RectangleF> performSelection;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when the drag selection has finished.
|
||||
/// </summary>
|
||||
public event Action DragEnd;
|
||||
|
||||
private Drawable box;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="DragBox"/>.
|
||||
/// </summary>
|
||||
/// <param name="performSelection">A delegate that performs drag selection.</param>
|
||||
public DragBox(Action<RectangleF> performSelection)
|
||||
{
|
||||
this.performSelection = performSelection;
|
||||
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
AlwaysPresent = true;
|
||||
Alpha = 0;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
InternalChild = box = new Container
|
||||
{
|
||||
Masking = true,
|
||||
BorderColour = Color4.White,
|
||||
BorderThickness = SelectionBox.BORDER_RADIUS,
|
||||
Child = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Alpha = 0.1f
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected override bool OnDragStart(DragStartEvent e)
|
||||
{
|
||||
this.FadeIn(250, Easing.OutQuint);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override bool OnDrag(DragEvent e)
|
||||
{
|
||||
var dragPosition = e.ScreenSpaceMousePosition;
|
||||
var dragStartPosition = e.ScreenSpaceMouseDownPosition;
|
||||
|
||||
var dragQuad = new Quad(dragStartPosition.X, dragStartPosition.Y, dragPosition.X - dragStartPosition.X, dragPosition.Y - dragStartPosition.Y);
|
||||
|
||||
// We use AABBFloat instead of RectangleF since it handles negative sizes for us
|
||||
var dragRectangle = dragQuad.AABBFloat;
|
||||
|
||||
var topLeft = ToLocalSpace(dragRectangle.TopLeft);
|
||||
var bottomRight = ToLocalSpace(dragRectangle.BottomRight);
|
||||
|
||||
box.Position = topLeft;
|
||||
box.Size = bottomRight - topLeft;
|
||||
|
||||
performSelection?.Invoke(dragRectangle);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override bool OnDragEnd(DragEndEvent e)
|
||||
{
|
||||
this.FadeOut(250, Easing.OutQuint);
|
||||
DragEnd?.Invoke();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user