mirror of
https://github.com/ppy/osu.git
synced 2025-02-21 20:53:04 +08:00
Seperated DragBar class.
This commit is contained in:
parent
9c2d3990ce
commit
35b1d0ae50
69
osu.Game/Overlays/DragBar.cs
Normal file
69
osu.Game/Overlays/DragBar.cs
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
|
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
public DragBar()
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.X;
|
||||||
|
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
fill = new Box()
|
||||||
|
{
|
||||||
|
Origin = Anchor.CentreLeft,
|
||||||
|
Anchor = Anchor.CentreLeft,
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Width = 0
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdatePosition(float position)
|
||||||
|
{
|
||||||
|
if (isDragging) return;
|
||||||
|
|
||||||
|
fill.Width = position;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void seek(InputState state)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -63,6 +63,7 @@
|
|||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Overlays\DragBar.cs" />
|
||||||
<Compile Include="Overlays\MusicController.cs" />
|
<Compile Include="Overlays\MusicController.cs" />
|
||||||
<Compile Include="Beatmaps\Beatmap.cs" />
|
<Compile Include="Beatmaps\Beatmap.cs" />
|
||||||
<Compile Include="Beatmaps\Drawable\BeatmapSetHeader.cs" />
|
<Compile Include="Beatmaps\Drawable\BeatmapSetHeader.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user