From b3ae6f7cf84f292b796095bd07ed0fb6aae5ec97 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 3 Oct 2021 15:24:58 +0900 Subject: [PATCH 1/4] use base class instead. --- osu.Framework.Font/Graphics/MultiShaderBufferedDrawNode.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Framework.Font/Graphics/MultiShaderBufferedDrawNode.cs b/osu.Framework.Font/Graphics/MultiShaderBufferedDrawNode.cs index b6e8c0a..c03a794 100644 --- a/osu.Framework.Font/Graphics/MultiShaderBufferedDrawNode.cs +++ b/osu.Framework.Font/Graphics/MultiShaderBufferedDrawNode.cs @@ -98,7 +98,7 @@ protected override void DrawContents() else { // should draw origin content if no shader effects. - DrawFrameBuffer(SharedData.CurrentEffectBuffer, DrawRectangle, Color4.White); + base.DrawContents(); } } From d2adc3c6f87f7f491bc80300314d73a8e3843e4c Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 3 Oct 2021 16:13:49 +0900 Subject: [PATCH 2/4] Implement scale rectangle. --- .../Extensions/RectangleFExtensionsTest.cs | 29 ++++++++++ .../Extensions/RectangleFExtensions.cs | 54 +++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 osu.Framework.Font.Tests/Extensions/RectangleFExtensionsTest.cs create mode 100644 osu.Framework.Font/Graphics/Extensions/RectangleFExtensions.cs diff --git a/osu.Framework.Font.Tests/Extensions/RectangleFExtensionsTest.cs b/osu.Framework.Font.Tests/Extensions/RectangleFExtensionsTest.cs new file mode 100644 index 0000000..7b9bb06 --- /dev/null +++ b/osu.Framework.Font.Tests/Extensions/RectangleFExtensionsTest.cs @@ -0,0 +1,29 @@ +// Copyright (c) andy840119 . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using NUnit.Framework; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Extensions; +using osu.Framework.Graphics.Primitives; + +namespace osu.Framework.Font.Tests.Extensions +{ + public class RectangleFExtensionsTest + { + [TestCase(2, Anchor.Centre, 0, 5, 40, 20)] + [TestCase(2, Anchor.TopLeft, 10, 10, 40, 20)] + [TestCase(2, Anchor.TopRight, -10, 10, 40, 20)] + [TestCase(2, Anchor.BottomLeft, 10, 0, 40, 20)] + [TestCase(2, Anchor.BottomRight, -10, 0, 40, 20)] + public void TestScale(float scale, Anchor origin, float x, float y, float width, float height) + { + var rectangle = new RectangleF(10, 10, 20, 10); + var target = rectangle.Scale(scale, origin); + + Assert.AreEqual(target.X, x); + Assert.AreEqual(target.Y, y); + Assert.AreEqual(target.Width, width); + Assert.AreEqual(target.Height, height); + } + } +} diff --git a/osu.Framework.Font/Graphics/Extensions/RectangleFExtensions.cs b/osu.Framework.Font/Graphics/Extensions/RectangleFExtensions.cs new file mode 100644 index 0000000..e9f65c9 --- /dev/null +++ b/osu.Framework.Font/Graphics/Extensions/RectangleFExtensions.cs @@ -0,0 +1,54 @@ +// Copyright (c) andy840119 . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Extensions.EnumExtensions; +using osu.Framework.Graphics.Primitives; +using osuTK; + +namespace osu.Framework.Graphics.Extensions +{ + public static class RectangleFExtensions + { + public static RectangleF Scale(this RectangleF source, float scale, Anchor origin = Anchor.Centre) + => source.Scale(new Vector2(scale), origin); + + public static RectangleF Scale(this RectangleF source, Vector2 scale, Anchor origin = Anchor.Centre) + { + var newWidth = source.Width * scale.X; + var newHeight = source.Height * scale.Y; + + var x = source.X - getXScale(origin) * (newWidth - source.Width); + var y = source.Y - getYScale(origin) * (newHeight - source.Height); + + return new RectangleF(x, y, newWidth, newHeight); + + static float getXScale(Anchor origin) + { + if (origin.HasFlagFast(Anchor.x0)) + return 0; + + if (origin.HasFlagFast(Anchor.x1)) + return 0.5f; + + if (origin.HasFlagFast(Anchor.x2)) + return 1f; + + return 100; + } + + static float getYScale(Anchor origin) + { + if (origin.HasFlagFast(Anchor.y0)) + return 0; + + if (origin.HasFlagFast(Anchor.y1)) + return 0.5f; + + if (origin.HasFlagFast(Anchor.y2)) + return 1f; + + return 100; + } + } + } +} From 102da150d585648bcd88303816e52f61a735f881 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 3 Oct 2021 16:59:35 +0900 Subject: [PATCH 3/4] Make draw size become bigger. --- .../Graphics/Sprites/LyricSpriteText_DrawNode.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/osu.Framework.Font/Graphics/Sprites/LyricSpriteText_DrawNode.cs b/osu.Framework.Font/Graphics/Sprites/LyricSpriteText_DrawNode.cs index 00faf10..8e5b6ef 100644 --- a/osu.Framework.Font/Graphics/Sprites/LyricSpriteText_DrawNode.cs +++ b/osu.Framework.Font/Graphics/Sprites/LyricSpriteText_DrawNode.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using osu.Framework.Graphics.Extensions; using osu.Framework.Graphics.OpenGL.Vertices; using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Shaders; @@ -13,6 +14,13 @@ namespace osu.Framework.Graphics.Sprites { public partial class LyricSpriteText { + protected override Quad ComputeScreenSpaceDrawQuad() + { + // make draw size become bigger (for not masking the shader). + var newRectangle = DrawRectangle.Scale(2); + return ToScreenSpace(newRectangle); + } + // todo: should have a better way to let user able to customize formats? protected override DrawNode CreateDrawNode() => new LyricSpriteTextShaderEffectDrawNode(this, new MultiShaderBufferedDrawNodeSharedData()); From 184fdfa547f2b3369355fee3573496b15bc68afe Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 3 Oct 2021 17:22:58 +0900 Subject: [PATCH 4/4] draw quade size should change on karaoke sprite text also. --- .../Graphics/Sprites/KaraokeSpriteText_DrawNode.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/osu.Framework.Font/Graphics/Sprites/KaraokeSpriteText_DrawNode.cs b/osu.Framework.Font/Graphics/Sprites/KaraokeSpriteText_DrawNode.cs index 34b51c3..059377c 100644 --- a/osu.Framework.Font/Graphics/Sprites/KaraokeSpriteText_DrawNode.cs +++ b/osu.Framework.Font/Graphics/Sprites/KaraokeSpriteText_DrawNode.cs @@ -3,12 +3,21 @@ using System.Collections.Generic; using System.Linq; +using osu.Framework.Graphics.Extensions; +using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Shaders; namespace osu.Framework.Graphics.Sprites { public partial class KaraokeSpriteText { + protected override Quad ComputeScreenSpaceDrawQuad() + { + // make draw size become bigger (for not masking the shader). + var newRectangle = DrawRectangle.Scale(2); + return ToScreenSpace(newRectangle); + } + // todo: should have a better way to let user able to customize formats? protected override DrawNode CreateDrawNode() => new KaraokeSpriteTextShaderEffectDrawNode(this, new MultiShaderBufferedDrawNodeSharedData());