From 42e7a69db6954a3866af5f3c488f7f1bc4517293 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 16 Jun 2025 19:50:12 +0900 Subject: [PATCH] Fix incorect masking when displayed at small sizes --- .../Graphics/UserInterface/LoadingLayer.cs | 1 - .../Graphics/UserInterface/LoadingSpinner.cs | 103 ++++++++++-------- 2 files changed, 56 insertions(+), 48 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/LoadingLayer.cs b/osu.Game/Graphics/UserInterface/LoadingLayer.cs index 8d7852562a..916b041696 100644 --- a/osu.Game/Graphics/UserInterface/LoadingLayer.cs +++ b/osu.Game/Graphics/UserInterface/LoadingLayer.cs @@ -4,7 +4,6 @@ #nullable disable using System; -using JetBrains.Annotations; using osu.Framework.Graphics; using osu.Framework.Graphics.Shapes; using osu.Framework.Input.Events; diff --git a/osu.Game/Graphics/UserInterface/LoadingSpinner.cs b/osu.Game/Graphics/UserInterface/LoadingSpinner.cs index cb13a730a7..b4bc6fb8c3 100644 --- a/osu.Game/Graphics/UserInterface/LoadingSpinner.cs +++ b/osu.Game/Graphics/UserInterface/LoadingSpinner.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System.Diagnostics; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Colour; @@ -24,12 +25,14 @@ namespace osu.Game.Graphics.UserInterface protected override bool StartHidden => true; - protected Drawable MainContents; - - private readonly Container? roundedContent; + protected Container MainContents; private readonly TrianglesV2 triangles; + private readonly Container? trianglesMasking; + + private readonly bool withBox; + private const float spin_duration = 900; /// @@ -39,6 +42,8 @@ namespace osu.Game.Graphics.UserInterface /// Whether colours should be inverted (black spinner instead of white). public LoadingSpinner(bool withBox = false, bool inverted = false) { + this.withBox = withBox; + Size = new Vector2(60); Anchor = Anchor.Centre; @@ -46,7 +51,7 @@ namespace osu.Game.Graphics.UserInterface if (withBox) { - Child = MainContents = roundedContent = new Container + Child = MainContents = new Container { RelativeSizeAxes = Axes.Both, Masking = true, @@ -86,46 +91,49 @@ namespace osu.Game.Graphics.UserInterface } else { - Child = MainContents = new Container + Children = new[] { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - RelativeSizeAxes = Axes.Both, - Children = new Drawable[] + MainContents = new Container { - new Container + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + RelativeSizeAxes = Axes.Both, + Children = new Drawable[] { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - RelativeSizeAxes = Axes.Both, - Size = new Vector2(0.8f), - Masking = true, - CornerRadius = 20, - Children = new Drawable[] + spinner = new SpriteIcon { - triangles = new TrianglesV2 - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Alpha = 0.4f, - Colour = ColourInfo.GradientVertical( - inverted ? Color4.Black.Opacity(0) : Color4.White.Opacity(0), - inverted ? Color4.Black : Color4.White), - RelativeSizeAxes = Axes.Both, - ScaleAdjust = 0.4f, - SpawnRatio = 4, - }, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Colour = inverted ? Color4.Black : Color4.White, + RelativeSizeAxes = Axes.Both, + Icon = FontAwesome.Solid.CircleNotch } - }, - spinner = new SpriteIcon - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Colour = inverted ? Color4.Black : Color4.White, - RelativeSizeAxes = Axes.Both, - Icon = FontAwesome.Solid.CircleNotch } - } + }, + trianglesMasking = new Container + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + RelativeSizeAxes = Axes.Both, + Size = new Vector2(0.8f), + Masking = true, + CornerRadius = 20, + Children = new Drawable[] + { + triangles = new TrianglesV2 + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Alpha = 0.4f, + Colour = ColourInfo.GradientVertical( + inverted ? Color4.Black.Opacity(0) : Color4.White.Opacity(0), + inverted ? Color4.Black : Color4.White), + RelativeSizeAxes = Axes.Both, + ScaleAdjust = 0.4f, + SpawnRatio = 4, + }, + } + }, }; } } @@ -137,19 +145,20 @@ namespace osu.Game.Graphics.UserInterface rotate(); } - protected override void Update() - { - base.Update(); - - if (roundedContent != null) - roundedContent.CornerRadius = MainContents.DrawWidth / 4; - } - protected override void UpdateAfterChildren() { base.UpdateAfterChildren(); - triangles.Rotation = -MainContents.Rotation; + if (withBox) + { + MainContents.CornerRadius = MainContents.DrawWidth / 4; + triangles.Rotation = -MainContents.Rotation; + } + else + { + Debug.Assert(trianglesMasking != null); + trianglesMasking.CornerRadius = MainContents.DrawWidth / 2; + } } protected override void PopIn()