mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-26 16:15:39 +00:00
Adjusted ScrollableContainer autoscroll.
Scroll delay and speed are now hardcoded instead of arguments. Changed resetAutoscroll() to just reset(), which now also resets cursor position. Autoscroll now automatically returns to the top (via reset()) after 10 seconds.
This commit is contained in:
parent
75e31d915c
commit
0d39586c2d
|
@ -38,7 +38,7 @@ ScraperSearchComponent::ScraperSearchComponent(Window* window, SearchType type)
|
||||||
mDescContainer = std::make_shared<ScrollableContainer>(mWindow);
|
mDescContainer = std::make_shared<ScrollableContainer>(mWindow);
|
||||||
mResultDesc = std::make_shared<TextComponent>(mWindow, "Result desc", Font::get(FONT_SIZE_SMALL), 0x777777FF);
|
mResultDesc = std::make_shared<TextComponent>(mWindow, "Result desc", Font::get(FONT_SIZE_SMALL), 0x777777FF);
|
||||||
mDescContainer->addChild(mResultDesc.get());
|
mDescContainer->addChild(mResultDesc.get());
|
||||||
mDescContainer->setAutoScroll(2200, 0.015f);
|
mDescContainer->setAutoScroll(true);
|
||||||
|
|
||||||
// metadata
|
// metadata
|
||||||
auto font = Font::get(FONT_SIZE_SMALL); // this gets replaced in onSizeChanged() so its just a placeholder
|
auto font = Font::get(FONT_SIZE_SMALL); // this gets replaced in onSizeChanged() so its just a placeholder
|
||||||
|
@ -300,8 +300,7 @@ void ScraperSearchComponent::updateInfoPane()
|
||||||
ScraperSearchResult& res = mScraperResults.at(i);
|
ScraperSearchResult& res = mScraperResults.at(i);
|
||||||
mResultName->setText(strToUpper(res.mdl.get("name")));
|
mResultName->setText(strToUpper(res.mdl.get("name")));
|
||||||
mResultDesc->setText(strToUpper(res.mdl.get("desc")));
|
mResultDesc->setText(strToUpper(res.mdl.get("desc")));
|
||||||
mDescContainer->setScrollPos(Eigen::Vector2d(0, 0));
|
mDescContainer->reset();
|
||||||
mDescContainer->resetAutoScrollTimer();
|
|
||||||
|
|
||||||
mResultThumbnail->setImage("");
|
mResultThumbnail->setImage("");
|
||||||
const std::string& thumb = res.thumbnailUrl.empty() ? res.imageUrl : res.thumbnailUrl;
|
const std::string& thumb = res.thumbnailUrl.empty() ? res.imageUrl : res.thumbnailUrl;
|
||||||
|
|
|
@ -2,8 +2,12 @@
|
||||||
#include "../Renderer.h"
|
#include "../Renderer.h"
|
||||||
#include "../Log.h"
|
#include "../Log.h"
|
||||||
|
|
||||||
|
#define AUTO_SCROLL_RESET_DELAY 10000 // ms to reset to top after we reach the bottom
|
||||||
|
#define AUTO_SCROLL_DELAY 8000 // ms to wait before we start to scroll
|
||||||
|
#define AUTO_SCROLL_SPEED 50 // ms between scrolls
|
||||||
|
|
||||||
ScrollableContainer::ScrollableContainer(Window* window) : GuiComponent(window),
|
ScrollableContainer::ScrollableContainer(Window* window) : GuiComponent(window),
|
||||||
mAutoScrollDelay(0), mAutoScrollSpeed(0), mAutoScrollTimer(0), mScrollPos(0, 0), mScrollDir(0, 0)
|
mAutoScrollDelay(0), mAutoScrollSpeed(0), mAutoScrollAccumulator(0), mScrollPos(0, 0), mScrollDir(0, 0), mAutoScrollResetAccumulator(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +22,7 @@ void ScrollableContainer::render(const Eigen::Affine3f& parentTrans)
|
||||||
|
|
||||||
Renderer::pushClipRect(clipPos, clipDim);
|
Renderer::pushClipRect(clipPos, clipDim);
|
||||||
|
|
||||||
trans.translate(Eigen::Vector3f((float)-mScrollPos.x(), (float)-mScrollPos.y(), 0));
|
trans.translate(-Eigen::Vector3f(mScrollPos.x(), mScrollPos.y(), 0));
|
||||||
Renderer::setMatrix(trans);
|
Renderer::setMatrix(trans);
|
||||||
|
|
||||||
GuiComponent::renderChildren(trans);
|
GuiComponent::renderChildren(trans);
|
||||||
|
@ -26,65 +30,75 @@ void ScrollableContainer::render(const Eigen::Affine3f& parentTrans)
|
||||||
Renderer::popClipRect();
|
Renderer::popClipRect();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScrollableContainer::setAutoScroll(int delay, double speed)
|
void ScrollableContainer::setAutoScroll(bool autoScroll)
|
||||||
{
|
{
|
||||||
mAutoScrollDelay = delay;
|
if(autoScroll)
|
||||||
mAutoScrollSpeed = speed;
|
{
|
||||||
mAutoScrollTimer = 0;
|
mScrollDir << 0, 1;
|
||||||
|
mAutoScrollDelay = AUTO_SCROLL_DELAY;
|
||||||
|
mAutoScrollSpeed = AUTO_SCROLL_SPEED;
|
||||||
|
reset();
|
||||||
|
}else{
|
||||||
|
mScrollDir << 0, 0;
|
||||||
|
mAutoScrollDelay = 0;
|
||||||
|
mAutoScrollSpeed = 0;
|
||||||
|
mAutoScrollAccumulator = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Eigen::Vector2d ScrollableContainer::getScrollPos() const
|
Eigen::Vector2f ScrollableContainer::getScrollPos() const
|
||||||
{
|
{
|
||||||
return mScrollPos;
|
return mScrollPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScrollableContainer::setScrollPos(const Eigen::Vector2d& pos)
|
void ScrollableContainer::setScrollPos(const Eigen::Vector2f& pos)
|
||||||
{
|
{
|
||||||
mScrollPos = pos;
|
mScrollPos = pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScrollableContainer::update(int deltaTime)
|
void ScrollableContainer::update(int deltaTime)
|
||||||
{
|
{
|
||||||
double scrollAmt = (double)deltaTime;
|
|
||||||
|
|
||||||
if(mAutoScrollSpeed != 0)
|
if(mAutoScrollSpeed != 0)
|
||||||
{
|
{
|
||||||
mAutoScrollTimer += deltaTime;
|
mAutoScrollAccumulator += deltaTime;
|
||||||
|
|
||||||
scrollAmt = (float)(mAutoScrollTimer - mAutoScrollDelay);
|
//scale speed by our width! more text per line = slower scrolling
|
||||||
|
const float widthMod = (680.0f / getSize().x());
|
||||||
if(scrollAmt > 0)
|
while(mAutoScrollAccumulator >= mAutoScrollSpeed)
|
||||||
{
|
{
|
||||||
//scroll the amount of time left over from the delay
|
mScrollPos += mScrollDir;
|
||||||
mAutoScrollTimer = mAutoScrollDelay;
|
mAutoScrollAccumulator -= mAutoScrollSpeed;
|
||||||
|
|
||||||
//scale speed by our width! more text per line = slower scrolling
|
|
||||||
const double widthMod = (680.0 / getSize().x());
|
|
||||||
mScrollDir = Eigen::Vector2d(0, mAutoScrollSpeed * widthMod);
|
|
||||||
}else{
|
|
||||||
//not enough to pass the delay, do nothing
|
|
||||||
scrollAmt = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Eigen::Vector2d scroll = mScrollDir * scrollAmt;
|
|
||||||
mScrollPos += scroll;
|
|
||||||
|
|
||||||
//clip scrolling within bounds
|
//clip scrolling within bounds
|
||||||
if(mScrollPos.x() < 0)
|
if(mScrollPos.x() < 0)
|
||||||
mScrollPos[0] = 0;
|
mScrollPos[0] = 0;
|
||||||
if(mScrollPos.y() < 0)
|
if(mScrollPos.y() < 0)
|
||||||
mScrollPos[1] = 0;
|
mScrollPos[1] = 0;
|
||||||
|
|
||||||
|
const Eigen::Vector2f contentSize = getContentSize();
|
||||||
Eigen::Vector2f contentSize = getContentSize();
|
|
||||||
if(mScrollPos.x() + getSize().x() > contentSize.x())
|
if(mScrollPos.x() + getSize().x() > contentSize.x())
|
||||||
mScrollPos[0] = (double)contentSize.x() - getSize().x();
|
{
|
||||||
|
mScrollPos[0] = contentSize.x() - getSize().x();
|
||||||
|
mAtEnd = true;
|
||||||
|
}
|
||||||
|
|
||||||
if(contentSize.y() < getSize().y())
|
if(contentSize.y() < getSize().y())
|
||||||
|
{
|
||||||
mScrollPos[1] = 0;
|
mScrollPos[1] = 0;
|
||||||
else if(mScrollPos.y() + getSize().y() > contentSize.y())
|
}else if(mScrollPos.y() + getSize().y() > contentSize.y())
|
||||||
mScrollPos[1] = (double)contentSize.y() - getSize().y();
|
{
|
||||||
|
mScrollPos[1] = contentSize.y() - getSize().y();
|
||||||
|
mAtEnd = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(mAtEnd)
|
||||||
|
{
|
||||||
|
mAutoScrollResetAccumulator += deltaTime;
|
||||||
|
if(mAutoScrollResetAccumulator >= AUTO_SCROLL_RESET_DELAY)
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
|
||||||
GuiComponent::update(deltaTime);
|
GuiComponent::update(deltaTime);
|
||||||
}
|
}
|
||||||
|
@ -106,7 +120,10 @@ Eigen::Vector2f ScrollableContainer::getContentSize()
|
||||||
return max;
|
return max;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScrollableContainer::resetAutoScrollTimer()
|
void ScrollableContainer::reset()
|
||||||
{
|
{
|
||||||
mAutoScrollTimer = 0;
|
mScrollPos << 0, 0;
|
||||||
|
mAutoScrollResetAccumulator = 0;
|
||||||
|
mAutoScrollAccumulator = -mAutoScrollDelay + mAutoScrollSpeed;
|
||||||
|
mAtEnd = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,10 +7,10 @@ class ScrollableContainer : public GuiComponent
|
||||||
public:
|
public:
|
||||||
ScrollableContainer(Window* window);
|
ScrollableContainer(Window* window);
|
||||||
|
|
||||||
Eigen::Vector2d getScrollPos() const;
|
Eigen::Vector2f getScrollPos() const;
|
||||||
void setScrollPos(const Eigen::Vector2d& pos);
|
void setScrollPos(const Eigen::Vector2f& pos);
|
||||||
void setAutoScroll(int delay, double speed); //Use 0 for speed to disable.
|
void setAutoScroll(bool autoScroll);
|
||||||
void resetAutoScrollTimer();
|
void reset();
|
||||||
|
|
||||||
void update(int deltaTime) override;
|
void update(int deltaTime) override;
|
||||||
void render(const Eigen::Affine3f& parentTrans) override;
|
void render(const Eigen::Affine3f& parentTrans) override;
|
||||||
|
@ -18,9 +18,11 @@ public:
|
||||||
private:
|
private:
|
||||||
Eigen::Vector2f getContentSize();
|
Eigen::Vector2f getContentSize();
|
||||||
|
|
||||||
Eigen::Vector2d mScrollPos;
|
Eigen::Vector2f mScrollPos;
|
||||||
Eigen::Vector2d mScrollDir;
|
Eigen::Vector2f mScrollDir;
|
||||||
int mAutoScrollDelay;
|
int mAutoScrollDelay; // ms to wait before starting to autoscroll
|
||||||
double mAutoScrollSpeed;
|
int mAutoScrollSpeed; // ms to wait before scrolling down by mScrollDir
|
||||||
int mAutoScrollTimer;
|
int mAutoScrollAccumulator;
|
||||||
|
bool mAtEnd;
|
||||||
|
int mAutoScrollResetAccumulator;
|
||||||
};
|
};
|
||||||
|
|
|
@ -58,7 +58,7 @@ DetailedGameListView::DetailedGameListView(Window* window, FileData* root) :
|
||||||
|
|
||||||
mDescContainer.setPosition(mSize.x() * padding, mSize.y() * 0.65f);
|
mDescContainer.setPosition(mSize.x() * padding, mSize.y() * 0.65f);
|
||||||
mDescContainer.setSize(mSize.x() * (0.50f - 2*padding), mSize.y() - mDescContainer.getPosition().y());
|
mDescContainer.setSize(mSize.x() * (0.50f - 2*padding), mSize.y() - mDescContainer.getPosition().y());
|
||||||
mDescContainer.setAutoScroll((int)(1600 + mDescContainer.getSize().x()), 0.025f);
|
mDescContainer.setAutoScroll(true);
|
||||||
addChild(&mDescContainer);
|
addChild(&mDescContainer);
|
||||||
|
|
||||||
mDescription.setFont(Font::get(FONT_SIZE_SMALL));
|
mDescription.setFont(Font::get(FONT_SIZE_SMALL));
|
||||||
|
@ -199,8 +199,7 @@ void DetailedGameListView::updateInfoPanel()
|
||||||
mPlayCount.setValue(file->metadata.get("playcount"));
|
mPlayCount.setValue(file->metadata.get("playcount"));
|
||||||
|
|
||||||
mDescription.setText(file->metadata.get("desc"));
|
mDescription.setText(file->metadata.get("desc"));
|
||||||
mDescContainer.resetAutoScrollTimer();
|
mDescContainer.reset();
|
||||||
mDescContainer.setScrollPos(Eigen::Vector2d(0, 0));
|
|
||||||
fadingOut = false;
|
fadingOut = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue