Exemplo n.º 1
0
Arquivo: Rect.cpp Projeto: D-os/BeFree
inline BRect rect_intersection(BRect r1, BRect r2)
{
	if (r1.IsValid() == false || r2.IsValid() == false) return BRect();

	BRect r3;
	r3.left = max_c(r1.left, r2.left);
	r3.top = max_c(r1.top, r2.top);
	r3.right = min_c(r1.right, r2.right);
	r3.bottom = min_c(r1.bottom, r2.bottom);

	return r3;
}
Exemplo n.º 2
0
// TODO: why another version?
// point_line_dist
float
point_line_dist(BPoint start, BPoint end, BPoint p, float radius)
{
	BRect r(min_c(start.x, end.x), min_c(start.y, end.y), max_c(start.x, end.x),
		max_c(start.y, end.y));
	r.InsetBy(-radius, -radius);
	if (r.Contains(p)) {
		return fabs(agg::calc_line_point_distance(start.x, start.y, end.x, end.y,
			p.x, p.y));
	}

	return min_c(point_point_distance(start, p), point_point_distance(end, p));
}
Exemplo n.º 3
0
BRect
RemoteView::_BuildInvalidateRect(BPoint *points, int32 pointCount)
{
	BRect bounds(1000000, 1000000, 0, 0);
	for (int32 i = 0; i < pointCount; i++) {
		bounds.left = min_c(bounds.left, points[i].x);
		bounds.top = min_c(bounds.top, points[i].y);
		bounds.right = max_c(bounds.right, points[i].x);
		bounds.bottom = max_c(bounds.bottom, points[i].y);
	}

	return bounds;
}
Exemplo n.º 4
0
BRect
RemoteDrawingEngine::_BuildBounds(BPoint* points, int32 pointCount)
{
	BRect bounds(1000000, 1000000, 0, 0);
	for (int32 i = 0; i < pointCount; i++) {
		bounds.left = min_c(bounds.left, points[i].x);
		bounds.top = min_c(bounds.top, points[i].y);
		bounds.right = max_c(bounds.right, points[i].x);
		bounds.bottom = max_c(bounds.bottom, points[i].y);
	}

	return bounds;
}
Exemplo n.º 5
0
void VisualColorControl::AttachedToWindow()
{
	BPoint *points = new BPoint[3];
	points[0] = BPoint(0,0);
	points[1] = BPoint(-4,-4);
	points[2] = BPoint(4,-4);

	// calculate the initial ramps
	CalcRamps();

	// create the arrow-pictures
	BeginPicture(new BPicture());
		SetHighColor(100,100,255);
		FillPolygon(points,3);
		SetHighColor(0,0,0);
		StrokePolygon(points,3);
	down_arrow = EndPicture();

	if (Parent() != NULL)
		SetViewColor(Parent()->ViewColor());

	BStringView *sv = new BStringView(BRect(0,COLOR_HEIGHT/2,1,COLOR_HEIGHT/2),"label view",label1);
	AddChild(sv);
	float sv_width = sv->StringWidth(label1);
	sv_width = max_c(sv_width,sv->StringWidth(label2));
	sv_width = max_c(sv_width,sv->StringWidth(label3));
	font_height fHeight;
	sv->GetFontHeight(&fHeight);
	sv->ResizeTo(sv_width,fHeight.ascent+fHeight.descent);
	sv->MoveBy(0,-(fHeight.ascent+fHeight.descent)/2.0);
	BRect sv_frame = sv->Frame();
	sv_frame.OffsetBy(0,COLOR_HEIGHT);
	sv->SetAlignment(B_ALIGN_CENTER);
	sv = new BStringView(sv_frame,"label view",label2);
	AddChild(sv);
	sv->SetAlignment(B_ALIGN_CENTER);
	sv_frame.OffsetBy(0,COLOR_HEIGHT);
	sv = new BStringView(sv_frame,"label view",label3);
	AddChild(sv);
	sv->SetAlignment(B_ALIGN_CENTER);
	sv_frame.OffsetBy(0,COLOR_HEIGHT);
	sv = new BStringView(sv_frame,"label view",label4);
	AddChild(sv);
	sv->SetAlignment(B_ALIGN_CENTER);

	ramp_left_edge = sv->Bounds().IntegerWidth()+2;

	ResizeBy(ramp_left_edge,0);

	delete[] points;
}
Exemplo n.º 6
0
AboutWindow::AboutWindow()
	: BWindow(BRect(0, 0, 500, 300), B_TRANSLATE("About this system"),
		B_TITLED_WINDOW, B_AUTO_UPDATE_SIZE_LIMITS | B_NOT_ZOOMABLE)
{
	SetLayout(new BGroupLayout(B_VERTICAL));
	AddChild(new AboutView());

	// Make sure we take the minimal window size into account when centering
	BSize size = GetLayout()->MinSize();
	ResizeTo(max_c(size.width, Bounds().Width()),
		max_c(size.height, Bounds().Height()));

	CenterOnScreen();
}
Exemplo n.º 7
0
void AttribBrush::ConstructBrush ()
{
	delete fBrush;
	float rangle = -fAngle/180*M_PI;
	int ssx = 2*fX + 1;
	int ssy = 2*fY + 1;
	int sx = max_c (abs (int (ssx*cos (rangle))), abs (int ((ssy*sin (rangle))*(1.0 + sin (-rangle)/4))));
	int sy = max_c (abs (int (ssy*cos (rangle))), abs (int ((ssx*sin (rangle))*(1.0 + sin (-rangle)/4))));
	// printf ("Width: %d, Height: %d\n", sx, sy);
	fBrush = new Brush (sy*1.1, sx*1.1, fSpacing);
	mkGaussianBrush (fBrush, fX, fY, fAngle, fStrength, fHardness/10 + 1);
	bv->SetBitmap (fBrush->ToBitmap (Black, White));
//	printf ("bv = %p, fBrush = %p\n", bv, fBrush);
}
Exemplo n.º 8
0
status_t
DataTranslationsWindow::_ShowConfigView(int32 id)
{
	// Shows the config panel for the translator with the given id

	if (id < 0)
		return B_BAD_VALUE;

	BTranslatorRoster *roster = BTranslatorRoster::Default();

	// fConfigView is NULL the first time this function
	// is called, prevent a segment fault
	if (fConfigView)
		fRightBox->RemoveChild(fConfigView);

	BMessage emptyMsg;
	BRect rect(0, 0, 200, 233);
	status_t ret = roster->MakeConfigurationView(id, &emptyMsg, &fConfigView, &rect);
	if (ret != B_OK) {
		fRightBox->RemoveChild(fConfigView);
		return ret;
	}

	BRect configRect(fRightBox->Bounds());
	configRect.InsetBy(3, 3);
	configRect.bottom -= 45;
	float width = 0, height = 0;
	if ((fConfigView->Flags() & B_SUPPORTS_LAYOUT) != 0) {
		BSize configSize = fConfigView->ExplicitPreferredSize();
		width = configSize.Width();
		height = configSize.Height();
	} else {
		fConfigView->GetPreferredSize(&width, &height);
	}
	float widen = max_c(0, width - configRect.Width());
	float heighten = max_c(0, height - configRect.Height());
	if (widen > 0 || heighten > 0) {
		ResizeBy(widen, heighten);
		configRect.right += widen;
		configRect.bottom += heighten;
	}
	fConfigView->MoveTo(configRect.left, configRect.top);
	fConfigView->ResizeTo(configRect.Width(), configRect.Height());
	fConfigView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
		// force config views to all have the same color
	fRightBox->AddChild(fConfigView);

	return B_OK;
}
Exemplo n.º 9
0
float
EFontFT2::StringWidth(const char *string, float size, float spacing, float shear, bool bold, eint32 length) const
{
	EAutolock <ELocker> autolock(&etk_ft2_font_locker);

	if(!IsAttached()) return 0;

	bool isfixed = IsFixedSize(size);
	if(!fScalable && !isfixed) return 0;

	if(isfixed ? FT_Set_Pixel_Sizes(fFace, 0, (FT_UInt)size) :
		     FT_Set_Char_Size(fFace, 0, (FT_F26Dot6)(size * 64.f), 0, 0)) return 0;
//	if(FT_Set_Pixel_Sizes(fFace, 0, (FT_UInt)size)) return 0;

	eunichar *unicode = e_utf8_convert_to_unicode(string, length);
	if(!unicode) return 0;

	float width = 0;

	int minx = 0, maxx = 0;

	const eunichar *ch;
	int x = 0;
	int fontSpacing = (int)ceil((double)(spacing * size)) * 64;
	for(ch = unicode; !(ch == NULL || *ch == 0); ch = e_unicode_next(ch, NULL))
	{
		FT_UInt glyph_index = FT_Get_Char_Index(fFace, *ch);
		if(FT_Load_Glyph(fFace, glyph_index, FT_LOAD_DEFAULT))
		{
			ETK_DEBUG("[FONT]: %s --- FT_Load_Glyph failed.", __PRETTY_FUNCTION__);
			continue;
		}

		FT_Glyph_Metrics *metrics = &(fFace->glyph->metrics);

		minx = min_c(minx, x + metrics->horiBearingX);
		maxx = max_c(maxx, x + max_c(metrics->horiAdvance, metrics->horiBearingX + metrics->width));

		x += metrics->horiAdvance + fontSpacing;
	}
	if(x > fontSpacing) x -= fontSpacing;

	width = (float)(maxx - minx) / 64.f;

	free(unicode);

	return width;
}
Exemplo n.º 10
0
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);
}
Exemplo n.º 11
0
BButton*
BAlert::_CreateButton(int32 which, const char* label)
{
	BMessage* message = new BMessage(kAlertButtonMsg);
	if (message == NULL)
		return NULL;

	message->AddInt32("which", which);

	BRect rect;
	rect.top = Bounds().bottom - kBottomOffset;
	rect.bottom = rect.top;

	char name[32];
	snprintf(name, sizeof(name), "_b%ld_", which);

	BButton* button = new(std::nothrow) BButton(rect, name, label, message,
		B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
	if (button == NULL)
		return NULL;

	float width, height;
	button->GetPreferredSize(&width, &height);

	if (fButtonWidth == B_WIDTH_AS_USUAL) {
		float fontFactor = be_plain_font->Size() / 11.0f;
		width = max_c(width, kButtonUsualWidth * fontFactor);
	}

	button->ResizeTo(width, height);
	button->MoveBy(0.0f, -height);
	return button;
}
Exemplo n.º 12
0
// KeyDown
void
AlphaSlider::KeyDown(const char* bytes, int32 numBytes)
{
	if (!IsEnabled() || numBytes <= 0) {
		BControl::KeyDown(bytes, numBytes);
		return;
	}

	switch (bytes[0]) {
		case B_HOME:
			SetValue(0);
			break;
		case B_END:
			SetValue(255);
			break;

		case B_LEFT_ARROW:
		case B_UP_ARROW:
			SetValue(max_c(0, Value() - 1));
			break;
		case B_RIGHT_ARROW:
		case B_DOWN_ARROW:
			SetValue(min_c(255, Value() + 1));
			break;

		default:
			BControl::KeyDown(bytes, numBytes);
			break;
	}
}
Exemplo n.º 13
0
int32 SaturationManipulator::PreviewBitmap(Selection *selection,bool full_quality,BRegion *updated_region)
{
	progress_bar = NULL;
	current_selection = selection;
	if (settings == previous_settings ) {
		if ((last_calculated_resolution != highest_available_quality) && (last_calculated_resolution > 0))
			last_calculated_resolution = max_c(highest_available_quality,floor(last_calculated_resolution/2.0));
		else
			last_calculated_resolution = 0;
	}
	else
		last_calculated_resolution = lowest_available_quality;

	if (full_quality) {
		last_calculated_resolution = min_c(1,last_calculated_resolution);
	}
	previous_settings = settings;

	if (last_calculated_resolution > 0) {
		current_resolution = last_calculated_resolution;
		updated_region->Set(preview_bitmap->Bounds());

		target_bitmap = preview_bitmap;
		source_bitmap = copy_of_the_preview_bitmap;
		current_settings = settings;

		start_threads();
	}

	return last_calculated_resolution;
}
Exemplo n.º 14
0
void SaturationManipulator::CalculateLuminanceImage(BBitmap *bitmap)
{
	uint8 *luminance_bits = (uint8*)luminance_image->Bits();
	uint32 luminance_bpr = luminance_image->BytesPerRow();

	uint32 *bits = (uint32*)bitmap->Bits();
	uint32 bpr = bitmap->BytesPerRow()/4;

	int32 width = bitmap->Bounds().Width();
	int32 height = bitmap->Bounds().Height();

	union {
		uint8 bytes[4];
		uint32 word;
	} color;

	for (int32 y=0;y<=height;y++) {
		int32 y_times_bpr = y*bpr;
		int32 y_times_luminance_bpr = y*luminance_bpr;
		for (int32 x=0;x<=width;x++) {
			color.word = *(bits + x + y_times_bpr);
			uint8 luminance;
			luminance = min_c(255,max_c(0,0.144 * color.bytes[0] + 0.587 * color.bytes[1] + 0.299 * color.bytes[2]));
			*(luminance_bits + x + y_times_luminance_bpr) = luminance;
		}
	}
}
Exemplo n.º 15
0
// ValidScrollOffsetFor
//
// Returns the valid scroll offset next to the supplied offset.
BPoint
Scrollable::ValidScrollOffsetFor(BPoint offset, const BRect& dataRect) const
{
	float maxX = max_c(dataRect.left, dataRect.right - fVisibleWidth);
	float maxY = max_c(dataRect.top, dataRect.bottom - fVisibleHeight);
	// adjust the offset to be valid
	if (offset.x < dataRect.left)
		offset.x = dataRect.left;
	else if (offset.x > maxX)
		offset.x = maxX;
	if (offset.y < dataRect.top)
		offset.y = dataRect.top;
	else if (offset.y > maxY)
		offset.y = maxY;
	return offset;
}
Exemplo n.º 16
0
// AlignInFrame
void
BLayoutUtils::AlignInFrame(BView* view, BRect frame)
{
 	BSize maxSize = view->MaxSize();
 	BAlignment alignment = view->LayoutAlignment();
 
 	if (view->HasHeightForWidth()) {
 		// The view has height for width, so we do the horizontal alignment
 		// ourselves and restrict the height max constraint respectively.
 
 		if (maxSize.width < frame.Width()
 			&& alignment.horizontal != B_ALIGN_USE_FULL_WIDTH) {
 			frame.OffsetBy(floor((frame.Width() - maxSize.width)
 				* alignment.RelativeHorizontal()), 0);
 			frame.right = frame.left + maxSize.width;
 		}
 		alignment.horizontal = B_ALIGN_USE_FULL_WIDTH;
 
 		float minHeight;
 		float maxHeight;
 		float preferredHeight;
 		view->GetHeightForWidth(frame.Width(), &minHeight, &maxHeight,
 			&preferredHeight);
 		
 		frame.bottom = frame.top + max_c(frame.Height(), minHeight);
 		maxSize.height = minHeight;
 	}
 
 	frame = AlignInFrame(frame, maxSize, alignment);
 	view->MoveTo(frame.LeftTop());
 	view->ResizeTo(frame.Size());
}
Exemplo n.º 17
0
void
BListView::_RescanSelection(int32 from, int32 to)
{
	if (from > to) {
		int32 tmp = from;
		from = to;
		to = tmp;
	}

	from = max_c(0, from);
	to = min_c(to, CountItems() - 1);

	if (fAnchorIndex != -1) {
		if (fAnchorIndex == from)
			fAnchorIndex = to;
		else if (fAnchorIndex == to)
			fAnchorIndex = from;
	}

	for (int32 i = from; i <= to; i++) {
		if (ItemAt(i)->IsSelected()) {
			fFirstSelected = i;
			break;
		}
	}

	if (fFirstSelected > from)
		from = fFirstSelected;

	fLastSelected = fFirstSelected;
	for (int32 i = from; i <= to; i++) {
		if (ItemAt(i)->IsSelected())
			fLastSelected = i;
	}
}
Exemplo n.º 18
0
void
GPCapabilityExtractor::ResolutionParameter(const char* name, const char* key,
		const char* displayName, int x, int y)
{
	bool isDefault = fDefaultKey == key;
	EnumCap* capability;
	int resolution;

	switch (fState) {
		case kExtractResolutionParameter:
			if (x <= 0 || y <= 0) {
				// usually this is the entry for the "Default" resolution
				// if we want to show this in the UI, we need a way to
				// determine the resolution (x and y) for it, because
				// libprint needs it for rasterization
				fCapabilities->fResolutions.DecreaseSize();
				break;
			}

			// TODO remove this workaround when libprint supports x != y too
			// for now use the maximum resolution to render the page bands
			resolution = max_c(x, y);

			capability = new ResolutionCap(displayName,	isDefault, fIndex,
				resolution, resolution);
			AddCapability(fCapabilities->fResolutions, capability, key);
			break;

		default:
			break;
	}
}
Exemplo n.º 19
0
// FrameResized
void
ListLabelView::FrameResized(float width, float height)
{
	Invalidate(BRect(min_c(fOldWidth - 1, width - 1), 0,
		max_c(fOldWidth - 1, width - 1), height));
	fOldWidth = width;
}
Exemplo n.º 20
0
status_t
VolumeCryptContext::Setup(int fd, const uint8* key, uint32 keyLength,
	const uint8* random, uint32 randomLength)
{
	off_t size;
	status_t status = get_size(fd, size);
	if (status != B_OK)
		return status;

	fOffset = max_c(4096, BLOCK_SIZE);
	fSize = size - fOffset;
	fHidden = false;

	const uint8* salt = random;
	random += PKCS5_SALT_SIZE;

	uint8 buffer[BLOCK_SIZE];
	memcpy(buffer, salt, PKCS5_SALT_SIZE);
	memset(buffer + PKCS5_SALT_SIZE, 0, BLOCK_SIZE - PKCS5_SALT_SIZE);

	true_crypt_header& header = *(true_crypt_header*)&buffer[PKCS5_SALT_SIZE];
	header.magic = B_HOST_TO_BENDIAN_INT32(kTrueCryptMagic);
	header.version = B_HOST_TO_BENDIAN_INT16(0x4);
	header.required_program_version = B_HOST_TO_BENDIAN_INT16(0x600);
	header.volume_size = B_HOST_TO_BENDIAN_INT64(fSize);
	header.encrypted_offset = B_HOST_TO_BENDIAN_INT64(fOffset);
	header.encrypted_size = B_HOST_TO_BENDIAN_INT64(fSize);
	header.flags = 0;
	memcpy(header.disk_key, random, sizeof(header.disk_key));
	header.crc_checksum = B_HOST_TO_BENDIAN_INT32(crc32(header.disk_key, 256));
	header.header_crc_checksum
		= B_HOST_TO_BENDIAN_INT32(crc32((uint8*)&header, 188));

	return _WriteHeader(fd, key, keyLength, 0, buffer);
}
Exemplo n.º 21
0
static int32
low_resource_state_no_update(uint32 resources)
{
	int32 state = B_NO_LOW_RESOURCE;

	if ((resources & B_KERNEL_RESOURCE_PAGES) != 0)
		state = max_c(state, sLowPagesState);
	if ((resources & B_KERNEL_RESOURCE_MEMORY) != 0)
		state = max_c(state, sLowMemoryState);
	if ((resources & B_KERNEL_RESOURCE_SEMAPHORES) != 0)
		state = max_c(state, sLowSemaphoresState);
	if ((resources & B_KERNEL_RESOURCE_ADDRESS_SPACE) != 0)
		state = max_c(state, sLowSpaceState);

	return state;
}
Exemplo n.º 22
0
float
TeamsColumn::GetPreferredWidth(BField *_field, BView* parent) const
{
	BBitmapStringField* bitmapField
		= dynamic_cast<BBitmapStringField*>(_field);
	BStringField* stringField = dynamic_cast<BStringField*>(_field);

	float parentWidth = Inherited::GetPreferredWidth(_field, parent);
	float width = 0.0;

	if (bitmapField) {
		const BBitmap* bitmap = bitmapField->Bitmap();
		BFont font;
		parent->GetFont(&font);
		width = font.StringWidth(bitmapField->String()) + 3 * sTextMargin;
		if (bitmap)
			width += bitmap->Bounds().Width();
		else
			width += 16;
	} else if (stringField) {
		BFont font;
		parent->GetFont(&font);
		width = font.StringWidth(stringField->String()) + 2 * sTextMargin;
	}
	return max_c(width, parentWidth);
}
Exemplo n.º 23
0
// _LayoutItem
void
BSplitLayout::_LayoutItem(BLayoutItem* item, BRect frame, bool visible)
{
	// update the layout frame
	ItemLayoutInfo* info = _ItemLayoutInfo(item);
	info->isVisible = visible;
	if (visible)
		info->layoutFrame = frame;
	else
		info->layoutFrame = BRect(0, 0, -1, -1);

	// update min/max
	info->min = item->MinSize();
	info->max = item->MaxSize();

	if (item->HasHeightForWidth()) {
		BSize size = _SubtractInsets(View()->Frame().Size());
		float minHeight, maxHeight;
		item->GetHeightForWidth(size.width, &minHeight, &maxHeight, NULL);
		info->min.height = max_c(info->min.height, minHeight);
		info->max.height = min_c(info->max.height, maxHeight);
	}

	// layout the item
	if (visible)
		item->AlignInFrame(frame);
}
Exemplo n.º 24
0
/*static*/ status_t
InterfaceAddress::Set(sockaddr** _address, const sockaddr* to)
{
	sockaddr* address = *_address;

	if (to == NULL || to->sa_family == AF_UNSPEC) {
		// Clear address
		free(address);
		*_address = NULL;
		return B_OK;
	}

	// Set address

	size_t size = max_c(to->sa_len, sizeof(sockaddr));
	if (size > sizeof(sockaddr_storage))
		size = sizeof(sockaddr_storage);

	address = Prepare(_address, size);
	if (address == NULL)
		return B_NO_MEMORY;

	memcpy(address, to, size);
	address->sa_len = size;

	return B_OK;
}
Exemplo n.º 25
0
void
Spinner::GetPreferredSize(float *width, float *height)
{
	float w, h;
	
	// This code shamelessly copied from the Haiku TextControl.cpp and adapted
	
	// we need enough space for the label and the child text view
	font_height fontHeight;
	fTextControl->GetFontHeight(&fontHeight);
	float labelHeight = ceil(fontHeight.ascent + fontHeight.descent + fontHeight.leading);
	float textHeight = fTextControl->TextView()->LineHeight(0) + 4.0;

	h = max_c(labelHeight, textHeight);
	
	w = 25.0f + ceilf(fTextControl->StringWidth(fTextControl->Label())) + 
		ceilf(fTextControl->StringWidth(fTextControl->Text()));
	
	w += B_V_SCROLL_BAR_WIDTH;
	if (h < fDownButton->Frame().bottom)
		h = fDownButton->Frame().bottom;
	
	if (width)
		*width = w;
	if (height)
		*height = h;
}
Exemplo n.º 26
0
// Layout
void
SimpleLayouter::Layout(LayoutInfo* layoutInfo, float _size)
{
	int32 size = int32(_size + 1);

	fLayoutInfo = (MyLayoutInfo*)layoutInfo;
	
	_ValidateMinMax();

	if (fElementCount == 0)
		return;

	fLayoutInfo->fSize = max_c(size, fMin);

	// layout the elements
	if (fLayoutInfo->fSize >= fMax)
		_LayoutMax();
	else
		_LayoutStandard();

	// set locations
	int location = 0;
	for (int i = 0; i < fElementCount; i++) {
		fLayoutInfo->fElements[i].location = location;
		location += fSpacing + fLayoutInfo->fElements[i].size;
	}
}
Exemplo n.º 27
0
InfoWin::InfoWin(BPoint leftTop, Controller* controller)
	:
	BWindow(BRect(leftTop.x, leftTop.y, leftTop.x + MIN_WIDTH - 1,
		leftTop.y + 300), NAME, B_TITLED_WINDOW,
		B_ASYNCHRONOUS_CONTROLS | B_NOT_RESIZABLE | B_NOT_ZOOMABLE),
	fController(controller),
	fControllerObserver(new ControllerObserver(this,
		OBSERVE_FILE_CHANGES | OBSERVE_TRACK_CHANGES | OBSERVE_STAT_CHANGES))
{
	BRect rect = Bounds();

	// accomodate for big fonts
	float div = max_c(2 * 32, be_plain_font->StringWidth("Display Mode") + 10);

	fInfoView = new InfoView(rect, "background", div);
	fInfoView->SetViewColor(ui_color(B_DOCUMENT_BACKGROUND_COLOR));
	AddChild(fInfoView);

	BFont bigFont(be_plain_font);
	bigFont.SetSize(bigFont.Size() + 6);
	font_height fh;
	bigFont.GetHeight(&fh);
	fFilenameView = new BStringView(
		BRect(div + 10, 20, rect.right - 10, 20 + fh.ascent + 5),
		"filename", "");
	AddChild(fFilenameView);
	fFilenameView->SetFont(&bigFont);
	fFilenameView->SetViewColor(fInfoView->ViewColor());
	fFilenameView->SetLowColor(fInfoView->ViewColor());
#ifdef B_BEOS_VERSION_DANO /* maybe we should support that as well ? */
	fFilenameView->SetTruncation(B_TRUNCATE_END);
#endif

	rect.top = BASE_HEIGHT;

	BRect lr(rect);
	BRect cr(rect);
	lr.right = div - 1;
	cr.left = div + 1;
	BRect tr;
	tr = lr.OffsetToCopy(0, 0).InsetByCopy(5, 1);
	fLabelsView = new BTextView(lr, "labels", tr, B_FOLLOW_BOTTOM);
	fLabelsView->SetViewColor(kGreen);
	fLabelsView->SetAlignment(B_ALIGN_RIGHT);
	fLabelsView->SetWordWrap(false);
	AddChild(fLabelsView);
	tr = cr.OffsetToCopy(0, 0).InsetByCopy(10, 1);
	fContentsView = new BTextView(cr, "contents", tr, B_FOLLOW_BOTTOM);
	fContentsView->SetWordWrap(false);
	AddChild(fContentsView);

	fLabelsView->MakeSelectable();
	fContentsView->MakeSelectable();

	fController->AddListener(fControllerObserver);
	Update();

	Show();
}
Exemplo n.º 28
0
void ArrowedView::GetPreferredSize(float *width, float *height)
{
	fArrowButton->GetPreferredSize(width, height);
	(*height) ++;

	if (Value()) {
		if (CountChildren()==1) {
			*height += 15;
		}
		else {
			*width	= max_c( *width, fMaxWidth );
			*height	= max_c( *height, fMaxHeight );

			(*height) ++;
		}
	}
}
Exemplo n.º 29
0
static inline int32
icon_layout_scale()
{
#ifdef __ANTARES__
	return max_c(1, ((int32)be_plain_font->Size() + 15) / 16);
#endif
	return 1;
}
Exemplo n.º 30
0
void
WorkspacesView::_DrawWorkspace(DrawingEngine* drawingEngine,
	BRegion& redraw, int32 index)
{
	BRect rect = _WorkspaceAt(index);

	Workspace workspace(*Window()->Desktop(), index);
	bool active = workspace.IsCurrent();
	if (active) {
		// draw active frame
		rgb_color black = (rgb_color){ 0, 0, 0, 255 };
		drawingEngine->StrokeRect(rect, black);
	} else if (index == fSelectedWorkspace) {
		rgb_color gray = (rgb_color){ 80, 80, 80, 255 };
		drawingEngine->StrokeRect(rect, gray);
	}

	rect.InsetBy(1, 1);

	rgb_color color = workspace.Color();
	if (!active)
		_DarkenColor(color);

	// draw windows

	BRegion backgroundRegion = redraw;

	// TODO: would be nice to get the real update region here

	BRect screenFrame = _ScreenFrame(index);

	BRegion workspaceRegion(rect);
	backgroundRegion.IntersectWith(&workspaceRegion);
	drawingEngine->ConstrainClippingRegion(&backgroundRegion);

	ServerFont font = fDrawState->Font();
	font.SetSize(fWindow->ServerWindow()->App()->PlainFont().Size());
	float reducedSize = ceilf(max_c(8.0f,
		min_c(Frame().Height(), Frame().Width()) / 15));
	if (font.Size() > reducedSize)
		font.SetSize(reducedSize);
	fDrawState->SetFont(font);
	drawingEngine->SetFont(font);

	// We draw from top down and cut the window out of the clipping region
	// which reduces the flickering
	::Window* window;
	BPoint leftTop;
	while (workspace.GetPreviousWindow(window, leftTop) == B_OK) {
		_DrawWindow(drawingEngine, rect, screenFrame, window,
			leftTop, backgroundRegion, active);
	}

	// draw background
	drawingEngine->FillRect(rect, color);

	drawingEngine->ConstrainClippingRegion(&redraw);
}