From 498136bbf832a177ea237b53403247d20ead6227 Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Sun, 29 Jun 2014 21:02:32 +0200 Subject: [PATCH] Switch to vertical layout automatically as the window is being resized Prevents ending up in the wrong layout on startup and being unable to fix it without restarting the emulator. --- UI/MainScreen.cpp | 12 +++++++++++- UI/MainScreen.h | 3 +++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index 5d08d9b92b..6aa0df5a2d 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -707,6 +707,7 @@ UI::EventReturn GameBrowser::NavigateClick(UI::EventParams &e) { MainScreen::MainScreen() : highlightProgress_(0.0f), prevHighlightProgress_(0.0f), backFromStore_(false), lockBackgroundAudio_(false) { System_SendMessage("event", "mainscreen"); SetBackgroundAudioGame(""); + lastVertical_ = UseVerticalLayout(); } MainScreen::~MainScreen() { @@ -721,7 +722,7 @@ void MainScreen::CreateViews() { using namespace UI; // Vertical mode is not finished. - bool vertical = dp_yres > dp_xres; + bool vertical = UseVerticalLayout(); I18NCategory *m = GetI18NCategory("MainMenu"); @@ -906,6 +907,15 @@ void MainScreen::sendMessage(const char *message, const char *value) { void MainScreen::update(InputState &input) { UIScreen::update(input); UpdateUIState(UISTATE_MENU); + bool vertical = UseVerticalLayout(); + if (vertical != lastVertical_) { + RecreateViews(); + lastVertical_ = vertical; + } +} + +bool MainScreen::UseVerticalLayout() const { + return dp_yres > dp_xres * 1.1f; } UI::EventReturn MainScreen::OnLoadFile(UI::EventParams &e) { diff --git a/UI/MainScreen.h b/UI/MainScreen.h index c3142ca685..76ed9ee00c 100644 --- a/UI/MainScreen.h +++ b/UI/MainScreen.h @@ -71,6 +71,9 @@ private: float prevHighlightProgress_; bool lockBackgroundAudio_; bool backFromStore_; + bool lastVertical_; + + bool UseVerticalLayout() const; }; class GamePauseScreen : public UIDialogScreenWithGameBackground {