From dd5cc592501115d2584ae032cf97a0b6dd939315 Mon Sep 17 00:00:00 2001 From: TocoToucan Date: Fri, 23 Mar 2018 22:53:06 +0300 Subject: [PATCH 01/16] Introduce 'Capture menu cursor' setting --- osu.Game/Configuration/OsuConfigManager.cs | 4 +++- osu.Game/Graphics/ScreenshotManager.cs | 3 +++ .../Overlays/Settings/Sections/Graphics/DetailSettings.cs | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/osu.Game/Configuration/OsuConfigManager.cs b/osu.Game/Configuration/OsuConfigManager.cs index 70260b349e..d55cd6bf2c 100644 --- a/osu.Game/Configuration/OsuConfigManager.cs +++ b/osu.Game/Configuration/OsuConfigManager.cs @@ -84,6 +84,7 @@ namespace osu.Game.Configuration Set(OsuSetting.Version, string.Empty); Set(OsuSetting.ScreenshotFormat, ScreenshotFormat.Jpg); + Set(OsuSetting.ScreenshotCaptureMenuCursor, false); } public OsuConfigManager(Storage storage) : base(storage) @@ -128,6 +129,7 @@ namespace osu.Game.Configuration ShowConvertedBeatmaps, SpeedChangeVisualisation, Skin, - ScreenshotFormat + ScreenshotFormat, + ScreenshotCaptureMenuCursor } } diff --git a/osu.Game/Graphics/ScreenshotManager.cs b/osu.Game/Graphics/ScreenshotManager.cs index b0cd997837..68ac6e9df4 100644 --- a/osu.Game/Graphics/ScreenshotManager.cs +++ b/osu.Game/Graphics/ScreenshotManager.cs @@ -22,6 +22,8 @@ namespace osu.Game.Graphics public class ScreenshotManager : Container, IKeyBindingHandler, IHandleGlobalInput { private Bindable screenshotFormat; + private Bindable captureMenuCursor; + private GameHost host; private Storage storage; private NotificationOverlay notificationOverlay; @@ -36,6 +38,7 @@ namespace osu.Game.Graphics this.notificationOverlay = notificationOverlay; screenshotFormat = config.GetBindable(OsuSetting.ScreenshotFormat); + captureMenuCursor = config.GetBindable(OsuSetting.ScreenshotCaptureMenuCursor); shutter = audio.Sample.Get("UI/shutter"); } diff --git a/osu.Game/Overlays/Settings/Sections/Graphics/DetailSettings.cs b/osu.Game/Overlays/Settings/Sections/Graphics/DetailSettings.cs index fa57a85454..e124d4cf7e 100644 --- a/osu.Game/Overlays/Settings/Sections/Graphics/DetailSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Graphics/DetailSettings.cs @@ -30,6 +30,11 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics { LabelText = "Screenshot format", Bindable = config.GetBindable(OsuSetting.ScreenshotFormat) + }, + new SettingsCheckbox + { + LabelText = "Capture menu cursor", + Bindable = config.GetBindable(OsuSetting.ScreenshotCaptureMenuCursor) } }; } From e91d24f31a9f1059b98650a2a0ccdce5e11fe476 Mon Sep 17 00:00:00 2001 From: TocoToucan Date: Sat, 24 Mar 2018 12:53:01 +0300 Subject: [PATCH 02/16] Use ScreenshotCaptureMenuCursor in ScreenshotManager --- osu.Game/Graphics/ScreenshotManager.cs | 23 ++++++++++++++++++++++- osu.Game/OsuGameBase.cs | 2 +- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/osu.Game/Graphics/ScreenshotManager.cs b/osu.Game/Graphics/ScreenshotManager.cs index 68ac6e9df4..7d50a298ec 100644 --- a/osu.Game/Graphics/ScreenshotManager.cs +++ b/osu.Game/Graphics/ScreenshotManager.cs @@ -4,15 +4,19 @@ using System; using System.Drawing.Imaging; using System.IO; +using System.Threading; +using System.Threading.Tasks; using osu.Framework.Allocation; using osu.Framework.Audio; using osu.Framework.Audio.Sample; using osu.Framework.Configuration; using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Cursor; using osu.Framework.Input; using osu.Framework.Input.Bindings; using osu.Framework.Platform; using osu.Game.Configuration; +using osu.Game.Graphics.Cursor; using osu.Game.Input.Bindings; using osu.Game.Overlays; using osu.Game.Overlays.Notifications; @@ -29,13 +33,15 @@ namespace osu.Game.Graphics private NotificationOverlay notificationOverlay; private SampleChannel shutter; + private CursorContainer menuCursorContainer; [BackgroundDependencyLoader] - private void load(GameHost host, OsuConfigManager config, Storage storage, NotificationOverlay notificationOverlay, AudioManager audio) + private void load(GameHost host, OsuConfigManager config, Storage storage, NotificationOverlay notificationOverlay, AudioManager audio, CursorOverrideContainer cursorOverrideContainer) { this.host = host; this.storage = storage.GetStorageForDirectory(@"screenshots"); this.notificationOverlay = notificationOverlay; + this.menuCursorContainer = cursorOverrideContainer.Cursor; screenshotFormat = config.GetBindable(OsuSetting.ScreenshotFormat); captureMenuCursor = config.GetBindable(OsuSetting.ScreenshotCaptureMenuCursor); @@ -60,6 +66,18 @@ namespace osu.Game.Graphics public async void TakeScreenshotAsync() { + var menuCursorWasHidden = false; + if (!captureMenuCursor.Value && menuCursorContainer.State == Visibility.Visible) + { + menuCursorContainer.ToggleVisibility(); + await Task.Run(() => + { + while (menuCursorContainer.ActiveCursor.Alpha > 0) + Thread.Sleep(1); + }); + menuCursorWasHidden = true; + } + using (var bitmap = await host.TakeScreenshotAsync()) { var fileName = getFileName(); @@ -89,6 +107,9 @@ namespace osu.Game.Graphics } }); } + + if (menuCursorWasHidden) + menuCursorContainer.ToggleVisibility(); } private string getFileName() diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 54a279e977..ac5e300f16 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -214,7 +214,7 @@ namespace osu.Game GlobalActionContainer globalBinding; - CursorOverrideContainer = new CursorOverrideContainer { RelativeSizeAxes = Axes.Both }; + dependencies.Cache(CursorOverrideContainer = new CursorOverrideContainer { RelativeSizeAxes = Axes.Both }); CursorOverrideContainer.Child = globalBinding = new GlobalActionContainer(this) { RelativeSizeAxes = Axes.Both, From 458594d24d19511882960d2105b930cd09801659 Mon Sep 17 00:00:00 2001 From: TocoToucan Date: Tue, 27 Mar 2018 18:03:57 +0300 Subject: [PATCH 03/16] Qualifier 'this.' is redundant --- osu.Game/Graphics/ScreenshotManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Graphics/ScreenshotManager.cs b/osu.Game/Graphics/ScreenshotManager.cs index 7d50a298ec..434a9d0a72 100644 --- a/osu.Game/Graphics/ScreenshotManager.cs +++ b/osu.Game/Graphics/ScreenshotManager.cs @@ -41,7 +41,7 @@ namespace osu.Game.Graphics this.host = host; this.storage = storage.GetStorageForDirectory(@"screenshots"); this.notificationOverlay = notificationOverlay; - this.menuCursorContainer = cursorOverrideContainer.Cursor; + menuCursorContainer = cursorOverrideContainer.Cursor; screenshotFormat = config.GetBindable(OsuSetting.ScreenshotFormat); captureMenuCursor = config.GetBindable(OsuSetting.ScreenshotCaptureMenuCursor); From d7812ab12e37e70abc948fb437dec84d96f784d1 Mon Sep 17 00:00:00 2001 From: TocoToucan Date: Wed, 11 Apr 2018 21:22:52 +0300 Subject: [PATCH 04/16] CursorOverrideContainer.ShowMenuCursor --- .../Graphics/Cursor/CursorOverrideContainer.cs | 9 +++++++++ osu.Game/Graphics/ScreenshotManager.cs | 16 ++++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/osu.Game/Graphics/Cursor/CursorOverrideContainer.cs b/osu.Game/Graphics/Cursor/CursorOverrideContainer.cs index 0fae4579fa..73fa065919 100644 --- a/osu.Game/Graphics/Cursor/CursorOverrideContainer.cs +++ b/osu.Game/Graphics/Cursor/CursorOverrideContainer.cs @@ -21,6 +21,7 @@ namespace osu.Game.Graphics.Cursor /// Whether any cursors can be displayed. /// public bool CanShowCursor = true; + public bool ShowMenuCursor = true; public CursorContainer Cursor { get; } public bool ProvidingUserCursor => true; @@ -53,6 +54,14 @@ namespace osu.Game.Graphics.Cursor return; } + if (currentTarget?.Cursor is MenuCursor) + { + if (ShowMenuCursor && currentTarget?.Cursor.State == Visibility.Hidden) + currentTarget?.Cursor?.Show(); + else if (!ShowMenuCursor && currentTarget?.Cursor.State == Visibility.Visible) + currentTarget?.Cursor?.Hide(); + } + var newTarget = inputManager.HoveredDrawables.OfType().FirstOrDefault(t => t.ProvidingUserCursor) ?? this; if (currentTarget == newTarget) diff --git a/osu.Game/Graphics/ScreenshotManager.cs b/osu.Game/Graphics/ScreenshotManager.cs index 434a9d0a72..e918ff016e 100644 --- a/osu.Game/Graphics/ScreenshotManager.cs +++ b/osu.Game/Graphics/ScreenshotManager.cs @@ -11,7 +11,6 @@ using osu.Framework.Audio; using osu.Framework.Audio.Sample; using osu.Framework.Configuration; using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Cursor; using osu.Framework.Input; using osu.Framework.Input.Bindings; using osu.Framework.Platform; @@ -33,7 +32,7 @@ namespace osu.Game.Graphics private NotificationOverlay notificationOverlay; private SampleChannel shutter; - private CursorContainer menuCursorContainer; + private CursorOverrideContainer cursorOverrideContainer; [BackgroundDependencyLoader] private void load(GameHost host, OsuConfigManager config, Storage storage, NotificationOverlay notificationOverlay, AudioManager audio, CursorOverrideContainer cursorOverrideContainer) @@ -41,7 +40,7 @@ namespace osu.Game.Graphics this.host = host; this.storage = storage.GetStorageForDirectory(@"screenshots"); this.notificationOverlay = notificationOverlay; - menuCursorContainer = cursorOverrideContainer.Cursor; + this.cursorOverrideContainer = cursorOverrideContainer; screenshotFormat = config.GetBindable(OsuSetting.ScreenshotFormat); captureMenuCursor = config.GetBindable(OsuSetting.ScreenshotCaptureMenuCursor); @@ -66,16 +65,14 @@ namespace osu.Game.Graphics public async void TakeScreenshotAsync() { - var menuCursorWasHidden = false; - if (!captureMenuCursor.Value && menuCursorContainer.State == Visibility.Visible) + if (!captureMenuCursor.Value) { - menuCursorContainer.ToggleVisibility(); + cursorOverrideContainer.ShowMenuCursor = false; await Task.Run(() => { - while (menuCursorContainer.ActiveCursor.Alpha > 0) + while (cursorOverrideContainer.Cursor.ActiveCursor.Alpha > 0) Thread.Sleep(1); }); - menuCursorWasHidden = true; } using (var bitmap = await host.TakeScreenshotAsync()) @@ -108,8 +105,7 @@ namespace osu.Game.Graphics }); } - if (menuCursorWasHidden) - menuCursorContainer.ToggleVisibility(); + cursorOverrideContainer.ShowMenuCursor = true; } private string getFileName() From ebe36f061292b658cc6eb87dc1e5720fe53f2948 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 13 Apr 2018 17:27:10 +0900 Subject: [PATCH 05/16] Instantly hide cursor for required frames while taking screenshot --- .../Cursor/CursorOverrideContainer.cs | 20 ++++++------ osu.Game/Graphics/Cursor/MenuCursor.cs | 3 ++ osu.Game/Graphics/ScreenshotManager.cs | 32 +++++++++++++++---- 3 files changed, 37 insertions(+), 18 deletions(-) diff --git a/osu.Game/Graphics/Cursor/CursorOverrideContainer.cs b/osu.Game/Graphics/Cursor/CursorOverrideContainer.cs index 73fa065919..58d566c34b 100644 --- a/osu.Game/Graphics/Cursor/CursorOverrideContainer.cs +++ b/osu.Game/Graphics/Cursor/CursorOverrideContainer.cs @@ -21,16 +21,22 @@ namespace osu.Game.Graphics.Cursor /// Whether any cursors can be displayed. /// public bool CanShowCursor = true; - public bool ShowMenuCursor = true; - public CursorContainer Cursor { get; } + public bool ShowMenuCursor + { + get => cursor.ShowCursor; + set => cursor.ShowCursor = value; + } + + private readonly MenuCursor cursor; + public CursorContainer Cursor => cursor; public bool ProvidingUserCursor => true; public CursorOverrideContainer() { AddRangeInternal(new Drawable[] { - Cursor = new MenuCursor { State = Visibility.Hidden }, + cursor = new MenuCursor { State = Visibility.Hidden }, content = new Container { RelativeSizeAxes = Axes.Both } }); } @@ -54,14 +60,6 @@ namespace osu.Game.Graphics.Cursor return; } - if (currentTarget?.Cursor is MenuCursor) - { - if (ShowMenuCursor && currentTarget?.Cursor.State == Visibility.Hidden) - currentTarget?.Cursor?.Show(); - else if (!ShowMenuCursor && currentTarget?.Cursor.State == Visibility.Visible) - currentTarget?.Cursor?.Hide(); - } - var newTarget = inputManager.HoveredDrawables.OfType().FirstOrDefault(t => t.ProvidingUserCursor) ?? this; if (currentTarget == newTarget) diff --git a/osu.Game/Graphics/Cursor/MenuCursor.cs b/osu.Game/Graphics/Cursor/MenuCursor.cs index bdee7d289d..4edac3e050 100644 --- a/osu.Game/Graphics/Cursor/MenuCursor.cs +++ b/osu.Game/Graphics/Cursor/MenuCursor.cs @@ -18,6 +18,9 @@ namespace osu.Game.Graphics.Cursor { public class MenuCursor : CursorContainer { + public bool ShowCursor = true; + public override bool IsPresent => ShowCursor && base.IsPresent; + protected override Drawable CreateCursor() => new Cursor(); private Bindable cursorRotate; diff --git a/osu.Game/Graphics/ScreenshotManager.cs b/osu.Game/Graphics/ScreenshotManager.cs index e918ff016e..0d77af8f81 100644 --- a/osu.Game/Graphics/ScreenshotManager.cs +++ b/osu.Game/Graphics/ScreenshotManager.cs @@ -14,6 +14,7 @@ using osu.Framework.Graphics.Containers; using osu.Framework.Input; using osu.Framework.Input.Bindings; using osu.Framework.Platform; +using osu.Framework.Threading; using osu.Game.Configuration; using osu.Game.Graphics.Cursor; using osu.Game.Input.Bindings; @@ -63,20 +64,31 @@ namespace osu.Game.Graphics public bool OnReleased(GlobalAction action) => false; - public async void TakeScreenshotAsync() + private volatile int screenShotTasks; + + public async Task TakeScreenshotAsync() => Task.Run(async () => { + Interlocked.Increment(ref screenShotTasks); + if (!captureMenuCursor.Value) { cursorOverrideContainer.ShowMenuCursor = false; - await Task.Run(() => - { - while (cursorOverrideContainer.Cursor.ActiveCursor.Alpha > 0) - Thread.Sleep(1); - }); + + // We need to wait for at most 3 draw nodes to be drawn, following which we can be assured at least one DrawNode has been generated/drawn with the set value + const int frames_to_wait = 3; + + int framesWaited = 0; + ScheduledDelegate waitDelegate = host.DrawThread.Scheduler.AddDelayed(() => framesWaited++, 0, true); + while (framesWaited < frames_to_wait) + Thread.Sleep(10); + + waitDelegate.Cancel(); } using (var bitmap = await host.TakeScreenshotAsync()) { + Interlocked.Decrement(ref screenShotTasks); + var fileName = getFileName(); if (fileName == null) return; @@ -104,8 +116,14 @@ namespace osu.Game.Graphics } }); } + }); - cursorOverrideContainer.ShowMenuCursor = true; + protected override void Update() + { + base.Update(); + + if (Interlocked.CompareExchange(ref screenShotTasks, 0, 0) == 0) + cursorOverrideContainer.ShowMenuCursor = true; } private string getFileName() From 826a8552e598dc55cc59d11982fdcda470011f70 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 13 Apr 2018 17:30:02 +0900 Subject: [PATCH 06/16] Reword options item to include "screenshot" --- osu.Game/Overlays/Settings/Sections/Graphics/DetailSettings.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Overlays/Settings/Sections/Graphics/DetailSettings.cs b/osu.Game/Overlays/Settings/Sections/Graphics/DetailSettings.cs index e124d4cf7e..3060cfdea9 100644 --- a/osu.Game/Overlays/Settings/Sections/Graphics/DetailSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Graphics/DetailSettings.cs @@ -33,7 +33,7 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics }, new SettingsCheckbox { - LabelText = "Capture menu cursor", + LabelText = "Show menu cursor in screenshots", Bindable = config.GetBindable(OsuSetting.ScreenshotCaptureMenuCursor) } }; From 2e5bbe707499549c225b7a5f55f463fb535835ae Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 13 Apr 2018 17:36:38 +0900 Subject: [PATCH 07/16] Don't expose CursorOverrideContainer via DI + internalise access --- .../Graphics/Cursor/CursorOverrideContainer.cs | 16 +++++----------- osu.Game/Graphics/ScreenshotManager.cs | 14 +++++++++----- osu.Game/OsuGame.cs | 2 +- osu.Game/OsuGameBase.cs | 2 +- 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/osu.Game/Graphics/Cursor/CursorOverrideContainer.cs b/osu.Game/Graphics/Cursor/CursorOverrideContainer.cs index 58d566c34b..810847349a 100644 --- a/osu.Game/Graphics/Cursor/CursorOverrideContainer.cs +++ b/osu.Game/Graphics/Cursor/CursorOverrideContainer.cs @@ -20,23 +20,17 @@ namespace osu.Game.Graphics.Cursor /// /// Whether any cursors can be displayed. /// - public bool CanShowCursor = true; - - public bool ShowMenuCursor - { - get => cursor.ShowCursor; - set => cursor.ShowCursor = value; - } - - private readonly MenuCursor cursor; - public CursorContainer Cursor => cursor; + internal bool CanShowCursor = true; + internal readonly MenuCursor MenuCursor; + + public CursorContainer Cursor => MenuCursor; public bool ProvidingUserCursor => true; public CursorOverrideContainer() { AddRangeInternal(new Drawable[] { - cursor = new MenuCursor { State = Visibility.Hidden }, + MenuCursor = new MenuCursor { State = Visibility.Hidden }, content = new Container { RelativeSizeAxes = Axes.Both } }); } diff --git a/osu.Game/Graphics/ScreenshotManager.cs b/osu.Game/Graphics/ScreenshotManager.cs index 0d77af8f81..1f4b5cee3e 100644 --- a/osu.Game/Graphics/ScreenshotManager.cs +++ b/osu.Game/Graphics/ScreenshotManager.cs @@ -33,15 +33,19 @@ namespace osu.Game.Graphics private NotificationOverlay notificationOverlay; private SampleChannel shutter; - private CursorOverrideContainer cursorOverrideContainer; + private readonly MenuCursor menuCursor; + + public ScreenshotManager(MenuCursor menuCursor) + { + this.menuCursor = menuCursor; + } [BackgroundDependencyLoader] - private void load(GameHost host, OsuConfigManager config, Storage storage, NotificationOverlay notificationOverlay, AudioManager audio, CursorOverrideContainer cursorOverrideContainer) + private void load(GameHost host, OsuConfigManager config, Storage storage, NotificationOverlay notificationOverlay, AudioManager audio) { this.host = host; this.storage = storage.GetStorageForDirectory(@"screenshots"); this.notificationOverlay = notificationOverlay; - this.cursorOverrideContainer = cursorOverrideContainer; screenshotFormat = config.GetBindable(OsuSetting.ScreenshotFormat); captureMenuCursor = config.GetBindable(OsuSetting.ScreenshotCaptureMenuCursor); @@ -72,7 +76,7 @@ namespace osu.Game.Graphics if (!captureMenuCursor.Value) { - cursorOverrideContainer.ShowMenuCursor = false; + menuCursor.ShowCursor = false; // We need to wait for at most 3 draw nodes to be drawn, following which we can be assured at least one DrawNode has been generated/drawn with the set value const int frames_to_wait = 3; @@ -123,7 +127,7 @@ namespace osu.Game.Graphics base.Update(); if (Interlocked.CompareExchange(ref screenShotTasks, 0, 0) == 0) - cursorOverrideContainer.ShowMenuCursor = true; + menuCursor.ShowCursor = true; } private string getFileName() diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 89447b8ed6..b95def9c73 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -239,7 +239,7 @@ namespace osu.Game loadComponentSingleFile(volume = new VolumeOverlay(), overlayContent.Add); loadComponentSingleFile(onscreenDisplay = new OnScreenDisplay(), Add); - loadComponentSingleFile(new ScreenshotManager(), Add); + loadComponentSingleFile(new ScreenshotManager(CursorOverrideContainer.MenuCursor), Add); //overlay elements loadComponentSingleFile(direct = new DirectOverlay { Depth = -1 }, mainContent.Add); diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index ac5e300f16..54a279e977 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -214,7 +214,7 @@ namespace osu.Game GlobalActionContainer globalBinding; - dependencies.Cache(CursorOverrideContainer = new CursorOverrideContainer { RelativeSizeAxes = Axes.Both }); + CursorOverrideContainer = new CursorOverrideContainer { RelativeSizeAxes = Axes.Both }; CursorOverrideContainer.Child = globalBinding = new GlobalActionContainer(this) { RelativeSizeAxes = Axes.Both, From 0235eba9deef9a4e00b7214ff5ea94174b384220 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 13 Apr 2018 17:50:59 +0900 Subject: [PATCH 08/16] Make TakeScreenshotAsync await on the internal task --- osu.Game/Graphics/Cursor/CursorOverrideContainer.cs | 2 +- osu.Game/Graphics/ScreenshotManager.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Graphics/Cursor/CursorOverrideContainer.cs b/osu.Game/Graphics/Cursor/CursorOverrideContainer.cs index 810847349a..30e9b36252 100644 --- a/osu.Game/Graphics/Cursor/CursorOverrideContainer.cs +++ b/osu.Game/Graphics/Cursor/CursorOverrideContainer.cs @@ -22,7 +22,7 @@ namespace osu.Game.Graphics.Cursor /// internal bool CanShowCursor = true; internal readonly MenuCursor MenuCursor; - + public CursorContainer Cursor => MenuCursor; public bool ProvidingUserCursor => true; diff --git a/osu.Game/Graphics/ScreenshotManager.cs b/osu.Game/Graphics/ScreenshotManager.cs index 1f4b5cee3e..d7746647c4 100644 --- a/osu.Game/Graphics/ScreenshotManager.cs +++ b/osu.Game/Graphics/ScreenshotManager.cs @@ -70,7 +70,7 @@ namespace osu.Game.Graphics private volatile int screenShotTasks; - public async Task TakeScreenshotAsync() => Task.Run(async () => + public async Task TakeScreenshotAsync() => await Task.Run(async () => { Interlocked.Increment(ref screenShotTasks); From cd594ce12bcc4960d943d05f2af5a2835ae84f3f Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 13 Apr 2018 20:46:01 +0900 Subject: [PATCH 09/16] BDL cache screenshot manager --- osu.Game/OsuGame.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index b95def9c73..b65e9de663 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -56,6 +56,8 @@ namespace osu.Game private BeatmapSetOverlay beatmapSetOverlay; + private ScreenshotManager screenshotManager; + public virtual Storage GetStorageForStableInstall() => null; private Intro intro @@ -125,6 +127,7 @@ namespace osu.Game } dependencies.CacheAs(this); + dependencies.Cache(screenshotManager = new ScreenshotManager()); // bind config int to database RulesetInfo configRuleset = LocalConfig.GetBindable(OsuSetting.Ruleset); @@ -239,7 +242,8 @@ namespace osu.Game loadComponentSingleFile(volume = new VolumeOverlay(), overlayContent.Add); loadComponentSingleFile(onscreenDisplay = new OnScreenDisplay(), Add); - loadComponentSingleFile(new ScreenshotManager(CursorOverrideContainer.MenuCursor), Add); + + loadComponentSingleFile(screenshotManager, Add); //overlay elements loadComponentSingleFile(direct = new DirectOverlay { Depth = -1 }, mainContent.Add); From 34adb2527c2be60ac304cdf13726b24002e557b4 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 13 Apr 2018 21:12:33 +0900 Subject: [PATCH 10/16] A lot more protection from outsiders --- .../Cursor/CursorOverrideContainer.cs | 5 ++--- osu.Game/Graphics/Cursor/MenuCursor.cs | 22 ++++++++++++------- osu.Game/Graphics/ScreenshotManager.cs | 21 +++++++++--------- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/osu.Game/Graphics/Cursor/CursorOverrideContainer.cs b/osu.Game/Graphics/Cursor/CursorOverrideContainer.cs index 30e9b36252..7dffc6491a 100644 --- a/osu.Game/Graphics/Cursor/CursorOverrideContainer.cs +++ b/osu.Game/Graphics/Cursor/CursorOverrideContainer.cs @@ -21,16 +21,15 @@ namespace osu.Game.Graphics.Cursor /// Whether any cursors can be displayed. /// internal bool CanShowCursor = true; - internal readonly MenuCursor MenuCursor; - public CursorContainer Cursor => MenuCursor; + public CursorContainer Cursor { get; } public bool ProvidingUserCursor => true; public CursorOverrideContainer() { AddRangeInternal(new Drawable[] { - MenuCursor = new MenuCursor { State = Visibility.Hidden }, + Cursor = new MenuCursor { State = Visibility.Hidden }, content = new Container { RelativeSizeAxes = Axes.Both } }); } diff --git a/osu.Game/Graphics/Cursor/MenuCursor.cs b/osu.Game/Graphics/Cursor/MenuCursor.cs index 4edac3e050..b0b15c8572 100644 --- a/osu.Game/Graphics/Cursor/MenuCursor.cs +++ b/osu.Game/Graphics/Cursor/MenuCursor.cs @@ -12,14 +12,15 @@ using osu.Framework.Input; using osu.Game.Configuration; using System; using System.Diagnostics; +using JetBrains.Annotations; using osu.Framework.Graphics.Textures; namespace osu.Game.Graphics.Cursor { public class MenuCursor : CursorContainer { - public bool ShowCursor = true; - public override bool IsPresent => ShowCursor && base.IsPresent; + private readonly IBindable screenshotCursorVisibility = new Bindable(true); + public override bool IsPresent => screenshotCursorVisibility.Value && base.IsPresent; protected override Drawable CreateCursor() => new Cursor(); @@ -28,6 +29,17 @@ namespace osu.Game.Graphics.Cursor private bool startRotation; + private ScreenshotManager screenshotManager; + + [BackgroundDependencyLoader(true)] + private void load([NotNull] OsuConfigManager config, [CanBeNull] ScreenshotManager screenshotManager) + { + cursorRotate = config.GetBindable(OsuSetting.CursorRotation); + + if (screenshotManager != null) + screenshotCursorVisibility.BindTo(screenshotManager.CursorVisibility); + } + protected override bool OnMouseMove(InputState state) { if (cursorRotate && dragging) @@ -107,12 +119,6 @@ namespace osu.Game.Graphics.Cursor ActiveCursor.ScaleTo(0.6f, 250, Easing.In); } - [BackgroundDependencyLoader] - private void load(OsuConfigManager config) - { - cursorRotate = config.GetBindable(OsuSetting.CursorRotation); - } - public class Cursor : Container { private Container cursorContainer; diff --git a/osu.Game/Graphics/ScreenshotManager.cs b/osu.Game/Graphics/ScreenshotManager.cs index d7746647c4..fb111f2786 100644 --- a/osu.Game/Graphics/ScreenshotManager.cs +++ b/osu.Game/Graphics/ScreenshotManager.cs @@ -16,7 +16,6 @@ using osu.Framework.Input.Bindings; using osu.Framework.Platform; using osu.Framework.Threading; using osu.Game.Configuration; -using osu.Game.Graphics.Cursor; using osu.Game.Input.Bindings; using osu.Game.Overlays; using osu.Game.Overlays.Notifications; @@ -25,6 +24,14 @@ namespace osu.Game.Graphics { public class ScreenshotManager : Container, IKeyBindingHandler, IHandleGlobalInput { + private readonly BindableBool cursorVisibility = new BindableBool(true); + + /// + /// Invoked when screenshots are or have finished being taken, to control whether cursors should be visible. + /// If cursors should not be visible, cursors have 3 frames to hide themselves. + /// + public IBindable CursorVisibility => cursorVisibility; + private Bindable screenshotFormat; private Bindable captureMenuCursor; @@ -33,12 +40,6 @@ namespace osu.Game.Graphics private NotificationOverlay notificationOverlay; private SampleChannel shutter; - private readonly MenuCursor menuCursor; - - public ScreenshotManager(MenuCursor menuCursor) - { - this.menuCursor = menuCursor; - } [BackgroundDependencyLoader] private void load(GameHost host, OsuConfigManager config, Storage storage, NotificationOverlay notificationOverlay, AudioManager audio) @@ -76,7 +77,7 @@ namespace osu.Game.Graphics if (!captureMenuCursor.Value) { - menuCursor.ShowCursor = false; + cursorVisibility.Value = false; // We need to wait for at most 3 draw nodes to be drawn, following which we can be assured at least one DrawNode has been generated/drawn with the set value const int frames_to_wait = 3; @@ -126,8 +127,8 @@ namespace osu.Game.Graphics { base.Update(); - if (Interlocked.CompareExchange(ref screenShotTasks, 0, 0) == 0) - menuCursor.ShowCursor = true; + if (cursorVisibility == false && Interlocked.CompareExchange(ref screenShotTasks, 0, 0) == 0) + cursorVisibility.Value = true; } private string getFileName() From cf658335725ee15bacafee32b438336dd3d52123 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 13 Apr 2018 21:15:08 +0900 Subject: [PATCH 11/16] Reword xmldoc --- osu.Game/Graphics/ScreenshotManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Graphics/ScreenshotManager.cs b/osu.Game/Graphics/ScreenshotManager.cs index 0626bc98b7..90580c50df 100644 --- a/osu.Game/Graphics/ScreenshotManager.cs +++ b/osu.Game/Graphics/ScreenshotManager.cs @@ -27,7 +27,7 @@ namespace osu.Game.Graphics private readonly BindableBool cursorVisibility = new BindableBool(true); /// - /// Invoked when screenshots are or have finished being taken, to control whether cursors should be visible. + /// Changed when screenshots are being or have finished being taken, to control whether cursors should be visible. /// If cursors should not be visible, cursors have 3 frames to hide themselves. /// public IBindable CursorVisibility => cursorVisibility; From 3ece54e1c33a709efba79df82369e3be6006987e Mon Sep 17 00:00:00 2001 From: FreezyLemon Date: Sat, 14 Apr 2018 00:08:54 +0200 Subject: [PATCH 12/16] make buttons only accept input when expanded both other states are "inactive"/invisible so should never accept keyboard input --- osu.Game/Screens/Menu/Button.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Screens/Menu/Button.cs b/osu.Game/Screens/Menu/Button.cs index 33e423a558..542ddd2c92 100644 --- a/osu.Game/Screens/Menu/Button.cs +++ b/osu.Game/Screens/Menu/Button.cs @@ -222,7 +222,7 @@ namespace osu.Game.Screens.Menu boxHoverLayer.FadeOut(800, Easing.OutExpo); } - public override bool HandleKeyboardInput => state != ButtonState.Exploded; + public override bool HandleKeyboardInput => state == ButtonState.Expanded; public override bool HandleMouseInput => state != ButtonState.Exploded && box.Scale.X >= 0.8f; protected override void Update() From c095fe1919c3d8e5d7f2262f726896accdf84457 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 16 Apr 2018 00:21:03 +0900 Subject: [PATCH 13/16] Update framework --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index eb6362eaf1..f155804739 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit eb6362eaf1317b0fa27b2c9e559bd9a0f1ce357c +Subproject commit f155804739b8bf6e8e04cbdbadca88618d325a32 From 96ef564f442d4d94742cd00ac7cf33f5ba8e8552 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 16 Apr 2018 00:25:05 +0900 Subject: [PATCH 14/16] Remove unused field --- osu.Game/Graphics/Cursor/MenuCursor.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/osu.Game/Graphics/Cursor/MenuCursor.cs b/osu.Game/Graphics/Cursor/MenuCursor.cs index 575e2979cd..5f57fb76b0 100644 --- a/osu.Game/Graphics/Cursor/MenuCursor.cs +++ b/osu.Game/Graphics/Cursor/MenuCursor.cs @@ -29,8 +29,6 @@ namespace osu.Game.Graphics.Cursor private bool startRotation; - private ScreenshotManager screenshotManager; - [BackgroundDependencyLoader(true)] private void load([NotNull] OsuConfigManager config, [CanBeNull] ScreenshotManager screenshotManager) { From 2eefe722f3d213ac0507ef7269e5f6dbc66db610 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 16 Apr 2018 00:38:32 +0900 Subject: [PATCH 15/16] Move cache to a slightly more familiar place and add comment --- osu.Game/OsuGame.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 4265cc0140..941e49e87e 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -131,7 +131,6 @@ namespace osu.Game } dependencies.CacheAs(this); - dependencies.Cache(screenshotManager = new ScreenshotManager()); // bind config int to database RulesetInfo configRuleset = LocalConfig.GetBindable(OsuSetting.Ruleset); @@ -203,6 +202,9 @@ namespace osu.Game protected override void LoadComplete() { + // this needs to be cached before base.LoadComplete as it is used by CursorOverrideContainer. + dependencies.Cache(screenshotManager = new ScreenshotManager()); + base.LoadComplete(); // The next time this is updated is in UpdateAfterChildren, which occurs too late and results From c3086531e08ea6a60b2878841c34a6b7d14550cb Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 16 Apr 2018 02:54:24 +0900 Subject: [PATCH 16/16] Update framework --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index f155804739..7e8788e601 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit f155804739b8bf6e8e04cbdbadca88618d325a32 +Subproject commit 7e8788e601b62577e51197a29e24f56eeeac0286