diff --git a/es-app/src/guis/GuiScraperSearch.cpp b/es-app/src/guis/GuiScraperSearch.cpp index 4d69a1bf7..05ea4a26d 100644 --- a/es-app/src/guis/GuiScraperSearch.cpp +++ b/es-app/src/guis/GuiScraperSearch.cpp @@ -68,9 +68,9 @@ GuiScraperSearch::GuiScraperSearch( // Adjust the game description text scrolling parameters depending on the search type. if (mSearchType == NEVER_AUTO_ACCEPT) - mDescContainer->setScrollParameters(1500, 1500, 11, AUTO_WIDTH_MOD); + mDescContainer->setScrollParameters(2500, 3000, 30); else - mDescContainer->setScrollParameters(4000, 1500, 11, AUTO_WIDTH_MOD); + mDescContainer->setScrollParameters(6000, 3000, 30); mResultDesc = std::make_shared(mWindow, "Result desc", Font::get(FONT_SIZE_SMALL), 0x777777FF); diff --git a/es-app/src/views/gamelist/DetailedGameListView.cpp b/es-app/src/views/gamelist/DetailedGameListView.cpp index f1d0719ef..ee531883b 100644 --- a/es-app/src/views/gamelist/DetailedGameListView.cpp +++ b/es-app/src/views/gamelist/DetailedGameListView.cpp @@ -123,6 +123,7 @@ DetailedGameListView::DetailedGameListView( mDescription.setFont(Font::get(FONT_SIZE_SMALL)); mDescription.setSize(mDescContainer.getSize().x(), 0); mDescContainer.addChild(&mDescription); + mDescContainer.setFontSizeSpeedAdjustments(Font::get(FONT_SIZE_SMALL)->getSize()); mGamelistInfo.setOrigin(0.5f, 0.5f); mGamelistInfo.setFont(Font::get(FONT_SIZE_SMALL)); @@ -174,6 +175,7 @@ void DetailedGameListView::onThemeChanged(const std::shared_ptr& them mDescription.setSize(mDescContainer.getSize().x(), 0); mDescription.applyTheme(theme, getName(), "md_description", ALL ^ (POSITION | ThemeFlags::SIZE | ThemeFlags::ORIGIN | TEXT | ROTATION)); + mDescContainer.setFontSizeSpeedAdjustments(mDescription.getFont()->getSize()); mGamelistInfo.applyTheme(theme, getName(), "gamelistInfo", ALL ^ ThemeFlags::TEXT); diff --git a/es-app/src/views/gamelist/GridGameListView.cpp b/es-app/src/views/gamelist/GridGameListView.cpp index fd27554b7..05fc8a53c 100644 --- a/es-app/src/views/gamelist/GridGameListView.cpp +++ b/es-app/src/views/gamelist/GridGameListView.cpp @@ -117,6 +117,7 @@ GridGameListView::GridGameListView( mDescription.setFont(Font::get(FONT_SIZE_SMALL)); mDescription.setSize(mDescContainer.getSize().x(), 0); mDescContainer.addChild(&mDescription); + mDescContainer.setFontSizeSpeedAdjustments(Font::get(FONT_SIZE_SMALL)->getSize()); mMarquee.setOrigin(0.5f, 0.5f); mMarquee.setPosition(mSize.x() * 0.25f, mSize.y() * 0.10f); @@ -305,6 +306,7 @@ void GridGameListView::onThemeChanged(const std::shared_ptr& theme) mDescription.setSize(mDescContainer.getSize().x(), 0); mDescription.applyTheme(theme, getName(), "md_description", ALL ^ (POSITION | ThemeFlags::SIZE | ThemeFlags::ORIGIN | TEXT | ROTATION)); + mDescContainer.setFontSizeSpeedAdjustments(mDescription.getFont()->getSize()); // Repopulate list in case a new theme is displaying a different image. // Preserve selection. diff --git a/es-app/src/views/gamelist/VideoGameListView.cpp b/es-app/src/views/gamelist/VideoGameListView.cpp index 55f909e00..aa7e351fa 100644 --- a/es-app/src/views/gamelist/VideoGameListView.cpp +++ b/es-app/src/views/gamelist/VideoGameListView.cpp @@ -141,6 +141,7 @@ VideoGameListView::VideoGameListView( mDescription.setFont(Font::get(FONT_SIZE_SMALL)); mDescription.setSize(mDescContainer.getSize().x(), 0); mDescContainer.addChild(&mDescription); + mDescContainer.setFontSizeSpeedAdjustments(Font::get(FONT_SIZE_SMALL)->getSize()); mGamelistInfo.setOrigin(0.5f, 0.5f); mGamelistInfo.setFont(Font::get(FONT_SIZE_SMALL)); @@ -199,6 +200,7 @@ void VideoGameListView::onThemeChanged(const std::shared_ptr& theme) mDescription.setSize(mDescContainer.getSize().x(), 0); mDescription.applyTheme(theme, getName(), "md_description", ALL ^ (POSITION | ThemeFlags::SIZE | ThemeFlags::ORIGIN | TEXT | ROTATION)); + mDescContainer.setFontSizeSpeedAdjustments(mDescription.getFont()->getSize()); mGamelistInfo.applyTheme(theme, getName(), "gamelistInfo", ALL ^ ThemeFlags::TEXT); diff --git a/es-core/src/GuiComponent.h b/es-core/src/GuiComponent.h index 703b10618..dd7c9938a 100644 --- a/es-core/src/GuiComponent.h +++ b/es-core/src/GuiComponent.h @@ -169,7 +169,7 @@ public: virtual void setHiddenValue(const std::string& value); // Used to set the parameters for ScrollableContainer. - virtual void setScrollParameters(float, float, int, float) {}; + virtual void setScrollParameters(float, float, int) {}; virtual void onFocusGained() {}; virtual void onFocusLost() {}; diff --git a/es-core/src/components/ScrollableContainer.cpp b/es-core/src/components/ScrollableContainer.cpp index 654429838..dc2c93433 100644 --- a/es-core/src/components/ScrollableContainer.cpp +++ b/es-core/src/components/ScrollableContainer.cpp @@ -12,6 +12,7 @@ #include "animations/LambdaAnimation.h" #include "math/Vector2i.h" #include "renderers/Renderer.h" +#include "resources/Font.h" #include "Window.h" ScrollableContainer::ScrollableContainer( @@ -31,7 +32,6 @@ ScrollableContainer::ScrollableContainer( mAutoScrollResetDelayConstant = AUTO_SCROLL_RESET_DELAY; mAutoScrollDelayConstant = AUTO_SCROLL_DELAY; mAutoScrollSpeedConstant = AUTO_SCROLL_SPEED; - mAutoWidthModConstant = AUTO_WIDTH_MOD; } Vector2f ScrollableContainer::getScrollPos() const @@ -61,13 +61,27 @@ void ScrollableContainer::setAutoScroll(bool autoScroll) } void ScrollableContainer::setScrollParameters(float autoScrollDelayConstant, - float autoScrollResetDelayConstant, int autoScrollSpeedConstant, - float autoWidthModConstant) + float autoScrollResetDelayConstant, int autoScrollSpeedConstant) { mAutoScrollResetDelayConstant = autoScrollResetDelayConstant; mAutoScrollDelayConstant = autoScrollDelayConstant; mAutoScrollSpeedConstant = autoScrollSpeedConstant; - mAutoWidthModConstant = autoWidthModConstant; +} + +void ScrollableContainer::setFontSizeSpeedAdjustments(int size) +{ + // Adjust scrolling speed relative to the font size, i.e. a larger size makes it faster. + float fontSizeModifier = + static_cast(Font::get(FONT_SIZE_SMALL)->getSize()) / (static_cast(size)); + fontSizeModifier = fontSizeModifier * fontSizeModifier * fontSizeModifier; + mAutoScrollSpeed = + static_cast((static_cast(mAutoScrollSpeed) * fontSizeModifier) / 2.0f); + + // Also adjust the speed relative to the width of the text container. This is not perfect + // but at least increases the speed for narrower fields to a reasonable level. + float widthSpeedModifier = getContentSize().x() / Renderer::getScreenWidth(); + mAutoScrollSpeed = + static_cast(static_cast(mAutoScrollSpeed) * widthSpeedModifier); } void ScrollableContainer::reset() @@ -89,12 +103,8 @@ 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() / mAutoWidthModConstant / mResolutionModifier; - - // Adjust delta time by text width and screen resolution. - int adjustedDeltaTime = - static_cast(static_cast(deltaTime) * mResolutionModifier / widthMod); + // Adjust delta time by screen resolution. + int adjustedDeltaTime = static_cast(static_cast(deltaTime) * mResolutionModifier); if (mAutoScrollSpeed != 0) { mAutoScrollAccumulator += adjustedDeltaTime; @@ -126,8 +136,7 @@ void ScrollableContainer::update(int deltaTime) if (mAtEnd) { mAutoScrollResetAccumulator += deltaTime; - if (mAutoScrollResetAccumulator >= - static_cast(mAutoScrollResetDelayConstant * widthMod)) { + if (mAutoScrollResetAccumulator >= static_cast(mAutoScrollResetDelayConstant)) { // 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)); diff --git a/es-core/src/components/ScrollableContainer.h b/es-core/src/components/ScrollableContainer.h index 98e8aab1d..cb4167361 100644 --- a/es-core/src/components/ScrollableContainer.h +++ b/es-core/src/components/ScrollableContainer.h @@ -10,10 +10,12 @@ #ifndef ES_CORE_COMPONENTS_SCROLLABLE_CONTAINER_H #define ES_CORE_COMPONENTS_SCROLLABLE_CONTAINER_H -#define AUTO_SCROLL_DELAY 2400.0f // 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_SPEED 48 // Relative scrolling speed (lower is faster). -#define AUTO_WIDTH_MOD 350.0f // Line width modifier to use to calculate scrolling speed. +// Time in ms to wait before scrolling starts. +#define AUTO_SCROLL_DELAY 4500.0f +// Time in ms before resetting to the top after we reach the bottom. +#define AUTO_SCROLL_RESET_DELAY 7000.0f +// Relative scrolling speed (lower is faster). +#define AUTO_SCROLL_SPEED 420 #include "GuiComponent.h" @@ -26,7 +28,9 @@ public: void setScrollPos(const Vector2f& pos); void setAutoScroll(bool autoScroll); void setScrollParameters(float autoScrollDelayConstant, float autoScrollResetDelayConstant, - int autoScrollSpeedConstant, float autoWidthModConstant) override; + int autoScrollSpeedConstant) override; + // Adjust scrolling speed based on the font size (and text container width). + void setFontSizeSpeedAdjustments(int size); void reset(); void update(int deltaTime) override; @@ -41,7 +45,6 @@ private: float mAutoScrollResetDelayConstant; float mAutoScrollDelayConstant; int mAutoScrollSpeedConstant; - float mAutoWidthModConstant; float mResolutionModifier; int mAutoScrollDelay;