Skip to content

Commit

Permalink
Changed Font::getHeight to return a float like it should.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Aloshi committed Mar 19, 2014
1 parent 8e5c910 commit daa6212
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 11 deletions.
5 changes: 4 additions & 1 deletion src/components/ScraperSearchComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/components/TextComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/components/TextEditComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/components/TextListComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void TextListComponent<T>::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;

Expand Down Expand Up @@ -161,7 +161,7 @@ void TextListComponent<T>::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<TextListData, T>::Entry& entry = mEntries.at((unsigned int)i);
Expand Down
4 changes: 2 additions & 2 deletions src/guis/GuiInputConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/guis/GuiMsgBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/resources/Font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down
2 changes: 1 addition & 1 deletion src/resources/Font.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Font : public IReloadable

void drawCenteredText(std::string text, float xOffset, float y, unsigned int color);

int getHeight() const;
float getHeight() const;

void unload(std::shared_ptr<ResourceManager>& rm) override;
void reload(std::shared_ptr<ResourceManager>& rm) override;
Expand Down

0 comments on commit daa6212

Please sign in to comment.