@@ -223,13 +223,13 @@ void AnimatedIcon::OnLayoutUpdatedAfterStateChanged(winrt::IInspectable const& s
223223 case winrt::AnimatedIconAnimationQueueBehavior::QueueOne:
224224 if (m_isPlaying)
225225 {
226- // If we already have a queued state , cancel the current animation with the previously queued transition
226+ // If we already have too many queued states , cancel the current animation with the previously queued transition
227227 // then Queue this new transition.
228- if (!m_queuedState. empty () )
228+ if (m_queuedStates. size () >= m_queueLength )
229229 {
230- TransitionAndUpdateStates (m_currentState, m_queuedState );
230+ TransitionAndUpdateStates (m_currentState, m_queuedStates. front () );
231231 }
232- m_queuedState = m_pendingState;
232+ m_queuedStates. push ( m_pendingState) ;
233233 }
234234 else
235235 {
@@ -239,29 +239,38 @@ void AnimatedIcon::OnLayoutUpdatedAfterStateChanged(winrt::IInspectable const& s
239239 case winrt::AnimatedIconAnimationQueueBehavior::SpeedUpQueueOne:
240240 if (m_isPlaying)
241241 {
242- // Cancel the previous animation completed handler, before we cancel that animation by starting a new one.
243- if (m_batch)
244- {
245- m_batchCompletedRevoker.revoke ();
246- }
247-
248- // If we already have a queued state, cancel the current animation with the previously queued transition
242+ // If we already have too many queued states, cancel the current animation with the previously queued transition
249243 // played speed up then Queue this new transition.
250- if (!m_queuedState. empty () )
244+ if (m_queuedStates. size () >= m_queueLength )
251245 {
252- TransitionAndUpdateStates (m_currentState, m_queuedState, m_speedUpMultiplier);
253- m_queuedState = m_pendingState;
246+ // Cancel the previous animation completed handler, before we cancel that animation by starting a new one.
247+ if (m_batch)
248+ {
249+ m_batchCompletedRevoker.revoke ();
250+ }
251+ TransitionAndUpdateStates (m_currentState, m_queuedStates.front (), m_speedUpMultiplier);
252+ m_queuedStates.push (m_pendingState);
254253 }
255254 else
256255 {
257- m_queuedState = m_pendingState;
258-
259- auto const markers = Source ().Markers ();
260- winrt::hstring transitionEndName = StringUtil::FormatString (L" %1!s!%2!s!%3!s!%4!s!" , m_previousState.c_str (), s_transitionInfix.data (), m_currentState.c_str (), s_transitionEndSuffix.data ());
261- auto const hasEndMarker = markers.HasKey (transitionEndName);
262- if (hasEndMarker)
256+ m_queuedStates.push (m_pendingState);
257+ if (!m_isSpeedUp)
263258 {
264- PlaySegment (NAN, static_cast <float >(markers.Lookup (transitionEndName)), m_speedUpMultiplier);
259+ // Cancel the previous animation completed handler, before we cancel that animation by starting a new one.
260+ if (m_batch)
261+ {
262+ m_batchCompletedRevoker.revoke ();
263+ }
264+
265+ m_isSpeedUp = true ;
266+
267+ auto const markers = Source ().Markers ();
268+ winrt::hstring transitionEndName = StringUtil::FormatString (L" %1!s!%2!s!%3!s!%4!s!" , m_previousState.c_str (), s_transitionInfix.data (), m_currentState.c_str (), s_transitionEndSuffix.data ());
269+ auto const hasEndMarker = markers.HasKey (transitionEndName);
270+ if (hasEndMarker)
271+ {
272+ PlaySegment (NAN, static_cast <float >(markers.Lookup (transitionEndName)), m_speedUpMultiplier);
273+ }
265274 }
266275 }
267276 }
@@ -279,7 +288,10 @@ void AnimatedIcon::TransitionAndUpdateStates(const winrt::hstring& fromState, co
279288 TransitionStates (fromState, toState, playbackMultiplier);
280289 m_previousState = fromState;
281290 m_currentState = toState;
282- m_queuedState = L" " ;
291+ if (!m_queuedStates.empty ())
292+ {
293+ m_queuedStates.pop ();
294+ }
283295}
284296
285297void AnimatedIcon::TransitionStates (const winrt::hstring& fromState, const winrt::hstring& toState, float playbackMultiplier)
@@ -606,10 +618,22 @@ void AnimatedIcon::OnAnimationCompleted(winrt::IInspectable const&, winrt::Compo
606618 case winrt::AnimatedIconAnimationQueueBehavior::Cut:
607619 break ;
608620 case winrt::AnimatedIconAnimationQueueBehavior::QueueOne:
621+ if (!m_queuedStates.empty ())
622+ {
623+ TransitionAndUpdateStates (m_currentState, m_queuedStates.front ());
624+ }
625+ break ;
609626 case winrt::AnimatedIconAnimationQueueBehavior::SpeedUpQueueOne:
610- if (!m_queuedState .empty ())
627+ if (!m_queuedStates .empty ())
611628 {
612- TransitionAndUpdateStates (m_currentState, m_queuedState);
629+ if (m_queuedStates.size () == 1 )
630+ {
631+ TransitionAndUpdateStates (m_currentState, m_queuedStates.front ());
632+ }
633+ else
634+ {
635+ TransitionAndUpdateStates (m_currentState, m_queuedStates.front (), m_isSpeedUp ? m_speedUpMultiplier : 1 .0f );
636+ }
613637 }
614638 break ;
615639 }
@@ -632,6 +656,11 @@ void AnimatedIcon::SetSpeedUpMultiplier(float multiplier)
632656 m_speedUpMultiplier = multiplier;
633657}
634658
659+ void AnimatedIcon::SetQueueLength (unsigned int length)
660+ {
661+ m_queueLength = length;
662+ }
663+
635664winrt::hstring AnimatedIcon::GetLastAnimationSegment ()
636665{
637666 return m_lastAnimationSegment;
0 commit comments