From 8ffa56e652905248da4c0193cf107029d864d184 Mon Sep 17 00:00:00 2001 From: Aloshi Date: Sat, 19 Apr 2014 15:21:15 -0500 Subject: [PATCH] Changed title format for GuiMetaDataEd. Started fixing some alignment stuff for the editors too. --- src/components/MenuComponent.cpp | 2 +- src/components/MenuComponent.h | 2 + src/guis/GuiMetaDataEd.cpp | 80 +++++++++++++++++++++++++------- src/guis/GuiMetaDataEd.h | 11 ++++- 4 files changed, 74 insertions(+), 21 deletions(-) diff --git a/src/components/MenuComponent.cpp b/src/components/MenuComponent.cpp index 622d9e6bc..36cb2f596 100644 --- a/src/components/MenuComponent.cpp +++ b/src/components/MenuComponent.cpp @@ -4,7 +4,7 @@ #define BUTTON_GRID_VERT_PADDING 32 #define BUTTON_GRID_HORIZ_PADDING 10 -#define TITLE_HEIGHT (mTitle->getFont()->getLetterHeight() + Renderer::getScreenHeight()*0.0637f) +#define TITLE_HEIGHT (mTitle->getFont()->getLetterHeight() + TITLE_VERT_PADDING) using namespace Eigen; diff --git a/src/components/MenuComponent.h b/src/components/MenuComponent.h index a1e570596..a95d622c8 100644 --- a/src/components/MenuComponent.h +++ b/src/components/MenuComponent.h @@ -12,6 +12,8 @@ class ImageComponent; std::shared_ptr makeButtonGrid(Window* window, const std::vector< std::shared_ptr >& buttons); std::shared_ptr makeArrow(Window* window); +#define TITLE_VERT_PADDING (Renderer::getScreenHeight()*0.0637f) + class MenuComponent : public GuiComponent { public: diff --git a/src/guis/GuiMetaDataEd.cpp b/src/guis/GuiMetaDataEd.cpp index 300bdf1af..b195e1d42 100644 --- a/src/guis/GuiMetaDataEd.cpp +++ b/src/guis/GuiMetaDataEd.cpp @@ -12,17 +12,34 @@ #include "../components/RatingComponent.h" #include "GuiTextEditPopup.h" +using namespace Eigen; + GuiMetaDataEd::GuiMetaDataEd(Window* window, MetaDataList* md, const std::vector& mdd, ScraperSearchParams scraperParams, const std::string& header, std::function saveCallback, std::function deleteFunc) : GuiComponent(window), mScraperParams(scraperParams), - mMenu(window, header.c_str()), + + mBackground(window, ":/frame.png"), + mGrid(window, Vector2i(1, 3)), + mMetaDataDecl(mdd), mMetaData(md), mSavedCallback(saveCallback), mDeleteFunc(deleteFunc) { - setSize((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight()); + addChild(&mBackground); + addChild(&mGrid); + + mHeaderGrid = std::make_shared(mWindow, Vector2i(1, 5)); - addChild(&mMenu); + mTitle = std::make_shared(mWindow, "EDIT METADATA", Font::get(FONT_SIZE_LARGE), 0x333333FF, TextComponent::ALIGN_CENTER); + mSubtitle = std::make_shared(mWindow, strToUpper(scraperParams.game->getPath().filename().generic_string()), + Font::get(FONT_SIZE_SMALL), 0x777777FF, TextComponent::ALIGN_CENTER); + mHeaderGrid->setEntry(mTitle, Vector2i(0, 1), false, true); + mHeaderGrid->setEntry(mSubtitle, Vector2i(0, 3), false, true); + + mGrid.setEntry(mHeaderGrid, Vector2i(0, 0), false, true); + + mList = std::make_shared(mWindow); + mGrid.setEntry(mList, Vector2i(0, 1), true, true); // populate list for(auto iter = mdd.begin(); iter != mdd.end(); iter++) @@ -47,21 +64,23 @@ GuiMetaDataEd::GuiMetaDataEd(Window* window, MetaDataList* md, const std::vector const float height = lbl->getSize().y() * 0.71f; ed->setSize(height * 4.9f, height); row.addElement(ed, false, true); - mMenu.addRow(row); break; } case MD_DATE: { ed = std::make_shared(window); row.addElement(ed, false); - mMenu.addRow(row); + + auto spacer = std::make_shared(mWindow); + spacer->setSize(Renderer::getScreenWidth() * 0.0025f, 0); + row.addElement(spacer, false); + break; } case MD_TIME: { ed = std::make_shared(window, DateTimeComponent::DISP_RELATIVE_TO_NOW); row.addElement(ed, false); - mMenu.addRow(row); break; } case MD_MULTILINE_STRING: @@ -71,6 +90,10 @@ GuiMetaDataEd::GuiMetaDataEd(Window* window, MetaDataList* md, const std::vector ed = std::make_shared(window, "", Font::get(FONT_SIZE_SMALL, FONT_PATH_LIGHT), 0x777777FF, TextComponent::ALIGN_RIGHT); row.addElement(ed, true); + auto spacer = std::make_shared(mWindow); + spacer->setSize(Renderer::getScreenWidth() * 0.005f, 0); + row.addElement(spacer, false); + auto bracket = std::make_shared(mWindow); bracket->setImage(":/arrow.svg"); bracket->setResize(Eigen::Vector2f(0, lbl->getFont()->getLetterHeight())); @@ -82,33 +105,54 @@ GuiMetaDataEd::GuiMetaDataEd(Window* window, MetaDataList* md, const std::vector row.makeAcceptInputHandler([this, title, ed, updateVal, multiLine] { mWindow->pushGui(new GuiTextEditPopup(mWindow, title, ed->getValue(), updateVal, multiLine)); }); - - mMenu.addRow(row); break; } } assert(ed); + mList->addRow(row); ed->setValue(mMetaData->get(iter->key)); mEditors.push_back(ed); } - //add buttons - mMenu.addButton("SCRAPE", "scrape", std::bind(&GuiMetaDataEd::fetch, this)); - mMenu.addButton("SAVE", "save", [&] { save(); delete this; }); - + std::vector< std::shared_ptr > buttons; + buttons.push_back(std::make_shared(mWindow, "SCRAPE", "scrape", std::bind(&GuiMetaDataEd::fetch, this))); + buttons.push_back(std::make_shared(mWindow, "SAVE", "save", [&] { save(); delete this; })); + if(mDeleteFunc) { auto deleteFileAndSelf = [&] { mDeleteFunc(); delete this; }; auto deleteBtnFunc = [this, deleteFileAndSelf] { mWindow->pushGui(new GuiMsgBox(mWindow, "This will delete a file!\nAre you sure?", "YES", deleteFileAndSelf, "NO", nullptr)); }; - mMenu.addButton("DELETE", "delete", deleteBtnFunc); + buttons.push_back(std::make_shared(mWindow, "DELETE", "delete", deleteBtnFunc)); } - // initially put cursor on "SCRAPE" - mMenu.setCursorToButtons(); + mButtons = makeButtonGrid(mWindow, buttons); + mGrid.setEntry(mButtons, Vector2i(0, 2), true, false); - // position menu - mMenu.setPosition((mSize.x() - mMenu.getSize().x()) / 2, Renderer::getScreenHeight() * 0.15f); //center it + // initially put cursor on "SCRAPE" + mGrid.setCursorTo(mButtons); + + // resize + center + setSize(Renderer::getScreenWidth() * 0.5f, Renderer::getScreenHeight() * 0.71f); + setPosition((Renderer::getScreenWidth() - mSize.x()) / 2, (Renderer::getScreenHeight() - mSize.y()) / 2); +} + +void GuiMetaDataEd::onSizeChanged() +{ + mBackground.fitTo(mSize, Vector3f::Zero(), Vector2f(-32, -32)); + + mGrid.setSize(mSize); + + const float titleHeight = mTitle->getFont()->getLetterHeight(); + const float subtitleHeight = mSubtitle->getFont()->getLetterHeight() + 2; + const float titleSubtitleSpacing = mSize.y() * 0.03f; + + mGrid.setRowHeightPerc(0, (titleHeight + titleSubtitleSpacing + subtitleHeight + TITLE_VERT_PADDING) / mSize.y()); + mGrid.setRowHeightPerc(2, mButtons->getSize().y() / mSize.y()); + + mHeaderGrid->setRowHeightPerc(1, titleHeight / mHeaderGrid->getSize().y()); + mHeaderGrid->setRowHeightPerc(2, titleSubtitleSpacing / mHeaderGrid->getSize().y()); + mHeaderGrid->setRowHeightPerc(3, subtitleHeight / mHeaderGrid->getSize().y()); } void GuiMetaDataEd::save() @@ -160,7 +204,7 @@ bool GuiMetaDataEd::input(InputConfig* config, Input input) std::vector GuiMetaDataEd::getHelpPrompts() { - std::vector prompts = mMenu.getHelpPrompts(); + std::vector prompts = mGrid.getHelpPrompts(); prompts.push_back(HelpPrompt("b", "discard")); return prompts; } diff --git a/src/guis/GuiMetaDataEd.h b/src/guis/GuiMetaDataEd.h index 295f4e312..3b86772ab 100644 --- a/src/guis/GuiMetaDataEd.h +++ b/src/guis/GuiMetaDataEd.h @@ -14,7 +14,7 @@ public: const std::string& header, std::function savedCallback, std::function deleteFunc); bool input(InputConfig* config, Input input) override; - + void onSizeChanged() override; virtual std::vector getHelpPrompts() override; private: @@ -22,7 +22,14 @@ private: void fetch(); void fetchDone(const ScraperSearchResult& result); - MenuComponent mMenu; + NinePatchComponent mBackground; + ComponentGrid mGrid; + + std::shared_ptr mTitle; + std::shared_ptr mSubtitle; + std::shared_ptr mHeaderGrid; + std::shared_ptr mList; + std::shared_ptr mButtons; ScraperSearchParams mScraperParams;