BBitmap* MainView::CreateIcon(const rgb_color colorIn)
{
	BRect rect(0, 0, 15, 15);
	BBitmap* toReturn = new BBitmap(rect, B_CMAP8, true);
	BView* drawing = new BView(rect, 
								"drawer", 
								B_FOLLOW_LEFT | B_FOLLOW_TOP,
								B_WILL_DRAW);
	if (!drawing || !toReturn) { return NULL; }	
	toReturn->AddChild(drawing);
	if (toReturn->Lock()) {
		drawing->SetHighColor(kWhite);
		drawing->FillRect(rect);
		drawing->SetHighColor(kBlack);
		drawing->SetPenSize(1);
		drawing->StrokeRect(rect);
		drawing->SetHighColor(colorIn);
		drawing->FillRect(rect.InsetBySelf(1, 1));
		drawing->Sync();
		toReturn->Unlock();			
	}
	toReturn->RemoveChild(drawing);
	delete drawing;
	return toReturn;
}
Пример #2
0
BBitmap* SwatchView::make_bitmap(void)
{
	BRect rect(0.0, 0.0, 12.0, 12.0);
	
	BBitmap *bitmap = new BBitmap(rect, B_RGB32, true);
	BView *view = new BView(rect, "", B_FOLLOW_NONE, B_WILL_DRAW);

	bitmap->Lock();

	bitmap->AddChild(view);

	view->SetDrawingMode(B_OP_ALPHA);
	view->SetHighColor(m_color);
	view->FillRect(rect);
	
	view->SetDrawingMode(B_OP_COPY);
	view->SetHighColor(0, 0, 0, 255);
	view->StrokeRect(rect);
	view->Sync();

	bitmap->RemoveChild(view);
	delete view;

	bitmap->Unlock();
	
	return bitmap;
}
Пример #3
0
void CounterView::Draw (BRect updateRect)
{
  BRect MovingRect (
    m_MovingDotPoint.x,
    m_MovingDotPoint.y,
    m_MovingDotPoint.x + m_MovingDotSize,
    m_MovingDotPoint.y + m_MovingDotSize);
  char TempString [40];

  if (m_BackingBitmap != NULL)
  {
    m_BackingBitmap->Lock ();
    m_BackingView.SetHighColor (60, 60, 255, 8);
    m_BackingView.FillRect (m_BndRect);
    m_BackingView.SetHighColor (255, 255, 0, 255);
    m_BackingView.MovePenTo (m_TextStartPoint);
    sprintf (TempString, "%d", m_CurrentCount);
    m_BackingView.DrawString (TempString);
    m_BackingView.FillRect (MovingRect);
    m_BackingView.Sync ();
    m_BackingBitmap->Unlock ();
    MovePenTo (0, 0);
    DrawBitmap (m_BackingBitmap);
  }
}
Пример #4
0
void MediaJack::_updateBitmap()
{
	D_METHOD(("MediaJack::_updateBitmap()\n"));

	if (m_bitmap)
	{
		delete m_bitmap;
	}
	BBitmap *tempBitmap = new BBitmap(Frame().OffsetToCopy(0.0, 0.0), B_CMAP8, true);
	tempBitmap->Lock();
	{
		BView *tempView = new BView(tempBitmap->Bounds(), "", B_FOLLOW_NONE, 0);
		tempBitmap->AddChild(tempView);
		tempView->SetOrigin(0.0, 0.0);

		MediaRoutingView* mediaView = dynamic_cast<MediaRoutingView*>(view());
		int32 layout = mediaView ? mediaView->getLayout() : MediaRoutingView::M_ICON_VIEW;

		_drawInto(tempView, tempView->Bounds(), layout);

		tempView->Sync();
		tempBitmap->RemoveChild(tempView);
		delete tempView;
	}
	tempBitmap->Unlock();
	m_bitmap = new BBitmap(tempBitmap);
	delete tempBitmap;
}
Пример #5
0
// SetIcon
status_t
IconButton::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(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 alright.
            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(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("IconButton::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("IconButton::SetIcon() - error allocating bitmap: %s\n", strerror(status));
        delete quickResBitmap;
    }
    return status;
}
Пример #6
0
/*!
 *	\brief		Create the square icon filled with submitted color.
 *	\param[in]	color		The color of the requested icon.
 *	\param[in]	toChange	If there is an allocated item, it may be changed.
 *							If the submitted pointer is not NULL (which is default),
 *							this BBitmap is tested for dimensions match, and if dimensions
 *							allow, its contents are replaced with new icon. Else, old icon
 *							is deleted, and a new is created. In this case, both the
 *							"toChange" pointer and returned pointer point to the same
 *							BBitmap. 
 */
BBitmap* CategoryMenuItem::CreateIcon(const rgb_color colorIn, BBitmap* toChange )
{
	font_height fh;
	BFont plainFont( be_plain_font );
	plainFont.GetHeight( &fh );
	
	int squareSize = ceilf( fh.ascent + fh.descent + fh.leading - 2 );	//!< Side of the square.
	BRect rect(0, 0, squareSize, squareSize );
	BBitmap* toReturn = NULL;
	if ( !toChange )	// Checking availability of the input
	{
		toReturn = new BBitmap(rect, B_RGB32, true);
	} else {
		// It would be a good idea to check also the color space,
		// but it may be changed by the BBitmap itself, so...
		if ( ceilf ( ( toChange->Bounds() ).Width() ) != squareSize )
		{
			delete toChange;
			toChange = new BBitmap(rect, B_RGB32, true);
			if ( !toChange )
			{
				/* Panic! */
				exit(1);
			}			
		}
		toReturn = toChange;
	}
	
	BView* drawing = new BView( rect, 
								"Drawer", 
								B_FOLLOW_LEFT | B_FOLLOW_TOP,
								B_WILL_DRAW);
	if (!drawing || !toReturn) { return NULL; }	
	toReturn->AddChild(drawing);
	if (toReturn->Lock()) {
		
		// Clean the area
		drawing->SetHighColor( ui_color( B_DOCUMENT_BACKGROUND_COLOR ) );
		drawing->FillRect(rect);
		
		// Draw the black square
		drawing->SetHighColor( ui_color( B_DOCUMENT_TEXT_COLOR ) );
		drawing->SetPenSize(1);
		drawing->StrokeRect(rect);
		
		// Fill the inside of the square
		drawing->SetHighColor( colorIn );
		drawing->FillRect(rect.InsetBySelf(1, 1));
		
		// Flush the actions to BBitmap
		drawing->Sync();
		toReturn->Unlock();
	}
	toReturn->RemoveChild(drawing);			// Cleanup
	delete drawing;
	return toReturn;
}	// <-- end of function CategoryMenuItem::CreateIcon
status_t
MakeScreenshot(BBitmap **here)
{
	status_t err;
	BScreen bs;
	BWindow *win;
	BBitmap *shot;
	BBitmap *scaledBmp = NULL;
	be_app->Lock();
	win = be_app->WindowAt(0);
	if (win) {
		win->Lock();
		win->Hide();
		win->Unlock();
	}
	snooze(500000);
	err = bs.GetBitmap(&shot);
	if (!err) {
		BRect scaledBounds(0,0,640-1,480-1);
		scaledBmp = new BBitmap(scaledBounds, B_BITMAP_ACCEPTS_VIEWS, B_RGB32/*shot->ColorSpace()*/);
		err = scaledBmp->InitCheck();
		if (!err) {
			err = ENOSYS;
#ifdef B_ZETA_VERSION
			err = ScaleBitmap(*shot, *scaledBmp);
#endif
			if (err) {
				// filtered scaling didn't work, do it manually
				BView *v = new BView(scaledBounds, "scaleview", B_FOLLOW_NONE, 0);
				scaledBmp->AddChild(v);
				v->LockLooper();
				v->DrawBitmap(shot);
				v->Sync();
				v->UnlockLooper();
				scaledBmp->RemoveChild(v);
				delete v;
				err = B_OK;
			}
		}
		delete shot;
	}

	if (win) {
		win->Lock();
		win->Show();
		win->Unlock();
	}
	be_app->Unlock();
	
	if (err)
		return err;
	
	*here = scaledBmp;

	return B_OK;
}
Пример #8
0
void
IconView::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage)
{
	if (fTracking && !fDragging && fIcon != NULL
		&& (abs((int32)(where.x - fDragPoint.x)) > 3
			|| abs((int32)(where.y - fDragPoint.y)) > 3)) {
		// Start drag
		BMessage message(B_SIMPLE_DATA);

		::Icon* icon = fIconData;
		if (fHasRef || fHasType) {
			icon = new ::Icon;
			if (fHasRef)
				icon->SetTo(fRef, fType.Type());
			else if (fHasType)
				icon->SetTo(fType);
		}

		icon->CopyTo(message);

		if (icon != fIconData)
			delete icon;

		BBitmap *dragBitmap = new BBitmap(fIcon->Bounds(), B_RGBA32, true);
		dragBitmap->Lock();
		BView *view
			= new BView(dragBitmap->Bounds(), B_EMPTY_STRING, B_FOLLOW_NONE, 0);
		dragBitmap->AddChild(view);

		view->SetHighColor(B_TRANSPARENT_COLOR);
		view->FillRect(dragBitmap->Bounds());
		view->SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_COMPOSITE);
		view->SetDrawingMode(B_OP_ALPHA);
		view->SetHighColor(0, 0, 0, 160);
		view->DrawBitmap(fIcon);

		view->Sync();
		dragBitmap->Unlock();

		DragMessage(&message, dragBitmap, B_OP_ALPHA,
			fDragPoint - BitmapRect().LeftTop(), this);
		fDragging = true;
		SetMouseEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY);
	}

	if (dragMessage != NULL && !fDragging && AcceptsDrag(dragMessage)) {
		bool dropTarget = transit == B_ENTERED_VIEW || transit == B_INSIDE_VIEW;
		if (dropTarget != fDropTarget) {
			fDropTarget = dropTarget;
			Invalidate();
		}
	} else if (fDropTarget) {
		fDropTarget = false;
		Invalidate();
	}
}
Пример #9
0
void KlondikeView::_LoadBitmaps()
{
	BString suits[] = {
		"spade",
		"heart",
		"club",
		"diamond"
	};

	// load images
	BString filename;
	for (short i = 0; i < CARDS_IN_SUIT; i++) {
		for (short j = 0; j < 4; j++) {
			filename = "";
			filename << "Artwork/" << i + 1 << "_" << suits[j] << ".png";
			fCards[j * CARDS_IN_SUIT + i]
				= BTranslationUtils::GetBitmap('rGFX', filename);
		}
	}
	fBack[0] = BTranslationUtils::GetBitmap('rGFX', "Artwork/back.png");
	fEmpty = BTranslationUtils::GetBitmap('rGFX', "Artwork/empty.png");

	// load audio
	fResources = be_app->AppResources();
	fShuffle = _LoadSound("Artwork/shuffle.wav");
	fFanfare = _LoadSound("Artwork/fanfare.wav");
	
	// cache multiple backs in a row
	for (short i = 1; i < CACHED_BACKS; i++) {
		fBack[i] = new BBitmap(BRect(0, 0, CARD_WIDTH - 1,
			CARD_HEIGHT + i * 18), fBack[0]->ColorSpace(), true);
		
		BView* fBackView = new BView(fBack[i]->Bounds(), NULL, 0, 0);
		BRect destRect = fBack[0]->Bounds();
		fBack[i]->AddChild(fBackView);
		fBack[i]->Lock();
		
		fBackView->SetDrawingMode(B_OP_COPY);
		fBackView->DrawBitmap(fBack[0], destRect);
		destRect.top = i * 18;
		destRect.bottom = destRect.top + CARD_HEIGHT;
		fBackView->DrawBitmap(fBack[0], destRect);
		
		fBackView->SetDrawingMode(B_OP_ALPHA);
		for (short j = 0; j < i + 1; j++) {
			destRect.top = j * 18;
			destRect.bottom = destRect.top + CARD_HEIGHT;
			fBackView->DrawBitmap(fBack[0], destRect);
		}
		fBackView->Sync();
		fBack[i]->Unlock();
	}

	Invalidate();
}
Пример #10
0
BBitmap *
PictureTest::CreateBitmap(BPicture *picture, BRect frame)
{
	OffscreenBitmap bitmap(frame, fColorSpace);
	TEST_AND_RETURN(bitmap.InitCheck() != B_OK, "Offscreen bitmap for picture drawing could not be created!" , NULL);

	BView *view = bitmap.View();		
	view->DrawPicture(picture);
	view->Sync();
	
	return bitmap.Copy();
}
Пример #11
0
BBitmap *DragonView::_MakeDragBitmap( void )
{
	// If the currently displayed bitmap is too large to drag around,
	// we'll just drag around a rectangle.

	BRect drag_rect = _bits->Bounds();

	if( drag_rect.Width() > _drag_max_size.x ||
		drag_rect.Height() > _drag_max_size.y ) return NULL;

	// If we've got a PNG image, we'll assume that it's got
	// "interesting" alpha information.  The ones that are built
	// into DragonDrop's resources all have "interesting" alpha
	// channels.
			
	if( _image_is_png ) {
		BBitmap *drag_me = new BBitmap( _bits );
		memcpy( drag_me->Bits(), _bits->Bits(), _bits->BitsLength() );
		
		return drag_me;
	}

	// If you've made it here, we'll need to build a semi-transparent image
	// to drag around.  This magic is from Pavel Cisler, and it ensures that
	// you've got a drag bitmap that's translucent.
	
	BRect rect( _bits->Bounds() );
	BBitmap *bitmap = new BBitmap( rect, B_RGBA32, true );
	BView *view = new BView( rect, "drag view", B_FOLLOW_NONE, 0 );

	bitmap->Lock();
	bitmap->AddChild( view );
	
	BRegion new_clip;
	new_clip.Set( rect );
	view->ConstrainClippingRegion( &new_clip );
	
	view->SetHighColor( 0, 0, 0, 0 );
	view->FillRect( rect );
	view->SetDrawingMode( B_OP_ALPHA );
	
	view->SetHighColor( 0, 0, 0, 128 );
	view->SetBlendingMode( B_CONSTANT_ALPHA, B_ALPHA_COMPOSITE );
	
	view->DrawBitmap( _bits );
	
	view->Sync();
	
	bitmap->Unlock();

	return bitmap;
}
Пример #12
0
void
KeyboardLayoutView::Draw(BRect updateRect)
{
	if (fOldSize != BSize(Bounds().Width(), Bounds().Height())) {
		_InitOffscreen();
		_LayoutKeyboard();
	}

	BView* view;
	if (fOffscreenBitmap != NULL) {
		view = fOffscreenView;
		view->LockLooper();
	} else
		view = this;

	// Draw background

	if (Parent())
		view->SetLowColor(Parent()->ViewColor());
	else
		view->SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));

	view->FillRect(updateRect, B_SOLID_LOW);

	// Draw keys

	for (int32 i = 0; i < fLayout->CountKeys(); i++) {
		Key* key = fLayout->KeyAt(i);

		_DrawKey(view, updateRect, key, _FrameFor(key),
			_IsKeyPressed(key->code));
	}

	// Draw LED indicators

	for (int32 i = 0; i < fLayout->CountIndicators(); i++) {
		Indicator* indicator = fLayout->IndicatorAt(i);

		_DrawIndicator(view, updateRect, indicator, _FrameFor(indicator->frame),
			(fModifiers & indicator->modifier) != 0);
	}

	if (fOffscreenBitmap != NULL) {
		view->Sync();
		view->UnlockLooper();

		DrawBitmapAsync(fOffscreenBitmap, BPoint(0, 0));
	}
}
Пример #13
0
BBitmap*
OffscreenBitmap::Copy()
{
	// the result bitmap that does not accept views	
	// to save resources in the application server
	BBitmap *copy = new BBitmap(fFrame, fColorSpace, false);
	AutoDelete<BBitmap> _copy(copy);
	if (copy == NULL || copy->IsValid() == false || copy->InitCheck() != B_OK)
		return NULL;

	fView->Sync();
	fBitmap->Unlock();
	
	memcpy(copy->Bits(), fBitmap->Bits(), fBitmap->BitsLength());	
	
	fBitmap->Lock();

	return _copy.Release();
}
Пример #14
0
BBitmap *bitmap (char *title)
{
	strcpy (title, "Grabbed");
	BBitmap *b = new BBitmap (BRect (0, 0, 127, 127), B_RGB_32_BIT, true);
	BView *v = new BView (BRect (0, 0, 127, 127), "bg", 0, 0);
	b->Lock();
	b->AddChild (v);
	rgb_color fg, bg;
	fg.red = 255; fg.green = 255; fg.blue = 255; fg.alpha = 255;
	bg.red = 0;   bg.green = 0;   bg.blue = 0;   bg.alpha = 127;
	v->SetHighColor (fg);
	v->SetLowColor (bg);
	v->FillRect (BRect (0, 0, 127, 127), B_MIXED_COLORS);
	v->Sync();
	b->RemoveChild (v);
	b->Unlock();
	delete v;
	return (b);
}
Пример #15
0
// _ConvertToRGB32
BBitmap*
IconButton::_ConvertToRGB32(const BBitmap* bitmap) const
{
    BBitmap* convertedBitmap = new(nothrow) BBitmap(bitmap->Bounds(), B_BITMAP_ACCEPTS_VIEWS, B_RGBA32);
    if (convertedBitmap && convertedBitmap->IsValid()) {
        memset(convertedBitmap->Bits(), 0, convertedBitmap->BitsLength());
        BView* helper = new BView(bitmap->Bounds(), "helper",
                                  B_FOLLOW_NONE, B_WILL_DRAW);
        if (convertedBitmap->Lock()) {
            convertedBitmap->AddChild(helper);
            helper->SetDrawingMode(B_OP_OVER);
            helper->DrawBitmap(bitmap, BPoint(0.0, 0.0));
            helper->Sync();
            convertedBitmap->Unlock();
        }
    } else {
        delete convertedBitmap;
        convertedBitmap = NULL;
    }
    return convertedBitmap;
}
Пример #16
0
BBitmap *DragonView::_MakeNoneImage( void )
{
	// Draw an "empty" bitmap to represent "no image"; we'll use one
	// that tells the user what to do.
	BBitmap *bitmap = new BBitmap( BRect( 0, 0, 319, 199 ),
								   BScreen().ColorSpace(),
								   true );
	BView *view = new BView( bitmap->Bounds(),
							 "not a bitmap",
							 B_FOLLOW_ALL_SIDES, 0 );
	bitmap->AddChild( view );

	DragonApp *app = dynamic_cast<DragonApp *>( be_app );
	
	rgb_color White = { 255, 255, 255, 0 };
	rgb_color Black = { 0, 0, 0, 0 };
	
	bitmap->Lock();

	view->SetLowColor( White );
	view->SetViewColor( White );
	view->SetHighColor( Black );
	view->SetDrawingMode( B_OP_OVER );
	view->FillRect( view->Bounds(), B_SOLID_LOW );

	// Excercise for the reader here:  Read the old newsletter articles
	// about how to use the font metrics to find out how large a font is,
	// then center to font in the window dynamically no matter what font
	// settings the user has.

	view->SetFont( be_plain_font );
	view->MovePenTo( 5, 100 );
	view->DrawString( app->rsrc_strings->FindString( RSRC_Drop_an_image ) );
	view->Sync();
	
	bitmap->Unlock();

	return bitmap;
}
Пример #17
0
bool
ClipView::InitiateDrag(BPoint point, int32 index, bool wasSelected)
{
	ClipItem* sItem = dynamic_cast<ClipItem *> (ItemAt(index));
	if (sItem == NULL)
		return false;

	BString string(sItem->GetClip());
	BMessage message(FAV_ADD);
	message.AddData("text/plain", B_MIME_TYPE, string, string.Length());
	message.AddPointer("clip", sItem);

	BRect dragRect(0.0f, 0.0f, Bounds().Width(), sItem->Height());
	BBitmap* dragBitmap = new BBitmap(dragRect, B_RGB32, true);
	if (dragBitmap->IsValid()) {
		BView* view = new BView(dragBitmap->Bounds(), "helper", B_FOLLOW_NONE,
			B_WILL_DRAW);
		dragBitmap->AddChild(view);
		dragBitmap->Lock();

		sItem->DrawItem(view, dragRect);
		view->SetHighColor(0, 0, 0, 255);
		view->StrokeRect(view->Bounds());
		view->Sync();

		dragBitmap->Unlock();
	} else {
		delete dragBitmap;
		dragBitmap = NULL;
	}

	if (dragBitmap != NULL)
		DragMessage(&message, dragBitmap, B_OP_ALPHA, BPoint(0.0, 0.0));
	else
		DragMessage(&message, dragRect.OffsetToCopy(point), this);

	return true;
}
Пример #18
0
void MediaNodePanel::_updateBitmap()
{
	if (m_bitmap)
	{
		delete m_bitmap;
	}
	BBitmap *tempBitmap = new BBitmap(Frame().OffsetToCopy(0.0, 0.0), B_CMAP8, true);
	tempBitmap->Lock();
	{
		BView *tempView = new BView(tempBitmap->Bounds(), "", B_FOLLOW_NONE, 0);
		tempBitmap->AddChild(tempView);
		tempView->SetOrigin(0.0, 0.0);
	
		int32 layout = dynamic_cast<MediaRoutingView *>(view())->getLayout();	
		_drawInto(tempView, tempView->Bounds(), layout);

		tempView->Sync();
		tempBitmap->RemoveChild(tempView);
		delete tempView;
	}
	tempBitmap->Unlock();
	m_bitmap = new BBitmap(tempBitmap);
	delete tempBitmap;
}
Пример #19
0
// MouseMoved
void
ObjectView::MouseMoved(BPoint where, uint32 transit,
					   const BMessage* dragMessage)
{
//	BRect dirty(where, where);
//	dirty.InsetBy(-10, -10);
//	Invalidate(dirty);
	
if (dragMessage) {
//printf("ObjectView::MouseMoved(BPoint(%.1f, %.1f)) - DRAG MESSAGE\n", where.x, where.y);
//Window()->CurrentMessage()->PrintToStream();
} else {
//printf("ObjectView::MouseMoved(BPoint(%.1f, %.1f))\n", where.x, where.y);
}

	if (fScrolling) {
		BCursor cursor(kGrabCursor);
		SetViewCursor(&cursor);
	
		BPoint offset = fLastMousePos - where;
		ScrollBy(offset.x, offset.y);
		fLastMousePos = where + offset;
	} else if (fInitiatingDrag) {
		BPoint offset = fLastMousePos - where;
		if (sqrtf(offset.x * offset.x + offset.y * offset.y) > 5.0) {
			BMessage newDragMessage('drag');
			BBitmap* dragBitmap = new BBitmap(BRect(0, 0, 40, 40), B_RGBA32,
				true);
			if (dragBitmap->Lock()) {
				BView* helper = new BView(dragBitmap->Bounds(),
					"offscreen view", B_FOLLOW_ALL, B_WILL_DRAW);
				dragBitmap->AddChild(helper);
				helper->SetDrawingMode(B_OP_ALPHA);
				helper->SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_COMPOSITE);

				BRect r(helper->Bounds());
				helper->SetHighColor(0, 0, 0, 128);
				helper->StrokeRect(r);

				helper->SetHighColor(200, 200, 200, 100);
				r.InsetBy(1, 1);
				helper->FillRect(r);

				helper->SetHighColor(0, 0, 0, 255);
				const char* text = B_TRANSLATE("Test");
				float pos = (r.Width() - helper->StringWidth(text)) / 2;
				helper->DrawString(text, BPoint(pos, 25));
				helper->Sync();
			}
			
			DragMessage(&newDragMessage, dragBitmap, B_OP_ALPHA, B_ORIGIN,
				this);
			fInitiatingDrag = false;
		}
	} else {
		BCursor cursor(kMoveCursor);
		SetViewCursor(&cursor);
	
		if (fState && fState->IsTracking()) {
			BRect before = fState->Bounds();
	
			fState->MouseMoved(where);
	
			BRect after = fState->Bounds();
			BRect invalid(before | after);
			Invalidate(invalid);
		}
	}
