Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update AnimatedVisuals with new designs #5167

Merged
merged 3 commits into from
Jun 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 53 additions & 24 deletions dev/AnimatedIcon/AnimatedIcon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,13 @@ void AnimatedIcon::OnLayoutUpdatedAfterStateChanged(winrt::IInspectable const& s
case winrt::AnimatedIconAnimationQueueBehavior::QueueOne:
if (m_isPlaying)
{
// If we already have a queued state, cancel the current animation with the previously queued transition
// If we already have too many queued states, cancel the current animation with the previously queued transition
// then Queue this new transition.
if (!m_queuedState.empty())
if (m_queuedStates.size() >= m_queueLength)
{
TransitionAndUpdateStates(m_currentState, m_queuedState);
TransitionAndUpdateStates(m_currentState, m_queuedStates.front());
}
m_queuedState = m_pendingState;
m_queuedStates.push(m_pendingState);
}
else
{
Expand All @@ -239,29 +239,38 @@ void AnimatedIcon::OnLayoutUpdatedAfterStateChanged(winrt::IInspectable const& s
case winrt::AnimatedIconAnimationQueueBehavior::SpeedUpQueueOne:
if (m_isPlaying)
{
// Cancel the previous animation completed handler, before we cancel that animation by starting a new one.
if (m_batch)
{
m_batchCompletedRevoker.revoke();
}

// If we already have a queued state, cancel the current animation with the previously queued transition
// If we already have too many queued states, cancel the current animation with the previously queued transition
// played speed up then Queue this new transition.
if (!m_queuedState.empty())
if (m_queuedStates.size() >= m_queueLength)
{
TransitionAndUpdateStates(m_currentState, m_queuedState, m_speedUpMultiplier);
m_queuedState = m_pendingState;
// Cancel the previous animation completed handler, before we cancel that animation by starting a new one.
if (m_batch)
{
m_batchCompletedRevoker.revoke();
}
TransitionAndUpdateStates(m_currentState, m_queuedStates.front(), m_speedUpMultiplier);
m_queuedStates.push(m_pendingState);
}
else
{
m_queuedState = m_pendingState;

auto const markers = Source().Markers();
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());
auto const hasEndMarker = markers.HasKey(transitionEndName);
if (hasEndMarker)
m_queuedStates.push(m_pendingState);
if (!m_isSpeedUp)
{
PlaySegment(NAN, static_cast<float>(markers.Lookup(transitionEndName)), m_speedUpMultiplier);
// Cancel the previous animation completed handler, before we cancel that animation by starting a new one.
if (m_batch)
{
m_batchCompletedRevoker.revoke();
}

m_isSpeedUp = true;

auto const markers = Source().Markers();
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());
auto const hasEndMarker = markers.HasKey(transitionEndName);
if (hasEndMarker)
{
PlaySegment(NAN, static_cast<float>(markers.Lookup(transitionEndName)), m_speedUpMultiplier);
}
}
}
}
Expand All @@ -279,7 +288,10 @@ void AnimatedIcon::TransitionAndUpdateStates(const winrt::hstring& fromState, co
TransitionStates(fromState, toState, playbackMultiplier);
m_previousState = fromState;
m_currentState = toState;
m_queuedState = L"";
if (!m_queuedStates.empty())
{
m_queuedStates.pop();
}
}

void AnimatedIcon::TransitionStates(const winrt::hstring& fromState, const winrt::hstring& toState, float playbackMultiplier)
Expand Down Expand Up @@ -606,10 +618,22 @@ void AnimatedIcon::OnAnimationCompleted(winrt::IInspectable const&, winrt::Compo
case winrt::AnimatedIconAnimationQueueBehavior::Cut:
break;
case winrt::AnimatedIconAnimationQueueBehavior::QueueOne:
if (!m_queuedStates.empty())
{
TransitionAndUpdateStates(m_currentState, m_queuedStates.front());
}
break;
case winrt::AnimatedIconAnimationQueueBehavior::SpeedUpQueueOne:
if (!m_queuedState.empty())
if (!m_queuedStates.empty())
{
TransitionAndUpdateStates(m_currentState, m_queuedState);
if (m_queuedStates.size() == 1)
{
TransitionAndUpdateStates(m_currentState, m_queuedStates.front());
}
else
{
TransitionAndUpdateStates(m_currentState, m_queuedStates.front(), m_isSpeedUp ? m_speedUpMultiplier : 1.0f);
}
}
break;
}
Expand All @@ -632,6 +656,11 @@ void AnimatedIcon::SetSpeedUpMultiplier(float multiplier)
m_speedUpMultiplier = multiplier;
}

void AnimatedIcon::SetQueueLength(unsigned int length)
{
m_queueLength = length;
}

