From daa62123d171349b51565cbdcd19f57b070acbac Mon Sep 17 00:00:00 2001 From: Aloshi Date: Wed, 19 Mar 2014 13:10:30 -0500 Subject: [PATCH] Changed Font::getHeight to return a float like it should. Added minimum message height to GuiMsgBox. TextComponent now vertically centers text. Fixed a bug that would cause ScraperSearchComponent to return results continuously until another search was started. --- src/components/ScraperSearchComponent.cpp | 5 ++++- src/components/TextComponent.cpp | 2 +- src/components/TextEditComponent.cpp | 2 +- src/components/TextListComponent.h | 4 ++-- src/guis/GuiInputConfig.cpp | 4 ++-- src/guis/GuiMsgBox.cpp | 3 ++- src/resources/Font.cpp | 4 ++-- src/resources/Font.h | 2 +- 8 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/components/ScraperSearchComponent.cpp b/src/components/ScraperSearchComponent.cpp index ce93f7553..0e5931376 100644 --- a/src/components/ScraperSearchComponent.cpp +++ b/src/components/ScraperSearchComponent.cpp @@ -334,8 +334,11 @@ void ScraperSearchComponent::update(int deltaTime) { if(mMDResolveHandle->status() == ASYNC_DONE) { + ScraperSearchResult result = mMDResolveHandle->getResult(); + mMDResolveHandle.reset(); + // this might end in us being deleted, depending on mAcceptCallback - so make sure this is the last thing we do in update() - returnResult(mMDResolveHandle->getResult()); + returnResult(result); }else if(mMDResolveHandle->status() == ASYNC_ERROR) { onSearchError(mMDResolveHandle->getStatusString()); diff --git a/src/components/TextComponent.cpp b/src/components/TextComponent.cpp index e1c2abbf2..d450c59c2 100644 --- a/src/components/TextComponent.cpp +++ b/src/components/TextComponent.cpp @@ -79,7 +79,7 @@ void TextComponent::render(const Eigen::Affine3f& parentTrans) if(mCentered) { const Eigen::Vector2f& textSize = mTextCache->metrics.size; - Eigen::Vector3f off((getSize().x() - textSize.x()) / 2, 0, 0); + Eigen::Vector3f off((getSize().x() - textSize.x()) / 2, (getSize().y() - textSize.y()) / 2, 0); trans.translate(off); Renderer::setMatrix(trans); diff --git a/src/components/TextEditComponent.cpp b/src/components/TextEditComponent.cpp index 6d4ff0e0f..ed85aef23 100644 --- a/src/components/TextEditComponent.cpp +++ b/src/components/TextEditComponent.cpp @@ -206,7 +206,7 @@ void TextEditComponent::render(const Eigen::Affine3f& parentTrans) cursorPos[1] = 0; } - Renderer::drawRect((int)cursorPos.x(), (int)cursorPos.y(), 3, f->getHeight(), 0x000000FF); + Renderer::drawRect((int)cursorPos.x(), (int)cursorPos.y(), 3, (int)f->getHeight(), 0x000000FF); } Renderer::popClipRect(); diff --git a/src/components/TextListComponent.h b/src/components/TextListComponent.h index 55072be15..b0503d1ee 100644 --- a/src/components/TextListComponent.h +++ b/src/components/TextListComponent.h @@ -129,7 +129,7 @@ void TextListComponent::render(const Eigen::Affine3f& parentTrans) } const int cutoff = 0; - const int entrySize = font->getHeight() + 5; + const int entrySize = (int)font->getHeight() + 5; int startEntry = 0; @@ -161,7 +161,7 @@ void TextListComponent::render(const Eigen::Affine3f& parentTrans) if(mCursor == i) { Renderer::setMatrix(trans); - Renderer::drawRect(0, (int)y, (int)mSize.x(), font->getHeight(), mSelectorColor); + Renderer::drawRect(0, (int)y, (int)mSize.x(), (int)font->getHeight(), mSelectorColor); } typename IList::Entry& entry = mEntries.at((unsigned int)i); diff --git a/src/guis/GuiInputConfig.cpp b/src/guis/GuiInputConfig.cpp index b57cfac52..68103d049 100644 --- a/src/guis/GuiInputConfig.cpp +++ b/src/guis/GuiInputConfig.cpp @@ -85,11 +85,11 @@ void GuiInputConfig::render(const Eigen::Affine3f& parentTrans) stream << "PLAYER " << mTargetConfig->getPlayerNum() + 1 << ", press..."; font->drawText(stream.str(), Eigen::Vector2f(10, 10), 0x000000FF); - int y = 14 + font->getHeight(); + int y = 14 + (int)font->getHeight(); for(int i = 0; i < mCurInputId; i++) { font->drawText(inputDispName[i], Eigen::Vector2f(10, y), 0x00CC00FF); - y += font->getHeight() + 5; + y += (int)font->getHeight() + 5; } if(mCurInputId >= inputCount) diff --git a/src/guis/GuiMsgBox.cpp b/src/guis/GuiMsgBox.cpp index e7d85ae28..0c997f61e 100644 --- a/src/guis/GuiMsgBox.cpp +++ b/src/guis/GuiMsgBox.cpp @@ -59,7 +59,8 @@ GuiMsgBox::GuiMsgBox(Window* window, const std::string& text, } } - setSize(width, mMsg->getSize().y() + mButtonGrid->getSize().y() + BUTTON_VERT_PADDING); + const float msgHeight = std::max(Font::get(FONT_SIZE_LARGE)->getHeight(), mMsg->getSize().y()); + setSize(width, msgHeight + mButtonGrid->getSize().y() + BUTTON_VERT_PADDING); // center for good measure setPosition((Renderer::getScreenWidth() - mSize.x()) / 2.0f, (Renderer::getScreenHeight() - mSize.y()) / 2.0f); diff --git a/src/resources/Font.cpp b/src/resources/Font.cpp index 638869a66..aa628f73a 100644 --- a/src/resources/Font.cpp +++ b/src/resources/Font.cpp @@ -276,9 +276,9 @@ Eigen::Vector2f Font::sizeText(std::string text) const return Eigen::Vector2f(highestWidth, y); } -int Font::getHeight() const +float Font::getHeight() const { - return (int)(mMaxGlyphHeight * 1.5f * fontScale); + return mMaxGlyphHeight * 1.5f * fontScale; } diff --git a/src/resources/Font.h b/src/resources/Font.h index af4f367b4..2ceefcc1a 100644 --- a/src/resources/Font.h +++ b/src/resources/Font.h @@ -65,7 +65,7 @@ public: void drawCenteredText(std::string text, float xOffset, float y, unsigned int color); - int getHeight() const; + float getHeight() const; void unload(std::shared_ptr& rm) override; void reload(std::shared_ptr& rm) override;