//------------------------------------------------------------------------
 bool platform_support::create_img(unsigned idx, unsigned width, unsigned height)
 {
     if(idx < max_images)
     {
         if(width  == 0) width  = m_specific->fApp->Window()->View()->Bitmap()->Bounds().IntegerWidth() + 1;
         if(height == 0) height = m_specific->fApp->Window()->View()->Bitmap()->Bounds().IntegerHeight() + 1;
         BBitmap* bitmap = new BBitmap(BRect(0.0, 0.0, width - 1, height - 1), 0, B_RGBA32);;
         if (bitmap && bitmap->IsValid()) {
             delete m_specific->fImages[idx];
             m_specific->fImages[idx] = bitmap;
             attach_buffer_to_BBitmap(m_rbuf_img[idx], bitmap, m_flip_y);
             return true;
         } else {
             delete bitmap;
         }
     }
     return false;
 }
Example #2
0
void
AppMenuItem::DrawContent()
{
	Menu()->SetDrawingMode(B_OP_OVER);
	Menu()->MovePenBy(0.0, -1.0);
	Menu()->DrawBitmap(fIcon);
	Menu()->MovePenBy(fIcon->Bounds().Width() + kSmallHMargin, 0.0);
	BMenuItem::DrawContent();
}
Example #3
0
void
PictureView::Draw(BRect updateRect)
{
	BRect rect = Bounds();

	// Draw the outer frame
	rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
	if (IsFocus() && Window() && Window()->IsActive())
		SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR));
	else
		SetHighColor(tint_color(base, B_DARKEN_3_TINT));
	StrokeRect(rect);

	if (fFocusChanging) {
		// focus frame is already redraw, stop here
		return;
	}

	BBitmap* picture = fPicture ? fPicture : fDefaultPicture;
	if (picture != NULL) {
		// scale to fit and center picture in frame
		BRect frame = rect.InsetByCopy(kPictureMargin, kPictureMargin);
		BRect srcRect = picture->Bounds();
		BSize size = frame.Size();
		if (srcRect.Width() > srcRect.Height())
			size.height = srcRect.Height() * size.width / srcRect.Width();
		else
			size.width = srcRect.Width() * size.height / srcRect.Height();

		fPictureRect = BLayoutUtils::AlignInFrame(frame, size,
			BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER));

		SetDrawingMode(B_OP_ALPHA);
		if (picture == fDefaultPicture) {
			SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_OVERLAY);
			SetHighColor(0, 0, 0, 24);
		}

 		DrawBitmapAsync(picture, srcRect, fPictureRect,
 			B_FILTER_BITMAP_BILINEAR);

		SetDrawingMode(B_OP_OVER);
	}
}
Example #4
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);
}
Example #5
0
BBitmap*
SharedBitmap::_LoadIconFromBuffer(const void* data, size_t dataSize,
	int32 size) const
{
	BBitmap* bitmap = new BBitmap(BRect(0, 0, size - 1, size - 1), 0,
		B_RGBA32);
	status_t status = bitmap->InitCheck();
	if (status == B_OK) {
		status = BIconUtils::GetVectorIcon(
			reinterpret_cast<const uint8*>(data), dataSize, bitmap);
	};

	if (status != B_OK) {
		delete bitmap;
		bitmap = NULL;
	}

	return bitmap;
}
/*=============================================================================================*\
|	FetchBitmap																					|
+-----------------------------------------------------------------------------------------------+
|	Effet: Converie une image en un BBitmap. La couleur de transparence est celle du pixel dans	|
|			le coin superieur gauche.															|
|	Entree:																						|
|		char *pzFileName: Le path du fichier image a convertir.									|
|		bool bTran: True si on utilise la transparence, false sinon.							|
|	Sortie:																						|
|		BBitmap *: Le pointeur le bitmap de l'image. NULL si la conversion a echouer.			|
\*=============================================================================================*/
BBitmap * BeNetBitmapCatalog::FetchBitmap(char *pzFileName, bool bTrans) 
{ 
      BFile file(pzFileName, B_READ_ONLY); 
      BTranslatorRoster *roster = BTranslatorRoster::Default(); 
      BBitmapStream stream; 
      BBitmap *result = NULL; 
      if (roster->Translate(&file, NULL, NULL, &stream, 
            B_TRANSLATOR_BITMAP) < B_OK) 
         return NULL; 
      stream.DetachBitmap(&result); 
            
      
      if(!bTrans) return result;
      int32 iLenght = result->BitsLength() / 4;
      int32 i;
      int32 * cBit = (int32)result->Bits();
      int32 backColor = cBit[result->Bounds().IntegerWidth() - 1];
      int32 iTrans = 0;
      
      //Determine le mode de definition de couleur
      switch(result->ColorSpace())
      {
      		case B_RGB32:{
      				iTrans = B_TRANSPARENT_MAGIC_RGBA32;
      			}break;
      		case B_RGB32_BIG:{
      				iTrans = B_TRANSPARENT_MAGIC_RGBA32_BIG;
      			}break;
       }
      
      if(iTrans)
      {
     	for(i = 0; i < iLenght; i++)
      	{
      		if(cBit[i] == backColor)
      		{
     			cBit[i] = B_TRANSPARENT_MAGIC_RGBA32_BIG;
      		}
      	}
      }
      
      return result; 
}//Fin de FetchBitmap.
void
PreviewView::UpdateBitmap()
{
	if (Window() == NULL)
		printf("window is null\n");
	if (fChanged && Window() != NULL) {
		BBitmap *bitmap;
		fChanged = false;
		BScreen screen(Window());
		screen.GetBitmap(&bitmap, false, &fCoordRect);		
	
		if (bitmap != NULL) {
			fBitmapView->SetViewBitmap(bitmap, bitmap->Bounds(),
				fBitmapView->Bounds(),
				B_FOLLOW_TOP|B_FOLLOW_LEFT, 0);
			Invalidate();
		}
	}
}
void
MesaSoftwareRenderer::_ClearFront(gl_context* ctx)
{
	CALLED();

	MesaSoftwareRenderer* mr = (MesaSoftwareRenderer*)ctx->DriverCtx;
	BGLView* bglview = mr->GLView();
	assert(bglview);
	BBitmap* bitmap = mr->fBitmap;
	assert(bitmap);
	GLuint* start = (GLuint*)bitmap->Bits();
	size_t pixelSize = 0;
	get_pixel_size_for(bitmap->ColorSpace(), &pixelSize, NULL, NULL);
	const GLuint* clearPixelPtr = (const GLuint*)mr->fClearColor;
	const GLuint clearPixel = B_LENDIAN_TO_HOST_INT32(*clearPixelPtr);

	int x = ctx->DrawBuffer->_Xmin;
	int y = ctx->DrawBuffer->_Ymin;
	uint32 width = ctx->DrawBuffer->_Xmax - x;
	uint32 height = ctx->DrawBuffer->_Ymax - y;
	GLboolean all = (width == ctx->DrawBuffer->Width
		&& height == ctx->DrawBuffer->Height);

	if (all) {
		const int numPixels = mr->fWidth * mr->fHeight;
		if (clearPixel == 0) {
			memset(start, 0, numPixels * pixelSize);
		} else {
			for (int i = 0; i < numPixels; i++) {
				start[i] = clearPixel;
			}
		}
	} else {
		// XXX untested
		start += y * mr->fWidth + x;
		for (uint32 i = 0; i < height; i++) {
			for (uint32 j = 0; j < width; j++) {
				start[j] = clearPixel;
			}
			start += mr->fWidth;
		}
	}
}
Example #9
0
void
BitmapView::ConstrainBitmap(void)
{
	if (!fBitmap || fMaxWidth < 1 || fMaxHeight < 1)
		return;
	
	BRect r = ScaleRectToFit(fBitmap->Bounds(), BRect(0, 0, fMaxWidth - 1, fMaxHeight - 1));
	r.OffsetTo(0, 0);
	
	BBitmap *scaled = new BBitmap(r, fBitmap->ColorSpace(), true);
	BView *view = new BView(r, "drawview", 0, 0);
	
	scaled->Lock();
	scaled->AddChild(view);
	view->DrawBitmap(fBitmap, fBitmap->Bounds(), scaled->Bounds());
	scaled->Unlock();
	
	delete fBitmap;
	fBitmap = new BBitmap(scaled, false);
}
Example #10
0
BBitmap*
SharedBitmap::_CreateBitmapFromMimeType(int32 size) const
{
	BMimeType mimeType(fMimeType.String());
	status_t status = mimeType.InitCheck();
	if (status != B_OK)
		return NULL;

	BBitmap* bitmap = new BBitmap(BRect(0, 0, size - 1, size - 1), 0, B_RGBA32);
	status = bitmap->InitCheck();
	if (status == B_OK)
		status = mimeType.GetIcon(bitmap, B_MINI_ICON);

	if (status != B_OK) {
		delete bitmap;
		bitmap = NULL;
	}

	return bitmap;
}
Example #11
0
void
BIconButton::Draw(BRect updateRect)
{
	rgb_color background;
	if (fCustomBackground)
		background = {120,120,120};
	else
		background = LowColor();

	BRect r(Bounds());

	uint32 flags = 0;
	BBitmap* bitmap = fNormalBitmap;
	if (!IsEnabled()) {
		flags |= BControlLook::B_DISABLED;
		bitmap = fDisabledBitmap;
	}
	if (_HasFlags(STATE_PRESSED) || _HasFlags(STATE_FORCE_PRESSED))
		flags |= BControlLook::B_ACTIVATED;

	if (ShouldDrawBorder()) {
		DrawBorder(r, updateRect, background, flags);
		DrawBackground(r, updateRect, background, flags);
	} else {
		SetHighColor(background);
		FillRect(r);
	}

	if (bitmap && bitmap->IsValid()) {
		if (bitmap->ColorSpace() == B_RGBA32
			|| bitmap->ColorSpace() == B_RGBA32_BIG) {
			SetDrawingMode(B_OP_ALPHA);
			SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
		}
		float x = r.left + floorf((r.Width()
			- bitmap->Bounds().Width()) / 2.0 + 0.5);
		float y = r.top + floorf((r.Height()
			- bitmap->Bounds().Height()) / 2.0 + 0.5);
		DrawBitmap(bitmap, BPoint(x, y));
	}
}
Example #12
0
void ContactItem::DrawItem(BView *owner, BRect itemRect, bool drawEverything)
{
	BString name = m_contact->FriendlyName();
	Status *status = m_contact->GetStatus();
	//draw status icon
	BBitmap *statusBitmap = status->GetStatusIcon();
	
	owner->SetDrawingMode(B_OP_OVER);
	float bitmapWidth = (statusBitmap->Bounds()).Width();
	BRect fillRect = itemRect;
	itemRect.left += bitmapWidth;

	//if selected
	if(IsSelected())
		owner->SetHighColor(ui_color(B_MENU_SELECTION_BACKGROUND_COLOR));
	else
		owner->SetHighColor(255,255,255);	
	owner->FillRect(fillRect);
	
	owner->SetDrawingMode(B_OP_ALPHA);
	if (statusBitmap)
		owner->DrawBitmap(statusBitmap, itemRect.LeftTop() + BPoint(0.0f,1.0f));
	
	//draw name(with emoticons)
	float textHeight = 12.0f;			
	BFont normal;
	owner->SetFont(&normal);
	owner->SetHighColor(0,0,0);
	owner->SetDrawingMode(B_OP_ALPHA);
	owner->DrawString(name.String(), itemRect.LeftTop() + BPoint(bitmapWidth + 5.0f, 1.0f + textHeight));
	//draw personal message, if available
	if (m_contact->HasPersonalMessage())
	{
		owner->DrawString(" - ");
		BFont italic;
		italic.SetFace(B_ITALIC_FACE); 
		owner->SetFont(&italic);	
		BString personalMessage = m_contact->PersonalMessage();
		owner->DrawString(personalMessage.String());
	}
}
Example #13
0
void
ShowImageWindow::_ResizeWindowToImage()
{
	BBitmap* bitmap = fImageView->Bitmap();
	BScreen screen;
	if (bitmap == NULL || !screen.IsValid())
		return;

	// TODO: use View::GetPreferredSize() instead?
	BRect r(bitmap->Bounds());
	float width = r.Width() + B_V_SCROLL_BAR_WIDTH;
	float height = r.Height() + 1 + fBar->Frame().Height()
		+ B_H_SCROLL_BAR_HEIGHT;

	BRect frame = screen.Frame();
	const float windowBorder = 5;
	// dimensions so that window does not reach outside of screen
	float maxWidth = frame.Width() + 1 - windowBorder - Frame().left;
	float maxHeight = frame.Height() + 1 - windowBorder - Frame().top;

	// We have to check size limits manually, otherwise
	// menu bar will be too short for small images.

	float minW, maxW, minH, maxH;
	GetSizeLimits(&minW, &maxW, &minH, &maxH);
	if (maxWidth > maxW)
		maxWidth = maxW;
	if (maxHeight > maxH)
		maxHeight = maxH;
	if (width < minW)
		width = minW;
	if (height < minH)
		height = minH;

	if (width > maxWidth)
		width = maxWidth;
	if (height > maxHeight)
		height = maxHeight;

	ResizeTo(width, height);
}
void CounterView::FrameResized (float width, float height)
{
  BRect BitmapRect (0, 0, width, height);
  char  TempString [40];

  m_BndRect = Bounds ();

  m_MovingDotSize = (int) (height / 20);
  if (m_MovingDotSize < 1)
    m_MovingDotSize = 1;
  m_MoveSpeed = m_MovingDotSize / 2.0;
  
  // Resize the offscreen bitmap and its view.

  if (m_BackingBitmap != NULL)
  {
    m_BackingBitmap->RemoveChild (&m_BackingView);
    delete m_BackingBitmap;
    m_BackingBitmap = NULL;
  }

  m_BackingView.ResizeTo (width, height);

  m_BackingBitmap = new BBitmap (BitmapRect, B_RGBA32, true /* Accepts subviews */);
  if (!m_BackingBitmap->IsValid ())
  {
    delete m_BackingBitmap;
    m_BackingBitmap = NULL;
  }
  else
  {
    m_BackingBitmap->AddChild (&m_BackingView);
    m_BackingBitmap->Lock ();
    m_BackingView.SetDrawingMode (B_OP_ALPHA);
    m_BackingView.SetFontSize (height * 0.8);
    sprintf (TempString, "%d", m_CurrentCount);
    m_TextStartPoint.x = width / 2 - m_BackingView.StringWidth (TempString) / 2;
    m_TextStartPoint.y = height / 2 + height * 0.25;
    m_BackingBitmap->Unlock ();
  }
}
Example #15
0
BBitmap *GetCicnFromResource(const char *theResource)
{	
	// Get application info
	app_info info;
	
	be_app->GetAppInfo(&info);
	BFile file(&info.ref, O_RDONLY);	
	if (file.InitCheck())
		return NULL;
	
	size_t 		size;
	cicn 		*icon;
	
	BResources res; 
	status_t err; 
	if ( (err = res.SetTo(&file)) != B_NO_ERROR ) 
		return NULL;
		
	icon = (cicn *)res.FindResource('cicn', theResource, &size);
	if (!icon)			
		return NULL;
			
	// 	Swap bytes if needed.  We do this because the resources are currently
	// 	built on Macintosh BeOS
	if (B_HOST_IS_LENDIAN)
	{
		status_t retVal;
		retVal = swap_data(B_INT16_TYPE, &icon->width, sizeof(int16), B_SWAP_BENDIAN_TO_HOST);		
		retVal = swap_data(B_INT16_TYPE, &icon->height, sizeof(int16), B_SWAP_BENDIAN_TO_HOST);
	}
	
	// Get cicn bounding rect
	BRect bounds(0, 0, icon->width-1, icon->height-1);
		
	// Load bitmap
	BBitmap *bitmap = new BBitmap(bounds, B_COLOR_8_BIT);
	ASSERT(bitmap);
	bitmap->SetBits(&icon->data, size - sizeof(int16)*2, 0, B_COLOR_8_BIT);
	
	return (bitmap);	
}
Example #16
0
void
AGGView::FrameResized(float width, float height)
{
    BRect r(0.0, 0.0, width, height);
    BBitmap* bitmap = new BBitmap(r, 0, pix_format_to_color_space(fFormat));
    if (bitmap->IsValid()) {
        delete fBitmap;
        fBitmap = bitmap;
           attach_buffer_to_BBitmap(fAGG->rbuf_window(), fBitmap, fFlipY);

        fAGG->trans_affine_resizing((int)width + 1,
                                    (int)height + 1);

        // pass the event on to AGG
        fAGG->on_resize((int)width + 1, (int)height + 1);
        
        fRedraw = true;
        Invalidate();
    } else
        delete bitmap;
}
Example #17
0
BBitmap*
PictureView::_CopyPicture(uint8 alpha)
{
	bool hasAlpha = alpha != 255;

	if (!fPicture)
		return NULL;

	BRect rect = fPictureRect.OffsetToCopy(B_ORIGIN);
	BView view(rect, NULL, B_FOLLOW_NONE, B_WILL_DRAW);
	BBitmap* bitmap = new(nothrow) BBitmap(rect, hasAlpha ? B_RGBA32
		: fPicture->ColorSpace(), true);
	if (bitmap == NULL || !bitmap->IsValid()) {
		delete bitmap;
		return NULL;
	}

	if (bitmap->Lock()) {
		bitmap->AddChild(&view);
		if (hasAlpha) {
			view.SetHighColor(0, 0, 0, 0);
			view.FillRect(rect);
			view.SetDrawingMode(B_OP_ALPHA);
			view.SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_COMPOSITE);
			view.SetHighColor(0, 0, 0, alpha);
		}
		view.DrawBitmap(fPicture, fPicture->Bounds().OffsetToCopy(B_ORIGIN),
			rect, B_FILTER_BITMAP_BILINEAR);
		view.Sync();
		bitmap->RemoveChild(&view);
		bitmap->Unlock();
	}

	return bitmap;
}
Example #18
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;
}
Example #19
0
// Drawing Routines
void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dst, const FloatRect& src, ColorSpace styleColorSpace, CompositeOperator op)
{
    if (!m_source.initialized())
        return;

    // Spin the animation to the correct frame before we try to draw it, so we
    // don't draw an old frame and then immediately need to draw a newer one,
    // causing flicker and wasting CPU.
    startAnimation();

    BBitmap* image = nativeImageForCurrentFrame();
    if (!image || !image->IsValid()) // If the image hasn't fully loaded.
        return;

    if (mayFillWithSolidColor()) {
        fillWithSolidColor(ctxt, dst, solidColor(), styleColorSpace, op);
        return;
    }

    ctxt->save();
    ctxt->setCompositeOperation(op);

    BRect srcRect(src);
    BRect dstRect(dst);

    // Test using example site at
    // http://www.meyerweb.com/eric/css/edge/complexspiral/demo.html
    ctxt->platformContext()->SetDrawingMode(B_OP_ALPHA);
    uint32 options = 0;
    if (ctxt->imageInterpolationQuality() == InterpolationDefault
        || ctxt->imageInterpolationQuality() > InterpolationLow) {
        options |= B_FILTER_BITMAP_BILINEAR;
    }
    ctxt->platformContext()->DrawBitmapAsync(image, srcRect, dstRect, options);
    ctxt->restore();

    if (imageObserver())
        imageObserver()->didDraw(this);
}
Example #20
0
void
BasicPreviewView::SetColumnWidth(const int32& width)
{
    if (fColumnWidth == width || fEngine == nullptr)
        return;
     
    // TODO: Not a good solution
    BBitmap* bitmap = fEngine->Page(fCurrentPageNumber);
    while (bitmap == nullptr) {
		++fCurrentPageNumber;
		if (fCurrentPageNumber >= fEngine->PageCount())
			return;
			
		bitmap = fEngine->Page(fCurrentPageNumber);
	}
	
	if (bitmap == nullptr)
		!out << "NULL" << endl;
		
    int page = fCurrentPageNumber;

    fColumnWidth = width;
    fPageHeight = _PageHeight();
  	
    
    if (width <= 0) {
        fZoom = Bounds().Width() / bitmap->Bounds().Width();
        fColumns = 1;
        _AdaptCache();
    } else {
        fZoom = fColumnWidth / bitmap->Bounds().Width();
        fColumns = (Bounds().Width() - 2*fHMargin + fHSpace) / (fColumnWidth + fHSpace);
        if (fColumns < 1)
        	fColumns = 1;
        	
        _AdaptCache();
    }
    _ShowPage(page);
}
Example #21
0
// -------------------------------------------------------------------
//	* CONSTRUCTORS and DESTRUCTORS
// -------------------------------------------------------------------
DPRegression::DPRegression() : BApplication(data_plus_regr_sig)
{

	// Install this app and data file type if necessary
	BMimeType mime(data_plus_regr_sig);
	if (mime.InitCheck() == B_OK && !mime.IsInstalled()) {
		mime.Install();
	}
	BMimeType dataMime(regrplot_mime_type);
	if (dataMime.InitCheck() == B_OK && !dataMime.IsInstalled()) {
		dataMime.Install();
		// Set the document icons
		status_t status;
		BBitmap* lgIcon = new BBitmap(BRect(0,0,31,31),B_CMAP8);
		lgIcon->SetBits(largeIcon_bits,sizeof(largeIcon_bits),0,B_CMAP8);
		status = dataMime.SetIcon(lgIcon,B_LARGE_ICON);
		delete lgIcon;

		BBitmap* miniIcon = new BBitmap(BRect(0,0,15,15),B_CMAP8);
		miniIcon->SetBits(smallIcon_bits,sizeof(smallIcon_bits),0,B_CMAP8);
		status = dataMime.SetIcon(miniIcon,B_MINI_ICON);
		delete miniIcon;
	}
	// Make sure data marker is installed
	BMimeType markMime(data_plus_marker_sig);
	if (markMime.InitCheck() == B_OK && !markMime.IsInstalled()) {
		markMime.Install();
	}

	// We should get preference data for this
	
	mData = new BList();
	
	// Show the regression graph
	BRect	dataRect;
	dataRect.Set(100, 100, 450, 450);
	mRegrWindow = new DRRegrWindow(dataRect);
	mRegrWindow->Show();
}
Example #22
0
void SwatchView::MouseDown(BPoint where)
{
	if (!IsEnabled())
		return;

//	BMessage *mesg = Window()->CurrentMessage();
//	int32 clicks = mesg->FindInt32("clicks");

//	if (m_clicks == clicks)
//		SetColorWindow(ICommon, m_name, m_color, this);

	BPoint w2;
	uint32 mods;
	while(true)
	{
		GetMouse(&w2, &mods);
		if (!mods) //releasing the buttons without moving means no drag
		{
			Invoke();
			return;	
		}
		if (w2 != where)
			break;
	}
	snooze(40000);

	BMessage msg(B_PASTE);
	msg.AddData("RGBColor",B_RGB_COLOR_TYPE,(const void**)&m_color,sizeof(rgb_color));
	BString s = RGBtoText(m_color);
	msg.AddData("text/plain",B_MIME_DATA,(const void**)s.String(),s.Length());
	msg.AddString("be:types", "text/plain");
	msg.AddInt32("be:actions", B_COPY_TARGET);
	msg.AddInt32("be:actions", B_TRASH_TARGET);
	  
	BBitmap *bitmap = make_bitmap();
	 
	BPoint pt(bitmap->Bounds().Width()/2.0, bitmap->Bounds().Height()/2);
	DragMessage(&msg, bitmap, B_OP_ALPHA, pt, Window());
}
Example #23
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;
}
Example #24
0
BBitmap *RBitmapLoader::TranslateIcon(int index, const char *name)
{
	BPath path(&mAppDir, name);
	RIconLoader l;
	BBitmap *result = 0;
	if (l.Open(path.Path()))
	{
		ICONDATA *data = l.m_Icon.IconData + index;
		ICONENTRY *dir = l.m_Icon.IconDir + index;
		RGB *sourcebits = 0;
		RGB opacity;
		uint32 opaque = B_TRANSPARENT_MAGIC_RGBA32;
		opacity = *(RGB*)&opaque;
		switch(dir->NumColors) {
			case 0: // 256
			{
				sourcebits = l.Expand8ToRGB(data->XorMap, data->Palette, dir->Width * dir->Height);
			}
			break;
			case 16:
			{
				sourcebits = l.Expand4ToRGB(data->XorMap, data->Palette, dir->Width * dir->Height);
			}
			break;
		}
		
		l.PreMask(sourcebits, data->AndMap, dir->Width * dir->Height, opacity);
		l.InvertY(sourcebits, dir->Width, dir->Height);
 		result = new BBitmap(BRect(0,0, dir->Width-1, dir->Height-1), B_RGB32);
 		if (sourcebits)
 		{ 			
 			BYTE *rvb = ConvertTo24bit(dir->Width, dir->Height, (BYTE*)sourcebits, dir->Width * 4);
 			result->SetBits(rvb, dir->Width * dir->Height * 3, 0, B_RGB32);
 			delete rvb;
 		}	 
	}
	return result;
}
/**
 * _cairo_image_surface_to_bitmap:
 *
 * Converts an image surface to a BBitmap. The return value must be freed with
 * delete.
 **/
