From 61546a053c62937e6bb8a6dfd88b7efc738ad5cd Mon Sep 17 00:00:00 2001 From: andy840119 Date: Wed, 4 May 2022 23:51:18 +0800 Subject: [PATCH 1/3] Change the interface name because we should calculate new draw size, not the new screen space. --- ...ableToDrawQuad.cs => IApplicableToDrawRectangle.cs} | 4 ++-- osu.Framework.Font/Graphics/Shaders/OutlineShader.cs | 9 +++------ osu.Framework.Font/Graphics/Shaders/ShadowShader.cs | 10 +++------- osu.Framework.Font/Graphics/Shaders/StepShader.cs | 8 ++++---- 4 files changed, 12 insertions(+), 19 deletions(-) rename osu.Framework.Font/Graphics/Shaders/{IApplicableToDrawQuad.cs => IApplicableToDrawRectangle.cs} (67%) diff --git a/osu.Framework.Font/Graphics/Shaders/IApplicableToDrawQuad.cs b/osu.Framework.Font/Graphics/Shaders/IApplicableToDrawRectangle.cs similarity index 67% rename from osu.Framework.Font/Graphics/Shaders/IApplicableToDrawQuad.cs rename to osu.Framework.Font/Graphics/Shaders/IApplicableToDrawRectangle.cs index bdcde53..e100c72 100644 --- a/osu.Framework.Font/Graphics/Shaders/IApplicableToDrawQuad.cs +++ b/osu.Framework.Font/Graphics/Shaders/IApplicableToDrawRectangle.cs @@ -5,8 +5,8 @@ namespace osu.Framework.Graphics.Shaders { - public interface IApplicableToDrawQuad + public interface IApplicableToDrawRectangle { - Quad ComputeScreenSpaceDrawQuad(Quad originDrawQuad); + RectangleF ComputeDrawRectangle(RectangleF originDrawRectangle); } } diff --git a/osu.Framework.Font/Graphics/Shaders/OutlineShader.cs b/osu.Framework.Font/Graphics/Shaders/OutlineShader.cs index b733c30..7919a70 100644 --- a/osu.Framework.Font/Graphics/Shaders/OutlineShader.cs +++ b/osu.Framework.Font/Graphics/Shaders/OutlineShader.cs @@ -8,7 +8,7 @@ namespace osu.Framework.Graphics.Shaders { - public class OutlineShader : InternalShader, IApplicableToCharacterSize, IApplicableToDrawQuad, IHasTextureSize, IHasInflationPercentage + public class OutlineShader : InternalShader, IApplicableToCharacterSize, IApplicableToDrawRectangle, IHasTextureSize, IHasInflationPercentage { public override string ShaderName => "Outline"; @@ -33,10 +33,7 @@ public override void ApplyValue() public RectangleF ComputeCharacterDrawRectangle(RectangleF originalCharacterDrawRectangle) => originalCharacterDrawRectangle.Inflate(Math.Max(Radius, 0)); - public Quad ComputeScreenSpaceDrawQuad(Quad originDrawQuad) - { - var rectangle = ComputeCharacterDrawRectangle(originDrawQuad.AABBFloat); - return Quad.FromRectangle(rectangle); - } + public RectangleF ComputeDrawRectangle(RectangleF originDrawRectangle) + => ComputeCharacterDrawRectangle(originDrawRectangle); } } diff --git a/osu.Framework.Font/Graphics/Shaders/ShadowShader.cs b/osu.Framework.Font/Graphics/Shaders/ShadowShader.cs index 5c4e270..f2c082e 100644 --- a/osu.Framework.Font/Graphics/Shaders/ShadowShader.cs +++ b/osu.Framework.Font/Graphics/Shaders/ShadowShader.cs @@ -8,7 +8,7 @@ namespace osu.Framework.Graphics.Shaders { - public class ShadowShader : InternalShader, IApplicableToDrawQuad, IHasTextureSize, IHasInflationPercentage + public class ShadowShader : InternalShader, IApplicableToDrawRectangle, IHasTextureSize, IHasInflationPercentage { public override string ShaderName => "Shadow"; @@ -25,17 +25,13 @@ public override void ApplyValue() GetUniform(@"g_Offset").UpdateValue(ref shadowOffset); } - public Quad ComputeScreenSpaceDrawQuad(Quad originDrawQuad) - { - var rectangle = originDrawQuad.AABBFloat.Inflate(new MarginPadding + public RectangleF ComputeDrawRectangle(RectangleF originDrawRectangle) + => originDrawRectangle.Inflate(new MarginPadding { Left = Math.Max(-ShadowOffset.X, 0), Right = Math.Max(ShadowOffset.X, 0), Top = Math.Max(-ShadowOffset.Y, 0), Bottom = Math.Max(ShadowOffset.Y, 0), }); - - return Quad.FromRectangle(rectangle); - } } } diff --git a/osu.Framework.Font/Graphics/Shaders/StepShader.cs b/osu.Framework.Font/Graphics/Shaders/StepShader.cs index ab25279..c7816a8 100644 --- a/osu.Framework.Font/Graphics/Shaders/StepShader.cs +++ b/osu.Framework.Font/Graphics/Shaders/StepShader.cs @@ -8,7 +8,7 @@ namespace osu.Framework.Graphics.Shaders { - public class StepShader : IStepShader, IApplicableToCharacterSize, IApplicableToDrawQuad + public class StepShader : IStepShader, IApplicableToCharacterSize, IApplicableToDrawRectangle { public string Name { get; set; } @@ -50,8 +50,8 @@ public RectangleF ComputeCharacterDrawRectangle(RectangleF originalCharacterDraw StepShaders.OfType() .Aggregate(originalCharacterDrawRectangle, (rectangle, shader) => shader.ComputeCharacterDrawRectangle(rectangle)); - public Quad ComputeScreenSpaceDrawQuad(Quad originDrawQuad) => - StepShaders.OfType() - .Aggregate(originDrawQuad, (quad, shader) => shader.ComputeScreenSpaceDrawQuad(quad)); + public RectangleF ComputeDrawRectangle(RectangleF originDrawRectangle) => + StepShaders.OfType() + .Aggregate(originDrawRectangle, (quad, shader) => shader.ComputeDrawRectangle(quad)); } } From f2d5b00addf196f9f53dfea894b06ef6a2722202 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Wed, 4 May 2022 23:54:39 +0800 Subject: [PATCH 2/3] Fix the compile error in both KaraokeSpriteText and LyricSpriteText. --- .../Graphics/Sprites/KaraokeSpriteText_DrawNode.cs | 13 ++++++------- .../Graphics/Sprites/LyricSpriteText_DrawNode.cs | 9 ++++----- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/osu.Framework.Font/Graphics/Sprites/KaraokeSpriteText_DrawNode.cs b/osu.Framework.Font/Graphics/Sprites/KaraokeSpriteText_DrawNode.cs index ad7b15c..dfdc063 100644 --- a/osu.Framework.Font/Graphics/Sprites/KaraokeSpriteText_DrawNode.cs +++ b/osu.Framework.Font/Graphics/Sprites/KaraokeSpriteText_DrawNode.cs @@ -12,17 +12,16 @@ public partial class KaraokeSpriteText { protected override Quad ComputeScreenSpaceDrawQuad() { - var quad = ToScreenSpace(DrawRectangle); - var lyricSpriteTextDrawRectangle = LeftLyricTextShaders.Concat(RightLyricTextShaders).OfType() - .Select(x => x.ComputeScreenSpaceDrawQuad(quad).AABBFloat) - .Aggregate(quad.AABBFloat, RectangleF.Union); + var lyricSpriteTextDrawRectangle = LeftLyricTextShaders.Concat(RightLyricTextShaders).OfType() + .Select(x => x.ComputeDrawRectangle(DrawRectangle)) + .Aggregate(DrawRectangle, RectangleF.Union); // after union the size of left side and right side of the internal sprite text draw size, need to calculate the extra size in the karaoke sprite text itself. - var drawRectangle = Shaders.OfType() - .Select(x => x.ComputeScreenSpaceDrawQuad(quad).AABBFloat) + var drawRectangle = Shaders.OfType() + .Select(x => x.ComputeDrawRectangle(lyricSpriteTextDrawRectangle)) .Aggregate(lyricSpriteTextDrawRectangle, RectangleF.Union); - return Quad.FromRectangle(drawRectangle); + return ToScreenSpace(drawRectangle); } protected override DrawNode CreateDrawNode() diff --git a/osu.Framework.Font/Graphics/Sprites/LyricSpriteText_DrawNode.cs b/osu.Framework.Font/Graphics/Sprites/LyricSpriteText_DrawNode.cs index eaa881a..65656f6 100644 --- a/osu.Framework.Font/Graphics/Sprites/LyricSpriteText_DrawNode.cs +++ b/osu.Framework.Font/Graphics/Sprites/LyricSpriteText_DrawNode.cs @@ -17,12 +17,11 @@ public partial class LyricSpriteText protected override Quad ComputeScreenSpaceDrawQuad() { // make draw size become bigger (for not masking the shader). - var quad = ToScreenSpace(DrawRectangle); - var drawRectangle = Shaders.OfType() - .Select(x => x.ComputeScreenSpaceDrawQuad(quad).AABBFloat) - .Aggregate(quad.AABBFloat, RectangleF.Union); + var drawRectangle = Shaders.OfType() + .Select(x => x.ComputeDrawRectangle(DrawRectangle)) + .Aggregate(DrawRectangle, RectangleF.Union); - return Quad.FromRectangle(drawRectangle); + return ToScreenSpace(drawRectangle); } protected override DrawNode CreateDrawNode() From 2eb6e9f34bcb3f499a361f92fd6aeb5873f93aa2 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Wed, 4 May 2022 23:56:09 +0800 Subject: [PATCH 3/3] Fix compile error in the test case. --- osu.Framework.Font.Tests/Shaders/OutlineShaderTest.cs | 3 +-- osu.Framework.Font.Tests/Shaders/ShadowShaderTest.cs | 3 +-- osu.Framework.Font.Tests/Shaders/StepShaderTest.cs | 9 +++------ 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/osu.Framework.Font.Tests/Shaders/OutlineShaderTest.cs b/osu.Framework.Font.Tests/Shaders/OutlineShaderTest.cs index e967c0b..54008d4 100644 --- a/osu.Framework.Font.Tests/Shaders/OutlineShaderTest.cs +++ b/osu.Framework.Font.Tests/Shaders/OutlineShaderTest.cs @@ -37,8 +37,7 @@ public void TestComputeScreenSpaceDrawQuad(int radius, float expectedX, float ex Radius = radius }; - var quad = shader.ComputeScreenSpaceDrawQuad(new Quad(5, 5, 10, 10)); - var rectangle = quad.AABBFloat; + var rectangle = shader.ComputeDrawRectangle(new RectangleF(5, 5, 10, 10)); Assert.AreEqual(expectedX, rectangle.X); Assert.AreEqual(expectedY, rectangle.Y); Assert.AreEqual(expectedWidth, rectangle.Width); diff --git a/osu.Framework.Font.Tests/Shaders/ShadowShaderTest.cs b/osu.Framework.Font.Tests/Shaders/ShadowShaderTest.cs index f83ab2d..7706cda 100644 --- a/osu.Framework.Font.Tests/Shaders/ShadowShaderTest.cs +++ b/osu.Framework.Font.Tests/Shaders/ShadowShaderTest.cs @@ -24,8 +24,7 @@ public void TestComputeScreenSpaceDrawQuad(float offsetX, float offsetY, float e ShadowOffset = new Vector2(offsetX, offsetY) }; - var quad = shader.ComputeScreenSpaceDrawQuad(new Quad(5, 5, 10, 10)); - var rectangle = quad.AABBFloat; + var rectangle = shader.ComputeDrawRectangle(new RectangleF(5, 5, 10, 10)); Assert.AreEqual(expectedX, rectangle.X); Assert.AreEqual(expectedY, rectangle.Y); Assert.AreEqual(expectedWidth, rectangle.Width); diff --git a/osu.Framework.Font.Tests/Shaders/StepShaderTest.cs b/osu.Framework.Font.Tests/Shaders/StepShaderTest.cs index 42c594b..daa86a0 100644 --- a/osu.Framework.Font.Tests/Shaders/StepShaderTest.cs +++ b/osu.Framework.Font.Tests/Shaders/StepShaderTest.cs @@ -61,8 +61,7 @@ public void TestComputeScreenSpaceDrawQuad() } }; - var quad = shader.ComputeScreenSpaceDrawQuad(new Quad(5, 5, 10, 10)); - var rectangle = quad.AABBFloat; + var rectangle = shader.ComputeDrawRectangle(new RectangleF(5, 5, 10, 10)); Assert.AreEqual(5 - outline_radius, rectangle.X); Assert.AreEqual(5 - outline_radius, rectangle.Y); Assert.AreEqual(10 + outline_radius * 2 + shadow_offset_x, rectangle.Width); @@ -86,8 +85,7 @@ public void TestEmptyComputeScreenSpaceDrawQuadWithEmptyShader() { var shader = new StepShader(); - var quad = shader.ComputeScreenSpaceDrawQuad(new Quad(5, 5, 10, 10)); - var rectangle = quad.AABBFloat; + var rectangle = shader.ComputeDrawRectangle(new RectangleF(5, 5, 10, 10)); Assert.AreEqual(5, rectangle.X); Assert.AreEqual(5, rectangle.Y); Assert.AreEqual(10, rectangle.Width); @@ -123,8 +121,7 @@ public void TestEmptyComputeScreenSpaceDrawQuadNoneMatchedShader() } }; - var quad = shader.ComputeScreenSpaceDrawQuad(new Quad(5, 5, 10, 10)); - var rectangle = quad.AABBFloat; + var rectangle = shader.ComputeDrawRectangle(new RectangleF(5, 5, 10, 10)); Assert.AreEqual(5, rectangle.X); Assert.AreEqual(5, rectangle.Y); Assert.AreEqual(10, rectangle.Width);