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.
This commit is contained in:
Leon Styhre 2021-01-02 21:17:23 +01:00
parent 910b9e0125
commit 1a746ac98f
3 changed files with 31 additions and 12 deletions

View file

@ -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

View file

@ -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<float>(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<int>(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<int>(static_cast<float>(deltaTime) * mResolutionModifier / widthMod);
if (mAutoScrollSpeed != 0) {
mAutoScrollAccumulator += deltaTime / static_cast<int>(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<int>(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<unsigned char>(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);

View file

@ -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