#include <stdio.h>
#include <Application.h>
#include <View.h>
#include <Window.h>
class TestView : public BView {
public:
TestView(BRect frame);
~TestView();
virtual void Draw(BRect updateRect);
virtual void DrawAfterChildren(BRect updateRect);
};
TestView::TestView(BRect frame)
: BView(frame, "TestView", B_FOLLOW_ALL,
B_WILL_DRAW | B_DRAW_ON_CHILDREN | B_FULL_UPDATE_ON_RESIZE)
{
SetViewColor(200, 220, 255);
}
TestView::~TestView()
{
}
void
TestView::Draw(BRect updateRect)
{
printf("Draw(BRect(%.1f, %.1f, %.1f, %.1f))\n",
updateRect.left, updateRect.top, updateRect.right, updateRect.bottom);
printf("pensize: %.2f\n", PenSize());
SetHighColor(0, 0, 255);
StrokeLine(Bounds().LeftBottom(), Bounds().RightTop());
SetPenSize(5);
}
void
TestView::DrawAfterChildren(BRect updateRect)
{
printf("DrawAfterChildren(BRect(%.1f, %.1f, %.1f, %.1f))\n",
updateRect.left, updateRect.top, updateRect.right, updateRect.bottom);
printf("pensize: %.2f\n", PenSize());
SetHighColor(255, 0, 0);
StrokeLine(Bounds().LeftTop(), Bounds().RightBottom());
Sync();
SetPenSize(7);
}
class ChildView : public BView {
public:
ChildView(BRect frame, const char* name, rgb_color viewColor);
~ChildView();
virtual void Draw(BRect updateRect);
};
ChildView::ChildView(BRect frame, const char* name, rgb_color viewColor)
: BView(frame, name, B_FOLLOW_ALL, 0)
{
SetLowColor(200, 200, 200);
SetViewColor(viewColor);
if (*(int32*)&viewColor == *(int32*)&B_TRANSPARENT_COLOR)
SetFlags(Flags() | B_WILL_DRAW);
}
ChildView::~ChildView()
{
}
void
ChildView::Draw(BRect updateRect)
{
FillRect(updateRect, B_SOLID_LOW);
}
int
main(int argc, char** argv)
{
BApplication app("application/x-vnd.Haiku-DrawAfterChildren");
BRect frame(100, 100, 700, 400);
BWindow* window = new BWindow(frame, "Window",
B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE);
frame.OffsetTo(B_ORIGIN);
TestView* view = new TestView(frame);
window->AddChild(view);
frame.InsetBy(20, 20);
frame.right = frame.left + frame.Width() / 2 - 10;
BView* child = new ChildView(frame, "child 1",
(rgb_color){ 200, 200, 200, 255 });
view->AddChild(child);
frame.OffsetBy(frame.Width() + 20, 0);
child = new ChildView(frame, "child 2", B_TRANSPARENT_COLOR);
view->AddChild(child);
window->Show();
app.Run();
return 0;
}