mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-26 08:05:38 +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)
|
||||
{
|
||||
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::Affine3f centeredTrans = trans;
|
||||
|
|
|
@ -37,6 +37,7 @@ public:
|
|||
std::string name;
|
||||
T object;
|
||||
unsigned int colorId;
|
||||
std::shared_ptr<TextCache> textCache;
|
||||
};
|
||||
|
||||
void add(const std::string& name, const T& obj, unsigned int colorId);
|
||||
|
@ -52,7 +53,7 @@ public:
|
|||
void stopScrolling();
|
||||
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; }
|
||||
|
||||
enum CursorState {
|
||||
|
@ -113,7 +114,6 @@ template <typename T>
|
|||
void TextListComponent<T>::render(const Eigen::Affine3f& parentTrans)
|
||||
{
|
||||
Eigen::Affine3f trans = parentTrans * getTransform();
|
||||
Renderer::setMatrix(trans);
|
||||
|
||||
std::shared_ptr<Font> font = mTheme->getFont(THEME_FONT);
|
||||
|
||||
|
@ -155,10 +155,11 @@ void TextListComponent<T>::render(const Eigen::Affine3f& parentTrans)
|
|||
//draw selector bar
|
||||
if(mCursor == i)
|
||||
{
|
||||
Renderer::setMatrix(trans);
|
||||
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);
|
||||
|
||||
|
@ -168,10 +169,21 @@ void TextListComponent<T>::render(const Eigen::Affine3f& parentTrans)
|
|||
else
|
||||
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)
|
||||
font->drawCenteredText(row.name, x, y, color);
|
||||
else
|
||||
font->drawText(row.name, Eigen::Vector2f(x, y), color);
|
||||
offset[0] += (mSize.x() - row.textCache->metrics.size.x()) / 2;
|
||||
|
||||
Eigen::Affine3f drawTrans = trans;
|
||||
drawTrans.translate(offset);
|
||||
Renderer::setMatrix(drawTrans);
|
||||
|
||||
font->renderTextCache(row.textCache.get());
|
||||
|
||||
y += entrySize;
|
||||
}
|
||||
|
@ -370,4 +382,14 @@ void TextListComponent<T>::onCursorChanged(CursorState 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
|
||||
|
|
|
@ -6,7 +6,6 @@ DetailedGameListView::DetailedGameListView(Window* window, FileData* root) :
|
|||
mImage(window), mInfoBackground(window)
|
||||
{
|
||||
mHeaderImage.setPosition(mSize.x() * 0.25f, 0);
|
||||
mHeaderImage.setResize(mSize.x() * 0.5f, 0, true);
|
||||
|
||||
mInfoBackground.setPosition(0, mSize.y() * 0.5f, 0);
|
||||
mInfoBackground.setOrigin(0, 0.5f);
|
||||
|
@ -38,11 +37,16 @@ DetailedGameListView::DetailedGameListView(Window* window, FileData* root) :
|
|||
|
||||
void DetailedGameListView::setTheme(const std::shared_ptr<ThemeData>& theme)
|
||||
{
|
||||
mHeaderImage.setResize(mSize.x() * 0.5f, 0, true);
|
||||
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.setColor(theme->getColor("descriptionColor"));
|
||||
mInfoBackground.setImage(theme->getImage("infoBackgroundImage").getTexture());
|
||||
mInfoBackground.setTiling(theme->getImage("infoBackgroundImage").tile);
|
||||
}
|
||||
|
||||
void DetailedGameListView::updateInfoPanel()
|
||||
|
|
|
@ -180,5 +180,15 @@ void ViewController::render(const Eigen::Affine3f& parentTrans)
|
|||
|
||||
//should really do some clipping here
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@ public:
|
|||
void goToPrevSystem();
|
||||
void goToSystem(SystemData* system);
|
||||
void goToSystemSelect();
|
||||
void showQuickSystemSelect();
|
||||
|
||||
void onFileChanged(FileData* file, FileChangeType change);
|
||||
|
||||
|
|
Loading…
Reference in a new issue