2020-09-17 20:00:07 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-06-06 14:48:05 +00:00
|
|
|
//
|
2020-09-17 20:00:07 +00:00
|
|
|
// EmulationStation Desktop Edition
|
2020-06-28 16:39:18 +00:00
|
|
|
// TextListComponent.h
|
2020-06-06 14:48:05 +00:00
|
|
|
//
|
2021-01-12 21:41:28 +00:00
|
|
|
// Text list used for displaying and navigating the gamelist views.
|
2020-06-06 14:48:05 +00:00
|
|
|
//
|
|
|
|
|
2017-10-31 17:12:50 +00:00
|
|
|
#ifndef ES_APP_COMPONENTS_TEXT_LIST_COMPONENT_H
|
|
|
|
#define ES_APP_COMPONENTS_TEXT_LIST_COMPONENT_H
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
#include "Log.h"
|
|
|
|
#include "Sound.h"
|
2014-06-25 16:29:58 +00:00
|
|
|
#include "components/IList.h"
|
2017-11-06 11:05:57 +00:00
|
|
|
#include "math/Misc.h"
|
2021-01-12 21:41:28 +00:00
|
|
|
#include "resources/Font.h"
|
2018-01-27 17:04:28 +00:00
|
|
|
#include "utils/StringUtil.h"
|
2020-09-17 20:00:07 +00:00
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
#include <memory>
|
2017-11-01 22:21:10 +00:00
|
|
|
|
|
|
|
class TextCache;
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-06-06 14:48:05 +00:00
|
|
|
struct TextListData {
|
2020-06-28 16:39:18 +00:00
|
|
|
unsigned int colorId;
|
|
|
|
std::shared_ptr<TextCache> textCache;
|
2014-06-25 16:29:58 +00:00
|
|
|
};
|
|
|
|
|
2020-06-06 14:48:05 +00:00
|
|
|
// A graphical list. Supports multiple colors for rows and scrolling.
|
2021-07-07 18:31:46 +00:00
|
|
|
template <typename T> class TextListComponent : public IList<TextListData, T>
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
|
|
|
protected:
|
2020-06-28 16:39:18 +00:00
|
|
|
using IList<TextListData, T>::mEntries;
|
|
|
|
using IList<TextListData, T>::listUpdate;
|
|
|
|
using IList<TextListData, T>::listInput;
|
|
|
|
using IList<TextListData, T>::listRenderTitleOverlay;
|
|
|
|
using IList<TextListData, T>::getTransform;
|
|
|
|
using IList<TextListData, T>::mSize;
|
|
|
|
using IList<TextListData, T>::mCursor;
|
2020-09-17 20:00:07 +00:00
|
|
|
using IList<TextListData, T>::mWindow;
|
2020-06-28 16:39:18 +00:00
|
|
|
using IList<TextListData, T>::IList;
|
2014-06-25 16:29:58 +00:00
|
|
|
|
|
|
|
public:
|
2020-06-28 16:39:18 +00:00
|
|
|
using IList<TextListData, T>::size;
|
|
|
|
using IList<TextListData, T>::isScrolling;
|
|
|
|
using IList<TextListData, T>::stopScrolling;
|
|
|
|
|
|
|
|
TextListComponent(Window* window);
|
|
|
|
|
|
|
|
bool input(InputConfig* config, Input input) override;
|
|
|
|
void update(int deltaTime) override;
|
2021-08-15 17:30:31 +00:00
|
|
|
void render(const glm::mat4& parentTrans) override;
|
2021-07-07 18:31:46 +00:00
|
|
|
void applyTheme(const std::shared_ptr<ThemeData>& theme,
|
|
|
|
const std::string& view,
|
|
|
|
const std::string& element,
|
|
|
|
unsigned int properties) override;
|
2020-06-28 16:39:18 +00:00
|
|
|
|
|
|
|
void add(const std::string& name, const T& obj, unsigned int colorId);
|
|
|
|
|
|
|
|
enum Alignment {
|
2021-07-07 18:31:46 +00:00
|
|
|
ALIGN_LEFT, // Replace with AllowShortEnumsOnASingleLine: false (clang-format >=11.0).
|
2020-06-28 16:39:18 +00:00
|
|
|
ALIGN_CENTER,
|
|
|
|
ALIGN_RIGHT
|
|
|
|
};
|
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
void setAlignment(Alignment align) { mAlignment = align; }
|
2020-06-28 16:39:18 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
void setCursorChangedCallback(const std::function<void(CursorState state)>& func)
|
|
|
|
{
|
|
|
|
mCursorChangedCallback = func;
|
|
|
|
}
|
2020-06-28 16:39:18 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
void setFont(const std::shared_ptr<Font>& font)
|
2020-06-28 16:39:18 +00:00
|
|
|
{
|
|
|
|
mFont = font;
|
|
|
|
for (auto it = mEntries.begin(); it != mEntries.end(); it++)
|
|
|
|
it->data.textCache.reset();
|
|
|
|
}
|
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
void setUppercase(bool /*uppercase*/)
|
2020-06-28 16:39:18 +00:00
|
|
|
{
|
|
|
|
mUppercase = true;
|
|
|
|
for (auto it = mEntries.begin(); it != mEntries.end(); it++)
|
|
|
|
it->data.textCache.reset();
|
|
|
|
}
|
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
void setSelectorHeight(float selectorScale) { mSelectorHeight = selectorScale; }
|
|
|
|
void setSelectorOffsetY(float selectorOffsetY) { mSelectorOffsetY = selectorOffsetY; }
|
|
|
|
void setSelectorColor(unsigned int color) { mSelectorColor = color; }
|
|
|
|
void setSelectorColorEnd(unsigned int color) { mSelectorColorEnd = color; }
|
|
|
|
void setSelectorColorGradientHorizontal(bool horizontal)
|
|
|
|
{
|
|
|
|
mSelectorColorGradientHorizontal = horizontal;
|
|
|
|
}
|
|
|
|
void setSelectedColor(unsigned int color) { mSelectedColor = color; }
|
|
|
|
void setColor(unsigned int id, unsigned int color) { mColors[id] = color; }
|
|
|
|
void setLineSpacing(float lineSpacing) { mLineSpacing = lineSpacing; }
|
2014-06-25 16:29:58 +00:00
|
|
|
|
|
|
|
protected:
|
2021-01-12 21:41:28 +00:00
|
|
|
virtual void onScroll() override
|
|
|
|
{
|
|
|
|
if (!NavigationSounds::getInstance()->isPlayingThemeNavigationSound(SCROLLSOUND))
|
|
|
|
NavigationSounds::getInstance()->playThemeNavigationSound(SCROLLSOUND);
|
|
|
|
}
|
2020-06-28 16:39:18 +00:00
|
|
|
virtual void onCursorChanged(const CursorState& state) override;
|
2014-06-25 16:29:58 +00:00
|
|
|
|
|
|
|
private:
|
2020-06-28 16:39:18 +00:00
|
|
|
int mMarqueeOffset;
|
|
|
|
int mMarqueeOffset2;
|
|
|
|
int mMarqueeTime;
|
2021-06-28 18:45:52 +00:00
|
|
|
bool mMarqueeScroll;
|
2020-06-28 16:39:18 +00:00
|
|
|
|
|
|
|
Alignment mAlignment;
|
|
|
|
float mHorizontalMargin;
|
|
|
|
|
|
|
|
std::function<void(CursorState state)> mCursorChangedCallback;
|
|
|
|
|
|
|
|
std::shared_ptr<Font> mFont;
|
|
|
|
bool mUppercase;
|
|
|
|
float mLineSpacing;
|
|
|
|
float mSelectorHeight;
|
|
|
|
float mSelectorOffsetY;
|
|
|
|
unsigned int mSelectorColor;
|
|
|
|
unsigned int mSelectorColorEnd;
|
|
|
|
bool mSelectorColorGradientHorizontal = true;
|
|
|
|
unsigned int mSelectedColor;
|
|
|
|
static const unsigned int COLOR_ID_COUNT = 2;
|
|
|
|
unsigned int mColors[COLOR_ID_COUNT];
|
|
|
|
|
|
|
|
ImageComponent mSelectorImage;
|
2014-06-25 16:29:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
2021-07-07 18:31:46 +00:00
|
|
|
TextListComponent<T>::TextListComponent(Window* window)
|
|
|
|
: IList<TextListData, T>(window)
|
|
|
|
, mSelectorImage(window)
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2020-06-28 16:39:18 +00:00
|
|
|
mMarqueeOffset = 0;
|
|
|
|
mMarqueeOffset2 = 0;
|
|
|
|
mMarqueeTime = 0;
|
2021-06-28 18:45:52 +00:00
|
|
|
mMarqueeScroll = false;
|
2020-06-28 16:39:18 +00:00
|
|
|
|
2021-06-28 18:45:52 +00:00
|
|
|
mHorizontalMargin = 0.0f;
|
2020-06-28 16:39:18 +00:00
|
|
|
mAlignment = ALIGN_CENTER;
|
|
|
|
|
|
|
|
mFont = Font::get(FONT_SIZE_MEDIUM);
|
|
|
|
mUppercase = false;
|
|
|
|
mLineSpacing = 1.5f;
|
|
|
|
mSelectorHeight = mFont->getSize() * 1.5f;
|
|
|
|
mSelectorOffsetY = 0;
|
|
|
|
mSelectorColor = 0x000000FF;
|
|
|
|
mSelectorColorEnd = 0x000000FF;
|
|
|
|
mSelectorColorGradientHorizontal = true;
|
|
|
|
mSelectedColor = 0;
|
|
|
|
mColors[0] = 0x0000FFFF;
|
|
|
|
mColors[1] = 0x00FF00FF;
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 17:30:31 +00:00
|
|
|
template <typename T> void TextListComponent<T>::render(const glm::mat4& parentTrans)
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2021-06-28 18:45:52 +00:00
|
|
|
if (size() == 0)
|
|
|
|
return;
|
2020-06-28 16:39:18 +00:00
|
|
|
|
2021-08-15 17:30:31 +00:00
|
|
|
glm::mat4 trans = parentTrans * getTransform();
|
2020-06-28 16:39:18 +00:00
|
|
|
std::shared_ptr<Font>& font = mFont;
|
|
|
|
|
2021-06-28 18:45:52 +00:00
|
|
|
int startEntry = 0;
|
|
|
|
float y = 0;
|
2020-06-28 16:39:18 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
const float entrySize =
|
|
|
|
std::max(font->getHeight(1.0), static_cast<float>(font->getSize())) * mLineSpacing;
|
2020-06-28 16:39:18 +00:00
|
|
|
|
2020-08-06 14:48:32 +00:00
|
|
|
// Number of entries that can fit on the screen simultaneously.
|
2021-08-16 16:25:01 +00:00
|
|
|
int screenCount = static_cast<int>(mSize.y / entrySize + 0.5f);
|
2020-06-28 16:39:18 +00:00
|
|
|
|
2020-08-02 09:45:59 +00:00
|
|
|
if (size() >= screenCount) {
|
2021-07-07 18:31:46 +00:00
|
|
|
startEntry = mCursor - screenCount / 2;
|
2020-06-28 16:39:18 +00:00
|
|
|
if (startEntry < 0)
|
|
|
|
startEntry = 0;
|
|
|
|
if (startEntry >= size() - screenCount)
|
|
|
|
startEntry = size() - screenCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
int listCutoff = startEntry + screenCount;
|
|
|
|
if (listCutoff > size())
|
|
|
|
listCutoff = size();
|
|
|
|
|
|
|
|
// Draw selector bar.
|
|
|
|
if (startEntry < listCutoff) {
|
|
|
|
if (mSelectorImage.hasImage()) {
|
2021-07-07 18:31:46 +00:00
|
|
|
mSelectorImage.setPosition(0.0f, (mCursor - startEntry) * entrySize + mSelectorOffsetY,
|
|
|
|
0.0f);
|
2020-06-28 16:39:18 +00:00
|
|
|
mSelectorImage.render(trans);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Renderer::setMatrix(trans);
|
2021-08-16 16:25:01 +00:00
|
|
|
Renderer::drawRect(0.0f, (mCursor - startEntry) * entrySize + mSelectorOffsetY, mSize.x,
|
|
|
|
mSelectorHeight, mSelectorColor, mSelectorColorEnd,
|
2021-07-07 18:31:46 +00:00
|
|
|
mSelectorColorGradientHorizontal);
|
2020-06-28 16:39:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-22 17:07:15 +00:00
|
|
|
if (Settings::getInstance()->getBool("DebugText")) {
|
2021-08-16 16:25:01 +00:00
|
|
|
Renderer::drawRect(mHorizontalMargin, 0.0f, mSize.x - mHorizontalMargin * 2.0f, mSize.y,
|
2021-07-07 18:31:46 +00:00
|
|
|
0x00000033, 0x00000033);
|
2021-08-16 16:25:01 +00:00
|
|
|
Renderer::drawRect(0.0f, 0.0f, mSize.x, mSize.y, 0x0000FF33, 0x0000FF33);
|
2021-03-22 17:07:15 +00:00
|
|
|
}
|
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
// Clip to inside margins.
|
2021-08-16 16:25:01 +00:00
|
|
|
glm::vec3 dim(mSize.x, mSize.y, 0.0f);
|
2021-08-15 17:30:31 +00:00
|
|
|
dim.x = (trans[0].x * dim.x + trans[3].x) - trans[3].x;
|
|
|
|
dim.y = (trans[1].y * dim.y + trans[3].y) - trans[3].y;
|
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
Renderer::pushClipRect(
|
2021-08-15 17:30:31 +00:00
|
|
|
Vector2i(static_cast<int>(trans[3].x + mHorizontalMargin), static_cast<int>(trans[3].y)),
|
|
|
|
Vector2i(static_cast<int>(dim.x - mHorizontalMargin * 2.0f), static_cast<int>(dim.y)));
|
2020-06-28 16:39:18 +00:00
|
|
|
|
|
|
|
for (int i = startEntry; i < listCutoff; i++) {
|
2020-09-17 20:00:07 +00:00
|
|
|
typename IList<TextListData, T>::Entry& entry = mEntries.at(static_cast<unsigned int>(i));
|
2020-06-28 16:39:18 +00:00
|
|
|
|
|
|
|
unsigned int color;
|
|
|
|
if (mCursor == i && mSelectedColor)
|
|
|
|
color = mSelectedColor;
|
|
|
|
else
|
|
|
|
color = mColors[entry.data.colorId];
|
|
|
|
|
|
|
|
if (!entry.data.textCache)
|
2021-07-07 18:31:46 +00:00
|
|
|
entry.data.textCache = std::unique_ptr<TextCache>(font->buildTextCache(
|
|
|
|
mUppercase ? Utils::String::toUpper(entry.name) : entry.name, 0, 0, 0x000000FF));
|
2020-06-28 16:39:18 +00:00
|
|
|
|
2020-09-17 20:00:07 +00:00
|
|
|
// If a game is marked as hidden, lower the text opacity a lot.
|
|
|
|
// If a game is marked to not be counted, lower the opacity a moderate amount.
|
2020-08-06 14:48:32 +00:00
|
|
|
if (entry.object->getHidden())
|
2020-08-06 16:16:31 +00:00
|
|
|
entry.data.textCache->setColor(color & 0xFFFFFF44);
|
2020-08-06 14:48:32 +00:00
|
|
|
else if (!entry.object->getCountAsGame())
|
|
|
|
entry.data.textCache->setColor(color & 0xFFFFFF77);
|
|
|
|
else
|
|
|
|
entry.data.textCache->setColor(color);
|
2020-06-28 16:39:18 +00:00
|
|
|
|
2021-08-15 17:30:31 +00:00
|
|
|
glm::vec3 offset(0.0f, y, 0.0f);
|
2020-06-28 16:39:18 +00:00
|
|
|
|
|
|
|
switch (mAlignment) {
|
2021-07-07 18:31:46 +00:00
|
|
|
case ALIGN_LEFT:
|
2021-08-15 17:30:31 +00:00
|
|
|
offset.x = mHorizontalMargin;
|
2021-07-07 18:31:46 +00:00
|
|
|
break;
|
|
|
|
case ALIGN_CENTER:
|
2021-08-15 17:30:31 +00:00
|
|
|
offset.x =
|
2021-08-16 16:25:01 +00:00
|
|
|
static_cast<float>((mSize.x - entry.data.textCache->metrics.size.x) / 2.0f);
|
2021-08-15 17:30:31 +00:00
|
|
|
if (offset.x < mHorizontalMargin)
|
|
|
|
offset.x = mHorizontalMargin;
|
2021-07-07 18:31:46 +00:00
|
|
|
break;
|
|
|
|
case ALIGN_RIGHT:
|
2021-08-16 16:25:01 +00:00
|
|
|
offset.x = (mSize.x - entry.data.textCache->metrics.size.x);
|
2021-08-15 17:30:31 +00:00
|
|
|
offset.x -= mHorizontalMargin;
|
|
|
|
if (offset.x < mHorizontalMargin)
|
|
|
|
offset.x = mHorizontalMargin;
|
2021-07-07 18:31:46 +00:00
|
|
|
break;
|
2020-06-28 16:39:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Render text.
|
2021-08-15 17:30:31 +00:00
|
|
|
glm::mat4 drawTrans = trans;
|
2020-06-28 16:39:18 +00:00
|
|
|
|
|
|
|
// Currently selected item text might be scrolling.
|
2021-06-28 18:45:52 +00:00
|
|
|
if (mCursor == i && mMarqueeOffset > 0)
|
2021-08-15 17:30:31 +00:00
|
|
|
drawTrans = glm::translate(
|
|
|
|
drawTrans, offset - glm::vec3(static_cast<float>(mMarqueeOffset), 0.0f, 0.0f));
|
2020-06-28 16:39:18 +00:00
|
|
|
else
|
2021-08-15 17:30:31 +00:00
|
|
|
drawTrans = glm::translate(drawTrans, offset);
|
2020-06-28 16:39:18 +00:00
|
|
|
|
2021-06-28 18:45:52 +00:00
|
|
|
// Needed to avoid flickering when returning to the start position.
|
|
|
|
if (mMarqueeOffset == 0 && mMarqueeOffset2 == 0)
|
|
|
|
mMarqueeScroll = false;
|
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
Renderer::setMatrix(drawTrans);
|
|
|
|
font->renderTextCache(entry.data.textCache.get());
|
|
|
|
|
2021-06-28 18:45:52 +00:00
|
|
|
// Render currently selected row again if marquee is scrolled far enough for it to repeat.
|
|
|
|
if ((mCursor == i && mMarqueeOffset2 < 0) || (mCursor == i && mMarqueeScroll)) {
|
|
|
|
mMarqueeScroll = true;
|
2020-06-28 16:39:18 +00:00
|
|
|
drawTrans = trans;
|
2021-08-15 17:30:31 +00:00
|
|
|
drawTrans = glm::translate(
|
|
|
|
drawTrans, offset - glm::vec3(static_cast<float>(mMarqueeOffset2), 0.0f, 0.0f));
|
2020-06-28 16:39:18 +00:00
|
|
|
Renderer::setMatrix(drawTrans);
|
|
|
|
font->renderTextCache(entry.data.textCache.get());
|
|
|
|
}
|
|
|
|
y += entrySize;
|
|
|
|
}
|
|
|
|
Renderer::popClipRect();
|
|
|
|
listRenderTitleOverlay(trans);
|
|
|
|
GuiComponent::renderChildren(trans);
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
template <typename T> bool TextListComponent<T>::input(InputConfig* config, Input input)
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2020-06-28 16:39:18 +00:00
|
|
|
if (size() > 0) {
|
|
|
|
if (input.value != 0) {
|
|
|
|
if (config->isMappedLike("down", input)) {
|
|
|
|
listInput(1);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config->isMappedLike("up", input)) {
|
|
|
|
listInput(-1);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (config->isMappedLike("rightshoulder", input)) {
|
|
|
|
listInput(10);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config->isMappedLike("leftshoulder", input)) {
|
|
|
|
listInput(-10);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config->isMappedLike("righttrigger", input)) {
|
|
|
|
return this->listLastRow();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config->isMappedLike("lefttrigger", input)) {
|
|
|
|
return this->listFirstRow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2021-07-07 18:31:46 +00:00
|
|
|
if (config->isMappedLike("down", input) || config->isMappedLike("up", input) ||
|
|
|
|
config->isMappedLike("rightshoulder", input) ||
|
|
|
|
config->isMappedLike("leftshoulder", input) ||
|
|
|
|
config->isMappedLike("lefttrigger", input) ||
|
|
|
|
config->isMappedLike("righttrigger", input))
|
2020-06-28 16:39:18 +00:00
|
|
|
stopScrolling();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return GuiComponent::input(config, input);
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
template <typename T> void TextListComponent<T>::update(int deltaTime)
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2020-06-28 16:39:18 +00:00
|
|
|
listUpdate(deltaTime);
|
|
|
|
|
2020-11-10 21:18:20 +00:00
|
|
|
if (mWindow->isScreensaverActive() || !mWindow->getAllowTextScrolling())
|
2020-09-17 20:00:07 +00:00
|
|
|
stopScrolling();
|
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
if (!isScrolling() && size() > 0) {
|
|
|
|
// Always reset the marquee offsets.
|
2021-06-28 18:45:52 +00:00
|
|
|
mMarqueeOffset = 0;
|
2020-06-28 16:39:18 +00:00
|
|
|
mMarqueeOffset2 = 0;
|
|
|
|
|
2021-06-28 18:45:52 +00:00
|
|
|
// If we're not scrolling and this object's text exceeds our size, then marquee it.
|
2021-07-07 18:31:46 +00:00
|
|
|
const float textLength = mFont
|
|
|
|
->sizeText(Utils::String::toUpper(
|
|
|
|
mEntries.at(static_cast<unsigned int>(mCursor)).name))
|
2021-08-16 16:25:01 +00:00
|
|
|
.x;
|
|
|
|
const float limit = mSize.x - mHorizontalMargin * 2.0f;
|
2020-06-28 16:39:18 +00:00
|
|
|
|
|
|
|
if (textLength > limit) {
|
|
|
|
// Loop.
|
|
|
|
// Pixels per second (based on nes-mini font at 1920x1080 to produce a speed of 200).
|
2021-08-16 16:25:01 +00:00
|
|
|
const float speed = mFont->sizeText("ABCDEFGHIJKLMNOPQRSTUVWXYZ").x * 0.247f;
|
2021-06-28 18:45:52 +00:00
|
|
|
const float delay = 3000.0f;
|
2020-06-28 16:39:18 +00:00
|
|
|
const float scrollLength = textLength;
|
|
|
|
const float returnLength = speed * 1.5f;
|
2021-06-28 18:45:52 +00:00
|
|
|
const float scrollTime = (scrollLength * 1000.0f) / speed;
|
|
|
|
const float returnTime = (returnLength * 1000.0f) / speed;
|
2020-09-17 20:00:07 +00:00
|
|
|
const int maxTime = static_cast<int>(delay + scrollTime + returnTime);
|
2020-06-28 16:39:18 +00:00
|
|
|
|
|
|
|
mMarqueeTime += deltaTime;
|
|
|
|
while (mMarqueeTime > maxTime)
|
|
|
|
mMarqueeTime -= maxTime;
|
|
|
|
|
2020-09-17 20:00:07 +00:00
|
|
|
mMarqueeOffset = static_cast<int>(Math::Scroll::loop(delay, scrollTime + returnTime,
|
2021-07-07 18:31:46 +00:00
|
|
|
static_cast<float>(mMarqueeTime),
|
|
|
|
scrollLength + returnLength));
|
2020-06-28 16:39:18 +00:00
|
|
|
|
|
|
|
if (mMarqueeOffset > (scrollLength - (limit - returnLength)))
|
2020-09-17 20:00:07 +00:00
|
|
|
mMarqueeOffset2 = static_cast<int>(mMarqueeOffset - (scrollLength + returnLength));
|
2020-06-28 16:39:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GuiComponent::update(deltaTime);
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2020-06-06 14:48:05 +00:00
|
|
|
// List management stuff.
|
2014-06-25 16:29:58 +00:00
|
|
|
template <typename T>
|
|
|
|
void TextListComponent<T>::add(const std::string& name, const T& obj, unsigned int color)
|
|
|
|
{
|
2020-06-28 16:39:18 +00:00
|
|
|
assert(color < COLOR_ID_COUNT);
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
typename IList<TextListData, T>::Entry entry;
|
|
|
|
entry.name = name;
|
|
|
|
entry.object = obj;
|
|
|
|
entry.data.colorId = color;
|
2020-08-30 20:25:38 +00:00
|
|
|
static_cast<IList<TextListData, T>*>(this)->add(entry);
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
template <typename T> void TextListComponent<T>::onCursorChanged(const CursorState& state)
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2020-06-28 16:39:18 +00:00
|
|
|
mMarqueeOffset = 0;
|
|
|
|
mMarqueeOffset2 = 0;
|
|
|
|
mMarqueeTime = 0;
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
if (mCursorChangedCallback)
|
|
|
|
mCursorChangedCallback(state);
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2020-06-06 14:48:05 +00:00
|
|
|
void TextListComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
|
2021-07-07 18:31:46 +00:00
|
|
|
const std::string& view,
|
|
|
|
const std::string& element,
|
|
|
|
unsigned int properties)
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2020-06-28 16:39:18 +00:00
|
|
|
GuiComponent::applyTheme(theme, view, element, properties);
|
|
|
|
|
|
|
|
const ThemeData::ThemeElement* elem = theme->getElement(view, element, "textlist");
|
|
|
|
if (!elem)
|
|
|
|
return;
|
|
|
|
|
|
|
|
using namespace ThemeFlags;
|
|
|
|
if (properties & COLOR) {
|
|
|
|
if (elem->has("selectorColor")) {
|
|
|
|
setSelectorColor(elem->get<unsigned int>("selectorColor"));
|
|
|
|
setSelectorColorEnd(elem->get<unsigned int>("selectorColor"));
|
|
|
|
}
|
|
|
|
if (elem->has("selectorColorEnd"))
|
|
|
|
setSelectorColorEnd(elem->get<unsigned int>("selectorColorEnd"));
|
|
|
|
if (elem->has("selectorGradientType"))
|
2021-07-07 18:31:46 +00:00
|
|
|
setSelectorColorGradientHorizontal(
|
|
|
|
!(elem->get<std::string>("selectorGradientType").compare("horizontal")));
|
2020-06-28 16:39:18 +00:00
|
|
|
if (elem->has("selectedColor"))
|
|
|
|
setSelectedColor(elem->get<unsigned int>("selectedColor"));
|
|
|
|
if (elem->has("primaryColor"))
|
|
|
|
setColor(0, elem->get<unsigned int>("primaryColor"));
|
|
|
|
if (elem->has("secondaryColor"))
|
|
|
|
setColor(1, elem->get<unsigned int>("secondaryColor"));
|
|
|
|
}
|
|
|
|
|
|
|
|
setFont(Font::getFromTheme(elem, properties, mFont));
|
2021-07-07 18:31:46 +00:00
|
|
|
const float selectorHeight =
|
|
|
|
std::max(mFont->getHeight(1.0), static_cast<float>(mFont->getSize())) * mLineSpacing;
|
2020-06-28 16:39:18 +00:00
|
|
|
setSelectorHeight(selectorHeight);
|
|
|
|
|
|
|
|
if (properties & ALIGNMENT) {
|
|
|
|
if (elem->has("alignment")) {
|
|
|
|
const std::string& str = elem->get<std::string>("alignment");
|
|
|
|
if (str == "left")
|
|
|
|
setAlignment(ALIGN_LEFT);
|
|
|
|
else if (str == "center")
|
|
|
|
setAlignment(ALIGN_CENTER);
|
|
|
|
else if (str == "right")
|
|
|
|
setAlignment(ALIGN_RIGHT);
|
|
|
|
else
|
|
|
|
LOG(LogError) << "Unknown TextListComponent alignment \"" << str << "\"!";
|
|
|
|
}
|
|
|
|
if (elem->has("horizontalMargin")) {
|
|
|
|
mHorizontalMargin = elem->get<float>("horizontalMargin") *
|
2021-08-16 16:25:01 +00:00
|
|
|
(this->mParent ? this->mParent->getSize().x :
|
2021-07-07 18:31:46 +00:00
|
|
|
static_cast<float>(Renderer::getScreenWidth()));
|
2020-06-28 16:39:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (properties & FORCE_UPPERCASE && elem->has("forceUppercase"))
|
|
|
|
setUppercase(elem->get<bool>("forceUppercase"));
|
|
|
|
|
|
|
|
if (properties & LINE_SPACING) {
|
|
|
|
if (elem->has("lineSpacing"))
|
|
|
|
setLineSpacing(elem->get<float>("lineSpacing"));
|
|
|
|
if (elem->has("selectorHeight"))
|
|
|
|
setSelectorHeight(elem->get<float>("selectorHeight") * Renderer::getScreenHeight());
|
|
|
|
if (elem->has("selectorOffsetY")) {
|
2021-08-16 16:25:01 +00:00
|
|
|
float scale = this->mParent ? this->mParent->getSize().y :
|
2021-07-07 18:31:46 +00:00
|
|
|
static_cast<float>(Renderer::getScreenHeight());
|
2020-06-28 16:39:18 +00:00
|
|
|
setSelectorOffsetY(elem->get<float>("selectorOffsetY") * scale);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
setSelectorOffsetY(0.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (elem->has("selectorImagePath")) {
|
|
|
|
std::string path = elem->get<std::string>("selectorImagePath");
|
|
|
|
bool tile = elem->has("selectorImageTile") && elem->get<bool>("selectorImageTile");
|
|
|
|
mSelectorImage.setImage(path, tile);
|
2021-08-16 16:25:01 +00:00
|
|
|
mSelectorImage.setSize(mSize.x, mSelectorHeight);
|
2020-06-28 16:39:18 +00:00
|
|
|
mSelectorImage.setColorShift(mSelectorColor);
|
|
|
|
mSelectorImage.setColorShiftEnd(mSelectorColorEnd);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mSelectorImage.setImage("");
|
|
|
|
}
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
2017-10-31 17:12:50 +00:00
|
|
|
|
|
|
|
#endif // ES_APP_COMPONENTS_TEXT_LIST_COMPONENT_H
|