From 9d47dd9ff906f985fbd9d53601fb091e793fcc38 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 12 Jul 2017 18:57:44 +0900 Subject: [PATCH 1/5] Add support for right mouse absolute scrolling (when enabled) Will likely need to be bindable when hooked up to settings and actually used. --- .../Graphics/Containers/OsuScrollContainer.cs | 72 +++++++++++++++++++ .../Graphics/Containers/SectionsContainer.cs | 2 +- .../Overlays/Chat/ChannelSelectionOverlay.cs | 2 +- osu.Game/Overlays/Chat/DrawableChannel.cs | 3 +- osu.Game/Overlays/Music/PlaylistList.cs | 3 +- osu.Game/Overlays/NotificationManager.cs | 2 +- .../SearchableList/SearchableListOverlay.cs | 3 +- osu.Game/Screens/Multiplayer/RoomInspector.cs | 3 +- .../Select/Leaderboards/Leaderboard.cs | 3 +- osu.Game/osu.Game.csproj | 1 + 10 files changed, 86 insertions(+), 8 deletions(-) create mode 100644 osu.Game/Graphics/Containers/OsuScrollContainer.cs diff --git a/osu.Game/Graphics/Containers/OsuScrollContainer.cs b/osu.Game/Graphics/Containers/OsuScrollContainer.cs new file mode 100644 index 0000000000..66e21fbf67 --- /dev/null +++ b/osu.Game/Graphics/Containers/OsuScrollContainer.cs @@ -0,0 +1,72 @@ +using osu.Framework.Graphics.Containers; +using osu.Framework.Input; +using OpenTK.Input; + +namespace osu.Game.Graphics.Containers +{ + class OsuScrollContainer : ScrollContainer + { + /// + /// Add the ability to seek to an absolute scroll position when the right mouse button is pressed or dragged. + /// Uses the value of to smoothly scroll to the dragged location. + /// + public bool RightMouseScrollbar = false; + + /// + /// Controls the rate with which the target position is approached when performing a relative drag. Default is 0.02. + /// + public double DistanceDecayOnRightMouseScrollbar = 0.02; + + private bool shouldPerformRelativeDrag(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 (shouldPerformRelativeDrag(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 (shouldPerformRelativeDrag(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); + } + } +} diff --git a/osu.Game/Graphics/Containers/SectionsContainer.cs b/osu.Game/Graphics/Containers/SectionsContainer.cs index 1d792f1b78..37c3804543 100644 --- a/osu.Game/Graphics/Containers/SectionsContainer.cs +++ b/osu.Game/Graphics/Containers/SectionsContainer.cs @@ -114,7 +114,7 @@ namespace osu.Game.Graphics.Containers public SectionsContainer() { - Add(ScrollContainer = new ScrollContainer() + Add(ScrollContainer = new OsuScrollContainer() { RelativeSizeAxes = Axes.Both, Masking = false, diff --git a/osu.Game/Overlays/Chat/ChannelSelectionOverlay.cs b/osu.Game/Overlays/Chat/ChannelSelectionOverlay.cs index 9f61d13813..135f8f43b9 100644 --- a/osu.Game/Overlays/Chat/ChannelSelectionOverlay.cs +++ b/osu.Game/Overlays/Chat/ChannelSelectionOverlay.cs @@ -81,7 +81,7 @@ namespace osu.Game.Overlays.Chat Padding = new MarginPadding { Top = 85, Right = WIDTH_PADDING }, Children = new[] { - new ScrollContainer + new OsuScrollContainer { RelativeSizeAxes = Axes.Both, Children = new[] diff --git a/osu.Game/Overlays/Chat/DrawableChannel.cs b/osu.Game/Overlays/Chat/DrawableChannel.cs index f8b7c7e581..e51f931959 100644 --- a/osu.Game/Overlays/Chat/DrawableChannel.cs +++ b/osu.Game/Overlays/Chat/DrawableChannel.cs @@ -7,6 +7,7 @@ using System.Linq; using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Game.Graphics.Containers; using osu.Game.Online.Chat; namespace osu.Game.Overlays.Chat @@ -25,7 +26,7 @@ namespace osu.Game.Overlays.Chat Children = new Drawable[] { - scroll = new ScrollContainer + scroll = new OsuScrollContainer { RelativeSizeAxes = Axes.Both, Children = new Drawable[] diff --git a/osu.Game/Overlays/Music/PlaylistList.cs b/osu.Game/Overlays/Music/PlaylistList.cs index eeb072fb00..ca46bdea95 100644 --- a/osu.Game/Overlays/Music/PlaylistList.cs +++ b/osu.Game/Overlays/Music/PlaylistList.cs @@ -7,6 +7,7 @@ using System.Linq; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Database; +using osu.Game.Graphics.Containers; namespace osu.Game.Overlays.Music { @@ -49,7 +50,7 @@ namespace osu.Game.Overlays.Music { Children = new Drawable[] { - new ScrollContainer + new OsuScrollContainer { RelativeSizeAxes = Axes.Both, Children = new Drawable[] diff --git a/osu.Game/Overlays/NotificationManager.cs b/osu.Game/Overlays/NotificationManager.cs index 382683cbcc..18cb49f335 100644 --- a/osu.Game/Overlays/NotificationManager.cs +++ b/osu.Game/Overlays/NotificationManager.cs @@ -36,7 +36,7 @@ namespace osu.Game.Overlays Colour = Color4.Black, Alpha = 0.6f, }, - scrollContainer = new ScrollContainer + scrollContainer = new OsuScrollContainer { RelativeSizeAxes = Axes.Both, Margin = new MarginPadding { Top = Toolbar.Toolbar.HEIGHT }, diff --git a/osu.Game/Overlays/SearchableList/SearchableListOverlay.cs b/osu.Game/Overlays/SearchableList/SearchableListOverlay.cs index 25f6b4f60b..c5b8b0cf85 100644 --- a/osu.Game/Overlays/SearchableList/SearchableListOverlay.cs +++ b/osu.Game/Overlays/SearchableList/SearchableListOverlay.cs @@ -7,6 +7,7 @@ using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Framework.Input; using osu.Game.Graphics.Backgrounds; +using osu.Game.Graphics.Containers; namespace osu.Game.Overlays.SearchableList { @@ -60,7 +61,7 @@ namespace osu.Game.Overlays.SearchableList RelativeSizeAxes = Axes.Both, Children = new[] { - new ScrollContainer + new OsuScrollContainer { RelativeSizeAxes = Axes.Both, ScrollbarVisible = false, diff --git a/osu.Game/Screens/Multiplayer/RoomInspector.cs b/osu.Game/Screens/Multiplayer/RoomInspector.cs index 3a822be791..761204dda4 100644 --- a/osu.Game/Screens/Multiplayer/RoomInspector.cs +++ b/osu.Game/Screens/Multiplayer/RoomInspector.cs @@ -17,6 +17,7 @@ using osu.Framework.Localisation; using osu.Game.Beatmaps.Drawables; using osu.Game.Database; using osu.Game.Graphics; +using osu.Game.Graphics.Containers; using osu.Game.Graphics.Sprites; using osu.Game.Online.Multiplayer; using osu.Game.Users; @@ -341,7 +342,7 @@ namespace osu.Game.Screens.Multiplayer }, }, }, - participantsScroll = new ScrollContainer + participantsScroll = new OsuScrollContainer { Anchor = Anchor.BottomLeft, Origin = Anchor.BottomLeft, diff --git a/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs b/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs index e560cfe413..2a8e4ca5fb 100644 --- a/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs +++ b/osu.Game/Screens/Select/Leaderboards/Leaderboard.cs @@ -12,6 +12,7 @@ using System; using osu.Framework.Allocation; using osu.Framework.Threading; using osu.Game.Database; +using osu.Game.Graphics.Containers; using osu.Game.Graphics.UserInterface; using osu.Game.Rulesets.Scoring; using osu.Game.Online.API; @@ -74,7 +75,7 @@ namespace osu.Game.Screens.Select.Leaderboards { Children = new Drawable[] { - scrollContainer = new ScrollContainer + scrollContainer = new OsuScrollContainer { RelativeSizeAxes = Axes.Both, ScrollbarVisible = false, diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 3d84f287f0..691df1d2d1 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -78,6 +78,7 @@ + From a6ac61f735417a9bc877d17c993d373ba88b5ad8 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 14 Jul 2017 06:24:07 +0900 Subject: [PATCH 2/5] Update framework --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index 46a56e0e11..991177da4f 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 46a56e0e11d56c788ff8db089582718a606ed158 +Subproject commit 991177da4fbed2dd8260c215f2d341ebc858b03e From bfa6a9aa4ea498689e913a077ca92a61a8fe7aff Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 14 Jul 2017 06:43:33 +0900 Subject: [PATCH 3/5] Add missing licence header --- osu.Game/Graphics/Containers/OsuScrollContainer.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/osu.Game/Graphics/Containers/OsuScrollContainer.cs b/osu.Game/Graphics/Containers/OsuScrollContainer.cs index 66e21fbf67..cfed92866b 100644 --- a/osu.Game/Graphics/Containers/OsuScrollContainer.cs +++ b/osu.Game/Graphics/Containers/OsuScrollContainer.cs @@ -1,4 +1,7 @@ -using osu.Framework.Graphics.Containers; +// Copyright (c) 2007-2017 ppy Pty Ltd . +// 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; From b1d447bf714f5d87a7896a99ff87756c56221bcd Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 14 Jul 2017 07:05:39 +0900 Subject: [PATCH 4/5] Add missing access modifier --- osu.Game/Graphics/Containers/OsuScrollContainer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Graphics/Containers/OsuScrollContainer.cs b/osu.Game/Graphics/Containers/OsuScrollContainer.cs index cfed92866b..970a0ef0ae 100644 --- a/osu.Game/Graphics/Containers/OsuScrollContainer.cs +++ b/osu.Game/Graphics/Containers/OsuScrollContainer.cs @@ -7,7 +7,7 @@ using OpenTK.Input; namespace osu.Game.Graphics.Containers { - class OsuScrollContainer : ScrollContainer + internal class OsuScrollContainer : ScrollContainer { /// /// Add the ability to seek to an absolute scroll position when the right mouse button is pressed or dragged. From b7612af20cff4ff828011125eb9be7616e12c643 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 14 Jul 2017 18:08:47 +0900 Subject: [PATCH 5/5] Make comment different --- osu.Game/Graphics/Containers/OsuScrollContainer.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/osu.Game/Graphics/Containers/OsuScrollContainer.cs b/osu.Game/Graphics/Containers/OsuScrollContainer.cs index 970a0ef0ae..e395f1b7bd 100644 --- a/osu.Game/Graphics/Containers/OsuScrollContainer.cs +++ b/osu.Game/Graphics/Containers/OsuScrollContainer.cs @@ -10,7 +10,7 @@ namespace osu.Game.Graphics.Containers internal class OsuScrollContainer : ScrollContainer { /// - /// Add the ability to seek to an absolute scroll position when the right mouse button is pressed or dragged. + /// Allows controlling the scroll bar from any position in the container using the right mouse button. /// Uses the value of to smoothly scroll to the dragged location. /// public bool RightMouseScrollbar = false; @@ -20,7 +20,7 @@ namespace osu.Game.Graphics.Containers /// public double DistanceDecayOnRightMouseScrollbar = 0.02; - private bool shouldPerformRelativeDrag(InputState state) => RightMouseScrollbar && state.Mouse.IsPressed(MouseButton.Right); + 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); @@ -30,7 +30,7 @@ namespace osu.Game.Graphics.Containers protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) { - if (shouldPerformRelativeDrag(state)) + if (shouldPerformRightMouseScroll(state)) { scrollToRelative(state.Mouse.Position[ScrollDim]); return true; @@ -52,7 +52,7 @@ namespace osu.Game.Graphics.Containers protected override bool OnDragStart(InputState state) { - if (shouldPerformRelativeDrag(state)) + if (shouldPerformRightMouseScroll(state)) { mouseScrollBarDragging = true; return true;