Changed the 'marquee' variable names to 'loop' in TextListComponent.h

This commit is contained in:
Leon Styhre 2021-10-18 18:07:20 +02:00
parent 1166539466
commit 94c825e3a3

View file

@ -24,7 +24,7 @@ struct TextListData {
std::shared_ptr<TextCache> textCache; std::shared_ptr<TextCache> textCache;
}; };
// A graphical list. Supports multiple colors for rows and scrolling. // A scrollable text list supporting multiple row colors.
template <typename T> class TextListComponent : public IList<TextListData, T> template <typename T> class TextListComponent : public IList<TextListData, T>
{ {
protected: protected:
@ -108,10 +108,10 @@ protected:
virtual void onCursorChanged(const CursorState& state) override; virtual void onCursorChanged(const CursorState& state) override;
private: private:
int mMarqueeOffset; int mLoopOffset;
int mMarqueeOffset2; int mLoopOffset2;
int mMarqueeTime; int mLoopTime;
bool mMarqueeScroll; bool mLoopScroll;
Alignment mAlignment; Alignment mAlignment;
float mHorizontalMargin; float mHorizontalMargin;
@ -138,10 +138,10 @@ TextListComponent<T>::TextListComponent(Window* window)
: IList<TextListData, T>(window) : IList<TextListData, T>(window)
, mSelectorImage(window) , mSelectorImage(window)
{ {
mMarqueeOffset = 0; mLoopOffset = 0;
mMarqueeOffset2 = 0; mLoopOffset2 = 0;
mMarqueeTime = 0; mLoopTime = 0;
mMarqueeScroll = false; mLoopScroll = false;
mHorizontalMargin = 0.0f; mHorizontalMargin = 0.0f;
mAlignment = ALIGN_CENTER; mAlignment = ALIGN_CENTER;
@ -271,26 +271,26 @@ template <typename T> void TextListComponent<T>::render(const glm::mat4& parentT
// Render text. // Render text.
glm::mat4 drawTrans{trans}; glm::mat4 drawTrans{trans};
// Currently selected item text might be scrolling. // Currently selected item text might be looping.
if (mCursor == i && mMarqueeOffset > 0) if (mCursor == i && mLoopOffset > 0)
drawTrans = glm::translate( drawTrans = glm::translate(
drawTrans, offset - glm::vec3{static_cast<float>(mMarqueeOffset), 0.0f, 0.0f}); drawTrans, offset - glm::vec3{static_cast<float>(mLoopOffset), 0.0f, 0.0f});
else else
drawTrans = glm::translate(drawTrans, offset); drawTrans = glm::translate(drawTrans, offset);
// Needed to avoid flickering when returning to the start position. // Needed to avoid flickering when returning to the start position.
if (mMarqueeOffset == 0 && mMarqueeOffset2 == 0) if (mLoopOffset == 0 && mLoopOffset2 == 0)
mMarqueeScroll = false; mLoopScroll = false;
Renderer::setMatrix(drawTrans); Renderer::setMatrix(drawTrans);
font->renderTextCache(entry.data.textCache.get()); font->renderTextCache(entry.data.textCache.get());
// Render currently selected row again if marquee is scrolled far enough for it to repeat. // Render currently selected row again if text is moved far enough for it to repeat.
if ((mCursor == i && mMarqueeOffset2 < 0) || (mCursor == i && mMarqueeScroll)) { if ((mCursor == i && mLoopOffset2 < 0) || (mCursor == i && mLoopScroll)) {
mMarqueeScroll = true; mLoopScroll = true;
drawTrans = trans; drawTrans = trans;
drawTrans = glm::translate( drawTrans = glm::translate(
drawTrans, offset - glm::vec3{static_cast<float>(mMarqueeOffset2), 0.0f, 0.0f}); drawTrans, offset - glm::vec3{static_cast<float>(mLoopOffset2), 0.0f, 0.0f});
Renderer::setMatrix(drawTrans); Renderer::setMatrix(drawTrans);
font->renderTextCache(entry.data.textCache.get()); font->renderTextCache(entry.data.textCache.get());
} }
@ -353,11 +353,11 @@ template <typename T> void TextListComponent<T>::update(int deltaTime)
stopScrolling(); stopScrolling();
if (!isScrolling() && size() > 0) { if (!isScrolling() && size() > 0) {
// Always reset the marquee offsets. // Always reset the loop offsets.
mMarqueeOffset = 0; mLoopOffset = 0;
mMarqueeOffset2 = 0; mLoopOffset2 = 0;
// If we're not scrolling and this object's text exceeds our size, then marquee it. // If we're not scrolling and this object's text exceeds our size, then loop it.
const float textLength = mFont const float textLength = mFont
->sizeText(Utils::String::toUpper( ->sizeText(Utils::String::toUpper(
mEntries.at(static_cast<unsigned int>(mCursor)).name)) mEntries.at(static_cast<unsigned int>(mCursor)).name))
@ -374,16 +374,16 @@ template <typename T> void TextListComponent<T>::update(int deltaTime)
const float returnTime = (returnLength * 1000.0f) / speed; const float returnTime = (returnLength * 1000.0f) / speed;
const int maxTime = static_cast<int>(delay + scrollTime + returnTime); const int maxTime = static_cast<int>(delay + scrollTime + returnTime);
mMarqueeTime += deltaTime; mLoopTime += deltaTime;
while (mMarqueeTime > maxTime) while (mLoopTime > maxTime)
mMarqueeTime -= maxTime; mLoopTime -= maxTime;
mMarqueeOffset = static_cast<int>(Utils::Math::loop(delay, scrollTime + returnTime, mLoopOffset = static_cast<int>(Utils::Math::loop(delay, scrollTime + returnTime,
static_cast<float>(mMarqueeTime), static_cast<float>(mLoopTime),
scrollLength + returnLength)); scrollLength + returnLength));
if (mMarqueeOffset > (scrollLength - (limit - returnLength))) if (mLoopOffset > (scrollLength - (limit - returnLength)))
mMarqueeOffset2 = static_cast<int>(mMarqueeOffset - (scrollLength + returnLength)); mLoopOffset2 = static_cast<int>(mLoopOffset - (scrollLength + returnLength));
} }
} }
@ -405,9 +405,9 @@ void TextListComponent<T>::add(const std::string& name, const T& obj, unsigned i
template <typename T> void TextListComponent<T>::onCursorChanged(const CursorState& state) template <typename T> void TextListComponent<T>::onCursorChanged(const CursorState& state)
{ {
mMarqueeOffset = 0; mLoopOffset = 0;
mMarqueeOffset2 = 0; mLoopOffset2 = 0;
mMarqueeTime = 0; mLoopTime = 0;
if (mCursorChangedCallback) if (mCursorChangedCallback)
mCursorChangedCallback(state); mCursorChangedCallback(state);