void MImRotationAnimation::remoteWindowChanged(MImRemoteWindow* newRemoteWindow) { remoteWindow = newRemoteWindow; damageMonitor->remoteWindowChanged(newRemoteWindow); // Stop playing animations when underlying window is unmapped. if (!remoteWindow) { qDebug() << __PRETTY_FUNCTION__ << " - remote window gone, cancelling animation."; cancelAnimation(); } }
void ViewController::playViewTransition() { Eigen::Vector3f target(Eigen::Vector3f::Identity()); if(mCurrentView) target = mCurrentView->getPosition(); // no need to animate, we're not going anywhere (probably goToNextGamelist() or goToPrevGamelist() when there's only 1 system) if(target == -mCamera.translation() && !isAnimationPlaying(0)) return; if(Settings::getInstance()->getString("TransitionStyle") == "fade") { // fade // stop whatever's currently playing, leaving mFadeOpacity wherever it is cancelAnimation(0); auto fadeFunc = [this](float t) { mFadeOpacity = lerp<float>(0, 1, t); }; const static int FADE_DURATION = 240; // fade in/out time const static int FADE_WAIT = 320; // time to wait between in/out setAnimation(new LambdaAnimation(fadeFunc, FADE_DURATION), 0, [this, fadeFunc, target] { this->mCamera.translation() = -target; updateHelpPrompts(); setAnimation(new LambdaAnimation(fadeFunc, FADE_DURATION), FADE_WAIT, nullptr, true); }); // fast-forward animation if we're partway faded if(target == -mCamera.translation()) { // not changing screens, so cancel the first half entirely advanceAnimation(0, FADE_DURATION); advanceAnimation(0, FADE_WAIT); advanceAnimation(0, FADE_DURATION - (int)(mFadeOpacity * FADE_DURATION)); }else{ advanceAnimation(0, (int)(mFadeOpacity * FADE_DURATION)); } }else{ // slide setAnimation(new MoveCameraAnimation(mCamera, target)); updateHelpPrompts(); // update help prompts immediately } }
ScrollResult ScrollAnimator::userScroll(ScrollGranularity granularity, const ScrollOffset& delta) { if (!m_scrollableArea->scrollAnimatorEnabled()) return ScrollAnimatorBase::userScroll(granularity, delta); TRACE_EVENT0("blink", "ScrollAnimator::scroll"); if (granularity == ScrollByPrecisePixel) { // Cancel scroll animation because asked to instant scroll. if (hasRunningAnimation()) cancelAnimation(); return ScrollAnimatorBase::userScroll(granularity, delta); } bool needsPostAnimationCleanup = m_runState == RunState::PostAnimationCleanup; if (m_runState == RunState::PostAnimationCleanup) resetAnimationState(); ScrollOffset consumedDelta = computeDeltaToConsume(delta); ScrollOffset targetOffset = desiredTargetOffset(); targetOffset += consumedDelta; if (willAnimateToOffset(targetOffset)) { m_lastGranularity = granularity; // Report unused delta only if there is no animation running. See // comment below regarding scroll latching. // TODO(bokan): Need to standardize how ScrollAnimators report // unusedDelta. This differs from ScrollAnimatorMac currently. return ScrollResult(true, true, 0, 0); } // If the run state when this method was called was PostAnimationCleanup and // we're not starting an animation, stay in PostAnimationCleanup state so // that the main thread scrolling reason can be removed. if (needsPostAnimationCleanup) m_runState = RunState::PostAnimationCleanup; // Report unused delta only if there is no animation and we are not // starting one. This ensures we latch for the duration of the // animation rather than animating multiple scrollers at the same time. return ScrollResult(false, false, delta.width(), delta.height()); }
void SystemView::onCursorChanged(const CursorState& state) { // update help style updateHelpPrompts(); float startPos = mCamOffset; float posMax = (float)mEntries.size(); float target = (float)mCursor; // what's the shortest way to get to our target? // it's one of these... float endPos = target; // directly float dist = abs(endPos - startPos); if(abs(target + posMax - startPos) < dist) endPos = target + posMax; // loop around the end (0 -> max) if(abs(target - posMax - startPos) < dist) endPos = target - posMax; // loop around the start (max - 1 -> -1) // animate mSystemInfo's opacity (fade out, wait, fade back in) cancelAnimation(1); cancelAnimation(2); const float infoStartOpacity = mSystemInfo.getOpacity() / 255.f; Animation* infoFadeOut = new LambdaAnimation( [infoStartOpacity, this] (float t) { mSystemInfo.setOpacity((unsigned char)(lerp<float>(infoStartOpacity, 0.f, t) * 255)); }, (int)(infoStartOpacity * 150)); unsigned int gameCount = getSelected()->getGameCount(); // also change the text after we've fully faded out setAnimation(infoFadeOut, 0, [this, gameCount] { std::stringstream ss; // only display a game count if there are at least 2 games if(gameCount > 1) ss << gameCount << " GAMES AVAILABLE"; mSystemInfo.setText(ss.str()); }, false, 1); // only display a game count if there are at least 2 games if(gameCount > 1) { Animation* infoFadeIn = new LambdaAnimation( [this](float t) { mSystemInfo.setOpacity((unsigned char)(lerp<float>(0.f, 1.f, t) * 255)); }, 300); // wait 600ms to fade in setAnimation(infoFadeIn, 2000, nullptr, false, 2); } // no need to animate transition, we're not going anywhere (probably mEntries.size() == 1) if(endPos == mCamOffset && endPos == mExtrasCamOffset) return; Animation* anim; if(Settings::getInstance()->getString("TransitionStyle") == "fade") { float startExtrasFade = mExtrasFadeOpacity; anim = new LambdaAnimation( [startExtrasFade, startPos, endPos, posMax, this](float t) { t -= 1; float f = lerp<float>(startPos, endPos, t*t*t + 1); if(f < 0) f += posMax; if(f >= posMax) f -= posMax; this->mCamOffset = f; t += 1; if(t < 0.3f) this->mExtrasFadeOpacity = lerp<float>(0.0f, 1.0f, t / 0.3f + startExtrasFade); else if(t < 0.7f) this->mExtrasFadeOpacity = 1.0f; else this->mExtrasFadeOpacity = lerp<float>(1.0f, 0.0f, (t - 0.7f) / 0.3f); if(t > 0.5f) this->mExtrasCamOffset = endPos; }, 500); } else{ // slide anim = new LambdaAnimation( [startPos, endPos, posMax, this](float t) { t -= 1; float f = lerp<float>(startPos, endPos, t*t*t + 1); if(f < 0) f += posMax; if(f >= posMax) f -= posMax; this->mCamOffset = f; this->mExtrasCamOffset = f; }, 500); } setAnimation(anim, 0, nullptr, false, 0); }
void ProgrammaticScrollAnimator::scrollToOffsetWithoutAnimation( const ScrollOffset& offset) { cancelAnimation(); notifyOffsetChanged(offset); }
void ProgrammaticScrollAnimator::scrollToOffsetWithoutAnimation(const FloatPoint& offset) { cancelAnimation(); notifyPositionChanged(offset); }
void SystemView::onCursorChanged(const CursorState& /*state*/) { // update help style updateHelpPrompts(); float startPos = mCamOffset; float posMax = (float)mEntries.size(); float target = (float)mCursor; // what's the shortest way to get to our target? // it's one of these... float endPos = target; // directly float dist = abs(endPos - startPos); if(abs(target + posMax - startPos) < dist) endPos = target + posMax; // loop around the end (0 -> max) if(abs(target - posMax - startPos) < dist) endPos = target - posMax; // loop around the start (max - 1 -> -1) // animate mSystemInfo's opacity (fade out, wait, fade back in) cancelAnimation(1); cancelAnimation(2); std::string transition_style = Settings::getInstance()->getString("TransitionStyle"); bool goFast = transition_style == "instant"; const float infoStartOpacity = mSystemInfo.getOpacity() / 255.f; Animation* infoFadeOut = new LambdaAnimation( [infoStartOpacity, this] (float t) { mSystemInfo.setOpacity((unsigned char)(Math::lerp(infoStartOpacity, 0.f, t) * 255)); }, (int)(infoStartOpacity * (goFast ? 10 : 150))); unsigned int gameCount = getSelected()->getDisplayedGameCount(); // also change the text after we've fully faded out setAnimation(infoFadeOut, 0, [this, gameCount] { std::stringstream ss; if (!getSelected()->isGameSystem()) ss << "CONFIGURATION"; else ss << gameCount << " GAMES AVAILABLE"; mSystemInfo.setText(ss.str()); }, false, 1); Animation* infoFadeIn = new LambdaAnimation( [this](float t) { mSystemInfo.setOpacity((unsigned char)(Math::lerp(0.f, 1.f, t) * 255)); }, goFast ? 10 : 300); // wait 600ms to fade in setAnimation(infoFadeIn, goFast ? 0 : 2000, nullptr, false, 2); // no need to animate transition, we're not going anywhere (probably mEntries.size() == 1) if(endPos == mCamOffset && endPos == mExtrasCamOffset) return; Animation* anim; bool move_carousel = Settings::getInstance()->getBool("MoveCarousel"); if(transition_style == "fade") { float startExtrasFade = mExtrasFadeOpacity; anim = new LambdaAnimation( [this, startExtrasFade, startPos, endPos, posMax, move_carousel](float t) { t -= 1; float f = Math::lerp(startPos, endPos, t*t*t + 1); if(f < 0) f += posMax; if(f >= posMax) f -= posMax; this->mCamOffset = move_carousel ? f : endPos; t += 1; if(t < 0.3f) this->mExtrasFadeOpacity = Math::lerp(0.0f, 1.0f, t / 0.3f + startExtrasFade); else if(t < 0.7f) this->mExtrasFadeOpacity = 1.0f; else this->mExtrasFadeOpacity = Math::lerp(1.0f, 0.0f, (t - 0.7f) / 0.3f); if(t > 0.5f) this->mExtrasCamOffset = endPos; }, 500); } else if (transition_style == "slide") { // slide anim = new LambdaAnimation( [this, startPos, endPos, posMax, move_carousel](float t) { t -= 1; float f = Math::lerp(startPos, endPos, t*t*t + 1); if(f < 0) f += posMax; if(f >= posMax) f -= posMax; this->mCamOffset = move_carousel ? f : endPos; this->mExtrasCamOffset = f; }, 500); } else { // instant anim = new LambdaAnimation( [this, startPos, endPos, posMax, move_carousel ](float t) { t -= 1; float f = Math::lerp(startPos, endPos, t*t*t + 1); if(f < 0) f += posMax; if(f >= posMax) f -= posMax; this->mCamOffset = move_carousel ? f : endPos; this->mExtrasCamOffset = endPos; }, move_carousel ? 500 : 1); } setAnimation(anim, 0, nullptr, false, 0); }