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


C++ BResources类代码示例

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


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

示例1:

BBitmap * BitmapUtils::LoadFromResource(int32 id)
{
	BArchivable *archivable;
	BResources resources;
	BMessage message;
	const void *data;
	BBitmap *bitmap;
	app_info info;
	BFile file;
	size_t len;

	if (be_app->GetAppInfo(&info) != B_OK) return NULL;
	if (file.SetTo(&(info.ref), B_READ_ONLY) != B_OK) return NULL;
	if (resources.SetTo(&file, false) != B_OK) return NULL;
	data = resources.LoadResource('BBMP', id, &len);
	if (data == NULL || len <= 0) return NULL;
	if (message.Unflatten((const char *)data) != B_OK) return NULL;
	archivable = BBitmap::Instantiate(&message);
	if (archivable == NULL) return NULL;
	bitmap = dynamic_cast<BBitmap*>(archivable);
	if (bitmap == NULL) {
		delete archivable;
		return NULL;
	}
	return bitmap;
}
开发者ID:HaikuArchives,项目名称:BeTeX,代码行数:26,代码来源:BitmapUtils.cpp

示例2: BBitmap

BBitmap*
MediaAlert::InitIcon()
{
	// The alert icons are in the app_server resources
	BBitmap* icon = NULL;
	BPath path;
	if (find_directory(B_BEOS_SERVERS_DIRECTORY, &path) == B_OK) {
		path.Append("app_server");
		BFile file;
		if (file.SetTo(path.Path(), B_READ_ONLY) == B_OK) {
			BResources resources;
			if (resources.SetTo(&file) == B_OK) {
				// Which icon are we trying to load?
				const char* iconName = "warn";

				// Load the raw icon data
				size_t size;
				const void* rawIcon =
					resources.LoadResource(B_VECTOR_ICON_TYPE, iconName, &size);

				if (rawIcon != NULL) {
					// Now build the bitmap
					icon = new BBitmap(BRect(0, 0, 31, 31), B_RGBA32);
					if (BIconUtils::GetVectorIcon((const uint8*)rawIcon, size,
							icon) != B_OK) {
						delete icon;
						return NULL;
					}
				}
			}
		}
	}

	return icon;
}
开发者ID:mmanley,项目名称:Antares,代码行数:35,代码来源:MediaAlert.cpp

示例3: memio

// ---------------------------------------------------------------
// GetBitmap
//
// Returns a BBitmap object for the bitmap resource identified by
// the type type with the resource id, id. 
// The user has to delete this object.
//
// Preconditions:
//
// Parameters: type, the type of resource to be loaded
//             id, the id for the resource to be loaded
//             roster, BTranslatorRoster used to do the translation
//
// Postconditions:
//
// Returns: NULL, if the resource couldn't be loaded or couldn't
//                be translated to a BBitmap
//          BBitmap * to the bitmap identified by type and id
// ---------------------------------------------------------------
BBitmap *
BTranslationUtils::GetBitmap(uint32 type, int32 id, BTranslatorRoster *roster)
{
	BResources *pResources = BApplication::AppResources();
		// Remember: pResources must not be freed because
		// it belongs to the application
	if (pResources == NULL || pResources->HasResource(type, id) == false)
		return NULL;
	
	// Load the bitmap resource from the application file 
	// pRawData should be NULL if the resource is an
	// unknown type or not available
	size_t bitmapSize = 0;
	const void *kpRawData = pResources->LoadResource(type, id, &bitmapSize);
	if (kpRawData == NULL || bitmapSize == 0)
		return NULL;
	
	BMemoryIO memio(kpRawData, bitmapSize);
		// Put the pointer to the raw image data into a BMemoryIO object
		// so that it can be used with BTranslatorRoster->Translate() in
		// the GetBitmap(BPositionIO *, BTranslatorRoster *) function
	
	return GetBitmap(&memio, roster);
		// Translate the data in memio using the BTranslatorRoster roster
}
开发者ID:mmanley,项目名称:Antares,代码行数:44,代码来源:TranslationUtils.cpp

示例4: BBitmap

BBitmap*
AlertView::InitIcon()
{
	// This is how BAlert gets to its icon
	BBitmap* icon = NULL;
	BPath path;
	if (find_directory(B_BEOS_SERVERS_DIRECTORY, &path) == B_OK) {
		path.Append("app_server");
		BResources resources;
		BFile file;
		if (file.SetTo(path.Path(), B_READ_ONLY) == B_OK
			&& resources.SetTo(&file) == B_OK) {
			size_t size;
			const void* data = resources.LoadResource(B_VECTOR_ICON_TYPE,
				"warn", &size);
			if (data) {
				icon = new BBitmap(BRect(0, 0, 31, 31), 0, B_RGBA32);
				if (BIconUtils::GetVectorIcon((const uint8*)data, size, icon)
						!= B_OK) {
					delete icon;
					icon = NULL;
				}
			}
		}
	}

	return icon;
}
开发者ID:mmanley,项目名称:Antares,代码行数:28,代码来源:AlertView.cpp