//	SetViewCursor();
}
Пример #20
0
// When this is running, no member variable should be accessed
// from other threads
status_t
MovieEncoder::_EncoderThread()
{	
	int32 framesLeft = fFileList->CountItems();
	int32 framesWritten = 0;
	
	if (framesLeft <= 0) {
		DisposeData();
		BMessage message(kEncodingFinished);
		message.AddInt32("status", (int32)B_ERROR);
		fMessenger.SendMessage(&message);
		return B_ERROR;
	}
	
	// Create movie
	entry_ref movieRef;
	get_ref_for_path(fOutputFile.Path(), &movieRef);
		
	BitmapEntry* entry = fFileList->ItemAt(0);
	BBitmap* bitmap = entry->Bitmap();
	BRect sourceFrame = bitmap->Bounds();
	delete bitmap;
		
	if (!fDestFrame.IsValid())
		fDestFrame = sourceFrame.OffsetToCopy(B_ORIGIN);
	
	// Calc the average time difference between the first 100 frames,
	// and use it to calculate the framerate.
	// TODO: Actually we could just calculate the number of frames and
	// the time difference between the first and the last one.
	/*int32 maxTimeStampNum = std::min((int32)100, fFileList->CountItems());	
	bigtime_t previousFrameTime = entry->TimeStamp();
	bigtime_t diffSum = 0;
	for (int32 i = 0; i < maxTimeStampNum; i++) {
		BitmapEntry* entry = fFileList->ItemAt(i);
		bigtime_t currentFrameTime = entry->TimeStamp();
		diffSum += currentFrameTime - previousFrameTime;		
		previousFrameTime = currentFrameTime;
	}
	
	float medianDiffTime = diffSum / maxTimeStampNum;
	*/
	int32 numFrames = fFileList->CountItems();
	BitmapEntry* firstEntry = fFileList->ItemAt(0);
	BitmapEntry* lastEntry = fFileList->ItemAt(numFrames - 1);
	int frameSeconds = (1000000 * numFrames) / (lastEntry->TimeStamp() - firstEntry->TimeStamp());
	media_format inputFormat = fFormat;
	inputFormat.u.raw_video.field_rate = frameSeconds;
	
	status_t status = _CreateFile(movieRef, fFileFormat, inputFormat, fCodecInfo);
	if (status < B_OK) {
		DisposeData();
		BMessage message(kEncodingFinished);
		message.AddInt32("status", (int32)status);
		fMessenger.SendMessage(&message);		
		return status;
	}
		
	// Bitmap and view used to convert the source bitmap
	// to the correct size and depth	
	BBitmap* destBitmap = new BBitmap(fDestFrame, fColorSpace, true);
	BView* destDrawer = new BView(fDestFrame, "drawing view", B_FOLLOW_NONE, 0);
	if (destBitmap->Lock()) {
		destBitmap->AddChild(destDrawer);
		destBitmap->Unlock();
	}
	
	const uint32 keyFrameFrequency = 10;
		// TODO: Make this tunable
	
	BMessage progressMessage(B_UPDATE_STATUS_BAR);
	progressMessage.AddFloat("delta", 1.0);
	
	destBitmap->Bounds().PrintToStream();
	PrintMediaFormat(inputFormat);
	
	status = B_OK;
	while (BitmapEntry* entry = const_cast<FileList*>(fFileList)->Pop()) {
		if (fKillThread)
			break;
	
		bool keyFrame = (framesWritten % keyFrameFrequency == 0);
		BBitmap* frame = entry->Bitmap();
		if (frame == NULL) {
			// TODO: What to do here ? Exit with an error ?
			std::cerr << "Error while loading bitmap entry" << std::endl;
			delete entry;
			continue;
		}
						
		// Draw scaled
		if (status == B_OK) {
			destBitmap->Lock();
			destDrawer->DrawBitmap(frame, frame->Bounds(), destDrawer->Bounds());
			destDrawer->Sync();
			destBitmap->Unlock();
		}
		
		delete frame;
		delete entry;
			
		if (status == B_OK)
			status = _WriteFrame(destBitmap, keyFrame);
		
		if (status != B_OK)
			break;

		framesWritten++;

		if (fMessenger.IsValid())
			fMessenger.SendMessage(new BMessage(progressMessage));
		else {
			// BMessenger is no longer valid. This means that the application
			// has been closed or it has crashed.
			break;
		}
	}

	delete destBitmap;
	
	DisposeData();
	
	if (fMessenger.IsValid()) {
		BMessage message(kEncodingFinished);
		message.AddInt32("status", (int32)status);
		message.AddInt32("frames", (int32)framesWritten);
		fMessenger.SendMessage(&message);
	}
		
	return status;
}
Пример #21
0
void MonthWindowView::DrawMonth()
{
 Bmp->Lock();
 
 float y=yearStringView->Frame().bottom+h_cell;
 float x=0;
 
 if(NewMonth)
 {
  BmpView->SetHighColor(VIEW_COLOR);
  BmpView->FillRect(BRect(0,y+1,
                    BmpView->Bounds().right,todayStringView->Frame().top-6));
  BmpView->SetHighColor(0,0,0,0);
  NewMonth=false;
 }
 
 int byear=cyear; // base year
 if(tyear<byear) byear=tyear;
  
 int day1=0, m=0, k=byear;
 
 while(k<cyear)
 {
  day1++;

  if(k%4==0) // leap year?
   if((k%100!=0) || (k%400==0)) day1++; // yes
  
  k++;
 }
 while(++m<cmonth)
 {
  day1+=(monthDays[m-1]-28);
  if(m==2) if((cyear%4)==0) if((cyear%100!=0) || (cyear%400==0)) day1++;
 }
 day1++; // day1 is number of 1st day of chosen month in chosen year
 day1=day1%7;
 
 int day2=0;
 m=0;
 k=byear;
 while(k<tyear)
 {
  day2++;
  if((k%4)==0) if((k%100!=0) || (k%400==0)) day2++;
  k++;
 }
 while(++m<tmonth)
 {
  day2+=(monthDays[m-1]-28);
  if(m==2) if((tyear%4)==0) if((tyear%100!=0) || (tyear%400==0)) day2++;
 }
 day2+=tday; // day2 - number of today's day in today's year
 day2=day2%7;
 
 k=(twday==0) ? 6 : twday-1;
 
 k=k-day2+day1;
 while(k<0) k+=7;
 k=k%7;
 cwday1=k;
 
 x=w_cell*k+1;
 y+=h_cell;
 
 int qu_days=monthDays[cmonth-1]; // quantity of days in month
 
 if(cmonth==2) if(cyear%4==0) if((cyear%100!=0) || (cyear%400==0)) qu_days=29;
 
 BString s;
 int t=0;
 while(t<qu_days)
 {
  t++;
  
  s<<t;
  
  if(cyear==tyear) if(cmonth==tmonth) if(t==tday) BmpView->SetHighColor(200,0,0,0);
  BmpView->DrawString(s.String(),BPoint(x+(w_cell-StringWidth(s.String()))/2,y));
  if(cyear==tyear) if(cmonth==tmonth) if(t==tday) BmpView->SetHighColor(0,0,0,0);
  
  if(t==cday)
  {
   cwday=k;
   if(which_focused==2) BmpView->SetHighColor(ACTIVE_COLOR);
   else BmpView->SetHighColor(NOACTIVE_COLOR);
   cursor.Set(x,y-h_cell+5,x+w_cell-1,y+4);
   BmpView->StrokeRect(cursor);
   BmpView->SetHighColor(0,0,0,0);
  }
  
  x+=w_cell;
  k++;
  s.SetTo("");
  
  if(k==7)
  {
   k=0;
   y+=h_cell;
   x=1;
  }
 }
 
 BmpView->Sync();
 Bmp->Unlock();
 Draw(Bounds());
}
/*!	\function	CategoryMenuItem::CreateIcon
 *	\brief		Create the square icon filled with submitted color.
 *	\param[in]	color		The color of the requested icon.
 *	\param[in]	toChange	If there is an allocated item, it may be changed.
 *							If the submitted pointer is not NULL (which is default),
 *							this BBitmap is tested for dimensions match, and if dimensions
 *							allow, its contents are replaced with new icon. Else, old icon
 *							is deleted, and a new is created. In this case, both the
 *							"toChange" pointer and returned pointer point to the same
 *							BBitmap.
 */
