mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-03-06 14:27:43 +00:00
Improved the speed consistency for ScrollableContainer.
This commit is contained in:
parent
90f4c29048
commit
66e1c4e897
|
@ -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(2500, 3000, 30);
|
mDescContainer->setScrollParameters(2500, 3000, 70);
|
||||||
else
|
else
|
||||||
mDescContainer->setScrollParameters(6000, 3000, 30);
|
mDescContainer->setScrollParameters(6000, 3000, 70);
|
||||||
|
|
||||||
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,7 +123,6 @@ 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));
|
||||||
|
@ -175,7 +174,6 @@ 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,7 +117,6 @@ 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);
|
||||||
|
@ -306,7 +305,6 @@ 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,7 +141,6 @@ 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));
|
||||||
|
@ -200,7 +199,6 @@ 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);
|
||||||
|
|
||||||
|
|
|
@ -160,6 +160,8 @@ public:
|
||||||
virtual bool getEnabled() { return mEnabled; };
|
virtual bool getEnabled() { return mEnabled; };
|
||||||
virtual void setEnabled(bool state) { mEnabled = state; };
|
virtual void setEnabled(bool state) { mEnabled = state; };
|
||||||
|
|
||||||
|
virtual std::shared_ptr<Font> getFont() const { return nullptr; };
|
||||||
|
|
||||||
const Transform4x4f& getTransform();
|
const Transform4x4f& getTransform();
|
||||||
|
|
||||||
virtual std::string getValue() const;
|
virtual std::string getValue() const;
|
||||||
|
|
|
@ -61,7 +61,7 @@ public:
|
||||||
virtual std::vector<HelpPrompt> getHelpPrompts() override;
|
virtual std::vector<HelpPrompt> getHelpPrompts() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<Font> getFont() const;
|
std::shared_ptr<Font> getFont() const override;
|
||||||
|
|
||||||
std::string getDisplayString(DisplayMode mode) const;
|
std::string getDisplayString(DisplayMode mode) const;
|
||||||
DisplayMode getCurrentDisplayMode() const;
|
DisplayMode getCurrentDisplayMode() const;
|
||||||
|
|
|
@ -23,11 +23,19 @@ ScrollableContainer::ScrollableContainer(
|
||||||
mAutoScrollAccumulator(0),
|
mAutoScrollAccumulator(0),
|
||||||
mScrollPos(0, 0),
|
mScrollPos(0, 0),
|
||||||
mScrollDir(0, 0),
|
mScrollDir(0, 0),
|
||||||
mAutoScrollResetAccumulator(0)
|
mAutoScrollResetAccumulator(0),
|
||||||
|
mFontSize(0.0f)
|
||||||
{
|
{
|
||||||
// Set the modifier to get equivalent scrolling speed regardless of screen resolution.
|
// Set the modifier to get equivalent scrolling speed regardless of screen resolution.
|
||||||
// 1080p is the reference.
|
mResolutionModifier = Renderer::getScreenHeightModifier();
|
||||||
mResolutionModifier = Renderer::getScreenWidthModifier();
|
mSmallFontSize = static_cast<float>(Font::get(FONT_SIZE_SMALL)->getSize());
|
||||||
|
|
||||||
|
// For narrower aspect ratios than 16:9 there is a need to set an additional compensation
|
||||||
|
// to get somehow consistent scrolling speeds.
|
||||||
|
float aspectCompensation = static_cast<float>(Renderer::getScreenHeight()) /
|
||||||
|
static_cast<float>(Renderer::getScreenWidth()) - 0.5625f;
|
||||||
|
if (aspectCompensation > 0)
|
||||||
|
mResolutionModifier += aspectCompensation * 4.0f;
|
||||||
|
|
||||||
mAutoScrollResetDelayConstant = AUTO_SCROLL_RESET_DELAY;
|
mAutoScrollResetDelayConstant = AUTO_SCROLL_RESET_DELAY;
|
||||||
mAutoScrollDelayConstant = AUTO_SCROLL_DELAY;
|
mAutoScrollDelayConstant = AUTO_SCROLL_DELAY;
|
||||||
|
@ -48,8 +56,10 @@ void ScrollableContainer::setAutoScroll(bool autoScroll)
|
||||||
{
|
{
|
||||||
if (autoScroll) {
|
if (autoScroll) {
|
||||||
mScrollDir = Vector2f(0, 1);
|
mScrollDir = Vector2f(0, 1);
|
||||||
mAutoScrollDelay = static_cast<int>(mAutoScrollDelayConstant * mResolutionModifier);
|
mAutoScrollDelay = static_cast<int>(mAutoScrollDelayConstant);
|
||||||
mAutoScrollSpeed = mAutoScrollSpeedConstant;
|
mAutoScrollSpeed = mAutoScrollSpeedConstant;
|
||||||
|
mAutoScrollSpeed = static_cast<int>(static_cast<float>(mAutoScrollSpeedConstant) /
|
||||||
|
mResolutionModifier);
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -68,22 +78,6 @@ void ScrollableContainer::setScrollParameters(float autoScrollDelayConstant,
|
||||||
mAutoScrollSpeedConstant = autoScrollSpeedConstant;
|
mAutoScrollSpeedConstant = autoScrollSpeedConstant;
|
||||||
}
|
}
|
||||||
|
|
||||||
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()
|
||||||
{
|
{
|
||||||
mScrollPos = Vector2f(0, 0);
|
mScrollPos = Vector2f(0, 0);
|
||||||
|
@ -102,16 +96,24 @@ void ScrollableContainer::update(int deltaTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
const Vector2f contentSize = getContentSize();
|
const Vector2f contentSize = getContentSize();
|
||||||
|
int adjustedAutoScrollSpeed = mAutoScrollSpeed;
|
||||||
|
|
||||||
// Adjust delta time by screen resolution.
|
// Adjust the scrolling speed based on the width of the container.
|
||||||
int adjustedDeltaTime = static_cast<int>(static_cast<float>(deltaTime) * mResolutionModifier);
|
float widthModifier = contentSize.x() / static_cast<float>(Renderer::getScreenWidth());
|
||||||
|
adjustedAutoScrollSpeed *= widthModifier;
|
||||||
|
|
||||||
if (mAutoScrollSpeed != 0) {
|
// Also adjust the scrolling speed based on the size of the font.
|
||||||
mAutoScrollAccumulator += adjustedDeltaTime;
|
float fontSizeModifier = mSmallFontSize / mFontSize;
|
||||||
|
adjustedAutoScrollSpeed *= fontSizeModifier * fontSizeModifier;
|
||||||
|
|
||||||
while (mAutoScrollAccumulator >= mAutoScrollSpeed) {
|
if (adjustedAutoScrollSpeed < 0)
|
||||||
|
adjustedAutoScrollSpeed = 1;
|
||||||
|
|
||||||
|
if (adjustedAutoScrollSpeed != 0) {
|
||||||
|
mAutoScrollAccumulator += deltaTime;
|
||||||
|
while (mAutoScrollAccumulator >= adjustedAutoScrollSpeed) {
|
||||||
mScrollPos += mScrollDir;
|
mScrollPos += mScrollDir;
|
||||||
mAutoScrollAccumulator -= mAutoScrollSpeed;
|
mAutoScrollAccumulator -= adjustedAutoScrollSpeed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,6 +187,8 @@ Vector2f ScrollableContainer::getContentSize()
|
||||||
max.x() = bottomRight.x();
|
max.x() = bottomRight.x();
|
||||||
if (bottomRight.y() > max.y())
|
if (bottomRight.y() > max.y())
|
||||||
max.y() = bottomRight.y();
|
max.y() = bottomRight.y();
|
||||||
|
if (!mFontSize)
|
||||||
|
mFontSize = static_cast<float>(mChildren.at(i)->getFont()->getSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
return max;
|
return max;
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
// Time in ms before resetting to the top after we reach the bottom.
|
// Time in ms before resetting to the top after we reach the bottom.
|
||||||
#define AUTO_SCROLL_RESET_DELAY 7000.0f
|
#define AUTO_SCROLL_RESET_DELAY 7000.0f
|
||||||
// Relative scrolling speed (lower is faster).
|
// Relative scrolling speed (lower is faster).
|
||||||
#define AUTO_SCROLL_SPEED 420
|
#define AUTO_SCROLL_SPEED 90
|
||||||
|
|
||||||
#include "GuiComponent.h"
|
#include "GuiComponent.h"
|
||||||
|
|
||||||
|
@ -29,8 +29,6 @@ public:
|
||||||
void setAutoScroll(bool autoScroll);
|
void setAutoScroll(bool autoScroll);
|
||||||
void setScrollParameters(float autoScrollDelayConstant, float autoScrollResetDelayConstant,
|
void setScrollParameters(float autoScrollDelayConstant, float autoScrollResetDelayConstant,
|
||||||
int autoScrollSpeedConstant) 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;
|
||||||
|
@ -42,6 +40,9 @@ private:
|
||||||
Vector2f mScrollPos;
|
Vector2f mScrollPos;
|
||||||
Vector2f mScrollDir;
|
Vector2f mScrollDir;
|
||||||
|
|
||||||
|
float mFontSize;
|
||||||
|
float mSmallFontSize;
|
||||||
|
|
||||||
float mAutoScrollResetDelayConstant;
|
float mAutoScrollResetDelayConstant;
|
||||||
float mAutoScrollDelayConstant;
|
float mAutoScrollDelayConstant;
|
||||||
int mAutoScrollSpeedConstant;
|
int mAutoScrollSpeedConstant;
|
||||||
|
|
|
@ -63,7 +63,7 @@ public:
|
||||||
const std::string& element, unsigned int properties) override;
|
const std::string& element, unsigned int properties) override;
|
||||||
|
|
||||||
unsigned int getColor() const override { return mColor; };
|
unsigned int getColor() const override { return mColor; };
|
||||||
inline std::shared_ptr<Font> getFont() const { return mFont; }
|
inline std::shared_ptr<Font> getFont() const override { return mFont; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void onTextChanged();
|
virtual void onTextChanged();
|
||||||
|
|
|
@ -38,7 +38,7 @@ public:
|
||||||
void stopEditing();
|
void stopEditing();
|
||||||
|
|
||||||
inline bool isEditing() const { return mEditing; };
|
inline bool isEditing() const { return mEditing; };
|
||||||
inline const std::shared_ptr<Font>& getFont() const { return mFont; }
|
inline std::shared_ptr<Font> getFont() const override{ return mFont; }
|
||||||
|
|
||||||
void setCursor(size_t pos);
|
void setCursor(size_t pos);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue