From 4aab77a14d133f57e8001431408979bfd0cf8e6f Mon Sep 17 00:00:00 2001 From: Stephen Thirlwall Date: Fri, 28 Aug 2015 16:57:45 +1000 Subject: [PATCH] Simplify and fix SystemView slide scrolling logic Looping around the ends becomes much simpler if we take mScrollVelocity into account, as it tells us which way we're supposed to be scrolling. The existing method works if you wait for the transition to finish before scrolling to the next item, but if you press the arrows too quickly you'll zoom from end->start rather than wrapping. --- es-app/src/views/SystemView.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/es-app/src/views/SystemView.cpp b/es-app/src/views/SystemView.cpp index 6a16f01d2c..89e3cf016a 100644 --- a/es-app/src/views/SystemView.cpp +++ b/es-app/src/views/SystemView.cpp @@ -144,22 +144,21 @@ void SystemView::onCursorChanged(const CursorState& state) updateHelpPrompts(); float startPos = mCamOffset; + float endPos = (float)mCursor; 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) + if ((mScrollVelocity < 0) && (endPos > startPos)) { + // We are scrolling left, but the destination is to our right. + // => Loop around the start. + endPos -= posMax; + } + else if ((mScrollVelocity > 0) && (endPos < startPos)) { + // We are scrolling right, but the destination is to our left. + // => Loop around the end. + endPos += posMax; + } - // animate mSystemInfo's opacity (fade out, wait, fade back in) cancelAnimation(1);