mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-07-11 01:25:07 +02:00
Progress bar: Fix the indeterminate state
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
+25
-11
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user