From 5bc61849eb133c27f708bffaa7ee6a407ca49e16 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Thu, 1 Oct 2020 23:32:01 +1000 Subject: [PATCH] FrontendCommon: Add duck icon to loading screens --- src/duckstation-qt/qthostinterface.cpp | 4 +- src/duckstation-sdl/sdl_host_interface.cpp | 5 +++ src/frontend-common/common_host_interface.cpp | 37 ++++++++++++++++++- src/frontend-common/common_host_interface.h | 7 ++++ 4 files changed, 50 insertions(+), 3 deletions(-) diff --git a/src/duckstation-qt/qthostinterface.cpp b/src/duckstation-qt/qthostinterface.cpp index 8a59d478e..bef854d57 100644 --- a/src/duckstation-qt/qthostinterface.cpp +++ b/src/duckstation-qt/qthostinterface.cpp @@ -482,7 +482,8 @@ bool QtHostInterface::AcquireHostDisplay() createImGuiContext(display_widget->devicePixelRatioFromScreen()); if (!m_display->MakeRenderContextCurrent() || - !m_display->InitializeRenderDevice(GetShaderCacheBasePath(), g_settings.gpu_use_debug_device)) + !m_display->InitializeRenderDevice(GetShaderCacheBasePath(), g_settings.gpu_use_debug_device) || + !CreateHostDisplayResources()) { destroyImGuiContext(); m_display->DestroyRenderDevice(); @@ -561,6 +562,7 @@ void QtHostInterface::ReleaseHostDisplay() { Assert(m_display); + ReleaseHostDisplayResources(); m_display->DestroyRenderDevice(); destroyImGuiContext(); emit destroyDisplayRequested(); diff --git a/src/duckstation-sdl/sdl_host_interface.cpp b/src/duckstation-sdl/sdl_host_interface.cpp index 758a92acc..2e55842a8 100644 --- a/src/duckstation-sdl/sdl_host_interface.cpp +++ b/src/duckstation-sdl/sdl_host_interface.cpp @@ -248,11 +248,16 @@ bool SDLHostInterface::AcquireHostDisplay() ImGui::NewFrame(); } + if (!CreateHostDisplayResources()) + return false; + return true; } void SDLHostInterface::ReleaseHostDisplay() { + ReleaseHostDisplayResources(); + if (m_fullscreen) SetFullscreen(false); diff --git a/src/frontend-common/common_host_interface.cpp b/src/frontend-common/common_host_interface.cpp index defaaab22..01f6082dc 100644 --- a/src/frontend-common/common_host_interface.cpp +++ b/src/frontend-common/common_host_interface.cpp @@ -19,6 +19,7 @@ #include "core/system.h" #include "core/timers.h" #include "game_list.h" +#include "icon.h" #include "imgui.h" #include "ini_settings_interface.h" #include "save_state_selector_ui.h" @@ -432,6 +433,21 @@ bool CommonHostInterface::SetFullscreen(bool enabled) return false; } +bool CommonHostInterface::CreateHostDisplayResources() +{ + m_logo_texture = + m_display->CreateTexture(APP_ICON_WIDTH, APP_ICON_HEIGHT, APP_ICON_DATA, sizeof(u32) * APP_ICON_WIDTH, false); + if (!m_logo_texture) + Log_WarningPrintf("Failed to create logo texture"); + + return true; +} + +void CommonHostInterface::ReleaseHostDisplayResources() +{ + m_logo_texture.reset(); +} + std::unique_ptr CommonHostInterface::CreateAudioStream(AudioBackend backend) { switch (backend) @@ -2035,9 +2051,26 @@ void CommonHostInterface::DisplayLoadingScreen(const char* message, int progress // ImGui::EndFrame(); // ImGui::NewFrame(); + const float logo_width = static_cast(APP_ICON_WIDTH) * scale; + const float logo_height = static_cast(APP_ICON_HEIGHT) * scale; + + ImGui::SetNextWindowSize(ImVec2(logo_width, logo_height), ImGuiCond_Always); + ImGui::SetNextWindowPos(ImVec2(io.DisplaySize.x * 0.5f, (io.DisplaySize.y * 0.5f) - (50.0f * scale)), + ImGuiCond_Always, ImVec2(0.5f, 0.5f)); + if (ImGui::Begin("LoadingScreenLogo", nullptr, + ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoMove | + ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoNav | + ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoFocusOnAppearing | + ImGuiWindowFlags_NoBackground)) + { + if (m_logo_texture) + ImGui::Image(m_logo_texture->GetHandle(), ImVec2(logo_width, logo_height)); + } + ImGui::End(); + ImGui::SetNextWindowSize(ImVec2(width, (has_progress ? 50.0f : 30.0f) * scale), ImGuiCond_Always); - ImGui::SetNextWindowPos(ImVec2(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.5f), ImGuiCond_Always, - ImVec2(0.5f, 0.5f)); + ImGui::SetNextWindowPos(ImVec2(io.DisplaySize.x * 0.5f, (io.DisplaySize.y * 0.5f) + (100.0f * scale)), + ImGuiCond_Always, ImVec2(0.5f, 0.0f)); if (ImGui::Begin("LoadingScreen", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoNav | diff --git a/src/frontend-common/common_host_interface.h b/src/frontend-common/common_host_interface.h index a6d4c860e..def300da2 100644 --- a/src/frontend-common/common_host_interface.h +++ b/src/frontend-common/common_host_interface.h @@ -12,6 +12,8 @@ #include #include +class HostDisplayTexture; + class ControllerInterface; namespace FrontendCommon { @@ -296,6 +298,9 @@ protected: void ApplyGameSettings(bool display_osd_messages); + bool CreateHostDisplayResources(); + void ReleaseHostDisplayResources(); + virtual void DrawImGuiWindows(); void DrawFPSWindow(); @@ -307,6 +312,8 @@ protected: std::unique_ptr m_controller_interface; + std::unique_ptr m_logo_texture; + std::deque m_osd_messages; std::mutex m_osd_messages_lock;