From a2e400dd2b8b6609b64f7d24f44dcc139c69b539 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Fri, 10 Feb 2023 00:25:22 +0100 Subject: [PATCH] Multiple layout improvements when running in vertical screen orientation. Also cleaned up some code. --- .../src/guis/GuiCollectionSystemsOptions.cpp | 14 ++-- es-app/src/guis/GuiCollectionSystemsOptions.h | 1 + es-app/src/guis/GuiGamelistFilter.cpp | 8 +- es-app/src/guis/GuiMenu.cpp | 30 +++++--- es-app/src/guis/GuiMetaDataEd.cpp | 45 ++++++----- es-app/src/guis/GuiMetaDataEd.h | 1 + es-app/src/guis/GuiScraperSearch.cpp | 4 +- es-app/src/guis/GuiSettings.cpp | 14 ++-- es-app/src/guis/GuiSettings.h | 1 + es-app/src/views/ViewController.cpp | 23 +++--- es-core/src/guis/GuiTextEditKeyboardPopup.cpp | 74 +++++++++++-------- es-core/src/guis/GuiTextEditKeyboardPopup.h | 3 + 12 files changed, 130 insertions(+), 88 deletions(-) diff --git a/es-app/src/guis/GuiCollectionSystemsOptions.cpp b/es-app/src/guis/GuiCollectionSystemsOptions.cpp index 63d1b96f0..a3533469c 100644 --- a/es-app/src/guis/GuiCollectionSystemsOptions.cpp +++ b/es-app/src/guis/GuiCollectionSystemsOptions.cpp @@ -21,6 +21,7 @@ GuiCollectionSystemsOptions::GuiCollectionSystemsOptions(std::string title) : GuiSettings {title} + , mRenderer {Renderer::getInstance()} , mAddedCustomCollection {false} , mDeletedCustomCollection {false} { @@ -217,9 +218,11 @@ GuiCollectionSystemsOptions::GuiCollectionSystemsOptions(std::string title) if (Settings::getInstance()->getBool("VirtualKeyboard")) { row.makeAcceptInputHandler([this, createCollectionCall] { - mWindow->pushGui(new GuiTextEditKeyboardPopup(getHelpStyle(), "New Collection Name", "", - createCollectionCall, false, "CREATE", - "CREATE COLLECTION?")); + const float verticalPosition { + mRenderer->getIsVerticalOrientation() ? getMenu().getPosition().y : 0.0f}; + mWindow->pushGui(new GuiTextEditKeyboardPopup( + getHelpStyle(), verticalPosition, "New Collection Name", "", createCollectionCall, + false, "CREATE", "CREATE COLLECTION?")); }); } else { @@ -304,8 +307,9 @@ GuiCollectionSystemsOptions::GuiCollectionSystemsOptions(std::string title) // Make the menu slightly wider to fit the scroll indicators. glm::vec2 menuSize {ss->getMenuSize()}; glm::vec3 menuPos {ss->getMenuPosition()}; - ss->setMenuSize(glm::vec2 {menuSize.x * 1.08f, menuSize.y}); - menuPos.x = (Renderer::getScreenWidth() - ss->getMenuSize().x) / 2.0f; + const float maxWidthModifier {mRenderer->getIsVerticalOrientation() ? 1.0f : 1.08f}; + ss->setMenuSize(glm::vec2 {menuSize.x * maxWidthModifier, menuSize.y}); + menuPos.x = (mRenderer->getScreenWidth() - ss->getMenuSize().x) / 2.0f; ss->setMenuPosition(menuPos); mWindow->pushGui(ss); }); diff --git a/es-app/src/guis/GuiCollectionSystemsOptions.h b/es-app/src/guis/GuiCollectionSystemsOptions.h index bd5eb2758..25317ddbf 100644 --- a/es-app/src/guis/GuiCollectionSystemsOptions.h +++ b/es-app/src/guis/GuiCollectionSystemsOptions.h @@ -22,6 +22,7 @@ public: private: void createCustomCollection(std::string inName); + Renderer* mRenderer; std::shared_ptr> mCollectionSystemsAuto; std::shared_ptr> mCollectionSystemsCustom; diff --git a/es-app/src/guis/GuiGamelistFilter.cpp b/es-app/src/guis/GuiGamelistFilter.cpp index 5379f5974..7f5e10810 100644 --- a/es-app/src/guis/GuiGamelistFilter.cpp +++ b/es-app/src/guis/GuiGamelistFilter.cpp @@ -118,9 +118,11 @@ void GuiGamelistFilter::addFiltersToMenu() if (Settings::getInstance()->getBool("VirtualKeyboard")) { row.makeAcceptInputHandler([this, updateVal] { - mWindow->pushGui(new GuiTextEditKeyboardPopup(getHelpStyle(), "GAME NAME", - mTextFilterField->getValue(), updateVal, - false, "OK", "APPLY CHANGES?")); + const float verticalPosition { + Renderer::getIsVerticalOrientation() ? mMenu.getPosition().y : 0.0f}; + mWindow->pushGui(new GuiTextEditKeyboardPopup( + getHelpStyle(), verticalPosition, "GAME NAME", mTextFilterField->getValue(), + updateVal, false, "OK", "APPLY CHANGES?")); }); } else { diff --git a/es-app/src/guis/GuiMenu.cpp b/es-app/src/guis/GuiMenu.cpp index 80ff03b0b..ca278a634 100644 --- a/es-app/src/guis/GuiMenu.cpp +++ b/es-app/src/guis/GuiMenu.cpp @@ -1179,11 +1179,22 @@ void GuiMenu::openConfigInput(GuiSettings* settings) // the input device settings menu later on. settings->setNeedsSaving(false); - std::string message {"THE KEYBOARD AND CONTROLLERS ARE AUTOMATICALLY\n" - "CONFIGURED, BUT USING THIS CONFIGURATION TOOL\n" - "YOU CAN OVERRIDE THE DEFAULT BUTTON MAPPINGS\n" - "(THIS WILL NOT AFFECT THE HELP PROMPTS)\n" - "CONTINUE?"}; + std::string message; + if (Renderer::getIsVerticalOrientation()) { + message = "THE KEYBOARD AND CONTROLLERS ARE\n" + "AUTOMATICALLY CONFIGURED, BUT USING\n" + "THIS CONFIGURATION TOOL YOU CAN\n" + "OVERRIDE THE DEFAULT BUTTON MAPPINGS\n" + "(THIS WILL NOT AFFECT THE HELP PROMPTS)\n" + "CONTINUE?"; + } + else { + message = "THE KEYBOARD AND CONTROLLERS ARE AUTOMATICALLY\n" + "CONFIGURED, BUT USING THIS CONFIGURATION TOOL\n" + "YOU CAN OVERRIDE THE DEFAULT BUTTON MAPPINGS\n" + "(THIS WILL NOT AFFECT THE HELP PROMPTS)\n" + "CONTINUE?"; + } Window* window {mWindow}; window->pushGui(new GuiMsgBox( @@ -1228,14 +1239,15 @@ void GuiMenu::openOtherOptions() ViewController::getInstance()->reloadAll(); mWindow->invalidateCachedBackground(); }; - rowMediaDir.makeAcceptInputHandler([this, titleMediaDir, mediaDirectoryStaticText, + rowMediaDir.makeAcceptInputHandler([this, s, titleMediaDir, mediaDirectoryStaticText, defaultDirectoryText, initValueMediaDir, updateValMediaDir, multiLineMediaDir] { if (Settings::getInstance()->getBool("VirtualKeyboard")) { mWindow->pushGui(new GuiTextEditKeyboardPopup( - getHelpStyle(), titleMediaDir, Settings::getInstance()->getString("MediaDirectory"), - updateValMediaDir, multiLineMediaDir, "SAVE", "SAVE CHANGES?", - mediaDirectoryStaticText, defaultDirectoryText, "load default directory")); + getHelpStyle(), s->getMenu().getPosition().y, titleMediaDir, + Settings::getInstance()->getString("MediaDirectory"), updateValMediaDir, + multiLineMediaDir, "SAVE", "SAVE CHANGES?", mediaDirectoryStaticText, + defaultDirectoryText, "load default directory")); } else { mWindow->pushGui(new GuiTextEditPopup( diff --git a/es-app/src/guis/GuiMetaDataEd.cpp b/es-app/src/guis/GuiMetaDataEd.cpp index 63428093b..a2cde562a 100644 --- a/es-app/src/guis/GuiMetaDataEd.cpp +++ b/es-app/src/guis/GuiMetaDataEd.cpp @@ -42,7 +42,8 @@ GuiMetaDataEd::GuiMetaDataEd(MetaDataList* md, std::function saveCallback, std::function clearGameFunc, std::function deleteGameFunc) - : mBackground {":/graphics/frame.svg"} + : mRenderer {Renderer::getInstance()} + , mBackground {":/graphics/frame.svg"} , mGrid {glm::ivec2 {2, 6}} , mScraperParams {scraperParams} , mControllerBadges {BadgeComponent::getGameControllers()} @@ -160,7 +161,7 @@ GuiMetaDataEd::GuiMetaDataEd(MetaDataList* md, } case MD_RATING: { auto spacer = std::make_shared(); - spacer->setSize(Renderer::getScreenWidth() * 0.0025f, 0.0f); + spacer->setSize(mRenderer->getScreenWidth() * 0.0025f, 0.0f); row.addElement(spacer, false); ed = std::make_shared(true, true); @@ -176,7 +177,7 @@ GuiMetaDataEd::GuiMetaDataEd(MetaDataList* md, } case MD_DATE: { auto spacer = std::make_shared(); - spacer->setSize(Renderer::getScreenWidth() * 0.0025f, 0.0f); + spacer->setSize(mRenderer->getScreenWidth() * 0.0025f, 0.0f); row.addElement(spacer, false); ed = std::make_shared(true); @@ -195,7 +196,7 @@ GuiMetaDataEd::GuiMetaDataEd(MetaDataList* md, row.addElement(ed, true); auto spacer = std::make_shared(); - spacer->setSize(Renderer::getScreenWidth() * 0.005f, 0.0f); + spacer->setSize(mRenderer->getScreenWidth() * 0.005f, 0.0f); row.addElement(spacer, false); auto bracket = std::make_shared(); @@ -258,9 +259,9 @@ GuiMetaDataEd::GuiMetaDataEd(MetaDataList* md, s->addRow(row, false); } - float aspectValue {1.778f / Renderer::getScreenAspectRatio()}; - float maxWidthModifier {glm::clamp(0.64f * aspectValue, 0.42f, 0.92f)}; - float maxWidth {Renderer::getScreenWidth() * maxWidthModifier}; + const float aspectValue {1.778f / mRenderer->getScreenAspectRatio()}; + const float maxWidthModifier {glm::clamp(0.64f * aspectValue, 0.42f, 0.92f)}; + const float maxWidth {mRenderer->getScreenWidth() * maxWidthModifier}; s->setMenuSize(glm::vec2 {maxWidth, s->getMenuSize().y}); s->setMenuPosition( @@ -277,7 +278,7 @@ GuiMetaDataEd::GuiMetaDataEd(MetaDataList* md, row.addElement(ed, true); auto spacer = std::make_shared(); - spacer->setSize(Renderer::getScreenWidth() * 0.005f, 0.0f); + spacer->setSize(mRenderer->getScreenWidth() * 0.005f, 0.0f); row.addElement(spacer, false); auto bracket = std::make_shared(); @@ -389,10 +390,10 @@ GuiMetaDataEd::GuiMetaDataEd(MetaDataList* md, s->addRow(row, false); } - const float aspectValue {1.778f / Renderer::getScreenAspectRatio()}; + const float aspectValue {1.778f / mRenderer->getScreenAspectRatio()}; const float maxWidthModifier { glm::clamp(0.64f * aspectValue, 0.42f, 0.92f)}; - const float maxWidth {static_cast(Renderer::getScreenWidth()) * + const float maxWidth {static_cast(mRenderer->getScreenWidth()) * maxWidthModifier}; s->setMenuSize(glm::vec2 {maxWidth, s->getMenuSize().y}); @@ -413,7 +414,7 @@ GuiMetaDataEd::GuiMetaDataEd(MetaDataList* md, row.addElement(ed, true); auto spacer = std::make_shared(); - spacer->setSize(Renderer::getScreenWidth() * 0.005f, 0.0f); + spacer->setSize(mRenderer->getScreenWidth() * 0.005f, 0.0f); row.addElement(spacer, false); auto bracket = std::make_shared(); @@ -510,9 +511,9 @@ GuiMetaDataEd::GuiMetaDataEd(MetaDataList* md, s->addRow(row, false); } - float aspectValue {1.778f / Renderer::getScreenAspectRatio()}; - float maxWidthModifier {glm::clamp(0.64f * aspectValue, 0.42f, 0.92f)}; - float maxWidth {Renderer::getScreenWidth() * maxWidthModifier}; + const float aspectValue {1.778f / mRenderer->getScreenAspectRatio()}; + const float maxWidthModifier {glm::clamp(0.64f * aspectValue, 0.42f, 0.92f)}; + const float maxWidth {mRenderer->getScreenWidth() * maxWidthModifier}; s->setMenuSize(glm::vec2 {maxWidth, s->getMenuSize().y}); s->setMenuPosition( @@ -529,7 +530,7 @@ GuiMetaDataEd::GuiMetaDataEd(MetaDataList* md, row.addElement(ed, true); auto spacer = std::make_shared(); - spacer->setSize(Renderer::getScreenWidth() * 0.005f, 0.0f); + spacer->setSize(mRenderer->getScreenWidth() * 0.005f, 0.0f); row.addElement(spacer, false); auto bracket = std::make_shared(); @@ -586,9 +587,11 @@ GuiMetaDataEd::GuiMetaDataEd(MetaDataList* md, if (Settings::getInstance()->getBool("VirtualKeyboard")) { row.makeAcceptInputHandler([this, title, ed, updateVal, multiLine] { + const float verticalPosition { + mRenderer->getIsVerticalOrientation() ? mPosition.y : 0.0f}; mWindow->pushGui(new GuiTextEditKeyboardPopup( - getHelpStyle(), title, ed->getValue(), updateVal, multiLine, "apply", - "APPLY CHANGES?", "", "")); + getHelpStyle(), verticalPosition, title, ed->getValue(), updateVal, + multiLine, "apply", "APPLY CHANGES?", "", "")); }); } else { @@ -699,7 +702,9 @@ GuiMetaDataEd::GuiMetaDataEd(MetaDataList* md, mGrid.setEntry(mButtons, glm::ivec2 {0, 5}, true, false, glm::ivec2 {2, 1}); // Resize + center. - float width {std::min(Renderer::getScreenHeight() * 1.05f, Renderer::getScreenWidth() * 0.90f)}; + float width {std::min(mRenderer->getScreenHeight() * 1.05f, + mRenderer->getScreenWidth() * + (mRenderer->getIsVerticalOrientation() ? 0.95f : 0.90f))}; // Set height explicitly to ten rows for the component list. float height {mList->getRowHeight(0) * 10.0f + mTitle->getSize().y + mSubtitle->getSize().y + @@ -723,8 +728,8 @@ void GuiMetaDataEd::onSizeChanged() mGrid.setSize(mSize); mBackground.fitTo(mSize, glm::vec3 {}, glm::vec2 {-32.0f, -32.0f}); - setPosition((Renderer::getScreenWidth() - mSize.x) / 2.0f, - (Renderer::getScreenHeight() - mSize.y) / 2.0f); + setPosition((mRenderer->getScreenWidth() - mSize.x) / 2.0f, + (mRenderer->getScreenHeight() - mSize.y) / 2.0f); // Add some extra margins to the file/folder name. const float newSizeX {mSize.x * 0.96f}; diff --git a/es-app/src/guis/GuiMetaDataEd.h b/es-app/src/guis/GuiMetaDataEd.h index f1a5c6a38..762c2f63b 100644 --- a/es-app/src/guis/GuiMetaDataEd.h +++ b/es-app/src/guis/GuiMetaDataEd.h @@ -46,6 +46,7 @@ private: void fetchDone(const ScraperSearchResult& result); void close(); + Renderer* mRenderer; NinePatchComponent mBackground; ComponentGrid mGrid; diff --git a/es-app/src/guis/GuiScraperSearch.cpp b/es-app/src/guis/GuiScraperSearch.cpp index 4978c3a1c..6d91c7f35 100644 --- a/es-app/src/guis/GuiScraperSearch.cpp +++ b/es-app/src/guis/GuiScraperSearch.cpp @@ -923,8 +923,8 @@ void GuiScraperSearch::openInputScreen(ScraperSearchParams& params) searchString = Utils::String::replace(searchString, "_", " "); if (Settings::getInstance()->getBool("VirtualKeyboard")) { - mWindow->pushGui(new GuiTextEditKeyboardPopup(getHelpStyle(), "REFINE SEARCH", searchString, - searchForFunc, false, "SEARCH", + mWindow->pushGui(new GuiTextEditKeyboardPopup(getHelpStyle(), 0.0f, "REFINE SEARCH", + searchString, searchForFunc, false, "SEARCH", "SEARCH USING REFINED NAME?")); } else { diff --git a/es-app/src/guis/GuiSettings.cpp b/es-app/src/guis/GuiSettings.cpp index 5b541d8dc..7a89012ca 100644 --- a/es-app/src/guis/GuiSettings.cpp +++ b/es-app/src/guis/GuiSettings.cpp @@ -23,7 +23,8 @@ #include GuiSettings::GuiSettings(std::string title) - : mMenu {title} + : mRenderer {Renderer::getInstance()} + , mMenu {title} , mGoToSystem {nullptr} , mNeedsSaving {false} , mNeedsCollectionsUpdate {false} @@ -213,12 +214,13 @@ void GuiSettings::addEditableTextComponent(const std::string label, row.makeAcceptInputHandler([this, label, ed, updateVal, isPassword] { // Never display the value if it's a password, instead set it to blank. if (isPassword) - mWindow->pushGui(new GuiTextEditKeyboardPopup(getHelpStyle(), label, "", updateVal, - false, "SAVE", "SAVE CHANGES?")); + mWindow->pushGui( + new GuiTextEditKeyboardPopup(getHelpStyle(), getMenu().getPosition().y, label, + "", updateVal, false, "SAVE", "SAVE CHANGES?")); else - mWindow->pushGui(new GuiTextEditKeyboardPopup(getHelpStyle(), label, ed->getValue(), - updateVal, false, "SAVE", - "SAVE CHANGES?")); + mWindow->pushGui(new GuiTextEditKeyboardPopup( + getHelpStyle(), getMenu().getPosition().y, label, ed->getValue(), updateVal, + false, "SAVE", "SAVE CHANGES?")); }); } else { diff --git a/es-app/src/guis/GuiSettings.h b/es-app/src/guis/GuiSettings.h index 1388818df..8a8fdeffb 100644 --- a/es-app/src/guis/GuiSettings.h +++ b/es-app/src/guis/GuiSettings.h @@ -64,6 +64,7 @@ public: HelpStyle getHelpStyle() override { return ViewController::getInstance()->getViewHelpStyle(); } private: + Renderer* mRenderer; MenuComponent mMenu; std::vector> mSaveFuncs; SystemData* mGoToSystem; diff --git a/es-app/src/views/ViewController.cpp b/es-app/src/views/ViewController.cpp index 049a06b48..f15c79c05 100644 --- a/es-app/src/views/ViewController.cpp +++ b/es-app/src/views/ViewController.cpp @@ -12,6 +12,7 @@ #include "views/ViewController.h" +#include "CollectionSystemsManager.h" #include "FileFilterIndex.h" #include "InputManager.h" #include "Log.h" @@ -59,11 +60,11 @@ ViewController* ViewController::getInstance() void ViewController::invalidSystemsFileDialog() { - std::string errorMessage = "COULDN'T PARSE THE SYSTEMS CONFIGURATION FILE.\n" - "IF YOU HAVE A CUSTOMIZED es_systems.xml FILE, THEN\n" - "SOMETHING IS LIKELY WRONG WITH YOUR XML SYNTAX.\n" - "IF YOU DON'T HAVE A CUSTOM SYSTEMS FILE, THEN THE\n" - "EMULATIONSTATION INSTALLATION IS BROKEN. SEE THE\n" + std::string errorMessage = "COULDN'T PARSE THE SYSTEMS CONFIGURATION FILE. " + "IF YOU HAVE A CUSTOMIZED es_systems.xml FILE, THEN " + "SOMETHING IS LIKELY WRONG WITH YOUR XML SYNTAX. " + "IF YOU DON'T HAVE A CUSTOM SYSTEMS FILE, THEN THE " + "EMULATIONSTATION INSTALLATION IS BROKEN. SEE THE " "APPLICATION LOG FILE es_log.txt FOR ADDITIONAL INFO."; mWindow->pushGui(new GuiMsgBox( @@ -78,11 +79,11 @@ void ViewController::invalidSystemsFileDialog() void ViewController::noGamesDialog() { - mNoGamesErrorMessage = "NO GAME FILES WERE FOUND. EITHER PLACE YOUR GAMES IN\n" - "THE CURRENTLY CONFIGURED ROM DIRECTORY OR CHANGE\n" - "ITS PATH USING THE BUTTON BELOW. OPTIONALLY THE ROM\n" - "DIRECTORY STRUCTURE CAN BE GENERATED WHICH WILL\n" - "CREATE A TEXT FILE FOR EACH SYSTEM PROVIDING SOME\n" + mNoGamesErrorMessage = "NO GAME FILES WERE FOUND. EITHER PLACE YOUR GAMES IN " + "THE CURRENTLY CONFIGURED ROM DIRECTORY OR CHANGE " + "ITS PATH USING THE BUTTON BELOW. OPTIONALLY THE ROM " + "DIRECTORY STRUCTURE CAN BE GENERATED WHICH WILL " + "CREATE A TEXT FILE FOR EACH SYSTEM PROVIDING SOME " "INFORMATION SUCH AS THE SUPPORTED FILE EXTENSIONS.\n" "THIS IS THE CURRENTLY CONFIGURED ROM DIRECTORY:\n"; @@ -103,7 +104,7 @@ void ViewController::noGamesDialog() #endif if (Settings::getInstance()->getBool("VirtualKeyboard")) { mWindow->pushGui(new GuiTextEditKeyboardPopup( - HelpStyle(), "ENTER ROM DIRECTORY PATH", currentROMDirectory, + HelpStyle(), 0.0f, "ENTER ROM DIRECTORY PATH", currentROMDirectory, [this](const std::string& newROMDirectory) { Settings::getInstance()->setString("ROMDirectory", Utils::String::trim(newROMDirectory)); diff --git a/es-core/src/guis/GuiTextEditKeyboardPopup.cpp b/es-core/src/guis/GuiTextEditKeyboardPopup.cpp index bc0f9c089..3c2570123 100644 --- a/es-core/src/guis/GuiTextEditKeyboardPopup.cpp +++ b/es-core/src/guis/GuiTextEditKeyboardPopup.cpp @@ -77,6 +77,7 @@ std::vector> kbLastRowLoad { GuiTextEditKeyboardPopup::GuiTextEditKeyboardPopup( const HelpStyle& helpstyle, + const float verticalPosition, const std::string& title, const std::string& initValue, const std::function& okCallback, @@ -104,6 +105,7 @@ GuiTextEditKeyboardPopup::GuiTextEditKeyboardPopup( , mDeleteRepeat {false} , mShift {false} , mAlt {false} + , mVerticalPosition {verticalPosition} , mDeleteRepeatTimer {0} , mNavigationRepeatTimer {0} , mNavigationRepeatDirX {0} @@ -129,7 +131,7 @@ GuiTextEditKeyboardPopup::GuiTextEditKeyboardPopup( mHorizontalKeyCount = static_cast(kbLayout[0].size()); mKeyboardGrid = std::make_shared( - glm::ivec2(mHorizontalKeyCount, static_cast(kbLayout.size()) / 3)); + glm::ivec2 {mHorizontalKeyCount, static_cast(kbLayout.size()) / 3}); mText = std::make_shared(); mText->setValue(initValue); @@ -137,7 +139,7 @@ GuiTextEditKeyboardPopup::GuiTextEditKeyboardPopup( // Header. mGrid.setEntry(mTitle, glm::ivec2 {0, 0}, false, true); - int yPos = 1; + int yPos {1}; if (mComplexMode) { mInfoString = std::make_shared(infoString, Font::get(FONT_SIZE_MEDIUM), @@ -157,19 +159,19 @@ GuiTextEditKeyboardPopup::GuiTextEditKeyboardPopup( std::vector>> buttonList; // Create keyboard. - for (int i = 0; i < static_cast(kbLayout.size()) / 4; ++i) { + for (int i {0}; i < static_cast(kbLayout.size()) / 4; ++i) { std::vector> buttons; - for (int j = 0; j < static_cast(kbLayout[i].size()); ++j) { - std::string lower = kbLayout[4 * i][j]; + for (int j {0}; j < static_cast(kbLayout[i].size()); ++j) { + std::string lower {kbLayout[4 * i][j]}; if (lower.empty() || lower == "-rowspan-" || lower == "-colspan-") continue; - std::string upper = kbLayout[4 * i + 1][j]; - std::string alted = kbLayout[4 * i + 2][j]; - std::string altshifted = kbLayout[4 * i + 3][j]; + std::string upper {kbLayout[4 * i + 1][j]}; + std::string alted {kbLayout[4 * i + 2][j]}; + std::string altshifted {kbLayout[4 * i + 3][j]}; - std::shared_ptr button = nullptr; + std::shared_ptr button; if (lower == "DEL") { lower = DELETE_SYMBOL; @@ -211,12 +213,12 @@ GuiTextEditKeyboardPopup::GuiTextEditKeyboardPopup( } button->setPadding( - glm::vec4(BUTTON_GRID_HORIZ_PADDING / 4.0f, BUTTON_GRID_HORIZ_PADDING / 4.0f, - BUTTON_GRID_HORIZ_PADDING / 4.0f, BUTTON_GRID_HORIZ_PADDING / 4.0f)); + glm::vec4 {BUTTON_GRID_HORIZ_PADDING / 4.0f, BUTTON_GRID_HORIZ_PADDING / 4.0f, + BUTTON_GRID_HORIZ_PADDING / 4.0f, BUTTON_GRID_HORIZ_PADDING / 4.0f}); buttons.push_back(button); - int colSpan = 1; - for (int cs = j + 1; cs < static_cast(kbLayout[i].size()); ++cs) { + int colSpan {1}; + for (int cs {j + 1}; cs < static_cast(kbLayout[i].size()); ++cs) { if (std::string(kbLayout[4 * i][cs]) == "-colspan-") ++colSpan; else @@ -224,7 +226,7 @@ GuiTextEditKeyboardPopup::GuiTextEditKeyboardPopup( } int rowSpan = 1; - for (int cs = (4 * i) + 4; cs < static_cast(kbLayout.size()); cs += 4) { + for (int cs {(4 * i) + 4}; cs < static_cast(kbLayout.size()); cs += 4) { if (std::string(kbLayout[cs][j]) == "-rowspan-") ++rowSpan; else @@ -240,7 +242,7 @@ GuiTextEditKeyboardPopup::GuiTextEditKeyboardPopup( mGrid.setEntry(mKeyboardGrid, glm::ivec2 {0, yPos + 1}, true, true, glm::ivec2 {1, 4}); - float textHeight = mText->getFont()->getHeight(); + float textHeight {mText->getFont()->getHeight()}; // If the multiLine option has been set, then include three lines of text on screen. if (multiLine) { textHeight *= 3.0f; @@ -268,15 +270,20 @@ GuiTextEditKeyboardPopup::GuiTextEditKeyboardPopup( // Adapt width to the geometry of the display. The 1.778 aspect ratio is the 16:9 reference. float aspectValue {1.778f / mRenderer->getScreenAspectRatio()}; - float width {glm::clamp(0.78f * aspectValue, 0.35f, 0.90f) * mRenderer->getScreenWidth()}; + const float maxWidthMultiplier {mRenderer->getIsVerticalOrientation() ? 0.95f : 0.90f}; + float width {glm::clamp(0.78f * aspectValue, 0.35f, maxWidthMultiplier) * + mRenderer->getScreenWidth()}; // The combination of multiLine and complex mode is not supported as there is currently // no need for that. if (mMultiLine) { setSize(width, KEYBOARD_HEIGHT + textHeight - mText->getFont()->getHeight()); - setPosition((mRenderer->getScreenWidth() - mSize.x) / 2.0f, - (mRenderer->getScreenHeight() - mSize.y) / 2.0f); + if (mVerticalPosition == 0.0f) + setPosition((mRenderer->getScreenWidth() - mSize.x) / 2.0f, + (mRenderer->getScreenHeight() - mSize.y) / 2.0f); + else + setPosition((mRenderer->getScreenWidth() - mSize.x) / 2.0f, mVerticalPosition); } else { if (mComplexMode) @@ -284,8 +291,11 @@ GuiTextEditKeyboardPopup::GuiTextEditKeyboardPopup( else setSize(width, KEYBOARD_HEIGHT); - setPosition((mRenderer->getScreenWidth() - mSize.x) / 2.0f, - (mRenderer->getScreenHeight() - mSize.y) / 2.0f); + if (mVerticalPosition == 0.0f) + setPosition((mRenderer->getScreenWidth() - mSize.x) / 2.0f, + (mRenderer->getScreenHeight() - mSize.y) / 2.0f); + else + setPosition((mRenderer->getScreenWidth() - mSize.x) / 2.0f, mVerticalPosition); } if (!multiLine) @@ -294,7 +304,7 @@ GuiTextEditKeyboardPopup::GuiTextEditKeyboardPopup( void GuiTextEditKeyboardPopup::onSizeChanged() { - mBackground.fitTo(mSize, glm::vec3 {}, glm::vec2 {-32.0f, -32.0f}); + mBackground.fitTo(mSize, glm::vec3 {0.0f, 0.0f, 0.0f}, glm::vec2 {-32.0f, -32.0f}); mText->setSize(mSize.x - KEYBOARD_PADDINGX - KEYBOARD_PADDINGX, mText->getSize().y); // Update grid. @@ -345,8 +355,8 @@ bool GuiTextEditKeyboardPopup::input(InputConfig* config, Input input) } // Ignore whatever key is mapped to the back button so it can be used for text input. - bool keyboardBack {config->getDeviceId() == DEVICE_KEYBOARD && mText->isEditing() && - config->isMappedLike("b", input)}; + const bool keyboardBack {config->getDeviceId() == DEVICE_KEYBOARD && mText->isEditing() && + config->isMappedLike("b", input)}; // Pressing back (or the escape key if using keyboard input) closes us. if ((config->getDeviceId() == DEVICE_KEYBOARD && input.value && input.id == SDLK_ESCAPE) || @@ -391,7 +401,7 @@ bool GuiTextEditKeyboardPopup::input(InputConfig* config, Input input) mDeleteRepeat = true; mDeleteRepeatTimer = -(DELETE_REPEAT_START_DELAY - DELETE_REPEAT_SPEED); - bool editing = mText->isEditing(); + const bool editing {mText->isEditing()}; if (!editing) mText->startEditing(); @@ -410,7 +420,7 @@ bool GuiTextEditKeyboardPopup::input(InputConfig* config, Input input) // Right shoulder button inserts a blank space. if (config->isMappedTo("rightshoulder", input) && input.value) { - bool editing = mText->isEditing(); + const bool editing {mText->isEditing()}; if (!editing) mText->startEditing(); @@ -527,7 +537,7 @@ void GuiTextEditKeyboardPopup::updateDeleteRepeat(int deltaTime) mDeleteRepeatTimer += deltaTime; while (mDeleteRepeatTimer >= DELETE_REPEAT_SPEED) { - bool editing = mText->isEditing(); + bool editing {mText->isEditing()}; if (!editing) mText->startEditing(); @@ -595,7 +605,7 @@ void GuiTextEditKeyboardPopup::shiftKeys() } else { for (auto& kb : mKeyboardButtons) { - const std::string& text = mShift ? kb.shiftedKey : kb.key; + const std::string& text {mShift ? kb.shiftedKey : kb.key}; auto sz = kb.button->getSize(); kb.button->setText(text, text, false); kb.button->setSize(sz); @@ -628,7 +638,7 @@ void GuiTextEditKeyboardPopup::altKeys() } else { for (auto& kb : mKeyboardButtons) { - const std::string& text = mAlt ? kb.altedKey : kb.key; + const std::string& text {mAlt ? kb.altedKey : kb.key}; auto sz = kb.button->getSize(); kb.button->setText(text, text, false); kb.button->setSize(sz); @@ -639,7 +649,7 @@ void GuiTextEditKeyboardPopup::altKeys() void GuiTextEditKeyboardPopup::altShiftKeys() { for (auto& kb : mKeyboardButtons) { - const std::string& text = kb.altshiftedKey; + const std::string& text {kb.altshiftedKey}; auto sz = kb.button->getSize(); kb.button->setText(text, text, false); kb.button->setSize(sz); @@ -652,7 +662,7 @@ std::shared_ptr GuiTextEditKeyboardPopup::makeButton( const std::string& altedKey, const std::string& altshiftedKey) { - std::shared_ptr button = std::make_shared( + std::shared_ptr button {std::make_shared( key, key, [this, key, shiftedKey, altedKey, altshiftedKey] { if (key == (OK_SYMBOL) || key.find("OK") != std::string::npos) { @@ -702,9 +712,9 @@ std::shared_ptr GuiTextEditKeyboardPopup::makeButton( mText->stopEditing(); }, - false, true); + false, true)}; - KeyboardButton kb(button, key, shiftedKey, altedKey, altshiftedKey); + KeyboardButton kb {button, key, shiftedKey, altedKey, altshiftedKey}; mKeyboardButtons.push_back(kb); return button; } diff --git a/es-core/src/guis/GuiTextEditKeyboardPopup.h b/es-core/src/guis/GuiTextEditKeyboardPopup.h index a1785f458..9fcd28db9 100644 --- a/es-core/src/guis/GuiTextEditKeyboardPopup.h +++ b/es-core/src/guis/GuiTextEditKeyboardPopup.h @@ -19,6 +19,7 @@ class GuiTextEditKeyboardPopup : public GuiComponent { public: GuiTextEditKeyboardPopup(const HelpStyle& helpstyle, + const float verticalPosition, const std::string& title, const std::string& initValue, const std::function& okCallback, @@ -101,6 +102,8 @@ private: bool mShift; bool mAlt; + float mVerticalPosition; + int mHorizontalKeyCount; int mDeleteRepeatTimer; int mNavigationRepeatTimer;