2017-07-14 05:43:33 +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
|
|
|
|
|
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-07-12 17:57:44 +08:00
|
|
|
|
using osu.Framework.Input;
|
|
|
|
|
using OpenTK.Input;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.Containers
|
|
|
|
|
{
|
2017-07-14 06:05:39 +08:00
|
|
|
|
internal class OsuScrollContainer : ScrollContainer
|
2017-07-12 17:57:44 +08:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2017-07-14 17:08:47 +08:00
|
|
|
|
/// Allows controlling the scroll bar from any position in the container using the right mouse button.
|
2017-07-12 17:57:44 +08:00
|
|
|
|
/// Uses the value of <see cref="DistanceDecayOnRightMouseScrollbar"/> to smoothly scroll to the dragged location.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool RightMouseScrollbar = false;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Controls the rate with which the target position is approached when performing a relative drag. Default is 0.02.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public double DistanceDecayOnRightMouseScrollbar = 0.02;
|
|
|
|
|
|
2017-07-14 17:08:47 +08:00
|
|
|
|
private bool shouldPerformRightMouseScroll(InputState state) => RightMouseScrollbar && state.Mouse.IsPressed(MouseButton.Right);
|
2017-07-12 17:57:44 +08:00
|
|
|
|
|
|
|
|
|
private void scrollToRelative(float value) => ScrollTo(Clamp((value - Scrollbar.DrawSize[ScrollDim] / 2) / Scrollbar.Size[ScrollDim]), true, DistanceDecayOnRightMouseScrollbar);
|
|
|
|
|
|
|
|
|
|
private bool mouseScrollBarDragging;
|
|
|
|
|
|
|
|
|
|
protected override bool IsDragging => base.IsDragging || mouseScrollBarDragging;
|
|
|
|
|
|
|
|
|
|
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
|
|
|
|
|
{
|
2017-07-14 17:08:47 +08:00
|
|
|
|
if (shouldPerformRightMouseScroll(state))
|
2017-07-12 17:57:44 +08:00
|
|
|
|
{
|
|
|
|
|
scrollToRelative(state.Mouse.Position[ScrollDim]);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return base.OnMouseDown(state, args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnDrag(InputState state)
|
|
|
|
|
{
|
|
|
|
|
if (mouseScrollBarDragging)
|
|
|
|
|
{
|
|
|
|
|
scrollToRelative(state.Mouse.Position[ScrollDim]);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return base.OnDrag(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnDragStart(InputState state)
|
|
|
|
|
{
|
2017-07-14 17:08:47 +08:00
|
|
|
|
if (shouldPerformRightMouseScroll(state))
|
2017-07-12 17:57:44 +08:00
|
|
|
|
{
|
|
|
|
|
mouseScrollBarDragging = true;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return base.OnDragStart(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnDragEnd(InputState state)
|
|
|
|
|
{
|
|
|
|
|
if (mouseScrollBarDragging)
|
|
|
|
|
{
|
|
|
|
|
mouseScrollBarDragging = false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return base.OnDragEnd(state);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|