From 35b1d0ae508f049da5f9ed212c5058678622fd4b Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Thu, 27 Oct 2016 17:58:33 +0800 Subject: [PATCH] Seperated DragBar class. --- osu.Game/Overlays/DragBar.cs | 69 ++++++++++++++++++++++++++++++++++++ osu.Game/osu.Game.csproj | 1 + 2 files changed, 70 insertions(+) create mode 100644 osu.Game/Overlays/DragBar.cs diff --git a/osu.Game/Overlays/DragBar.cs b/osu.Game/Overlays/DragBar.cs new file mode 100644 index 0000000000..ee54d21d74 --- /dev/null +++ b/osu.Game/Overlays/DragBar.cs @@ -0,0 +1,69 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//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 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; + } + } +} diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 28297fcca1..12436d8673 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -63,6 +63,7 @@ +