void CSelectionView::ChooseFont() { CFontMetrics metrics = gFontSizeTable[fCellView->BorderFontID()]; BFont myFont = metrics.Font(); font_height fi; do { myFont.GetHeight(&fi); if (fi.ascent + fi.descent <= Bounds().Height()) break; float size = myFont.Size(); myFont.SetSize(size - 1); myFont.GetHeight(&fi); if (fi.ascent + fi.descent <= Bounds().Height()) break; myFont.SetSize(size - 2); myFont.GetHeight(&fi); if (fi.ascent + fi.descent <= Bounds().Height()) break; myFont = be_plain_font; myFont.GetHeight(&fi); if (fi.ascent + fi.descent <= Bounds().Height()) break; // uh, oh, trouble... } while (false); SetFont(&myFont); Invalidate(); } /* CSelectionView::ChooseFont */
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)); }
///////////////////////////////////////////////////////////////////// // makeKanBeWin ///////////////////////////////////////////////////////////////////// void kanBeApp::makeKanBeWin(void) { BFont aFont; font_height h_info; float h, w; char basepath[B_FILE_NAME_LENGTH]; ReadSetting(basepath, &aFont); setBasePath(basepath); w = aFont.StringWidth(B_UTF8_HIROSHI); // kanji width aFont.GetHeight(&h_info); h = h_info.ascent + h_info.descent + h_info.leading; mWindow = new BWindow(InitFrame(w, h), "kanBe ver. 0.52", B_TITLED_WINDOW, B_NOT_RESIZABLE|B_NOT_CLOSABLE|B_NOT_MINIMIZABLE|B_NOT_ZOOMABLE); mWindow->Lock(); mView = new FEPView(mWindow->Bounds()); mView->SetFont(&aFont); mWindow->AddChild(mView); mWindow->Unlock(); mWindow->Show(); }
//: Returns width and postion of the title. //!param: width - In this parameter the available space //!param: for the title is returned. //!param: pos - In this parameter the position for the //!param: title is returned. void CMDITitleView::GetTitleWidthAndPos(float &width, BPoint &pos) { BFont titleFont; GetTitleFont(&titleFont); font_height titleFontHeight; titleFont.GetHeight(&titleFontHeight); width = Bounds().Width() - distFromMaximizeBox - distFromCloseBox; if(DisplayCloseButton()) { pos.x = CloseButtonRect().right + distFromCloseBox; width -= CloseButtonRect().right; } else { pos.x = distFromCloseBox; } if(DisplayMaximizeButton()) { width -= MaximizeButtonRect().Width() - distFromRightBorder; } pos.y = titleFontHeight.ascent + 3; }
PieView::PieView(BVolume* volume) : BView(NULL, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_SUBPIXEL_PRECISE), fWindow(NULL), fScanner(NULL), fVolume(volume), fMouseOverInfo(), fClicked(false), fDragging(false), fUpdateFileAt(false) { fMouseOverMenu = new BPopUpMenu(kEmptyStr, false, false); fMouseOverMenu->AddItem(new BMenuItem(B_TRANSLATE("Get Info"), NULL), kIdxGetInfo); fMouseOverMenu->AddItem(new BMenuItem(B_TRANSLATE("Open"), NULL), kIdxOpen); fFileUnavailableMenu = new BPopUpMenu(kEmptyStr, false, false); BMenuItem* item = new BMenuItem(B_TRANSLATE("file unavailable"), NULL); item->SetEnabled(false); fFileUnavailableMenu->AddItem(item); BFont font; GetFont(&font); font.SetSize(ceilf(font.Size() * 1.33)); font.SetFace(B_BOLD_FACE); SetFont(&font); struct font_height fh; font.GetHeight(&fh); fFontHeight = ceilf(fh.ascent) + ceilf(fh.descent) + ceilf(fh.leading); }
void BTitledColumn::DrawString(const char* string, BView* parent, BRect rect) { float width = rect.Width() - (2 * kTEXT_MARGIN); float y; BFont font; font_height finfo; parent->GetFont(&font); font.GetHeight(&finfo); y = rect.top + ((rect.Height() - (finfo.ascent + finfo.descent + finfo.leading)) / 2) + (finfo.ascent + finfo.descent) - 2; switch (Alignment()) { default: case B_ALIGN_LEFT: parent->MovePenTo(rect.left + kTEXT_MARGIN, y); break; case B_ALIGN_CENTER: parent->MovePenTo(rect.left + kTEXT_MARGIN + ((width - font.StringWidth(string)) / 2), y); break; case B_ALIGN_RIGHT: parent->MovePenTo(rect.right - kTEXT_MARGIN - font.StringWidth(string), y); break; } parent->DrawString(string); }
/*! \function CategoryListView::GetPreferredSize * \brief Returns preferred width and height for this CategoryListView * \param[out] width Preferred width * \param[out] height Preferred height */ void CategoryListView::GetPreferredSize( float* width, float* height ) { int numOfItems = this->CountItems(); font_height fh; BFont font; this->GetFont( &font ); font.GetHeight( &fh ); int heightOfSingleItem = fh.leading + fh.ascent + fh.descent; *height = ( numOfItems == 0 ? heightOfSingleItem : heightOfSingleItem * numOfItems ); float currentWidth = 0; *width = 0; for ( int i = 0; i < numOfItems; ++i ) { currentWidth = ( ( this->ItemAt( i ) )->Width() ); if ( currentWidth > *width ) { *width = currentWidth; } } width += ( heightOfSingleItem - 2 ) + 2 * SPACING; } // <-- end of function "CategoryListView::GetPreferredSize"
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)); }
void ExpanderWindow::_UpdateWindowSize(bool showContents) { float minWidth, maxWidth, minHeight, maxHeight; GetSizeLimits(&minWidth, &maxWidth, &minHeight, &maxHeight); float bottom = fSizeLimit; if (showContents) { if (fPreviousHeight < 0.0) { BFont font; font_height fontHeight; fListingText->GetFont(&font); font.GetHeight(&fontHeight); fLineHeight = ceilf(fontHeight.ascent + fontHeight.descent + fontHeight.leading); fPreviousHeight = bottom + 10.0 * fLineHeight; } minHeight = bottom + 5.0 * fLineHeight; maxHeight = 32767.0; bottom = max_c(fPreviousHeight, minHeight); } else { minHeight = fSizeLimit; maxHeight = fSizeLimit; fPreviousHeight = Frame().Height(); } SetSizeLimits(minWidth, maxWidth, minHeight, maxHeight); ResizeTo(Frame().Width(), bottom); }
// 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 BmCaption::Draw( BRect updateRect) { BRect r = Bounds(); if (mHighlight) { if (BeamOnDano) SetLowColor( keyboard_navigation_color()); else { rgb_color highlightCol = {255, 217, 121, 255}; SetLowColor( highlightCol); } } else SetLowColor( ui_color( B_PANEL_BACKGROUND_COLOR)); #ifndef __HAIKU__ FillRect( r.InsetByCopy(1.0, 1.0), B_SOLID_LOW); #else FillRect( BRect(r.top + 1, r.left + 1, r.right, r.bottom - 1), B_SOLID_LOW); #endif SetHighColor( ui_color( B_SHINE_COLOR)); StrokeLine( BPoint(0.0,1.0), BPoint(r.right,1.0)); StrokeLine( BPoint(0.0,1.0), r.LeftBottom()); SetHighColor( BmWeakenColor( B_SHADOW_COLOR, BeShadowMod)); if (BeamOnDano) StrokeLine( r.RightTop(), r.RightBottom()); #ifndef __HAIKU__ else // looks better on R5, as it blends with scrollbar: StrokeLine( r.RightTop(), r.RightBottom(), B_SOLID_LOW); #endif StrokeLine( r.LeftTop(), r.RightTop()); StrokeLine( r.LeftBottom(), r.RightBottom()); SetHighColor( ui_color( B_PANEL_TEXT_COLOR)); font_height fInfo; BFont captionFont; GetFont(&captionFont); captionFont.GetHeight( &fInfo); float offset = (1.0f+r.Height()-(fInfo.ascent+fInfo.descent))/2.0f; float freeWidth = r.Width(); if (mHighlight && mHighlightLabel.Length()) { freeWidth -= StringWidth(mHighlightLabel.String())+2; BPoint pos( 2.0, fInfo.ascent+offset); DrawString( mHighlightLabel.String(), pos); } const char* text = mText.String(); float width; while(1) { width = StringWidth(text); if (width+4.0 < freeWidth) break; text++; while((*text & 0xc0) == 0x80) text++; // skip UTF8 subsequence chars if (!*text) break; } BPoint pos( r.Width()-width-2.0f, fInfo.ascent+offset); DrawString( text, pos); }
//***************************************************** void TimeBarView::Draw(BRect rect) { BRect r = Bounds(); char s[255]; SetLowColor(Prefs.time_back_color); FillRect(r, B_SOLID_LOW); if (Pool.size == 0) return; SetHighColor(64,64,64); StrokeLine(BPoint(r.left, r.top), BPoint(r.right, r.top)); if (Pool.sample_type == NONE) return; int32 w = r.IntegerWidth(); int32 x = (int32)r.left; float b; BFont font; GetFont(&font); font_height fh; font.GetHeight(&fh); float fw = font.StringWidth(" 00:00.000 "); // float t = floor( Pool.l_pointer/Pool.frequency); float t = ( Pool.l_pointer/Pool.frequency); float t_add = (Pool.r_pointer - Pool.l_pointer)/(Pool.frequency*w); float t_marge = t_add * fw; float t_small_marge = t_marge/5.0f; float t_small_bound = t + t_small_marge; float t_bound = t + t_marge; while (w>0){ t += t_add; if (t >= t_bound){ int time = (int)((t-(int)t)*1000); int sec = (int)fmod(t,60); int min = ((int)t)/60; sprintf(s, "%d:%.2d.%.3d", min, sec, time); t_bound += t_marge; b = r.top + 5; SetHighColor(Prefs.time_text_color); DrawString(s, BPoint(x - font.StringWidth(s)/2.0f, r.bottom)); SetHighColor(Prefs.time_marks_color); StrokeLine( BPoint( x, r.top+1 ), BPoint( x, b) ); }else if (t >= t_small_bound){ t_small_bound += t_small_marge; SetHighColor(Prefs.time_small_marks_color); b = r.top + 1; StrokeLine( BPoint( x, r.top+1 ), BPoint( x, b) ); } x ++; w --; } }
void Spinner::_InitObject(void) { SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); BRect r(Bounds()); if (r.Height() < B_H_SCROLL_BAR_HEIGHT * 2) r.bottom = r.top + 1 + B_H_SCROLL_BAR_HEIGHT * 2; ResizeTo(r.Width(),r.Height()); r.right -= B_V_SCROLL_BAR_WIDTH; font_height fh; BFont font; font.GetHeight(&fh); float textheight = fh.ascent + fh.descent + fh.leading; r.top = 0; r.bottom = textheight; fTextControl = new BTextControl(r,"textcontrol",Label(),"0", new BMessage(M_TEXT_CHANGED), B_FOLLOW_TOP | B_FOLLOW_LEFT_RIGHT, B_WILL_DRAW | B_NAVIGABLE); AddChild(fTextControl); fTextControl->ResizeTo(r.Width(), MAX(textheight, fTextControl->TextView()->LineHeight(0) + 4.0)); fTextControl->MoveTo(0, ((B_H_SCROLL_BAR_HEIGHT * 2) - fTextControl->Bounds().Height()) / 2); fTextControl->SetDivider(StringWidth(Label()) + 5); BTextView *tview = fTextControl->TextView(); tview->SetAlignment(B_ALIGN_LEFT); tview->SetWordWrap(false); BString string("QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,/qwertyuiop{}| " "asdfghjkl:\"zxcvbnm<>?!@#$%^&*()-_=+`~\r"); for (int32 i = 0; i < string.CountChars(); i++) { char c = string.ByteAt(i); tview->DisallowChar(c); } r = Bounds(); r.left = r.right - B_V_SCROLL_BAR_WIDTH; r.bottom = B_H_SCROLL_BAR_HEIGHT; fUpButton = new SpinnerArrowButton(r.LeftTop(),"up",ARROW_UP); AddChild(fUpButton); r.OffsetBy(0,r.Height() + 1); fDownButton = new SpinnerArrowButton(r.LeftTop(),"down",ARROW_DOWN); AddChild(fDownButton); fPrivateData = new SpinnerPrivateData; fFilter = new SpinnerMsgFilter; }
void MultiLineStringView::GetPreferredSize(float *width, float *height) { BFont font; font_height fh; GetFont(&font); font.GetHeight(&fh); *width = fWidth; *height = (fLines.size() + 1) * (fh.ascent + fh.leading + fh.descent); };
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 FieldView::Draw(BRect update) { if (fPauseMode) { SetHighColor(128,128,128); FillRect(Bounds()); SetHighColor(255,255,255); SetDrawingMode(B_OP_ALPHA); BFont font; font.SetSize(28.0); font_height fh; font.GetHeight(&fh); float width = font.StringWidth(B_TRANSLATE("PAUSED")); SetFont(&font); float y = (Bounds().Height() / 3) + fh.ascent; DrawString(B_TRANSLATE("PAUSED"),BPoint( (Bounds().Width() - width) / 2.0,y)); SetFont(be_plain_font); y += fh.descent + fh.leading + 10.0; width = be_plain_font->StringWidth(B_TRANSLATE("Click to resume")); DrawString(B_TRANSLATE("Click to resume"),BPoint( (Bounds().Width() - width) / 2.0,y)); } else { // The corresponding box numbers for the update rectangle uint16 leftx,rightx,topy,bottomy; BRect r = gGameStyle->TileSize(); // We have to do this because of a bug in BRect::Width()/Height() // A rect of (0,0,23,23) will return a Width/Height of 23, not 24. int32 tilewidth = r.IntegerWidth() + 1; int32 tileheight = r.IntegerHeight() + 1; leftx = uint16(update.left / tilewidth); rightx = uint16(update.right / tilewidth); topy = uint16(update.top / tileheight); bottomy = uint16(update.bottom / tileheight); for (uint16 y = topy; y <= bottomy; y++) for (uint16 x = leftx; x <= rightx; x++) { bool down = false; if (fTracking && fSelection.x == x && fSelection.y == y) down = true; DrawBox(x,y, down); } if (gGameState == GAME_OVER) { SetHighColor(64,64,64,72); FillRect(Bounds()); } } }
/*********************************************************** * DrawString ***********************************************************/ void HToolbarButton::DrawString(BView *view ,const char* label,bool downState,bool enabled) { BRect bounds = view->Bounds(); if(NORMAL_WIDTH == bounds.Width()) return; int32 x,y; BFont font; font.SetFamilyAndStyle("Swis721 BT","Roman"); font.SetSize(10); font.SetSpacing(B_BITMAP_SPACING); font_height height; font.GetHeight(&height); float h = height.ascent + height.descent; y = (int32)(bounds.bottom - h + 4); float w = view->StringWidth(label); if(w > bounds.Width()) x = 1; else{ x = (int32)(bounds.Width() - w)/2; } if(downState) { x ++; y ++; } view->SetLowColor(bgcolor); /* if(enabled && !downState) { view->SetHighColor(237,237,237); view->SetDrawingMode(B_OP_COPY); font.SetFace(B_BOLD_FACE); view->SetFont(&font); view->DrawString(label,BPoint(x+1,y+1)); } */ if(enabled) { if(!downState) view->SetHighColor(Black); else view->SetHighColor(255,0,0); }else view->SetHighColor(BeDarkShadow); font.SetFace(B_REGULAR_FACE); view->SetFont(&font); view->DrawString(label,BPoint(x,y)); }
void ShortcutsSpec::_CacheViewFont(BView* owner) { if (sFontCached == false) { sFontCached = true; owner->GetFont(&sViewFont); font_height fh; sViewFont.GetHeight(&fh); sFontHeight = fh.ascent - fh.descent; } }
// GetHeight void Font::GetHeight(font_height* fh) const { if (!fCachedFontHeightValid) { // TODO: BFont helper = GetBFont(); helper.GetHeight(&fCachedFontHeight); fCachedFontHeightValid = true; } *fh = fCachedFontHeight; }
void TeamListItem::DrawItem(BView* owner, BRect frame, bool complete) { rgb_color kHighlight = { 140, 140, 140, 0 }; rgb_color kBlack = { 0, 0, 0, 0 }; rgb_color kBlue = { 0, 0, 255, 0 }; rgb_color kRed = { 255, 0, 0, 0 }; BRect r(frame); if (IsSelected() || complete) { rgb_color color; if (IsSelected()) color = kHighlight; else color = owner->ViewColor(); owner->SetHighColor(color); owner->SetLowColor(color); owner->FillRect(r); owner->SetHighColor(kBlack); } else { owner->SetLowColor(owner->ViewColor()); } frame.left += 4; BRect iconFrame(frame); iconFrame.Set(iconFrame.left, iconFrame.top + 1, iconFrame.left + 15, iconFrame.top + 16); owner->SetDrawingMode(B_OP_ALPHA); owner->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY); owner->DrawBitmap(&fMiniIcon, iconFrame); owner->SetDrawingMode(B_OP_COPY); frame.left += 16; if (fRefusingToQuit) owner->SetHighColor(kRed); else owner->SetHighColor(IsSystemServer() ? kBlue : kBlack); BFont font = be_plain_font; font_height finfo; font.GetHeight(&finfo); owner->SetFont(&font); owner->MovePenTo(frame.left + 8, frame.top + ((frame.Height() - (finfo.ascent + finfo.descent + finfo.leading)) / 2) + finfo.ascent); if (gLocalizedNamePreferred) owner->DrawString(fLocalizedName.String()); else owner->DrawString(fPath.Leaf()); }
void HColorControl::Draw(BRect /*updateRect*/) { BRect r(Bounds()); SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)); font_height fh; BFont font; GetFont(&font); font.GetHeight(&fh); BPoint p(3, r.bottom - fh.descent); if (IsFocus()) { SetHighColor(keyboard_navigation_color()); StrokeLine(BPoint(p.x, p.y + 1), BPoint(p.x + StringWidth(fLabel), p.y + 1)); SetHighColor(255, 255, 255); StrokeLine(BPoint(p.x, p.y + 2), BPoint(p.x + StringWidth(fLabel), p.y + 2)); SetHighColor(0, 0, 0); } DrawString(fLabel, p); r.left = r.right - 32; r.bottom -= fh.descent - 2; r.top = r.bottom - 12; FillRect(r, B_SOLID_LOW); r.left += 2; r.top += 2; if (fDown) { SetHighColor(kBlack); StrokeRect(r); r.InsetBy(1, 1); rgb_color c = fColor; c.red >>= 1; c.green >>= 1; c.blue >>= 1; SetHighColor(c); FillRect(r); SetHighColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_1_TINT)); r.InsetBy(-1, -1); r.OffsetBy(-1, -1); StrokeLine(r.LeftBottom(), r.LeftTop()); StrokeLine(r.LeftTop(), r.RightTop()); } else {
void HBox::Draw(BRect update) { BRect R(Bounds()); float l = R.left, t = R.top, r = R.right, b = R.bottom; if (Label()) { BFont font; GetFont(&font); font_height fh; font.GetHeight(&fh); float lh = fh.ascent + fh.descent, w = StringWidth(Label()) + 4; DrawString(Label(), BPoint(7, fh.ascent)); BeginLineArray(10); AddLine(BPoint(l, t + lh / 2), BPoint(l + 4, t + lh / 2), tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_1_TINT)); AddLine(BPoint(l + 1, t + lh / 2 + 1), BPoint(l + 5, t + lh / 2 + 1), kWhite); AddLine(BPoint(l + w + 4, t + lh / 2), BPoint(r, t + lh / 2), tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_1_TINT)); AddLine(BPoint(l + w + 4, t + lh / 2 + 1), BPoint(r - 1, t + lh / 2 + 1), kWhite); AddLine(BPoint(l, t + lh / 2), BPoint(l, b), tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_1_TINT)); AddLine(BPoint(l + 1, t + lh / 2 + 1), BPoint(l + 1, b - 2), kWhite); AddLine(BPoint(l, b - 1), BPoint(r - 1, b - 1), tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_1_TINT)); AddLine(BPoint(l, b), BPoint(r, b), kWhite); AddLine(BPoint(r - 1, b - 1), BPoint(r - 1, t + lh / 2), tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_1_TINT)); AddLine(BPoint(r, b), BPoint(r, t + lh / 2), kWhite); EndLineArray(); } else { BeginLineArray(8); AddLine(BPoint(l, t), BPoint(r - 1, t), tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_1_TINT)); AddLine(BPoint(l + 1, t + 1), BPoint(r - 2, t + 1), kWhite); AddLine(BPoint(l, t), BPoint(l, b - 1), tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_1_TINT)); AddLine(BPoint(l + 1, t + 1), BPoint(l + 1, b - 2), kWhite); AddLine(BPoint(l, b - 1), BPoint(r - 1, b - 1), tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_1_TINT)); AddLine(BPoint(l, b), BPoint(r, b), kWhite); AddLine(BPoint(r - 1, b - 1), BPoint(r - 1, t), tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_1_TINT)); AddLine(BPoint(r, b), BPoint(r, t), kWhite); EndLineArray(); } } /* HBox::Draw */
void BRadioButton::GetPreferredSize(float *width, float *height) { if (width == NULL && height == NULL) return; BFont font; GetFont(&font); font_height fontHeight; font.GetHeight(&fontHeight); float sHeight = fontHeight.ascent + fontHeight.descent; if (width) *width = font.StringWidth(Label()) + sHeight + 20; if (height) *height = sHeight + 4; }
void SimpleFontData::platformInit() { BFont* font = m_platformData.font(); if (!font) return; font_height height; font->GetHeight(&height); m_ascent = static_cast<int>(height.ascent); m_descent = static_cast<int>(height.descent); m_lineSpacing = m_ascent + m_descent; m_xHeight = height.ascent * 0.56f; // Hack taken from the win port. m_lineGap = height.leading; }
static void testDrawStringWithLength(BView *view, BRect frame) { BFont font; view->GetFont(&font); font_height height; font.GetHeight(&height); float baseline = frame.bottom - height.descent; // draw base line view->SetHighColor(kGreen); view->StrokeLine(BPoint(frame.left, baseline - 1), BPoint(frame.right, baseline -1)); view->SetHighColor(kBlack); view->DrawString("Haiku [ÖÜÄöüä]", 13, BPoint(frame.left, baseline)); }
// 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))); }
virtual void GetContentSize(float *width, float *height) { const char* l = Label(); if (!boldFont || !l) { inherited::GetContentSize(width, height); return; } font_height fh; boldFont->GetHeight(&fh); float w = boldFont->StringWidth(l), h = ceil(fh.ascent + fh.descent + fh.leading); if (width) *width = w; if (height) *height = h; }
BSize ExtensionListView::MinSize() { if (!fMinSize.IsWidthSet()) { BFont font; GetFont(&font); fMinSize.width = font.StringWidth(".mmmmm"); font_height height; font.GetHeight(&height); fMinSize.height = (height.ascent + height.descent + height.leading) * 3; } return fMinSize; }
BSize BatteryInfoView::_MeasureString(const BString& string) { BFont font; GetFont(&font); BSize size; size.width = font.StringWidth(string); font_height height; font.GetHeight(&height); size.height = height.ascent + height.descent; return size; }
static void testDrawStringWithOffsets(BView* view, BRect frame) { BFont font; view->GetFont(&font); font_height height; font.GetHeight(&height); float baseline = frame.bottom - height.descent; // draw base line view->SetHighColor(kGreen); view->StrokeLine(BPoint(frame.left, baseline - 1), BPoint(frame.right, baseline -1)); view->SetHighColor(kBlack); const BPoint pointArray[] = { BPoint(frame.left, baseline) }; view->DrawString("Haiku [ÖÜÄöüä]", pointArray, sizeof(pointArray) / sizeof(pointArray[0])); }