예제 #1
0
void
ScreenshotWindow::_ResizeToFitAndCenter()
{
	// Find out dimensions of the largest screenshot of this package
	ScreenshotInfoList screenshotInfos;
	if (fPackage.Get() != NULL)
		screenshotInfos = fPackage->ScreenshotInfos();

	int32 largestScreenshotWidth = 0;
	int32 largestScreenshotHeight = 0;

	const uint32 numScreenshots = fPackage->ScreenshotInfos().CountItems();
	for (uint32 i = 0; i < numScreenshots; i++) {
		const ScreenshotInfo& info = screenshotInfos.ItemAtFast(i);
		if (info.Width() > largestScreenshotWidth)
			largestScreenshotWidth = info.Width();
		if (info.Height() > largestScreenshotHeight)
			largestScreenshotHeight = info.Height();
	}

	fScreenshotView->SetExplicitMinSize(
		BSize(largestScreenshotWidth, largestScreenshotHeight));
	Layout(false);

	// TODO: Limit window size to screen size (with a little margin),
	//       the image should then become scrollable.

	float minWidth;
	float minHeight;
	GetSizeLimits(&minWidth, NULL, &minHeight, NULL);
	ResizeTo(minWidth, minHeight);
	CenterOnScreen();
}
예제 #2
0
void
ScreenshotWindow::_DownloadThread()
{
	printf("_DownloadThread()\n");
	if (!Lock()) {
		printf("  failed to lock screenshot window\n");
		return;
	}

	fScreenshotView->UnsetBitmap();

	ScreenshotInfoList screenshotInfos;
	if (fPackage.Get() != NULL)
		screenshotInfos = fPackage->ScreenshotInfos();

	Unlock();

	if (screenshotInfos.CountItems() == 0) {
		printf("  package has no screenshots\n");
		return;
	}

	// Obtain the correct code for the screenshot to display
	// TODO: Once navigation buttons are added, we could use the
	// ScreenshotInfo at the "current" index.
	const ScreenshotInfo& info = screenshotInfos.ItemAtFast(
		atomic_get(&fCurrentScreenshotIndex));

	BMallocIO buffer;
	WebAppInterface interface;

	// Only indicate being busy with the download if it takes a little while
	BMessenger messenger(this);
	BMessageRunner delayedMessenger(messenger,
		new BMessage(MSG_DOWNLOAD_START),
		kProgressIndicatorDelay, 1);

	// Retrieve screenshot from web-app
	status_t status = interface.RetrieveScreenshot(info.Code(),
		info.Width(), info.Height(), &buffer);

	delayedMessenger.SetCount(0);
	messenger.SendMessage(MSG_DOWNLOAD_STOP);

	if (status == B_OK && Lock()) {
		printf("got screenshot");
		fScreenshot = BitmapRef(new(std::nothrow)SharedBitmap(buffer), true);
		fScreenshotView->SetBitmap(fScreenshot);
		_ResizeToFitAndCenter();
		Unlock();
	} else {
		printf("  failed to download screenshot\n");
	}
}
예제 #3
0
void
ScreenshotWindow::_DownloadThread()
{
	printf("_DownloadThread()\n");
	if (!Lock()) {
		printf("  failed to lock screenshot window\n");
		return;
	}

	fScreenshotView->UnsetBitmap();

	ScreenshotInfoList screenshotInfos;
	if (fPackage.Get() != NULL)
		screenshotInfos = fPackage->ScreenshotInfos();

	Unlock();

	if (screenshotInfos.CountItems() == 0) {
		printf("  package has no screenshots\n");
		return;
	}

	// Obtain the correct code for the screenshot to display
	// TODO: Once navigation buttons are added, we could use the
	// ScreenshotInfo at the "current" index.
	const ScreenshotInfo& info = screenshotInfos.ItemAtFast(0);

	BMallocIO buffer;
	WebAppInterface interface;

	// Retrieve screenshot from web-app
	status_t status = interface.RetrieveScreenshot(info.Code(),
		info.Width(), info.Height(), &buffer);
	if (status == B_OK && Lock()) {
		printf("got screenshot");
		fScreenshot = BitmapRef(new(std::nothrow)SharedBitmap(buffer), true);
		fScreenshotView->SetBitmap(fScreenshot);
		_ResizeToFitAndCenter();
		Unlock();
	} else {
		printf("  failed to download screenshot\n");
	}
}