本文整理汇总了C++中BFont类的典型用法代码示例。如果您正苦于以下问题:C++ BFont类的具体用法?C++ BFont怎么用?C++ BFont使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BFont类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void
CharacterWindow::_SetFont(const char* family, const char* style)
{
BFont font = fCharacterView->CharacterFont();
font.SetFamilyAndStyle(family, style);
fCharacterView->SetCharacterFont(font);
fGlyphView->SetFont(&font, B_FONT_FAMILY_AND_STYLE);
}
示例2:
void
TeamDescriptionView::SetItem(TeamListItem* item)
{
fItem = item;
if (item == NULL) {
int32 styleStart = 0;
int32 styleEnd = 0;
BString text;
text.SetToFormat(fInfoString, fSeconds);
fInfoTextView->SetText(text);
if (fRebootRunner != NULL && fSeconds < 4) {
styleStart = text.FindLast('\n');
styleEnd = text.Length();
}
if (styleStart != styleEnd && fInfoTextView != NULL) {
BFont font;
fInfoTextView->GetFont(&font);
font.SetFace(B_BOLD_FACE);
fInfoTextView->SetStylable(true);
fInfoTextView->SetFontAndColor(styleStart, styleEnd, &font);
}
} else {
fTeamName->SetText(item->Path()->Path());
if (item->IsSystemServer()) {
if (fSysComponent->IsHidden(fSysComponent))
fSysComponent->Show();
} else {
if (!fSysComponent->IsHidden(fSysComponent))
fSysComponent->Hide();
}
if (item->IsRefusingToQuit()) {
if (fQuitOverdue->IsHidden(fQuitOverdue))
fQuitOverdue->Show();
} else {
if (!fQuitOverdue->IsHidden(fQuitOverdue))
fQuitOverdue->Hide();
}
fIconView->SetIcon(item->Path()->Path());
}
if (fLayout == NULL)
return;
if (item == NULL)
fLayout->SetVisibleItem((int32)0);
else
fLayout->SetVisibleItem((int32)1);
Invalidate();
}
示例3: scnr
bool Bookmark::Read(const char* name) {
Scanner scnr(name);
if (scnr.InitCheck() == B_OK) {
BString s; float version; bool ok;
ok = scnr.ReadName(&s) && scnr.ReadFloat(&version);
if (!ok || strcmp(s.String(), "Bookmarks") != 0 || (version != 1.0 && version != 2.0) ) {
REPORT(kError, 0, "Bookmarks (line %d, column %d): '%s' not a bookmarks file or wrong version!", scnr.Line(), scnr.Column(), name);
return false;
}
while (!scnr.IsEOF()) {
float level, size;
bool expanded = false;
BString family, style, expand;
if (!(scnr.ReadFloat(&level) && level >= 1.0 && level <= 10.0)) {
REPORT(kError, 0, "Bookmarks (line %d, column %d): Invalid level", scnr.Line(), scnr.Column());
return false;
}
if (!scnr.ReadString(&family)) {
REPORT(kError, 0, "Bookmarks (line %d, column %d): Invalid font family", scnr.Line(), scnr.Column());
return false;
}
if (!scnr.ReadString(&style)) {
REPORT(kError, 0, "Bookmarks (line %d, column %d): Invalid font style", scnr.Line(), scnr.Column());
return false;
}
if (!scnr.ReadFloat(&size)) {
REPORT(kError, 0, "Bookmarks (line %d, column %d): Invalid font size", scnr.Line(), scnr.Column());
return false;
}
if (version == 2.0) {
if (!scnr.ReadName(&expand) || (strcmp(expand.String(), "expanded") != 0 && strcmp(expand.String(), "collapsed") != 0)) {
REPORT(kError, 0, "Bookmarks (line %d, column %d): Invalid expanded value", scnr.Line(), scnr.Column());
return false;
}
expanded = strcmp(expand.String(), "expanded") == 0;
}
if (Exists(family.String(), style.String())) {
BFont font;
font.SetFamilyAndStyle(family.String(), style.String());
font.SetSize(size);
AddDefinition((int)level, &font, expanded);
} else {
REPORT(kWarning, 0, "Bookmarks (line %d, column %d): Font %s-%s not available!", scnr.Line(), scnr.Column(), family.String(), style.String());
}
scnr.SkipSpaces();
}
return true;
} else {
REPORT(kError, 0, "Bookmarks: Could not open bookmarks file '%d'", name);
}
return false;
}
示例4: max_c
float
BStringColumn::GetPreferredWidth(BField *_field, BView* parent) const
{
BStringField* field = static_cast<BStringField*>(_field);
BFont font;
parent->GetFont(&font);
float width = font.StringWidth(field->String()) + 2 * kTEXT_MARGIN;
float parentWidth = BTitledColumn::GetPreferredWidth(_field, parent);
return max_c(width, parentWidth);
}
示例5:
/*static*/ int32
DataView::WidthForFontSize(float size)
{
BFont font = be_fixed_font;
font.SetSize(size);
float charWidth = font.StringWidth("w");
return (int32)ceilf(charWidth * (kBlockSize * 4 + kPositionLength + 6)
+ 2 * kHorizontalSpace);
}
示例6:
void TSorterListItem::Update(BView *owner, const BFont *font)
{
// This is a cheap hack to get the height of the listItem set
// properly. We aren't actually using a font this large.
BFont theFont;
owner->GetFont(&theFont);
theFont.SetSize(kSorterFontSize + 6);
BListItem::Update(owner, &theFont);
}
示例7: GetPreferredSize
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);
};
示例8: SetHighColor
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());
}
}
}
示例9: GetFontHeight
void
MediaFileInfoView::Draw(BRect /*update*/)
{
font_height fh;
GetFontHeight(&fh);
BPoint p(2, fh.ascent + fh.leading);
BFont font;
GetFont(&font);
font.SetFace(B_BOLD_FACE);
font.SetSize(12);
SetFont(&font);
if (fMediaFile == NULL) {
DrawString(NO_FILE_LABEL, p);
return;
}
BString aFmt, vFmt, aDetails, vDetails, duration;
_GetFileInfo(&aFmt, &vFmt, &aDetails, &vDetails, &duration);
// draw filename
DrawString(fRef.name, p);
float lineHeight = fh.ascent + fh.descent + fh.leading;
p.y += (float)ceil(lineHeight * 1.5);
float durLen = StringWidth(DURATION_LABEL) + 5;
float audLen = StringWidth(AUDIO_INFO_LABEL) + 5;
float vidLen = StringWidth(VIDEO_INFO_LABEL) + 5;
float maxLen = MAX(durLen, audLen);
maxLen = MAX(maxLen, vidLen);
// draw labels
DrawString(AUDIO_INFO_LABEL, p + BPoint(maxLen - audLen, 0));
BPoint p2 = p;
p2.x += maxLen + 4;
p.y += lineHeight * 2;
DrawString(VIDEO_INFO_LABEL, p + BPoint(maxLen - vidLen, 0));
p.y += lineHeight * 2;
DrawString(DURATION_LABEL, p + BPoint(maxLen - durLen, 0));
// draw audio/video/duration info
font.SetFace(B_REGULAR_FACE);
font.SetSize(10);
SetFont(&font);
DrawString(aFmt.String(), p2);
p2.y += lineHeight;
DrawString(aDetails.String(), p2);
p2.y += lineHeight;
DrawString(vFmt.String(), p2);
p2.y += lineHeight;
DrawString(vDetails.String(), p2);
p2.y += lineHeight;
DrawString(duration.String(), p2);
}
示例10: Read
status_t
CanvasMessage::ReadFontState(BFont& font)
{
uint8 encoding, spacing;
uint16 face;
uint32 flags, familyAndStyle;
font_direction direction;
float falseBoldWidth, rotation, shear, size;
Read(direction);
Read(encoding);
Read(flags);
Read(spacing);
Read(shear);
Read(rotation);
Read(falseBoldWidth);
Read(size);
Read(face);
status_t result = Read(familyAndStyle);
if (result != B_OK)
return result;
font.SetFamilyAndStyle(familyAndStyle);
font.SetEncoding(encoding);
font.SetFlags(flags);
font.SetSpacing(spacing);
font.SetShear(shear);
font.SetRotation(rotation);
font.SetFalseBoldWidth(falseBoldWidth);
font.SetSize(size);
font.SetFace(face);
return B_OK;
}
示例11: Draw
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);
}
示例12: Bounds
KouhoWindow::KouhoWindow( BFont *font, BLooper *looper )
:BWindow( DUMMY_RECT,
"kouho", B_MODAL_WINDOW_LOOK,
B_FLOATING_ALL_WINDOW_FEEL,
B_NOT_RESIZABLE | B_NOT_CLOSABLE |
B_NOT_ZOOMABLE | B_NOT_MINIMIZABLE | B_AVOID_FOCUS |
B_NOT_ANCHORED_ON_ACTIVATE )
{
float fontHeight;
BRect frame;
BFont indexfont;
cannaLooper = looper;
kouhoFont = font;
font_family family;
font_style style;
strcpy( family, "Haru" );
strcpy( style, "Regular" );
indexfont.SetFamilyAndStyle( family, style );
indexfont.SetSize( 10 );
#ifdef DEBUG
SERIAL_PRINT(( "kouhoWindow: Constructor called.\n" ));
#endif
//setup main pane
indexWidth = indexfont.StringWidth( "W" ) + INDEXVIEW_SIDE_MARGIN * 2;
minimumWidth = indexfont.StringWidth( "ギリシャ 100/100" );
frame = Bounds();
frame.left = indexWidth + 2;
frame.bottom -= INFOVIEW_HEIGHT;
kouhoView = new KouhoView( frame );
BRect screenrect = BScreen( this ).Frame();
kouhoView->SetTextRect( screenrect ); //big enough
kouhoView->SetFontAndColor( kouhoFont );
kouhoView->SetWordWrap( false );
AddChild( kouhoView );
fontHeight = kouhoView->LineHeight();
frame = Bounds();
frame.right = indexWidth;
frame.bottom = frame.bottom - INFOVIEW_HEIGHT + 1;
indexView = new KouhoIndexView( frame, fontHeight );
indexView->SetFont( &indexfont );
AddChild( indexView );
frame = Bounds();
frame.top = frame.bottom - INFOVIEW_HEIGHT + 1;
infoView = new KouhoInfoView( frame );
infoView->SetFont( &indexfont );
infoView->SetAlignment( B_ALIGN_RIGHT );
AddChild( infoView );
}
示例13:
// SetFont
void
Painter::SetFont(const BFont& font)
{
//fFont.SetFamilyAndStyle(font.GetFamily(), font.GetStyle());
fFont.SetSpacing(font.Spacing());
fFont.SetShear(font.Shear());
fFont.SetRotation(font.Rotation());
fFont.SetSize(font.Size());
_UpdateFont();
}
示例14: string
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';
}
示例15: BView
HVIFView::HVIFView(const char* name, uint32 flags, TranslatorSettings *settings)
:
BView(name, flags, new BGroupLayout(B_VERTICAL)),
fSettings(settings)
{
BAlignment labelAlignment(B_ALIGN_LEFT, B_ALIGN_NO_VERTICAL);
BStringView* title= new BStringView("title",
B_TRANSLATE("Native Haiku icon format translator"));
title->SetFont(be_bold_font);
title->SetExplicitAlignment(labelAlignment);
char versionString[256];
snprintf(versionString, sizeof(versionString),
B_TRANSLATE("Version %d.%d.%d, %s"),
int(B_TRANSLATION_MAJOR_VERSION(HVIF_TRANSLATOR_VERSION)),
int(B_TRANSLATION_MINOR_VERSION(HVIF_TRANSLATOR_VERSION)),
int(B_TRANSLATION_REVISION_VERSION(HVIF_TRANSLATOR_VERSION)),
__DATE__);
BStringView* version = new BStringView("version", versionString);
version->SetExplicitAlignment(labelAlignment);
BStringView* copyright = new BStringView("copyright",
B_UTF8_COPYRIGHT"2009 Haiku Inc.");
copyright->SetExplicitAlignment(labelAlignment);
int32 renderSize = fSettings->SetGetInt32(HVIF_SETTING_RENDER_SIZE);
BString label = B_TRANSLATE("Render size:");
label << " " << renderSize;
fRenderSize = new BSlider("renderSize", label.String(),
NULL, 1, 32, B_HORIZONTAL);
fRenderSize->SetValue(renderSize / 8);
fRenderSize->SetHashMarks(B_HASH_MARKS_BOTTOM);
fRenderSize->SetHashMarkCount(16);
fRenderSize->SetModificationMessage(
new BMessage(HVIF_SETTING_RENDER_SIZE_CHANGED));
fRenderSize->SetExplicitAlignment(labelAlignment);
float padding = 5.0f;
BLayoutBuilder::Group<>(this, B_VERTICAL, padding)
.SetInsets(padding)
.Add(title)
.Add(version)
.Add(copyright)
.Add(fRenderSize)
.AddGlue();
BFont font;
GetFont(&font);
SetExplicitPreferredSize(
BSize((font.Size() * 270) / 12, (font.Size() * 100) / 12));
}