mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-12-01 18:45:39 +00:00
Optimized the hell out of TextListComponent (and TextComponent a bit)
This commit is contained in:
parent
87137df51e
commit
4b4fff39ef
|
@ -83,7 +83,7 @@ void TextComponent::render(const Eigen::Affine3f& parentTrans)
|
||||||
|
|
||||||
if(mCentered)
|
if(mCentered)
|
||||||
{
|
{
|
||||||
Eigen::Vector2f textSize = font->sizeWrappedText(mText, getSize().x());
|
const Eigen::Vector2f& textSize = mTextCache->metrics.size;
|
||||||
Eigen::Vector2f pos((getSize().x() - textSize.x()) / 2, 0);
|
Eigen::Vector2f pos((getSize().x() - textSize.x()) / 2, 0);
|
||||||
|
|
||||||
Eigen::Affine3f centeredTrans = trans;
|
Eigen::Affine3f centeredTrans = trans;
|
||||||
|
|
|
@ -37,6 +37,7 @@ public:
|
||||||
std::string name;
|
std::string name;
|
||||||
T object;
|
T object;
|
||||||
unsigned int colorId;
|
unsigned int colorId;
|
||||||
|
std::shared_ptr<TextCache> textCache;
|
||||||
};
|
};
|
||||||
|
|
||||||
void add(const std::string& name, const T& obj, unsigned int colorId);
|
void add(const std::string& name, const T& obj, unsigned int colorId);
|
||||||
|
@ -52,7 +53,7 @@ public:
|
||||||
void stopScrolling();
|
void stopScrolling();
|
||||||
inline bool isScrolling() const { return mScrollDir != 0; }
|
inline bool isScrolling() const { return mScrollDir != 0; }
|
||||||
|
|
||||||
inline void setTheme(const std::shared_ptr<ThemeData>& theme) { mTheme = theme; }
|
void setTheme(const std::shared_ptr<ThemeData>& theme);
|
||||||
inline void setCentered(bool centered) { mCentered = centered; }
|
inline void setCentered(bool centered) { mCentered = centered; }
|
||||||
|
|
||||||
enum CursorState {
|
enum CursorState {
|
||||||
|
@ -113,7 +114,6 @@ template <typename T>
|
||||||
void TextListComponent<T>::render(const Eigen::Affine3f& parentTrans)
|
void TextListComponent<T>::render(const Eigen::Affine3f& parentTrans)
|
||||||
{
|
{
|
||||||
Eigen::Affine3f trans = parentTrans * getTransform();
|
Eigen::Affine3f trans = parentTrans * getTransform();
|
||||||
Renderer::setMatrix(trans);
|
|
||||||
|
|
||||||
std::shared_ptr<Font> font = mTheme->getFont(THEME_FONT);
|
std::shared_ptr<Font> font = mTheme->getFont(THEME_FONT);
|
||||||
|
|
||||||
|
@ -155,10 +155,11 @@ void TextListComponent<T>::render(const Eigen::Affine3f& parentTrans)
|
||||||
//draw selector bar
|
//draw selector bar
|
||||||
if(mCursor == i)
|
if(mCursor == i)
|
||||||
{
|
{
|
||||||
|
Renderer::setMatrix(trans);
|
||||||
Renderer::drawRect(0, (int)y, (int)getSize().x(), font->getHeight(), mTheme->getColor(THEME_SELECTOR_COLOR));
|
Renderer::drawRect(0, (int)y, (int)getSize().x(), font->getHeight(), mTheme->getColor(THEME_SELECTOR_COLOR));
|
||||||
}
|
}
|
||||||
|
|
||||||
ListRow row = mRowVector.at((unsigned int)i);
|
ListRow& row = mRowVector.at((unsigned int)i);
|
||||||
|
|
||||||
float x = (float)(mCursor == i ? -mMarqueeOffset : 0);
|
float x = (float)(mCursor == i ? -mMarqueeOffset : 0);
|
||||||
|
|
||||||
|
@ -168,10 +169,21 @@ void TextListComponent<T>::render(const Eigen::Affine3f& parentTrans)
|
||||||
else
|
else
|
||||||
color = mTheme->getColor(THEME_ENTRY_COLOR[row.colorId]);
|
color = mTheme->getColor(THEME_ENTRY_COLOR[row.colorId]);
|
||||||
|
|
||||||
|
if(!row.textCache)
|
||||||
|
row.textCache = std::unique_ptr<TextCache>(font->buildTextCache(row.name, 0, 0, 0x000000FF));
|
||||||
|
|
||||||
|
row.textCache->setColor(color);
|
||||||
|
|
||||||
|
Eigen::Vector3f offset(x, y, 0);
|
||||||
|
|
||||||
if(mCentered)
|
if(mCentered)
|
||||||
font->drawCenteredText(row.name, x, y, color);
|
offset[0] += (mSize.x() - row.textCache->metrics.size.x()) / 2;
|
||||||
else
|
|
||||||
font->drawText(row.name, Eigen::Vector2f(x, y), color);
|
Eigen::Affine3f drawTrans = trans;
|
||||||
|
drawTrans.translate(offset);
|
||||||
|
Renderer::setMatrix(drawTrans);
|
||||||
|
|
||||||
|
font->renderTextCache(row.textCache.get());
|
||||||
|
|
||||||
y += entrySize;
|
y += entrySize;
|
||||||
}
|
}
|
||||||
|
@ -370,4 +382,14 @@ void TextListComponent<T>::onCursorChanged(CursorState state)
|
||||||
mCursorChangedCallback(state);
|
mCursorChangedCallback(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void TextListComponent<T>::setTheme(const std::shared_ptr<ThemeData>& theme)
|
||||||
|
{
|
||||||
|
mTheme = theme;
|
||||||
|
|
||||||
|
// invalidate text caches in case font changed
|
||||||
|
for(auto it = mRowVector.begin(); it != mRowVector.end(); it++)
|
||||||
|
it->textCache.reset();
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -6,7 +6,6 @@ DetailedGameListView::DetailedGameListView(Window* window, FileData* root) :
|
||||||
mImage(window), mInfoBackground(window)
|
mImage(window), mInfoBackground(window)
|
||||||
{
|
{
|
||||||
mHeaderImage.setPosition(mSize.x() * 0.25f, 0);
|
mHeaderImage.setPosition(mSize.x() * 0.25f, 0);
|
||||||
mHeaderImage.setResize(mSize.x() * 0.5f, 0, true);
|
|
||||||
|
|
||||||
mInfoBackground.setPosition(0, mSize.y() * 0.5f, 0);
|
mInfoBackground.setPosition(0, mSize.y() * 0.5f, 0);
|
||||||
mInfoBackground.setOrigin(0, 0.5f);
|
mInfoBackground.setOrigin(0, 0.5f);
|
||||||
|
@ -38,11 +37,16 @@ DetailedGameListView::DetailedGameListView(Window* window, FileData* root) :
|
||||||
|
|
||||||
void DetailedGameListView::setTheme(const std::shared_ptr<ThemeData>& theme)
|
void DetailedGameListView::setTheme(const std::shared_ptr<ThemeData>& theme)
|
||||||
{
|
{
|
||||||
|
mHeaderImage.setResize(mSize.x() * 0.5f, 0, true);
|
||||||
BasicGameListView::setTheme(theme);
|
BasicGameListView::setTheme(theme);
|
||||||
|
|
||||||
|
if(mHeaderImage.getPosition().y() + mHeaderImage.getSize().y() > mImage.getPosition().y())
|
||||||
|
mHeaderImage.setResize(0, mSize.y() * 0.185f, true);
|
||||||
|
|
||||||
mDescription.setFont(theme->getFont("descriptionFont"));
|
mDescription.setFont(theme->getFont("descriptionFont"));
|
||||||
mDescription.setColor(theme->getColor("descriptionColor"));
|
mDescription.setColor(theme->getColor("descriptionColor"));
|
||||||
mInfoBackground.setImage(theme->getImage("infoBackgroundImage").getTexture());
|
mInfoBackground.setImage(theme->getImage("infoBackgroundImage").getTexture());
|
||||||
|
mInfoBackground.setTiling(theme->getImage("infoBackgroundImage").tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DetailedGameListView::updateInfoPanel()
|
void DetailedGameListView::updateInfoPanel()
|
||||||
|
|
|
@ -180,5 +180,15 @@ void ViewController::render(const Eigen::Affine3f& parentTrans)
|
||||||
|
|
||||||
//should really do some clipping here
|
//should really do some clipping here
|
||||||
for(auto it = mSystemViews.begin(); it != mSystemViews.end(); it++)
|
for(auto it = mSystemViews.begin(); it != mSystemViews.end(); it++)
|
||||||
|
{
|
||||||
|
Eigen::Vector3f pos = it->second->getPosition();
|
||||||
|
Eigen::Vector2f size = it->second->getSize();
|
||||||
|
|
||||||
|
Eigen::Vector3f camPos = -trans.translation();
|
||||||
|
Eigen::Vector2f camSize((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight());
|
||||||
|
|
||||||
|
if(pos.x() + size.x() >= camPos.x() && pos.y() + size.y() >= camPos.y() &&
|
||||||
|
pos.x() <= camPos.x() + camSize.x() && pos.y() <= camPos.y() + camSize.y())
|
||||||
it->second->render(trans);
|
it->second->render(trans);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -14,7 +14,6 @@ public:
|
||||||
void goToPrevSystem();
|
void goToPrevSystem();
|
||||||
void goToSystem(SystemData* system);
|
void goToSystem(SystemData* system);
|
||||||
void goToSystemSelect();
|
void goToSystemSelect();
|
||||||
void showQuickSystemSelect();
|
|
||||||
|
|
||||||
void onFileChanged(FileData* file, FileChangeType change);
|
void onFileChanged(FileData* file, FileChangeType change);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue