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


C++ BBitmap::Bounds方法代码示例

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


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

示例1: CreatePicture

/*------------------------------------------------------------------------------*\
	( )
		-	
\*------------------------------------------------------------------------------*/
BPicture* BmToolbarButton::CreatePicture( int32 mode, float width, 
														float height) {
	const char* label = mLabel.String();
	BmBitmapHandle* imageHandle 
		= TheResources->IconByName(BmString("Button_")<<mResourceName);
	BBitmap* image = imageHandle ? imageHandle->bitmap : NULL;
	// Calc icon/label positions
	BFont font( be_plain_font);
	bool showIcons = ThePrefs->GetBool( "ShowToolbarIcons", true);
	BmString labelMode = ThePrefs->GetString( "ShowToolbarLabel", "Bottom");
	float labelWidth 
		= (label && labelMode != "Hide") ? font.StringWidth( label) : 0;
	float labelHeight 
		= (label && labelMode != "Hide") 
				? TheResources->FontLineHeight( &font) 
				: 0;
	float iconWidth  = (showIcons && image) ? image->Bounds().Width()  : 0;
	float iconHeight = (showIcons && image) ? image->Bounds().Height() : 0;

	BPoint posIcon( 0,0), posLabel( 0,0);
	if (showIcons && (labelMode == "Left")) {
		// Icon + Label/Left
		float d = (width-(mNeedsLatch ? DIVLATCHW : 0)-DIVW-labelWidth-iconWidth)/2;
		posLabel = BPoint( d,(height-labelHeight)/2);
		posIcon = BPoint( d+DIVW+labelWidth+(mNeedsLatch ? DIVLATCHW : 0),
								(height-iconHeight)/2-1);
	} else if (showIcons && (labelMode == "Right")) {
		// Icon + Label/Right
		float d = (width-(mNeedsLatch ? DIVLATCHW : 0)-DIVW-labelWidth-iconWidth)/2;
		posLabel = BPoint( d+DIVW+iconWidth,(height-labelHeight)/2);
		posIcon = BPoint( d,(height-iconHeight)/2-1);
	} else if (showIcons && (labelMode == "Top")) {
		// Icon + Label/top
		float d = (height-DIVH-labelHeight-iconHeight)/2-2;
		posLabel = BPoint( (width-labelWidth-(mNeedsLatch ? DIVLATCHW : 0))/2, d);
		posIcon = BPoint( (width-iconWidth)/2-1,d+DIVH+labelHeight);
	} else if (showIcons && (labelMode == "Bottom")) {
		// Icon + Label/bottom
		float d = (height-DIVH-labelHeight-iconHeight)/2;
		posLabel = BPoint( (width-labelWidth-(mNeedsLatch ? DIVLATCHW : 0))/2, 
								 d+DIVH+iconHeight);
		posIcon = BPoint( (width-iconWidth)/2-1,d);
	} else if (!showIcons && labelMode != "Hide") {
		// Label only
		posLabel = BPoint( (width-labelWidth-(mNeedsLatch ? DIVLATCHW : 0))/2, 
								 (height-labelHeight)/2);
	} else if (showIcons && labelMode == "Hide") {
		// Icon only
		posIcon = BPoint( (width-iconWidth-(mNeedsLatch ? DIVLATCHW : 0))/2,
								(height-iconHeight)/2);
	}
	
	if (mNeedsLatch) {
		if (labelMode == "Hide")
			mLatchRect.Set( posIcon.x+iconWidth+2, 
								 posIcon.y+iconHeight/2-LATCHSZ/2, 
								 width, height);
		else
			mLatchRect.Set( posLabel.x+labelWidth+2, 
								 posLabel.y+labelHeight/2-LATCHSZ/2, 
								 width, height);
	} else
		mLatchRect.Set( -1, -1, -1, -1);

	// Draw
	BRect rect(0,0,width-1,height-1);
	BView* view = new BView( rect, NULL, B_FOLLOW_NONE, 0);
	BBitmap* drawImage = new BBitmap( rect, B_RGBA32, true);
	drawImage->AddChild( view);
	drawImage->Lock();
	BPicture* picture = new BPicture();
	view->BeginPicture( picture);
	view->SetHighColor( ui_color( B_PANEL_TEXT_COLOR));
	view->SetViewColor( B_TRANSPARENT_COLOR);
	view->SetLowColor( ui_color( B_PANEL_BACKGROUND_COLOR));

#ifndef __HAIKU__
	BmToolbar* toolbar = dynamic_cast<BmToolbar*>(Parent()->Parent());
	BBitmap* toolbarBackground = NULL;
	if (toolbar) {
		toolbarBackground = toolbar->BackgroundBitmap();
		if (toolbarBackground)
			view->DrawBitmap( toolbarBackground, Frame(), rect);
	}

	if (mode == STATE_ON) {
		rect.InsetBy( 1, 1);
		view->BeginLineArray(4);
		view->AddLine( rect.LeftBottom(), rect.LeftTop(), 
							BmWeakenColor(B_SHADOW_COLOR, BeShadowMod));
		view->AddLine( rect.LeftTop(), rect.RightTop(), 
							BmWeakenColor(B_SHADOW_COLOR, BeShadowMod));
		view->AddLine( rect.LeftBottom(), rect.RightBottom(), 
							ui_color( B_SHINE_COLOR));
		view->AddLine( rect.RightBottom(), rect.RightTop(), 
							ui_color( B_SHINE_COLOR));
//.........这里部分代码省略.........
开发者ID:HaikuArchives,项目名称:Beam,代码行数:101,代码来源:BmToolbarButton.cpp

示例2: namePosition

void
DriveItem::DrawItem(BView* owner, BRect frame, bool complete)
{
	owner->PushState();
	owner->SetDrawingMode(B_OP_ALPHA);

	if (IsSelected() || complete) {
		if (IsSelected()) {
			owner->SetHighColor(ui_color(B_LIST_SELECTED_BACKGROUND_COLOR));
			owner->SetLowColor(owner->HighColor());
		} else
			owner->SetHighColor(owner->LowColor());

		owner->FillRect(frame);
	}

	if (!IsEnabled()) {
		rgb_color textColor;
		if (IsSelected())
			textColor = ui_color(B_LIST_SELECTED_ITEM_TEXT_COLOR);
		else
			textColor = ui_color(B_LIST_ITEM_TEXT_COLOR);

		if (textColor.red + textColor.green + textColor.blue > 128 * 3)
			owner->SetHighColor(tint_color(textColor, B_DARKEN_1_TINT));
		else
			owner->SetHighColor(tint_color(textColor, B_LIGHTEN_1_TINT));
	} else {
		if (IsSelected())
			owner->SetHighColor(ui_color(B_LIST_SELECTED_ITEM_TEXT_COLOR));
		else
			owner->SetHighColor(ui_color(B_LIST_ITEM_TEXT_COLOR));
	}


	// icon
	owner->MovePenTo(frame.left + 4, frame.top + 1);
	owner->DrawBitmap(fIcon);

	// device
	owner->MovePenTo(frame.left + 8 + fIcon->Bounds().Width(),
		frame.top + fSecondBaselineOffset);
	owner->DrawString(fPath.Path());

	// name
	BFont boldFont;
	BFont ownerFont;
	owner->GetFont(&ownerFont);
	owner->GetFont(&boldFont);
	boldFont.SetFace(B_BOLD_FACE);
	owner->SetFont(&boldFont);

	BPoint namePosition(frame.left + 8 + fIcon->Bounds().Width(),
		frame.top + fBaselineOffset);

	owner->MovePenTo(namePosition);
	owner->DrawString(fName.String());

	float nameWidth = owner->StringWidth(fName.String());
	float messageWidth = frame.right - 4 - fSizeWidth
		- (frame.left + 8 + fIcon->Bounds().Width()) - nameWidth
		- fBaselineOffset * 2;

	if (fCanBeInstalled != B_OK) {
		rgb_color highColor = owner->HighColor();
		owner->SetHighColor(ui_color(B_FAILURE_COLOR));
		owner->MovePenBy(fBaselineOffset, 0);
		const char* message;
		switch (fCanBeInstalled) {
			case B_PARTITION_TOO_SMALL:
				message = B_TRANSLATE_COMMENT("No space available!",
					"Cannot install");
				break;
			case B_ENTRY_NOT_FOUND:
				message = B_TRANSLATE_COMMENT("Incompatible format!",
					"Cannot install");
				break;
			default:
				message = B_TRANSLATE_COMMENT("Cannot access!",
					"Cannot install");
				break;
		}
		BString truncatedMessage = message;
		owner->TruncateString(&truncatedMessage, B_TRUNCATE_END, messageWidth);
		owner->DrawString(truncatedMessage);
		owner->SetHighColor(highColor);
	}
	owner->SetFont(&ownerFont);
		// size
	BPoint sizePosition(frame.right - 4 - fSizeWidth,
		frame.top + fBaselineOffset);
	if (sizePosition.x > namePosition.x + nameWidth) {
		owner->MovePenTo(sizePosition);
		owner->DrawString(fSize.String());
	}

	owner->PopState();
}
开发者ID:AmirAbrams,项目名称:haiku,代码行数:98,代码来源:DrivesPage.cpp

示例3: GetSrcImage

void
Scaler::ScaleBilinear(intType fromRow, int32 toRow)
{
	BBitmap* src;
	BBitmap* dest;
	intType srcW, srcH;
	intType destW, destH;
	intType x, y, i;
	ColumnData* columnData;
	ColumnData* cd;
	const uchar* srcBits;
	uchar* destBits;
	intType srcBPR, destBPR;
	const uchar* srcData;
	uchar* destDataRow;
	uchar* destData;
	const int32 kBPP = 4;

	src = GetSrcImage();
	dest = fScaledImage;

	srcW = src->Bounds().IntegerWidth();
	srcH = src->Bounds().IntegerHeight();
	destW = dest->Bounds().IntegerWidth();
	destH = dest->Bounds().IntegerHeight();

	srcBits = (uchar*)src->Bits();
	destBits = (uchar*)dest->Bits();
	srcBPR = src->BytesPerRow();
	destBPR = dest->BytesPerRow();

	columnData = new ColumnData[destW];
	cd = columnData;
	for (i = 0; i < destW; i ++, cd++) {
		float column = (float)i * (float)srcW / (float)destW;
		cd->srcColumn = (intType)column;
		cd->alpha1 = column - cd->srcColumn;
		cd->alpha0 = 1.0 - cd->alpha1;
	}

	destDataRow = destBits + fromRow * destBPR;

	for (y = fromRow; IsRunning() && y <= toRow; y ++, destDataRow += destBPR) {
		float row;
		intType srcRow;
		float alpha0, alpha1;

		if (destH == 0) {
			row = 0;
		} else {
			row = (float)y * (float)srcH / (float)destH;
		}
		srcRow = (intType)row;
		alpha1 = row - srcRow;
		alpha0 = 1.0 - alpha1;

		srcData = srcBits + srcRow * srcBPR;
		destData = destDataRow;

		if (y < destH) {
			float a0, a1;
			const uchar *a, *b, *c, *d;

			for (x = 0; x < destW; x ++, destData += kBPP) {
				a = srcData + columnData[x].srcColumn * kBPP;
				b = a + kBPP;
				c = a + srcBPR;
				d = c + kBPP;

				a0 = columnData[x].alpha0;
				a1 = columnData[x].alpha1;

				destData[0] = static_cast<uchar>(
								(a[0] * a0 + b[0] * a1) * alpha0 +
								(c[0] * a0 + d[0] * a1) * alpha1);
				destData[1] = static_cast<uchar>(
								(a[1] * a0 + b[1] * a1) * alpha0 +
								(c[1] * a0 + d[1] * a1) * alpha1);
				destData[2] = static_cast<uchar>(
								(a[2] * a0 + b[2] * a1) * alpha0 +
								(c[2] * a0 + d[2] * a1) * alpha1);
				destData[3] = static_cast<uchar>(
								(a[3] * a0 + b[3] * a1) * alpha0 +
								(c[3] * a0 + d[3] * a1) * alpha1);
			}

			// right column
			a = srcData + srcW * kBPP;
			c = a + srcBPR;

			destData[0] = static_cast<uchar>(a[0] * alpha0 + c[0] * alpha1);
			destData[1] = static_cast<uchar>(a[1] * alpha0 + c[1] * alpha1);
			destData[2] = static_cast<uchar>(a[2] * alpha0 + c[2] * alpha1);
			destData[3] = static_cast<uchar>(a[3] * alpha0 + c[3] * alpha1);
		} else {
			float a0, a1;
			const uchar *a, *b;
			for (x = 0; x < destW; x ++, destData += kBPP) {
				a = srcData + columnData[x].srcColumn * kBPP;
				b = a + kBPP;
//.........这里部分代码省略.........
开发者ID:nielx,项目名称:haiku-serviceskit,代码行数:101,代码来源:Filter.cpp

示例4: GetDestImage

void
Scaler::Dither(int32 fromRow, int32 toRow)
{
	BBitmap* src;
	BBitmap* dest;
	intType destW, destH;
	intType x, y;

	uchar* srcBits;
	intType srcBPR;
	uchar* srcDataRow;
	uchar* srcData;

	uchar* destBits;
	intType destBPR;
	uchar* destDataRow;
	uchar* destData;
	const int32 kBPP = 4;
	DitheringColumnData* columnData0;
	DitheringColumnData* columnData;
	DitheringColumnData* cd;
	BScreen screen;
	intType error[3], err[3];
	
	src = fScaledImage;
	dest = GetDestImage();

	ASSERT(src->ColorSpace() == B_RGB32 || src->ColorSpace() == B_RGBA32);
	ASSERT(dest->ColorSpace() == B_CMAP8);
	ASSERT(src->Bounds().IntegerWidth() == dest->Bounds().IntegerWidth());
	ASSERT(src->Bounds().IntegerHeight() == dest->Bounds().IntegerHeight());
	
	destW = dest->Bounds().IntegerWidth();
	destH = dest->Bounds().IntegerHeight();
	
	srcBits = (uchar*)src->Bits();
	srcBPR = src->BytesPerRow();
	destBits = (uchar*)dest->Bits();
	destBPR = dest->BytesPerRow();
	
	// Allocate space for sentinel at left and right bounds,
	// so that columnData[-1] and columnData[destW+1] can be safely accessed
	columnData0 = new DitheringColumnData[destW+3];
	columnData = columnData0 + 1;
		
	// clear error
	cd = columnData;
	for (x = destW; x >= 0; x --, cd ++) {
		cd->error[0] = cd->error[1] = cd->error[2] =0;
	}

	srcDataRow = srcBits + fromRow * srcBPR;
	destDataRow = destBits + fromRow * destBPR;
	for (y = fromRow; IsRunning() && y <= toRow; y ++, srcDataRow += srcBPR, destDataRow += destBPR) {
		// left to right
		error[0] = error[1] = error[2] = 0;
		srcData = srcDataRow;
		destData = destDataRow;
		for (x = 0; x <= destW; x ++, srcData += kBPP, destData += 1) {
			rgb_color color, actualColor;
			uint8 index;
			
			color.red = Limit(srcData[2] + error[0] / 16);
			color.green = Limit(srcData[1] + error[1] / 16);
			color.blue = Limit(srcData[0] + error[2] / 16);
			
			index = screen.IndexForColor(color);
			actualColor = screen.ColorForIndex(index);
			
			*destData = index;
			
			err[0] = color.red - actualColor.red;
			err[1] = color.green -actualColor.green;
			err[2] = color.blue -actualColor.blue;
			
			// distribute error
			// get error for next pixel
			cd = &columnData[x+1];
			error[0] = cd->error[0] + 7 * err[0];
			error[1] = cd->error[1] + 7 * err[1];
			error[2] = cd->error[2] + 7 * err[2];
			
			// set error for right pixel below current pixel
			cd->error[0] = err[0];
			cd->error[1] = err[1];
			cd->error[2] = err[2];
			
			// add error for pixel below current pixel
			cd --;
			cd->error[0] += 5 * err[0];
			cd->error[1] += 5 * err[1];
			cd->error[2] += 5 * err[2];
			
			// add error for left pixel below current pixel
			cd --;
			cd->error[0] += 3 * err[0];
			cd->error[1] += 3 * err[1];
			cd->error[2] += 3 * err[2];
		}
		// Note: Alogrithm has good results with "left to right" already
//.........这里部分代码省略.........
开发者ID:threedeyes,项目名称:DjVuViewer,代码行数:101,代码来源:Filter.cpp

示例5: msg

// InitiateDrag
bool
DragSortableListView::InitiateDrag(BPoint point, int32 index, bool)
{
	// supress drag&drop while an item is focused
	if (fFocusedIndex >= 0)
		return false;

	bool success = false;
	BListItem* item = ItemAt(CurrentSelection(0));
	if (!item) {
		// workarround a timing problem
		Select(index);
		item = ItemAt(index);
	}
	if (item) {
		// create drag message
		BMessage msg(fDragCommand);
		MakeDragMessage(&msg);
		// figure out drag rect
		float width = Bounds().Width();
		BRect dragRect(0.0, 0.0, width, -1.0);
		// figure out, how many items fit into our bitmap
		int32 numItems;
		bool fade = false;
		for (numItems = 0; BListItem* item = ItemAt(CurrentSelection(numItems)); numItems++) {
			dragRect.bottom += ceilf(item->Height()) + 1.0;
			if (dragRect.Height() > MAX_DRAG_HEIGHT) {
				fade = true;
				dragRect.bottom = MAX_DRAG_HEIGHT;
				numItems++;
				break;
			}
		}
		BBitmap* dragBitmap = new BBitmap(dragRect, B_RGB32, true);
		if (dragBitmap && dragBitmap->IsValid()) {
			if (BView *v = new BView(dragBitmap->Bounds(), "helper",
									 B_FOLLOW_NONE, B_WILL_DRAW)) {
				dragBitmap->AddChild(v);
				dragBitmap->Lock();
				BRect itemBounds(dragRect) ;
				itemBounds.bottom = 0.0;
				// let all selected items, that fit into our drag_bitmap, draw
				for (int32 i = 0; i < numItems; i++) {
					int32 index = CurrentSelection(i);
					BListItem* item = ItemAt(index);
					itemBounds.bottom = itemBounds.top + ceilf(item->Height());
					if (itemBounds.bottom > dragRect.bottom)
						itemBounds.bottom = dragRect.bottom;
					DrawListItem(v, index, itemBounds);
					itemBounds.top = itemBounds.bottom + 1.0;
				}
				// make a black frame arround the edge
				v->SetHighColor(0, 0, 0, 255);
				v->StrokeRect(v->Bounds());
				v->Sync();
	
				uint8 *bits = (uint8 *)dragBitmap->Bits();
				int32 height = (int32)dragBitmap->Bounds().Height() + 1;
				int32 width = (int32)dragBitmap->Bounds().Width() + 1;
				int32 bpr = dragBitmap->BytesPerRow();
	
				if (fade) {
					for (int32 y = 0; y < height - ALPHA / 2; y++, bits += bpr) {
						uint8 *line = bits + 3;
						for (uint8 *end = line + 4 * width; line < end; line += 4)
							*line = ALPHA;
					}
					for (int32 y = height - ALPHA / 2; y < height; y++, bits += bpr) {
						uint8 *line = bits + 3;
						for (uint8 *end = line + 4 * width; line < end; line += 4)
							*line = (height - y) << 1;
					}
				} else {
					for (int32 y = 0; y < height; y++, bits += bpr) {
						uint8 *line = bits + 3;
						for (uint8 *end = line + 4 * width; line < end; line += 4)
							*line = ALPHA;
					}
				}
				dragBitmap->Unlock();
			}
		} else {
			delete dragBitmap;
			dragBitmap = NULL;
		}
		if (dragBitmap)
			DragMessage(&msg, dragBitmap, B_OP_ALPHA, BPoint(0.0, 0.0));
		else
			DragMessage(&msg, dragRect.OffsetToCopy(point), this);

		_SetDragMessage(&msg);
		success = true;
	}
	return success;
}
开发者ID:DonCN,项目名称:haiku,代码行数:96,代码来源:ListViews.cpp

示例6: reply

void
RemoteView::_DrawThread()
{
	RemoteMessage reply(NULL, fSendBuffer);
	RemoteMessage message(fReceiveBuffer, NULL);

	// cursor
	BPoint cursorHotSpot(0, 0);

	while (!fStopThread) {
		uint16 code;
		status_t status = message.NextMessage(code);
		if (status != B_OK) {
			TRACE_ERROR("failed to read message from receiver\n");
			break;
		}

		TRACE("code %u with %ld bytes data\n", code, message.DataLeft());

		BAutolock locker(this->Looper());
		if (!locker.IsLocked())
			break;

		// handle stuff that doesn't go to a specicifc engine
		switch (code) {
			case RP_INIT_CONNECTION:
			{
				uint16 port;
				status_t result = message.Read(port);
				if (result != B_OK) {
					TRACE_ERROR("failed to read remote port\n");
					continue;
				}

				BNetEndpoint *endpoint = fReceiver->Endpoint();
				if (endpoint == NULL) {
					TRACE_ERROR("receiver not connected anymore\n");
					continue;
				}

				in_addr remoteHost;
				char hostName[MAXHOSTNAMELEN + 1];
				BNetAddress address(endpoint->RemoteAddr());
				address.GetAddr(remoteHost);
				address.GetAddr(hostName, NULL);
				address.SetTo(remoteHost, port);

				TRACE("connecting to host \"%s\" port %u\n", hostName, port);
				result = fSendEndpoint->Connect(address);
				if (result != B_OK) {
					TRACE_ERROR("failed to connect to host \"%s\" port %u\n",
						hostName, port);
					continue;
				}

				BRect bounds = fOffscreenBitmap->Bounds();
				reply.Start(RP_UPDATE_DISPLAY_MODE);
				reply.Add(bounds.IntegerWidth() + 1);
				reply.Add(bounds.IntegerHeight() + 1);
				if (reply.Flush() == B_OK)
					fIsConnected = true;

				continue;
			}

			case RP_CLOSE_CONNECTION:
			{
				be_app->PostMessage(B_QUIT_REQUESTED);
				continue;
			}

			case RP_CREATE_STATE:
			case RP_DELETE_STATE:
			{
				uint32 token;
				message.Read(token);

				if (code == RP_CREATE_STATE)
					_CreateState(token);
				else
					_DeleteState(token);

				continue;
			}

			case RP_SET_CURSOR:
			{
				BBitmap *bitmap;
				BPoint oldHotSpot = cursorHotSpot;
				message.Read(cursorHotSpot);
				if (message.ReadBitmap(&bitmap) != B_OK)
					continue;

				delete fCursorBitmap;
				fCursorBitmap = bitmap;

				Invalidate(fCursorFrame);

				BRect bounds = fCursorBitmap->Bounds();
				fCursorFrame.right = fCursorFrame.left
//.........这里部分代码省略.........
开发者ID:veer77,项目名称:Haiku-services-branch,代码行数:101,代码来源:RemoteView.cpp

示例7: ClipRenderer

// constructor
BitmapRenderer::BitmapRenderer(ClipPlaylistItem* item,
		BitmapClip* bitmapClip, color_space renderFormat)
	: ClipRenderer(item, bitmapClip)
	, fClip(bitmapClip)
	, fBuffer(NULL)
	, fFadeMode(fClip ? fClip->FadeMode() : FADE_MODE_ALPHA)
{
	if (!fClip)
		return;
	BBitmap* bitmap = NULL;
	try {
		bitmap = BTranslationUtils::GetBitmap(fClip->Ref());
	} catch (...) {
		return;
	}

	ObjectDeleter<BBitmap> bitmapDeleter(bitmap);

	if (!bitmap || bitmap->InitCheck() < B_OK)
		return;

	pixel_format format = (pixel_format)bitmap->ColorSpace();
	uint32 width = bitmap->Bounds().IntegerWidth() + 1;
	uint32 height = bitmap->Bounds().IntegerHeight() + 1;
	uint32 bpr = bitmap->BytesPerRow();

	// NOTE: YCbCr422 is not directly supported, Painter knows
	// how to render both, if the format is either 422 or 444
	if ((pixel_format)renderFormat == YCbCr444
		|| (pixel_format)renderFormat == YCbCr422) {
		if (bitmap->ColorSpace() == B_RGBA32) {
			// we need an alpha channel
			format = YCbCrA;
			bpr = width * 4;
		} else {
			format = YCbCr444;
			bpr = ((width * 3 + 3) / 4) * 4;
		}
	}

	// see if the alpha channel is used at all
	uint8* src = (uint8*)bitmap->Bits();
	uint32 srcBPR = bitmap->BytesPerRow();


	if ((pixel_format)bitmap->ColorSpace() == BGRA32) {
		bool hasAlpha = false;
		for (uint32 y = 0; y < height; y++) {
			uint8* s = src;
			for (uint32 x = 0; x < width; x++) {
				if (s[3] < 255) {
					hasAlpha = true;
					break;
				}
				s += 4;
			}
			src += srcBPR;
		}
		// override target format by removing superfluous alpha channel
		if (!hasAlpha) {
			if (format == YCbCrA) {
				format = YCbCr444;
				bpr = ((width * 3 + 3) / 4) * 4;
			} else {
				format = BGR32;
			}
		}
	}

	fBuffer = new (nothrow) MemoryBuffer(width, height, format, bpr);

	status_t ret = fBuffer ? fBuffer->InitCheck() : B_NO_MEMORY;
	if (ret < B_OK) {
		printf("BitmapRenderer() - failed to create buffer: %s\n",
			   strerror(ret));
		return;
	}

	if (((pixel_format)bitmap->ColorSpace() == BGR32
		 || (pixel_format)bitmap->ColorSpace() == BGRA32)
		&& (format == BGR32 || format == BGRA32)) {
		// copy contents of the bitmap
		uint32 bytes = min_c(srcBPR, bpr);
		src = (uint8*)bitmap->Bits();
		uint8* dst = (uint8*)fBuffer->Bits();
		if (format == BGR32 && (pixel_format)bitmap->ColorSpace() == format) {
			for (uint32 i = 0; i < height; i++) {
				memcpy(dst, src, bytes);
				dst += bpr;
				src += srcBPR;
			}
		} else {
			for (uint32 y = 0; y < height; y++) {
				uint8* d = dst;
				uint8* s = src;
				if ((pixel_format)bitmap->ColorSpace() == BGRA32) {
					// bitmap has alpha channel, pre-multiply
					for (uint32 x = 0; x < width; x++) {
						if (s[3] < 255) {
//.........这里部分代码省略.........
开发者ID:stippi,项目名称:Clockwerk,代码行数:101,代码来源:BitmapRenderer.cpp

示例8: rect

PrinterItem::PrinterItem(PrintersWindow* window, const BDirectory& node,
		PrinterListLayoutData& layoutData)
	: BListItem(0, false),
	fFolder(NULL),
	fNode(node),
	fLayoutData(layoutData)
{
	BRect rect(0, 0, B_LARGE_ICON - 1, B_LARGE_ICON - 1);
	if (sIcon == NULL) {
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
		sIcon = new BBitmap(rect, B_RGBA32);
#else
		sIcon = new BBitmap(rect, B_CMAP8);
#endif
		BMimeType type(PSRV_PRINTER_FILETYPE);
		type.GetIcon(sIcon, B_LARGE_ICON);
	}

	if (sIcon && sIcon->IsValid() && sSelectedIcon == NULL) {
		const float checkMarkIconSize = 20.0;
		BBitmap *checkMark = _LoadVectorIcon("check_mark_icon",
			checkMarkIconSize);
		if (checkMark && checkMark->IsValid()) {
			sSelectedIcon = new BBitmap(rect, B_RGBA32, true);
			if (sSelectedIcon && sSelectedIcon->IsValid()) {
				// draw check mark at bottom left over printer icon
				BView *view = new BView(rect, "offscreen", B_FOLLOW_ALL,
					B_WILL_DRAW);
				float y = rect.Height() - checkMark->Bounds().Height();
				sSelectedIcon->Lock();
				sSelectedIcon->AddChild(view);
				view->DrawBitmap(sIcon);
				view->SetDrawingMode(B_OP_ALPHA);
				view->DrawBitmap(checkMark, BPoint(0, y));
				view->Sync();
				view->RemoveSelf();
				sSelectedIcon->Unlock();
				delete view;
			}
		}
		delete checkMark;
	}

	// Get Name of printer
	_GetStringProperty(PSRV_PRINTER_ATTR_PRT_NAME, fName);
	_GetStringProperty(PSRV_PRINTER_ATTR_COMMENTS, fComments);
	_GetStringProperty(PSRV_PRINTER_ATTR_TRANSPORT, fTransport);
	_GetStringProperty(PSRV_PRINTER_ATTR_TRANSPORT_ADDR, fTransportAddress);
	_GetStringProperty(PSRV_PRINTER_ATTR_DRV_NAME, fDriverName);

	BPath path;
	if (find_directory(B_USER_PRINTERS_DIRECTORY, &path) != B_OK)
		return;

	// Setup spool folder
	path.Append(fName.String());
	BDirectory dir(path.Path());
	if (dir.InitCheck() == B_OK) {
		fFolder = new SpoolFolder(window, this, dir);
		UpdatePendingJobs();
	}
}
开发者ID:AmirAbrams,项目名称:haiku,代码行数:62,代码来源:PrinterListView.cpp

示例9: locker

void
ImageView::_UpdateImage()
{
	// ToDo: add scroller if necessary?!

	BAutolock locker(fEditor);

	// we need all the data...

	size_t viewSize = fEditor.ViewSize();
	// that may need some more memory...
	if ((off_t)viewSize < fEditor.FileSize())
		fEditor.SetViewSize(fEditor.FileSize());

	const char *data;
	if (fEditor.GetViewBuffer((const uint8 **)&data) != B_OK) {
		fEditor.SetViewSize(viewSize);
		return;
	}

	if (fBitmap != NULL && (fEditor.Type() == B_MINI_ICON_TYPE
			|| fEditor.Type() == B_LARGE_ICON_TYPE)) {
		// optimize icon update...
		fBitmap->SetBits(data, fEditor.FileSize(), 0, B_CMAP8);
		fEditor.SetViewSize(viewSize);
		return;
	}
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
	if (fBitmap != NULL && fEditor.Type() == B_VECTOR_ICON_TYPE
		&& fScaleSlider->Value() * 8 - 1 == fBitmap->Bounds().Width()) {
		if (BIconUtils::GetVectorIcon((const uint8 *)data,
				(size_t)fEditor.FileSize(), fBitmap) == B_OK) {
			fEditor.SetViewSize(viewSize);
			return;
		}
	}
#endif

	delete fBitmap;
	fBitmap = NULL;

	switch (fEditor.Type()) {
		case B_MINI_ICON_TYPE:
			fBitmap = new BBitmap(BRect(0, 0, 15, 15), B_CMAP8);
			if (fBitmap->InitCheck() == B_OK)
				fBitmap->SetBits(data, fEditor.FileSize(), 0, B_CMAP8);
			break;
		case B_LARGE_ICON_TYPE:
			fBitmap = new BBitmap(BRect(0, 0, 31, 31), B_CMAP8);
			if (fBitmap->InitCheck() == B_OK)
				fBitmap->SetBits(data, fEditor.FileSize(), 0, B_CMAP8);
			break;
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
		case B_VECTOR_ICON_TYPE:
			fBitmap = new BBitmap(BRect(0, 0, fScaleSlider->Value() * 8 - 1,
				fScaleSlider->Value() * 8 - 1), B_RGB32);
			if (fBitmap->InitCheck() != B_OK
				|| BIconUtils::GetVectorIcon((const uint8 *)data,
					(size_t)fEditor.FileSize(), fBitmap) != B_OK) {
				delete fBitmap;
				fBitmap = NULL;
			}
			break;
#endif
		case B_PNG_FORMAT:
		{
			BMemoryIO stream(data, fEditor.FileSize());
			fBitmap = BTranslationUtils::GetBitmap(&stream);
			break;
		}
		case B_MESSAGE_TYPE:
		{
			BMessage message;
			// ToDo: this could be problematic if the data is not large
			//		enough to contain the message...
			if (message.Unflatten(data) == B_OK)
				fBitmap = new BBitmap(&message);
			break;
		}
	}

	// Update the bitmap description. If no image can be displayed,
	// we will show our "unsupported" message

	if (fBitmap != NULL && fBitmap->InitCheck() != B_OK) {
		delete fBitmap;
		fBitmap = NULL;
	}

	if (fBitmap != NULL) {
		char buffer[256];
		const char *type = B_TRANSLATE("Unknown type");
		switch (fEditor.Type()) {
			case B_MINI_ICON_TYPE:
			case B_LARGE_ICON_TYPE:
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
			case B_VECTOR_ICON_TYPE:
#endif
				type = B_TRANSLATE("Icon");
				break;
//.........这里部分代码省略.........
开发者ID:DonCN,项目名称:haiku,代码行数:101,代码来源:TypeEditors.cpp

示例10: resFile

BBitmap *RBitmapLoader::LoadIcon(const char *name)
{
	// Init App 
	ASSERT(name);
	if (!initied) init();

	// try to load image from ressource
	BBitmap *mIcon = 0;
	app_info info;
	be_app->GetAppInfo(&info);
	BFile resFile(&info.ref, B_READ_WRITE);
	if (resFile.InitCheck() == B_NO_ERROR)
	{
		BResources res(&resFile);
		int32 idFound;
		size_t size;
		if (res.GetResourceInfo('ICCN', name, &idFound, &size))
		{
			// ressource exist, load it into a buffer
			char *image_data = new char[size];
            ASSERT(image_data);
			if (res.ReadResource('ICCN', idFound, image_data, 0, size) == B_NO_ERROR)
			{
				float *p = (float*)image_data;
				mIcon = new BBitmap(BRect(p[0], p[1], p[2], p[3]), B_RGB32, false, true);
				GetIcon(mIcon, image_data + 4 * sizeof(float), p[2] - p[0], p[3] - p[1]);
			}
			// delete buffer
			delete image_data;
		}
	}

	if (!mIcon)
	{
		printf("Loading into resource %s\n",name);
		// if not in ressource, load from file and copy into ressources
		
		mIcon = TranslateIcon(0, name);		
		if (!mIcon) return 0;

		// try to put into ressource
		if (resFile.InitCheck() == B_NO_ERROR)
		{
			BResources res(&resFile);
			size_t image_size = 4 * sizeof(float) + mIcon->BitsLength();
			char *image_data = new char[image_size];
			float *p = (float*) image_data;
			BRect b = mIcon->Bounds();
			p[0] = b.left;
			p[1] = b.top; 
			p[2] = b.right;
			p[3] = b.bottom;
			SetIcon(mIcon, image_data + 4 * sizeof(float), p[2] - p[0], p[3] - p[1]);
			
			if (res.AddResource('ICCN',  g_current_id , image_data, image_size, name)==B_OK)
			{
				g_current_id++;
			}
			delete image_data;
			res.Sync();
		}
	}
	return mIcon;
} 
开发者ID:HaikuArchives,项目名称:WinRC2Be,代码行数:64,代码来源:RBitmapLoader.cpp

示例11: locker

static cairo_int_status_t
_cairo_beos_surface_composite (cairo_operator_t		op,
			       cairo_pattern_t	       *src,
			       cairo_pattern_t	       *mask,
			       void		       *dst,
			       int		 	src_x,
			       int			src_y,
			       int			mask_x,
			       int			mask_y,
			       int			dst_x,
			       int			dst_y,
			       unsigned int		width,
			       unsigned int		height)
{
    cairo_beos_surface_t *surface = reinterpret_cast<cairo_beos_surface_t*>(
							dst);
    AutoLockView locker(surface->view);
    if (!locker)
	return CAIRO_INT_STATUS_SUCCESS;

    drawing_mode mode;
    if (!_cairo_op_to_be_op(op, &mode))
	return CAIRO_INT_STATUS_UNSUPPORTED;

    // XXX Masks are not yet supported
    if (mask)
	return CAIRO_INT_STATUS_UNSUPPORTED;

    // XXX should eventually support the others
    if (src->type != CAIRO_PATTERN_TYPE_SURFACE ||
	src->extend != CAIRO_EXTEND_NONE)
    {
	return CAIRO_INT_STATUS_UNSUPPORTED;
    }

    // Can we maybe support other matrices as well? (scale? if the filter is right)
    int itx, ity;
    if (!_cairo_matrix_is_integer_translation(&src->matrix, &itx, &ity))
	return CAIRO_INT_STATUS_UNSUPPORTED;

    BRect srcRect(src_x + itx,
		  src_y + ity,
		  src_x + itx + width - 1,
		  src_y + ity + height - 1);
    BRect dstRect(dst_x, dst_y, dst_x + width - 1, dst_y + height - 1);

    cairo_surface_t* src_surface = reinterpret_cast<cairo_surface_pattern_t*>(src)->
					surface;

    // Get a bitmap
    BBitmap* bmp = NULL;
    bool free_bmp = false;
    if (_cairo_surface_is_image(src_surface)) {
	cairo_image_surface_t* img_surface =
	    reinterpret_cast<cairo_image_surface_t*>(src_surface);

	bmp = _cairo_image_surface_to_bitmap(img_surface);
	free_bmp = true;
    } else if (src_surface->backend == surface->base.backend) {
	cairo_beos_surface_t *beos_surface =
	    reinterpret_cast<cairo_beos_surface_t*>(src_surface);
	if (beos_surface->bitmap) {
	    AutoLockView locker(beos_surface->view);
	    if (locker)
		beos_surface->view->Sync();
	    bmp = beos_surface->bitmap;
	} else {
	    _cairo_beos_view_to_bitmap(surface->view, &bmp);
	    free_bmp = true;
	}
    }

    if (!bmp)
	return CAIRO_INT_STATUS_UNSUPPORTED;

    // So, BeOS seems to screw up painting an opaque bitmap onto a
    // translucent one (it makes them partly transparent). Just return
    // unsupported.
    if (bmp->ColorSpace() == B_RGB32 && surface->bitmap &&
	surface->bitmap->ColorSpace() == B_RGBA32 &&
	(mode == B_OP_COPY || mode == B_OP_ALPHA))
    {
	if (free_bmp)
	    delete bmp;
	return CAIRO_INT_STATUS_UNSUPPORTED;
    }

    fprintf(stderr, "Composite\n");

    // Draw it on screen.
    surface->view->PushState();

	// If our image rect is only a subrect of the desired size, and we
	// aren't using B_OP_ALPHA, then we need to fill the rect first.
	if (mode == B_OP_COPY && !bmp->Bounds().Contains(srcRect)) {
	    rgb_color black = { 0, 0, 0, 0 };

	    surface->view->SetDrawingMode(mode);
	    surface->view->SetHighColor(black);
	    surface->view->FillRect(dstRect);
//.........这里部分代码省略.........
开发者ID:hideakihata,项目名称:mozilla-central.fgv,代码行数:101,代码来源:cairo-beos-surface.cpp

示例12: ToolScript

ToolScript*
TransparencyTool::UseTool(ImageView* view, uint32 buttons, BPoint point, BPoint)
{
	// Wait for the last_updated_region to become empty
	while (LastUpdatedRect().IsValid())
		snooze(50000);

	BWindow* window = view->Window();
	BBitmap* bitmap = view->ReturnImage()->ReturnActiveBitmap();

	ToolScript* the_script = new ToolScript(Type(), fToolSettings,
		((PaintApplication*)be_app)->Color(true));

	BRect bounds = bitmap->Bounds();
	uint32* bits_origin = (uint32*)bitmap->Bits();
	int32 bpr = bitmap->BytesPerRow() / 4;

	// for the quick calculation of square-roots
	float sqrt_table[5500];
	for (int32 i=0;i<5500;i++)
		sqrt_table[i] = sqrt(i);

	float half_size = fToolSettings.size/2;
	BRect rc = BRect(floor(point.x - half_size), floor(point.y - half_size),
		ceil(point.x + half_size), ceil(point.y + half_size));
	rc = rc & bounds;
	SetLastUpdatedRect(rc);

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

	while (buttons) {
		the_script->AddPoint(point);
		uint32 transparency_value = ((PaintApplication*)be_app)->Color(true).alpha;
		int32 x_dist,y_sqr;

		int32 width = rc.IntegerWidth();
		int32 height = rc.IntegerHeight();
		for (int32 y=0;y<height+1;y++) {
			y_sqr = (int32)(point.y - rc.top - y);
			y_sqr *= y_sqr;
			int32 real_y = (int32)(rc.top + y);
			int32 real_x;
			for (int32 x=0;x<width+1;x++) {
				x_dist = (int32)(point.x-rc.left-x);
				real_x = (int32)(rc.left+x);
				if (sqrt_table[x_dist*x_dist + y_sqr] <= half_size) {
//					for (int32 i=0;i<(float)GetCurrentValue(PRESSURE_OPTION)/4.0;i++) {
						color.word = *(bits_origin + real_y*bpr + real_x);
						if (color.bytes[3] < transparency_value) {
							color.bytes[3] = (uint8)min_c(color.bytes[3] +
								GetCurrentValue(PRESSURE_OPTION)/4.0,transparency_value);
							*(bits_origin + real_y*bpr + real_x) = color.word;
						} else if (color.bytes[3] > transparency_value) {
							color.bytes[3] = (uint8)max_c(color.bytes[3] -
								GetCurrentValue(PRESSURE_OPTION)/4.0,transparency_value);
							*(bits_origin + real_y*bpr + real_x) = color.word;
						}
//					}
				}
			}
		}

		if (rc.IsValid()) {
			window->Lock();
			view->UpdateImage(rc);
			view->Sync();
			view->getCoords(&point,&buttons);
			window->Unlock();
			half_size = fToolSettings.size/2;
			rc = BRect(floor(point.x - half_size), floor(point.y - half_size),
				ceil(point.x + half_size), ceil(point.y + half_size));
			rc = rc & bounds;
			SetLastUpdatedRect(LastUpdatedRect() | rc);
			//snooze(20.0 * 1000.0);
		} else {
			window->Lock();
			view->getCoords(&point,&buttons);
			window->Unlock();
			half_size = fToolSettings.size/2;
			rc = BRect(floor(point.x - half_size), floor(point.y - half_size),
				ceil(point.x + half_size), ceil(point.y + half_size));
			rc = rc & bounds;
			SetLastUpdatedRect(LastUpdatedRect() | rc);
			snooze(20 * 1000);
		}
	}

	view->ReturnImage()->Render(rc);
	window->Lock();
	view->Draw(view->convertBitmapRectToView(rc));
	SetLastUpdatedRect(LastUpdatedRect() | rc);	// ???
	window->Unlock();

	return the_script;
}
开发者ID:HaikuArchives,项目名称:ArtPaint,代码行数:98,代码来源:TransparencyTool.cpp

示例13:

BBitmap *TutGLView::LoadTexture( const char *tex_name )
{
	// NOTE: This replaces auxDIBImageLoad() in the original!
	BBitmap *bits = BTranslationUtils::GetBitmap( tex_name );
	if( !bits ) return bits;

	// We'll only deal with 32-bit textures, because we're lazy.
	// If you're not lazy, you could convert the bitmap here, or
	// add more colour space handlers below where we make the texture
	// with glTexImage2D().
	if( bits->ColorSpace() != B_RGBA32 && bits->ColorSpace() != B_RGB32 ) {
    	delete bits;
    	return NULL;
    }

	// BeOS bitmaps have 0,0 in the top-left; OpenGL expects them in the
	// lower-left.  Dang.
	//
	// Note that this isn't going to behave if you've got an odd number of
	// rows in the bitmap.  Then again, you won't be able to use that as an
	// OpenGL texture.
	bits->Lock();

	int32 bpr = bits->BytesPerRow();

	char *top = static_cast<char *>( bits->Bits() );
	char *bottom = top + bits->Bounds().IntegerHeight() * bpr;

	char *tmp_bytes = new char[bpr];
	while( top < bottom ) {
		// Save a line into the temp buffer.
		memcpy( tmp_bytes, bottom, bpr );

#if 0
		// The way we'd like to do it:
		memcpy( bottom, top, bpr );
		memcpy( top, tmp_bytes, bpr );
#else
		// The way we have to do it.  Why?  BBitmap and OpenGL don't
		// even agree on the order of bytes within an RGBA colour.  :-(
		rgb_color *b = (rgb_color *)( bottom );
		rgb_color *t = (rgb_color *)( top );
		for( int i = 0; i < ( bpr / 4 ); i++ ) {
			b->red = t->blue;
			b->green = t->green;
			b->blue = t->red;
			b->alpha = t->alpha;
			b++, t++;
		}
		t = (rgb_color *)( top );
		b = (rgb_color *)( tmp_bytes );
		for( int i = 0; i < ( bpr / 4 ); i++ ) {
			t->red = b->blue;
			t->green = b->green;
			t->blue = b->red;
			t->alpha = b->alpha;
			b++, t++;
		}
#endif
		bottom -= bpr;
		top += bpr;
	}

	bits->Unlock();

	return bits;
}
开发者ID:zzzzzzzzz,项目名称:Organizer,代码行数:67,代码来源:glView.cpp

示例14: message

bool
AudioListView::InitiateDrag(BPoint point, int32 dragIndex, bool)
{
	BListItem* item = ItemAt(CurrentSelection(0));
	if (item == NULL) {
		// workaround for a timing problem (see Locale prefs)
		Select(dragIndex);
		item = ItemAt(dragIndex);
	}
	if (item == NULL)
		return false;

	// create drag message
	BMessage message(kDraggedItem);
	for (int32 i = 0;; i++) {
		int32 index = CurrentSelection(i);
		if (index < 0)
			break;
		message.AddPointer("trackitem", ItemAt(CurrentSelection(i)));
	}

	// figure out drag rect
	BRect dragRect(0.0, 0.0, Bounds().Width(), -1.0);

	// figure out, how many items fit into our bitmap
	bool fade = false;

	for (int32 i = 0; message.FindPointer("trackitem", i,
		reinterpret_cast<void**>(&item)) == B_OK; i++) {

		dragRect.bottom += ceilf(item->Height()) + 1.0;

		if (dragRect.Height() > MAX_DRAG_HEIGHT) {
			dragRect.bottom = MAX_DRAG_HEIGHT;
			fade = true;
			break;
		}
	}

	BBitmap* dragBitmap = new BBitmap(dragRect, B_RGB32, true);
	if (dragBitmap->IsValid()) {
		BView* view = new BView(dragBitmap->Bounds(), "helper", B_FOLLOW_NONE,
			B_WILL_DRAW);
		dragBitmap->AddChild(view);
		dragBitmap->Lock();
		BRect itemBounds(dragRect) ;
		itemBounds.bottom = 0.0;
		// let all selected items, that fit into our drag_bitmap, draw
		for (int32 i = 0; message.FindPointer("trackitem", i,
				reinterpret_cast<void**>(&item)) == B_OK; i++) {
			AudioListItem* item;
			message.FindPointer("trackitem", i,
				reinterpret_cast<void**>(&item));
			itemBounds.bottom = itemBounds.top + ceilf(item->Height());
			if (itemBounds.bottom > dragRect.bottom)
				itemBounds.bottom = dragRect.bottom;
			item->DrawItem(view, itemBounds);
			itemBounds.top = itemBounds.bottom + 1.0;
		}
		// make a black frame around the edge
		view->SetHighColor(0, 0, 0, 255);
		view->StrokeRect(view->Bounds());
		view->Sync();

		uint8* bits = (uint8*)dragBitmap->Bits();
		int32 height = (int32)dragBitmap->Bounds().Height() + 1;
		int32 width = (int32)dragBitmap->Bounds().Width() + 1;
		int32 bpr = dragBitmap->BytesPerRow();

		if (fade) {
			for (int32 y = 0; y < height - ALPHA / 2; y++, bits += bpr) {
				uint8* line = bits + 3;
				for (uint8* end = line + 4 * width; line < end; line += 4)
					*line = ALPHA;
			}
			for (int32 y = height - ALPHA / 2; y < height;
				y++, bits += bpr) {
				uint8* line = bits + 3;
				for (uint8* end = line + 4 * width; line < end; line += 4)
					*line = (height - y) << 1;
			}
		} else {
			for (int32 y = 0; y < height; y++, bits += bpr) {
				uint8* line = bits + 3;
				for (uint8* end = line + 4 * width; line < end; line += 4)
					*line = ALPHA;
			}
		}
		dragBitmap->Unlock();
	} else {
		delete dragBitmap;
		dragBitmap = NULL;
	}

	if (dragBitmap != NULL)
		DragMessage(&message, dragBitmap, B_OP_ALPHA, BPoint(0.0, 0.0));
	else
		DragMessage(&message, dragRect.OffsetToCopy(point), this);

	return true;
//.........这里部分代码省略.........
开发者ID:HaikuArchives,项目名称:BurnItNow,代码行数:101,代码来源:AudioList.cpp

示例15: screen

void
SLoadingModulesView::ReGetBitmap()
{
	BWindow *window = Window();
	if(!window) return;

	bool is_hidden = window->IsHidden();

	if(!is_hidden) window->Hide();

	BScreen screen(window);
	BBitmap *screen_bitmap = NULL;
	BRect rect = screen.Frame().OffsetToCopy(B_ORIGIN);
	if(screen.GetBitmap(&screen_bitmap, false, &rect) == B_OK)
	{
		if(screen_bitmap)
		{
			if(bitmap) delete bitmap;
			rect = ConvertToScreen(Bounds());
			bitmap = new BBitmap(rect.OffsetToCopy(B_ORIGIN), B_BITMAP_ACCEPTS_VIEWS, B_RGB32);
			if(bitmap)
			{
				SAutolock<BBitmap> autolock(bitmap);
				BView *bitmap_view = new BView(bitmap->Bounds(), NULL, B_FOLLOW_NONE, B_WILL_DRAW);
				bitmap->AddChild(bitmap_view);
				bitmap_view->PushState();
				bitmap_view->SetDrawingMode(B_OP_COPY);
				bitmap_view->DrawBitmap(screen_bitmap, rect, rect.OffsetToCopy(B_ORIGIN));
				bitmap_view->SetDrawingMode(B_OP_ALPHA);

				BPoint circle_center;
				float circle_radius = bitmap->Bounds().Height() / 2;
				circle_center.x = bitmap->Bounds().left + circle_radius;
				circle_center.y = bitmap->Bounds().top + circle_radius;
				
				bitmap_view->SetHighColor(ViewColor());
				bitmap_view->FillArc(circle_center, circle_radius, circle_radius, 0, 360);
				bitmap_view->SetHighColor(220, 220, 220, 150);
				bitmap_view->StrokeArc(circle_center, circle_radius, circle_radius, 45, 180);
				bitmap_view->SetHighColor(20, 20, 20, 150);
				bitmap_view->StrokeArc(circle_center, circle_radius, circle_radius, 225, 180);

				BRect rect = bitmap->Bounds();
				rect.left = circle_center.x;
				rect.InsetBy(0, 5);

				bitmap_view->SetHighColor(ViewColor());
				bitmap_view->FillRoundRect(rect, 3, 3);
				bitmap_view->SetHighColor(220, 220, 220, 150);
				bitmap_view->StrokeRoundRect(rect, 3, 3);
				bitmap_view->SetHighColor(20, 20, 20, 150);
				rect.left += 1; rect.top += 1;
				bitmap_view->StrokeRoundRect(rect, 3, 3);
				rect.right -= 1; rect.bottom -= 1;
				bitmap_view->SetHighColor(ViewColor());
				bitmap_view->FillArc(circle_center, circle_radius - 1, circle_radius - 1, 0, 360);
				bitmap_view->FillRoundRect(rect, 3, 3);

				bitmap_view->PopState();
				bitmap_view->Sync();
			}
			delete screen_bitmap;
		}
	}

	if(!is_hidden) window->Show();
}
开发者ID:Haiku-cn,项目名称:BeCJK,代码行数:67,代码来源:LoadingModules.cpp


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