2018-09-24 23:57:44 +08:00
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
2018-09-25 03:51:40 +08:00
|
|
|
using osu.Framework.Graphics;
|
2018-09-24 23:57:44 +08:00
|
|
|
using osu.Framework.Graphics.Containers;
|
2018-10-12 17:49:47 +08:00
|
|
|
using osu.Framework.Input.Events;
|
2018-09-24 23:57:44 +08:00
|
|
|
using OpenTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Tournament.Screens.Ladder
|
|
|
|
{
|
|
|
|
public class ScrollableContainer : Container
|
|
|
|
{
|
2018-10-12 17:49:47 +08:00
|
|
|
protected override bool OnDragStart(DragStartEvent e) => true;
|
2018-09-24 23:57:44 +08:00
|
|
|
|
2018-10-12 17:49:47 +08:00
|
|
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true;
|
2018-09-24 23:57:44 +08:00
|
|
|
|
2018-09-25 03:51:40 +08:00
|
|
|
private Vector2 target;
|
|
|
|
|
|
|
|
private float scale = 1;
|
|
|
|
|
2018-10-12 17:49:47 +08:00
|
|
|
protected override bool OnDrag(DragEvent e)
|
2018-09-24 23:57:44 +08:00
|
|
|
{
|
2018-10-12 17:49:47 +08:00
|
|
|
this.MoveTo(target += e.Delta, 1000, Easing.OutQuint);
|
2018-09-25 09:46:09 +08:00
|
|
|
return true;
|
2018-09-24 23:57:44 +08:00
|
|
|
}
|
2018-09-25 03:51:40 +08:00
|
|
|
|
2018-10-12 17:49:47 +08:00
|
|
|
protected override bool OnScroll(ScrollEvent e)
|
2018-09-25 03:51:40 +08:00
|
|
|
{
|
2018-10-12 17:49:47 +08:00
|
|
|
var newScale = scale + e.ScrollDelta.Y / 15 * scale;
|
|
|
|
this.MoveTo(target = target - e.MousePosition * (newScale - scale), 1000, Easing.OutQuint);
|
2018-09-25 09:46:09 +08:00
|
|
|
|
|
|
|
this.ScaleTo(scale = newScale, 1000, Easing.OutQuint);
|
2018-09-25 03:51:40 +08:00
|
|
|
|
2018-09-25 09:46:09 +08:00
|
|
|
return true;
|
2018-09-25 03:51:40 +08:00
|
|
|
}
|
2018-09-25 09:21:50 +08:00
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
Invalidate();
|
|
|
|
}
|
2018-09-24 23:57:44 +08:00
|
|
|
}
|
|
|
|
}
|