void TTeamMenuItem::DrawContentLabel() { BMenu* menu = Menu(); menu->MovePenBy(0, fLabelAscent); float cachedWidth = menu->StringWidth(Label()); if (Submenu() && fVertical) cachedWidth += 18; const char* label = Label(); char* truncLabel = NULL; float max = 0; if (fVertical && static_cast<TBarApp*>(be_app)->Settings()->superExpando) max = menu->MaxContentWidth() - kSwitchWidth; else max = menu->MaxContentWidth() - 4.0f; if (max > 0) { BPoint penloc = menu->PenLocation(); BRect frame = Frame(); float offset = penloc.x - frame.left; if (cachedWidth + offset > max) { truncLabel = (char*)malloc(strlen(label) + 4); if (!truncLabel) return; TruncateLabel(max-offset, truncLabel); label = truncLabel; } } if (!label) label = Label(); TBarView* barview = (static_cast<TBarApp*>(be_app))->BarView(); bool canHandle = !barview->Dragging() || barview->AppCanHandleTypes(Signature()); if (_IsSelected() && IsEnabled() && canHandle) menu->SetLowColor(tint_color(menu->LowColor(), B_HIGHLIGHT_BACKGROUND_TINT)); else menu->SetLowColor(menu->LowColor()); menu->DrawString(label); free(truncLabel); }
void TWindowMenuItem::DrawContent() { BMenu* menu = Menu(); BPoint contentLocation = ContentLocation() + BPoint(kHPad, 0); if (fID >= 0) { menu->SetDrawingMode(B_OP_OVER); float width = fBitmap->Bounds().Width(); if (width > 16) contentLocation.x -= 8; float height; GetContentSize(NULL, &height); contentLocation.y += (height - fBitmap->Bounds().Height()) / 2; menu->MovePenTo(contentLocation); menu->DrawBitmapAsync(fBitmap); if (width > 16) contentLocation.x += 8; contentLocation.x += kIconRect.Width() + kLabelOffset; } contentLocation.y = ContentLocation().y + kVPad + fLabelAscent; menu->SetDrawingMode(B_OP_COPY); menu->MovePenTo(contentLocation); if (IsSelected()) menu->SetHighColor(ui_color(B_MENU_SELECTED_ITEM_TEXT_COLOR)); else menu->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR)); float labelWidth = menu->StringWidth(Label()); BPoint penLocation = menu->PenLocation(); float offset = penLocation.x - Frame().left; menu->DrawString(Label(labelWidth + offset)); }
virtual void DrawContent() { BRect b = Frame(); BMenu *parent = Menu(); BPoint loc = parent->PenLocation(); enum { W_CHAR = 0, A_CHAR = 1, OPEN_CHAR = 2, CLOSE_CHAR = 3, SPACE_CHAR = 4, NUM_CHARS = 5 }; float escapements[NUM_CHARS]; BFont font; parent->GetFont(&font); font.GetEscapements("WA() ", NUM_CHARS, escapements); for (int32 i=0; i<NUM_CHARS; i++) { escapements[i] *= font.Size(); } const float blockWidth = escapements[W_CHAR]+escapements[A_CHAR]; const rgb_color old_col = parent->HighColor(); font_height fh; const bool showInitial = !CompareColors(fInitialColor, fColor); b.InsetBy(1, 1); b.bottom -= 1; b.left = loc.x; if (showInitial) { parent->GetFontHeight(&fh); parent->DrawString("(", BPoint(b.left, loc.y+fh.ascent)); } b.left += escapements[OPEN_CHAR]; b.InsetBy(2, 2); b.right = b.left + escapements[W_CHAR]; if (showInitial) { parent->SetHighColor(fInitialColor); parent->FillRect(b); } b.InsetBy(-1, -1); if (showInitial) { parent->SetHighColor(old_col); parent->StrokeRect(b); } b.InsetBy(-1, -1); if (showInitial) { parent->DrawString(")", BPoint(b.right+1, loc.y+fh.ascent)); } b.right += escapements[CLOSE_CHAR] + 1; b.left = b.right + escapements[SPACE_CHAR]; b.right = b.left + blockWidth; parent->SetHighColor(fColor); parent->FillRect(b); parent->SetHighColor(old_col); b.InsetBy(-1, -1); parent->StrokeRect(b); parent->MovePenTo(b.right + escapements[SPACE_CHAR]*2 + 2, loc.y); BMenuItem::DrawContent(); }