BBitmap*	CategoryMenuItem::CreateIcon( const rgb_color color,
										  BBitmap* toChange )
{
	BBitmap* toReturn = NULL;	//!< This is the value to be returned.
	BRect tempRect;
	float width, height, squareSide;
	
	// Get size of the square
	this->GetContentSize( &width, &height );
	squareSide = ceilf( height ) - 2;
	
	// Compare submitted bitmap to calculated size
	if ( toChange )
	{
		tempRect = toChange->Bounds();
		if ( ( tempRect.Width() != squareSide ) ||
			 ( tempRect.Height() != squareSide ) )
		{
			// Dimensions don't match - need to delete the bitmap and reallocate it
			delete toChange;
			tempRect.Set( 0, 0, squareSide, squareSide );
			toChange = new BBitmap( tempRect, B_RGB32, true );
			if ( !toChange )
			{
				/* Panic! */
				exit(1);
			}
			
			toReturn = toChange;
		}
		else
		{
			/*!	\note	Note about color spaces
			 *			Actually, even if the dimensions are correct, the existing
			 *			BBitmap may be not suitable due to incorrect color space.
			 *			However, BBitmap may change the color space on its own, (and
			 *			probably will, since there's no much sense in having 32 bits
			 *			per pixel for bitmap with only 2 colors - black for the frame
			 *			and Category's color for the inside). Therefore, color space is
			 *			not checked. It's assumed that existing color space is good enough.
			 */
			// Dimensions match, color space is not checked - continuing
			toReturn = toChange;
		}
	}
	else	// No bitmap is submitted
	{
		toReturn = new BBitmap( tempRect, B_RGB32, true );
		if ( !toReturn )
		{
			/* Panic! */
			exit(1);
		}
	}
	
	/* Here toReturn is already set. */
	
	// Add the drawing view to the bitmap
	tempRect.Set( 0, 0, squareSide, squareSide );
	BView* drawing = new BView (tempRect,
								"Drawer", 
								B_FOLLOW_LEFT | B_FOLLOW_TOP,
								B_WILL_DRAW);
	if (!drawing || !toReturn) {
		/* Panic! */
		return NULL;
	}	
	toReturn->AddChild(drawing);
	if (toReturn->Lock()) {

		// Clean the area
		drawing->SetHighColor( ui_color( B_MENU_BACKGROUND_COLOR ) );
		drawing->FillRect( tempRect );
		
		// Draw the black square
		drawing->SetHighColor( ui_color( B_MENU_ITEM_TEXT_COLOR ) );
		drawing->SetPenSize( 1 );
		drawing->StrokeRect( tempRect );
		
		// Fill the inside of the square
		drawing->SetHighColor( color );
		drawing->FillRect( tempRect.InsetBySelf( 1, 1 ) );
		
		// Flush the actions to BBitmap
		drawing->Sync();
		toReturn->Unlock();	
	}

	toReturn->RemoveChild( drawing );
	delete drawing;

	return toReturn;
}	// <-- end of function "CategoryMenuItem::CreateIcon"
Пример #23
0
void MonthWindowView::KeyDown(const char *bytes, int32 numBytes)
{
 switch(bytes[0])
 {
  case B_TAB:
  {
   Bmp->Lock();
   switch(which_focused)
   {
    case 0: // months
    {
     BmpView->SetHighColor(VIEW_COLOR);
     BmpView->StrokeLine(BPoint(monthMStringView[0]->Frame().left,
                                monthMStringView[0]->Frame().bottom+1),
                         BPoint(monthMStringView[1]->Frame().right,
                                monthMStringView[1]->Frame().bottom+1));
     BmpView->SetHighColor(0,0,0);
     break;
    }
    case 1: // years
    {
     BmpView->SetHighColor(VIEW_COLOR);
     BmpView->StrokeLine(BPoint(yearMStringView[0]->Frame().left,
                                yearMStringView[0]->Frame().bottom+1),
                         BPoint(yearMStringView[1]->Frame().right,
                                yearMStringView[1]->Frame().bottom+1));
     BmpView->SetHighColor(0,0,0);
     break;
    }
    case 2: // days of month
    {
     BmpView->SetHighColor(NOACTIVE_COLOR);
     BmpView->StrokeRect(cursor);
     BmpView->SetHighColor(0,0,0);
     break;
    }
    case 3: // today
    {
     BmpView->SetHighColor(VIEW_COLOR);
     BmpView->StrokeLine(BPoint(todayStringView->Frame().left,
                                todayStringView->Frame().bottom+1),
                         BPoint(todayStringView->Frame().right,
                                todayStringView->Frame().bottom+1));
     BmpView->SetHighColor(0,0,0);
     break;
    }
   }
   
   // changing which_focused
   if(modifiers() & B_SHIFT_KEY)
   {
    if(which_focused==0)
      which_focused=3;
    else which_focused--;
   }
   else // simply Tab
   {
    if(which_focused==3)
     which_focused=0;
    else which_focused++;
   }
   
   // drawing with new which_focused
   switch(which_focused)
   {
    case 0: // months
    {
     BmpView->SetHighColor(ACTIVE_COLOR);
     BmpView->StrokeLine(BPoint(monthMStringView[0]->Frame().left,
                                monthMStringView[0]->Frame().bottom+1),
                         BPoint(monthMStringView[1]->Frame().right,
                                monthMStringView[1]->Frame().bottom+1));
     BmpView->SetHighColor(0,0,0);
     break;
    }
    case 1: // years
    {
     BmpView->SetHighColor(ACTIVE_COLOR);
     BmpView->StrokeLine(BPoint(yearMStringView[0]->Frame().left,
                                yearMStringView[0]->Frame().bottom+1),
                         BPoint(yearMStringView[1]->Frame().right,
                                yearMStringView[1]->Frame().bottom+1));
     BmpView->SetHighColor(0,0,0);
     break;
    }
    case 2: // days of month
    {
     BmpView->SetHighColor(ACTIVE_COLOR);
     BmpView->StrokeRect(cursor);
     BmpView->SetHighColor(0,0,0);
     break;
    }
    case 3: // today
    {
     BmpView->SetHighColor(ACTIVE_COLOR);
     BmpView->StrokeLine(BPoint(todayStringView->Frame().left,
                                todayStringView->Frame().bottom+1),
                         BPoint(todayStringView->Frame().right,
                                todayStringView->Frame().bottom+1));
     BmpView->SetHighColor(0,0,0);
     break;
    }
   }
   BmpView->Sync();
   Bmp->Unlock();
   Draw(Bounds());
   break;
  } // B_TAB
  
  case B_DOWN_ARROW:
  {
   if(which_focused==0) // month
   { 
    BMessage msg('MON0');
    MessageReceived(&msg);
   }
   else if(which_focused==1) // year
   {
    BMessage msg('YEA0');
    MessageReceived(&msg);
   }
   else if(which_focused==2) // days of month
   {
    int qu_days=monthDays[cmonth-1];
    if(cmonth==2) if(cyear%4==0) if((cyear%100!=0) || (cyear%400==0)) qu_days=29;
    if((cday+7)<=qu_days)
    {
     Bmp->Lock();
     BmpView->SetHighColor(VIEW_COLOR);
     BmpView->StrokeRect(cursor);
     cursor.OffsetBySelf(0, h_cell);
     cday+=7;
     BmpView->SetHighColor(ACTIVE_COLOR);
     BmpView->StrokeRect(cursor);
     BmpView->SetHighColor(0,0,0);
     BmpView->Sync();
     Bmp->Unlock();
     Draw(Bounds());
    }
   }
   break;
  }
  
  case B_UP_ARROW:
  {
   // Test whether Ctrl+UpArrow is pressed
   if(modifiers() & B_CONTROL_KEY)
    Window()->PostMessage(B_QUIT_REQUESTED);
   else
   {
    if(which_focused==0) // month
    {
     BMessage msg('MON1');
     MessageReceived(&msg);
    }
    else if(which_focused==1) // year
    {
     BMessage msg('YEA1');
     MessageReceived(&msg);
    }
    else if(which_focused==2) // days of month
    {
     if((cday-7)>=1)
     {
      Bmp->Lock();
      BmpView->SetHighColor(VIEW_COLOR);
      BmpView->StrokeRect(cursor);
      cursor.OffsetBySelf(0, -h_cell);
      cday-=7;
      BmpView->SetHighColor(ACTIVE_COLOR);
      BmpView->StrokeRect(cursor);
      BmpView->SetHighColor(0,0,0);
      BmpView->Sync();
      Bmp->Unlock();
      Draw(Bounds());
     }
    }
   }
   break;
  }
  
  case B_LEFT_ARROW:
  {
   if(which_focused==0) // month
   {
    BMessage msg('MON0');
    MessageReceived(&msg);
   }
   else if(which_focused==1) // year
   {
    BMessage msg('YEA0');
    MessageReceived(&msg);
   }
   else if(which_focused==2) // days of month
   {
    if(cday>1)
    {
     Bmp->Lock();
     BmpView->SetHighColor(VIEW_COLOR);
     BmpView->StrokeRect(cursor);
     if(cwday>0) // by dates no matter of day of week
     {
      cursor.OffsetBySelf(-w_cell,0);
      cwday--;
     }
     else // cwday==0
     {
      cursor.OffsetBySelf(w_cell*6,-h_cell);
      cwday=6;
     }
     cday--;
     BmpView->SetHighColor(ACTIVE_COLOR);
     BmpView->StrokeRect(cursor);
     BmpView->SetHighColor(0,0,0);
     BmpView->Sync();
     Bmp->Unlock();
     Draw(Bounds());
    }
    else // 1st of month, go month before
    {
     if(cyear>first_year || cmonth>1) // one can go
     {
      int cm=(cmonth==1) ? 12 : cmonth-1;
      int qu_days=monthDays[cm-1];
      if(cm==2) if(cyear%4==0) 
       if((cyear%100!=0) || (cyear%400==0)) qu_days=29;
       // it is correct not to pay attention to year changing
       // because if we moved to february then year was not changed
       // but if month is other then february 
       // then it has the same number of days every year.
      cday=qu_days;
      
      BMessage msg('MON0');
      MessageReceived(&msg); // here month, cwday and year (if needed) will be changed
     }
    }
   }
   break;
  }
  
  case B_RIGHT_ARROW:
  {
   if(which_focused==0) // month
   {
    BMessage msg('MON1');
    MessageReceived(&msg);
   }
   else if(which_focused==1) // year
   {
    BMessage msg('YEA1');
    MessageReceived(&msg);
   }
   else if(which_focused==2) // days of month
   {
    int qu_days=monthDays[cmonth-1];
    if(cmonth==2) if(cyear%4==0) if((cyear%100!=0) || (cyear%400==0)) qu_days=29;
    if(cday<qu_days)
    {
     Bmp->Lock();
     BmpView->SetHighColor(VIEW_COLOR);
     BmpView->StrokeRect(cursor);
     if(cwday<6) // by dates no matter of day of week
     {
      cursor.OffsetBySelf(w_cell,0);
      cwday++;
     }
     else // cwday==6
     {
      cursor.OffsetBySelf(-w_cell*6,h_cell);
      cwday=0;
     }
     cday++;
     BmpView->SetHighColor(ACTIVE_COLOR);
     BmpView->StrokeRect(cursor);
     BmpView->SetHighColor(0,0,0);
     BmpView->Sync();
     Bmp->Unlock();
     Draw(Bounds());
    }
    else // last of month, go next month
    {
     if(cyear<last_year || cmonth<12) // one can go
     {
      cday=1;
      BMessage msg('MON1');
      MessageReceived(&msg); // here month, cwday and year (if needed) will be changed
     }
    }
   }
   break;
  }
  
  case B_ESCAPE:
  {
   Window()->PostMessage(B_QUIT_REQUESTED);
   break;
  }
  
  case B_ENTER:
  {
   if(which_focused==2)
   {
    // here it is needed to send dayPressed (==cwday), cyear, cmonth
    // to window and leave
    BMessage *msg=new BMessage('MVME');
    msg->AddInt32("day",cday);
    msg->AddInt32("month",cmonth);
    msg->AddInt32("year",cyear);
    Window()->PostMessage(msg);
   }
   else if(which_focused==3)
   {
    BMessage msg('TODA');
    MessageReceived(&msg);
   }
   break;
  }
  
  case B_SPACE: // the same as B_ENTER
  {
   if(which_focused==2)
   {
    // here it is needed to send dayPressed (==cwday), cyear, cmonth
    // to window and leave
    BMessage *msg=new BMessage('MVME');
    msg->AddInt32("day",cday);
    msg->AddInt32("month",cmonth);
    msg->AddInt32("year",cyear);
    Window()->PostMessage(msg);
   }
   else if(which_focused==3)
   {
    BMessage msg('TODA');
    MessageReceived(&msg);
   }
   break;
  }
  
  default: 
   BView::KeyDown(bytes, numBytes);
 }
}
Пример #24
0
void KlondikeView::MouseDown(BPoint point)
{
	if (fMouseLock)
		return;
	fMouseLock = true;
	
	uint32 mouse;
	GetMouse(&point, &mouse);
	
	if (mouse == B_SECONDARY_MOUSE_BUTTON) {
		// stop auto-play if it's started
		if (fAutoPlayStarted) {
			fAutoPlayStarted = false;
			return;
		}
		
		if (fQuickAutoPlay) {
			while(MoveOneToFoundation());
			
			Invalidate();
			CheckBoard();
		}
		else {
			fAutoPlayStarted = true;
		}
		
		return;
	}

	int hSpacing = _CardHSpacing();
	
	short stack = (int)((point.x - hSpacing) / (CARD_WIDTH + hSpacing));
	
	if (point.x > (stack + 1) * (CARD_WIDTH + hSpacing))
		return;
	
	// stock
	if (point.y < 15 + CARD_HEIGHT && point.y > 15
		&& stack == 0 && point.x > hSpacing) {
		int revealed = 0;
		for (short i = 0; i < 24; i++)
			if (fStock[i]->fRevealed)
				revealed++;
		
		if (revealed < 24 && ++fWasteCard == 24) {
			fWasteCard = -1;
			
			fPoints -= 100;
			if (fPoints < 0)
				fPoints = 0;
		}
		
		Invalidate();
		return;
	}
	
	// pick up a card from waste
	if (stack == 1 && point.y < 15 + CARD_HEIGHT) {		
		if (fWasteCard == -1)
			return;
		
		if (fDoubleClick == -1)
			fDoubleClick = 1;
		else if (fDoubleClick > -1) {
			_MoveWasteToFoundation();
			
			CheckBoard();	
			Invalidate();
			fDoubleClick = -1;
			
			return;
		}
		
		card* picked = fStock[fWasteCard];
		fPickedCard = picked;
		fIsWasteCardPicked = true;
		
		BMessage msg(B_SIMPLE_DATA);
		msg.AddPointer("view", this);
		BBitmap* img = new BBitmap(
			fCards[picked->fColor * CARDS_IN_SUIT + picked->fValue]);
		
		DragMessage(&msg, img, B_OP_BLEND,
			BPoint((int)(point.x - hSpacing) % (CARD_WIDTH + hSpacing),
			point.y - 15));
		
		Invalidate();
		
		return;
	}
	
	// pick up a card from a foundation
	if (stack > 2 && stack < 7 && point.y < 15 + CARD_HEIGHT) {
		short foundation = stack - 3;
		short value = fFoundations[foundation];
		short color = fFoundationsColors[foundation];
		
		if (fFoundations[foundation] == -1)
			return;
		
		// find picked card
		for (short i = 0; i < CARDS_IN_DECK; i++) {
			if (fAllCards[i]->fValue == value
				&& fAllCards[i]->fColor == color)
			fPickedCard = fAllCards[i];
		}
		
		BMessage msg(B_SIMPLE_DATA);
		msg.AddPointer("view", this);
		BBitmap* img = new BBitmap(
			fCards[fPickedCard->fColor * CARDS_IN_SUIT + fPickedCard->fValue]);
		
		fIsFoundationCardPicked = true;
		fPickedCardBoardPos = foundation;
		fFoundations[foundation]--;
		
		DragMessage(&msg, img, B_OP_BLEND,
			BPoint((int)(point.x - hSpacing) % (CARD_WIDTH + hSpacing),
			point.y - 15));
		
		Invalidate();
		
		return;
	}

	// pick up a stack
	if (stack < 7 && fBoard[stack] != NULL
		&& point.x > hSpacing && point.y > 2 * 15 + CARD_HEIGHT) {
		// find clicked on card
		int cardNumber = 1;
		card* picked = fBoard[stack];
		while (picked->fNextCard != NULL) {
			if (point.y - 18 * cardNumber - CARD_HEIGHT - 15 < 18) {
				break;
			}
			picked = picked->fNextCard;
			cardNumber++;
		}
		if (picked->fNextCard == NULL) {
			// on last card, if below than not clicking on card
			if (point.y - 18 * cardNumber - CARD_HEIGHT - 15 >= CARD_HEIGHT) {
				return;
			}
			
			if (fDoubleClick == -1)
				fDoubleClick = 1;
			else if (fDoubleClick > -1 && fAutoPlayEnabled) {
				MoveOneToFoundation(stack, stack);
				
				CheckBoard();	
				Invalidate();
				fDoubleClick = -1;
				
				return;
			}
		}
		
		if (picked->fRevealed == false)
			return;
		
		card* currentCard = picked->fNextCard;
		card* lastCard = picked;
		short pickedHeight = 1;
		for (short i = 1; currentCard != NULL;
				i++) {
			pickedHeight++;
			if (lastCard->fIsColorRed == currentCard->fIsColorRed)
				return;
			lastCard = currentCard;
			currentCard = currentCard->fNextCard;
		}
		
		fPickedCardBoardPos = stack;
		fPickedCard = picked;
		fIsCardPicked = true;

		_RemoveCardFromPile(stack, picked);

		BMessage msg(B_SIMPLE_DATA);
		msg.AddPointer("view", this);
		BBitmap* img;
		if (pickedHeight == 1)
			img = new BBitmap(
				fCards[picked->fColor * CARDS_IN_SUIT + picked->fValue]);
		else {
			img = new BBitmap(BRect(0, 0, CARD_WIDTH - 1,
				CARD_HEIGHT + (pickedHeight - 1) * 18),
				fBack[0]->ColorSpace(), true);
			BView* imgView = new BView(img->Bounds(), NULL, 0, 0);
			BRect destRect = fBack[0]->Bounds();
			img->AddChild(imgView);
			img->Lock();
			currentCard = picked;

			imgView->SetDrawingMode(B_OP_COPY);
			imgView->DrawBitmap(fCards
				[currentCard->fColor * CARDS_IN_SUIT + currentCard->fValue],
				destRect);
			destRect.top = (pickedHeight - 1) * 18;
			destRect.bottom = destRect.top + CARD_HEIGHT;

			imgView->DrawBitmap(fBack[0], destRect);
				// we don't know the top card yet, so we'll overwrite this

			imgView->SetDrawingMode(B_OP_ALPHA);
			for (short j = 0; j < pickedHeight; j++) {
				destRect.top = j * 18;
				destRect.bottom = destRect.top + CARD_HEIGHT;
				imgView->DrawBitmap(fCards[currentCard->fColor
					* CARDS_IN_SUIT + currentCard->fValue], destRect);
				currentCard = currentCard->fNextCard;
			}
			
			imgView->Sync();
			img->Unlock();
			img->RemoveChild(imgView);
			delete imgView;
		}
		DragMessage(&msg, img, B_OP_BLEND,
			BPoint((int)(point.x - hSpacing) % (CARD_WIDTH + hSpacing),
			point.y - cardNumber * 18 - 131));
		
		Invalidate();
	}
}
Пример #25
0
void
ActivityView::_DrawHistory(bool drawBackground)
{
	_UpdateOffscreenBitmap();

	BView* view = this;
	if (fOffscreen != NULL) {
		fOffscreen->Lock();
		view = _OffscreenView();
	}

	BRect frame = _HistoryFrame();
	BRect outerFrame = frame.InsetByCopy(-2, -2);

	// draw the outer frame
	uint32 flags = 0;
	if (!drawBackground)
		flags |= BControlLook::B_BLEND_FRAME;
	be_control_look->DrawTextControlBorder(this, outerFrame,
		outerFrame, fLegendBackgroundColor, flags);

	// convert to offscreen view if necessary
	if (view != this)
		frame.OffsetTo(B_ORIGIN);

	view->SetLowColor(fHistoryBackgroundColor);
	view->FillRect(frame, B_SOLID_LOW);

	uint32 step = 2;
	uint32 resolution = fDrawResolution;
	if (fDrawResolution > 1) {
		step = 1;
		resolution--;
	}

	// We would get a negative number of steps which isn't a good idea.
	if (frame.IntegerWidth() <= 10)
		return;

	uint32 width = frame.IntegerWidth() - 10;
	uint32 steps = width / step;
	bigtime_t timeStep = RefreshInterval() * resolution;
	bigtime_t now = system_time();

	// Draw scale
	// TODO: add second markers?

	view->SetPenSize(1);

	rgb_color scaleColor = view->LowColor();
	uint32 average = (scaleColor.red + scaleColor.green + scaleColor.blue) / 3;
	if (average < 96)
		scaleColor = tint_color(scaleColor, B_LIGHTEN_2_TINT);
	else
		scaleColor = tint_color(scaleColor, B_DARKEN_2_TINT);

	view->SetHighColor(scaleColor);
	view->StrokeLine(BPoint(frame.left, frame.top + frame.Height() / 2),
		BPoint(frame.right, frame.top + frame.Height() / 2));

	// Draw values

	view->SetPenSize(1.5);
	BAutolock _(fSourcesLock);

	for (uint32 i = fSources.CountItems(); i-- > 0;) {
		ViewHistory* viewValues = fViewValues.ItemAt(i);
		DataSource* source = fSources.ItemAt(i);
		DataHistory* values = fValues.ItemAt(i);

		viewValues->Update(values, steps, fDrawResolution, now, timeStep,
			RefreshInterval());

		if (viewValues->Start() >= (int32)steps - 1)
			continue;

		uint32 x = viewValues->Start() * step;

		bool first = true;

		view->SetHighColor(source->Color());
		view->SetLineMode(B_BUTT_CAP, B_ROUND_JOIN);
		view->MovePenTo(B_ORIGIN);

		try {
			view->BeginLineArray(steps - viewValues->Start() - 1);

			BPoint prev;

			for (uint32 j = viewValues->Start(); j < steps; x += step, j++) {
				float y = _PositionForValue(source, values,
					viewValues->ValueAt(j));

				if (first) {
					first = false;
				} else
					view->AddLine(prev, BPoint(x, y), source->Color());

				prev.Set(x, y);
			}

		} catch (std::bad_alloc) {
			// Not enough memory to allocate the line array.
			// TODO we could try to draw using the slower but less memory
			// consuming solution using StrokeLine.
		}

		view->EndLineArray();
	}

	// TODO: add marks when an app started or quit
	view->Sync();
	if (fOffscreen != NULL) {
		fOffscreen->Unlock();
		DrawBitmap(fOffscreen, outerFrame.LeftTop());
	}
}
Пример #26
0
// _UpdateThread
status_t
ColorSlider::_UpdateThread(void* data)
{
	// initializing
	ColorSlider* colorSlider = (ColorSlider*)data;
	
	bool looperLocked = colorSlider->LockLooper();

	port_id	port = colorSlider->fUpdatePort;
	orientation orient = colorSlider->fOrientation;

	if (looperLocked)
		colorSlider->UnlockLooper();
	
	float h, s, v, r, g, b;
	int R, G, B;
		
	// drawing

    int32 msg_code;
    char msg_buffer;

	while (true) {

		port_info info;

		do {

			read_port(port, &msg_code, &msg_buffer, sizeof(msg_buffer));
			get_port_info(port, &info);
			
		} while (info.queue_count);
		
		if (colorSlider->LockLooper()) {
	
			uint 	colormode = colorSlider->fMode;
			float	fixedvalue1 = colorSlider->fFixedValue1;
			float	fixedvalue2 = colorSlider->fFixedValue2;
		    
			BBitmap* bitmap = colorSlider->fBgBitmap;
			BView* view = colorSlider->fBgView;

			bitmap->Lock();

			colorSlider->UnlockLooper();	
	
			view->BeginLineArray(256);
			
			switch (colormode) {
				
				case R_SELECTED: {
					G = round(fixedvalue1 * 255);
					B = round(fixedvalue2 * 255);
					for (int R = 0; R < 256; ++R) {
						_DrawColorLineY( view, R, R, G, B );
					}
				}; break;
				
				case G_SELECTED: {
					R = round(fixedvalue1 * 255);
					B = round(fixedvalue2 * 255);
					for (int G = 0; G < 256; ++G) {
						_DrawColorLineY( view, G, R, G, B );
					}
				}; break;
				
				case B_SELECTED: {
					R = round(fixedvalue1 * 255);
					G = round(fixedvalue2 * 255);
					for (int B = 0; B < 256; ++B) {
						_DrawColorLineY( view, B, R, G, B );
					}
				}; break;
				
				case H_SELECTED: {
					s = 1.0;//fixedvalue1;
					v = 1.0;//fixedvalue2;
					if (orient == B_VERTICAL) {
						for (int y = 0; y < 256; ++y) {
							HSV_to_RGB( (float)y*6.0/255.0, s, v, r, g, b );
							_DrawColorLineY( view, y, r*255, g*255, b*255 );
						}
					} else {
						for (int x = 0; x < 256; ++x) {
							HSV_to_RGB( (float)x*6.0/255.0, s, v, r, g, b );
							_DrawColorLineX( view, x, r*255, g*255, b*255 );
						}
					}
				}; break;
				
				case S_SELECTED: {
					h = fixedvalue1;
					v = 1.0;//fixedvalue2;
					for (int y = 0; y < 256; ++y) {
						HSV_to_RGB( h, (float)y/255, v, r, g, b );
						_DrawColorLineY( view, y, r*255, g*255, b*255 );
					}
				}; break;
				
				case V_SELECTED: {
					h = fixedvalue1;
					s = 1.0;//fixedvalue2;
					for (int y = 0; y < 256; ++y) {
						HSV_to_RGB( h, s, (float)y/255, r, g, b );
						_DrawColorLineY( view, y, r*255, g*255, b*255 );
					}
				}; break;
			}
		
			view->EndLineArray();
			view->Sync();
			bitmap->Unlock();

			if (colorSlider->LockLooper()) {
				colorSlider->Update(1);
				colorSlider->UnlockLooper();
			}
		}
	}
	return B_OK;
}
Пример #27
0
void
BTitleView::Draw(BRect /*updateRect*/, bool useOffscreen, bool updateOnly,
	const BColumnTitle* pressedColumn,
	void (*trackRectBlitter)(BView*, BRect), BRect passThru)
{
	BRect bounds(Bounds());
	BView* view;

	if (useOffscreen) {
		ASSERT(sOffscreen);
		BRect frame(bounds);
		frame.right += frame.left;
			// ToDo: this is kind of messy way of avoiding being clipped
			// by the amount the title is scrolled to the left
		view = sOffscreen->BeginUsing(frame);
		view->SetOrigin(-bounds.left, 0);
		view->SetLowColor(LowColor());
		view->SetHighColor(HighColor());
		BFont font;
		GetFont(&font);
		view->SetFont(&font);
	} else
		view = this;

	view->SetHighUIColor(B_PANEL_BACKGROUND_COLOR, B_DARKEN_2_TINT);
	view->StrokeLine(bounds.LeftBottom(), bounds.RightBottom());
	bounds.bottom--;

	rgb_color baseColor = ui_color(B_PANEL_BACKGROUND_COLOR);
	be_control_look->DrawButtonBackground(view, bounds, bounds, baseColor, 0,
		BControlLook::B_TOP_BORDER | BControlLook::B_BOTTOM_BORDER);

	int32 count = fTitleList.CountItems();
	float minx = bounds.right;
	float maxx = bounds.left;
	for (int32 index = 0; index < count; index++) {
		BColumnTitle* title = fTitleList.ItemAt(index);
		title->Draw(view, title == pressedColumn);
		BRect titleBounds(title->Bounds());
		if (titleBounds.left < minx)
			minx = titleBounds.left;
		if (titleBounds.right > maxx)
			maxx = titleBounds.right;
	}

	bounds = Bounds();
	minx--;
	view->SetHighUIColor(B_PANEL_BACKGROUND_COLOR, B_DARKEN_1_TINT);
	view->StrokeLine(BPoint(minx, bounds.top),
		BPoint(minx, bounds.bottom - 1));

#if !(APP_SERVER_CLEARS_BACKGROUND)
	FillRect(BRect(bounds.left, bounds.top + 1, minx - 1, bounds.bottom - 1),
		B_SOLID_LOW);
	FillRect(BRect(maxx + 1, bounds.top + 1, bounds.right, bounds.bottom - 1),
		B_SOLID_LOW);
#endif

	if (useOffscreen) {
		if (trackRectBlitter)
			(trackRectBlitter)(view, passThru);

		view->Sync();
		DrawBitmap(sOffscreen->Bitmap());
		sOffscreen->DoneUsing();
	} else if (trackRectBlitter)
		(trackRectBlitter)(view, passThru);
}
Пример #28
0
void
RemoteView::_DrawThread()
{
	RemoteMessage reply(NULL, fSendBuffer);
	RemoteMessage message(fReceiveBuffer, NULL);

	// cursor
	BPoint cursorHotSpot(0, 0);

	while (!fStopThread) {
		uint16 code;
		status_t status = message.NextMessage(code);
		if (status != B_OK) {
			TRACE_ERROR("failed to read message from receiver\n");
			break;
		}

		TRACE("code %u with %ld bytes data\n", code, message.DataLeft());

		BAutolock locker(this->Looper());
		if (!locker.IsLocked())
			break;

		// handle stuff that doesn't go to a specicifc engine
		switch (code) {
			case RP_INIT_CONNECTION:
			{
				uint16 port;
				status_t result = message.Read(port);
				if (result != B_OK) {
					TRACE_ERROR("failed to read remote port\n");
					continue;
				}

				BNetEndpoint *endpoint = fReceiver->Endpoint();
				if (endpoint == NULL) {
					TRACE_ERROR("receiver not connected anymore\n");
					continue;
				}

				in_addr remoteHost;
				char hostName[MAXHOSTNAMELEN + 1];
				BNetAddress address(endpoint->RemoteAddr());
				address.GetAddr(remoteHost);
				address.GetAddr(hostName, NULL);
				address.SetTo(remoteHost, port);

				TRACE("connecting to host \"%s\" port %u\n", hostName, port);
				result = fSendEndpoint->Connect(address);
				if (result != B_OK) {
					TRACE_ERROR("failed to connect to host \"%s\" port %u\n",
						hostName, port);
					continue;
				}

				BRect bounds = fOffscreenBitmap->Bounds();
				reply.Start(RP_UPDATE_DISPLAY_MODE);
				reply.Add(bounds.IntegerWidth() + 1);
				reply.Add(bounds.IntegerHeight() + 1);
				if (reply.Flush() == B_OK)
					fIsConnected = true;

				continue;
			}

			case RP_CLOSE_CONNECTION:
			{
				be_app->PostMessage(B_QUIT_REQUESTED);
				continue;
			}

			case RP_CREATE_STATE:
			case RP_DELETE_STATE:
			{
				uint32 token;
				message.Read(token);

				if (code == RP_CREATE_STATE)
					_CreateState(token);
				else
					_DeleteState(token);

				continue;
			}

			case RP_SET_CURSOR:
			{
				BBitmap *bitmap;
				BPoint oldHotSpot = cursorHotSpot;
				message.Read(cursorHotSpot);
				if (message.ReadBitmap(&bitmap) != B_OK)
					continue;

				delete fCursorBitmap;
				fCursorBitmap = bitmap;

				Invalidate(fCursorFrame);

				BRect bounds = fCursorBitmap->Bounds();
				fCursorFrame.right = fCursorFrame.left
					+ bounds.IntegerWidth() + 1;
				fCursorFrame.bottom = fCursorFrame.bottom
					+ bounds.IntegerHeight() + 1;

				fCursorFrame.OffsetBy(oldHotSpot - cursorHotSpot);

				Invalidate(fCursorFrame);
				continue;
			}

			case RP_SET_CURSOR_VISIBLE:
			{
				bool wasVisible = fCursorVisible;
				message.Read(fCursorVisible);
				if (wasVisible != fCursorVisible)
					Invalidate(fCursorFrame);
				continue;
			}

			case RP_MOVE_CURSOR_TO:
			{
				BPoint position;
				message.Read(position);

				if (fCursorVisible)
					Invalidate(fCursorFrame);

				fCursorFrame.OffsetTo(position - cursorHotSpot);

				Invalidate(fCursorFrame);
				continue;
			}

			case RP_INVALIDATE_RECT:
			{
				BRect rect;
				if (message.Read(rect) != B_OK)
					continue;

				Invalidate(rect);
				continue;
			}

			case RP_INVALIDATE_REGION:
			{
				BRegion region;
				if (message.ReadRegion(region) != B_OK)
					continue;

				Invalidate(&region);
				continue;
			}

			case RP_FILL_REGION_COLOR_NO_CLIPPING:
			{
				BRegion region;
				rgb_color color;

				message.ReadRegion(region);
				if (message.Read(color) != B_OK)
					continue;

				fOffscreen->LockLooper();
				fOffscreen->SetHighColor(color);
				fOffscreen->FillRegion(&region);
				fOffscreen->UnlockLooper();
				Invalidate(&region);
				continue;
			}

			case RP_COPY_RECT_NO_CLIPPING:
			{
				int32 xOffset, yOffset;
				BRect rect;

				message.Read(xOffset);
				message.Read(yOffset);
				if (message.Read(rect) != B_OK)
					continue;

				BRect dest = rect.OffsetByCopy(xOffset, yOffset);
				fOffscreen->LockLooper();
				fOffscreen->CopyBits(rect, dest);
				fOffscreen->UnlockLooper();
				continue;
			}
		}

		uint32 token;
		message.Read(token);

		engine_state *state = _FindState(token);
		if (state == NULL) {
			TRACE_ERROR("didn't find state for token %lu\n", token);
			continue;
		}

		BView *offscreen = state->view;
		::pattern &pattern = state->pattern;
		BRegion &clippingRegion = state->clipping_region;
		float &penSize = state->pen_size;
		bool &syncDrawing = state->sync_drawing;
		BRegion invalidRegion;

		BAutolock offscreenLocker(offscreen->Looper());
		if (!offscreenLocker.IsLocked())
			break;

		switch (code) {
			case RP_ENABLE_SYNC_DRAWING:
				syncDrawing = true;
				continue;

			case RP_DISABLE_SYNC_DRAWING:
				syncDrawing = false;
				continue;

			case RP_SET_OFFSETS:
			{
				int32 xOffset, yOffset;
				message.Read(xOffset);
				if (message.Read(yOffset) != B_OK)
					continue;

				offscreen->MovePenTo(xOffset, yOffset);
				break;
			}

			case RP_SET_HIGH_COLOR:
			case RP_SET_LOW_COLOR:
			{
				rgb_color color;
				if (message.Read(color) != B_OK)
					continue;

				if (code == RP_SET_HIGH_COLOR)
					offscreen->SetHighColor(color);
				else
					offscreen->SetLowColor(color);

				break;
			}

			case RP_SET_PEN_SIZE:
			{
				float newPenSize;
				if (message.Read(newPenSize) != B_OK)
					continue;

				offscreen->SetPenSize(newPenSize);
				penSize = newPenSize / 2;
				break;
			}

			case RP_SET_STROKE_MODE:
			{
				cap_mode capMode;
				join_mode joinMode;
				float miterLimit;

				message.Read(capMode);
				message.Read(joinMode);
				if (message.Read(miterLimit) != B_OK)
					continue;

				offscreen->SetLineMode(capMode, joinMode, miterLimit);
				break;
			}

			case RP_SET_BLENDING_MODE:
			{
				source_alpha sourceAlpha;
				alpha_function alphaFunction;

				message.Read(sourceAlpha);
				if (message.Read(alphaFunction) != B_OK)
					continue;

				offscreen->SetBlendingMode(sourceAlpha, alphaFunction);
				break;
			}

			case RP_SET_PATTERN:
			{
				if (message.Read(pattern) != B_OK)
					continue;
				break;
			}

			case RP_SET_DRAWING_MODE:
			{
				drawing_mode drawingMode;
				if (message.Read(drawingMode) != B_OK)
					continue;

				offscreen->SetDrawingMode(drawingMode);
				break;
			}

			case RP_SET_FONT:
			{
				BFont font;
				if (message.ReadFontState(font) != B_OK)
					continue;

				offscreen->SetFont(&font);
				break;
			}

			case RP_CONSTRAIN_CLIPPING_REGION:
			{
				if (message.ReadRegion(clippingRegion) != B_OK)
					continue;

				offscreen->ConstrainClippingRegion(&clippingRegion);
				break;
			}

			case RP_INVERT_RECT:
			{
				BRect rect;
				if (message.Read(rect) != B_OK)
					continue;

				offscreen->InvertRect(rect);
				invalidRegion.Include(rect);
				break;
			}

			case RP_DRAW_BITMAP:
			{
				BBitmap *bitmap;
				BRect bitmapRect, viewRect;
				uint32 options;

				message.Read(bitmapRect);
				message.Read(viewRect);
				message.Read(options);
				if (message.ReadBitmap(&bitmap) != B_OK || bitmap == NULL)
					continue;

				offscreen->DrawBitmap(bitmap, bitmapRect, viewRect, options);
				invalidRegion.Include(viewRect);
				delete bitmap;
				break;
			}

			case RP_DRAW_BITMAP_RECTS:
			{
				color_space colorSpace;
				int32 rectCount;
				uint32 flags, options;

				message.Read(options);
				message.Read(colorSpace);
				message.Read(flags);
				message.Read(rectCount);
				for (int32 i = 0; i < rectCount; i++) {
					BBitmap *bitmap;
					BRect viewRect;

					message.Read(viewRect);
					if (message.ReadBitmap(&bitmap, true, colorSpace,
							flags) != B_OK || bitmap == NULL) {
						continue;
					}

					offscreen->DrawBitmap(bitmap, bitmap->Bounds(), viewRect,
						options);
					invalidRegion.Include(viewRect);
					delete bitmap;
				}

				break;
			}

			case RP_STROKE_ARC:
			case RP_FILL_ARC:
			case RP_FILL_ARC_GRADIENT:
			{
				BRect rect;
				float angle, span;

				message.Read(rect);
				message.Read(angle);
				if (message.Read(span) != B_OK)
					continue;

				if (code == RP_STROKE_ARC) {
					offscreen->StrokeArc(rect, angle, span, pattern);
					rect.InsetBy(-penSize, -penSize);
				} else if (code == RP_FILL_ARC)
					offscreen->FillArc(rect, angle, span, pattern);
				else {
					BGradient *gradient;
					if (message.ReadGradient(&gradient) != B_OK)
						continue;

					offscreen->FillArc(rect, angle, span, *gradient);
					delete gradient;
				}

				invalidRegion.Include(rect);
				break;
			}

			case RP_STROKE_BEZIER:
			case RP_FILL_BEZIER:
			case RP_FILL_BEZIER_GRADIENT:
			{
				BPoint points[4];
				if (message.ReadList(points, 4) != B_OK)
					continue;

				BRect bounds = _BuildInvalidateRect(points, 4);
				if (code == RP_STROKE_BEZIER) {
					offscreen->StrokeBezier(points, pattern);
					bounds.InsetBy(-penSize, -penSize);
				} else if (code == RP_FILL_BEZIER)
					offscreen->FillBezier(points, pattern);
				else {
					BGradient *gradient;
					if (message.ReadGradient(&gradient) != B_OK)
						continue;

					offscreen->FillBezier(points, *gradient);
					delete gradient;
				}

				invalidRegion.Include(bounds);
				break;
			}

			case RP_STROKE_ELLIPSE:
			case RP_FILL_ELLIPSE:
			case RP_FILL_ELLIPSE_GRADIENT:
			{
				BRect rect;
				if (message.Read(rect) != B_OK)
					continue;

				if (code == RP_STROKE_ELLIPSE) {
					offscreen->StrokeEllipse(rect, pattern);
					rect.InsetBy(-penSize, -penSize);
				} else if (code == RP_FILL_ELLIPSE)
					offscreen->FillEllipse(rect, pattern);
				else {
					BGradient *gradient;
					if (message.ReadGradient(&gradient) != B_OK)
						continue;

					offscreen->FillEllipse(rect, *gradient);
					delete gradient;
				}

				invalidRegion.Include(rect);
				break;
			}

			case RP_STROKE_POLYGON:
			case RP_FILL_POLYGON:
			case RP_FILL_POLYGON_GRADIENT:
			{
				BRect bounds;
				bool closed;
				int32 numPoints;

				message.Read(bounds);
				message.Read(closed);
				if (message.Read(numPoints) != B_OK)
					continue;

				BPoint points[numPoints];
				for (int32 i = 0; i < numPoints; i++)
					message.Read(points[i]);

				if (code == RP_STROKE_POLYGON) {
					offscreen->StrokePolygon(points, numPoints, bounds, closed,
						pattern);
					bounds.InsetBy(-penSize, -penSize);
				} else if (code == RP_FILL_POLYGON)
					offscreen->FillPolygon(points, numPoints, bounds, pattern);
				else {
					BGradient *gradient;
					if (message.ReadGradient(&gradient) != B_OK)
						continue;

					offscreen->FillPolygon(points, numPoints, bounds,
						*gradient);
					delete gradient;
				}

				invalidRegion.Include(bounds);
				break;
			}

			case RP_STROKE_RECT:
			case RP_FILL_RECT:
			case RP_FILL_RECT_GRADIENT:
			{
				BRect rect;
				if (message.Read(rect) != B_OK)
					continue;

				if (code == RP_STROKE_RECT) {
					offscreen->StrokeRect(rect, pattern);
					rect.InsetBy(-penSize, -penSize);
				} else if (code == RP_FILL_RECT)
					offscreen->FillRect(rect, pattern);
				else {
					BGradient *gradient;
					if (message.ReadGradient(&gradient) != B_OK)
						continue;

					offscreen->FillRect(rect, *gradient);
					delete gradient;
				}

				invalidRegion.Include(rect);
				break;
			}

			case RP_STROKE_ROUND_RECT:
			case RP_FILL_ROUND_RECT:
			case RP_FILL_ROUND_RECT_GRADIENT:
			{
				BRect rect;
				float xRadius, yRadius;

				message.Read(rect);
				message.Read(xRadius);
				if (message.Read(yRadius) != B_OK)
					continue;

				if (code == RP_STROKE_ROUND_RECT) {
					offscreen->StrokeRoundRect(rect, xRadius, yRadius,
						pattern);
					rect.InsetBy(-penSize, -penSize);
				} else if (code == RP_FILL_ROUND_RECT)
					offscreen->FillRoundRect(rect, xRadius, yRadius, pattern);
				else {
					BGradient *gradient;
					if (message.ReadGradient(&gradient) != B_OK)
						continue;

					offscreen->FillRoundRect(rect, xRadius, yRadius,
						*gradient);
					delete gradient;
				}

				invalidRegion.Include(rect);
				break;
			}

			case RP_STROKE_SHAPE:
			case RP_FILL_SHAPE:
			case RP_FILL_SHAPE_GRADIENT:
			{
				BRect bounds;
				int32 opCount, pointCount;

				message.Read(bounds);
				if (message.Read(opCount) != B_OK)
					continue;

				BMessage archive;
				for (int32 i = 0; i < opCount; i++) {
					int32 op;
					message.Read(op);
					archive.AddInt32("ops", op);
				}

				if (message.Read(pointCount) != B_OK)
					continue;

				for (int32 i = 0; i < pointCount; i++) {
					BPoint point;
					message.Read(point);
					archive.AddPoint("pts", point);
				}

				BPoint offset;
				message.Read(offset);

				float scale;
				if (message.Read(scale) != B_OK)
					continue;

				offscreen->PushState();
				offscreen->MovePenTo(offset);
				offscreen->SetScale(scale);

				BShape shape(&archive);
				if (code == RP_STROKE_SHAPE) {
					offscreen->StrokeShape(&shape, pattern);
					bounds.InsetBy(-penSize, -penSize);
				} else if (code == RP_FILL_SHAPE)
					offscreen->FillShape(&shape, pattern);
				else {
					BGradient *gradient;
					if (message.ReadGradient(&gradient) != B_OK) {
						offscreen->PopState();
						continue;
					}

					offscreen->FillShape(&shape, *gradient);
					delete gradient;
				}

				offscreen->PopState();
				invalidRegion.Include(bounds);
				break;
			}

			case RP_STROKE_TRIANGLE:
			case RP_FILL_TRIANGLE:
			case RP_FILL_TRIANGLE_GRADIENT:
			{
				BRect bounds;
				BPoint points[3];

				message.ReadList(points, 3);
				if (message.Read(bounds) != B_OK)
					continue;

				if (code == RP_STROKE_TRIANGLE) {
					offscreen->StrokeTriangle(points[0], points[1], points[2],
						bounds, pattern);
					bounds.InsetBy(-penSize, -penSize);
				} else if (code == RP_FILL_TRIANGLE) {
					offscreen->FillTriangle(points[0], points[1], points[2],
						bounds, pattern);
				} else {
					BGradient *gradient;
					if (message.ReadGradient(&gradient) != B_OK)
						continue;

					offscreen->FillTriangle(points[0], points[1], points[2],
						bounds, *gradient);
					delete gradient;
				}

				invalidRegion.Include(bounds);
				break;
			}

			case RP_STROKE_LINE:
			{
				BPoint points[2];
				if (message.ReadList(points, 2) != B_OK)
					continue;

				offscreen->StrokeLine(points[0], points[1], pattern);

				BRect bounds = _BuildInvalidateRect(points, 2);
				invalidRegion.Include(bounds.InsetBySelf(-penSize, -penSize));
				break;
			}

			case RP_STROKE_LINE_ARRAY:
			{
				int32 numLines;
				if (message.Read(numLines) != B_OK)
					continue;

				BRect bounds;
				offscreen->BeginLineArray(numLines);
				for (int32 i = 0; i < numLines; i++) {
					rgb_color color;
					BPoint start, end;
					message.ReadArrayLine(start, end, color);
					offscreen->AddLine(start, end, color);

					bounds.left = min_c(bounds.left, min_c(start.x, end.x));
					bounds.top = min_c(bounds.top, min_c(start.y, end.y));
					bounds.right = max_c(bounds.right, max_c(start.x, end.x));
					bounds.bottom = max_c(bounds.bottom, max_c(start.y, end.y));
				}

				offscreen->EndLineArray();
				invalidRegion.Include(bounds);
				break;
			}

			case RP_FILL_REGION:
			case RP_FILL_REGION_GRADIENT:
			{
				BRegion region;
				if (message.ReadRegion(region) != B_OK)
					continue;

				if (code == RP_FILL_REGION)
					offscreen->FillRegion(&region, pattern);
				else {
					BGradient *gradient;
					if (message.ReadGradient(&gradient) != B_OK)
						continue;

					offscreen->FillRegion(&region, *gradient);
					delete gradient;
				}

				invalidRegion.Include(&region);
				break;
			}

			case RP_STROKE_POINT_COLOR:
			{
				BPoint point;
				rgb_color color;

				message.Read(point);
				if (message.Read(color) != B_OK)
					continue;

				rgb_color oldColor = offscreen->HighColor();
				offscreen->SetHighColor(color);
				offscreen->StrokeLine(point, point);
				offscreen->SetHighColor(oldColor);

				invalidRegion.Include(
					BRect(point, point).InsetBySelf(-penSize, -penSize));
				break;
			}

			case RP_STROKE_LINE_1PX_COLOR:
			{
				BPoint points[2];
				rgb_color color;

				message.ReadList(points, 2);
				if (message.Read(color) != B_OK)
					continue;

				float oldSize = offscreen->PenSize();
				rgb_color oldColor = offscreen->HighColor();
				drawing_mode oldMode = offscreen->DrawingMode();
				offscreen->SetPenSize(1);
				offscreen->SetHighColor(color);
				offscreen->SetDrawingMode(B_OP_OVER);

				offscreen->StrokeLine(points[0], points[1]);

				offscreen->SetDrawingMode(oldMode);
				offscreen->SetHighColor(oldColor);
				offscreen->SetPenSize(oldSize);

				invalidRegion.Include(_BuildInvalidateRect(points, 2));
				break;
			}

			case RP_STROKE_RECT_1PX_COLOR:
			case RP_FILL_RECT_COLOR:
			{
				BRect rect;
				rgb_color color;

				message.Read(rect);
				if (message.Read(color) != B_OK)
					continue;

				rgb_color oldColor = offscreen->HighColor();
				offscreen->SetHighColor(color);

				if (code == RP_STROKE_RECT_1PX_COLOR) {
					float oldSize = PenSize();
					offscreen->SetPenSize(1);
					offscreen->StrokeRect(rect);
					offscreen->SetPenSize(oldSize);
				} else
					offscreen->FillRect(rect);

				offscreen->SetHighColor(oldColor);
				invalidRegion.Include(rect);
				break;
			}

			case RP_DRAW_STRING:
			{
				BPoint point;
				size_t length;
				char *string;
				bool hasDelta;

				message.Read(point);
				message.ReadString(&string, length);
				if (message.Read(hasDelta) != B_OK) {
					free(string);
					continue;
				}

				if (hasDelta) {
					escapement_delta delta[length];
					message.ReadList(delta, length);
					offscreen->DrawString(string, point, delta);
				} else
					offscreen->DrawString(string, point);

				free(string);
				reply.Start(RP_DRAW_STRING_RESULT);
				reply.Add(token);
				reply.Add(offscreen->PenLocation());
				reply.Flush();

				font_height height;
				offscreen->GetFontHeight(&height);

				BRect bounds(point, offscreen->PenLocation());
				bounds.top -= height.ascent;
				bounds.bottom += height.descent;
				invalidRegion.Include(bounds);
				break;
			}

			case RP_DRAW_STRING_WITH_OFFSETS:
			{
				size_t length;
				char *string;
				message.ReadString(&string, length);
				int32 count = UTF8CountChars(string, length);

				BPoint offsets[count];
				if (message.ReadList(offsets, count) != B_OK) {
					free(string);
					continue;
				}

				offscreen->DrawString(string, offsets, count);

				free(string);
				reply.Start(RP_DRAW_STRING_RESULT);
				reply.Add(token);
				reply.Add(offscreen->PenLocation());
				reply.Flush();

				BFont font;
				offscreen->GetFont(&font);

				BRect boxes[count];
				font.GetBoundingBoxesAsGlyphs(string, count, B_SCREEN_METRIC,
					boxes);

				font_height height;
				offscreen->GetFontHeight(&height);

				for (int32 i = 0; i < count; i++) {
					// TODO: validate
					boxes[i].OffsetBy(offsets[i] + BPoint(0, -height.ascent));
					invalidRegion.Include(boxes[i]);
				}

				break;
			}

			case RP_READ_BITMAP:
			{
				BRect bounds;
				bool drawCursor;

				message.Read(bounds);
				if (message.Read(drawCursor) != B_OK)
					continue;

				// TODO: support the drawCursor flag
				BBitmap bitmap(bounds, B_BITMAP_NO_SERVER_LINK, B_RGB32);
				bitmap.ImportBits(fOffscreenBitmap, bounds.LeftTop(),
					BPoint(0, 0), bounds.IntegerWidth() + 1,
					bounds.IntegerHeight() + 1);

				reply.Start(RP_READ_BITMAP_RESULT);
				reply.Add(token);
				reply.AddBitmap(&bitmap);
				reply.Flush();
				break;
			}

			default:
				TRACE_ERROR("unknown protocol code: %u\n", code);
				break;
		}

		if (syncDrawing) {
			offscreen->Sync();
			Invalidate(&invalidRegion);
		}
	}
}
Пример #29
0
void 
BTitleView::Draw(BRect /*updateRect*/, bool useOffscreen, bool updateOnly,
	const BColumnTitle *pressedColumn,
	void (*trackRectBlitter)(BView *, BRect), BRect passThru)
{
	BRect bounds(Bounds());
	BView *view;

	if (useOffscreen) {
		ASSERT(sOffscreen);
		BRect frame(bounds);
		frame.right += frame.left;
			// this is kind of messy way of avoiding being clipped by the ammount the
			// title is scrolled to the left
			// ToDo: fix this
		view = sOffscreen->BeginUsing(frame);
		view->SetOrigin(-bounds.left, 0);
		view->SetLowColor(LowColor());
		view->SetHighColor(HighColor());
		BFont font(be_plain_font);
		font.SetSize(9);
		view->SetFont(&font);
	} else
		view = this;

	if (be_control_look != NULL) {
		rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
		view->SetHighColor(tint_color(base, B_DARKEN_2_TINT));
		view->StrokeLine(bounds.LeftBottom(), bounds.RightBottom());
		bounds.bottom--;

		be_control_look->DrawButtonBackground(view, bounds, bounds, base, 0,
			BControlLook::B_TOP_BORDER | BControlLook::B_BOTTOM_BORDER);
	} else {
		// fill background with light gray background
		if (!updateOnly)
			view->FillRect(bounds, B_SOLID_LOW);
	
		view->BeginLineArray(4);
		view->AddLine(bounds.LeftTop(), bounds.RightTop(), sShadowColor);
		view->AddLine(bounds.LeftBottom(), bounds.RightBottom(), sShadowColor);
		// draw lighter gray and white inset lines
		bounds.InsetBy(0, 1);
		view->AddLine(bounds.LeftBottom(), bounds.RightBottom(), sLightShadowColor);
		view->AddLine(bounds.LeftTop(), bounds.RightTop(), sShineColor);
		view->EndLineArray();
	}

	int32 count = fTitleList.CountItems();
	float minx = bounds.right;
	float maxx = bounds.left;
	for (int32 index = 0; index < count; index++) {
		BColumnTitle *title = fTitleList.ItemAt(index);
		title->Draw(view, title == pressedColumn);
		BRect titleBounds(title->Bounds());
		if (titleBounds.left < minx)
			minx = titleBounds.left;
		if (titleBounds.right > maxx)
			maxx = titleBounds.right;
	}

	if (be_control_look != NULL) {
		bounds = Bounds();
		minx--;
		view->SetHighColor(sLightShadowColor);
		view->StrokeLine(BPoint(minx, bounds.top), BPoint(minx, bounds.bottom - 1));
	} else {
		// first and last shades before and after first column
		maxx++;
		minx--;
		view->BeginLineArray(2);
		view->AddLine(BPoint(minx, bounds.top),
					  BPoint(minx, bounds.bottom), sShadowColor);
		view->AddLine(BPoint(maxx, bounds.top),
					  BPoint(maxx, bounds.bottom), sShineColor);
		view->EndLineArray();
	}

#if !(APP_SERVER_CLEARS_BACKGROUND)
	FillRect(BRect(bounds.left, bounds.top + 1, minx - 1, bounds.bottom - 1), B_SOLID_LOW);
	FillRect(BRect(maxx + 1, bounds.top + 1, bounds.right, bounds.bottom - 1), B_SOLID_LOW);
#endif

	if (useOffscreen) {
		if (trackRectBlitter)
			(trackRectBlitter)(view, passThru);
		view->Sync();
		DrawBitmap(sOffscreen->Bitmap());
		sOffscreen->DoneUsing();
	} else if (trackRectBlitter)
		(trackRectBlitter)(view, passThru);
}
Пример #30
0
int32
ColorField::_UpdateThread(void *data)
{
	// initialization

	ColorField *colorField = (ColorField *)data;
	BLooper *looper = colorField->Looper();

	if (looper)
		looper->Lock();

	BBitmap* bitmap = colorField->fBgBitmap[0];
	BView* view = colorField->fBgView[0];

	port_id port = colorField->fUpdatePort;

	if (looper)
		looper->Unlock();

	// draw

	float h, s, v, r, g, b;
	int R, G, B;

	int32 msg_code;
	char msg_buffer;

	while (true) {
		port_info info;
		do {
			read_port(port, &msg_code, &msg_buffer, sizeof(msg_buffer));
			get_port_info(port, &info);
		} while (info.queue_count);

		if (looper)
			looper->Lock();
	
		uint colormode = colorField->fColorMode;
		float fixedvalue = colorField->fFixedValue;

		if (looper)
			looper->Unlock();

		bitmap->Lock();
		view->BeginLineArray(256 * 256);

		switch (colormode)
		{
			case R_SELECTED:
			{
				R = round(fixedvalue * 255);
				for (int G = 0; G < 256; ++G)
					for (int B = 0; B < 256; ++B)
						DrawColorPoint(BPoint(G, 255.0 - B), R, G, B);
				break;
			}

			case G_SELECTED:
			{
				G = round(fixedvalue * 255);
				for (int R = 0; R < 256; ++R)
					for (int B = 0; B < 256; ++B)
						DrawColorPoint(BPoint(R, 255.0 - B), R, G, B);
				break;
			}

			case B_SELECTED:
			{
				B = round(fixedvalue * 255);
				for (int R = 0; R < 256; ++R)
					for (int G = 0; G < 256; ++G)
						DrawColorPoint(BPoint(R, 255.0 - G), R, G, B);
				break;
			}

			case H_SELECTED:
			{
				h = fixedvalue;
				for (int x = 0; x < 256; ++x) {
					s = (float)x / 255.0;
					for (int y = 0; y < 256; ++y) {
						v = (float)y / 255.0;
						HSV_to_RGB(h, s, v, r, g, b);
						DrawColorPoint(BPoint(x, 255.0 - y), round(r * 255.0),
							round(g * 255.0), round(b * 255.0));
					}
				}
				break;
			}

			case S_SELECTED:
			{
				s = fixedvalue;
				for (int x = 0; x < 256; ++x) {
					h = 6.0 / 255 * x;
					for (int y = 0; y<256; ++y) {
						v = (float)y / 255.0;
						HSV_to_RGB(h, s, v, r, g, b);
						DrawColorPoint(BPoint(x, 255.0 - y), round(r * 255.0),
							round(g * 255.0), round(b * 255.0));
					}
				}
				break;
			}

			case V_SELECTED:
			{
				v = fixedvalue;
				for (int x = 0; x < 256; ++x) {
					h = 6.0 / 255 * x;
					for (int y = 0; y < 256; ++y) {
						s = (float)y / 255.0;
						HSV_to_RGB(h, s, v, r, g, b);
						DrawColorPoint(BPoint(x, 255.0 - y), round(r * 255.0),
							round(g * 255.0), round(b * 255.0));
					}
				}
				break;
			}
		}

		view->EndLineArray();
		view->Sync();

		bitmap->Unlock();

		looper = colorField->Looper();
		if (looper && looper->Lock()) {
			colorField->Update(2);
			looper->Unlock();
		}
	}

	return 0;
}