static BBitmap*
_cairo_image_surface_to_bitmap (cairo_image_surface_t* surface)
{
    BRect size(0.0, 0.0, surface->width - 1, surface->height - 1);
    switch (surface->format) {
	case CAIRO_FORMAT_ARGB32: {
	    BBitmap* data = new BBitmap(size, B_RGBA32);
	    unpremultiply_rgba(surface->data,
			       surface->width,
			       surface->height,
			       surface->stride,
			       reinterpret_cast<unsigned char*>(data->Bits()));
	    return data;
        }
	case CAIRO_FORMAT_RGB24: {
	    BBitmap* data = new BBitmap(size, B_RGB32);
	    memcpy(data->Bits(), surface->data, surface->height * surface->stride);
	    return data;
	}
	default:
	    return NULL;
    }
}
Example #26
0
// SetIcon
status_t
IconButton::SetIcon(const BMimeType* fileType, bool small)
{
    status_t status = fileType ? fileType->InitCheck() : B_BAD_VALUE;
    if (status >= B_OK) {
        BBitmap* mimeBitmap = new(nothrow) BBitmap(BRect(0.0, 0.0, 15.0, 15.0), B_CMAP8);
        if (mimeBitmap && mimeBitmap->IsValid()) {
            status = fileType->GetIcon(mimeBitmap, small ? B_MINI_ICON : B_LARGE_ICON);
            if (status >= B_OK) {
                if (BBitmap* bitmap = _ConvertToRGB32(mimeBitmap)) {
                    status = _MakeBitmaps(bitmap);
                    delete bitmap;
                } else
                    printf("IconButton::SetIcon() - B_RGB32 bitmap is not valid\n");
            } else
                printf("IconButton::SetIcon() - fileType->GetIcon() failed: %s\n", strerror(status));
        } else
            printf("IconButton::SetIcon() - B_CMAP8 bitmap is not valid\n");
        delete mimeBitmap;
    } else
        printf("IconButton::SetIcon() - fileType is not valid: %s\n", strerror(status));
    return status;
}
Example #27
0
static void fillBitmap(BBitmap &bitmap) {
	int32 height = bitmap.Bounds().IntegerHeight()+1;
	int32 width = bitmap.Bounds().IntegerWidth()+1;
	for (int32 y = 0; y < height; y ++) {
		for (int32 x = 0; x < width; x ++) {
			char *pixel = (char*)bitmap.Bits();
			pixel += bitmap.BytesPerRow() * y + 4 * x;
			if (isBorder(x, y, width, height)) {
				// fill with green
				pixel[0] = 255;
				pixel[1] = 0;
				pixel[2] = 255;
				pixel[3] = 0;
			} else  {
				// fill with blue
				pixel[0] = 255;
				pixel[1] = 0;
				pixel[2] = 0;
				pixel[3] = 255;
			}	
		}
	}
}
// Test a bitmap
static cairo_surface_t *
_cairo_boilerplate_beos_create_surface_for_bitmap (const char			 *name,
						   cairo_content_t		  content,
						   double				  width,
						   double				  height,
						   cairo_boilerplate_mode_t	  mode,
						   void				**closure)
{
    BRect rect(0.0, 0.0, width - 1, height - 1);
    color_space beosformat = (content == CAIRO_CONTENT_COLOR_ALPHA) ? B_RGBA32
								    : B_RGB32;
    BBitmap* bmp = new BBitmap(rect, beosformat, true);
    BView* view = new BView(rect, "Cairo test view", B_FOLLOW_ALL_SIDES, 0);
    bmp->AddChild(view);

    beos_boilerplate_closure* bclosure = new beos_boilerplate_closure;
    bclosure->view = view;
    bclosure->bitmap = bmp;
    bclosure->window = NULL;
    *closure = bclosure;

    return cairo_beos_surface_create_for_bitmap(view, bmp);
}
Example #29
0
// private methods
BBitmap*
MovieEncoder::GetCursorBitmap(const uint8* cursor)
{
	uint8 size = *cursor;
	
	BBitmap* cursorBitmap = new BBitmap(BRect(0, 0, size - 1, size - 1), B_RGBA32);
	
	uint32 black = 0xFF000000;
	uint32 white = 0xFFFFFFFF;
	
	uint8* castCursor = const_cast<uint8*>(cursor);
	uint16* cursorPtr = reinterpret_cast<uint16*>(castCursor + 4);
	uint16* maskPtr = reinterpret_cast<uint16*>(castCursor + 36);
	uint8* buffer = static_cast<uint8*>(cursorBitmap->Bits());
	uint16 cursorFlip, maskFlip;
	uint16 cursorVal, maskVal;
	for (uint8 row = 0; row < size; row++) {
		uint32* bits = (uint32*)(buffer + (row * cursorBitmap->BytesPerRow()));
		cursorFlip = (cursorPtr[row] & 0xFF) << 8;
		cursorFlip |= (cursorPtr[row] & 0xFF00) >> 8;
		
		maskFlip = (maskPtr[row] & 0xFF) << 8;
		maskFlip |= (maskPtr[row] & 0xFF00) >> 8;
		
		for (uint8 column = 0; column < size; column++) {
			uint16 posVal = 1 << (15 - column);
			cursorVal = cursorFlip & posVal;
			maskVal = maskFlip & posVal;
			bits[column] = (cursorVal != 0 ? black : white) &
							(maskVal > 0 ? white : 0x00FFFFFF);
							
		}
	}
		
	return cursorBitmap;
}
Example #30
0
void WrapWindow::FrameResized(float width, float height) {
        
    BRect bounds;
        
    bounds = Bounds();
        
    delete screen_buffer;
    screen_buffer = new BBitmap(bounds, (color_space)B_RGB32, false);            
            
    context->buffer = (uint32_t*)screen_buffer->Bits(); 
    context->width = (uint16_t)(bounds.right - bounds.left + 1);
    context->height = (uint16_t)(bounds.bottom - bounds.top + 1);  
            
    resize_handler(resize_obj, context->width, context->height);
}