Fixed a reverse scrolling issue in CarouselComponent.

This commit is contained in:
Leon Styhre 2022-02-09 00:05:06 +01:00
parent d1cbbad8ee
commit 03f8e020c3
3 changed files with 29 additions and 17 deletions

View file

@ -32,6 +32,7 @@ namespace
SystemView::SystemView() SystemView::SystemView()
: mCamOffset {0.0f} : mCamOffset {0.0f}
, mFadeOpacity {0.0f} , mFadeOpacity {0.0f}
, mPreviousScrollVelocity {0}
, mUpdatedGameCount {false} , mUpdatedGameCount {false}
, mViewNeedsReload {true} , mViewNeedsReload {true}
, mLegacyMode {false} , mLegacyMode {false}
@ -240,6 +241,20 @@ void SystemView::onCursorChanged(const CursorState& /*state*/)
if (fabs(target - posMax - startPos - scrollVelocity) < dist) if (fabs(target - posMax - startPos - scrollVelocity) < dist)
endPos = target - posMax; // Loop around the start (max - 1 -> -1). endPos = target - posMax; // Loop around the start (max - 1 -> -1).
// Make sure transitions do not animate in reverse.
bool changedDirection {false};
if (mPreviousScrollVelocity != 0 && mPreviousScrollVelocity != scrollVelocity)
changedDirection = true;
if (!changedDirection && scrollVelocity > 0 && endPos < startPos)
endPos = endPos + posMax;
if (!changedDirection && scrollVelocity < 0 && endPos > startPos)
endPos = endPos - posMax;
if (scrollVelocity != 0)
mPreviousScrollVelocity = scrollVelocity;
std::string transition_style {Settings::getInstance()->getString("TransitionStyle")}; std::string transition_style {Settings::getInstance()->getString("TransitionStyle")};
Animation* anim; Animation* anim;

View file

@ -90,6 +90,7 @@ private:
float mCamOffset; float mCamOffset;
float mFadeOpacity; float mFadeOpacity;
int mPreviousScrollVelocity;
bool mUpdatedGameCount; bool mUpdatedGameCount;
bool mViewNeedsReload; bool mViewNeedsReload;

View file

@ -435,23 +435,19 @@ void CarouselComponent::onCursorChanged(const CursorState& state)
if (fabs(target - posMax - startPos - mScrollVelocity) < dist) if (fabs(target - posMax - startPos - mScrollVelocity) < dist)
endPos = target - posMax; // Loop around the start (max - 1 -> -1). endPos = target - posMax; // Loop around the start (max - 1 -> -1).
// This logic is only needed when there are two game systems, to prevent ugly jumps back // Make sure there are no reverse jumps between logos.
// an forth when selecting the same direction rapidly several times in a row. bool changedDirection {false};
if (posMax == 2) { if (mPreviousScrollVelocity != 0 && mPreviousScrollVelocity != mScrollVelocity)
if (mPreviousScrollVelocity == 0) changedDirection = true;
mPreviousScrollVelocity = mScrollVelocity;
else if (mScrollVelocity < 0 && startPos < endPos) if (!changedDirection && mScrollVelocity > 0 && endPos < startPos)
mPreviousScrollVelocity = -1; endPos = endPos + posMax;
else if (mScrollVelocity > 0 && startPos > endPos)
mPreviousScrollVelocity = 1; if (!changedDirection && mScrollVelocity < 0 && endPos > startPos)
} endPos = endPos - posMax;
if (mPreviousScrollVelocity != 0 && posMax == 2 && mScrollVelocity == mPreviousScrollVelocity) {
if (fabs(endPos - startPos) < 0.5 || fabs(endPos - startPos) > 1.5) { if (mScrollVelocity != 0)
(mScrollVelocity < 0) ? endPos -= 1 : endPos += 1; mPreviousScrollVelocity = mScrollVelocity;
(mCursor == 0) ? mCursor = 1 : mCursor = 0;
return;
}
}
// No need to animate transition, we're not going anywhere (probably mEntries.size() == 1). // No need to animate transition, we're not going anywhere (probably mEntries.size() == 1).
if (endPos == mCamOffset) if (endPos == mCamOffset)