mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-21 21:55:38 +00:00
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:
parent
910b9e0125
commit
1a746ac98f
|
@ -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)
|
* 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
|
* Many additional quality of life improvements and removal of GUI inconsistencies
|
||||||
* Replaced the on and off button icons with new graphics
|
* 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
|
* 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
|
* 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
|
* No more attempts to open files directly under /etc, instead only the install prefix directory and the home directory are used
|
||||||
|
|
|
@ -9,14 +9,15 @@
|
||||||
|
|
||||||
#include "components/ScrollableContainer.h"
|
#include "components/ScrollableContainer.h"
|
||||||
|
|
||||||
|
#include "animations/LambdaAnimation.h"
|
||||||
#include "math/Vector2i.h"
|
#include "math/Vector2i.h"
|
||||||
#include "renderers/Renderer.h"
|
#include "renderers/Renderer.h"
|
||||||
#include "Window.h"
|
#include "Window.h"
|
||||||
|
|
||||||
#define AUTO_SCROLL_RESET_DELAY 6200 // Time before resetting to top after we reach the bottom.
|
#define AUTO_SCROLL_RESET_DELAY 4000.0f // 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_DELAY 2600.0f // Time to wait before we start to scroll.
|
||||||
#define AUTO_SCROLL_SPEED 42 // Relative scrolling speed (lower is faster).
|
#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(
|
ScrollableContainer::ScrollableContainer(
|
||||||
Window* window)
|
Window* window)
|
||||||
|
@ -28,6 +29,9 @@ ScrollableContainer::ScrollableContainer(
|
||||||
mScrollDir(0, 0),
|
mScrollDir(0, 0),
|
||||||
mAutoScrollResetAccumulator(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)
|
void ScrollableContainer::render(const Transform4x4f& parentTrans)
|
||||||
|
@ -57,7 +61,7 @@ void ScrollableContainer::setAutoScroll(bool autoScroll)
|
||||||
{
|
{
|
||||||
if (autoScroll) {
|
if (autoScroll) {
|
||||||
mScrollDir = Vector2f(0, 1);
|
mScrollDir = Vector2f(0, 1);
|
||||||
mAutoScrollDelay = AUTO_SCROLL_DELAY;
|
mAutoScrollDelay = static_cast<int>(AUTO_SCROLL_DELAY * mResolutionModifier);
|
||||||
mAutoScrollSpeed = AUTO_SCROLL_SPEED;
|
mAutoScrollSpeed = AUTO_SCROLL_SPEED;
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
@ -89,11 +93,16 @@ void ScrollableContainer::update(int deltaTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
const Vector2f contentSize = getContentSize();
|
const Vector2f contentSize = getContentSize();
|
||||||
|
|
||||||
// Scale speed by the text width, more text per line leads to slower scrolling.
|
// 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) {
|
if (mAutoScrollSpeed != 0) {
|
||||||
mAutoScrollAccumulator += deltaTime / static_cast<int>(widthMod);
|
mAutoScrollAccumulator += adjustedDeltaTime;
|
||||||
|
|
||||||
while (mAutoScrollAccumulator >= mAutoScrollSpeed) {
|
while (mAutoScrollAccumulator >= mAutoScrollSpeed) {
|
||||||
mScrollPos += mScrollDir;
|
mScrollPos += mScrollDir;
|
||||||
|
@ -122,14 +131,22 @@ void ScrollableContainer::update(int deltaTime)
|
||||||
|
|
||||||
if (mAtEnd) {
|
if (mAtEnd) {
|
||||||
mAutoScrollResetAccumulator += deltaTime;
|
mAutoScrollResetAccumulator += deltaTime;
|
||||||
if (mAutoScrollResetAccumulator >= AUTO_SCROLL_RESET_DELAY)
|
if (mAutoScrollResetAccumulator >= static_cast<int>(AUTO_SCROLL_RESET_DELAY * widthMod)) {
|
||||||
reset();
|
// 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);
|
GuiComponent::update(deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This should probably return a box to allow for when controls don't start at 0,0.
|
|
||||||
Vector2f ScrollableContainer::getContentSize()
|
Vector2f ScrollableContainer::getContentSize()
|
||||||
{
|
{
|
||||||
Vector2f max(0, 0);
|
Vector2f max(0, 0);
|
||||||
|
|
|
@ -30,11 +30,12 @@ private:
|
||||||
|
|
||||||
Vector2f mScrollPos;
|
Vector2f mScrollPos;
|
||||||
Vector2f mScrollDir;
|
Vector2f mScrollDir;
|
||||||
int mAutoScrollDelay; // ms to wait before starting to autoscroll.
|
float mResolutionModifier;
|
||||||
int mAutoScrollSpeed; // ms to wait before scrolling down by mScrollDir.
|
int mAutoScrollDelay;
|
||||||
|
int mAutoScrollSpeed;
|
||||||
int mAutoScrollAccumulator;
|
int mAutoScrollAccumulator;
|
||||||
bool mAtEnd;
|
|
||||||
int mAutoScrollResetAccumulator;
|
int mAutoScrollResetAccumulator;
|
||||||
|
bool mAtEnd;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ES_CORE_COMPONENTS_SCROLLABLE_CONTAINER_H
|
#endif // ES_CORE_COMPONENTS_SCROLLABLE_CONTAINER_H
|
||||||
|
|
Loading…
Reference in a new issue