2017-02-07 12:59:30 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
2016-10-27 17:58:33 +08:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2017-04-07 08:57:34 +08:00
|
|
|
|
using osu.Framework.Graphics.Transforms;
|
2016-10-27 17:58:33 +08:00
|
|
|
|
using osu.Framework.Input;
|
2017-04-07 10:02:37 +08:00
|
|
|
|
using OpenTK;
|
2016-10-27 17:58:33 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays
|
|
|
|
|
{
|
|
|
|
|
public class DragBar : Container
|
|
|
|
|
{
|
2017-03-23 16:44:22 +08:00
|
|
|
|
protected readonly Container FillContainer;
|
2016-10-27 17:58:33 +08:00
|
|
|
|
|
|
|
|
|
public Action<float> SeekRequested;
|
2017-04-07 14:20:20 +08:00
|
|
|
|
|
|
|
|
|
public bool IsSeeking { get; private set; }
|
2016-10-27 17:58:33 +08:00
|
|
|
|
|
2017-04-07 10:02:37 +08:00
|
|
|
|
private bool enabled = true;
|
2016-12-01 08:20:24 +08:00
|
|
|
|
public bool IsEnabled
|
|
|
|
|
{
|
|
|
|
|
get { return enabled; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
enabled = value;
|
|
|
|
|
if (!enabled)
|
2017-03-02 21:15:53 +08:00
|
|
|
|
FillContainer.Width = 0;
|
2016-12-01 08:20:24 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-27 17:58:33 +08:00
|
|
|
|
public DragBar()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-03-02 21:15:53 +08:00
|
|
|
|
FillContainer = new Container
|
2016-10-27 17:58:33 +08:00
|
|
|
|
{
|
2017-02-10 04:28:40 +08:00
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
2016-10-27 17:58:33 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-02-10 04:28:40 +08:00
|
|
|
|
Width = 0,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-04-07 14:20:39 +08:00
|
|
|
|
new Box
|
2017-02-10 04:28:40 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-27 17:58:33 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdatePosition(float position)
|
|
|
|
|
{
|
2017-04-07 14:20:20 +08:00
|
|
|
|
if (IsSeeking || !IsEnabled) return;
|
2016-10-27 17:58:33 +08:00
|
|
|
|
|
2017-04-07 08:57:34 +08:00
|
|
|
|
updatePosition(position);
|
2016-10-27 17:58:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void seek(InputState state)
|
|
|
|
|
{
|
2016-12-01 08:20:24 +08:00
|
|
|
|
if (!IsEnabled) return;
|
2016-10-27 17:58:33 +08:00
|
|
|
|
float seekLocation = state.Mouse.Position.X / DrawWidth;
|
|
|
|
|
SeekRequested?.Invoke(seekLocation);
|
2017-04-07 08:57:34 +08:00
|
|
|
|
updatePosition(seekLocation);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updatePosition(float position)
|
|
|
|
|
{
|
2017-04-07 10:02:37 +08:00
|
|
|
|
position = MathHelper.Clamp(position, 0, 1);
|
2017-04-07 14:20:39 +08:00
|
|
|
|
FillContainer.TransformTo(FillContainer.Width, position, 200, EasingTypes.OutQuint, new TransformSeek());
|
2016-10-27 17:58:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
seek(state);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnDrag(InputState state)
|
|
|
|
|
{
|
|
|
|
|
seek(state);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-07 14:20:20 +08:00
|
|
|
|
protected override bool OnDragStart(InputState state) => IsSeeking = true;
|
2016-10-27 17:58:33 +08:00
|
|
|
|
|
|
|
|
|
protected override bool OnDragEnd(InputState state)
|
|
|
|
|
{
|
2017-04-07 14:20:20 +08:00
|
|
|
|
IsSeeking = false;
|
2016-10-27 17:58:33 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2017-04-07 08:57:34 +08:00
|
|
|
|
|
2017-04-07 14:20:20 +08:00
|
|
|
|
private class TransformSeek : TransformFloat
|
2017-04-07 08:57:34 +08:00
|
|
|
|
{
|
|
|
|
|
public override void Apply(Drawable d)
|
|
|
|
|
{
|
|
|
|
|
base.Apply(d);
|
|
|
|
|
d.Width = CurrentValue;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-27 17:58:33 +08:00
|
|
|
|
}
|
|
|
|
|
}
|