示例5: file

/*static*/ void
BApplication::_InitAppResources()
{
	entry_ref ref;
	bool found = false;

	// App is already running. Get its entry ref with
	// GetAppInfo()
	app_info appInfo;
	if (be_app && be_app->GetAppInfo(&appInfo) == B_OK) {
		ref = appInfo.ref;
		found = true;
	} else {
		// Run() hasn't been called yet
		found = BPrivate::get_app_ref(&ref) == B_OK;
	}

	if (!found)
		return;

	BFile file(&ref, B_READ_ONLY);
	if (file.InitCheck() != B_OK)
		return;

	BResources* resources = new (std::nothrow) BResources(&file, false);
	if (resources == NULL || resources->InitCheck() != B_OK) {
		delete resources;
		return;
	}

	sAppResources = resources;
}
开发者ID:yunxiaoxiao110,项目名称:haiku,代码行数:32,代码来源:Application.cpp

示例6: SetViewColor

void
CamStatusView::AttachedToWindow()
{
	if (fController->LockLooper()) {
		fController->StartWatching(this, kMsgControllerCaptureStarted);
		fController->StartWatching(this, kMsgControllerCaptureStopped);
		fController->StartWatching(this, kMsgControllerCapturePaused);
		fController->StartWatching(this, kMsgControllerCaptureResumed);
		fController->StartWatching(this, kMsgControllerEncodeStarted);
		fController->StartWatching(this, kMsgControllerEncodeProgress);
		fController->StartWatching(this, kMsgControllerEncodeFinished);
		fController->UnlockLooper();
	}
	
	if (Parent())
		SetViewColor(Parent()->ViewColor());
	
	BResources* resources = be_app->AppResources();
	size_t size;
	const void* buffer = resources->LoadResource('VICN', "record_icon", &size);
	if (buffer != NULL)
		BIconUtils::GetVectorIcon((uint8*)buffer, size, fRecordingBitmap);
	buffer = resources->LoadResource('VICN', "pause_icon", &size);
	if (buffer != NULL)
		BIconUtils::GetVectorIcon((uint8*)buffer, size, fPauseBitmap);
	
	fBitmapView->SetBitmap(NULL);
}
开发者ID:jackburton79,项目名称:bescreencapture,代码行数:28,代码来源:CamStatusView.cpp

示例7: path

int32
Project::UpdateAttributes(void)
{
	BResources res;
	
	BPath path(fPath.GetFolder());
	path.Append(GetTargetName());
	
	BFile file(path.Path(), B_READ_WRITE);
	if (file.InitCheck() != B_OK)
		return B_BAD_VALUE;
	
	if (res.SetTo(&file) != B_OK)
		return B_ERROR;
	
	ResourceToAttribute(file,res,'MIMS',"BEOS:APP_SIG");
	ResourceToAttribute(file,res,'MIMS',"BEOS:TYPE");
	ResourceToAttribute(file,res,'MSGG',"BEOS:FILE_TYPES");
	ResourceToAttribute(file,res,'APPV',"BEOS:APP_VERSION");
	ResourceToAttribute(file,res,'APPF',"BEOS:APP_FLAGS");
	ResourceToAttribute(file,res,'ICON',"BEOS:L:STD_ICON");
	ResourceToAttribute(file,res,'MICN',"BEOS:M:STD_ICON");
	ResourceToAttribute(file,res,'VICN',"BEOS:ICON");
	
	return B_OK;
}
开发者ID:passick,项目名称:Paladin,代码行数:26,代码来源:Project.cpp

示例8: ResourceToAttribute

bool
ResourceToAttribute(BFile &file, BResources &res,type_code code, const char *name)
{
	if (!name)
		return false;
	
	int32 id;
	size_t length;
	if (res.GetResourceInfo(code,name,&id,&length))
	{
		const void *buffer = res.LoadResource(code,name,&length);
		if (!buffer)
		{
			STRACE(2,("Resource %s exists, but couldn't be loaded\n",name));
			return false;
		}
		file.WriteAttr(name,code,0,buffer,length);
		STRACE(2,("Successfully wrote attribute %s\n",name));
		return true;
	}
	else
	{
		STRACE(2,("Resource %s doesn't exist\n",name));
	}
	return false;
}
开发者ID:passick,项目名称:Paladin,代码行数:26,代码来源:Project.cpp

示例9: Flatten

