@@ -76,12 +76,54 @@ static std::unique_ptr<ManagedTexture> bgTexture;
76
76
class Animation {
77
77
public:
78
78
virtual ~Animation () {}
79
- virtual void Draw (UIContext &dc, double t, float alpha) = 0;
79
+ virtual void Draw (UIContext &dc, double t, float alpha, float x, float y, float z) = 0;
80
+ };
81
+
82
+ class MovingBackground : public Animation {
83
+ public:
84
+ void Draw (UIContext &dc, double t, float alpha, float x, float y, float z) override {
85
+ if (!bgTexture)
86
+ return ;
87
+
88
+ dc.Flush ();
89
+ dc.GetDrawContext ()->BindTexture (0 , bgTexture->GetTexture ());
90
+ Bounds bounds = dc.GetBounds ();
91
+
92
+ x = std::min (std::max (x/bounds.w , 0 .0f ), 1 .0f ) * XFAC;
93
+ y = std::min (std::max (y/bounds.h , 0 .0f ), 1 .0f ) * YFAC;
94
+ z = 1 .0f + std::max (XFAC, YFAC) + (z-1 .0f ) * ZFAC;
95
+
96
+ lastX_ = abs (x-lastX_) > 0 .001f ? x*XSPEED+lastX_*(1 .0f -XSPEED) : x;
97
+ lastY_ = abs (y-lastY_) > 0 .001f ? y*YSPEED+lastY_*(1 .0f -YSPEED) : y;
98
+ lastZ_ = abs (z-lastZ_) > 0 .001f ? z*ZSPEED+lastZ_*(1 .0f -ZSPEED) : z;
99
+
100
+ float u1 = lastX_/lastZ_;
101
+ float v1 = lastY_/lastZ_;
102
+ float u2 = (1 .0f +lastX_)/lastZ_;
103
+ float v2 = (1 .0f +lastY_)/lastZ_;
104
+
105
+ dc.Draw ()->DrawTexRect (bounds, u1, v1, u2, v2, whiteAlpha (alpha));
106
+
107
+ dc.Flush ();
108
+ dc.RebindTexture ();
109
+ }
110
+
111
+ private:
112
+ static constexpr float XFAC = 0 .3f ;
113
+ static constexpr float YFAC = 0 .3f ;
114
+ static constexpr float ZFAC = 0 .12f ;
115
+ static constexpr float XSPEED = 0 .05f ;
116
+ static constexpr float YSPEED = 0 .05f ;
117
+ static constexpr float ZSPEED = 0 .1f ;
118
+
119
+ float lastX_ = 0 .0f ;
120
+ float lastY_ = 0 .0f ;
121
+ float lastZ_ = 1 .0f + std::max(XFAC, YFAC);
80
122
};
81
123
82
124
class WaveAnimation : public Animation {
83
125
public:
84
- void Draw (UIContext &dc, double t, float alpha) override {
126
+ void Draw (UIContext &dc, double t, float alpha, float x, float y, float z ) override {
85
127
const uint32_t color = colorAlpha (0xFFFFFFFF , alpha * 0 .2f );
86
128
const float speed = 1.0 ;
87
129
@@ -114,7 +156,7 @@ class WaveAnimation : public Animation {
114
156
class FloatingSymbolsAnimation : public Animation {
115
157
public:
116
158
~FloatingSymbolsAnimation () override {}
117
- void Draw (UIContext &dc, double t, float alpha) override {
159
+ void Draw (UIContext &dc, double t, float alpha, float x, float y, float z ) override {
118
160
float xres = dc.GetBounds ().w ;
119
161
float yres = dc.GetBounds ().h ;
120
162
if (last_xres != xres || last_yres != yres) {
@@ -153,7 +195,7 @@ class FloatingSymbolsAnimation : public Animation {
153
195
class RecentGamesAnimation : public Animation {
154
196
public:
155
197
~RecentGamesAnimation () override {}
156
- void Draw (UIContext &dc, double t, float alpha) override {
198
+ void Draw (UIContext &dc, double t, float alpha, float x, float y, float z ) override {
157
199
if (lastIndex_ == nextIndex_) {
158
200
CheckNext (dc, t);
159
201
} else if (t > nextT_) {
@@ -253,7 +295,7 @@ void UIBackgroundShutdown() {
253
295
bgTextureInited = false ;
254
296
}
255
297
256
- void DrawBackground (UIContext &dc, float alpha) {
298
+ void DrawBackground (UIContext &dc, float alpha, float x, float y, float z ) {
257
299
if (!bgTextureInited) {
258
300
UIBackgroundInit (dc);
259
301
bgTextureInited = true ;
@@ -271,6 +313,9 @@ void DrawBackground(UIContext &dc, float alpha) {
271
313
case BackgroundAnimation::WAVE:
272
314
g_Animation.reset (new WaveAnimation ());
273
315
break ;
316
+ case BackgroundAnimation::MOVING_BACKGROUND:
317
+ g_Animation.reset (new MovingBackground ());
318
+ break ;
274
319
default :
275
320
g_Animation.reset (nullptr );
276
321
}
@@ -301,11 +346,11 @@ void DrawBackground(UIContext &dc, float alpha) {
301
346
#endif
302
347
303
348
if (g_Animation) {
304
- g_Animation->Draw (dc, t, alpha);
349
+ g_Animation->Draw (dc, t, alpha, x, y, z );
305
350
}
306
351
}
307
352
308
- void DrawGameBackground (UIContext &dc, const Path &gamePath) {
353
+ void DrawGameBackground (UIContext &dc, const Path &gamePath, float x, float y, float z ) {
309
354
std::shared_ptr<GameInfo> ginfo;
310
355
if (!gamePath.empty ())
311
356
ginfo = g_gameInfoCache->GetInfo (dc.GetDrawContext (), gamePath, GAMEINFO_WANTBG);
@@ -321,7 +366,7 @@ void DrawGameBackground(UIContext &dc, const Path &gamePath) {
321
366
dc.Flush ();
322
367
dc.RebindTexture ();
323
368
} else {
324
- ::DrawBackground (dc, 1 .0f );
369
+ ::DrawBackground (dc, 1 .0f , x, y, z );
325
370
dc.RebindTexture ();
326
371
dc.Flush ();
327
372
}
@@ -367,15 +412,19 @@ void HandleCommonMessages(const char *message, const char *value, ScreenManager
367
412
}
368
413
369
414
void UIScreenWithBackground::DrawBackground (UIContext &dc) {
370
- ::DrawBackground (dc, 1 .0f );
415
+ float x, y, z;
416
+ screenManager ()->getFocusPosition (x, y, z);
417
+ ::DrawBackground (dc, 1 .0f , x, y, z);
371
418
dc.Flush ();
372
419
}
373
420
374
421
void UIScreenWithGameBackground::DrawBackground (UIContext &dc) {
422
+ float x, y, z;
423
+ screenManager ()->getFocusPosition (x, y, z);
375
424
if (!gamePath_.empty ()) {
376
- DrawGameBackground (dc, gamePath_);
425
+ DrawGameBackground (dc, gamePath_, x, y, z );
377
426
} else {
378
- ::DrawBackground (dc, 1 .0f );
427
+ ::DrawBackground (dc, 1 .0f , x, y, z );
379
428
dc.Flush ();
380
429
}
381
430
}
@@ -389,7 +438,9 @@ void UIScreenWithGameBackground::sendMessage(const char *message, const char *va
389
438
}
390
439
391
440
void UIDialogScreenWithGameBackground::DrawBackground (UIContext &dc) {
392
- DrawGameBackground (dc, gamePath_);
441
+ float x, y, z;
442
+ screenManager ()->getFocusPosition (x, y, z);
443
+ DrawGameBackground (dc, gamePath_, x, y, z);
393
444
}
394
445
395
446
void UIDialogScreenWithGameBackground::sendMessage (const char *message, const char *value) {
@@ -405,7 +456,9 @@ void UIScreenWithBackground::sendMessage(const char *message, const char *value)
405
456
}
406
457
407
458
void UIDialogScreenWithBackground::DrawBackground (UIContext &dc) {
408
- ::DrawBackground (dc, 1 .0f );
459
+ float x, y, z;
460
+ screenManager ()->getFocusPosition (x, y, z);
461
+ ::DrawBackground (dc, 1 .0f , x, y, z);
409
462
dc.Flush ();
410
463
}
411
464
@@ -689,7 +742,9 @@ void LogoScreen::render() {
689
742
alphaText = 3 .0f - t;
690
743
uint32_t textColor = colorAlpha (dc.theme ->infoStyle .fgColor , alphaText);
691
744
692
- ::DrawBackground (dc, alpha);
745
+ float x, y, z;
746
+ screenManager ()->getFocusPosition (x, y, z);
747
+ ::DrawBackground (dc, alpha, x, y, z);
693
748
694
749
auto cr = GetI18NCategory (" PSPCredits" );
695
750
auto gr = GetI18NCategory (" Graphics" );
0 commit comments