diff --git a/src/components/TextComponent.cpp b/src/components/TextComponent.cpp index 1d172f97f..4808b9d7d 100644 --- a/src/components/TextComponent.cpp +++ b/src/components/TextComponent.cpp @@ -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; diff --git a/src/components/TextListComponent.h b/src/components/TextListComponent.h index 9a9e9f906..4313694bf 100644 --- a/src/components/TextListComponent.h +++ b/src/components/TextListComponent.h @@ -37,6 +37,7 @@ public: std::string name; T object; unsigned int colorId; + std::shared_ptr 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& theme) { mTheme = theme; } + void setTheme(const std::shared_ptr& theme); inline void setCentered(bool centered) { mCentered = centered; } enum CursorState { @@ -113,8 +114,7 @@ template void TextListComponent::render(const Eigen::Affine3f& parentTrans) { Eigen::Affine3f trans = parentTrans * getTransform(); - Renderer::setMatrix(trans); - + std::shared_ptr font = mTheme->getFont(THEME_FONT); const int cutoff = 0; @@ -155,10 +155,11 @@ void TextListComponent::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,11 +169,22 @@ void TextListComponent::render(const Eigen::Affine3f& parentTrans) else color = mTheme->getColor(THEME_ENTRY_COLOR[row.colorId]); - if(mCentered) - font->drawCenteredText(row.name, x, y, color); - else - font->drawText(row.name, Eigen::Vector2f(x, y), color); + if(!row.textCache) + row.textCache = std::unique_ptr(font->buildTextCache(row.name, 0, 0, 0x000000FF)); + row.textCache->setColor(color); + + Eigen::Vector3f offset(x, y, 0); + + if(mCentered) + 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::onCursorChanged(CursorState state) mCursorChangedCallback(state); } +template +void TextListComponent::setTheme(const std::shared_ptr& theme) +{ + mTheme = theme; + + // invalidate text caches in case font changed + for(auto it = mRowVector.begin(); it != mRowVector.end(); it++) + it->textCache.reset(); +} + #endif diff --git a/src/views/DetailedGameListView.cpp b/src/views/DetailedGameListView.cpp index 332021aeb..ba1d1cbdb 100644 --- a/src/views/DetailedGameListView.cpp +++ b/src/views/DetailedGameListView.cpp @@ -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& 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() diff --git a/src/views/ViewController.cpp b/src/views/ViewController.cpp index 6b1fabf98..eb18e758d 100644 --- a/src/views/ViewController.cpp +++ b/src/views/ViewController.cpp @@ -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++) - it->second->render(trans); + { + 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); + } } diff --git a/src/views/ViewController.h b/src/views/ViewController.h index e678d5cab..faf17bc56 100644 --- a/src/views/ViewController.h +++ b/src/views/ViewController.h @@ -14,8 +14,7 @@ public: void goToPrevSystem(); void goToSystem(SystemData* system); void goToSystemSelect(); - void showQuickSystemSelect(); - + void onFileChanged(FileData* file, FileChangeType change); // Plays a nice launch effect and launches the game at the end of it.