mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Add bouncing icon background animation
This commit is contained in:
parent
963ccf22e1
commit
748e2e980e
3 changed files with 102 additions and 1 deletions
|
@ -150,6 +150,7 @@ enum class BackgroundAnimation {
|
||||||
RECENT_GAMES = 2,
|
RECENT_GAMES = 2,
|
||||||
WAVE = 3,
|
WAVE = 3,
|
||||||
MOVING_BACKGROUND = 4,
|
MOVING_BACKGROUND = 4,
|
||||||
|
BOUNCING_ICON = 5,
|
||||||
};
|
};
|
||||||
|
|
||||||
// iOS only
|
// iOS only
|
||||||
|
|
|
@ -1164,7 +1164,7 @@ void GameSettingsScreen::CreateSystemSettings(UI::ViewGroup *systemSettings) {
|
||||||
|
|
||||||
systemSettings->Add(new PopupMultiChoice(&g_Config.iNotificationPos, sy->T("Notification screen position"), positions, -1, ARRAY_SIZE(positions), I18NCat::DIALOG, screenManager()));
|
systemSettings->Add(new PopupMultiChoice(&g_Config.iNotificationPos, sy->T("Notification screen position"), positions, -1, ARRAY_SIZE(positions), I18NCat::DIALOG, screenManager()));
|
||||||
|
|
||||||
static const char *backgroundAnimations[] = { "No animation", "Floating symbols", "Recent games", "Waves", "Moving background" };
|
static const char *backgroundAnimations[] = { "No animation", "Floating symbols", "Recent games", "Waves", "Moving background", "Bouncing icon" };
|
||||||
systemSettings->Add(new PopupMultiChoice(&g_Config.iBackgroundAnimation, sy->T("UI background animation"), backgroundAnimations, 0, ARRAY_SIZE(backgroundAnimations), I18NCat::SYSTEM, screenManager()));
|
systemSettings->Add(new PopupMultiChoice(&g_Config.iBackgroundAnimation, sy->T("UI background animation"), backgroundAnimations, 0, ARRAY_SIZE(backgroundAnimations), I18NCat::SYSTEM, screenManager()));
|
||||||
|
|
||||||
PopupMultiChoiceDynamic *theme = systemSettings->Add(new PopupMultiChoiceDynamic(&g_Config.sThemeName, sy->T("Theme"), GetThemeInfoNames(), I18NCat::THEMES, screenManager()));
|
PopupMultiChoiceDynamic *theme = systemSettings->Add(new PopupMultiChoiceDynamic(&g_Config.sThemeName, sy->T("Theme"), GetThemeInfoNames(), I18NCat::THEMES, screenManager()));
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include "ppsspp_config.h"
|
#include "ppsspp_config.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <cmath>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
#include "Common/Render/DrawBuffer.h"
|
#include "Common/Render/DrawBuffer.h"
|
||||||
|
@ -288,6 +289,102 @@ private:
|
||||||
double nextT_ = -INTERVAL;
|
double nextT_ = -INTERVAL;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class BouncingIconAnimation : public Animation {
|
||||||
|
public:
|
||||||
|
void Draw(UIContext &dc, double t, float alpha, float x, float y, float z) override {
|
||||||
|
dc.Flush();
|
||||||
|
dc.Begin();
|
||||||
|
|
||||||
|
// Handle change in resolution.
|
||||||
|
float xres = dc.GetBounds().w;
|
||||||
|
float yres = dc.GetBounds().h;
|
||||||
|
if (last_xres != xres || last_yres != yres) {
|
||||||
|
Recalculate(xres, yres);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw the image.
|
||||||
|
float xpos = xbase + dc.GetBounds().x;
|
||||||
|
float ypos = ybase + dc.GetBounds().y;
|
||||||
|
ImageID icon = !color_ix && System_GetPropertyBool(SYSPROP_APP_GOLD) ? ImageID("I_ICONGOLD") : ImageID("I_ICON");
|
||||||
|
ui_draw2d.DrawImage(icon, xpos, ypos, scale, colors[color_ix], ALIGN_CENTER);
|
||||||
|
dc.Flush();
|
||||||
|
|
||||||
|
// Switch direction if within border.
|
||||||
|
bool should_recolor = true;
|
||||||
|
if (xbase > xres - border || xbase < border) {
|
||||||
|
xspeed *= -1.0f;
|
||||||
|
RandomizeColor();
|
||||||
|
should_recolor = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ybase > yres - border || ybase < border) {
|
||||||
|
yspeed *= -1.0f;
|
||||||
|
|
||||||
|
if (should_recolor) {
|
||||||
|
RandomizeColor();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Place to border if out of bounds.
|
||||||
|
if (xbase > xres - border) xbase = xres - border;
|
||||||
|
else if (xbase < border) xbase = border;
|
||||||
|
if (ybase > yres - border) ybase = yres - border;
|
||||||
|
else if (ybase < border) ybase = border;
|
||||||
|
|
||||||
|
// Update location.
|
||||||
|
xbase += xspeed;
|
||||||
|
ybase += yspeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static constexpr int COLOR_COUNT = 11;
|
||||||
|
static constexpr Color colors[COLOR_COUNT] = { 0xFFFFFFFF, 0xFFFFFF00, 0xFFFF0000, 0xFF00FF00, 0xFF00FF00,
|
||||||
|
0xFF00FFFF, 0xFFFF00FF, 0xFF4111D1, 0xFF3577F3, 0xFFAA77FF, 0xFF623B84 };
|
||||||
|
|
||||||
|
float xbase = 0.0f;
|
||||||
|
float ybase = 0.0f;
|
||||||
|
float last_xres = 0.0f;
|
||||||
|
float last_yres = 0.0f;
|
||||||
|
float xspeed = 1.0f;
|
||||||
|
float yspeed = 1.0f;
|
||||||
|
float scale = 1.0f;
|
||||||
|
float border = 35.0f;
|
||||||
|
int color_ix = 0;
|
||||||
|
int last_color_ix = -1;
|
||||||
|
GMRng rng;
|
||||||
|
|
||||||
|
void Recalculate(int xres, int yres) {
|
||||||
|
// First calculation.
|
||||||
|
if (last_color_ix == -1) {
|
||||||
|
xbase = xres / 2.0f;
|
||||||
|
ybase = yres / 2.0f;
|
||||||
|
last_color_ix = 0;
|
||||||
|
|
||||||
|
// Determine initial direction.
|
||||||
|
if ((int)(rng.F() * xres) % 2) xspeed *= -1.0f;
|
||||||
|
if ((int)(rng.F() * yres) % 2) yspeed *= -1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scale certain attributes to resolution.
|
||||||
|
scale = std::min(xres, yres) / 400.0f;
|
||||||
|
float speed = scale < 2.5f ? scale * 0.58f : scale * 0.46f;
|
||||||
|
xspeed = std::signbit(xspeed) ? speed * -1.0f : speed;
|
||||||
|
yspeed = std::signbit(yspeed) ? speed * -1.0f : speed;
|
||||||
|
border = 35.0f * scale;
|
||||||
|
|
||||||
|
last_xres = xres;
|
||||||
|
last_yres = yres;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RandomizeColor() {
|
||||||
|
do {
|
||||||
|
color_ix = (int)(rng.F() * xbase) % COLOR_COUNT;
|
||||||
|
} while (color_ix == last_color_ix);
|
||||||
|
|
||||||
|
last_color_ix = color_ix;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// TODO: Add more styles. Remember to add to the enum in ConfigValues.h and the selector in GameSettings too.
|
// TODO: Add more styles. Remember to add to the enum in ConfigValues.h and the selector in GameSettings too.
|
||||||
|
|
||||||
static BackgroundAnimation g_CurBackgroundAnimation = BackgroundAnimation::OFF;
|
static BackgroundAnimation g_CurBackgroundAnimation = BackgroundAnimation::OFF;
|
||||||
|
@ -334,6 +431,9 @@ void DrawBackground(UIContext &dc, float alpha, float x, float y, float z) {
|
||||||
case BackgroundAnimation::MOVING_BACKGROUND:
|
case BackgroundAnimation::MOVING_BACKGROUND:
|
||||||
g_Animation.reset(new MovingBackground());
|
g_Animation.reset(new MovingBackground());
|
||||||
break;
|
break;
|
||||||
|
case BackgroundAnimation::BOUNCING_ICON:
|
||||||
|
g_Animation.reset(new BouncingIconAnimation());
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
g_Animation.reset(nullptr);
|
g_Animation.reset(nullptr);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue