Ticket #15920: BackBufferTest.cpp

File BackBufferTest.cpp, 1.7 KB (added by X512, 4 years ago)
Line 
1#include <stdio.h>
2#include <Application.h>
3#include <Window.h>
4#include <View.h>
5#include <Rect.h>
6
7enum {
8 updateMsg = 1,
9};
10
11class TestView: public BView
12{
13public:
14 TestView(BRect frame, const char *name): BView(frame, name, B_FOLLOW_NONE, B_FULL_UPDATE_ON_RESIZE | B_WILL_DRAW | B_SUBPIXEL_PRECISE)
15 {
16 this->SetViewColor(B_TRANSPARENT_COLOR);
17 }
18
19 void Draw(BRect dirty)
20 {
21 BRect rect(BPoint(0, 0), this->Frame().Size());
22 int i = 0;
23 this->PushState();
24 while ((rect.Width() > 0) && (rect.Height() > 0)) {
25 switch (i) {
26 case 0: this->SetHighColor(0xff, 0x00, 0x00); break;
27 case 1: this->SetHighColor(0x00, 0xff, 0x00); break;
28 case 2: this->SetHighColor(0x00, 0x00, 0xff); break;
29 }
30 this->FillRect(rect, B_SOLID_HIGH);
31 this->Sync();
32 snooze(10000);
33 rect.InsetBy(4, 4);
34 i = (i + 1) % 3;
35 }
36 this->PopState();
37 Looper()->PostMessage(updateMsg, this);
38 }
39
40 void MessageReceived(BMessage *msg)
41 {
42 switch(msg->what) {
43 case updateMsg: {
44 Invalidate();
45 break;
46 }
47 default:
48 BView::MessageReceived(msg);
49 }
50 }
51
52};
53
54class TestWindow: public BWindow
55{
56private:
57 TestView *fView;
58public:
59 TestWindow(BRect frame): BWindow(frame, "TestApp", B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS)
60 {
61 fView = new TestView(BRect(BPoint(0, 0), frame.Size()), "view");
62 fView->SetResizingMode(B_FOLLOW_ALL);
63 AddChild(fView, NULL);
64 fView->MakeFocus(true);
65 }
66
67};
68
69class TestApplication: public BApplication
70{
71public:
72 TestApplication(): BApplication("application/x-vnd.test-app")
73 {
74 }
75
76 void ReadyToRun() {
77 BWindow *wnd = new TestWindow(BRect(32, 32, 256, 256));
78 wnd->SetFlags(wnd->Flags() | B_QUIT_ON_WINDOW_CLOSE);
79 wnd->Show();
80 }
81};
82
83
84int main()
85{
86 TestApplication app;
87 app.Run();
88 return 0;
89}