1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-15 10:22:56 +08:00

Use ScreenshotCaptureMenuCursor in ScreenshotManager

This commit is contained in:
TocoToucan 2018-03-24 12:53:01 +03:00
parent dd5cc59250
commit e91d24f31a
2 changed files with 23 additions and 2 deletions

View File

@ -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<ScreenshotFormat>(OsuSetting.ScreenshotFormat);
captureMenuCursor = config.GetBindable<bool>(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()

View File

@ -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,