mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-25 15:45:38 +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.
|
||||
if (mSearchType == NEVER_AUTO_ACCEPT)
|
||||
mDescContainer->setScrollParameters(2500, 3000, 30);
|
||||
mDescContainer->setScrollParameters(2500, 3000, 70);
|
||||
else
|
||||
mDescContainer->setScrollParameters(6000, 3000, 30);
|
||||
mDescContainer->setScrollParameters(6000, 3000, 70);
|
||||
|
||||
mResultDesc = std::make_shared<TextComponent>(mWindow, "Result desc",
|
||||
Font::get(FONT_SIZE_SMALL), 0x777777FF);
|
||||
|
|
|
@ -123,7 +123,6 @@ 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));
|
||||
|
@ -175,7 +174,6 @@ void DetailedGameListView::onThemeChanged(const std::shared_ptr<ThemeData>& 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);
|
||||
|
||||
|
|
|
@ -117,7 +117,6 @@ 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);
|
||||
|
@ -306,7 +305,6 @@ void GridGameListView::onThemeChanged(const std::shared_ptr<ThemeData>& 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.
|
||||
|
|
|
@ -141,7 +141,6 @@ 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));
|
||||
|
@ -200,7 +199,6 @@ void VideoGameListView::onThemeChanged(const std::shared_ptr<ThemeData>& 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);
|
||||
|
||||
|
|
|
@ -160,6 +160,8 @@ public:
|
|||
virtual bool getEnabled() { return mEnabled; };
|
||||
virtual void setEnabled(bool state) { mEnabled = state; };
|
||||
|
||||
virtual std::shared_ptr<Font> getFont() const { return nullptr; };
|
||||
|
||||
const Transform4x4f& getTransform();
|
||||
|
||||
virtual std::string getValue() const;
|
||||
|
|
|
@ -61,7 +61,7 @@ public:
|
|||
virtual std::vector<HelpPrompt> getHelpPrompts() override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<Font> getFont() const;
|
||||
std::shared_ptr<Font> getFont() const override;
|
||||
|
||||
std::string getDisplayString(DisplayMode mode) const;
|
||||
DisplayMode getCurrentDisplayMode() const;
|
||||
|
|
|
@ -23,11 +23,19 @@ ScrollableContainer::ScrollableContainer(
|
|||
mAutoScrollAccumulator(0),
|
||||
mScrollPos(0, 0),
|
||||
mScrollDir(0, 0),
|
||||
mAutoScrollResetAccumulator(0)
|
||||
mAutoScrollResetAccumulator(0),
|
||||
mFontSize(0.0f)
|
||||
{
|
||||
// Set the modifier to get equivalent scrolling speed regardless of screen resolution.
|
||||
// 1080p is the reference.
|
||||
mResolutionModifier = Renderer::getScreenWidthModifier();
|
||||
mResolutionModifier = Renderer::getScreenHeightModifier();
|
||||
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;
|
||||
mAutoScrollDelayConstant = AUTO_SCROLL_DELAY;
|
||||
|
@ -48,8 +56,10 @@ void ScrollableContainer::setAutoScroll(bool autoScroll)
|
|||
{
|
||||
if (autoScroll) {
|
||||
mScrollDir = Vector2f(0, 1);
|
||||
mAutoScrollDelay = static_cast<int>(mAutoScrollDelayConstant * mResolutionModifier);
|
||||
mAutoScrollDelay = static_cast<int>(mAutoScrollDelayConstant);
|
||||
mAutoScrollSpeed = mAutoScrollSpeedConstant;
|
||||
mAutoScrollSpeed = static_cast<int>(static_cast<float>(mAutoScrollSpeedConstant) /
|
||||
mResolutionModifier);
|
||||
reset();
|
||||
}
|
||||
else {
|
||||
|
@ -68,22 +78,6 @@ void ScrollableContainer::setScrollParameters(float autoScrollDelayConstant,
|
|||
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()
|
||||
{
|
||||
mScrollPos = Vector2f(0, 0);
|
||||
|
@ -102,16 +96,24 @@ void ScrollableContainer::update(int deltaTime)
|
|||
}
|
||||
|
||||
const Vector2f contentSize = getContentSize();
|
||||
int adjustedAutoScrollSpeed = mAutoScrollSpeed;
|
||||
|
||||
// Adjust delta time by screen resolution.
|
||||
int adjustedDeltaTime = static_cast<int>(static_cast<float>(deltaTime) * mResolutionModifier);
|
||||
// Adjust the scrolling speed based on the width of the container.
|
||||
float widthModifier = contentSize.x() / static_cast<float>(Renderer::getScreenWidth());
|
||||
adjustedAutoScrollSpeed *= widthModifier;
|
||||
|
||||
if (mAutoScrollSpeed != 0) {
|
||||
mAutoScrollAccumulator += adjustedDeltaTime;
|
||||
// Also adjust the scrolling speed based on the size of the font.
|
||||
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;
|
||||
mAutoScrollAccumulator -= mAutoScrollSpeed;
|
||||
mAutoScrollAccumulator -= adjustedAutoScrollSpeed;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -185,6 +187,8 @@ Vector2f ScrollableContainer::getContentSize()
|
|||
max.x() = bottomRight.x();
|
||||
if (bottomRight.y() > max.y())
|
||||
max.y() = bottomRight.y();
|
||||
if (!mFontSize)
|
||||
mFontSize = static_cast<float>(mChildren.at(i)->getFont()->getSize());
|
||||
}
|
||||
|
||||
return max;
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
// 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
|
||||
#define AUTO_SCROLL_SPEED 90
|
||||
|
||||
#include "GuiComponent.h"
|
||||
|
||||
|
@ -29,8 +29,6 @@ public:
|
|||
void setAutoScroll(bool autoScroll);
|
||||
void setScrollParameters(float autoScrollDelayConstant, float autoScrollResetDelayConstant,
|
||||
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;
|
||||
|
@ -42,6 +40,9 @@ private:
|
|||
Vector2f mScrollPos;
|
||||
Vector2f mScrollDir;
|
||||
|
||||
float mFontSize;
|
||||
float mSmallFontSize;
|
||||
|
||||
float mAutoScrollResetDelayConstant;
|
||||
float mAutoScrollDelayConstant;
|
||||
int mAutoScrollSpeedConstant;
|
||||
|
|
|
@ -63,7 +63,7 @@ public:
|
|||
const std::string& element, unsigned int properties) override;
|
||||
|
||||
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:
|
||||
virtual void onTextChanged();
|
||||
|
|
|
@ -38,7 +38,7 @@ public:
|
|||
void stopEditing();
|
||||
|
||||
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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue