当前位置: 首页>>代码示例>>C++>>正文


C++ BFont::GetTruncatedStrings方法代码示例

本文整理汇总了C++中BFont::GetTruncatedStrings方法的典型用法代码示例。如果您正苦于以下问题:C++ BFont::GetTruncatedStrings方法的具体用法?C++ BFont::GetTruncatedStrings怎么用?C++ BFont::GetTruncatedStrings使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BFont的用法示例。


在下文中一共展示了BFont::GetTruncatedStrings方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

float
TruncStringBase(BString* outString, const char* inString, int32 length,
	const View* view, float width, uint32 truncMode = B_TRUNCATE_MIDDLE)
{
	// we are using a template version of this call to make sure
	// the right StringWidth gets picked up for BView x BPoseView
	// for max speed and flexibility

	// a standard ellipsis inserting fitting algorithm
	if (view->StringWidth(inString, length) <= width)
		*outString = inString;
	else {
		const char* source[1];
		char* results[1];

		source[0] = inString;
		results[0] = outString->LockBuffer(length + 3);

		BFont font;
		view->GetFont(&font);

		font.GetTruncatedStrings(source, 1, truncMode, width, results);
		outString->UnlockBuffer();
	}

	return view->StringWidth(outString->String(), outString->Length());
}
开发者ID:looncraz,项目名称:haiku,代码行数:27,代码来源:WidgetAttributeText.cpp

示例2: Draw

void TToolTipView::Draw(BRect /* where */)
{
	char		*src_strings[1];
	char		*tmp_string;
	char		*truncated_strings[1];
	BFont		font;
	BRect		r = Bounds();
	font_height	finfo;

	// draw border around window
#ifdef kDRAW_WINDOW_FRAME
	SetHighColor(0, 0, 0, 255);
	StrokeRect(r);
	r.InsetBy(1, 1);
#endif
	SetHighColor(kLIGHT_VIEW_COLOR);
	StrokeLine(BPoint(r.left, r.bottom), BPoint(r.left, r.top));
	StrokeLine(BPoint(r.left + 1, r.top), BPoint(r.right - 1, r.top));
	SetHighColor(kDARK_VIEW_COLOR);
	StrokeLine(BPoint(r.right, r.top), BPoint(r.right, r.bottom));
	StrokeLine(BPoint(r.right - 1, r.bottom), BPoint(r.left + 1, r.bottom));

	// set pen position
	GetFont(&font);
	font.GetHeight(&finfo);
	MovePenTo(kHOR_MARGIN + 1, kVER_MARGIN + finfo.ascent);

	// truncate string if needed
	src_strings[0] = fString;
	tmp_string = (char *)malloc(strlen(fString) + 16);
	truncated_strings[0] = tmp_string;
	font.GetTruncatedStrings((const char **)src_strings, 1, B_TRUNCATE_END,
		Bounds().Width() - (2 * kHOR_MARGIN) + 1, truncated_strings);

	// draw string
	SetLowColor(kVIEW_COLOR);
	SetHighColor(kTEXT_COLOR);
	DrawString(tmp_string);
	free(tmp_string);
}
开发者ID:HaikuArchives,项目名称:Globe,代码行数:40,代码来源:TToolTip.cpp

示例3: Draw

//: BeOS hook function
// Draws a BeOS style title tab. This method class the two attached
// decorations to draw the maximize and close buttons.
void CMDITitleView::Draw(BRect updateRect)
{
	Window()->BeginViewTransaction();

	// --- Calc colors

	CColor background = BackgroundColor();

	CColor highlight(	MIN(background.red+80, 255),
					 	MIN(background.green+80, 255),
					 	MIN(background.blue+80, 255) );
					 	
	CColor darkShadow(	MAX(background.red-81, 0),
						MAX(background.green-81, 0),
						MAX(background.blue-81, 0)	);

	CColor textColor = Active() ? CColor::Black : CColor(80, 80, 80);

	// --- Fill background
	
	SetHighColor(background);
	FillRect(updateRect);

	// --- Draw borders

	BRect bounds = Bounds();
	float width  = bounds.Width();
	float height = bounds.Height();

	SetHighColor(CColor::BeShadow);
	MovePenTo(0, height);
	StrokeLine(BPoint(0, 0));
	StrokeLine(BPoint(width, 0));
	SetHighColor(CColor::BeDarkShadow);
	MovePenTo(width, 1);
	StrokeLine(BPoint(width, height));

	SetHighColor(highlight);
	MovePenTo(1, height);
	StrokeLine(BPoint(1, 1));
	StrokeLine(BPoint(width-1, 1));
	SetHighColor(darkShadow);
	MovePenTo(width-1, 2);
	StrokeLine(BPoint(width-1, height));

	// --- Draw close button
	
	if(DisplayCloseButton()) {
		closeButton->SetPosition(CloseButtonRect().LeftTop());
		closeButton->SetBackgroundColor(background);
		closeButton->Draw();
	}

	// --- Draw maximize button
	
	if(DisplayMaximizeButton()) {
		maximizeButton->SetPosition(MaximizeButtonRect().LeftTop());
		maximizeButton->SetBackgroundColor(background);
		maximizeButton->Draw();
	}
	
	// --- Draw title
	
	BFont titleFont;
	GetTitleFont(&titleFont);	

	const char *title = target->Title();
	char *truncatedTitle = new char [strlen(title)+3];
	
	float titleWidth;
	BPoint titlePos;

	GetTitleWidthAndPos(titleWidth, titlePos);

	titleFont.GetTruncatedStrings(&title, 1, B_TRUNCATE_END, titleWidth, &truncatedTitle);

	SetHighColor(textColor);
	SetLowColor(background);
	SetFont(&titleFont);
	DrawString(truncatedTitle, strlen(truncatedTitle), titlePos);
	
	delete [] truncatedTitle;
	
	Window()->EndViewTransaction();
}
开发者ID:HaikuArchives,项目名称:BeMDI,代码行数:88,代码来源:MDITitleView.cpp


注:本文中的BFont::GetTruncatedStrings方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。