// widgetProgressBar.c — ProgressBar widget #include "widgetInternal.h" // ============================================================ // wgtProgressBar // ============================================================ WidgetT *wgtProgressBar(WidgetT *parent) { WidgetT *w = widgetAlloc(parent, WidgetProgressBarE); if (w) { w->as.progressBar.value = 0; w->as.progressBar.maxValue = 100; } return w; } // ============================================================ // wgtProgressBarGetValue // ============================================================ int32_t wgtProgressBarGetValue(const WidgetT *w) { if (!w || w->type != WidgetProgressBarE) { return 0; } return w->as.progressBar.value; } // ============================================================ // wgtProgressBarSetValue // ============================================================ void wgtProgressBarSetValue(WidgetT *w, int32_t value) { if (!w || w->type != WidgetProgressBarE) { return; } if (value < 0) { value = 0; } if (value > w->as.progressBar.maxValue) { value = w->as.progressBar.maxValue; } w->as.progressBar.value = value; } // ============================================================ // widgetProgressBarCalcMinSize // ============================================================ void widgetProgressBarCalcMinSize(WidgetT *w, const BitmapFontT *font) { w->calcMinW = font->charWidth * 12; w->calcMinH = font->charHeight + 4; } // ============================================================ // widgetProgressBarPaint // ============================================================ void widgetProgressBarPaint(WidgetT *w, DisplayT *d, const BlitOpsT *ops, const BitmapFontT *font, const ColorSchemeT *colors) { (void)font; uint32_t fg = w->fgColor ? w->fgColor : colors->activeTitleBg; uint32_t bg = w->bgColor ? w->bgColor : colors->contentBg; // Sunken border BevelStyleT bevel; bevel.highlight = colors->windowShadow; bevel.shadow = colors->windowHighlight; bevel.face = bg; bevel.width = 2; drawBevel(d, ops, w->x, w->y, w->w, w->h, &bevel); // Fill bar int32_t maxVal = w->as.progressBar.maxValue; if (maxVal <= 0) { maxVal = 100; } int32_t innerW = w->w - 4; int32_t innerH = w->h - 4; int32_t fillW = (innerW * w->as.progressBar.value) / maxVal; if (fillW > innerW) { fillW = innerW; } if (fillW > 0) { rectFill(d, ops, w->x + 2, w->y + 2, fillW, innerH, fg); } }