[haiku-development] Re: Hello, and a BBitmap question.

  • From: Stephan Assmus <superstippi@xxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Fri, 06 Jun 2008 11:39:15 +0200

jkim202@xxxxxxxxxxxxxxxxx wrote:
> Yes, BControls are already part of a BWindow hierarchy.
> 
> As François suggested, I tried removing them from the window.
> 
> How exactly do you remove BView or BControl object from the window they 
> belong to?
> 
> I tried calling BView::RemoveSelf(), BView::Invalidate(), BView::Flush(), 
> BView::DetachAll() but they don't seem to do what I expect.

You need to be more specific, because this should work. From memory, so 
apply with care:

BRect originalFrame = someControl->Frame();
BView* parent = someControl->Parent();
BView* nextSibling = someControl->NextSibling();

someControl->RemoveSelf();
someControl->MoveTo(B_ORIGIN);

BBitmap* bitmap = new BBitmap(someControl->Frame(), B_RGB32, true);
bitmap->Lock();
bitmap->AddChild(someControl);
someControl->PushState();
if (someControl->ViewColor() != B_TRANSPARENT_COLOR) {
        rgb_color highColor = someControl->HighColor();
        someControl->SetHighColor(someControl->ViewColor());
        someControl->FillRect(someControl->Bounds());
        someControl->SetHighColor(highColor);
}
someControl->Draw(someControl->Bounds());
someControl->Sync();
someControl->PopState();
someControl->RemoveSelf();
bitmap->Unlock();

// you can draw "bitmap" now with the help of any view that is
// attached to a window

someControl->MoveTo(originalFrame.LeftTop());
parent->AddChild(someControl, nextSibling);


Best regards,
-Stephan


Other related posts: