From 274160bc22c2ba076992d92673692cb79bdf03ff Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 9 Feb 2014 13:15:53 -0800 Subject: [PATCH] Centralize game background drawing code. No need to duplicate it everywhere. --- UI/ControlMappingScreen.cpp | 2 -- UI/CwCheatScreen.cpp | 1 - UI/GameScreen.cpp | 32 +------------------------------- UI/GameScreen.h | 10 ++++------ UI/GameSettingsScreen.cpp | 30 ------------------------------ UI/GameSettingsScreen.h | 7 +++---- UI/MainScreen.cpp | 28 ---------------------------- UI/MainScreen.h | 7 ++----- UI/MiscScreens.cpp | 35 +++++++++++++++++++++++++++++++++++ UI/MiscScreens.h | 18 ++++++++++++++++++ 10 files changed, 63 insertions(+), 107 deletions(-) diff --git a/UI/ControlMappingScreen.cpp b/UI/ControlMappingScreen.cpp index cd63faec49..4a69225afe 100644 --- a/UI/ControlMappingScreen.cpp +++ b/UI/ControlMappingScreen.cpp @@ -33,8 +33,6 @@ #include "UI/UIShader.h" #include "UI/GameSettingsScreen.h" -extern void DrawBackground(float alpha); - class ControlMapper : public UI::LinearLayout { public: ControlMapper(int pspKey, std::string keyName, ScreenManager *scrm, UI::LinearLayoutParams *layoutParams = 0); diff --git a/UI/CwCheatScreen.cpp b/UI/CwCheatScreen.cpp index 72a9c61031..acc3373359 100644 --- a/UI/CwCheatScreen.cpp +++ b/UI/CwCheatScreen.cpp @@ -37,7 +37,6 @@ static bool enableAll = false; static std::vector cheatList; -extern void DrawBackground(float alpha); static CWCheatEngine *cheatEngine2; static std::deque bEnableCheat; diff --git a/UI/GameScreen.cpp b/UI/GameScreen.cpp index 3fa1326c7e..6f4f547cfb 100644 --- a/UI/GameScreen.cpp +++ b/UI/GameScreen.cpp @@ -87,36 +87,6 @@ void GameScreen::CreateViews() { UI::SetFocusedView(play); } -void DrawBackground(float alpha); - -void GameScreen::DrawBackground(UIContext &dc) { - GameInfo *ginfo = g_gameInfoCache.GetInfo(gamePath_, true); - dc.Flush(); - - dc.RebindTexture(); - ::DrawBackground(1.0f); - dc.Flush(); - - if (ginfo && ginfo->pic1Texture) { - ginfo->pic1Texture->Bind(0); - uint32_t color = whiteAlpha(ease((time_now_d() - ginfo->timePic1WasLoaded) * 3)) & 0xFFc0c0c0; - dc.Draw()->DrawTexRect(0,0,dp_xres, dp_yres, 0,0,1,1,color); - dc.Flush(); - dc.RebindTexture(); - } - /* - if (ginfo && ginfo->pic0Texture) { - ginfo->pic0Texture->Bind(0); - // Pic0 is drawn in the bottom right corner, overlaying pic1. - float sizeX = dp_xres / 480 * ginfo->pic0Texture->Width(); - float sizeY = dp_yres / 272 * ginfo->pic0Texture->Height(); - uint32_t color = whiteAlpha(ease((time_now_d() - ginfo->timePic1WasLoaded) * 2)) & 0xFFc0c0c0; - ui_draw2d.DrawTexRect(dp_xres - sizeX, dp_yres - sizeY, dp_xres, dp_yres, 0,0,1,1,color); - ui_draw2d.Flush(); - dc.RebindTexture(); - }*/ -} - void GameScreen::update(InputState &input) { UIScreen::update(input); @@ -235,7 +205,7 @@ UI::EventReturn GameScreen::OnCreateShortcut(UI::EventParams &e) { return UI::EVENT_DONE; } -bool GameScreen::isRecentGame(std::string gamePath) { +bool GameScreen::isRecentGame(const std::string &gamePath) { for (auto it = g_Config.recentIsos.begin(); it != g_Config.recentIsos.end(); ++it) { #ifdef _WIN32 if (!strcmpIgnore((*it).c_str(), gamePath.c_str(), "\\","/")) diff --git a/UI/GameScreen.h b/UI/GameScreen.h index 2498088ea5..e13b4f49e4 100644 --- a/UI/GameScreen.h +++ b/UI/GameScreen.h @@ -17,6 +17,7 @@ #pragma once +#include "UI/MiscScreens.h" #include "base/functional.h" #include "ui/ui_screen.h" @@ -26,18 +27,17 @@ // Uses GameInfoCache heavily to implement the functionality. // Should possibly merge this with the PauseScreen. -class GameScreen : public UIDialogScreen { +class GameScreen : public UIDialogScreenWithGameBackground { public: - GameScreen(std::string gamePath) : gamePath_(gamePath) {} + GameScreen(const std::string &gamePath) : UIDialogScreenWithGameBackground(gamePath) {} virtual void update(InputState &input); protected: virtual void CreateViews(); - virtual void DrawBackground(UIContext &dc); void CallbackDeleteSaveData(bool yes); void CallbackDeleteGame(bool yes); - bool isRecentGame(std::string gamePath); + bool isRecentGame(const std::string &gamePath); private: // Event handlers @@ -50,8 +50,6 @@ private: UI::EventReturn OnRemoveFromRecent(UI::EventParams &e); UI::EventReturn OnShowInFolder(UI::EventParams &e); - std::string gamePath_; - // As we load metadata in the background, we need to be able to update these after the fact. UI::TextureView *texvGameIcon_; UI::TextView *tvTitle_; diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 33954ae5d8..4fef5820ee 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -404,8 +404,6 @@ UI::EventReturn GameSettingsScreen::OnShaderChange(UI::EventParams &e) { return UI::EVENT_DONE; } -void DrawBackground(float alpha); - UI::EventReturn GameSettingsScreen::OnDumpNextFrameToLog(UI::EventParams &e) { if (gpu) { gpu->DumpNextFrame(); @@ -413,34 +411,6 @@ UI::EventReturn GameSettingsScreen::OnDumpNextFrameToLog(UI::EventParams &e) { return UI::EVENT_DONE; } -void GameSettingsScreen::DrawBackground(UIContext &dc) { - GameInfo *ginfo = g_gameInfoCache.GetInfo(gamePath_, true); - dc.Flush(); - - dc.RebindTexture(); - ::DrawBackground(1.0f); - dc.Flush(); - - if (ginfo && ginfo->pic1Texture) { - ginfo->pic1Texture->Bind(0); - uint32_t color = whiteAlpha(ease((time_now_d() - ginfo->timePic1WasLoaded) * 3)) & 0xFFc0c0c0; - dc.Draw()->DrawTexRect(0,0,dp_xres, dp_yres, 0,0,1,1,color); - dc.Flush(); - dc.RebindTexture(); - } - /* - if (ginfo && ginfo->pic0Texture) { - ginfo->pic0Texture->Bind(0); - // Pic0 is drawn in the bottom right corner, overlaying pic1. - float sizeX = dp_xres / 480 * ginfo->pic0Texture->Width(); - float sizeY = dp_yres / 272 * ginfo->pic0Texture->Height(); - uint32_t color = whiteAlpha(ease((time_now_d() - ginfo->timePic1WasLoaded) * 2)) & 0xFFc0c0c0; - ui_draw2d.DrawTexRect(dp_xres - sizeX, dp_yres - sizeY, dp_xres, dp_yres, 0,0,1,1,color); - ui_draw2d.Flush(); - dc.RebindTexture(); - }*/ -} - void GameSettingsScreen::update(InputState &input) { UIScreen::update(input); g_Config.iForceMaxEmulatedFPS = cap60FPS_ ? 60 : 0; diff --git a/UI/GameSettingsScreen.h b/UI/GameSettingsScreen.h index e0c55270bb..5e1806779a 100644 --- a/UI/GameSettingsScreen.h +++ b/UI/GameSettingsScreen.h @@ -22,10 +22,10 @@ // Per-game settings screen - enables you to configure graphic options, control options, etc // per game. -class GameSettingsScreen : public UIDialogScreenWithBackground { +class GameSettingsScreen : public UIDialogScreenWithGameBackground { public: GameSettingsScreen(std::string gamePath, std::string gameID = "") - : gamePath_(gamePath), gameID_(gameID), iAlternateSpeedPercent_(3), enableReports_(false) {} + : UIDialogScreenWithGameBackground(gamePath), gameID_(gameID), iAlternateSpeedPercent_(3), enableReports_(false) {} virtual void update(InputState &input); virtual void onFinish(DialogResult result); @@ -34,12 +34,11 @@ public: protected: virtual void CreateViews(); - virtual void DrawBackground(UIContext &dc); virtual void sendMessage(const char *message, const char *value); void CallbackRestoreDefaults(bool yes); private: - std::string gamePath_, gameID_; + std::string gameID_; // As we load metadata in the background, we need to be able to update these after the fact. UI::TextView *tvTitle_; diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index 1d97bf5a88..8ddc317a86 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -958,34 +958,6 @@ void GamePauseScreen::update(InputState &input) { UIScreen::update(input); } -void DrawBackground(float alpha); - -void GamePauseScreen::DrawBackground(UIContext &dc) { - GameInfo *ginfo = g_gameInfoCache.GetInfo(gamePath_, true); - dc.Flush(); - - if (ginfo) { - bool hasPic = false; - if (ginfo->pic1Texture) { - ginfo->pic1Texture->Bind(0); - hasPic = true; - } else if (ginfo->pic0Texture) { - ginfo->pic0Texture->Bind(0); - hasPic = true; - } - if (hasPic) { - uint32_t color = whiteAlpha(ease((time_now_d() - ginfo->timePic1WasLoaded) * 3)) & 0xFFc0c0c0; - dc.Draw()->DrawTexRect(0,0,dp_xres, dp_yres, 0,0,1,1, color); - dc.Flush(); - dc.RebindTexture(); - } else { - ::DrawBackground(1.0f); - dc.RebindTexture(); - dc.Flush(); - } - } -} - GamePauseScreen::~GamePauseScreen() { if (saveSlots_ != NULL) { g_Config.iCurrentStateSlot = saveSlots_->GetSelection(); diff --git a/UI/MainScreen.h b/UI/MainScreen.h index 01080a155a..791aa28e78 100644 --- a/UI/MainScreen.h +++ b/UI/MainScreen.h @@ -63,15 +63,14 @@ private: bool backFromStore_; }; -class GamePauseScreen : public UIDialogScreen { +class GamePauseScreen : public UIDialogScreenWithGameBackground { public: - GamePauseScreen(const std::string &filename) : UIDialogScreen(), gamePath_(filename), saveSlots_(NULL) {} + GamePauseScreen(const std::string &filename) : UIDialogScreenWithGameBackground(filename), saveSlots_(NULL) {} virtual ~GamePauseScreen(); virtual void onFinish(DialogResult result); protected: - virtual void DrawBackground(UIContext &dc); virtual void CreateViews(); virtual void update(InputState &input); virtual void sendMessage(const char *message, const char *value); @@ -90,8 +89,6 @@ private: UI::EventReturn OnSwitchUMD(UI::EventParams &e); - std::string gamePath_; - UI::ChoiceStrip *saveSlots_; UI::Choice *saveStateButton_; UI::Choice *loadStateButton_; diff --git a/UI/MiscScreens.cpp b/UI/MiscScreens.cpp index 4d10e0c103..73e671112a 100644 --- a/UI/MiscScreens.cpp +++ b/UI/MiscScreens.cpp @@ -30,6 +30,7 @@ #include "UI/MiscScreens.h" #include "UI/EmuScreen.h" #include "UI/MainScreen.h" +#include "UI/GameInfoCache.h" #include "Core/Config.h" #include "Core/Host.h" #include "Core/System.h" @@ -99,6 +100,32 @@ void DrawBackground(float alpha) { } } +void DrawGameBackground(UIContext &dc, const std::string &gamePath) { + GameInfo *ginfo = g_gameInfoCache.GetInfo(gamePath, true); + dc.Flush(); + + if (ginfo) { + bool hasPic = false; + if (ginfo->pic1Texture) { + ginfo->pic1Texture->Bind(0); + hasPic = true; + } else if (ginfo->pic0Texture) { + ginfo->pic0Texture->Bind(0); + hasPic = true; + } + if (hasPic) { + uint32_t color = whiteAlpha(ease((time_now_d() - ginfo->timePic1WasLoaded) * 3)) & 0xFFc0c0c0; + dc.Draw()->DrawTexRect(0,0,dp_xres, dp_yres, 0,0,1,1, color); + dc.Flush(); + dc.RebindTexture(); + } else { + ::DrawBackground(1.0f); + dc.RebindTexture(); + dc.Flush(); + } + } +} + void HandleCommonMessages(const char *message, const char *value, ScreenManager *manager) { if (!strcmp(message, "clear jit")) { if (MIPSComp::jit && PSP_IsInited()) { @@ -112,6 +139,14 @@ void UIScreenWithBackground::DrawBackground(UIContext &dc) { dc.Flush(); } +void UIScreenWithGameBackground::DrawBackground(UIContext &dc) { + DrawGameBackground(dc, gamePath_); +} + +void UIDialogScreenWithGameBackground::DrawBackground(UIContext &dc) { + DrawGameBackground(dc, gamePath_); +} + void UIScreenWithBackground::sendMessage(const char *message, const char *value) { HandleCommonMessages(message, value, screenManager()); I18NCategory *de = GetI18NCategory("Developer"); diff --git a/UI/MiscScreens.h b/UI/MiscScreens.h index a06ea1bbbb..2160751256 100644 --- a/UI/MiscScreens.h +++ b/UI/MiscScreens.h @@ -39,6 +39,15 @@ protected: virtual UI::EventReturn OnLanguageChange(UI::EventParams &e); }; +class UIScreenWithGameBackground : public UIScreenWithBackground { +public: + UIScreenWithGameBackground(const std::string &gamePath) + : UIScreenWithBackground(), gamePath_(gamePath) {} + virtual void DrawBackground(UIContext &dc); +protected: + std::string gamePath_; +}; + class UIDialogScreenWithBackground : public UIDialogScreen { public: UIDialogScreenWithBackground() : UIDialogScreen() {} @@ -48,6 +57,15 @@ protected: virtual UI::EventReturn OnLanguageChange(UI::EventParams &e); }; +class UIDialogScreenWithGameBackground : public UIDialogScreenWithBackground { +public: + UIDialogScreenWithGameBackground(const std::string &gamePath) + : UIDialogScreenWithBackground(), gamePath_(gamePath) {} + virtual void DrawBackground(UIContext &dc); +protected: + std::string gamePath_; +}; + class PromptScreen : public UIDialogScreenWithBackground { public: PromptScreen(std::string message, std::string yesButtonText, std::string noButtonText,