status_t
DefaultCatalog::WriteToResource(const entry_ref &appOrAddOnRef)
{
	BFile file;
	status_t res = file.SetTo(&appOrAddOnRef, B_READ_WRITE);
	if (res != B_OK)
		return res;

	BResources rsrc;
	res = rsrc.SetTo(&file);
	if (res != B_OK)
		return res;

	BMallocIO mallocIO;
	mallocIO.SetBlockSize(max(fCatMap.Size() * 20, (int32)256));
		// set a largish block-size in order to avoid reallocs
	res = Flatten(&mallocIO);

	int mangledLanguage = CatKey::HashFun(fLanguageName.String(), 0);

	if (res == B_OK) {
		res = rsrc.AddResource('CADA', mangledLanguage,
			mallocIO.Buffer(), mallocIO.BufferLength(),
			BString(fLanguageName));
	}

	return res;
}
开发者ID:Barrett17,项目名称:haiku-contacts-kit-old,代码行数:28,代码来源:DefaultCatalog.cpp

示例10: ReadyToRun

void 
MyApp	::	ReadyToRun(	void) 
{
	BResources * appResources = AppResources();
	size_t len;
	char * str = (char *)appResources->FindResource('CSTR', "aResource", &len);
	printf("%s\n", str);
	free (str);
	PostMessage(B_QUIT_REQUESTED);
}//end
开发者ID:DonkeyWs,项目名称:BeGUI,代码行数:10,代码来源:hasResources.cpp

示例11: mime

status_t TaskFS::SetUpMimeTyp(void)
{
	status_t err;
	//set the MimeType
	BMimeType mime(TASK_MIMETYPE);
	//later do better check
	bool valid = mime.IsInstalled();
	if (!valid) {
		mime.Install();
		mime.SetShortDescription(B_TRANSLATE_CONTEXT("Tasks",
			"Short mimetype description"));
		mime.SetLongDescription(B_TRANSLATE_CONTEXT("Tasks",
			"Long mimetype description"));
		//get the icon from our Ressources
		BResources* res = BApplication::AppResources();
		if (res != NULL){
			size_t size;
			const void* data = res->LoadResource(B_VECTOR_ICON_TYPE, "TASK_ICON", &size);
			if (data!=NULL)
				mime.SetIcon(reinterpret_cast<const uint8*>(data), size);
		}
		mime.SetPreferredApp(APP_SIG);

		// add default task fields to meta-mime type
		BMessage fields;
		for (int32 i = 0; sDefaultAttributes[i].attribute; i++) {
			fields.AddString("attr:public_name", sDefaultAttributes[i].name);
			fields.AddString("attr:name", sDefaultAttributes[i].attribute);
			fields.AddInt32("attr:type", sDefaultAttributes[i].type);
			fields.AddString("attr:display_as", sDefaultAttributes[i].displayAs);
			fields.AddBool("attr:viewable", sDefaultAttributes[i].isPublic);
			fields.AddBool("attr:editable", sDefaultAttributes[i].editable);
			fields.AddInt32("attr:width", sDefaultAttributes[i].width);
			fields.AddInt32("attr:alignment", B_ALIGN_LEFT);
			fields.AddBool("attr:extra", false);
		}
		mime.SetAttrInfo(&fields);
			// create indices on all volumes for the found attributes.
		int32 count = 8;
		BVolumeRoster volumeRoster;
		BVolume volume;
		while (volumeRoster.GetNextVolume(&volume) == B_OK) {
			for (int32 i = 0; i < count; i++) {
				if (sDefaultAttributes[i].isPublic == true)
					fs_create_index(volume.Device(), sDefaultAttributes[i].attribute,
						sDefaultAttributes[i].type, 0);
			}
		}
	}
	else
		err = B_OK;
	return err;
}
开发者ID:Paradoxianer,项目名称:Tasks,代码行数:53,代码来源:TaskFS.cpp

示例12: LoadVectorIcon

BBitmap* LoadVectorIcon(const char* name, int32 size)
{
	BResources* res = BApplication::AppResources();
	size_t length = 0;
	const void* data = res->LoadResource(B_VECTOR_ICON_TYPE, name, &length);
	BBitmap* dest = new BBitmap(BRect(0, 0, size, size), B_RGBA32);
	if (data != NULL &&
		BIconUtils::GetVectorIcon((uint8*)data, length, dest) == B_OK)
		return dest;
	delete dest;
	return NULL;
}
开发者ID:Akujiism,项目名称:BePDF,代码行数:12,代码来源:ResourceLoader.cpp

示例13: BBitmap

