Merge pull request #14818 from iota97/super-wp

Focus based moving background
This commit is contained in:
Henrik Rydgård 2021-09-11 20:50:54 +02:00 committed by GitHub
commit b17ff0e5af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 107 additions and 16 deletions

View File

@ -24,7 +24,6 @@ static std::mutex eventMutex_;
static std::function<void(UISound)> soundCallback;
static bool soundEnabled = true;
struct DispatchQueueItem {
Event *e;
EventParams params;

View File

@ -4,6 +4,7 @@
#include "Common/UI/Screen.h"
#include "Common/UI/UI.h"
#include "Common/UI/View.h"
#include "Common/UI/ViewGroup.h"
#include "Common/Log.h"
#include "Common/TimeUtil.h"
@ -191,6 +192,15 @@ void ScreenManager::render() {
processFinishDialog();
}
void ScreenManager::getFocusPosition(float &x, float &y, float &z) {
UI::ScrollView::GetLastScrollPosition(x, y);
UI::View *v = UI::GetFocusedView();
x += v ? v->GetBounds().x : 0;
y += v ? v->GetBounds().y : 0;
z = stack_.size();
}
void ScreenManager::sendMessage(const char *msg, const char *value) {
if (!strcmp(msg, "recreateviews"))
RecreateAllViews();

View File

@ -141,6 +141,8 @@ public:
Screen *topScreen() const;
void getFocusPosition(float &x, float &y, float &z);
std::recursive_mutex inputLock_;
private:

View File

@ -1091,11 +1091,25 @@ bool ScrollView::CanScroll() const {
}
}
float ScrollView::lastScrollPosX = 0;
float ScrollView::lastScrollPosY = 0;
ScrollView::~ScrollView() {
lastScrollPosX = 0;
lastScrollPosY = 0;
}
void ScrollView::GetLastScrollPosition(float &x, float &y) {
x = lastScrollPosX;
y = lastScrollPosY;
}
void ScrollView::Update() {
if (visibility_ != V_VISIBLE) {
inertia_ = 0.0f;
}
ViewGroup::Update();
float oldPos = scrollPos_;
Gesture gesture = orientation_ == ORIENT_VERTICAL ? GESTURE_DRAG_VERTICAL : GESTURE_DRAG_HORIZONTAL;
gesture_.UpdateFrame();
@ -1124,6 +1138,9 @@ void ScrollView::Update() {
pull_ = 0.0f;
}
}
if (oldPos != scrollPos_)
orientation_ == ORIENT_HORIZONTAL ? lastScrollPosX = scrollPos_ : lastScrollPosY = scrollPos_;
}
void AnchorLayout::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert) {

View File

@ -264,6 +264,7 @@ class ScrollView : public ViewGroup {
public:
ScrollView(Orientation orientation, LayoutParams *layoutParams = 0, bool rememberPosition = false)
: ViewGroup(layoutParams), orientation_(orientation), rememberPosition_(rememberPosition) {}
~ScrollView();
void Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert) override;
void Layout() override;
@ -280,6 +281,9 @@ public:
bool CanScroll() const;
void Update() override;
// Get the last moved scroll view position
static void GetLastScrollPosition(float &x, float &y);
// Override so that we can scroll to the active one after moving the focus.
bool SubviewFocused(View *view) override;
void PersistData(PersistStatus status, std::string anonId, PersistMap &storage) override;
@ -306,6 +310,9 @@ private:
float lastViewSize_ = 0.0f;
bool scrollToTopOnSizeChange_ = false;
bool rememberPosition_;
static float lastScrollPosX;
static float lastScrollPosY;
};
class ViewPager : public ScrollView {

View File

@ -129,4 +129,5 @@ enum class BackgroundAnimation {
FLOATING_SYMBOLS = 1,
RECENT_GAMES = 2,
WAVE = 3,
MOVING_BACKGROUND = 4,
};

View File

@ -880,7 +880,7 @@ void GameSettingsScreen::CreateViews() {
if (backgroundChoice_ != nullptr) {
backgroundChoice_->OnClick.Handle(this, &GameSettingsScreen::OnChangeBackground);
}
static const char *backgroundAnimations[] = { "No animation", "Floating symbols", "Recent games", "Waves" };
static const char *backgroundAnimations[] = { "No animation", "Floating symbols", "Recent games", "Waves", "Moving background" };
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")));

View File

@ -76,12 +76,54 @@ static std::unique_ptr<ManagedTexture> bgTexture;
class Animation {
public:
virtual ~Animation() {}
virtual void Draw(UIContext &dc, double t, float alpha) = 0;
virtual void Draw(UIContext &dc, double t, float alpha, float x, float y, float z) = 0;
};
class MovingBackground : public Animation {
public:
void Draw(UIContext &dc, double t, float alpha, float x, float y, float z) override {
if (!bgTexture)
return;
dc.Flush();
dc.GetDrawContext()->BindTexture(0, bgTexture->GetTexture());
Bounds bounds = dc.GetBounds();
x = std::min(std::max(x/bounds.w, 0.0f), 1.0f) * XFAC;
y = std::min(std::max(y/bounds.h, 0.0f), 1.0f) * YFAC;
z = 1.0f + std::max(XFAC, YFAC) + (z-1.0f) * ZFAC;
lastX_ = abs(x-lastX_) > 0.001f ? x*XSPEED+lastX_*(1.0f-XSPEED) : x;
lastY_ = abs(y-lastY_) > 0.001f ? y*YSPEED+lastY_*(1.0f-YSPEED) : y;
lastZ_ = abs(z-lastZ_) > 0.001f ? z*ZSPEED+lastZ_*(1.0f-ZSPEED) : z;
float u1 = lastX_/lastZ_;
float v1 = lastY_/lastZ_;
float u2 = (1.0f+lastX_)/lastZ_;
float v2 = (1.0f+lastY_)/lastZ_;
dc.Draw()->DrawTexRect(bounds, u1, v1, u2, v2, whiteAlpha(alpha));
dc.Flush();
dc.RebindTexture();
}
private:
static constexpr float XFAC = 0.3f;
static constexpr float YFAC = 0.3f;
static constexpr float ZFAC = 0.12f;
static constexpr float XSPEED = 0.05f;
static constexpr float YSPEED = 0.05f;
static constexpr float ZSPEED = 0.1f;
float lastX_ = 0.0f;
float lastY_ = 0.0f;
float lastZ_ = 1.0f + std::max(XFAC, YFAC);
};
class WaveAnimation : public Animation {
public:
void Draw(UIContext &dc, double t, float alpha) override {
void Draw(UIContext &dc, double t, float alpha, float x, float y, float z) override {
const uint32_t color = colorAlpha(0xFFFFFFFF, alpha * 0.2f);
const float speed = 1.0;
@ -114,7 +156,7 @@ public:
class FloatingSymbolsAnimation : public Animation {
public:
~FloatingSymbolsAnimation() override {}
void Draw(UIContext &dc, double t, float alpha) override {
void Draw(UIContext &dc, double t, float alpha, float x, float y, float z) override {
float xres = dc.GetBounds().w;
float yres = dc.GetBounds().h;
if (last_xres != xres || last_yres != yres) {
@ -153,7 +195,7 @@ private:
class RecentGamesAnimation : public Animation {
public:
~RecentGamesAnimation() override {}
void Draw(UIContext &dc, double t, float alpha) override {
void Draw(UIContext &dc, double t, float alpha, float x, float y, float z) override {
if (lastIndex_ == nextIndex_) {
CheckNext(dc, t);
} else if (t > nextT_) {
@ -253,7 +295,7 @@ void UIBackgroundShutdown() {
bgTextureInited = false;
}
void DrawBackground(UIContext &dc, float alpha) {
void DrawBackground(UIContext &dc, float alpha, float x, float y, float z) {
if (!bgTextureInited) {
UIBackgroundInit(dc);
bgTextureInited = true;
@ -271,6 +313,9 @@ void DrawBackground(UIContext &dc, float alpha) {
case BackgroundAnimation::WAVE:
g_Animation.reset(new WaveAnimation());
break;
case BackgroundAnimation::MOVING_BACKGROUND:
g_Animation.reset(new MovingBackground());
break;
default:
g_Animation.reset(nullptr);
}
@ -301,11 +346,11 @@ void DrawBackground(UIContext &dc, float alpha) {
#endif
if (g_Animation) {
g_Animation->Draw(dc, t, alpha);
g_Animation->Draw(dc, t, alpha, x, y, z);
}
}
void DrawGameBackground(UIContext &dc, const Path &gamePath) {
void DrawGameBackground(UIContext &dc, const Path &gamePath, float x, float y, float z) {
std::shared_ptr<GameInfo> ginfo;
if (!gamePath.empty())
ginfo = g_gameInfoCache->GetInfo(dc.GetDrawContext(), gamePath, GAMEINFO_WANTBG);
@ -321,7 +366,7 @@ void DrawGameBackground(UIContext &dc, const Path &gamePath) {
dc.Flush();
dc.RebindTexture();
} else {
::DrawBackground(dc, 1.0f);
::DrawBackground(dc, 1.0f, x, y, z);
dc.RebindTexture();
dc.Flush();
}
@ -367,15 +412,19 @@ void HandleCommonMessages(const char *message, const char *value, ScreenManager
}
void UIScreenWithBackground::DrawBackground(UIContext &dc) {
::DrawBackground(dc, 1.0f);
float x, y, z;
screenManager()->getFocusPosition(x, y, z);
::DrawBackground(dc, 1.0f, x, y, z);
dc.Flush();
}
void UIScreenWithGameBackground::DrawBackground(UIContext &dc) {
float x, y, z;
screenManager()->getFocusPosition(x, y, z);
if (!gamePath_.empty()) {
DrawGameBackground(dc, gamePath_);
DrawGameBackground(dc, gamePath_, x, y, z);
} else {
::DrawBackground(dc, 1.0f);
::DrawBackground(dc, 1.0f, x, y, z);
dc.Flush();
}
}
@ -389,7 +438,9 @@ void UIScreenWithGameBackground::sendMessage(const char *message, const char *va
}
void UIDialogScreenWithGameBackground::DrawBackground(UIContext &dc) {
DrawGameBackground(dc, gamePath_);
float x, y, z;
screenManager()->getFocusPosition(x, y, z);
DrawGameBackground(dc, gamePath_, x, y, z);
}
void UIDialogScreenWithGameBackground::sendMessage(const char *message, const char *value) {
@ -405,7 +456,9 @@ void UIScreenWithBackground::sendMessage(const char *message, const char *value)
}
void UIDialogScreenWithBackground::DrawBackground(UIContext &dc) {
::DrawBackground(dc, 1.0f);
float x, y, z;
screenManager()->getFocusPosition(x, y, z);
::DrawBackground(dc, 1.0f, x, y, z);
dc.Flush();
}
@ -689,7 +742,9 @@ void LogoScreen::render() {
alphaText = 3.0f - t;
uint32_t textColor = colorAlpha(dc.theme->infoStyle.fgColor, alphaText);
::DrawBackground(dc, alpha);
float x, y, z;
screenManager()->getFocusPosition(x, y, z);
::DrawBackground(dc, alpha, x, y, z);
auto cr = GetI18NCategory("PSPCredits");
auto gr = GetI18NCategory("Graphics");