From c416c27de771e2670cf5cadeb269bc3c5cd4815b Mon Sep 17 00:00:00 2001 From: andy840119 Date: Wed, 20 Apr 2022 21:45:50 +0800 Subject: [PATCH 1/4] Should let developer decide remove complete transforms or not. --- osu.Framework.Font/Graphics/Sprites/KaraokeSpriteText.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/osu.Framework.Font/Graphics/Sprites/KaraokeSpriteText.cs b/osu.Framework.Font/Graphics/Sprites/KaraokeSpriteText.cs index 858ec14..eb5647e 100644 --- a/osu.Framework.Font/Graphics/Sprites/KaraokeSpriteText.cs +++ b/osu.Framework.Font/Graphics/Sprites/KaraokeSpriteText.cs @@ -470,7 +470,5 @@ protected override bool OnInvalidate(Invalidation invalidation, InvalidationSour return true; } - - public override bool RemoveCompletedTransforms => false; } } From 474b6c296109fa2e3e0a0274bf95b28291e3758d Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sat, 23 Apr 2022 12:55:42 +0800 Subject: [PATCH 2/4] front -> back --- osu.Framework.Font/Graphics/Sprites/KaraokeSpriteText.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Framework.Font/Graphics/Sprites/KaraokeSpriteText.cs b/osu.Framework.Font/Graphics/Sprites/KaraokeSpriteText.cs index eb5647e..408d770 100644 --- a/osu.Framework.Font/Graphics/Sprites/KaraokeSpriteText.cs +++ b/osu.Framework.Font/Graphics/Sprites/KaraokeSpriteText.cs @@ -1,4 +1,4 @@ -// Copyright (c) karaoke.dev . Licensed under the MIT Licence. +// Copyright (c) karaoke.dev . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; @@ -445,7 +445,7 @@ protected override bool OnInvalidate(Invalidation invalidation, InvalidationSour // should use absolute time to process time-tags. using (frontLyricTextContainer.BeginAbsoluteSequence(currentTime)) - using (frontLyricTextContainer.BeginAbsoluteSequence(currentTime)) + using (backLyricTextContainer.BeginAbsoluteSequence(currentTime)) { // get transform sequence and set initial delay time. var frontTransformSequence = frontLyricTextContainer.Delay(relativeTime - currentTime).Then(); From 1cb79e49bf76004bac2f880bc7392f4407d8b60d Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sat, 23 Apr 2022 12:57:55 +0800 Subject: [PATCH 3/4] Make reset transform into individual function. For better management and testing. --- .../Graphics/Sprites/KaraokeSpriteText.cs | 88 ++++++++++--------- 1 file changed, 45 insertions(+), 43 deletions(-) diff --git a/osu.Framework.Font/Graphics/Sprites/KaraokeSpriteText.cs b/osu.Framework.Font/Graphics/Sprites/KaraokeSpriteText.cs index 408d770..0c14f6f 100644 --- a/osu.Framework.Font/Graphics/Sprites/KaraokeSpriteText.cs +++ b/osu.Framework.Font/Graphics/Sprites/KaraokeSpriteText.cs @@ -421,54 +421,56 @@ protected override bool OnInvalidate(Invalidation invalidation, InvalidationSour if (!invalidation.HasFlag(Invalidation.Presence) || !hasTimeTag || !hasText) return result; - Schedule(() => + Schedule(RefreshStateTransforms); + + return true; + } + + public virtual void RefreshStateTransforms() + { + // set initial width. + // we should get width from child object because draw width haven't updated. + var width = frontLyricText.Width; + frontLyricTextContainer.Width = 0; + backLyricTextContainer.Width = width; + + // reset masking transform. + frontLyricTextContainer.ClearTransforms(); + backLyricTextContainer.ClearTransforms(); + + // filter valid time-tag with order. + var characters = frontLyricText.Characters; + var validTimeTag = TimeTags + .Where(x => x.Key.Index >= 0 && x.Key.Index < Text.Length) + .OrderBy(x => x.Value).ToArray(); + + // get first time-tag relative start time. + var currentTime = Time.Current; + var relativeTime = validTimeTag.FirstOrDefault().Value; + + // should use absolute time to process time-tags. + using (frontLyricTextContainer.BeginAbsoluteSequence(currentTime)) + using (backLyricTextContainer.BeginAbsoluteSequence(currentTime)) { - // set initial width. - // we should get width from child object because draw width haven't updated. - var width = frontLyricText.Width; - frontLyricTextContainer.Width = 0; - backLyricTextContainer.Width = width; - - // reset masking transform. - frontLyricTextContainer.ClearTransforms(); - backLyricTextContainer.ClearTransforms(); - - // filter valid time-tag with order. - var characters = frontLyricText.Characters; - var validTimeTag = TimeTags - .Where(x => x.Key.Index >= 0 && x.Key.Index < Text.Length) - .OrderBy(x => x.Value).ToArray(); - - // get first time-tag relative start time. - var currentTime = Time.Current; - var relativeTime = validTimeTag.FirstOrDefault().Value; - - // should use absolute time to process time-tags. - using (frontLyricTextContainer.BeginAbsoluteSequence(currentTime)) - using (backLyricTextContainer.BeginAbsoluteSequence(currentTime)) - { - // get transform sequence and set initial delay time. - var frontTransformSequence = frontLyricTextContainer.Delay(relativeTime - currentTime).Then(); - var backTransformSequence = backLyricTextContainer.Delay(relativeTime - currentTime).Then(); + // get transform sequence and set initial delay time. + var frontTransformSequence = frontLyricTextContainer.Delay(relativeTime - currentTime).Then(); + var backTransformSequence = backLyricTextContainer.Delay(relativeTime - currentTime).Then(); - foreach (var (textIndex, time) in validTimeTag) - { - // calculate position and duration relative to precious time-tag time. - var characterRectangle = characters[textIndex.Index].DrawRectangle; - var position = textIndex.State == TextIndex.IndexState.Start ? characterRectangle.Left : characterRectangle.Right; - var duration = Math.Max(time - relativeTime, 0); + foreach (var (textIndex, time) in validTimeTag) + { + // calculate position and duration relative to precious time-tag time. + var characterRectangle = characters[textIndex.Index].DrawRectangle; + var position = textIndex.State == TextIndex.IndexState.Start ? characterRectangle.Left : characterRectangle.Right; + var duration = Math.Max(time - relativeTime, 0); - // apply the position with delay time. - frontTransformSequence.ResizeWidthTo(position, duration).Then(); - backTransformSequence.ResizeWidthTo(DrawWidth - position, duration).Then(); + // apply the position with delay time. + frontTransformSequence.ResizeWidthTo(position, duration).Then(); + backTransformSequence.ResizeWidthTo(DrawWidth - position, duration).Then(); - // save current time-tag time for letting next time-tag able to calculate duration. - relativeTime = time; - } + // save current time-tag time for letting next time-tag able to calculate duration. + relativeTime = time; } - }); - - return true; + } } } } From 92e673cd9f1d2ca0a887a9bd5fa995b4fb768081 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sat, 23 Apr 2022 17:24:38 +0800 Subject: [PATCH 4/4] Fix the transform issue. --- .../Graphics/Sprites/KaraokeSpriteText.cs | 34 ++++++++----------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/osu.Framework.Font/Graphics/Sprites/KaraokeSpriteText.cs b/osu.Framework.Font/Graphics/Sprites/KaraokeSpriteText.cs index 0c14f6f..f396107 100644 --- a/osu.Framework.Font/Graphics/Sprites/KaraokeSpriteText.cs +++ b/osu.Framework.Font/Graphics/Sprites/KaraokeSpriteText.cs @@ -448,28 +448,24 @@ public virtual void RefreshStateTransforms() var currentTime = Time.Current; var relativeTime = validTimeTag.FirstOrDefault().Value; - // should use absolute time to process time-tags. - using (frontLyricTextContainer.BeginAbsoluteSequence(currentTime)) - using (backLyricTextContainer.BeginAbsoluteSequence(currentTime)) - { - // get transform sequence and set initial delay time. - var frontTransformSequence = frontLyricTextContainer.Delay(relativeTime - currentTime).Then(); - var backTransformSequence = backLyricTextContainer.Delay(relativeTime - currentTime).Then(); + // get transform sequence and set initial delay time. + var delay = relativeTime - currentTime; + var frontTransformSequence = frontLyricTextContainer.Delay(delay).ResizeWidthTo(0).Then(); + var backTransformSequence = backLyricTextContainer.Delay(delay).ResizeWidthTo(width).Then(); - foreach (var (textIndex, time) in validTimeTag) - { - // calculate position and duration relative to precious time-tag time. - var characterRectangle = characters[textIndex.Index].DrawRectangle; - var position = textIndex.State == TextIndex.IndexState.Start ? characterRectangle.Left : characterRectangle.Right; - var duration = Math.Max(time - relativeTime, 0); + foreach ((var textIndex, double time) in validTimeTag) + { + // calculate position and duration relative to precious time-tag time. + var characterRectangle = characters[textIndex.Index].DrawRectangle; + var position = textIndex.State == TextIndex.IndexState.Start ? characterRectangle.Left : characterRectangle.Right; + var duration = Math.Max(time - relativeTime, 0); - // apply the position with delay time. - frontTransformSequence.ResizeWidthTo(position, duration).Then(); - backTransformSequence.ResizeWidthTo(DrawWidth - position, duration).Then(); + // apply the position with delay time. + frontTransformSequence.ResizeWidthTo(position, duration).Then(); + backTransformSequence.ResizeWidthTo(width - position, duration).Then(); - // save current time-tag time for letting next time-tag able to calculate duration. - relativeTime = time; - } + // save current time-tag time for letting next time-tag able to calculate duration. + relativeTime = time; } } }