void
ConfigWindow::MakeHowToView()
{
	BResources *resources = BApplication::AppResources();
	if (resources)
	{
		size_t length;
		char *buffer = (char *)resources->FindResource('ICON',101,&length);
		if (buffer)
		{
			BBitmap *bitmap = new BBitmap(BRect(0,0,63,63),B_CMAP8);
			if (bitmap && bitmap->InitCheck() == B_OK)
			{
				// copy and enlarge a 32x32 8-bit bitmap
				char *bits = (char *)bitmap->Bits();
				for (int32 i = 0,j = -64;i < length;i++)
				{
					if ((i % 32) == 0)
						j += 64;

					char *b = bits + (i << 1) + j;
					b[0] = b[1] = b[64] = b[65] = buffer[i];
				}
				fConfigView->AddChild(new BitmapView(bitmap));
			}
			else
				delete bitmap;
		}
	}

	BRect rect = fConfigView->Bounds();
	BTextView *text = new BTextView(rect,NULL,rect,B_FOLLOW_NONE,B_WILL_DRAW);
	text->SetViewColor(fConfigView->Parent()->ViewColor());
	text->SetAlignment(B_ALIGN_CENTER);
	text->SetText(
		MDR_DIALECT_CHOICE ("\n\nCreate a new account using the \"Add\" button.\n\n"
		"Delete accounts (or only the inbound/outbound) by using the \"Remove\" button on the selected item.\n\n"
		"Select an item in the list to edit its configuration.",
		"\n\nアカウントの新規作成は\"追加\"ボタンを\n使います。"
		"\n\nアカウント自体またはアカウントの\n送受信設定を削除するには\n項目を選択して\"削除\"ボタンを使います。"
		"\n\nアカウント内容の変更は、\nマウスで項目をクリックしてください。"));
	rect = text->Bounds();
	text->ResizeTo(rect.Width(),text->TextHeight(0,42));
	text->SetTextRect(rect);

	text->MakeEditable(false);
	text->MakeSelectable(false);

	fConfigView->AddChild(text);
	
	static_cast<CenterContainer *>(fConfigView)->Layout();
}
开发者ID:HaikuArchives,项目名称:BeMailDaemon,代码行数:52,代码来源:ConfigWindow.cpp

示例14: read_boot_code_data

// read_boot_code_data
static uint8 *
read_boot_code_data(const char* programPath)
{
	// open our executable
	BFile executableFile;
	status_t error = executableFile.SetTo(programPath, B_READ_ONLY);
	if (error != B_OK) {
		fprintf(stderr, "Error: Failed to open my executable file (\"%s\": "
			"%s\n", programPath, strerror(error));
		exit(1);
	}

	uint8 *bootCodeData = new uint8[kBootCodeSize];

	// open our resources
	BResources resources;
	error = resources.SetTo(&executableFile);
	const void *resourceData = NULL;
	if (error == B_OK) {
		// read the boot block from the resources
		size_t resourceSize;
		resourceData = resources.LoadResource(B_RAW_TYPE, 666, &resourceSize);

		if (resourceData && resourceSize != (size_t)kBootCodeSize) {
			resourceData = NULL;
			printf("Warning: Something is fishy with my resources! The boot "
				"code doesn't have the correct size. Trying the attribute "
				"instead ...\n");
		}
	}

	if (resourceData) {
		// found boot data in the resources
		memcpy(bootCodeData, resourceData, kBootCodeSize);
	} else {
		// no boot data in the resources; try the attribute
		ssize_t bytesRead = executableFile.ReadAttr("BootCode", B_RAW_TYPE,
			0, bootCodeData, kBootCodeSize);
		if (bytesRead < 0) {
			fprintf(stderr, "Error: Failed to read boot code from resources "
				"or attribute.\n");
			exit(1);
		}
		if (bytesRead != kBootCodeSize) {
			fprintf(stderr, "Error: Failed to read boot code from resources, "
				"and the boot code in the attribute has the wrong size!\n");
			exit(1);
		}
	}

	return bootCodeData;
}
开发者ID:mmanley,项目名称:Antares,代码行数:53,代码来源:makebootable.cpp

示例15: rect

BBitmap *LoadMiniIcon(int32 id) {
	BResources *res = BApplication::AppResources();
	if (res != NULL) {
		size_t length;
		const void *bits = res->LoadResource(miniIcon, id, &length);
		if ((bits != NULL) && (length == B_MINI_ICON * B_MINI_ICON)) {
			BRect rect(0, 0, B_MINI_ICON-1, B_MINI_ICON-1);
			BBitmap *bitmap = new BBitmap(rect, B_CMAP8);
			bitmap->SetBits(bits, B_MINI_ICON * B_MINI_ICON, 0, B_CMAP8);
			return bitmap;
		}
	}
	return NULL;
}
开发者ID:Akujiism,项目名称:BePDF,代码行数:14,代码来源:ResourceLoader.cpp


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