Esempio n. 1
0
BBitmap*
SharedBitmap::_CreateBitmapFromResource(int32 size) const
{
	BResources resources;
	status_t status = get_app_resources(resources);
	if (status != B_OK)
		return NULL;

	size_t dataSize;
	const void* data = resources.LoadResource(B_VECTOR_ICON_TYPE, fResourceID,
		&dataSize);
	if (data != NULL)
		return _LoadIconFromBuffer(data, dataSize, size);

	data = resources.LoadResource(B_MESSAGE_TYPE, fResourceID, &dataSize);
	if (data != NULL)
		return _LoadBitmapFromBuffer(data, dataSize);

	return NULL;
}
Esempio n. 2
0
/**
 * Creates the throbber using a PNG for each frame.  The number of frames must
 * be at least two.  The first frame is the inactive frame, others are the
 * active frames.
 *
 * \param  frames  The number of frames.  Must be at least two.
 * \param  ...     Filenames of PNGs containing frames.
 * \return true on success.
 */
bool nsbeos_throbber_initialise_from_png(const int frames, ...)
{
	va_list filenames;
	struct nsbeos_throbber *throb;		/**< structure we generate */
	bool errors_when_loading = false;	/**< true if a frame failed */
	
	if (frames < 2) {
		/* we need at least two frames - one for idle, one for active */
		NSLOG(netsurf, INFO,
		      "Insufficent number of frames in throbber animation!");
		NSLOG(netsurf, INFO,
		      "(called with %d frames, where 2 is a minimum.)",
		      frames);
		return false;
	}

	BResources *res = get_app_resources();
	if (res == NULL) {
		NSLOG(netsurf, INFO, "Can't find resources for throbber!");
		return false;
	}

	throb = (struct nsbeos_throbber *)malloc(sizeof(*throb));
	throb->nframes = frames;
	throb->framedata = (BBitmap **)malloc(sizeof(BBitmap *) * throb->nframes);
	
	va_start(filenames, frames);
	
	for (int i = 0; i < frames; i++) {
		const char *fn = va_arg(filenames, const char *);
		const void *data;
		size_t size;
		data = res->LoadResource('data', fn, &size);
		throb->framedata[i] = NULL;
		if (!data) {
			NSLOG(netsurf, INFO, "Error when loading resource %s",
			      fn);
			errors_when_loading = true;
			continue;
		}
		BMemoryIO mem(data, size);
		throb->framedata[i] = BTranslationUtils::GetBitmap(&mem);
		if (throb->framedata[i] == NULL) {
			NSLOG(netsurf, INFO,
			      "Error when loading %s: GetBitmap() returned NULL",
			      fn);
			errors_when_loading = true;
		}
	}
	
	va_end(filenames);
	
	if (errors_when_loading == true) {
		for (int i = 0; i < frames; i++) {
			delete throb->framedata[i];
		}

		free(throb->framedata);
		free(throb);
		
		return false;		
	}
	
	nsbeos_throbber = throb;
	
	return true;
}