From 3c6f21173c66a3d4cf75d9715cb55a2094533489 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 8 Jan 2021 20:05:43 +0100 Subject: [PATCH] Add a fullscreen toggle button to the main screen (Windows-only for now) --- Common/UI/View.h | 3 +++ UI/MainScreen.cpp | 38 +++++++++++++++++++++++++++++++++++--- UI/MainScreen.h | 2 ++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/Common/UI/View.h b/Common/UI/View.h index 97c5c10513..4f779fa1f4 100644 --- a/Common/UI/View.h +++ b/Common/UI/View.h @@ -527,6 +527,9 @@ public: paddingW_ = w; paddingH_ = h; } + void SetImageID(ImageID imageID) { + imageID_ = imageID; + } // Needed an extra small button... void SetScale(float f) { diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index 643c0540af..c78120eacf 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -33,6 +33,7 @@ #include "Common/Data/Encoding/Utf8.h" #include "Common/File/PathBrowser.h" #include "Common/Math/curves.h" +#include "Common/Net/URL.h" #include "Common/File/FileUtil.h" #include "Common/TimeUtil.h" #include "Common/StringUtils.h" @@ -66,6 +67,8 @@ #ifdef _WIN32 // Unfortunate, for undef DrawText... #include "Common/CommonWindows.h" +// For fullscreen toggle +#include "Windows/MainWindow.h" #endif #include @@ -1099,9 +1102,10 @@ void MainScreen::CreateViews() { } logos->Add(new ImageView(ImageID("I_LOGO"), IS_DEFAULT, new LinearLayoutParams(Margins(-12, 0, 0, 0)))); -#if defined(USING_WIN_UI) || defined(USING_QT_UI) || PPSSPP_PLATFORM(UWP) +#if PPSSPP_PLATFORM(WINDOWS) && !PPSSPP_PLATFORM(UWP) if (!g_Config.bFullScreen) { - logos->Add(new ImageView(ImageID("I_FULLSCREEN"), IS_DEFAULT, new AnchorLayoutParams(64, 64, NONE, 0, 0, NONE, false))); + fullscreenButton_ = logos->Add(new Button(ImageID(g_Config.bFullScreen ? "I_RESTORE" : "I_FULLSCREEN"), new AnchorLayoutParams(48, 48, NONE, 0, 0, NONE, false))); + fullscreenButton_->OnClick.Handle(this, &MainScreen::OnFullScreenToggle); } #endif @@ -1210,9 +1214,26 @@ void MainScreen::sendMessage(const char *message, const char *value) { LaunchFile(screenManager(), std::string(value)); } if (!strcmp(message, "browse_folderSelect")) { + std::string filename; +#if PPSSPP_PLATFORM(ANDROID) + std::string url = value; + const char *prefix = "content://com.android.externalstorage.documents/tree/"; + if (startsWith(url, prefix)) { + url = url.substr(strlen(prefix)); + url = UriDecode(url); + } else { + // It's not gonna work. + // TODO: Show an error message? + return; + } + filename = url; +#else + filename = value; +#endif + INFO_LOG(SYSTEM, "Got folder: %s", filename.c_str()); int tab = tabHolder_->GetCurrentTab(); if (tab >= 0 && tab < (int)gameBrowsers_.size()) { - gameBrowsers_[tab]->SetPath(value); + gameBrowsers_[tab]->SetPath(filename); } } } @@ -1245,6 +1266,17 @@ UI::EventReturn MainScreen::OnLoadFile(UI::EventParams &e) { return UI::EVENT_DONE; } +UI::EventReturn MainScreen::OnFullScreenToggle(UI::EventParams &e) { + if (fullscreenButton_) { + fullscreenButton_->SetImageID(ImageID(!g_Config.bFullScreen ? "I_RESTORE" : "I_FULLSCREEN")); + } + // TODO: Need to abstract this more. +#if PPSSPP_PLATFORM(WINDOWS) && !PPSSPP_PLATFORM(UWP) + MainWindow::SendToggleFullscreen(!g_Config.bFullScreen); +#endif + return UI::EVENT_DONE; +} + void MainScreen::DrawBackground(UIContext &dc) { UIScreenWithBackground::DrawBackground(dc); if (highlightedGamePath_.empty() && prevHighlightedGamePath_.empty()) { diff --git a/UI/MainScreen.h b/UI/MainScreen.h index 86c22dd529..2bc2572533 100644 --- a/UI/MainScreen.h +++ b/UI/MainScreen.h @@ -125,9 +125,11 @@ protected: UI::EventReturn OnDownloadUpgrade(UI::EventParams &e); UI::EventReturn OnDismissUpgrade(UI::EventParams &e); UI::EventReturn OnAllowStorage(UI::EventParams &e); + UI::EventReturn OnFullScreenToggle(UI::EventParams &e); UI::LinearLayout *upgradeBar_ = nullptr; UI::TabHolder *tabHolder_ = nullptr; + UI::Button *fullscreenButton_ = nullptr; std::string restoreFocusGamePath_; std::vector gameBrowsers_;