mirror of
https://github.com/osukey/osukey.git
synced 2025-07-03 01:09:57 +09:00
Update ScrollContainer usages in line with framework changes
This commit is contained in:
@ -1,13 +1,18 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Input.Events;
|
||||
using osuTK;
|
||||
using osuTK.Graphics;
|
||||
using osuTK.Input;
|
||||
|
||||
namespace osu.Game.Graphics.Containers
|
||||
{
|
||||
public class OsuScrollContainer : ScrollContainer
|
||||
public class OsuScrollContainer : ScrollContainer<Drawable>
|
||||
{
|
||||
/// <summary>
|
||||
/// Allows controlling the scroll bar from any position in the container using the right mouse button.
|
||||
@ -28,6 +33,11 @@ namespace osu.Game.Graphics.Containers
|
||||
|
||||
protected override bool IsDragging => base.IsDragging || mouseScrollBarDragging;
|
||||
|
||||
public OsuScrollContainer(Direction scrollDirection = Direction.Vertical)
|
||||
: base(scrollDirection)
|
||||
{
|
||||
}
|
||||
|
||||
protected override bool OnMouseDown(MouseDownEvent e)
|
||||
{
|
||||
if (shouldPerformRightMouseScroll(e))
|
||||
@ -71,5 +81,87 @@ namespace osu.Game.Graphics.Containers
|
||||
|
||||
return base.OnDragEnd(e);
|
||||
}
|
||||
|
||||
protected override ScrollbarContainer CreateScrollbar(Direction direction) => new OsuScrollbar(direction);
|
||||
|
||||
protected class OsuScrollbar : ScrollbarContainer
|
||||
{
|
||||
private const float dim_size = 10;
|
||||
|
||||
private Color4 hoverColour;
|
||||
private Color4 defaultColour;
|
||||
private Color4 highlightColour;
|
||||
|
||||
private readonly Box box;
|
||||
|
||||
public OsuScrollbar(Direction scrollDir)
|
||||
: base(scrollDir)
|
||||
{
|
||||
Blending = BlendingMode.Additive;
|
||||
|
||||
CornerRadius = 5;
|
||||
|
||||
const float margin = 3;
|
||||
|
||||
Margin = new MarginPadding
|
||||
{
|
||||
Left = scrollDir == Direction.Vertical ? margin : 0,
|
||||
Right = scrollDir == Direction.Vertical ? margin : 0,
|
||||
Top = scrollDir == Direction.Horizontal ? margin : 0,
|
||||
Bottom = scrollDir == Direction.Horizontal ? margin : 0,
|
||||
};
|
||||
|
||||
Masking = true;
|
||||
Child = box = new Box { RelativeSizeAxes = Axes.Both };
|
||||
|
||||
ResizeTo(1);
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
Colour = defaultColour = colours.Gray8;
|
||||
hoverColour = colours.GrayF;
|
||||
highlightColour = colours.Green;
|
||||
}
|
||||
|
||||
public override void ResizeTo(float val, int duration = 0, Easing easing = Easing.None)
|
||||
{
|
||||
Vector2 size = new Vector2(dim_size)
|
||||
{
|
||||
[(int)ScrollDirection] = val
|
||||
};
|
||||
this.ResizeTo(size, duration, easing);
|
||||
}
|
||||
|
||||
protected override bool OnHover(HoverEvent e)
|
||||
{
|
||||
this.FadeColour(hoverColour, 100);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void OnHoverLost(HoverLostEvent e)
|
||||
{
|
||||
this.FadeColour(defaultColour, 100);
|
||||
}
|
||||
|
||||
protected override bool OnMouseDown(MouseDownEvent e)
|
||||
{
|
||||
if (!base.OnMouseDown(e)) return false;
|
||||
|
||||
//note that we are changing the colour of the box here as to not interfere with the hover effect.
|
||||
box.FadeColour(highlightColour, 100);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override bool OnMouseUp(MouseUpEvent e)
|
||||
{
|
||||
if (e.Button != MouseButton.Left) return false;
|
||||
|
||||
box.FadeColour(Color4.White, 100);
|
||||
|
||||
return base.OnMouseUp(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user