Example #1
0
void
MediaView::InitObject()
{
	BScreen screen;

	fMediaFile = NULL;
	fVideoTrack = NULL;
	fAudioTrack = NULL;
	fAudioOutput = NULL;
	fMediaBar = NULL;
	fBitmap = NULL;
	fBitmapDepth = screen.ColorSpace();
	fCurTime = 0;
	fPlayerThread = B_ERROR;
	fPlaySem = B_ERROR;
	fScrubSem = B_ERROR;
	fPlaying = false;
	fSnoozing = false;
	fAudioDumpingBuffer = NULL;

	BRect mediaBarFrame = Bounds();
	mediaBarFrame.top = mediaBarFrame.bottom - kMediaBarHeight;
	fMediaBar = new _MediaBar_(mediaBarFrame, this);
	AddChild(fMediaBar);

	SetViewColor(B_TRANSPARENT_32_BIT);
}
Example #2
0
void BBackView::Create()
{
	BScreen * screen = new BScreen();
	color_space clrmap = screen->ColorSpace(); 
	back = new BBitmap(Bounds(), clrmap, true);
	delete screen;	
}
Example #3
0
void Clock::Draw(BView *view, int32)
{
	BScreen screen;
	BBitmap buffer(view->Bounds(), screen.ColorSpace(), true);
	BView offscreen(view->Bounds(), NULL, 0, 0);
	buffer.AddChild(&offscreen);
	buffer.Lock();

	int n;
	float a,R;
	float width = view->Bounds().Width();
	float height = view->Bounds().Height();
	float zoom = (height/1024) * 0.85;

	time(&tmptodaytime);
	TodayTime = localtime(&tmptodaytime);

	todaysecond = TodayTime->tm_sec;
	todayminute = TodayTime->tm_min + (todaysecond/60.0);
	todayhour   = TodayTime->tm_hour + (todayminute/60.0);

	rgb_color bg_color = {0,0,0};
	offscreen.SetHighColor(bg_color);
	offscreen.SetLowColor(bg_color);
	offscreen.FillRect(offscreen.Bounds());

	offscreen.SetHighColor(200,200,200);

	for(n=0,a=0,R=510*zoom;n<60;n++,a+=(2*M_PI)/60) {
		float x = width/2 + R * cos(a);
		float y = height/2 + R * sin(a);
		DrawBlock(&offscreen,x,y,a,14*zoom);
	}

	offscreen.SetHighColor(255,255,255);

	for(n=0,a=0,R=500*zoom;n<12;n++,a+=(2*M_PI)/12) {
		float x = width/2 + R * cos(a);
		float y = height/2 + R * sin(a);
		DrawBlock(&offscreen,x,y,a,32*zoom);
	}

	offscreen.SetHighColor(255,255,255);
	DrawArrow(&offscreen, width/2,height/2, ( ((2*M_PI)/60) * todayminute) - (M_PI/2), 220*zoom, 1, 8*zoom);
	DrawArrow(&offscreen, width/2,height/2, ( ((2*M_PI)/12) * todayhour) - (M_PI/2), 140*zoom, 1, 14*zoom);
	offscreen.FillEllipse(BPoint(width/2,height/2),24*zoom,24*zoom);
	offscreen.SetHighColor(250,20,20);
	DrawArrow(&offscreen, width/2,height/2, ( ((2*M_PI)/60) * todaysecond) - (M_PI/2), 240*zoom, 1, 4*zoom);
	offscreen.FillEllipse(BPoint(width/2,height/2),20*zoom,20*zoom);

	offscreen.Sync();
	buffer.Unlock();
	view->DrawBitmap(&buffer);
	buffer.RemoveChild(&offscreen);
}
DeviceContext::DeviceContext
(void):
magic(DC_MAGIC),
owner(NULL),
stack(0)
{
	BScreen scr;
	color = scr.ColorSpace();
	objects = new Objects();
	memset(objects, 0, sizeof(Objects));
}
Example #5
0
int32
Controller::CaptureThread()
{
	Settings settings;
	BScreen screen;
	BRect bounds = settings.CaptureArea();
	bigtime_t captureDelay = (bigtime_t)settings.CaptureFrameDelay() * 1000;
	
	// TODO: Validate captureDelay with some limits
	
	_DumpSettings();
	_TestWaitForRetrace();
	
	const int32 windowBorder = settings.WindowFrameBorderSize();
	int32 token = GetWindowTokenForFrame(bounds, windowBorder);
	bigtime_t waitTime = 0;
	status_t error = B_ERROR;
	while (!fKillThread) {
		if (!fPaused) {		
			if (token != -1) {
				BRect windowBounds = GetWindowFrameForToken(token, windowBorder);
				if (windowBounds.IsValid())
					bounds.OffsetTo(windowBounds.LeftTop());
			}
				
			_WaitForRetrace(captureDelay); // Wait for Vsync
			BBitmap *bitmap = new BBitmap(bounds, screen.ColorSpace());
			error = ReadBitmap(bitmap, true, bounds);
			bigtime_t currentTime = system_time();
			// Takes ownership of the bitmap
	    	if (error == B_OK && fFileList->AddItem(bitmap, currentTime))
				atomic_add(&fNumFrames, 1);
			else {
				delete bitmap;
				break;
			}
		} else
			snooze(500000);
	}
	
	fCaptureThread = -1;
	fKillThread = true;
	
	if (error != B_OK) {
		BMessage message(kMsgControllerCaptureStopped);
		message.AddInt32("status", (int32)error);
		SendNotices(kMsgControllerCaptureStopped, &message);
		
		delete fFileList;
		fFileList = NULL;
	}
		
	return B_OK;
}
Example #6
0
/*	FUNCTION:		Video :: InitPlayer
	ARGUMENTS:		format
	RETURN:			n/a
	DESCRIPTION:	Create frame buffer and init decoder
*/
void Video :: InitPlayer(media_format *format)
{
	BRect frame(0, 0,
				format->u.encoded_video.output.display.line_width - 1.0f,
				format->u.encoded_video.output.display.line_count - 1.0f);
	
	BScreen screen;
	color_space cs = screen.ColorSpace();

	//	Loop asking the track for a format we can deal with
	for (;;)
	{
		fBitmap = new BBitmap(frame, cs);
		
		media_format mf, old_mf;
		memset(&mf, 0, sizeof(media_format));
		media_raw_video_format  *rvf = &mf.u.raw_video;
		rvf->last_active = (uint32)(frame.Height() - 1.0f);
		rvf->orientation = B_VIDEO_TOP_LEFT_RIGHT;
		rvf->pixel_width_aspect = 1;
		rvf->pixel_height_aspect = 3;
		rvf->display.format = cs;
		rvf->display.line_width = (int32)frame.Width();
		rvf->display.line_count = (int32)frame.Height();
		rvf->display.bytes_per_row = fBitmap->BytesPerRow();
		
		old_mf = mf;
		fVideoTrack->DecodedFormat(&mf);
		//	check if match found
		if (old_mf.u.raw_video.display.format == mf.u.raw_video.display.format)
			break;
		
		//	otherwise, change colour space
		cs = mf.u.raw_video.display.format;
		delete fBitmap;
	}
	
	media_header mh;
	fVideoTrack->SeekToTime(0);
	int64 dummy_num_frames;
	fVideoTrack->ReadFrames((char *)fBitmap->Bits(), &dummy_num_frames, &mh);
	fVideoTrack->SeekToTime(0);
}
Example #7
0
void
Clock::Draw(BView *view, int32)
{
	BScreen screenView;
	BBitmap bufferBitmap(view->Bounds(), screenView.ColorSpace(), true);
	BView offscreenView(view->Bounds(), NULL, 0, 0);
	bufferBitmap.AddChild(&offscreenView);
	bufferBitmap.Lock();

	float width = view->Bounds().Width();
	float height = view->Bounds().Height();
	float zoom = (height / 1024.0) * 0.65;
	
	time_t timeInfo;
	time(&timeInfo);
	struct tm *nowTime = localtime(&timeInfo);

	float secondVal = nowTime->tm_sec;
	float minuteVal = nowTime->tm_min + (secondVal / 60.0);
	float hourVal = nowTime->tm_hour + (minuteVal / 60.0);

	offscreenView.SetHighColor(0, 0, 0);
	offscreenView.SetLowColor(0, 0, 0);
	offscreenView.FillRect(offscreenView.Bounds());

	offscreenView.SetHighColor(200, 200, 200);
	
	centerX = width / 2.0;
	centerY = height / 2.0;

	float markAngle = 0;
	float markRadius = 510.0 * zoom;

	for(int mark = 0; mark < 60; mark++, markAngle += (2 * M_PI) / 60) {
		float x = centerX + markRadius * cos(markAngle);
		float y = centerY + markRadius * sin(markAngle);
		_drawBlock(&offscreenView, x, y, markAngle, 14.0 * zoom);
	}

	offscreenView.SetHighColor(255, 255, 255);

	markAngle = 0;
	markRadius = 500.0 * zoom;
	
	for (int mark = 0; mark < 12; mark++, markAngle += (2 * M_PI) / 12) {
		float x = centerX + markRadius * cos(markAngle);
		float y = centerY + markRadius * sin(markAngle);
		_drawBlock(&offscreenView, x, y, markAngle, 32 * zoom);
	}

	offscreenView.SetHighColor(255, 255, 255);
	_drawArrow(&offscreenView, centerX, centerY,
		((2 * M_PI / 60) * minuteVal) - (M_PI / 2), 220 * zoom, 1, 8 * zoom);

	_drawArrow(&offscreenView, centerX, centerY,
		((2 * M_PI / 12) * hourVal) - (M_PI / 2), 140 * zoom, 1, 14 * zoom);
	offscreenView.FillEllipse(BPoint(centerX, centerY),
		24 * zoom, 24 * zoom);
	
	offscreenView.SetHighColor(250, 20, 20);
	_drawArrow(&offscreenView, centerX, centerY,
		((2 * M_PI / 60) * secondVal) - (M_PI / 2), 240 * zoom, 1, 4 * zoom);
	offscreenView.FillEllipse(BPoint(centerX, centerY),
		20 * zoom, 20 * zoom);

	offscreenView.Sync();
	bufferBitmap.Unlock();
	view->DrawBitmap(&bufferBitmap);
	bufferBitmap.RemoveChild(&offscreenView);
}
Example #8
0
void 
Message::Draw(BView *view, int32 frame)
{
	// Double-buffered drawing
	BScreen screen;
	BBitmap buffer(view->Bounds(), screen.ColorSpace(), true);
	BView offscreen(view->Bounds(), NULL, 0, 0);
	buffer.AddChild(&offscreen);
	buffer.Lock();

	// Set up the colors
	rgb_color base_color = {rand() % 25, rand() % 25, rand() % 25};
	offscreen.SetHighColor(base_color); 
	offscreen.SetLowColor(tint_color(base_color, 0.815F));
	offscreen.FillRect(offscreen.Bounds(), kCheckered);
	rgb_color colors[8] = {
		tint_color(base_color, B_LIGHTEN_1_TINT),
		tint_color(base_color, 0.795F),
		tint_color(base_color, 0.851F),
		tint_color(base_color, 0.926F),
		tint_color(base_color, 1.05F),
		tint_color(base_color, B_DARKEN_1_TINT),
		tint_color(base_color, B_DARKEN_2_TINT),
		tint_color(base_color, B_DARKEN_3_TINT),
	};

	offscreen.SetDrawingMode(B_OP_OVER);

	// Set the basic font parameters, including random font family
	BFont font;
	offscreen.GetFont(&font);
	font.SetFace(B_BOLD_FACE);
	font.SetFamilyAndStyle(*(fFontFamilies.ItemAt(rand() % fFontFamilies.CountItems())), NULL);
	offscreen.SetFont(&font);

	// Get the message
	BString *message = get_message();
	BString *origMessage = new BString();
	message->CopyInto(*origMessage, 0, message->Length());
	// Replace newlines and tabs with spaces
	message->ReplaceSet("\n\t", ' ');

	int height = (int) offscreen.Bounds().Height();
	int width = (int) offscreen.Bounds().Width();

	// From 14 to 22 iterations
	int32 iterations = (rand() % 8) + 14;
	for (int32 i = 0; i < iterations; i++) {
		// Randomly set font size and shear
		BFont font;
		offscreen.GetFont(&font);
		float fontSize = ((rand() % 320) + 42) * fScaleFactor;
		font.SetSize(fontSize);
		// Set the shear off 90 about 1/2 of the time
		if (rand() % 2 == 1)
			font.SetShear((float) ((rand() % 135) + (rand() % 45)));
		else
			font.SetShear(90.0);
		offscreen.SetFont(&font);

		// Randomly set drawing location
		int x = (rand() % width) - (rand() % width/((rand() % 8)+1));
		int y = rand() % height;

		// Draw new text
		offscreen.SetHighColor(colors[rand() % 8]);
		int strLength = message->Length();
		// See how wide this string is with the current font
		float strWidth = offscreen.StringWidth(message->String());
		int drawingLength = (int) (strLength * (width / strWidth));
		int start = 0;
		if (drawingLength >= strLength)
			drawingLength = strLength;
		else
			start = rand() % (strLength - drawingLength);
		char *toDraw = new char[drawingLength+1];
		strncpy(toDraw, message->String()+start, drawingLength);
		toDraw[drawingLength] = 0;
		offscreen.DrawString(toDraw, BPoint(x, y));
		delete toDraw;
	}

	// Now draw the full message in a nice translucent box, but only
	// if this isn't preview mode
	if (!fPreview) {
		BFont font(be_fixed_font);
		font.SetSize(14.0); 
		offscreen.SetFont(&font);
		font_height fontHeight;
		font.GetHeight(&fontHeight);
		float lineHeight = fontHeight.ascent + fontHeight.descent + fontHeight.leading;
		
		BString **lines = NULL;
		int longestLine = 0;
		int count = get_lines(origMessage, &lines, &longestLine);

		float stringWidth = font.StringWidth(lines[longestLine]->String());
		BRect box(0, 0, stringWidth + 20, (lineHeight * count) + 20);
		box.OffsetTo((width - box.Width()) / 2, height - box.Height() - 40);

		offscreen.SetDrawingMode(B_OP_ALPHA);
		base_color.alpha = 128;
		offscreen.SetHighColor(base_color);
		offscreen.FillRoundRect(box, 8, 8);
		offscreen.SetHighColor(205, 205, 205);
		BPoint start = box.LeftTop();
		start.x += 10;
		start.y += 10 + fontHeight.ascent + fontHeight.leading;
		for (int i = 0; i < count; i++) {
			offscreen.DrawString(lines[i]->String(), start);
			start.y += lineHeight;
			delete lines[i];
		}
		delete[] lines;
	}

	delete origMessage;
	delete message;

	offscreen.Sync();
	buffer.Unlock();
	view->DrawBitmap(&buffer);
	buffer.RemoveChild(&offscreen);
}
Example #9
0
int main (int argc, char **argv)
{
	extern bool VerbQuit, VerbAddOns, NoAddOns, EasterEgg, UseMMX, ShowColors, BuiltInTablet, ExportCstruct;
	extern int DebugLevel, SilentOperation;
	
	VerbQuit		= false;
	VerbAddOns		= false;
	NoAddOns		= false;
	ShowColors		= false;
	PatronizeMIME	= true;
	BuiltInTablet	= false;
	ExportCstruct	= false;
	NoSettings		= false;
	WriteSettings	= false;
	EasterEgg		= EASTER_EGG;
	gGlobalAlpha	= REGISTERED;
	DebugLevel		= 0;
	SilentOperation	= 0;

	UseMMX		= true;

	for (int i = 1; i < argc; i++)
	{
		if (argv[i][0] == '-')
		{
			switch (argv[i][1])
			{
			case 'v':
			{
				VerbAddOns = true;
				break;
			}
			case 'q':
			{
				VerbQuit = true;
				break;
			}
			case 'x':
			{
				NoAddOns = true;
				break;
			}
			case 'e':
			{
				EasterEgg = !EASTER_EGG;
				break;
			}
			case 'D':
			{
				DebugLevel = atoi (&(argv[i][2]));
				fprintf (stderr, "Debug level set to %d\n", DebugLevel);
				break;
			}
			case 'd':
			{
				NoSettings = true;
				break;
			}
			case 'w':
			{
				WriteSettings = true;
				break;
			}
			case 'S':
			{
				SilentOperation = atoi (&(argv[i][2]));;
				break;
			}
			case 'M':
			{
				UseMMX = false;
				break;
			}
			case 'C':
			{
				ExportCstruct = true;
				break;
			}
			case 'c':
			{
				ShowColors = true;
				break;
			}
			case 't':
			{
				BuiltInTablet = true;
				break;
			}
			case 'h':
			{
				fprintf (stderr, "Recognized command line options:\n");
				fprintf (stderr, "  -v    Verbose add-on loading (useful for debugging your own)\n");
				fprintf (stderr, "  -q    Verbose quitting\n");
				fprintf (stderr, "  -x    Don't load add-ons (faster launch time)\n");
				fprintf (stderr, "  -d    Use default settings (don't load settings)\n");
				fprintf (stderr, "  -w    Force saving of settings (use with -d)\n");
				fprintf (stderr, "  -Dn   Debug verbosity level\n");
				fprintf (stderr, "  -Sn   Silence level (scripting operation)\n");
				fprintf (stderr, "  -M    Don't use MMX\n");
				fprintf (stderr, "  -c    Show recognized RGB color names at startup\n");
				fprintf (stderr, "  -C    Enable export as C struct\n");
				fprintf (stderr, "  -t    Switch on builtin Wacom tablet support\n");
				fprintf (stderr, "  -h    Display this message\n");
				break;
			}
			default:
				fprintf (stderr, "Unrecognized command line option: '%c'\n(Becasso -h displays command line usage help)\n", argv[i][1]);
			}
		}
	}
	#if defined (TIME_LIMITED)
		struct tm *mytime;
		time_t mytimet = time (NULL);
	#endif
	
#if defined (__INTEL__)
	if (UseMMX)
		UseMMX	= mmx_available();
#else
	UseMMX		= false;
#endif

	if (UseMMX)
		verbose (1, "MMX detected\n");
	else
		verbose (1, "No MMX\n");
	
	if (BuiltInTablet)
		verbose (1, "Builtin Tablet support enabled\n");
		
	mainapp = new Becasso();
	setup_alphabuffer();

	if (DebugLevel)
	{
		extern const char *Version;
		fprintf (stderr, "Becasso version %s %s, built %s\n",
			Version, (gGlobalAlpha ? "(Registered)" : "(Unregistered)"), __DATE__);
	}

	size_t bsize, ssize;
	void *becassodata, *sumdata;
	app_info info;
	mainapp->GetAppInfo (&info);
	BFile file (&info.ref, O_RDONLY);
	BResources res (&file);
	if (!(becassodata = res.FindResource ('blog', 128, &bsize)))
		fprintf (stderr, "Becasso logo resource not found\n");
	if (!(sumdata = res.FindResource ('slog', 129, &ssize)))
		fprintf (stderr, "Sum logo resource not found\n");
	BScreen screen;
	BRect becassorect = BRect (0, 0, 231, 93);
	BRect sumrect = BRect (0, 0, 63, 83);
	BBitmap *becasso = new BBitmap (becassorect, (screen.ColorSpace() == B_COLOR_8_BIT) ? B_COLOR_8_BIT : B_RGB32);
	// This strange color space thing is because we can't store bitmaps in 16 bit depth, so we use
	// a 32bit version for this screen mode (which doesn't look too bad).
	BBitmap *sum = new BBitmap (sumrect, B_RGB32);
	becasso->SetBits (becassodata, bsize, 0, B_RGB32);
	sum->SetBits (sumdata, ssize, 0, B_RGB32);
	BRect center = BRect (0, 0, 280, 210);
	center.OffsetTo (screen.Frame().Width()/2 - 140, screen.Frame().Height()/2 - 105);
	splash = new SplashWindow (center, becasso, sum);
	splash->Minimize (SilentOperation >= 3);
	splash->Show();
	mainapp->LoadAddOns();
	#if defined (TIME_LIMITED)
		mytime = localtime (&mytimet);
//		if (mytime->tm_year == 97 && mytime->tm_mon < 11)
		if (mytime->tm_year == 97)
			mainapp->Run();
		else
		{
			BAlert *alert = new BAlert ("", "This demo version of Becasso has expired.\nOn http://www.sumware.demon.nl you can find info on obtaining a newer version.\nThanks for your interest in Becasso!", "OK", NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT);
			alert->Go();
		}
	#else
		mainapp->Run();
	#endif
	delete mainapp;
//	delete BTranslatorRoster::Default();
	return 0;
}