Exemple #1
0
status_t 
ScreenSaver::StartSaver(BView *view, bool preview)
{
	// save view dimensions and preview mode
	fIsPreview = preview;
	fSizeX = view->Bounds().Width();
	fSizeY = view->Bounds().Height();
	
	// set a new font, about 1/8th of view height, and bold
	BFont font;
	view->GetFont(&font);
	font.SetSize(fSizeY / 8);
	font.SetFace(B_BOLD_FACE);
	view->SetFont(&font);
	
	// find out space needed for text display
	BRect rect;
	escapement_delta delta;
	delta.nonspace = 0;
	delta.space = 0;
	font.GetBoundingBoxesForStrings(&fText, 1, B_SCREEN_METRIC, &delta, &rect);
	fTextHeight = rect.Height();
	fTextWith = rect.Width();
	
	// seed the random number generator
	srand((int)system_time());
	
	return B_OK;
}
Exemple #2
0
status_t 
Shelf::StartSaver(BView *view, bool preview)
{
	PRINT(("%p:%s(, %d)\n", this, __FUNCTION__, preview));
	if (!preview) {
		view->SetViewColor(216, 216, 216, 0);
		fShelfData.Seek(SEEK_SET, 0LL);
		fShelf = new BShelf(&fShelfData, view);
		
	}
	BString s;
	s << "preview: " << preview << " ";
	s << "BView:Name: " << view->Name() << " ";
	s << "BApp:Name: " << be_app->Name();
	
	PRINT(("%p:%s:%s\n", this, __FUNCTION__, s.String()));
	//BAlert *a = new BAlert("debug", s.String(), "Ok");
	//a->Go();
	return B_ERROR;
#if 0
	float width = view->Bounds().Width();
	float height = view->Bounds().Height();
	
	BFont font;
	view->GetFont(&font);
	font.SetSize(height / 2.5);
	view->SetFont(&font);
	
	BRect rect;
	escapement_delta delta;
	delta.nonspace = 0;
	delta.space = 0;
	// If anyone has suggestions for how to clean this up, speak up
	font.GetBoundingBoxesForStrings(&fLine1, 1, B_SCREEN_METRIC, &delta, &rect);
	float y = ((height - (rect.Height() * 2 + height / 10)) / 2) + rect.Height();
	fLine1Start.Set((width - rect.Width()) / 2, y);
	font.GetBoundingBoxesForStrings(&fLine2, 1, B_SCREEN_METRIC, &delta, &rect);
	fLine2Start.Set((width - rect.Width()) / 2, y + rect.Height() + height / 10);
	
#endif
	return B_OK;
}
Exemple #3
0
BRect URLView::GetTextRect() {
	// This function will return a BRect that contains only the text
	// and the underline, so the mouse can change and the link will
	// be activated only when the mouse is over the text itself, not
	// just within the view.
	
	// Note:  We'll use bounding boxes, because they are the most
	//        accurate, and since the user is interacting with the
	//        view, off-by-one-pixel errors look bad.
	const char *textArray[1];
	textArray[0] = Text();
	
	escapement_delta delta;
	delta.nonspace = 0;
	delta.space = 0;
	escapement_delta escapements[1];
	escapements[0] = delta;
	
	BRect returnMe;
	BRect rectArray[1];
	rectArray[0] = returnMe;
	
	BFont font;
	GetFont( &font );
	font.GetBoundingBoxesForStrings( textArray, 1, B_SCREEN_METRIC, escapements, rectArray );

	BRect frame = Frame();
	frame.OffsetTo( B_ORIGIN );
	returnMe = rectArray[0];
	
	// Get the height of the current font.
	font_height height;
	GetFontHeight( &height );
	float descent = height.descent;
	
	// Account for rounding of the floats when drawn to avoid
	// one-pixel-off errors.
	float lowerBound = 0;
	if( (((int) descent) * 2) != ((int) (descent * 2)) )
		lowerBound = 1;
	
	// Adjust the bounding box to reflect where the text is in the view.
	returnMe.bottom += 1;
	returnMe.OffsetTo( B_ORIGIN );
	float rectHeight = returnMe.Height();
	returnMe.bottom = frame.bottom - descent;
	returnMe.top = returnMe.bottom - rectHeight;
	returnMe.bottom += 1 + underlineThickness;
	returnMe.OffsetBy( 0.0, -(1 + lowerBound) );

	return returnMe;
}
Exemple #4
0
void
TTimeView::CalculateTextPlacement()
{
	BRect bounds(Bounds());

	fDateLocation.x = 0.0;
	fTimeLocation.x = 0.0;

	BFont font;
	GetFont(&font);

	const char* stringArray[1];
	stringArray[0] = fCurrentTimeStr;
	BRect rectArray[1];
	escapement_delta delta = { 0.0, 0.0 };
	font.GetBoundingBoxesForStrings(stringArray, 1, B_SCREEN_METRIC, &delta,
		rectArray);

	fTimeLocation.y = fDateLocation.y = ceilf((bounds.Height()
		- rectArray[0].Height() + 1.0) / 2.0 - rectArray[0].top);
}