Skip to content

Commit 2eba45b

Browse files
Update AnimatedVisuals with new designs (#5167)
* Update Animated Visuals * Add a queue for the queued state and test helper that lets you set the queue size * change default queue length to 2 and default to behavior to Queue
1 parent b71ddf8 commit 2eba45b

28 files changed

+1830
-1889
lines changed

dev/AnimatedIcon/AnimatedIcon.cpp

Lines changed: 53 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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

285297
void 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+
635664
winrt::hstring AnimatedIcon::GetLastAnimationSegment()
636665
{
637666
return m_lastAnimationSegment;

dev/AnimatedIcon/AnimatedIcon.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "AnimatedIcon.g.h"
1010
#include "AnimatedIcon.properties.h"
11+
#include <queue>
1112

1213
class AnimatedIcon :
1314
public ReferenceTracker<AnimatedIcon, DeriveFromPathIconHelper_base, winrt::AnimatedIcon>,
@@ -44,6 +45,7 @@ class AnimatedIcon :
4445
void SetAnimationQueueBehavior(winrt::AnimatedIconAnimationQueueBehavior behavior);
4546
void SetDurationMultiplier(float multiplier);
4647
void SetSpeedUpMultiplier(float multiplier);
48+
void SetQueueLength(unsigned int length);
4749
winrt::hstring GetLastAnimationSegment();
4850
winrt::hstring GetLastAnimationSegmentStart();
4951
winrt::hstring GetLastAnimationSegmentEnd();
@@ -67,7 +69,8 @@ class AnimatedIcon :
6769

6870
winrt::hstring m_currentState{ L"" };
6971
winrt::hstring m_previousState{ L"" };
70-
winrt::hstring m_queuedState{ L"" };
72+
std::queue<winrt::hstring> m_queuedStates{};
73+
unsigned int m_queueLength{ 2 };
7174
winrt::hstring m_pendingState{ L"" };
7275
winrt::hstring m_lastAnimationSegment{ L"" };
7376
winrt::hstring m_lastAnimationSegmentStart{ L"" };
@@ -77,6 +80,7 @@ class AnimatedIcon :
7780
float m_previousSegmentLength{ 1.0f };
7881
float m_durationMultiplier{ 1.0 };
7982
float m_speedUpMultiplier{ 7.0f };
83+
bool m_isSpeedUp{ false };
8084

8185

8286
winrt::Composition::CompositionPropertySet m_progressPropertySet{ nullptr };
@@ -87,5 +91,5 @@ class AnimatedIcon :
8791
winrt::FrameworkElement::LayoutUpdated_revoker m_layoutUpdatedRevoker{};
8892
PropertyChanged_revoker m_foregroundColorPropertyChangedRevoker{};
8993

90-
winrt::AnimatedIconAnimationQueueBehavior m_queueBehavior{ winrt::AnimatedIconAnimationQueueBehavior::SpeedUpQueueOne };
94+
winrt::AnimatedIconAnimationQueueBehavior m_queueBehavior{ winrt::AnimatedIconAnimationQueueBehavior::QueueOne };
9195
};

dev/AnimatedIcon/AnimatedIconTestHooks.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ void AnimatedIconTestHooks::SetSpeedUpMultiplier(const winrt::AnimatedIcon& anim
3939
}
4040
}
4141

42+
void AnimatedIconTestHooks::SetQueueLength(const winrt::AnimatedIcon& animatedIcon, int length)
43+
{
44+
if (animatedIcon)
45+
{
46+
winrt::get_self<AnimatedIcon>(animatedIcon)->SetQueueLength(length);
47+
}
48+
}
49+
4250
winrt::hstring AnimatedIconTestHooks::GetLastAnimationSegment(const winrt::AnimatedIcon& animatedIcon)
4351
{
4452
if (animatedIcon)

dev/AnimatedIcon/AnimatedIconTestHooks.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class AnimatedIconTestHooks :
1818
static void SetAnimationQueueBehavior(const winrt::AnimatedIcon& animatedIcon, winrt::AnimatedIconAnimationQueueBehavior behavior);
1919
static void SetDurationMultiplier(const winrt::AnimatedIcon& animatedIcon, float multiplier);
2020
static void SetSpeedUpMultiplier(const winrt::AnimatedIcon& animatedIcon, float multiplier);
21+
static void SetQueueLength(const winrt::AnimatedIcon& animatedIcon, int length);
2122

2223
static winrt::hstring GetLastAnimationSegment(const winrt::AnimatedIcon& animatedIcon);
2324
static winrt::hstring GetLastAnimationSegmentStart(const winrt::AnimatedIcon& animatedIcon);

dev/AnimatedIcon/AnimatedIconTestHooks.idl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ runtimeclass AnimatedIconTestHooks
1818
static void SetAnimationQueueBehavior(MU_XC_NAMESPACE.AnimatedIcon animatedIcon, AnimatedIconAnimationQueueBehavior easingFunction);
1919
static void SetDurationMultiplier(MU_XC_NAMESPACE.AnimatedIcon animatedIcon, Single multiplier);
2020
static void SetSpeedUpMultiplier(MU_XC_NAMESPACE.AnimatedIcon animatedIcon, Single multiplier);
21+
static void SetQueueLength(MU_XC_NAMESPACE.AnimatedIcon animatedIcon, Int32 length);
2122

2223
static String GetLastAnimationSegment(MU_XC_NAMESPACE.AnimatedIcon animatedIcon);
2324
static String GetLastAnimationSegmentStart(MU_XC_NAMESPACE.AnimatedIcon animatedIcon);

0 commit comments

Comments
 (0)