mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-26 16:15:39 +00:00
ScrollableContainer now takes the font size into consideration for adjusting the scrolling speed.
This commit is contained in:
parent
7b19b2cc6b
commit
e68c8f1db3
|
@ -68,9 +68,9 @@ GuiScraperSearch::GuiScraperSearch(
|
||||||
|
|
||||||
// Adjust the game description text scrolling parameters depending on the search type.
|
// Adjust the game description text scrolling parameters depending on the search type.
|
||||||
if (mSearchType == NEVER_AUTO_ACCEPT)
|
if (mSearchType == NEVER_AUTO_ACCEPT)
|
||||||
mDescContainer->setScrollParameters(1500, 1500, 11, AUTO_WIDTH_MOD);
|
mDescContainer->setScrollParameters(2500, 3000, 30);
|
||||||
else
|
else
|
||||||
mDescContainer->setScrollParameters(4000, 1500, 11, AUTO_WIDTH_MOD);
|
mDescContainer->setScrollParameters(6000, 3000, 30);
|
||||||
|
|
||||||
mResultDesc = std::make_shared<TextComponent>(mWindow, "Result desc",
|
mResultDesc = std::make_shared<TextComponent>(mWindow, "Result desc",
|
||||||
Font::get(FONT_SIZE_SMALL), 0x777777FF);
|
Font::get(FONT_SIZE_SMALL), 0x777777FF);
|
||||||
|
|
|
@ -123,6 +123,7 @@ DetailedGameListView::DetailedGameListView(
|
||||||
mDescription.setFont(Font::get(FONT_SIZE_SMALL));
|
mDescription.setFont(Font::get(FONT_SIZE_SMALL));
|
||||||
mDescription.setSize(mDescContainer.getSize().x(), 0);
|
mDescription.setSize(mDescContainer.getSize().x(), 0);
|
||||||
mDescContainer.addChild(&mDescription);
|
mDescContainer.addChild(&mDescription);
|
||||||
|
mDescContainer.setFontSizeSpeedAdjustments(Font::get(FONT_SIZE_SMALL)->getSize());
|
||||||
|
|
||||||
mGamelistInfo.setOrigin(0.5f, 0.5f);
|
mGamelistInfo.setOrigin(0.5f, 0.5f);
|
||||||
mGamelistInfo.setFont(Font::get(FONT_SIZE_SMALL));
|
mGamelistInfo.setFont(Font::get(FONT_SIZE_SMALL));
|
||||||
|
@ -174,6 +175,7 @@ void DetailedGameListView::onThemeChanged(const std::shared_ptr<ThemeData>& them
|
||||||
mDescription.setSize(mDescContainer.getSize().x(), 0);
|
mDescription.setSize(mDescContainer.getSize().x(), 0);
|
||||||
mDescription.applyTheme(theme, getName(), "md_description",
|
mDescription.applyTheme(theme, getName(), "md_description",
|
||||||
ALL ^ (POSITION | ThemeFlags::SIZE | ThemeFlags::ORIGIN | TEXT | ROTATION));
|
ALL ^ (POSITION | ThemeFlags::SIZE | ThemeFlags::ORIGIN | TEXT | ROTATION));
|
||||||
|
mDescContainer.setFontSizeSpeedAdjustments(mDescription.getFont()->getSize());
|
||||||
|
|
||||||
mGamelistInfo.applyTheme(theme, getName(), "gamelistInfo", ALL ^ ThemeFlags::TEXT);
|
mGamelistInfo.applyTheme(theme, getName(), "gamelistInfo", ALL ^ ThemeFlags::TEXT);
|
||||||
|
|
||||||
|
|
|
@ -117,6 +117,7 @@ GridGameListView::GridGameListView(
|
||||||
mDescription.setFont(Font::get(FONT_SIZE_SMALL));
|
mDescription.setFont(Font::get(FONT_SIZE_SMALL));
|
||||||
mDescription.setSize(mDescContainer.getSize().x(), 0);
|
mDescription.setSize(mDescContainer.getSize().x(), 0);
|
||||||
mDescContainer.addChild(&mDescription);
|
mDescContainer.addChild(&mDescription);
|
||||||
|
mDescContainer.setFontSizeSpeedAdjustments(Font::get(FONT_SIZE_SMALL)->getSize());
|
||||||
|
|
||||||
mMarquee.setOrigin(0.5f, 0.5f);
|
mMarquee.setOrigin(0.5f, 0.5f);
|
||||||
mMarquee.setPosition(mSize.x() * 0.25f, mSize.y() * 0.10f);
|
mMarquee.setPosition(mSize.x() * 0.25f, mSize.y() * 0.10f);
|
||||||
|
@ -305,6 +306,7 @@ void GridGameListView::onThemeChanged(const std::shared_ptr<ThemeData>& theme)
|
||||||
mDescription.setSize(mDescContainer.getSize().x(), 0);
|
mDescription.setSize(mDescContainer.getSize().x(), 0);
|
||||||
mDescription.applyTheme(theme, getName(), "md_description",
|
mDescription.applyTheme(theme, getName(), "md_description",
|
||||||
ALL ^ (POSITION | ThemeFlags::SIZE | ThemeFlags::ORIGIN | TEXT | ROTATION));
|
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.
|
// Repopulate list in case a new theme is displaying a different image.
|
||||||
// Preserve selection.
|
// Preserve selection.
|
||||||
|
|
|
@ -141,6 +141,7 @@ VideoGameListView::VideoGameListView(
|
||||||
mDescription.setFont(Font::get(FONT_SIZE_SMALL));
|
mDescription.setFont(Font::get(FONT_SIZE_SMALL));
|
||||||
mDescription.setSize(mDescContainer.getSize().x(), 0);
|
mDescription.setSize(mDescContainer.getSize().x(), 0);
|
||||||
mDescContainer.addChild(&mDescription);
|
mDescContainer.addChild(&mDescription);
|
||||||
|
mDescContainer.setFontSizeSpeedAdjustments(Font::get(FONT_SIZE_SMALL)->getSize());
|
||||||
|
|
||||||
mGamelistInfo.setOrigin(0.5f, 0.5f);
|
mGamelistInfo.setOrigin(0.5f, 0.5f);
|
||||||
mGamelistInfo.setFont(Font::get(FONT_SIZE_SMALL));
|
mGamelistInfo.setFont(Font::get(FONT_SIZE_SMALL));
|
||||||
|
@ -199,6 +200,7 @@ void VideoGameListView::onThemeChanged(const std::shared_ptr<ThemeData>& theme)
|
||||||
mDescription.setSize(mDescContainer.getSize().x(), 0);
|
mDescription.setSize(mDescContainer.getSize().x(), 0);
|
||||||
mDescription.applyTheme(theme, getName(), "md_description",
|
mDescription.applyTheme(theme, getName(), "md_description",
|
||||||
ALL ^ (POSITION | ThemeFlags::SIZE | ThemeFlags::ORIGIN | TEXT | ROTATION));
|
ALL ^ (POSITION | ThemeFlags::SIZE | ThemeFlags::ORIGIN | TEXT | ROTATION));
|
||||||
|
mDescContainer.setFontSizeSpeedAdjustments(mDescription.getFont()->getSize());
|
||||||
|
|
||||||
mGamelistInfo.applyTheme(theme, getName(), "gamelistInfo", ALL ^ ThemeFlags::TEXT);
|
mGamelistInfo.applyTheme(theme, getName(), "gamelistInfo", ALL ^ ThemeFlags::TEXT);
|
||||||
|
|
||||||
|
|
|
@ -169,7 +169,7 @@ public:
|
||||||
virtual void setHiddenValue(const std::string& value);
|
virtual void setHiddenValue(const std::string& value);
|
||||||
|
|
||||||
// Used to set the parameters for ScrollableContainer.
|
// 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 onFocusGained() {};
|
||||||
virtual void onFocusLost() {};
|
virtual void onFocusLost() {};
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include "animations/LambdaAnimation.h"
|
#include "animations/LambdaAnimation.h"
|
||||||
#include "math/Vector2i.h"
|
#include "math/Vector2i.h"
|
||||||
#include "renderers/Renderer.h"
|
#include "renderers/Renderer.h"
|
||||||
|
#include "resources/Font.h"
|
||||||
#include "Window.h"
|
#include "Window.h"
|
||||||
|
|
||||||
ScrollableContainer::ScrollableContainer(
|
ScrollableContainer::ScrollableContainer(
|
||||||
|
@ -31,7 +32,6 @@ ScrollableContainer::ScrollableContainer(
|
||||||
mAutoScrollResetDelayConstant = AUTO_SCROLL_RESET_DELAY;
|
mAutoScrollResetDelayConstant = AUTO_SCROLL_RESET_DELAY;
|
||||||
mAutoScrollDelayConstant = AUTO_SCROLL_DELAY;
|
mAutoScrollDelayConstant = AUTO_SCROLL_DELAY;
|
||||||
mAutoScrollSpeedConstant = AUTO_SCROLL_SPEED;
|
mAutoScrollSpeedConstant = AUTO_SCROLL_SPEED;
|
||||||
mAutoWidthModConstant = AUTO_WIDTH_MOD;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2f ScrollableContainer::getScrollPos() const
|
Vector2f ScrollableContainer::getScrollPos() const
|
||||||
|
@ -61,13 +61,27 @@ void ScrollableContainer::setAutoScroll(bool autoScroll)
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScrollableContainer::setScrollParameters(float autoScrollDelayConstant,
|
void ScrollableContainer::setScrollParameters(float autoScrollDelayConstant,
|
||||||
float autoScrollResetDelayConstant, int autoScrollSpeedConstant,
|
float autoScrollResetDelayConstant, int autoScrollSpeedConstant)
|
||||||
float autoWidthModConstant)
|
|
||||||
{
|
{
|
||||||
mAutoScrollResetDelayConstant = autoScrollResetDelayConstant;
|
mAutoScrollResetDelayConstant = autoScrollResetDelayConstant;
|
||||||
mAutoScrollDelayConstant = autoScrollDelayConstant;
|
mAutoScrollDelayConstant = autoScrollDelayConstant;
|
||||||
mAutoScrollSpeedConstant = autoScrollSpeedConstant;
|
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<float>(Font::get(FONT_SIZE_SMALL)->getSize()) / (static_cast<float>(size));
|
||||||
|
fontSizeModifier = fontSizeModifier * fontSizeModifier * fontSizeModifier;
|
||||||
|
mAutoScrollSpeed =
|
||||||
|
static_cast<int>((static_cast<float>(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<int>(static_cast<float>(mAutoScrollSpeed) * widthSpeedModifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScrollableContainer::reset()
|
void ScrollableContainer::reset()
|
||||||
|
@ -89,12 +103,8 @@ 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.
|
// Adjust delta time by screen resolution.
|
||||||
const float widthMod = contentSize.x() / mAutoWidthModConstant / mResolutionModifier;
|
int adjustedDeltaTime = static_cast<int>(static_cast<float>(deltaTime) * 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 += adjustedDeltaTime;
|
mAutoScrollAccumulator += adjustedDeltaTime;
|
||||||
|
@ -126,8 +136,7 @@ void ScrollableContainer::update(int deltaTime)
|
||||||
|
|
||||||
if (mAtEnd) {
|
if (mAtEnd) {
|
||||||
mAutoScrollResetAccumulator += deltaTime;
|
mAutoScrollResetAccumulator += deltaTime;
|
||||||
if (mAutoScrollResetAccumulator >=
|
if (mAutoScrollResetAccumulator >= static_cast<int>(mAutoScrollResetDelayConstant)) {
|
||||||
static_cast<int>(mAutoScrollResetDelayConstant * widthMod)) {
|
|
||||||
// Fade in the text as it resets to the start position.
|
// Fade in the text as it resets to the start position.
|
||||||
auto func = [this](float t) {
|
auto func = [this](float t) {
|
||||||
this->setOpacity(static_cast<unsigned char>(Math::lerp(0.0f, 1.0f, t) * 255));
|
this->setOpacity(static_cast<unsigned char>(Math::lerp(0.0f, 1.0f, t) * 255));
|
||||||
|
|
|
@ -10,10 +10,12 @@
|
||||||
#ifndef ES_CORE_COMPONENTS_SCROLLABLE_CONTAINER_H
|
#ifndef ES_CORE_COMPONENTS_SCROLLABLE_CONTAINER_H
|
||||||
#define 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.
|
// Time in ms to wait before scrolling starts.
|
||||||
#define AUTO_SCROLL_RESET_DELAY 4000.0f // Time before resetting to top after we reach the bottom.
|
#define AUTO_SCROLL_DELAY 4500.0f
|
||||||
#define AUTO_SCROLL_SPEED 48 // Relative scrolling speed (lower is faster).
|
// Time in ms before resetting to the top after we reach the bottom.
|
||||||
#define AUTO_WIDTH_MOD 350.0f // Line width modifier to use to calculate scrolling speed.
|
#define AUTO_SCROLL_RESET_DELAY 7000.0f
|
||||||
|
// Relative scrolling speed (lower is faster).
|
||||||
|
#define AUTO_SCROLL_SPEED 420
|
||||||
|
|
||||||
#include "GuiComponent.h"
|
#include "GuiComponent.h"
|
||||||
|
|
||||||
|
@ -26,7 +28,9 @@ public:
|
||||||
void setScrollPos(const Vector2f& pos);
|
void setScrollPos(const Vector2f& pos);
|
||||||
void setAutoScroll(bool autoScroll);
|
void setAutoScroll(bool autoScroll);
|
||||||
void setScrollParameters(float autoScrollDelayConstant, float autoScrollResetDelayConstant,
|
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 reset();
|
||||||
|
|
||||||
void update(int deltaTime) override;
|
void update(int deltaTime) override;
|
||||||
|
@ -41,7 +45,6 @@ private:
|
||||||
float mAutoScrollResetDelayConstant;
|
float mAutoScrollResetDelayConstant;
|
||||||
float mAutoScrollDelayConstant;
|
float mAutoScrollDelayConstant;
|
||||||
int mAutoScrollSpeedConstant;
|
int mAutoScrollSpeedConstant;
|
||||||
float mAutoWidthModConstant;
|
|
||||||
|
|
||||||
float mResolutionModifier;
|
float mResolutionModifier;
|
||||||
int mAutoScrollDelay;
|
int mAutoScrollDelay;
|
||||||
|
|
Loading…
Reference in a new issue