mirror of
https://github.com/osukey/osukey.git
synced 2025-08-03 22:56:36 +09:00
Merge branch 'master' of https://github.com/ppy/osu into better-transforms
This commit is contained in:
75
osu.Game/Graphics/Containers/OsuScrollContainer.cs
Normal file
75
osu.Game/Graphics/Containers/OsuScrollContainer.cs
Normal file
@ -0,0 +1,75 @@
|
||||
// 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;
|
||||
using osu.Framework.Input;
|
||||
using OpenTK.Input;
|
||||
|
||||
namespace osu.Game.Graphics.Containers
|
||||
{
|
||||
internal class OsuScrollContainer : ScrollContainer
|
||||
{
|
||||
/// <summary>
|
||||
/// Allows controlling the scroll bar from any position in the container using the right mouse button.
|
||||
/// 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;
|
||||
|
||||
private bool shouldPerformRightMouseScroll(InputState state) => RightMouseScrollbar && state.Mouse.IsPressed(MouseButton.Right);
|
||||
|
||||
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)
|
||||
{
|
||||
if (shouldPerformRightMouseScroll(state))
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (shouldPerformRightMouseScroll(state))
|
||||
{
|
||||
mouseScrollBarDragging = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
return base.OnDragStart(state);
|
||||
}
|
||||
|
||||
protected override bool OnDragEnd(InputState state)
|
||||
{
|
||||
if (mouseScrollBarDragging)
|
||||
{
|
||||
mouseScrollBarDragging = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
return base.OnDragEnd(state);
|
||||
}
|
||||
}
|
||||
}
|
@ -114,7 +114,7 @@ namespace osu.Game.Graphics.Containers
|
||||
|
||||
public SectionsContainer()
|
||||
{
|
||||
Add(ScrollContainer = new ScrollContainer()
|
||||
Add(ScrollContainer = new OsuScrollContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Masking = false,
|
||||
@ -123,6 +123,8 @@ namespace osu.Game.Graphics.Containers
|
||||
originalSectionsMargin = sectionsContainer.Margin;
|
||||
}
|
||||
|
||||
public void ScrollTo(Drawable section) => ScrollContainer.ScrollTo(ScrollContainer.GetChildPosInContent(section) - FixedHeader.BoundingBox.Height);
|
||||
|
||||
private float lastKnownScroll;
|
||||
protected override void UpdateAfterChildren()
|
||||
{
|
||||
|
Reference in New Issue
Block a user