From 4ef36a79817b8bce87de740b9b73a9a3c9880a48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 23 Mar 2021 23:41:16 +0100 Subject: [PATCH] Add a setting for choosing background animation. Off and Floating Symbols are the only choices so far. --- Core/Config.cpp | 2 + Core/Config.h | 6 +++ UI/GameSettingsScreen.cpp | 28 +++++++------- UI/MiscScreens.cpp | 81 ++++++++++++++++++++++++++------------- 4 files changed, 77 insertions(+), 40 deletions(-) diff --git a/Core/Config.cpp b/Core/Config.cpp index 16a75c3a41..f8a70ae981 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -494,6 +494,8 @@ static ConfigSetting generalSettings[] = { #endif ConfigSetting("InternalScreenRotation", &g_Config.iInternalScreenRotation, ROTATION_LOCKED_HORIZONTAL), + ConfigSetting("BackgroundAnimation", &g_Config.iBackgroundAnimation, 1, true, false), + #if defined(USING_WIN_UI) ConfigSetting("TopMost", &g_Config.bTopMost, false), ConfigSetting("WindowX", &g_Config.iWindowX, -1), // -1 tells us to center the window. diff --git a/Core/Config.h b/Core/Config.h index 061b90f241..9589ffe6e6 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -38,6 +38,11 @@ enum ChatPositions { CENTER_RIGHT = 7, }; +enum class BackgroundAnimation { + OFF = 0, + FLOATING_SYMBOLS = 1, +}; + namespace http { class Download; class Downloader; @@ -239,6 +244,7 @@ public: bool bShowIDOnGameIcon; float fGameGridScale; bool bShowOnScreenMessages; + int iBackgroundAnimation; // enum BackgroundAnimation // TODO: Maybe move to a separate theme system. uint32_t uItemStyleFg; diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index fd0e821004..7ad03db35d 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -860,9 +860,23 @@ void GameSettingsScreen::CreateViews() { systemSettingsScroll->Add(systemSettings); tabHolder->AddTab(ms->T("System"), systemSettingsScroll); - systemSettings->Add(new ItemHeader(sy->T("UI Language"))); // Should be renamed "UI"? + systemSettings->Add(new ItemHeader(sy->T("UI"))); systemSettings->Add(new Choice(dev->T("Language", "Language")))->OnClick.Handle(this, &GameSettingsScreen::OnLanguage); systemSettings->Add(new CheckBox(&g_Config.bUISound, sy->T("UI Sound"))); + const std::string bgPng = GetSysDirectory(DIRECTORY_SYSTEM) + "background.png"; + const std::string bgJpg = GetSysDirectory(DIRECTORY_SYSTEM) + "background.jpg"; + if (File::Exists(bgPng) || File::Exists(bgJpg)) { + backgroundChoice_ = systemSettings->Add(new Choice(sy->T("Clear UI background"))); + } else if (System_GetPropertyBool(SYSPROP_HAS_IMAGE_BROWSER)) { + backgroundChoice_ = systemSettings->Add(new Choice(sy->T("Set UI background..."))); + } else { + backgroundChoice_ = nullptr; + } + if (backgroundChoice_ != nullptr) { + backgroundChoice_->OnClick.Handle(this, &GameSettingsScreen::OnChangeBackground); + } + static const char *backgroundAnimations[] = { "No animation", "Floating Symbols" }; + systemSettings->Add(new PopupMultiChoice(&g_Config.iBackgroundAnimation, sy->T("UI background animation"), backgroundAnimations, 0, ARRAY_SIZE(backgroundAnimations), sy->GetName(), screenManager())); systemSettings->Add(new ItemHeader(sy->T("Help the PPSSPP team"))); enableReports_ = Reporting::IsEnabled(); @@ -906,18 +920,6 @@ void GameSettingsScreen::CreateViews() { } #endif systemSettings->Add(new CheckBox(&g_Config.bCheckForNewVersion, sy->T("VersionCheck", "Check for new versions of PPSSPP"))); - const std::string bgPng = GetSysDirectory(DIRECTORY_SYSTEM) + "background.png"; - const std::string bgJpg = GetSysDirectory(DIRECTORY_SYSTEM) + "background.jpg"; - if (File::Exists(bgPng) || File::Exists(bgJpg)) { - backgroundChoice_ = systemSettings->Add(new Choice(sy->T("Clear UI background"))); - } else if (System_GetPropertyBool(SYSPROP_HAS_IMAGE_BROWSER)) { - backgroundChoice_ = systemSettings->Add(new Choice(sy->T("Set UI background..."))); - } else { - backgroundChoice_ = nullptr; - } - if (backgroundChoice_ != nullptr) { - backgroundChoice_->OnClick.Handle(this, &GameSettingsScreen::OnChangeBackground); - } systemSettings->Add(new Choice(sy->T("Restore Default Settings")))->OnClick.Handle(this, &GameSettingsScreen::OnRestoreDefaultSettings); systemSettings->Add(new CheckBox(&g_Config.bEnableStateUndo, sy->T("Savestate slot backups"))); diff --git a/UI/MiscScreens.cpp b/UI/MiscScreens.cpp index 19bcc038ab..1e8271b9dd 100644 --- a/UI/MiscScreens.cpp +++ b/UI/MiscScreens.cpp @@ -73,7 +73,47 @@ static const uint32_t colors[4] = { static std::unique_ptr bgTexture; -static bool backgroundInited; +class Animation { +public: + virtual ~Animation() {} + virtual void Draw(UIContext &dc, double t, float alpha) = 0; +}; + +class FloatingSymbolsAnimation : public Animation { +public: + ~FloatingSymbolsAnimation() override {} + void Draw(UIContext &dc, double t, float alpha) override { + float xres = dc.GetBounds().w; + float yres = dc.GetBounds().h; + if (xbase[0] == 0.0f || last_xres != xres || last_yres != yres) { + GMRng rng; + for (int i = 0; i < 100; i++) { + xbase[i] = rng.F() * xres; + ybase[i] = rng.F() * yres; + } + last_xres = xres; + last_yres = yres; + } + + for (int i = 0; i < 100; i++) { + float x = xbase[i] + dc.GetBounds().x; + float y = ybase[i] + dc.GetBounds().y + 40 * cosf(i * 7.2f + t * 1.3f); + float angle = (float)sin(i + t); + int n = i & 3; + ui_draw2d.DrawImageRotated(symbols[n], x, y, 1.0f, angle, colorAlpha(colors[n], alpha * 0.1f)); + } + } +private: + float xbase[100] = { 0 }; + float ybase[100] = { 0 }; + float last_xres = 0; + float last_yres = 0; +}; + +// TODO: Add more styles. Remember to add to the enum in Config.cpp and the selector in GameSettings too. + +static BackgroundAnimation g_CurBackgroundAnimation = BackgroundAnimation::OFF; +static std::unique_ptr g_Animation; void UIBackgroundInit(UIContext &dc) { const std::string bgPng = GetSysDirectory(DIRECTORY_SYSTEM) + "background.png"; @@ -86,32 +126,22 @@ void UIBackgroundInit(UIContext &dc) { void UIBackgroundShutdown() { bgTexture.reset(nullptr); - backgroundInited = false; + g_Animation.reset(nullptr); } void DrawBackground(UIContext &dc, float alpha) { - if (!backgroundInited) { - UIBackgroundInit(dc); - backgroundInited = true; - } + if (g_CurBackgroundAnimation != (BackgroundAnimation)g_Config.iBackgroundAnimation) { + g_CurBackgroundAnimation = (BackgroundAnimation)g_Config.iBackgroundAnimation; - static float xbase[100] = {0}; - static float ybase[100] = {0}; - float xres = dc.GetBounds().w; - float yres = dc.GetBounds().h; - static int last_xres = 0; - static int last_yres = 0; - - if (xbase[0] == 0.0f || last_xres != xres || last_yres != yres) { - GMRng rng; - for (int i = 0; i < 100; i++) { - xbase[i] = rng.F() * xres; - ybase[i] = rng.F() * yres; + switch (g_CurBackgroundAnimation) { + case BackgroundAnimation::FLOATING_SYMBOLS: + g_Animation.reset(new FloatingSymbolsAnimation()); + break; + default: + g_Animation.reset(nullptr); } - last_xres = xres; - last_yres = yres; } - + uint32_t bgColor = whiteAlpha(alpha); if (bgTexture != nullptr) { @@ -135,12 +165,9 @@ void DrawBackground(UIContext &dc, float alpha) { #else double t = time_now_d(); #endif - for (int i = 0; i < 100; i++) { - float x = xbase[i] + dc.GetBounds().x; - float y = ybase[i] + dc.GetBounds().y + 40 * cosf(i * 7.2f + t * 1.3f); - float angle = (float)sin(i + t); - int n = i & 3; - ui_draw2d.DrawImageRotated(symbols[n], x, y, 1.0f, angle, colorAlpha(colors[n], alpha * 0.1f)); + + if (g_Animation) { + g_Animation->Draw(dc, t, alpha); } }