// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using osu.Framework.Input.Events; using osu.Game.Rulesets.UI.Scrolling; namespace osu.Game.Screens.Edit.Compose.Components { /// /// A that scrolls along with the scrolling playfield. /// public class ScrollingDragBox : DragBox { public double MinTime { get; private set; } public double MaxTime { get; private set; } private double? startTime; private readonly ScrollingPlayfield playfield; public ScrollingDragBox(ScrollingPlayfield playfield) { this.playfield = playfield; } public override void HandleDrag(MouseButtonEvent e) { base.HandleDrag(e); startTime ??= playfield.TimeAtScreenSpacePosition(e.ScreenSpaceMouseDownPosition); double endTime = playfield.TimeAtScreenSpacePosition(e.ScreenSpaceMousePosition); MinTime = Math.Min(startTime.Value, endTime); MaxTime = Math.Max(startTime.Value, endTime); var startPos = ToLocalSpace(playfield.ScreenSpacePositionAtTime(startTime.Value)); var endPos = ToLocalSpace(playfield.ScreenSpacePositionAtTime(endTime)); switch (playfield.ScrollingInfo.Direction.Value) { case ScrollingDirection.Up: case ScrollingDirection.Down: Box.Y = Math.Min(startPos.Y, endPos.Y); Box.Height = Math.Max(startPos.Y, endPos.Y) - Box.Y; break; case ScrollingDirection.Left: case ScrollingDirection.Right: Box.X = Math.Min(startPos.X, endPos.X); Box.Width = Math.Max(startPos.X, endPos.X) - Box.X; break; } } public override void Hide() { base.Hide(); startTime = null; } } }