From 613787931a0621a4ed2158f024be55bb4b325534 Mon Sep 17 00:00:00 2001 From: Aloshi Date: Sat, 15 Mar 2014 13:39:19 -0500 Subject: [PATCH] Added a border above buttons on GuiMsgBox. Reluctantly changed button font to FONT_SIZE_MEDIUM because FONT_SIZE_SMALL has messed up sizing for some unknown reason. --- src/components/ButtonComponent.cpp | 16 ++++++---------- src/components/ButtonComponent.h | 2 +- src/guis/GuiMsgBox.cpp | 6 +++--- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/components/ButtonComponent.cpp b/src/components/ButtonComponent.cpp index 02b1d7042..2336e3698 100644 --- a/src/components/ButtonComponent.cpp +++ b/src/components/ButtonComponent.cpp @@ -2,9 +2,11 @@ #include "../Renderer.h" #include "../Window.h" #include "../Util.h" +#include "../Log.h" ButtonComponent::ButtonComponent(Window* window, const std::string& text, const std::string& helpText, const std::function& func) : GuiComponent(window), mBox(window, ":/button.png"), + mFont(Font::get(FONT_SIZE_MEDIUM)), mFocused(false), mEnabled(true), mTextColorFocused(0xFFFFFFFF), mTextColorUnfocused(0x777777FF) @@ -40,10 +42,9 @@ void ButtonComponent::setText(const std::string& text, const std::string& helpTe mText = strToUpper(text); mHelpText = helpText; - std::shared_ptr f = getFont(); - mTextCache = std::unique_ptr(f->buildTextCache(mText, 0, 0, getCurTextColor())); - - setSize(mTextCache->metrics.size + Eigen::Vector2f(12, 12)); + mTextCache = std::unique_ptr(mFont->buildTextCache(mText, 0, 0, getCurTextColor())); + + setSize(mTextCache->metrics.size + Eigen::Vector2f(12, 0)); updateHelpPrompts(); } @@ -94,18 +95,13 @@ void ButtonComponent::render(const Eigen::Affine3f& parentTrans) Renderer::setMatrix(trans); mTextCache->setColor(getCurTextColor()); - getFont()->renderTextCache(mTextCache.get()); + mFont->renderTextCache(mTextCache.get()); trans = trans.translate(-centerOffset); } renderChildren(trans); } -std::shared_ptr ButtonComponent::getFont() -{ - return Font::get(FONT_SIZE_SMALL); -} - unsigned int ButtonComponent::getCurTextColor() const { if(!mFocused) diff --git a/src/components/ButtonComponent.h b/src/components/ButtonComponent.h index b82211438..1d3b8ce8e 100644 --- a/src/components/ButtonComponent.h +++ b/src/components/ButtonComponent.h @@ -26,7 +26,7 @@ public: virtual std::vector getHelpPrompts() override; private: - std::shared_ptr getFont(); + std::shared_ptr mFont; std::function mPressedFunc; bool mFocused; diff --git a/src/guis/GuiMsgBox.cpp b/src/guis/GuiMsgBox.cpp index 3db5a3ff8..255d1c21f 100644 --- a/src/guis/GuiMsgBox.cpp +++ b/src/guis/GuiMsgBox.cpp @@ -4,7 +4,7 @@ #include "../components/ButtonComponent.h" #include "../components/MenuComponent.h" // for makeButtonGrid -#define BUTTON_VERT_PADDING 16.0f +#define BUTTON_VERT_PADDING 32.0f GuiMsgBox::GuiMsgBox(Window* window, const std::string& text, const std::string& name1, const std::function& func1, @@ -28,7 +28,7 @@ GuiMsgBox::GuiMsgBox(Window* window, const std::string& text, mButtonGrid = makeButtonGrid(mWindow, mButtons); mGrid.setEntry(mMsg, Eigen::Vector2i(0, 0), false, true); - mGrid.setEntry(mButtonGrid, Eigen::Vector2i(0, 1), true, false); + mGrid.setEntry(mButtonGrid, Eigen::Vector2i(0, 1), true, false, Eigen::Vector2i(1, 1), GridFlags::BORDER_TOP); if(mMsg->getSize().x() > width) { @@ -55,7 +55,7 @@ GuiMsgBox::GuiMsgBox(Window* window, const std::string& text, void GuiMsgBox::onSizeChanged() { mGrid.setSize(mSize); - mBackground.fitTo(mSize, Eigen::Vector3f::Zero(), Eigen::Vector2f(-16, -32)); + mBackground.fitTo(mSize, Eigen::Vector3f::Zero(), Eigen::Vector2f(-32, -32)); mGrid.setRowHeightPerc(1, (mButtonGrid->getSize().y() + BUTTON_VERT_PADDING) / mSize.y()); }