From 1a746ac98f6f354c79fc38c745bd752ed70f4d6f Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sat, 2 Jan 2021 21:17:23 +0100 Subject: [PATCH] Fixed an issue where the text scrolling speed would change relative to the screen resolution. Also added a fade-in animation when the scrolling resets to the start position. --- RELEASES.md | 1 + .../src/components/ScrollableContainer.cpp | 35 ++++++++++++++----- es-core/src/components/ScrollableContainer.h | 7 ++-- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/RELEASES.md b/RELEASES.md index 2977d401f..ba729b3c9 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -62,6 +62,7 @@ Many bugs have been fixed, and numerous features that were only partially implem * Added support for jumping to the start and end of gamelists and menus using the controller trigger buttons (or equivalent keyboard mappings) * Many additional quality of life improvements and removal of GUI inconsistencies * Replaced the on and off button icons with new graphics +* Made ScrollableContainer (used for the gamelist game descriptions) fade in as the text position is reset * Moved all resources to a subdirectory structure and enabled the CMake install prefix variable to generate the resources search path * Changed theme directory to the install prefix (e.g. /usr/local/share/emulationstation/themes) with themes in the home directory taking precedence * No more attempts to open files directly under /etc, instead only the install prefix directory and the home directory are used diff --git a/es-core/src/components/ScrollableContainer.cpp b/es-core/src/components/ScrollableContainer.cpp index d2c2576b1..feacbf151 100644 --- a/es-core/src/components/ScrollableContainer.cpp +++ b/es-core/src/components/ScrollableContainer.cpp @@ -9,14 +9,15 @@ #include "components/ScrollableContainer.h" +#include "animations/LambdaAnimation.h" #include "math/Vector2i.h" #include "renderers/Renderer.h" #include "Window.h" -#define AUTO_SCROLL_RESET_DELAY 6200 // Time before resetting to top after we reach the bottom. -#define AUTO_SCROLL_DELAY 2600 // Time to wait before we start to scroll. +#define AUTO_SCROLL_RESET_DELAY 4000.0f // Time before resetting to top after we reach the bottom. +#define AUTO_SCROLL_DELAY 2600.0f // Time to wait before we start to scroll. #define AUTO_SCROLL_SPEED 42 // Relative scrolling speed (lower is faster). -#define AUTO_WIDTH_MOD 350 // Line width modifier to use to calculate scrolling speed. +#define AUTO_WIDTH_MOD 350.0f // Line width modifier to use to calculate scrolling speed. ScrollableContainer::ScrollableContainer( Window* window) @@ -28,6 +29,9 @@ ScrollableContainer::ScrollableContainer( mScrollDir(0, 0), mAutoScrollResetAccumulator(0) { + // Set the modifier to get equivalent scrolling speed regardless of screen resolution. + // 1920p is the reference. + mResolutionModifier = static_cast(Renderer::getScreenWidth()) / 1920.0f; } void ScrollableContainer::render(const Transform4x4f& parentTrans) @@ -57,7 +61,7 @@ void ScrollableContainer::setAutoScroll(bool autoScroll) { if (autoScroll) { mScrollDir = Vector2f(0, 1); - mAutoScrollDelay = AUTO_SCROLL_DELAY; + mAutoScrollDelay = static_cast(AUTO_SCROLL_DELAY * mResolutionModifier); mAutoScrollSpeed = AUTO_SCROLL_SPEED; reset(); } @@ -89,11 +93,16 @@ void ScrollableContainer::update(int deltaTime) } const Vector2f contentSize = getContentSize(); + // Scale speed by the text width, more text per line leads to slower scrolling. - const float widthMod = contentSize.x() / AUTO_WIDTH_MOD; + const float widthMod = contentSize.x() / AUTO_WIDTH_MOD / mResolutionModifier; + + // Adjust delta time by text width and screen resolution. + int adjustedDeltaTime = + static_cast(static_cast(deltaTime) * mResolutionModifier / widthMod); if (mAutoScrollSpeed != 0) { - mAutoScrollAccumulator += deltaTime / static_cast(widthMod); + mAutoScrollAccumulator += adjustedDeltaTime; while (mAutoScrollAccumulator >= mAutoScrollSpeed) { mScrollPos += mScrollDir; @@ -122,14 +131,22 @@ void ScrollableContainer::update(int deltaTime) if (mAtEnd) { mAutoScrollResetAccumulator += deltaTime; - if (mAutoScrollResetAccumulator >= AUTO_SCROLL_RESET_DELAY) - reset(); + if (mAutoScrollResetAccumulator >= static_cast(AUTO_SCROLL_RESET_DELAY * widthMod)) { + // Fade in the text as it resets to the start position. + auto func = [this](float t) { + this->setOpacity(static_cast(Math::lerp(0.0f, 1.0f, t) * 255)); + mScrollPos = Vector2f(0, 0); + mAutoScrollResetAccumulator = 0; + mAutoScrollAccumulator = -mAutoScrollDelay + mAutoScrollSpeed; + mAtEnd = false; + }; + this->setAnimation(new LambdaAnimation(func, 300), 0, nullptr, false); + } } GuiComponent::update(deltaTime); } -// This should probably return a box to allow for when controls don't start at 0,0. Vector2f ScrollableContainer::getContentSize() { Vector2f max(0, 0); diff --git a/es-core/src/components/ScrollableContainer.h b/es-core/src/components/ScrollableContainer.h index 3418349ac..0a023869f 100644 --- a/es-core/src/components/ScrollableContainer.h +++ b/es-core/src/components/ScrollableContainer.h @@ -30,11 +30,12 @@ private: Vector2f mScrollPos; Vector2f mScrollDir; - int mAutoScrollDelay; // ms to wait before starting to autoscroll. - int mAutoScrollSpeed; // ms to wait before scrolling down by mScrollDir. + float mResolutionModifier; + int mAutoScrollDelay; + int mAutoScrollSpeed; int mAutoScrollAccumulator; - bool mAtEnd; int mAutoScrollResetAccumulator; + bool mAtEnd; }; #endif // ES_CORE_COMPONENTS_SCROLLABLE_CONTAINER_H