Add a fullscreen toggle button to the main screen (Windows-only for now)

This commit is contained in:
Henrik Rydgård 2021-01-08 20:05:43 +01:00
parent 75be1e999d
commit 3c6f21173c
3 changed files with 40 additions and 3 deletions

View File

@ -527,6 +527,9 @@ public:
paddingW_ = w;
paddingH_ = h;
}
void SetImageID(ImageID imageID) {
imageID_ = imageID;
}
// Needed an extra small button...
void SetScale(float f) {

View File

@ -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 <sstream>
@ -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()) {

View File

@ -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<GameBrowser *> gameBrowsers_;