diff --git a/Common/System/Request.cpp b/Common/System/Request.cpp index 33ec112840..059f49769b 100644 --- a/Common/System/Request.cpp +++ b/Common/System/Request.cpp @@ -95,8 +95,8 @@ void OnScreenDisplay::SetProgressBar(std::string id, std::string &&message, int bool found = false; for (auto &bar : bars_) { if (bar.id == id) { - _dbg_assert_(minValue == bar.minValue); - _dbg_assert_(maxValue == bar.maxValue); + bar.minValue = minValue; + bar.maxValue = maxValue; bar.progress = progress; bar.message = message; bar.endTime = now + 60.0; // Nudge the progress bar to keep it shown. diff --git a/UI/DevScreens.cpp b/UI/DevScreens.cpp index 78a82af7f1..277562edad 100644 --- a/UI/DevScreens.cpp +++ b/UI/DevScreens.cpp @@ -824,6 +824,10 @@ void SystemInfoScreen::CreateTabs() { g_OSD.SetProgressBar("testprogress", "Test Progress", 1, 100, 100); return UI::EVENT_DONE; }); + internals->Add(new Choice(si->T("N/A%")))->OnClick.Add([&](UI::EventParams &) { + g_OSD.SetProgressBar("testprogress", "Test Progress", 0, 0, 0); + return UI::EVENT_DONE; + }); internals->Add(new Choice(si->T("Clear")))->OnClick.Add([&](UI::EventParams &) { g_OSD.RemoveProgressBar("testprogress", 0.25f); return UI::EVENT_DONE; diff --git a/UI/OnScreenDisplay.cpp b/UI/OnScreenDisplay.cpp index c5f5342b85..a8feab680e 100644 --- a/UI/OnScreenDisplay.cpp +++ b/UI/OnScreenDisplay.cpp @@ -83,26 +83,40 @@ static void MeasureOSDProgressBar(UIContext &dc, const OnScreenDisplay::Progress } static void RenderOSDProgressBar(UIContext &dc, const OnScreenDisplay::ProgressBar &entry, Bounds bounds, int align, float alpha) { - UI::Drawable background = UI::Drawable(colorAlpha(0x806050, alpha)); - UI::Drawable progressBackground = UI::Drawable(colorAlpha(0xa08070, alpha)); - uint32_t foreGround = whiteAlpha(alpha); Bounds shadowBounds = bounds.Expand(10.0f); dc.Draw()->DrawImage4Grid(dc.theme->dropShadow4Grid, shadowBounds.x, shadowBounds.y + 4.0f, shadowBounds.x2(), shadowBounds.y2(), alphaMul(0xFF000000, 0.9f * alpha), 1.0f); - float ratio = (float)(entry.progress - entry.minValue) / (float)entry.maxValue; + uint32_t backgroundColor = colorAlpha(0x806050, alpha); + uint32_t progressBackgroundColor = colorAlpha(0xa08070, alpha); - Bounds boundLeft = bounds; - Bounds boundRight = bounds; + if (entry.maxValue > entry.minValue) { + // Normal progress bar - boundLeft.w *= ratio; - boundRight.x += ratio * boundRight.w; - boundRight.w *= (1.0f - ratio); + UI::Drawable background = UI::Drawable(backgroundColor); + UI::Drawable progressBackground = UI::Drawable(progressBackgroundColor); + + float ratio = (float)(entry.progress - entry.minValue) / (float)entry.maxValue; + + Bounds boundLeft = bounds; + Bounds boundRight = bounds; + + boundLeft.w *= ratio; + boundRight.x += ratio * boundRight.w; + boundRight.w *= (1.0f - ratio); + + dc.FillRect(progressBackground, boundLeft); + dc.FillRect(background, boundRight); + } else { + // Indeterminate spinner + float alpha = cos(time_now_d() * 5.0) * 0.5f + 0.5f; + uint32_t pulse = colorBlend(backgroundColor, progressBackgroundColor, alpha); + UI::Drawable background = UI::Drawable(pulse); + dc.FillRect(background, bounds); + } - dc.FillRect(progressBackground, boundLeft); - dc.FillRect(background, boundRight); dc.SetFontStyle(dc.theme->uiFont); dc.DrawTextShadowRect(entry.message.c_str(), bounds, colorAlpha(0xFFFFFFFF, alpha), (align & FLAG_DYNAMIC_ASCII) | ALIGN_CENTER);