2021-07-22 14:48:07 +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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2021-07-22 14:48:07 +08:00
|
|
|
using System;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
|
|
|
{
|
|
|
|
public class TimelineDragBox : DragBox
|
|
|
|
{
|
2022-10-05 21:04:43 +08:00
|
|
|
public double MinTime { get; private set; }
|
2022-10-05 19:43:02 +08:00
|
|
|
|
2022-10-05 21:04:43 +08:00
|
|
|
public double MaxTime { get; private set; }
|
2022-10-05 19:43:02 +08:00
|
|
|
|
|
|
|
private double? startTime;
|
|
|
|
|
2021-07-22 14:48:07 +08:00
|
|
|
[Resolved]
|
|
|
|
private Timeline timeline { get; set; }
|
|
|
|
|
|
|
|
protected override Drawable CreateBox() => new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
Alpha = 0.3f
|
|
|
|
};
|
|
|
|
|
2022-10-05 19:23:59 +08:00
|
|
|
public override void HandleDrag(MouseButtonEvent e)
|
2021-07-22 14:48:07 +08:00
|
|
|
{
|
2022-10-05 19:43:02 +08:00
|
|
|
startTime ??= timeline.TimeAtPosition(e.MouseDownPosition.X);
|
2022-10-05 21:04:43 +08:00
|
|
|
double endTime = timeline.TimeAtPosition(e.MousePosition.X);
|
|
|
|
|
|
|
|
MinTime = Math.Min(startTime.Value, endTime);
|
|
|
|
MaxTime = Math.Max(startTime.Value, endTime);
|
2021-07-22 14:48:07 +08:00
|
|
|
|
2022-10-05 19:43:02 +08:00
|
|
|
Box.X = timeline.PositionAtTime(MinTime);
|
|
|
|
Box.Width = timeline.PositionAtTime(MaxTime) - Box.X;
|
2021-07-22 14:48:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void Hide()
|
|
|
|
{
|
|
|
|
base.Hide();
|
2022-10-05 19:43:02 +08:00
|
|
|
startTime = null;
|
2021-07-22 14:48:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|