2020-06-06 14:48:05 +00:00
|
|
|
//
|
|
|
|
// TextListComponent.h
|
|
|
|
//
|
|
|
|
// Used for displaying and navigating the gamelists.
|
|
|
|
//
|
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
#pragma once
|
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
|
|
|
|
|
|
|
#include "components/IList.h"
|
2017-11-06 11:05:57 +00:00
|
|
|
#include "math/Misc.h"
|
2018-01-27 17:04:28 +00:00
|
|
|
#include "utils/StringUtil.h"
|
2014-06-25 16:29:58 +00:00
|
|
|
#include "Log.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "Sound.h"
|
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 {
|
2014-06-25 16:29:58 +00:00
|
|
|
unsigned int colorId;
|
|
|
|
std::shared_ptr<TextCache> textCache;
|
|
|
|
};
|
|
|
|
|
2020-06-06 14:48:05 +00:00
|
|
|
// A graphical list. Supports multiple colors for rows and scrolling.
|
2014-06-25 16:29:58 +00:00
|
|
|
template <typename T>
|
|
|
|
class TextListComponent : public IList<TextListData, T>
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
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-06-25 17:52:38 +00:00
|
|
|
// The following change is required for compilation with Clang.
|
|
|
|
// http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#2070
|
|
|
|
// using IList<TextListData, T>::Entry;
|
|
|
|
using IList<TextListData, T>::IList;
|
2014-06-25 16:29:58 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
using IList<TextListData, T>::size;
|
|
|
|
using IList<TextListData, T>::isScrolling;
|
|
|
|
using IList<TextListData, T>::stopScrolling;
|
|
|
|
|
|
|
|
TextListComponent(Window* window);
|
2019-08-25 15:23:02 +00:00
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
bool input(InputConfig* config, Input input) override;
|
|
|
|
void update(int deltaTime) override;
|
2017-10-28 20:24:35 +00:00
|
|
|
void render(const Transform4x4f& parentTrans) override;
|
2020-06-06 14:48:05 +00:00
|
|
|
void applyTheme(const std::shared_ptr<ThemeData>& theme, const std::string& view,
|
|
|
|
const std::string& element, unsigned int properties) override;
|
2014-06-25 16:29:58 +00:00
|
|
|
|
|
|
|
void add(const std::string& name, const T& obj, unsigned int colorId);
|
2019-08-25 15:23:02 +00:00
|
|
|
|
2020-06-06 14:48:05 +00:00
|
|
|
enum Alignment {
|
2014-06-25 16:29:58 +00:00
|
|
|
ALIGN_LEFT,
|
|
|
|
ALIGN_CENTER,
|
|
|
|
ALIGN_RIGHT
|
|
|
|
};
|
|
|
|
|
|
|
|
inline void setAlignment(Alignment align) { mAlignment = align; }
|
|
|
|
|
2020-06-06 14:48:05 +00:00
|
|
|
inline void setCursorChangedCallback(const std::function<void(CursorState state)>& func)
|
|
|
|
{ mCursorChangedCallback = func; }
|
2014-06-25 16:29:58 +00:00
|
|
|
|
|
|
|
inline void setFont(const std::shared_ptr<Font>& font)
|
|
|
|
{
|
|
|
|
mFont = font;
|
2020-06-06 14:48:05 +00:00
|
|
|
for (auto it = mEntries.begin(); it != mEntries.end(); it++)
|
2014-06-25 16:29:58 +00:00
|
|
|
it->data.textCache.reset();
|
|
|
|
}
|
|
|
|
|
2019-08-25 15:23:02 +00:00
|
|
|
inline void setUppercase(bool /*uppercase*/)
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
|
|
|
mUppercase = true;
|
2020-06-06 14:48:05 +00:00
|
|
|
for (auto it = mEntries.begin(); it != mEntries.end(); it++)
|
2014-06-25 16:29:58 +00:00
|
|
|
it->data.textCache.reset();
|
|
|
|
}
|
|
|
|
|
2017-05-29 01:08:07 +00:00
|
|
|
inline void setSelectorHeight(float selectorScale) { mSelectorHeight = selectorScale; }
|
|
|
|
inline void setSelectorOffsetY(float selectorOffsetY) { mSelectorOffsetY = selectorOffsetY; }
|
2014-06-25 16:29:58 +00:00
|
|
|
inline void setSelectorColor(unsigned int color) { mSelectorColor = color; }
|
2019-07-04 01:10:17 +00:00
|
|
|
inline void setSelectorColorEnd(unsigned int color) { mSelectorColorEnd = color; }
|
2020-06-06 14:48:05 +00:00
|
|
|
inline void setSelectorColorGradientHorizontal(bool horizontal)
|
|
|
|
{ mSelectorColorGradientHorizontal = horizontal; }
|
2014-06-25 16:29:58 +00:00
|
|
|
inline void setSelectedColor(unsigned int color) { mSelectedColor = color; }
|
|
|
|
inline void setColor(unsigned int id, unsigned int color) { mColors[id] = color; }
|
|
|
|
inline void setLineSpacing(float lineSpacing) { mLineSpacing = lineSpacing; }
|
|
|
|
|
|
|
|
protected:
|
2020-06-25 17:52:38 +00:00
|
|
|
virtual void onScroll() override {
|
2020-06-06 11:10:33 +00:00
|
|
|
NavigationSounds::getInstance()->playThemeNavigationSound(SCROLLSOUND); }
|
2020-06-25 17:52:38 +00:00
|
|
|
virtual void onCursorChanged(const CursorState& state) override;
|
2014-06-25 16:29:58 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
int mMarqueeOffset;
|
2017-11-06 11:05:57 +00:00
|
|
|
int mMarqueeOffset2;
|
2014-06-25 16:29:58 +00:00
|
|
|
int mMarqueeTime;
|
|
|
|
|
|
|
|
Alignment mAlignment;
|
|
|
|
float mHorizontalMargin;
|
|
|
|
|
|
|
|
std::function<void(CursorState state)> mCursorChangedCallback;
|
|
|
|
|
|
|
|
std::shared_ptr<Font> mFont;
|
|
|
|
bool mUppercase;
|
|
|
|
float mLineSpacing;
|
2017-05-29 01:08:07 +00:00
|
|
|
float mSelectorHeight;
|
|
|
|
float mSelectorOffsetY;
|
2014-06-25 16:29:58 +00:00
|
|
|
unsigned int mSelectorColor;
|
2019-07-04 01:10:17 +00:00
|
|
|
unsigned int mSelectorColorEnd;
|
|
|
|
bool mSelectorColorGradientHorizontal = true;
|
2014-06-25 16:29:58 +00:00
|
|
|
unsigned int mSelectedColor;
|
|
|
|
static const unsigned int COLOR_ID_COUNT = 2;
|
|
|
|
unsigned int mColors[COLOR_ID_COUNT];
|
2017-05-29 01:08:07 +00:00
|
|
|
|
|
|
|
ImageComponent mSelectorImage;
|
2014-06-25 16:29:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
2019-08-25 15:23:02 +00:00
|
|
|
TextListComponent<T>::TextListComponent(Window* window) :
|
2017-05-29 01:08:07 +00:00
|
|
|
IList<TextListData, T>(window), mSelectorImage(window)
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
|
|
|
mMarqueeOffset = 0;
|
2017-11-06 11:05:57 +00:00
|
|
|
mMarqueeOffset2 = 0;
|
|
|
|
mMarqueeTime = 0;
|
2014-06-25 16:29:58 +00:00
|
|
|
|
|
|
|
mHorizontalMargin = 0;
|
|
|
|
mAlignment = ALIGN_CENTER;
|
|
|
|
|
|
|
|
mFont = Font::get(FONT_SIZE_MEDIUM);
|
|
|
|
mUppercase = false;
|
|
|
|
mLineSpacing = 1.5f;
|
2017-05-29 01:08:07 +00:00
|
|
|
mSelectorHeight = mFont->getSize() * 1.5f;
|
|
|
|
mSelectorOffsetY = 0;
|
2014-06-25 16:29:58 +00:00
|
|
|
mSelectorColor = 0x000000FF;
|
2019-07-04 01:10:17 +00:00
|
|
|
mSelectorColorEnd = 0x000000FF;
|
|
|
|
mSelectorColorGradientHorizontal = true;
|
2014-06-25 16:29:58 +00:00
|
|
|
mSelectedColor = 0;
|
|
|
|
mColors[0] = 0x0000FFFF;
|
|
|
|
mColors[1] = 0x00FF00FF;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2017-10-28 20:24:35 +00:00
|
|
|
void TextListComponent<T>::render(const Transform4x4f& parentTrans)
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2017-10-28 20:24:35 +00:00
|
|
|
Transform4x4f trans = parentTrans * getTransform();
|
2019-08-25 15:23:02 +00:00
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
std::shared_ptr<Font>& font = mFont;
|
|
|
|
|
2020-06-06 14:48:05 +00:00
|
|
|
if (size() == 0)
|
2014-06-25 16:29:58 +00:00
|
|
|
return;
|
|
|
|
|
2017-11-13 22:16:38 +00:00
|
|
|
const float entrySize = Math::max(font->getHeight(1.0), (float)font->getSize()) * mLineSpacing;
|
2014-06-25 16:29:58 +00:00
|
|
|
|
|
|
|
int startEntry = 0;
|
|
|
|
|
2020-06-06 14:48:05 +00:00
|
|
|
// Number of entries that can fit on the screen simultaniously.
|
2014-06-25 16:29:58 +00:00
|
|
|
int screenCount = (int)(mSize.y() / entrySize + 0.5f);
|
2019-08-25 15:23:02 +00:00
|
|
|
|
2020-06-06 14:48:05 +00:00
|
|
|
if (size() >= screenCount)
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
|
|
|
startEntry = mCursor - screenCount/2;
|
2020-06-06 14:48:05 +00:00
|
|
|
if (startEntry < 0)
|
2014-06-25 16:29:58 +00:00
|
|
|
startEntry = 0;
|
2020-06-06 14:48:05 +00:00
|
|
|
if (startEntry >= size() - screenCount)
|
2014-06-25 16:29:58 +00:00
|
|
|
startEntry = size() - screenCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
float y = 0;
|
|
|
|
|
|
|
|
int listCutoff = startEntry + screenCount;
|
2020-06-06 14:48:05 +00:00
|
|
|
if (listCutoff > size())
|
2014-06-25 16:29:58 +00:00
|
|
|
listCutoff = size();
|
|
|
|
|
2020-06-06 14:48:05 +00:00
|
|
|
// Draw selector bar.
|
|
|
|
if (startEntry < listCutoff) {
|
2017-05-29 01:08:07 +00:00
|
|
|
if (mSelectorImage.hasImage()) {
|
2020-06-06 14:48:05 +00:00
|
|
|
mSelectorImage.setPosition(0.f,
|
|
|
|
(mCursor - startEntry)*entrySize + mSelectorOffsetY, 0.f);
|
2017-05-29 01:08:07 +00:00
|
|
|
mSelectorImage.render(trans);
|
2020-06-06 14:48:05 +00:00
|
|
|
}
|
|
|
|
else {
|
2017-05-29 01:08:07 +00:00
|
|
|
Renderer::setMatrix(trans);
|
2020-06-06 14:48:05 +00:00
|
|
|
Renderer::drawRect(
|
|
|
|
0.0f,
|
|
|
|
(mCursor - startEntry)*entrySize +
|
|
|
|
mSelectorOffsetY,
|
|
|
|
mSize.x(),
|
|
|
|
mSelectorHeight,
|
|
|
|
mSelectorColor,
|
|
|
|
mSelectorColorEnd,
|
|
|
|
mSelectorColorGradientHorizontal);
|
2017-05-29 01:08:07 +00:00
|
|
|
}
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2020-06-06 14:48:05 +00:00
|
|
|
// Clip to inside margins.
|
2017-10-28 20:24:35 +00:00
|
|
|
Vector3f dim(mSize.x(), mSize.y(), 0);
|
2014-06-25 16:29:58 +00:00
|
|
|
dim = trans * dim - trans.translation();
|
2020-06-06 14:48:05 +00:00
|
|
|
Renderer::pushClipRect(Vector2i((int)(trans.translation().x() + mHorizontalMargin),
|
|
|
|
(int)trans.translation().y()), Vector2i((int)(dim.x() - mHorizontalMargin*2),
|
|
|
|
(int)dim.y()));
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-06-06 14:48:05 +00:00
|
|
|
for (int i = startEntry; i < listCutoff; i++) {
|
2014-06-25 16:29:58 +00:00
|
|
|
typename IList<TextListData, T>::Entry& entry = mEntries.at((unsigned int)i);
|
|
|
|
|
|
|
|
unsigned int color;
|
2020-06-06 14:48:05 +00:00
|
|
|
if (mCursor == i && mSelectedColor)
|
2014-06-25 16:29:58 +00:00
|
|
|
color = mSelectedColor;
|
|
|
|
else
|
|
|
|
color = mColors[entry.data.colorId];
|
|
|
|
|
2020-06-06 14:48:05 +00:00
|
|
|
if (!entry.data.textCache)
|
|
|
|
entry.data.textCache = std::unique_ptr<TextCache>
|
|
|
|
(font->buildTextCache(mUppercase ?
|
|
|
|
Utils::String::toUpper(entry.name) : entry.name, 0, 0, 0x000000FF));
|
2014-06-25 16:29:58 +00:00
|
|
|
|
|
|
|
entry.data.textCache->setColor(color);
|
|
|
|
|
2017-10-28 20:24:35 +00:00
|
|
|
Vector3f offset(0, y, 0);
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-06-06 14:48:05 +00:00
|
|
|
switch (mAlignment) {
|
2014-06-25 16:29:58 +00:00
|
|
|
case ALIGN_LEFT:
|
|
|
|
offset[0] = mHorizontalMargin;
|
|
|
|
break;
|
|
|
|
case ALIGN_CENTER:
|
2019-03-03 19:13:10 +00:00
|
|
|
offset[0] = (int)((mSize.x() - entry.data.textCache->metrics.size.x()) / 2);
|
2020-06-06 14:48:05 +00:00
|
|
|
if (offset[0] < mHorizontalMargin)
|
2017-05-29 01:08:07 +00:00
|
|
|
offset[0] = mHorizontalMargin;
|
2014-06-25 16:29:58 +00:00
|
|
|
break;
|
|
|
|
case ALIGN_RIGHT:
|
|
|
|
offset[0] = (mSize.x() - entry.data.textCache->metrics.size.x());
|
|
|
|
offset[0] -= mHorizontalMargin;
|
2020-06-06 14:48:05 +00:00
|
|
|
if (offset[0] < mHorizontalMargin)
|
2017-05-29 01:08:07 +00:00
|
|
|
offset[0] = mHorizontalMargin;
|
2014-06-25 16:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-11-06 11:05:57 +00:00
|
|
|
|
2020-06-06 14:48:05 +00:00
|
|
|
// Render text.
|
2017-10-28 20:24:35 +00:00
|
|
|
Transform4x4f drawTrans = trans;
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-06-06 14:48:05 +00:00
|
|
|
// Currently selected item text might be scrolling.
|
|
|
|
if ((mCursor == i) && (mMarqueeOffset > 0))
|
2017-11-17 14:58:52 +00:00
|
|
|
drawTrans.translate(offset - Vector3f((float)mMarqueeOffset, 0, 0));
|
2017-11-06 11:05:57 +00:00
|
|
|
else
|
|
|
|
drawTrans.translate(offset);
|
|
|
|
|
|
|
|
Renderer::setMatrix(drawTrans);
|
2014-06-25 16:29:58 +00:00
|
|
|
font->renderTextCache(entry.data.textCache.get());
|
2017-11-06 11:05:57 +00:00
|
|
|
|
2020-06-06 14:48:05 +00:00
|
|
|
// Render currently selected item text again if marquee is
|
|
|
|
// scrolled far enough for it to repeat.
|
|
|
|
if ((mCursor == i) && (mMarqueeOffset2 < 0)) {
|
2017-11-06 11:05:57 +00:00
|
|
|
drawTrans = trans;
|
2017-11-17 14:58:52 +00:00
|
|
|
drawTrans.translate(offset - Vector3f((float)mMarqueeOffset2, 0, 0));
|
2017-11-06 11:05:57 +00:00
|
|
|
Renderer::setMatrix(drawTrans);
|
|
|
|
font->renderTextCache(entry.data.textCache.get());
|
|
|
|
}
|
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
y += entrySize;
|
|
|
|
}
|
|
|
|
|
|
|
|
Renderer::popClipRect();
|
|
|
|
listRenderTitleOverlay(trans);
|
|
|
|
GuiComponent::renderChildren(trans);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
bool TextListComponent<T>::input(InputConfig* config, Input input)
|
|
|
|
{
|
2020-06-06 14:48:05 +00:00
|
|
|
if (size() > 0) {
|
|
|
|
if (input.value != 0) {
|
|
|
|
if (config->isMappedLike("down", input)) {
|
2014-06-25 16:29:58 +00:00
|
|
|
listInput(1);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-06-06 14:48:05 +00:00
|
|
|
if (config->isMappedLike("up", input)) {
|
2014-06-25 16:29:58 +00:00
|
|
|
listInput(-1);
|
|
|
|
return true;
|
|
|
|
}
|
2020-06-06 14:48:05 +00:00
|
|
|
if (config->isMappedLike("rightshoulder", input)) {
|
2014-06-25 16:29:58 +00:00
|
|
|
listInput(10);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-06-06 14:48:05 +00:00
|
|
|
if (config->isMappedLike("leftshoulder", input)) {
|
2014-06-25 16:29:58 +00:00
|
|
|
listInput(-10);
|
|
|
|
return true;
|
|
|
|
}
|
2020-06-13 08:25:09 +00:00
|
|
|
|
|
|
|
if (config->isMappedLike("righttrigger", input)) {
|
|
|
|
return this->listLastRow();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config->isMappedLike("lefttrigger", input)) {
|
|
|
|
return this->listFirstRow();
|
|
|
|
}
|
2020-06-06 14:48:05 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (config->isMappedLike("down", input) ||
|
|
|
|
config->isMappedLike("up", input) ||
|
|
|
|
config->isMappedLike("rightshoulder", input) ||
|
2020-06-13 08:25:09 +00:00
|
|
|
config->isMappedLike("leftshoulder", input) ||
|
|
|
|
config->isMappedLike("lefttrigger", input) ||
|
|
|
|
config->isMappedLike("righttrigger", input))
|
2014-06-25 16:29:58 +00:00
|
|
|
stopScrolling();
|
|
|
|
}
|
|
|
|
}
|
2020-06-13 08:25:09 +00:00
|
|
|
// Explicitly stop the scrolling, otherwise it will go forever in case
|
|
|
|
// the menu was openened or another gamelist was selected using the
|
|
|
|
// quick system selector etc.
|
|
|
|
stopScrolling();
|
2014-06-25 16:29:58 +00:00
|
|
|
|
|
|
|
return GuiComponent::input(config, input);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void TextListComponent<T>::update(int deltaTime)
|
|
|
|
{
|
|
|
|
listUpdate(deltaTime);
|
2017-11-06 11:05:57 +00:00
|
|
|
|
2020-06-06 14:48:05 +00:00
|
|
|
if (!isScrolling() && size() > 0) {
|
|
|
|
// Always reset the marquee offsets.
|
2017-11-06 11:05:57 +00:00
|
|
|
mMarqueeOffset = 0;
|
|
|
|
mMarqueeOffset2 = 0;
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-06-06 14:48:05 +00:00
|
|
|
// If we're not scrolling and this object's text goes outside our size, marquee it!
|
2017-11-06 11:05:57 +00:00
|
|
|
const float textLength = mFont->sizeText(mEntries.at((unsigned int)mCursor).name).x();
|
2017-11-17 14:58:52 +00:00
|
|
|
const float limit = mSize.x() - mHorizontalMargin * 2;
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-06-06 14:48:05 +00:00
|
|
|
if (textLength > limit) {
|
|
|
|
// Loop.
|
|
|
|
// Pixels per second (based on nes-mini font at 1920x1080 to produce a speed of 200).
|
2017-11-06 11:05:57 +00:00
|
|
|
const float speed = mFont->sizeText("ABCDEFGHIJKLMNOPQRSTUVWXYZ").x() * 0.247f;
|
2017-11-17 14:58:52 +00:00
|
|
|
const float delay = 3000;
|
|
|
|
const float scrollLength = textLength;
|
|
|
|
const float returnLength = speed * 1.5f;
|
|
|
|
const float scrollTime = (scrollLength * 1000) / speed;
|
|
|
|
const float returnTime = (returnLength * 1000) / speed;
|
|
|
|
const int maxTime = (int)(delay + scrollTime + returnTime);
|
2017-11-06 11:05:57 +00:00
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
mMarqueeTime += deltaTime;
|
2020-06-06 14:48:05 +00:00
|
|
|
while (mMarqueeTime > maxTime)
|
2017-11-06 11:05:57 +00:00
|
|
|
mMarqueeTime -= maxTime;
|
|
|
|
|
2020-06-06 14:48:05 +00:00
|
|
|
mMarqueeOffset = (int)(Math::Scroll::loop(delay, scrollTime + returnTime,
|
|
|
|
(float)mMarqueeTime, scrollLength + returnLength));
|
2017-11-06 11:05:57 +00:00
|
|
|
|
2020-06-06 14:48:05 +00:00
|
|
|
if (mMarqueeOffset > (scrollLength - (limit - returnLength)))
|
2017-11-17 14:58:52 +00:00
|
|
|
mMarqueeOffset2 = (int)(mMarqueeOffset - (scrollLength + returnLength));
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GuiComponent::update(deltaTime);
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
assert(color < COLOR_ID_COUNT);
|
|
|
|
|
|
|
|
typename IList<TextListData, T>::Entry entry;
|
|
|
|
entry.name = name;
|
|
|
|
entry.object = obj;
|
|
|
|
entry.data.colorId = color;
|
|
|
|
static_cast<IList< TextListData, T >*>(this)->add(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void TextListComponent<T>::onCursorChanged(const CursorState& state)
|
|
|
|
{
|
|
|
|
mMarqueeOffset = 0;
|
2017-11-06 11:05:57 +00:00
|
|
|
mMarqueeOffset2 = 0;
|
|
|
|
mMarqueeTime = 0;
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-06-06 14:48:05 +00:00
|
|
|
if (mCursorChangedCallback)
|
2014-06-25 16:29:58 +00:00
|
|
|
mCursorChangedCallback(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2020-06-06 14:48:05 +00:00
|
|
|
void TextListComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
|
|
|
|
const std::string& view, const std::string& element, unsigned int properties)
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
|
|
|
GuiComponent::applyTheme(theme, view, element, properties);
|
|
|
|
|
|
|
|
const ThemeData::ThemeElement* elem = theme->getElement(view, element, "textlist");
|
2020-06-06 14:48:05 +00:00
|
|
|
if (!elem)
|
2014-06-25 16:29:58 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
using namespace ThemeFlags;
|
2020-06-06 14:48:05 +00:00
|
|
|
if (properties & COLOR) {
|
|
|
|
if (elem->has("selectorColor")) {
|
2014-06-25 16:29:58 +00:00
|
|
|
setSelectorColor(elem->get<unsigned int>("selectorColor"));
|
2019-07-04 01:10:17 +00:00
|
|
|
setSelectorColorEnd(elem->get<unsigned int>("selectorColor"));
|
|
|
|
}
|
|
|
|
if (elem->has("selectorColorEnd"))
|
|
|
|
setSelectorColorEnd(elem->get<unsigned int>("selectorColorEnd"));
|
|
|
|
if (elem->has("selectorGradientType"))
|
2020-06-06 14:48:05 +00:00
|
|
|
setSelectorColorGradientHorizontal(!(elem->get<std::string>
|
|
|
|
("selectorGradientType").compare("horizontal")));
|
|
|
|
if (elem->has("selectedColor"))
|
2014-06-25 16:29:58 +00:00
|
|
|
setSelectedColor(elem->get<unsigned int>("selectedColor"));
|
2020-06-06 14:48:05 +00:00
|
|
|
if (elem->has("primaryColor"))
|
2014-06-25 16:29:58 +00:00
|
|
|
setColor(0, elem->get<unsigned int>("primaryColor"));
|
2020-06-06 14:48:05 +00:00
|
|
|
if (elem->has("secondaryColor"))
|
2014-06-25 16:29:58 +00:00
|
|
|
setColor(1, elem->get<unsigned int>("secondaryColor"));
|
|
|
|
}
|
|
|
|
|
|
|
|
setFont(Font::getFromTheme(elem, properties, mFont));
|
2020-06-06 14:48:05 +00:00
|
|
|
const float selectorHeight = Math::max(mFont->getHeight(1.0),
|
|
|
|
(float)mFont->getSize()) * mLineSpacing;
|
2017-06-27 03:34:37 +00:00
|
|
|
setSelectorHeight(selectorHeight);
|
2020-06-06 11:10:33 +00:00
|
|
|
|
2020-06-06 14:48:05 +00:00
|
|
|
if (properties & ALIGNMENT) {
|
|
|
|
if (elem->has("alignment")) {
|
2014-06-25 16:29:58 +00:00
|
|
|
const std::string& str = elem->get<std::string>("alignment");
|
2020-06-06 14:48:05 +00:00
|
|
|
if (str == "left")
|
2014-06-25 16:29:58 +00:00
|
|
|
setAlignment(ALIGN_LEFT);
|
2020-06-06 14:48:05 +00:00
|
|
|
else if (str == "center")
|
2014-06-25 16:29:58 +00:00
|
|
|
setAlignment(ALIGN_CENTER);
|
2020-06-06 14:48:05 +00:00
|
|
|
else if (str == "right")
|
2014-06-25 16:29:58 +00:00
|
|
|
setAlignment(ALIGN_RIGHT);
|
|
|
|
else
|
|
|
|
LOG(LogError) << "Unknown TextListComponent alignment \"" << str << "\"!";
|
|
|
|
}
|
2020-06-06 14:48:05 +00:00
|
|
|
if (elem->has("horizontalMargin")) {
|
|
|
|
mHorizontalMargin = elem->get<float>("horizontalMargin") *
|
|
|
|
(this->mParent ? this->mParent->getSize().x() :
|
|
|
|
(float)Renderer::getScreenWidth());
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-06 14:48:05 +00:00
|
|
|
if (properties & FORCE_UPPERCASE && elem->has("forceUppercase"))
|
2014-06-25 16:29:58 +00:00
|
|
|
setUppercase(elem->get<bool>("forceUppercase"));
|
|
|
|
|
2020-06-06 14:48:05 +00:00
|
|
|
if (properties & LINE_SPACING) {
|
|
|
|
if (elem->has("lineSpacing"))
|
2017-05-29 01:08:07 +00:00
|
|
|
setLineSpacing(elem->get<float>("lineSpacing"));
|
2020-06-06 14:48:05 +00:00
|
|
|
if (elem->has("selectorHeight"))
|
2017-05-29 01:08:07 +00:00
|
|
|
setSelectorHeight(elem->get<float>("selectorHeight") * Renderer::getScreenHeight());
|
2020-06-06 14:48:05 +00:00
|
|
|
if (elem->has("selectorOffsetY")) {
|
2017-05-29 01:08:07 +00:00
|
|
|
float scale = this->mParent ? this->mParent->getSize().y() : (float)Renderer::getScreenHeight();
|
|
|
|
setSelectorOffsetY(elem->get<float>("selectorOffsetY") * scale);
|
2020-06-06 14:48:05 +00:00
|
|
|
}
|
|
|
|
else {
|
2017-05-29 01:08:07 +00:00
|
|
|
setSelectorOffsetY(0.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-06 14:48:05 +00:00
|
|
|
if (elem->has("selectorImagePath")) {
|
2017-05-29 01:08:07 +00:00
|
|
|
std::string path = elem->get<std::string>("selectorImagePath");
|
|
|
|
bool tile = elem->has("selectorImageTile") && elem->get<bool>("selectorImageTile");
|
|
|
|
mSelectorImage.setImage(path, tile);
|
|
|
|
mSelectorImage.setSize(mSize.x(), mSelectorHeight);
|
|
|
|
mSelectorImage.setColorShift(mSelectorColor);
|
2019-07-04 01:10:17 +00:00
|
|
|
mSelectorImage.setColorShiftEnd(mSelectorColorEnd);
|
2020-06-06 14:48:05 +00:00
|
|
|
}
|
|
|
|
else {
|
2017-05-29 01:08:07 +00:00
|
|
|
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
|