Skip to content

Commit

Permalink
Merge pull request #14313 from hrydgard/background-animation
Browse files Browse the repository at this point in the history
Add a setting for choosing background animation in PPSSPP's menus
  • Loading branch information
hrydgard committed Mar 23, 2021
2 parents 9435174 + 4ef36a7 commit a37ea1e
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 41 deletions.
2 changes: 2 additions & 0 deletions Core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions Core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ enum ChatPositions {
CENTER_RIGHT = 7,
};

enum class BackgroundAnimation {
OFF = 0,
FLOATING_SYMBOLS = 1,
};

namespace http {
class Download;
class Downloader;
Expand Down Expand Up @@ -239,6 +244,7 @@ struct Config {
bool bShowIDOnGameIcon;
float fGameGridScale;
bool bShowOnScreenMessages;
int iBackgroundAnimation; // enum BackgroundAnimation

// TODO: Maybe move to a separate theme system.
uint32_t uItemStyleFg;
Expand Down
28 changes: 15 additions & 13 deletions UI/GameSettingsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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")));
Expand Down
83 changes: 55 additions & 28 deletions UI/MiscScreens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,47 @@ static const uint32_t colors[4] = {

static std::unique_ptr<ManagedTexture> 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<Animation> g_Animation;

void UIBackgroundInit(UIContext &dc) {
const std::string bgPng = GetSysDirectory(DIRECTORY_SYSTEM) + "background.png";
Expand All @@ -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;
}

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;
if (g_CurBackgroundAnimation != (BackgroundAnimation)g_Config.iBackgroundAnimation) {
g_CurBackgroundAnimation = (BackgroundAnimation)g_Config.iBackgroundAnimation;

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) {
Expand All @@ -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);
}
}

Expand Down

0 comments on commit a37ea1e

Please sign in to comment.