Commit 0d39586c authored by Aloshi's avatar Aloshi

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.
parent 75e31d91
......@@ -38,7 +38,7 @@ ScraperSearchComponent::ScraperSearchComponent(Window* window, SearchType type)
mDescContainer = std::make_shared<ScrollableContainer>(mWindow);
mResultDesc = std::make_shared<TextComponent>(mWindow, "Result desc", Font::get(FONT_SIZE_SMALL), 0x777777FF);
mDescContainer->addChild(mResultDesc.get());
mDescContainer->setAutoScroll(2200, 0.015f);
mDescContainer->setAutoScroll(true);
// metadata
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);
mResultName->setText(strToUpper(res.mdl.get("name")));
mResultDesc->setText(strToUpper(res.mdl.get("desc")));
mDescContainer->setScrollPos(Eigen::Vector2d(0, 0));
mDescContainer->resetAutoScrollTimer();
mDescContainer->reset();
mResultThumbnail->setImage("");
const std::string& thumb = res.thumbnailUrl.empty() ? res.imageUrl : res.thumbnailUrl;
......
......@@ -2,8 +2,12 @@
#include "../Renderer.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),
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);
trans.translate(Eigen::Vector3f((float)-mScrollPos.x(), (float)-mScrollPos.y(), 0));
trans.translate(-Eigen::Vector3f(mScrollPos.x(), mScrollPos.y(), 0));
Renderer::setMatrix(trans);
GuiComponent::renderChildren(trans);
......@@ -26,65 +30,75 @@ void ScrollableContainer::render(const Eigen::Affine3f& parentTrans)
Renderer::popClipRect();
}
void ScrollableContainer::setAutoScroll(int delay, double speed)
void ScrollableContainer::setAutoScroll(bool autoScroll)
{
mAutoScrollDelay = delay;
mAutoScrollSpeed = speed;
mAutoScrollTimer = 0;
if(autoScroll)
{
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;
}
void ScrollableContainer::setScrollPos(const Eigen::Vector2d& pos)
void ScrollableContainer::setScrollPos(const Eigen::Vector2f& pos)
{
mScrollPos = pos;
}
void ScrollableContainer::update(int deltaTime)
{
double scrollAmt = (double)deltaTime;
if(mAutoScrollSpeed != 0)
{
mAutoScrollTimer += deltaTime;
mAutoScrollAccumulator += deltaTime;
scrollAmt = (float)(mAutoScrollTimer - mAutoScrollDelay);
if(scrollAmt > 0)
//scale speed by our width! more text per line = slower scrolling
const float widthMod = (680.0f / getSize().x());
while(mAutoScrollAccumulator >= mAutoScrollSpeed)
{
//scroll the amount of time left over from the delay
mAutoScrollTimer = mAutoScrollDelay;
//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;
mScrollPos += mScrollDir;
mAutoScrollAccumulator -= mAutoScrollSpeed;
}
}
Eigen::Vector2d scroll = mScrollDir * scrollAmt;
mScrollPos += scroll;
//clip scrolling within bounds
if(mScrollPos.x() < 0)
mScrollPos[0] = 0;
if(mScrollPos.y() < 0)
mScrollPos[1] = 0;
Eigen::Vector2f contentSize = getContentSize();
const Eigen::Vector2f contentSize = getContentSize();
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())
{
mScrollPos[1] = 0;
else if(mScrollPos.y() + getSize().y() > contentSize.y())
mScrollPos[1] = (double)contentSize.y() - getSize().y();
}else if(mScrollPos.y() + getSize().y() > contentSize.y())
{
mScrollPos[1] = contentSize.y() - getSize().y();
mAtEnd = true;
}
if(mAtEnd)
{
mAutoScrollResetAccumulator += deltaTime;
if(mAutoScrollResetAccumulator >= AUTO_SCROLL_RESET_DELAY)
reset();
}
GuiComponent::update(deltaTime);
}
......@@ -106,7 +120,10 @@ Eigen::Vector2f ScrollableContainer::getContentSize()
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:
ScrollableContainer(Window* window);
Eigen::Vector2d getScrollPos() const;
void setScrollPos(const Eigen::Vector2d& pos);
void setAutoScroll(int delay, double speed); //Use 0 for speed to disable.
void resetAutoScrollTimer();
Eigen::Vector2f getScrollPos() const;
void setScrollPos(const Eigen::Vector2f& pos);
void setAutoScroll(bool autoScroll);
void reset();
void update(int deltaTime) override;
void render(const Eigen::Affine3f& parentTrans) override;
......@@ -18,9 +18,11 @@ public:
private:
Eigen::Vector2f getContentSize();
Eigen::Vector2d mScrollPos;
Eigen::Vector2d mScrollDir;
int mAutoScrollDelay;
double mAutoScrollSpeed;
int mAutoScrollTimer;
Eigen::Vector2f mScrollPos;
Eigen::Vector2f mScrollDir;
int mAutoScrollDelay; // ms to wait before starting to autoscroll
int mAutoScrollSpeed; // ms to wait before scrolling down by mScrollDir
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.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);
mDescription.setFont(Font::get(FONT_SIZE_SMALL));
......@@ -199,8 +199,7 @@ void DetailedGameListView::updateInfoPanel()
mPlayCount.setValue(file->metadata.get("playcount"));
mDescription.setText(file->metadata.get("desc"));
mDescContainer.resetAutoScrollTimer();
mDescContainer.setScrollPos(Eigen::Vector2d(0, 0));
mDescContainer.reset();
fadingOut = false;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment