コード例 #1
0
ファイル: VolumeSlider.cpp プロジェクト: mmanley/Antares
// constructor
VolumeSlider::VolumeSlider(BRect frame, const char* name,
						   int32 minValue, int32 maxValue,
						   BMessage* message, BHandler* target)
	: BControl(frame, name, NULL, message, B_FOLLOW_LEFT | B_FOLLOW_TOP,
			   B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE),
	  fLeftSideBits(NULL),
	  fRightSideBits(NULL),
	  fKnobBits(NULL),
	  fTracking(false),
	  fMuted(false),
	  fMinValue(minValue),
	  fMaxValue(maxValue)
{
	SetTarget(target);

	// create bitmaps
	BRect r(0.0, 0.0,
			kVolumeSliderBitmapWidth - 1, kVolumeSliderBitmapHeight - 1);
	fLeftSideBits = new BBitmap(r, B_CMAP8);
	fRightSideBits = new BBitmap(r, B_CMAP8);
	r.Set(0.0, 0.0,
		  kVolumeSliderKnobWidth - 1, kVolumeSliderKnobHeight - 1);
	fKnobBits = new BBitmap(r, B_CMAP8);

	_MakeBitmaps();
}
コード例 #2
0
ファイル: IconButton.cpp プロジェクト: Barrett17/Faber
status_t
BIconButton::SetIcon(const BMimeType* fileType, bool small)
{
	status_t status = fileType ? fileType->InitCheck() : B_BAD_VALUE;
	if (status >= B_OK) {
		BBitmap* mimeBitmap = new(std::nothrow) BBitmap(BRect(0.0, 0.0, 15.0,
			15.0), B_CMAP8);
		if (mimeBitmap && mimeBitmap->IsValid()) {
			status = fileType->GetIcon(mimeBitmap, small ? B_MINI_ICON
				: B_LARGE_ICON);
			if (status >= B_OK) {
				if (BBitmap* bitmap = _ConvertToRGB32(mimeBitmap)) {
					status = _MakeBitmaps(bitmap);
					delete bitmap;
				} else {
					printf("BIconButton::SetIcon() - B_RGB32 bitmap is not "
						"valid\n");
				}
			} else {
				printf("BIconButton::SetIcon() - fileType->GetIcon() failed: "
					"%s\n", strerror(status));
			}
		} else
			printf("BIconButton::SetIcon() - B_CMAP8 bitmap is not valid\n");
		delete mimeBitmap;
	} else {
		printf("BIconButton::SetIcon() - fileType is not valid: %s\n",
			strerror(status));
	}
	return status;
}
コード例 #3
0
ファイル: IconButton.cpp プロジェクト: Barrett17/Faber
status_t
BIconButton::SetIcon(const BBitmap* bitmap, uint32 flags)
{
	if (bitmap && bitmap->ColorSpace() == B_CMAP8) {
		status_t status = bitmap->InitCheck();
		if (status >= B_OK) {
			if (BBitmap* rgb32Bitmap = _ConvertToRGB32(bitmap)) {
				status = _MakeBitmaps(rgb32Bitmap);
				delete rgb32Bitmap;
			} else
				status = B_NO_MEMORY;
		}
		return status;
	} else
		return _MakeBitmaps(bitmap);
}
コード例 #4
0
ファイル: VolumeSlider.cpp プロジェクト: mmanley/Antares
// SetMuted
void
VolumeSlider::SetMuted(bool mute)
{
	if (mute == fMuted)
		return;

	fMuted = mute;
	_MakeBitmaps();
	Invalidate();
}
コード例 #5
0
ファイル: VolumeSlider.cpp プロジェクト: mmanley/Antares
// SetEnabled
void
VolumeSlider::SetEnabled(bool enable)
{
	if (enable == IsEnabled())
		return;

	BControl::SetEnabled(enable);

	_MakeBitmaps();
	Invalidate();
}
コード例 #6
0
ファイル: IconButton.cpp プロジェクト: Barrett17/Faber
status_t
BIconButton::SetIcon(const char* pathToBitmap)
{
	if (pathToBitmap == NULL)
		return B_BAD_VALUE;

	status_t status = B_BAD_VALUE;
	BBitmap* fileBitmap = NULL;
	// try to load bitmap from either relative or absolute path
	BEntry entry(pathToBitmap, true);
	if (!entry.Exists()) {
		app_info info;
		status = be_app->GetAppInfo(&info);
		if (status == B_OK) {
			BEntry app_entry(&info.ref, true);
			BPath path;
			app_entry.GetPath(&path);
			status = path.InitCheck();
			if (status == B_OK) {
				status = path.GetParent(&path);
				if (status == B_OK) {
					status = path.Append(pathToBitmap, true);
					if (status == B_OK)
						fileBitmap = BTranslationUtils::GetBitmap(path.Path());
					else {
						printf("BIconButton::SetIcon() - path.Append() failed: "
							"%s\n", strerror(status));
					}
				} else {
					printf("BIconButton::SetIcon() - path.GetParent() failed: "
						"%s\n", strerror(status));
				}
			} else {
				printf("BIconButton::SetIcon() - path.InitCheck() failed: "
					"%s\n", strerror(status));
			}
		} else {
			printf("BIconButton::SetIcon() - be_app->GetAppInfo() failed: "
				"%s\n", strerror(status));
		}
	} else
		fileBitmap = BTranslationUtils::GetBitmap(pathToBitmap);
	if (fileBitmap) {
		status = _MakeBitmaps(fileBitmap);
		delete fileBitmap;
	} else
		status = B_ERROR;
	return status;
}
コード例 #7
0
ファイル: IconButton.cpp プロジェクト: Barrett17/Faber
status_t
BIconButton::SetIcon(const unsigned char* bitsFromQuickRes,
	uint32 width, uint32 height, color_space format, bool convertToBW)
{
	status_t status = B_BAD_VALUE;
	if (bitsFromQuickRes && width > 0 && height > 0) {
		BBitmap* quickResBitmap = new(std::nothrow) BBitmap(BRect(0.0, 0.0,
			width - 1.0, height - 1.0), format);
		status = quickResBitmap ? quickResBitmap->InitCheck() : B_ERROR;
		if (status >= B_OK) {
			// It doesn't look right to copy BitsLength() bytes, but bitmaps
			// exported from QuickRes still contain their padding, so it is
			// all right.
			memcpy(quickResBitmap->Bits(), bitsFromQuickRes,
				quickResBitmap->BitsLength());
			if (format != B_RGB32 && format != B_RGBA32
				&& format != B_RGB32_BIG && format != B_RGBA32_BIG) {
				// colorspace needs conversion
				BBitmap* bitmap = new(std::nothrow) BBitmap(
					quickResBitmap->Bounds(), B_RGB32, true);
				if (bitmap && bitmap->IsValid()) {
					BView* helper = new BView(bitmap->Bounds(), "helper",
						B_FOLLOW_NONE, B_WILL_DRAW);
					if (bitmap->Lock()) {
						bitmap->AddChild(helper);
						helper->SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
						helper->FillRect(helper->Bounds());
						helper->SetDrawingMode(B_OP_OVER);
						helper->DrawBitmap(quickResBitmap, BPoint(0.0, 0.0));
						helper->Sync();
						bitmap->Unlock();
					}
					status = _MakeBitmaps(bitmap);
				} else {
					printf("BIconButton::SetIcon() - B_RGB32 bitmap is not "
						"valid\n");
				}
				delete bitmap;
			} else {
				// native colorspace (32 bits)
				if (convertToBW) {
					// convert to gray scale icon
					uint8* bits = (uint8*)quickResBitmap->Bits();
					uint32 bpr = quickResBitmap->BytesPerRow();
					for (uint32 y = 0; y < height; y++) {
						uint8* handle = bits;
						uint8 gray;
						for (uint32 x = 0; x < width; x++) {
							gray = uint8((116 * handle[0] + 600 * handle[1]
								+ 308 * handle[2]) / 1024);
							handle[0] = gray;
							handle[1] = gray;
							handle[2] = gray;
							handle += 4;
						}
						bits += bpr;
					}
				}
				status = _MakeBitmaps(quickResBitmap);
			}
		} else {
			printf("BIconButton::SetIcon() - error allocating bitmap: "
				"%s\n", strerror(status));
		}
		delete quickResBitmap;
	}
	return status;
}
コード例 #8
0
ファイル: Icon.cpp プロジェクト: AmirAbrams/haiku
status_t
BIcon::SetTo(const BBitmap* bitmap, uint32 flags)
{
	if (!bitmap->IsValid())
		return B_BAD_VALUE;

	DeleteBitmaps();

	// check the color space
	bool hasAlpha = false;
	bool canUseForMakeBitmaps = false;

	switch (bitmap->ColorSpace()) {
		case B_RGBA32:
		case B_RGBA32_BIG:
			hasAlpha = true;
			// fall through
		case B_RGB32:
		case B_RGB32_BIG:
			canUseForMakeBitmaps = true;
			break;

		case B_UVLA32:
		case B_LABA32:
		case B_HSIA32:
		case B_HSVA32:
		case B_HLSA32:
		case B_CMYA32:
		case B_RGBA15:
		case B_RGBA15_BIG:
		case B_CMAP8:
			hasAlpha = true;
			break;

		default:
			break;
	}

	BBitmap* trimmedBitmap = NULL;

	// trim the bitmap, if requested and the bitmap actually has alpha
	status_t error;
	if ((flags & (B_TRIM_ICON_BITMAP | B_TRIM_ICON_BITMAP_KEEP_ASPECT)) != 0
		&& hasAlpha) {
		if (bitmap->ColorSpace() == B_RGBA32) {
			error = _TrimBitmap(bitmap,
				(flags & B_TRIM_ICON_BITMAP_KEEP_ASPECT) != 0, trimmedBitmap);
		} else {
			BBitmap* rgb32Bitmap = _ConvertToRGB32(bitmap, true);
			if (rgb32Bitmap != NULL) {
				error = _TrimBitmap(rgb32Bitmap,
					(flags & B_TRIM_ICON_BITMAP_KEEP_ASPECT) != 0,
					trimmedBitmap);
				delete rgb32Bitmap;
			} else
				error = B_NO_MEMORY;
		}

		if (error != B_OK)
			return error;

		bitmap = trimmedBitmap;
		canUseForMakeBitmaps = true;
	}

	// create the bitmaps
	if (canUseForMakeBitmaps) {
		error = _MakeBitmaps(bitmap, flags);
	} else {
		if (BBitmap* rgb32Bitmap = _ConvertToRGB32(bitmap, true)) {
			error = _MakeBitmaps(rgb32Bitmap, flags);
			delete rgb32Bitmap;
		} else
			error = B_NO_MEMORY;
	}

	delete trimmedBitmap;

	return error;
}