void BStatusBar::SetTo(float value, const char* text, const char* trailingText) { SetText(text); SetTrailingText(trailingText); if (value > fMax) value = fMax; else if (value < 0) value = 0; if (value == fCurrent) return; BRect barFrame = _BarFrame(); float oldPosition = _BarPosition(barFrame); fCurrent = value; float newPosition = _BarPosition(barFrame); if (oldPosition == newPosition) return; // update only the part of the status bar with actual changes BRect update = barFrame; if (oldPosition < newPosition) { update.left = floorf(max_c(oldPosition - 1, update.left)); update.right = ceilf(newPosition); } else { update.left = floorf(max_c(newPosition - 1, update.left)); update.right = ceilf(oldPosition); } // TODO: Ask the BControlLook in the first place about dirty rect. if (be_control_look != NULL) update.InsetBy(-1, -1); Invalidate(update); }
void BStatusBar::Draw(BRect updateRect) { rgb_color backgroundColor = LowColor(); font_height fontHeight; GetFontHeight(&fontHeight); BRect barFrame = _BarFrame(&fontHeight); BRect outerFrame = barFrame.InsetByCopy(-2, -2); BRegion background(updateRect); background.Exclude(outerFrame); FillRegion(&background, B_SOLID_LOW); // Draw labels/texts BRect rect = outerFrame; rect.top = 0; rect.bottom = outerFrame.top - 1; if (updateRect.Intersects(rect)) { // update labels BString leftText; leftText << fLabel << fText; BString rightText; rightText << fTrailingText << fTrailingLabel; float baseLine = ceilf(fontHeight.ascent) + 1; fTextDivider = rect.right; BFont font; GetFont(&font); if (rightText.Length()) { font.TruncateString(&rightText, B_TRUNCATE_BEGINNING, rect.Width()); fTextDivider -= StringWidth(rightText.String()); } if (leftText.Length()) { float width = max_c(0.0, fTextDivider - rect.left); font.TruncateString(&leftText, B_TRUNCATE_END, width); } rgb_color textColor = ui_color(B_PANEL_TEXT_COLOR); if (backgroundColor != ui_color(B_PANEL_BACKGROUND_COLOR)) { if (backgroundColor.Brightness() > 100) textColor = make_color(0, 0, 0, 255); else textColor = make_color(255, 255, 255, 255); } SetHighColor(textColor); if (leftText.Length()) DrawString(leftText.String(), BPoint(rect.left, baseLine)); if (rightText.Length()) DrawString(rightText.String(), BPoint(fTextDivider, baseLine)); } // Draw bar if (!updateRect.Intersects(outerFrame)) return; rect = outerFrame; if (be_control_look != NULL) { be_control_look->DrawStatusBar(this, rect, updateRect, backgroundColor, fBarColor, _BarPosition(barFrame)); return; } // First bevel SetHighColor(tint_color(backgroundColor, B_DARKEN_1_TINT)); StrokeLine(rect.LeftBottom(), rect.LeftTop()); StrokeLine(rect.RightTop()); SetHighColor(tint_color(backgroundColor, B_LIGHTEN_2_TINT)); StrokeLine(BPoint(rect.left + 1, rect.bottom), rect.RightBottom()); StrokeLine(BPoint(rect.right, rect.top + 1)); rect.InsetBy(1, 1); // Second bevel SetHighColor(tint_color(backgroundColor, B_DARKEN_4_TINT)); StrokeLine(rect.LeftBottom(), rect.LeftTop()); StrokeLine(rect.RightTop()); SetHighColor(backgroundColor); StrokeLine(BPoint(rect.left + 1, rect.bottom), rect.RightBottom()); StrokeLine(BPoint(rect.right, rect.top + 1)); rect = barFrame; rect.right = _BarPosition(barFrame); // draw bar itself if (rect.right >= rect.left) { // Bevel SetHighColor(tint_color(fBarColor, B_LIGHTEN_2_TINT)); StrokeLine(rect.LeftBottom(), rect.LeftTop()); StrokeLine(rect.RightTop()); SetHighColor(tint_color(fBarColor, B_DARKEN_2_TINT)); StrokeLine(BPoint(rect.left + 1, rect.bottom), rect.RightBottom()); StrokeLine(BPoint(rect.right, rect.top + 1)); // filling SetHighColor(fBarColor); FillRect(rect.InsetByCopy(1, 1)); } if (rect.right < barFrame.right) { // empty space rect.left = rect.right + 1; rect.right = barFrame.right; SetHighColor(tint_color(backgroundColor, B_LIGHTEN_MAX_TINT)); FillRect(rect); } }
void BStatusBar::Draw(BRect updateRect) { rgb_color backgroundColor = LowColor(); font_height fontHeight; GetFontHeight(&fontHeight); BRect barFrame = _BarFrame(&fontHeight); BRect outerFrame = barFrame.InsetByCopy(-2, -2); BRegion background(updateRect); background.Exclude(outerFrame); FillRegion(&background, B_SOLID_LOW); // Draw labels/texts BRect rect = outerFrame; rect.top = 0; rect.bottom = outerFrame.top - 1; if (updateRect.Intersects(rect)) { // update labels BString leftText; leftText << fLabel << fText; BString rightText; rightText << fTrailingText << fTrailingLabel; float baseLine = ceilf(fontHeight.ascent) + 1; fTextDivider = rect.right; BFont font; GetFont(&font); if (rightText.Length()) { font.TruncateString(&rightText, B_TRUNCATE_BEGINNING, rect.Width()); fTextDivider -= StringWidth(rightText.String()); } if (leftText.Length()) { float width = max_c(0.0, fTextDivider - rect.left); font.TruncateString(&leftText, B_TRUNCATE_END, width); } rgb_color textColor = ui_color(B_PANEL_TEXT_COLOR); if (backgroundColor != ui_color(B_PANEL_BACKGROUND_COLOR)) { if (backgroundColor.Brightness() > 100) textColor = make_color(0, 0, 0, 255); else textColor = make_color(255, 255, 255, 255); } SetHighColor(textColor); if (leftText.Length()) DrawString(leftText.String(), BPoint(rect.left, baseLine)); if (rightText.Length()) DrawString(rightText.String(), BPoint(fTextDivider, baseLine)); } // Draw bar if (!updateRect.Intersects(outerFrame)) return; rect = outerFrame; be_control_look->DrawStatusBar(this, rect, updateRect, backgroundColor, fBarColor, _BarPosition(barFrame)); }