UI: Add simple support for a custom background.

No UI.  Essentially, this is a cleaned up version of xiushudongfang's
implementation that supports all platforms, but no selection UI.
This commit is contained in:
Unknown W. Brackets 2017-03-25 15:01:33 -07:00
parent 67fb745278
commit 8f4d1634ad
5 changed files with 40 additions and 14 deletions

View File

@ -985,8 +985,6 @@ UI::EventReturn MainScreen::OnLoadFile(UI::EventParams &e) {
return UI::EVENT_DONE;
}
extern void DrawBackground(UIContext &dc, float alpha);
void MainScreen::DrawBackground(UIContext &dc) {
UIScreenWithBackground::DrawBackground(dc);
if (highlightedGamePath_.empty() && prevHighlightedGamePath_.empty()) {

View File

@ -69,7 +69,23 @@ static const uint32_t colors[4] = {
0xC0FFFFFF,
};
void DrawBackground(UIContext &dc, float alpha = 1.0f) {
static ManagedTexture *bgTexture = nullptr;
void UIBackgroundInit(UIContext &dc) {
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)) {
const std::string &bgFile = File::Exists(bgPng) ? bgPng : bgJpg;
bgTexture = CreateTextureFromFile(dc.GetDrawContext(), bgFile.c_str(), DETECT, true);
}
}
void UIBackgroundShutdown() {
delete bgTexture;
bgTexture = nullptr;
}
void DrawBackground(UIContext &dc, float alpha) {
static float xbase[100] = {0};
static float ybase[100] = {0};
float xres = dc.GetBounds().w;
@ -87,10 +103,20 @@ void DrawBackground(UIContext &dc, float alpha = 1.0f) {
last_yres = yres;
}
int img = I_BG;
uint32_t bgColor = whiteAlpha(alpha);
ui_draw2d.DrawImageStretch(img, dc.GetBounds(), bgColor);
if (bgTexture != nullptr) {
dc.Flush();
dc.GetDrawContext()->BindTexture(0, bgTexture->GetTexture());
dc.Draw()->DrawTexRect(dc.GetBounds(), 0, 0, 1, 1, bgColor);
dc.Flush();
dc.RebindTexture();
} else {
ImageID img = I_BG;
ui_draw2d.DrawImageStretch(img, dc.GetBounds(), bgColor);
}
float t = time_now();
for (int i = 0; i < 100; i++) {
float x = xbase[i] + dc.GetBounds().x;
@ -216,7 +242,7 @@ UI::EventReturn UIDialogScreenWithBackground::OnLanguageChange(UI::EventParams &
}
void UIDialogScreenWithBackground::DrawBackground(UIContext &dc) {
::DrawBackground(dc);
::DrawBackground(dc, 1.0f);
dc.Flush();
}

View File

@ -28,6 +28,8 @@
struct ShaderInfo;
extern std::string boot_filename;
void UIBackgroundInit(UIContext &dc);
void UIBackgroundShutdown();
inline void NoOpVoidBool(bool) {}
@ -147,7 +149,3 @@ private:
int frames_;
};
// Utility functions that create various popup screens
ListPopupScreen *CreateLanguageScreen();

View File

@ -633,6 +633,8 @@ void NativeInitGraphics(GraphicsContext *graphicsContext) {
screenManager->setUIContext(uiContext);
screenManager->setDrawContext(g_draw);
UIBackgroundInit(*uiContext);
#ifdef _WIN32
winAudioBackend = CreateAudioBackend((AudioBackendType)g_Config.iAudioBackend);
#if PPSSPP_PLATFORM(UWP)
@ -651,17 +653,19 @@ void NativeShutdownGraphics() {
#ifdef _WIN32
delete winAudioBackend;
winAudioBackend = NULL;
winAudioBackend = nullptr;
#endif
delete g_gameInfoCache;
g_gameInfoCache = nullptr;
UIBackgroundShutdown();
delete uiTexture;
uiTexture = nullptr;
delete uiContext;
uiContext = NULL;
uiContext = nullptr;
ui_draw2d.Shutdown();
ui_draw2d_front.Shutdown();

View File

@ -117,7 +117,7 @@ public:
void MeasureImage(ImageID atlas_image, float *w, float *h);
void DrawImage(ImageID atlas_image, float x, float y, float scale, Color color = COLOR(0xFFFFFF), int align = ALIGN_TOPLEFT);
void DrawImageStretch(ImageID atlas_image, float x1, float y1, float x2, float y2, Color color = COLOR(0xFFFFFF));
void DrawImageStretch(int atlas_image, const Bounds &bounds, Color color = COLOR(0xFFFFFF)) {
void DrawImageStretch(ImageID atlas_image, const Bounds &bounds, Color color = COLOR(0xFFFFFF)) {
DrawImageStretch(atlas_image, bounds.x, bounds.y, bounds.x2(), bounds.y2(), color);
}
void DrawImageRotated(ImageID atlas_image, float x, float y, float scale, float angle, Color color = COLOR(0xFFFFFF), bool mirror_h = false); // Always centers