void TBarMenuTitle::Draw() { BMenu* menu = Menu(); if (menu == NULL) return; BRect frame(Frame()); rgb_color base = menu->LowColor(); menu->PushState(); BRect windowBounds = menu->Window()->Bounds(); if (frame.right > windowBounds.right) frame.right = windowBounds.right; // fill in background if (IsSelected()) { be_control_look->DrawMenuItemBackground(menu, frame, frame, base, BControlLook::B_ACTIVATED); } else be_control_look->DrawButtonBackground(menu, frame, frame, base); menu->MovePenTo(ContentLocation()); DrawContent(); menu->PopState(); }
void TBarMenuTitle::DrawContent() { BMenu* menu = Menu(); BRect frame(Frame()); if (be_control_look != NULL) { menu->SetDrawingMode(B_OP_ALPHA); if (fIcon != NULL) { BRect dstRect(fIcon->Bounds()); dstRect.OffsetTo(frame.LeftTop()); dstRect.OffsetBy(rintf(((frame.Width() - dstRect.Width()) / 2) - 1.0f), rintf(((frame.Height() - dstRect.Height()) / 2) - 0.0f)); menu->DrawBitmapAsync(fIcon, dstRect); } return; } rgb_color menuColor = menu->ViewColor(); rgb_color dark = tint_color(menuColor, B_DARKEN_1_TINT); rgb_color light = tint_color(menuColor, B_LIGHTEN_2_TINT); rgb_color black = {0, 0, 0, 255}; bool inExpandoMode = dynamic_cast<TExpandoMenuBar*>(menu) != NULL; BRect bounds(menu->Window()->Bounds()); if (bounds.right < frame.right) frame.right = bounds.right; menu->SetDrawingMode(B_OP_COPY); if (!IsSelected() && !menu->IsRedrawAfterSticky()) { menu->BeginLineArray(8); menu->AddLine(frame.RightTop(), frame.LeftTop(), light); menu->AddLine(frame.LeftBottom(), frame.RightBottom(), dark); menu->AddLine(frame.LeftTop(), frame.LeftBottom()+BPoint(0, inExpandoMode ? 0 : -1), light); menu->AddLine(frame.RightBottom(), frame.RightTop(), dark); if (inExpandoMode) { frame.top += 1; menu->AddLine(frame.LeftTop(), frame.RightTop() + BPoint(-1, 0), light); } menu->EndLineArray(); frame.InsetBy(1, 1); menu->SetHighColor(menuColor); menu->FillRect(frame); menu->SetHighColor(black); frame.InsetBy(-1, -1); if (inExpandoMode) frame.top -= 1; } ASSERT(IsEnabled()); if (IsSelected() && !menu->IsRedrawAfterSticky()) { menu->SetHighColor(tint_color(menuColor, B_HIGHLIGHT_BACKGROUND_TINT)); menu->FillRect(frame); if (menu->IndexOf(this) > 0) { menu->SetHighColor(tint_color(menuColor, B_DARKEN_4_TINT)); menu->StrokeLine(frame.LeftTop(), frame.LeftBottom()); } menu->SetHighColor(black); } menu->SetDrawingMode(B_OP_ALPHA); if (fIcon != NULL) { BRect dstRect(fIcon->Bounds()); dstRect.OffsetTo(frame.LeftTop()); dstRect.OffsetBy(rintf(((frame.Width() - dstRect.Width()) / 2) - 1.0f), rintf(((frame.Height() - dstRect.Height()) / 2) - 0.0f)); menu->DrawBitmapAsync(fIcon, dstRect); } }