winrt::hstring AnimatedIcon::GetLastAnimationSegment()
{
return m_lastAnimationSegment;
Expand Down
8 changes: 6 additions & 2 deletions dev/AnimatedIcon/AnimatedIcon.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "AnimatedIcon.g.h"
#include "AnimatedIcon.properties.h"
#include <queue>

class AnimatedIcon :
public ReferenceTracker<AnimatedIcon, DeriveFromPathIconHelper_base, winrt::AnimatedIcon>,
Expand Down Expand Up @@ -44,6 +45,7 @@ class AnimatedIcon :
void SetAnimationQueueBehavior(winrt::AnimatedIconAnimationQueueBehavior behavior);
void SetDurationMultiplier(float multiplier);
void SetSpeedUpMultiplier(float multiplier);
void SetQueueLength(unsigned int length);
winrt::hstring GetLastAnimationSegment();
winrt::hstring GetLastAnimationSegmentStart();
winrt::hstring GetLastAnimationSegmentEnd();
Expand All @@ -67,7 +69,8 @@ class AnimatedIcon :

winrt::hstring m_currentState{ L"" };
winrt::hstring m_previousState{ L"" };
winrt::hstring m_queuedState{ L"" };
std::queue<winrt::hstring> m_queuedStates{};
unsigned int m_queueLength{ 2 };
winrt::hstring m_pendingState{ L"" };
winrt::hstring m_lastAnimationSegment{ L"" };
winrt::hstring m_lastAnimationSegmentStart{ L"" };
Expand All @@ -77,6 +80,7 @@ class AnimatedIcon :
float m_previousSegmentLength{ 1.0f };
float m_durationMultiplier{ 1.0 };
float m_speedUpMultiplier{ 7.0f };
bool m_isSpeedUp{ false };


winrt::Composition::CompositionPropertySet m_progressPropertySet{ nullptr };
Expand All @@ -87,5 +91,5 @@ class AnimatedIcon :
winrt::FrameworkElement::LayoutUpdated_revoker m_layoutUpdatedRevoker{};
PropertyChanged_revoker m_foregroundColorPropertyChangedRevoker{};

winrt::AnimatedIconAnimationQueueBehavior m_queueBehavior{ winrt::AnimatedIconAnimationQueueBehavior::SpeedUpQueueOne };
winrt::AnimatedIconAnimationQueueBehavior m_queueBehavior{ winrt::AnimatedIconAnimationQueueBehavior::QueueOne };
};
8 changes: 8 additions & 0 deletions dev/AnimatedIcon/AnimatedIconTestHooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ void AnimatedIconTestHooks::SetSpeedUpMultiplier(const winrt::AnimatedIcon& anim
}
}

void AnimatedIconTestHooks::SetQueueLength(const winrt::AnimatedIcon& animatedIcon, int length)
{
if (animatedIcon)
{
winrt::get_self<AnimatedIcon>(animatedIcon)->SetQueueLength(length);
}
}

winrt::hstring AnimatedIconTestHooks::GetLastAnimationSegment(const winrt::AnimatedIcon& animatedIcon)
{
if (animatedIcon)
Expand Down
1 change: 1 addition & 0 deletions dev/AnimatedIcon/AnimatedIconTestHooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class AnimatedIconTestHooks :
static void SetAnimationQueueBehavior(const winrt::AnimatedIcon& animatedIcon, winrt::AnimatedIconAnimationQueueBehavior behavior);
static void SetDurationMultiplier(const winrt::AnimatedIcon& animatedIcon, float multiplier);
static void SetSpeedUpMultiplier(const winrt::AnimatedIcon& animatedIcon, float multiplier);
static void SetQueueLength(const winrt::AnimatedIcon& animatedIcon, int length);

static winrt::hstring GetLastAnimationSegment(const winrt::AnimatedIcon& animatedIcon);
static winrt::hstring GetLastAnimationSegmentStart(const winrt::AnimatedIcon& animatedIcon);
Expand Down
1 change: 1 addition & 0 deletions dev/AnimatedIcon/AnimatedIconTestHooks.idl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ runtimeclass AnimatedIconTestHooks
static void SetAnimationQueueBehavior(MU_XC_NAMESPACE.AnimatedIcon animatedIcon, AnimatedIconAnimationQueueBehavior easingFunction);
static void SetDurationMultiplier(MU_XC_NAMESPACE.AnimatedIcon animatedIcon, Single multiplier);
static void SetSpeedUpMultiplier(MU_XC_NAMESPACE.AnimatedIcon animatedIcon, Single multiplier);
static void SetQueueLength(MU_XC_NAMESPACE.AnimatedIcon animatedIcon, Int32 length);

static String GetLastAnimationSegment(MU_XC_NAMESPACE.AnimatedIcon animatedIcon);
static String GetLastAnimationSegmentStart(MU_XC_NAMESPACE.AnimatedIcon animatedIcon);
Expand Down
Loading