2017-02-07 04:59:30 +00: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 09:58:33 +00:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Framework.Input;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays
|
|
|
|
|
{
|
|
|
|
|
public class DragBar : Container
|
|
|
|
|
{
|
|
|
|
|
private Box fill;
|
|
|
|
|
|
|
|
|
|
public Action<float> SeekRequested;
|
|
|
|
|
private bool isDragging;
|
|
|
|
|
|
2016-12-01 00:20:24 +00:00
|
|
|
|
private bool enabled;
|
|
|
|
|
public bool IsEnabled
|
|
|
|
|
{
|
|
|
|
|
get { return enabled; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
enabled = value;
|
|
|
|
|
if (!enabled)
|
|
|
|
|
fill.Width = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-27 09:58:33 +00:00
|
|
|
|
public DragBar()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-03-07 01:59:19 +00:00
|
|
|
|
fill = new Box
|
2016-10-27 09:58:33 +00:00
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Width = 0
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdatePosition(float position)
|
|
|
|
|
{
|
2016-12-01 00:20:24 +00:00
|
|
|
|
if (isDragging || !IsEnabled) return;
|
2016-10-27 09:58:33 +00:00
|
|
|
|
|
|
|
|
|
fill.Width = position;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void seek(InputState state)
|
|
|
|
|
{
|
2016-12-01 00:20:24 +00:00
|
|
|
|
if (!IsEnabled) return;
|
2016-10-27 09:58:33 +00:00
|
|
|
|
float seekLocation = state.Mouse.Position.X / DrawWidth;
|
|
|
|
|
SeekRequested?.Invoke(seekLocation);
|
|
|
|
|
fill.Width = seekLocation;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
seek(state);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnDrag(InputState state)
|
|
|
|
|
{
|
|
|
|
|
seek(state);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnDragStart(InputState state) => isDragging = true;
|
|
|
|
|
|
|
|
|
|
protected override bool OnDragEnd(InputState state)
|
|
|
|
|
{
|
|
|
|
|
isDragging = false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|