diff --git a/src/Font.cpp b/src/Font.cpp index 83a05a5aa..69592a122 100644 --- a/src/Font.cpp +++ b/src/Font.cpp @@ -397,8 +397,7 @@ void Font::drawWrappedText(std::string text, const Eigen::Vector2f& offset, floa Eigen::Vector2f Font::sizeWrappedText(std::string text, float xLen) const { - //this is incorrect for text that is so short it doesn't need to wrap - Eigen::Vector2f out(xLen, 0); + Eigen::Vector2f out(0, 0); float y = 0; @@ -443,6 +442,10 @@ Eigen::Vector2f Font::sizeWrappedText(std::string text, float xLen) const //move the word we skipped to the next line line = word; + + //update our maximum known line width + if(textSize.x() > out.x()) + out[0] = textSize.x(); }else{ //there's still space, continue building the line line = temp; diff --git a/src/components/GuiGameList.cpp b/src/components/GuiGameList.cpp index a08bc7aab..1eade1e9b 100644 --- a/src/components/GuiGameList.cpp +++ b/src/components/GuiGameList.cpp @@ -31,6 +31,7 @@ GuiGameList::GuiGameList(Window* window) : GuiComponent(window), mDescription(window), mDescContainer(window), mTransitionImage(window, 0.0f, 0.0f, "", (float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight(), true), + mHeaderText(mWindow), sortStateIndex(Settings::getInstance()->getInt("GameListSortIndex")) { //first object initializes the vector @@ -56,22 +57,27 @@ GuiGameList::GuiGameList(Window* window) : GuiComponent(window), mTransitionImage.setPosition((float)Renderer::getScreenWidth(), 0); mTransitionImage.setOrigin(0, 0); - mTransitionAnimation.addChild(&mTransitionImage); - //a hack! the GuiGameList doesn't use the children system right now because I haven't redone it to do so yet. - //the list depends on knowing it's final window coordinates (getGlobalOffset), which requires knowing the where the GuiGameList is. - //the GuiGameList now moves during screen transitions, so we have to let it know somehow. - //this should be removed in favor of using real children soon. - mList.setParent(this); + mHeaderText.setColor(0xFF0000FF); + mHeaderText.setFont(Font::get(*mWindow->getResourceManager(), Font::getDefaultPath(), FONT_SIZE_LARGE)); + mHeaderText.setPosition(0, 1); + mHeaderText.setSize((float)Renderer::getScreenWidth(), 0); + mHeaderText.setCentered(true); + + addChild(mTheme); + addChild(&mHeaderText); + addChild(&mScreenshot); + addChild(&mDescContainer); + addChild(&mList); + addChild(&mTransitionImage); + + mTransitionAnimation.addChild(this); setSystemId(0); } GuiGameList::~GuiGameList() { - //undo the parenting hack because otherwise it's not really a child and will try to remove itself on delete - mList.setParent(NULL); - delete mTheme; } @@ -105,38 +111,8 @@ void GuiGameList::setSystemId(int id) void GuiGameList::render(const Eigen::Affine3f& parentTrans) { - if(mTransitionImage.getPosition().x() > 0) //transitioning in from the left - mPosition[0] = mTransitionImage.getPosition().x() - Renderer::getScreenWidth(); - else //transitioning in from the right - mPosition[0] = mTransitionImage.getPosition().x() + Renderer::getScreenWidth(); - Eigen::Affine3f trans = parentTrans * getTransform(); - Renderer::setMatrix(trans); - - if(mTheme) - mTheme->render(trans); - - //reset modelview matrix if mTheme changed it - Renderer::setMatrix(trans); - - std::shared_ptr headerFont = Font::get(*mWindow->getResourceManager(), Font::getDefaultPath(), FONT_SIZE_LARGE); - - //header - if(!mTheme->getBool("hideHeader")) - headerFont->drawCenteredText(mSystem->getDescName(), 0, 1, 0xFF0000FF); - - if(isDetailed()) - { - //divider - if(!mTheme->getBool("hideDividers")) - Renderer::drawRect((int)(Renderer::getScreenWidth() * mTheme->getFloat("listOffsetX")) - 4, headerFont->getHeight() + 2, 8, Renderer::getScreenHeight(), 0x0000FFFF); - - mScreenshot.render(trans); - mDescContainer.render(trans); - } - - mList.render(trans); - mTransitionImage.render(parentTrans); + renderChildren(trans); } bool GuiGameList::input(InputConfig* config, Input input) @@ -330,6 +306,13 @@ void GuiGameList::updateTheme() mList.setFont(mTheme->getListFont()); mList.setPosition(0.0f, Font::get(*mWindow->getResourceManager(), Font::getDefaultPath(), FONT_SIZE_LARGE)->getHeight() + 2.0f); + if(!mTheme->getBool("hideHeader")) + { + mHeaderText.setText(mSystem->getDescName()); + }else{ + mHeaderText.setText(""); + } + if(isDetailed()) { mList.setCentered(mTheme->getBool("listCentered")); @@ -405,19 +388,21 @@ GuiGameList* GuiGameList::create(Window* window) void GuiGameList::update(int deltaTime) { - mImageAnimation.update(deltaTime); - mTransitionAnimation.update(deltaTime); - - mList.update(deltaTime); - - mDescContainer.update(deltaTime); + mImageAnimation.update(deltaTime); + GuiComponent::update(deltaTime); } void GuiGameList::doTransition(int dir) { mTransitionImage.copyScreen(); mTransitionImage.setOpacity(255); - mTransitionImage.setPosition(0, 0); + + //put the image of what's currently onscreen at what will be (in screen coords) 0, 0 + mTransitionImage.setPosition((float)Renderer::getScreenWidth() * dir, 0); + + //move the entire thing offscreen so we'll move into place + setPosition((float)Renderer::getScreenWidth() * -dir, mPosition[1]); + mTransitionAnimation.move(Renderer::getScreenWidth() * dir, 0, 50); } diff --git a/src/components/GuiGameList.h b/src/components/GuiGameList.h index 8a9bbd4c8..d6a3143ec 100644 --- a/src/components/GuiGameList.h +++ b/src/components/GuiGameList.h @@ -63,6 +63,7 @@ private: ScrollableContainer mDescContainer; AnimationComponent mImageAnimation; ThemeComponent* mTheme; + TextComponent mHeaderText; ImageComponent mTransitionImage; AnimationComponent mTransitionAnimation; diff --git a/src/components/TextComponent.cpp b/src/components/TextComponent.cpp index 727c617ed..8219caab6 100644 --- a/src/components/TextComponent.cpp +++ b/src/components/TextComponent.cpp @@ -4,12 +4,12 @@ #include "../Window.h" TextComponent::TextComponent(Window* window) : GuiComponent(window), - mFont(NULL), mColor(0x000000FF), mAutoCalcExtent(true, true) + mFont(NULL), mColor(0x000000FF), mAutoCalcExtent(true, true), mCentered(false) { } TextComponent::TextComponent(Window* window, const std::string& text, std::shared_ptr font, Eigen::Vector3f pos, Eigen::Vector2f size) : GuiComponent(window), - mFont(NULL), mColor(0x000000FF), mAutoCalcExtent(true, true) + mFont(NULL), mColor(0x000000FF), mAutoCalcExtent(true, true), mCentered(false) { setText(text); setFont(font); @@ -43,6 +43,11 @@ void TextComponent::setText(const std::string& text) calculateExtent(); } +void TextComponent::setCentered(bool center) +{ + mCentered = center; +} + std::shared_ptr TextComponent::getFont() const { if(mFont) @@ -56,9 +61,20 @@ void TextComponent::render(const Eigen::Affine3f& parentTrans) std::shared_ptr font = getFont(); Eigen::Affine3f trans = parentTrans * getTransform(); - Renderer::setMatrix(trans); - - font->drawWrappedText(mText, Eigen::Vector2f(0, 0), getSize().x(), mColor >> 8 << 8 | getOpacity()); + + if(font && !mText.empty()) + { + Renderer::setMatrix(trans); + + if(mCentered) + { + Eigen::Vector2f textSize = font->sizeWrappedText(mText, getSize().x()); + Eigen::Vector2f pos((getSize().x() - textSize.x()) / 2, 0); + font->drawWrappedText(mText, pos, getSize().x(), (mColor >> 8 << 8) | getOpacity()); + }else{ + font->drawWrappedText(mText, Eigen::Vector2f(0, 0), getSize().x(), mColor >> 8 << 8 | getOpacity()); + } + } GuiComponent::renderChildren(trans); } diff --git a/src/components/TextComponent.h b/src/components/TextComponent.h index 64be8c548..8df7749b1 100644 --- a/src/components/TextComponent.h +++ b/src/components/TextComponent.h @@ -14,6 +14,7 @@ public: void onSizeChanged() override; void setText(const std::string& text); void setColor(unsigned int color); + void setCentered(bool center); //Default is uncentered. void render(const Eigen::Affine3f& parentTrans) override; @@ -26,6 +27,7 @@ private: std::shared_ptr mFont; Eigen::Matrix mAutoCalcExtent; std::string mText; + bool mCentered; }; #endif