void BTab::DrawLabel(BView *owner, BRect frame) { if (Label() == NULL) return; BString label = Label(); float frameWidth = frame.Width(); float width = owner->StringWidth(label.String()); font_height fh; if (width > frameWidth) { BFont font; owner->GetFont(&font); font.TruncateString(&label, B_TRUNCATE_END, frameWidth); width = frameWidth; font.GetHeight(&fh); } else { owner->GetFontHeight(&fh); } owner->SetDrawingMode(B_OP_OVER); owner->SetHighColor(ui_color(B_CONTROL_TEXT_COLOR)); owner->DrawString(label.String(), BPoint((frame.left + frame.right - width) / 2.0, (frame.top + frame.bottom - fh.ascent - fh.descent) / 2.0 + fh.ascent)); }
// Draw void PropertyItemView::Draw(BRect updateRect) { const Property* property = GetProperty(); if (property && fParent) { BRect b(Bounds()); // just draw background and label rgb_color labelColor = LowColor(); if (fEnabled) labelColor = tint_color(labelColor, B_DARKEN_MAX_TINT); else labelColor = tint_color(labelColor, B_DISABLED_LABEL_TINT); SetHighColor(labelColor); BFont font; GetFont(&font); BString truncated(name_for_id(property->Identifier())); font.TruncateString(&truncated, B_TRUNCATE_MIDDLE, fLabelWidth - 10.0); font_height fh; font.GetHeight(&fh); FillRect(BRect(b.left, b.top, b.left + fLabelWidth, b.bottom), B_SOLID_LOW); DrawString(truncated.String(), BPoint(b.left + 5.0, floorf(b.top + b.Height() / 2.0 + fh.ascent / 2.0))); // draw a "separator" line behind the label SetHighColor(tint_color(LowColor(), B_DARKEN_1_TINT)); StrokeLine(BPoint(b.left + fLabelWidth - 1.0, b.top), BPoint(b.left + fLabelWidth - 1.0, b.bottom), B_SOLID_HIGH); } }
void YabTabView::DrawLabel(int32 current, BRect frame) { BString label = GetTabName(current); if (label == NULL) return; float frameWidth = frame.Width(); float width = StringWidth(label.String()); font_height fh; if (width > frameWidth) { BFont font; GetFont(&font); font.TruncateString(&label, B_TRUNCATE_END, frameWidth); width = frameWidth; font.GetHeight(&fh); } else { GetFontHeight(&fh); } SetDrawingMode(B_OP_OVER); SetHighColor(ui_color(B_CONTROL_TEXT_COLOR)); DrawString(label.String(), BPoint((frame.left + frame.right - width) / 2.0, (frame.top + frame.bottom - fh.ascent - fh.descent) / 2.0 + fh.ascent)); }
virtual void Draw(BRect updateRect) { if (fMouseOver) { float tint = (B_NO_TINT + B_LIGHTEN_1_TINT) / 2.0; SetHighColor(tint_color(HighColor(), tint)); SetLowColor(tint_color(LowColor(), tint)); } BRect b(Bounds()); if (fSelected) { SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR)); StrokeRect(b, B_SOLID_HIGH); b.InsetBy(1, 1); StrokeRect(b, B_SOLID_HIGH); b.InsetBy(1, 1); } else if (fLevel > 0) { StrokeRect(b, B_SOLID_HIGH); b.InsetBy(1, 1); } FillRect(b, B_SOLID_LOW); // prevent the text from moving when border width changes if (!fSelected) b.InsetBy(1, 1); float width; BFont font; GetFont(&font); font_height fh; font.GetHeight(&fh); // draw the partition label, but only if we have no child partition // views BPoint textOffset; if (CountChildren() > 0) { font.SetRotation(0.0); SetFont(&font); width = b.Width(); textOffset = b.LeftTop(); textOffset.x += 3; textOffset.y += ceilf(fh.ascent); } else { width = b.Height(); textOffset = b.LeftBottom(); textOffset.x += ceilf(fh.ascent); } BString name(Name()); font.TruncateString(&name, B_TRUNCATE_END, width); SetHighColor(tint_color(LowColor(), B_DARKEN_4_TINT)); DrawString(name.String(), textOffset); }
void BMenuItem::TruncateLabel(float maxWidth, char *newLabel) { BFont font; BString string(fLabel); font.TruncateString(&string, B_TRUNCATE_MIDDLE, maxWidth); string.CopyInto(newLabel, 0, string.Length()); newLabel[string.Length()] = '\0'; }
void CProgramChangeMonitorView::ProgramChange( BString program) { BFont font; GetFont(&font); font.TruncateString(&program, B_TRUNCATE_END, Bounds().Width()); m_program = program; m_fresh = 15; }
// Draw void FontValueView::Draw(BRect updateRect) { BRect b(Bounds()); // focus indication if (IsFocus()) { SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR)); StrokeRect(b); b.InsetBy(1.0, 1.0); BRegion clipping; clipping.Include(b); ConstrainClippingRegion(&clipping); b.left --; } // background FillRect(b, B_SOLID_LOW); rgb_color labelColor = LowColor(); if (fEnabled) labelColor = tint_color(labelColor, B_DARKEN_MAX_TINT); else labelColor = tint_color(labelColor, B_DISABLED_LABEL_TINT); SetHighColor(labelColor); b.InsetBy(2.0, 1.0); float center = floorf(b.top + b.Height() / 2.0); BPoint arrow[3]; arrow[0] = BPoint(b.left, center - 3.0); arrow[1] = BPoint(b.left, center + 3.0); arrow[2] = BPoint(b.left + 3.0, center); FillPolygon(arrow, 3); b.left += 6.0; BFont font; GetFont(&font); font_height fh; font.GetHeight(&fh); BString truncated(fCurrentFont); font.TruncateString(&truncated, B_TRUNCATE_END, b.Width()); DrawString(truncated.String(), BPoint(b.left, floorf(center + fh.ascent / 2.0))); }
void CControlChangeMonitorView::ControlChange( BString controllerName, unsigned char value) { if (controllerName != m_controllerName) { // truncate controller name to max width BFont font; GetFont(&font); font.TruncateString(&controllerName, B_TRUNCATE_END, Bounds().Width()); m_controllerName = controllerName; m_freshController = 15; } m_value = value; m_freshValue = 15; m_set = true; }
void ShowImageStatusView::Draw(BRect updateRect) { rgb_color darkShadow = tint_color(LowColor(), B_DARKEN_2_TINT); rgb_color shadow = tint_color(LowColor(), B_DARKEN_1_TINT); rgb_color light = tint_color(LowColor(), B_LIGHTEN_MAX_TINT); BRect b(Bounds()); BeginLineArray(5); AddLine(BPoint(b.left, b.top), BPoint(b.right, b.top), darkShadow); b.top += 1.0; AddLine(BPoint(b.left, b.top), BPoint(b.right, b.top), light); AddLine(BPoint(b.right, b.top + 1.0), BPoint(b.right, b.bottom), shadow); AddLine(BPoint(b.right - 1.0, b.bottom), BPoint(b.left + 1.0, b.bottom), shadow); AddLine(BPoint(b.left, b.bottom), BPoint(b.left, b.top + 1.0), light); EndLineArray(); b.InsetBy(1.0, 1.0); // Truncate and layout text BString truncated(fText); BFont font; GetFont(&font); font.TruncateString(&truncated, B_TRUNCATE_MIDDLE, b.Width() - 4.0); font_height fh; font.GetHeight(&fh); FillRect(b, B_SOLID_LOW); SetDrawingMode(B_OP_OVER); DrawString(truncated.String(), BPoint(b.left + 2.0, floorf(b.top + b.Height() / 2.0 + fh.ascent / 2.0))); }
void BButton::Draw(BRect updateRect) { if (be_control_look != NULL) { BRect rect(Bounds()); rgb_color background = LowColor(); rgb_color base = background; uint32 flags = be_control_look->Flags(this); if (IsDefault()) flags |= BControlLook::B_DEFAULT_BUTTON; be_control_look->DrawButtonFrame(this, rect, updateRect, base, background, flags); be_control_look->DrawButtonBackground(this, rect, updateRect, base, flags); // always leave some room around the label rect.InsetBy(3.0, 3.0); be_control_look->DrawLabel(this, Label(), rect, updateRect, base, flags, BAlignment(B_ALIGN_CENTER, B_ALIGN_MIDDLE)); return; } font_height fh; GetFontHeight(&fh); const BRect bounds = Bounds(); BRect rect = bounds; const bool enabled = IsEnabled(); const bool pushed = Value() == B_CONTROL_ON; // Default indicator if (IsDefault()) rect = _DrawDefault(rect, enabled); BRect fillArea = rect; fillArea.InsetBy(3.0, 3.0); BString text = Label(); #if 1 // Label truncation BFont font; GetFont(&font); font.TruncateString(&text, B_TRUNCATE_END, fillArea.Width() - 4); #endif // Label position const float stringWidth = StringWidth(text.String()); const float x = (rect.right - stringWidth) / 2.0; const float labelY = bounds.top + ((bounds.Height() - fh.ascent - fh.descent) / 2.0) + fh.ascent + 1.0; const float focusLineY = labelY + fh.descent; /* speed trick: if the focus changes but the button is not pressed then we can redraw only the focus line, if the focus changes and the button is pressed invert the internal rect this block takes care of all the focus changes */ if (IsFocusChanging()) { if (pushed) { rect.InsetBy(2.0, 2.0); InvertRect(rect); } else { _DrawFocusLine(x, focusLineY, stringWidth, IsFocus() && Window()->IsActive()); } return; } // colors rgb_color panelBgColor = ui_color(B_PANEL_BACKGROUND_COLOR); rgb_color buttonBgColor = tint_color(panelBgColor, B_LIGHTEN_1_TINT); rgb_color lightColor; rgb_color maxLightColor; rgb_color dark1BorderColor; rgb_color dark2BorderColor; rgb_color bevelColor1; rgb_color bevelColor2; rgb_color bevelColorRBCorner; rgb_color borderBevelShadow; rgb_color borderBevelLight; if (enabled) { lightColor = tint_color(panelBgColor, B_LIGHTEN_2_TINT); maxLightColor = tint_color(panelBgColor, B_LIGHTEN_MAX_TINT); dark1BorderColor = tint_color(panelBgColor, B_DARKEN_3_TINT); dark2BorderColor = tint_color(panelBgColor, B_DARKEN_4_TINT); bevelColor1 = tint_color(panelBgColor, B_DARKEN_2_TINT); bevelColor2 = panelBgColor; if (IsDefault()) { borderBevelShadow = tint_color(dark1BorderColor, (B_NO_TINT + B_DARKEN_1_TINT) / 2); borderBevelLight = tint_color(dark1BorderColor, B_LIGHTEN_1_TINT); borderBevelLight.red = (borderBevelLight.red + panelBgColor.red) / 2; borderBevelLight.green = (borderBevelLight.green + panelBgColor.green) / 2; borderBevelLight.blue = (borderBevelLight.blue + panelBgColor.blue) / 2; dark1BorderColor = tint_color(dark1BorderColor, B_DARKEN_3_TINT); dark2BorderColor = tint_color(dark1BorderColor, B_DARKEN_4_TINT); bevelColorRBCorner = borderBevelShadow; } else { borderBevelShadow = tint_color(panelBgColor, (B_NO_TINT + B_DARKEN_1_TINT) / 2); borderBevelLight = buttonBgColor; bevelColorRBCorner = dark1BorderColor; } } else { lightColor = tint_color(panelBgColor, B_LIGHTEN_2_TINT); maxLightColor = tint_color(panelBgColor, B_LIGHTEN_1_TINT); dark1BorderColor = tint_color(panelBgColor, B_DARKEN_1_TINT); dark2BorderColor = tint_color(panelBgColor, B_DARKEN_2_TINT); bevelColor1 = panelBgColor; bevelColor2 = buttonBgColor; if (IsDefault()) { borderBevelShadow = dark1BorderColor; borderBevelLight = panelBgColor; dark1BorderColor = tint_color(dark1BorderColor, B_DARKEN_1_TINT); dark2BorderColor = tint_color(dark1BorderColor, 1.16); } else { borderBevelShadow = panelBgColor; borderBevelLight = panelBgColor; } bevelColorRBCorner = tint_color(panelBgColor, 1.08);; } // fill the button area SetHighColor(buttonBgColor); FillRect(fillArea); BeginLineArray(22); // bevel around external border AddLine(BPoint(rect.left, rect.bottom), BPoint(rect.left, rect.top), borderBevelShadow); AddLine(BPoint(rect.left + 1, rect.top), BPoint(rect.right, rect.top), borderBevelShadow); AddLine(BPoint(rect.right, rect.top + 1), BPoint(rect.right, rect.bottom), borderBevelLight); AddLine(BPoint(rect.left + 1, rect.bottom), BPoint(rect.right - 1, rect.bottom), borderBevelLight); rect.InsetBy(1.0, 1.0); // external border AddLine(BPoint(rect.left, rect.bottom), BPoint(rect.left, rect.top), dark1BorderColor); AddLine(BPoint(rect.left + 1, rect.top), BPoint(rect.right, rect.top), dark1BorderColor); AddLine(BPoint(rect.right, rect.top + 1), BPoint(rect.right, rect.bottom), dark2BorderColor); AddLine(BPoint(rect.right - 1, rect.bottom), BPoint(rect.left + 1, rect.bottom), dark2BorderColor); rect.InsetBy(1.0, 1.0); // Light AddLine(BPoint(rect.left, rect.top), BPoint(rect.left, rect.top), buttonBgColor); AddLine(BPoint(rect.left, rect.top + 1), BPoint(rect.left, rect.bottom - 1), lightColor); AddLine(BPoint(rect.left, rect.bottom), BPoint(rect.left, rect.bottom), bevelColor2); AddLine(BPoint(rect.left + 1, rect.top), BPoint(rect.right - 1, rect.top), lightColor); AddLine(BPoint(rect.right, rect.top), BPoint(rect.right, rect.top), bevelColor2); // Shadow AddLine(BPoint(rect.left + 1, rect.bottom), BPoint(rect.right - 1, rect.bottom), bevelColor1); AddLine(BPoint(rect.right, rect.bottom), BPoint(rect.right, rect.bottom), bevelColorRBCorner); AddLine(BPoint(rect.right, rect.bottom - 1), BPoint(rect.right, rect.top + 1), bevelColor1); rect.InsetBy(1.0, 1.0); // Light AddLine(BPoint(rect.left, rect.top), BPoint(rect.left, rect.bottom - 1), maxLightColor); AddLine(BPoint(rect.left, rect.bottom), BPoint(rect.left, rect.bottom), buttonBgColor); AddLine(BPoint(rect.left + 1, rect.top), BPoint(rect.right - 1, rect.top), maxLightColor); AddLine(BPoint(rect.right, rect.top), BPoint(rect.right, rect.top), buttonBgColor); // Shadow AddLine(BPoint(rect.left + 1, rect.bottom), BPoint(rect.right, rect.bottom), bevelColor2); AddLine(BPoint(rect.right, rect.bottom - 1), BPoint(rect.right, rect.top + 1), bevelColor2); rect.InsetBy(1.0,1.0); EndLineArray(); // Invert if clicked if (enabled && pushed) { rect.InsetBy(-2.0, -2.0); InvertRect(rect); } // Label color if (enabled) { if (pushed) { SetHighColor(maxLightColor); SetLowColor(255 - buttonBgColor.red, 255 - buttonBgColor.green, 255 - buttonBgColor.blue); } else { SetHighColor(ui_color(B_CONTROL_TEXT_COLOR)); SetLowColor(buttonBgColor); } } else { SetHighColor(tint_color(panelBgColor, B_DISABLED_LABEL_TINT)); SetLowColor(buttonBgColor); } // Draw the label DrawString(text.String(), BPoint(x, labelY)); // Focus line if (enabled && IsFocus() && Window()->IsActive() && !pushed) _DrawFocusLine(x, focusLineY, stringWidth, true); }
void OpenWithMenu::DoneBuildingItemList() { // sort by app name fSupportingAppList->SortItems(SortByRelationAndName, this); // check if each app is unique bool isUnique = true; int32 count = fSupportingAppList->CountItems(); for (int32 index = 0; index < count - 1; index++) { // the list is sorted, just compare two adjacent models if (strcmp(fSupportingAppList->ItemAt(index)->fModel->Name(), fSupportingAppList->ItemAt(index + 1)->fModel->Name()) == 0) { isUnique = false; break; } } // add apps as menu items BFont font; GetFont(&font); int32 lastRelation = -1; for (int32 index = 0; index < count ; index++) { RelationCachingModelProxy* modelProxy = fSupportingAppList->ItemAt(index); Model* model = modelProxy->fModel; BMessage* message = new BMessage(fEntriesToOpen); message->AddRef("handler", model->EntryRef()); BContainerWindow* window = dynamic_cast<BContainerWindow*>(fParentWindow); if (window != NULL) { message->AddData("nodeRefsToClose", B_RAW_TYPE, window->TargetModel()->NodeRef(), sizeof(node_ref)); } BString result; if (isUnique) { // just use the app name result = model->Name(); } else { // get a truncated full path BPath path; BEntry entry(model->EntryRef()); if (entry.GetPath(&path) != B_OK) { PRINT(("stale entry ref %s\n", model->Name())); delete message; continue; } result = path.Path(); font.TruncateString(&result, B_TRUNCATE_MIDDLE, kMaxMenuWidth); } #if DEBUG BString relationDescription; fIterator->RelationDescription(&fEntriesToOpen, model, &relationDescription); result += " ("; result += relationDescription; result += ")"; #endif // divide different relations of opening with a separator int32 relation = modelProxy->Relation(fIterator, &fEntriesToOpen); if (lastRelation != -1 && relation != lastRelation) AddSeparatorItem(); lastRelation = relation; ModelMenuItem* item = new ModelMenuItem(model, result.String(), message); AddItem(item); // mark item if it represents the preferred app if (fHaveCommonPreferredApp && *(model->EntryRef()) == fPreferredRef) { //PRINT(("marking item for % as preferred", model->Name())); item->SetMarked(true); } } // target the menu if (target != NULL) SetTargetForItems(target); else SetTargetForItems(fMessenger); if (CountItems() == 0) { BMenuItem* item = new BMenuItem(B_TRANSLATE("no supporting apps"), 0); item->SetEnabled(false); AddItem(item); } }
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)); }
float PieView::_DrawDirectory(BRect b, FileInfo* info, float parentSpan, float beginAngle, int colorIdx, int level) { if (b.Width() < 2.0 * (kPieCenterSize + level * kPieRingSize + kPieOuterMargin + kPieInnerMargin)) { return 0.0; } if (info != NULL && info->color >= 0 && level == 0) colorIdx = info->color % kBasePieColorCount; else if (info != NULL) info->color = colorIdx; VolumeSnapshot* snapshot = fScanner->Snapshot(); float cx = floorf(b.left + b.Width() / 2.0 + 0.5); float cy = floorf(b.top + b.Height() / 2.0 + 0.5); float mySpan; if (level == 0) { // Make room for mouse over info. fMouseOverInfo.clear(); fMouseOverInfo[0] = SegmentList(); // Draw the center circle. const char* displayName; if (info == NULL) { // NULL represents the entire volume. Show used and free space in // the center circle, with the used segment representing the // volume's root directory. off_t volCapacity = snapshot->capacity; mySpan = 360.0 * (volCapacity - snapshot->freeBytes) / volCapacity; SetHighColor(kEmptySpcColor); FillEllipse(BPoint(cx, cy), kPieCenterSize, kPieCenterSize); SetHighColor(kBasePieColor[0]); FillArc(BPoint(cx, cy), kPieCenterSize, kPieCenterSize, 0.0, mySpan); // Show total volume capacity. char label[B_PATH_NAME_LENGTH]; size_to_string(volCapacity, label, sizeof(label)); SetHighColor(kPieBGColor); SetDrawingMode(B_OP_OVER); DrawString(label, BPoint(cx - StringWidth(label) / 2.0, cy + fFontHeight + kSmallVMargin)); SetDrawingMode(B_OP_COPY); displayName = snapshot->name.c_str(); // Record in-use space and free space for use during MouseMoved(). info = snapshot->rootDir; info->color = colorIdx; fMouseOverInfo[0].push_back(Segment(0.0, mySpan, info)); if (mySpan < 360.0 - kMinSegmentSpan) { fMouseOverInfo[0].push_back(Segment(mySpan, 360.0, snapshot->freeSpace)); } } else { // Show a normal directory. SetHighColor(kBasePieColor[colorIdx]); FillEllipse(BRect(cx - kPieCenterSize, cy - kPieCenterSize, cx + kPieCenterSize + 0.5, cy + kPieCenterSize + 0.5)); displayName = info->ref.name; mySpan = 360.0; // Record the segment for use during MouseMoved(). fMouseOverInfo[0].push_back(Segment(0.0, mySpan, info)); } SetPenSize(1.0); SetHighColor(kOutlineColor); StrokeEllipse(BPoint(cx, cy), kPieCenterSize + 0.5, kPieCenterSize + 0.5); // Show the name of the volume or directory. BString label(displayName); BFont font; GetFont(&font); font.TruncateString(&label, B_TRUNCATE_END, 2.0 * (kPieCenterSize - kSmallHMargin)); float labelWidth = font.StringWidth(label.String()); SetHighColor(kPieBGColor); SetDrawingMode(B_OP_OVER); DrawString(label.String(), BPoint(cx - labelWidth / 2.0, cy)); SetDrawingMode(B_OP_COPY); beginAngle = 0.0; } else { // Draw an exterior segment. float parentSize; if (info->parent == NULL) parentSize = (float)snapshot->capacity; else parentSize = (float)info->parent->size; mySpan = parentSpan * (float)info->size / parentSize; if (mySpan >= kMinSegmentSpan) { const float tint = 1.4f - level * 0.08f; float radius = kPieCenterSize + level * kPieRingSize - kPieRingSize / 2.0; // Draw the grey border SetHighColor(tint_color(kOutlineColor, tint)); SetPenSize(kPieRingSize + 1.5f); StrokeArc(BPoint(cx, cy), radius, radius, beginAngle - 0.001f * radius, mySpan + 0.002f * radius); // Draw the colored area rgb_color color = tint_color(kBasePieColor[colorIdx], tint); SetHighColor(color); SetPenSize(kPieRingSize); StrokeArc(BPoint(cx, cy), radius, radius, beginAngle, mySpan); // Record the segment for use during MouseMoved(). if (fMouseOverInfo.find(level) == fMouseOverInfo.end()) fMouseOverInfo[level] = SegmentList(); fMouseOverInfo[level].push_back( Segment(beginAngle, beginAngle + mySpan, info)); } } // Draw children. vector<FileInfo*>::iterator i = info->children.begin(); while (i != info->children.end()) { float childSpan = _DrawDirectory(b, *i, mySpan, beginAngle, colorIdx, level + 1); if (childSpan >= kMinSegmentSpan) { beginAngle += childSpan; colorIdx = (colorIdx + 1) % kBasePieColorCount; } i++; } return mySpan; }
// Draw void SplitManipulator::Draw(BView* into, BRect updateRect) { if (fItemFrame.IsValid()) { into->SetDrawingMode(B_OP_COPY); into->SetHighColor(0, 0, 0, 255); BRect r(fItemFrame); into->StrokeRect(r); if (r.IntegerWidth() < 3) return; into->SetDrawingMode(B_OP_ALPHA); into->SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_OVERLAY); rgb_color base; if (ToolIsActive()) base = (rgb_color){ 200, 200, 200, 220 }; else { base = (rgb_color){ 230, 230, 230, 200 }; if (fItem && fItem->IsSelected()) base = tint_color(base, B_DARKEN_1_TINT); } into->SetHighColor(base); into->SetLowColor(base); rgb_color lighten2 = tint_color(base, B_LIGHTEN_2_TINT); rgb_color darken2 = tint_color(base, B_DARKEN_2_TINT); r = _UpperFrame(); r.InsetBy(1, 1); into->BeginLineArray(3); into->AddLine(BPoint(r.left, r.bottom - 1), BPoint(r.left, r.top), lighten2); into->AddLine(BPoint(r.left + 1, r.top), BPoint(r.right - 1, r.top), lighten2); into->AddLine(BPoint(r.right, r.top), BPoint(r.right, r.bottom - 1), darken2); into->EndLineArray(); r.InsetBy(1, 1); into->FillRect(r); if (r.IntegerWidth() == 0) return; // clip name BString truncated(fItem->Name()); BFont font; into->GetFont(&font); if (fItem->IsVideoMuted() || fItem->IsAudioMuted()) { // TODO: icons for displaying this info instead of font font.SetFace(B_ITALIC_FACE); into->SetFont(&font, B_FONT_FACE); } font.TruncateString(&truncated, B_TRUNCATE_END, r.Width() - 10.0); font_height fh; font.GetHeight(&fh); BPoint textPos; textPos.x = r.left + 5.0; textPos.y = (r.top + r.bottom + fh.ascent) / 2.0 - 1.0; into->SetHighColor(0, 0, 0, 200); into->DrawString(truncated.String(), textPos); // let the tool manipulator draw ToolDraw(into, r); // fill lower half for property display r.left = fItemFrame.left + 1; r.right = fItemFrame.right - 1; r.top = r.bottom + 1; r.bottom = fItemFrame.bottom - 1; if (ToolIsActive()) base = (rgb_color){ 205, 205, 205, 220 }; else { base = (rgb_color){ 235, 235, 235, 220 }; if (fItem && fItem->IsSelected()) base = tint_color(base, B_DARKEN_1_TINT); } into->SetHighColor(base); lighten2 = tint_color(base, B_LIGHTEN_2_TINT); rgb_color darken1 = tint_color(base, (B_NO_TINT + B_DARKEN_1_TINT) / 2.0); darken2 = tint_color(base, B_DARKEN_1_TINT); into->BeginLineArray(4); into->AddLine(BPoint(r.left, r.bottom), BPoint(r.left, r.top + 1), lighten2); into->AddLine(BPoint(r.left, r.top), BPoint(r.right - 1, r.top), darken1); into->AddLine(BPoint(r.right, r.top), BPoint(r.right, r.bottom), darken2); into->AddLine(BPoint(r.right - 1, r.bottom), BPoint(r.left + 1, r.bottom), darken2); into->EndLineArray(); r.InsetBy(1, 1); into->FillRect(r); // let the property manipulator draw if (fPropertyManipulator) fPropertyManipulator->Draw(into, updateRect); } }