HostInterface: Add a helper to display a 'Loading Screen' during long startup
This commit is contained in:
@ -931,6 +931,46 @@ void HostInterface::SetTimerResolutionIncreased(bool enabled)
|
||||
#endif
|
||||
}
|
||||
|
||||
void HostInterface::DisplayLoadingScreen(const char* message, int progress_min /*= -1*/, int progress_max /*= -1*/,
|
||||
int progress_value /*= -1*/)
|
||||
{
|
||||
const auto& io = ImGui::GetIO();
|
||||
const float scale = io.DisplayFramebufferScale.x;
|
||||
const float width = (400.0f * scale);
|
||||
const bool has_progress = (progress_min < progress_max);
|
||||
|
||||
// eat the last imgui frame, it might've been partially rendered by the caller.
|
||||
ImGui::EndFrame();
|
||||
ImGui::NewFrame();
|
||||
|
||||
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));
|
||||
if (ImGui::Begin("LoadingScreen", nullptr,
|
||||
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoMove |
|
||||
ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoNav |
|
||||
ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoFocusOnAppearing))
|
||||
{
|
||||
if (has_progress)
|
||||
{
|
||||
ImGui::Text("%s: %d/%d", message, progress_value, progress_max);
|
||||
ImGui::ProgressBar(static_cast<float>(progress_value) / static_cast<float>(progress_max - progress_min),
|
||||
ImVec2(-1.0f, 0.0f), "");
|
||||
Log_InfoPrintf("%s: %d/%d", message, progress_value, progress_max);
|
||||
}
|
||||
else
|
||||
{
|
||||
const ImVec2 text_size(ImGui::CalcTextSize(message));
|
||||
ImGui::SetCursorPosX((width - text_size.x) / 2.0f);
|
||||
ImGui::TextUnformatted(message);
|
||||
Log_InfoPrintf("%s", message);
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
m_display->Render();
|
||||
}
|
||||
|
||||
bool HostInterface::SaveResumeSaveState()
|
||||
{
|
||||
if (!m_system)
|
||||
|
||||
Reference in New Issue
Block a user