Ticket #19227: FillRect.cpp

File FillRect.cpp, 2.2 KB (added by X512, 6 hours ago)
Line 
1#include <Application.h>
2#include <Window.h>
3#include <View.h>
4#include <Rect.h>
5#include <Shape.h>
6
7
8class TestView final: public BView {
9public:
10 TestView(BRect frame, const char *name): BView(frame, name, B_FOLLOW_NONE, B_WILL_DRAW | B_SUBPIXEL_PRECISE | B_FULL_UPDATE_ON_RESIZE)
11 {
12 }
13
14 void Draw(BRect dirty) final
15 {
16 BRect rect(0, 0, 63, 63);
17 rect.OffsetBy(8, 8);
18
19 SetHighColor(0, 0, 0);
20 SetLowColor(0xff, 0xff, 0xff);
21 {
22 BRect rect2 = rect;
23 bool flag = true;
24 while (rect2.Width() > 0 && rect2.Height() > 0) {
25 FillRect(rect2, flag ? B_SOLID_HIGH : B_SOLID_LOW);
26 rect2.InsetBy(M_SQRT2, M_SQRT2);
27 flag = !flag;
28 }
29 }
30 rect.OffsetBy(64 + 8, 0);
31 {
32 BRect rect2 = rect;
33 bool flag = true;
34 while (rect2.Width() > 0 && rect2.Height() > 0) {
35 BShape shape;
36 shape.MoveTo(BPoint(rect2.left, rect2.top));
37 shape.LineTo(BPoint(rect2.right + 1, rect2.top));
38 shape.LineTo(BPoint(rect2.right + 1, rect2.bottom + 1));
39 shape.LineTo(BPoint(rect2.left, rect2.bottom + 1));
40 shape.Close();
41 FillShape(&shape, flag ? B_SOLID_HIGH : B_SOLID_LOW);
42 rect2.InsetBy(M_SQRT2, M_SQRT2);
43 flag = !flag;
44 }
45 }
46 rect.OffsetBy(64 + 8, 0);
47 {
48 BRect rect2 = rect;
49 bool flag = true;
50 while (rect2.Width() > 0 && rect2.Height() > 0) {
51 FillEllipse(rect2, flag ? B_SOLID_HIGH : B_SOLID_LOW);
52 rect2.InsetBy(M_SQRT2, M_SQRT2);
53 flag = !flag;
54 }
55 }
56 }
57
58};
59
60class TestWindow final: public BWindow {
61private:
62 TestView *fView;
63
64public:
65 TestWindow(BRect frame): BWindow(frame, "TestApp", B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, B_ASYNCHRONOUS_CONTROLS)
66 {
67 fView = new TestView(frame.OffsetToCopy(B_ORIGIN), "view");
68 fView->SetResizingMode(B_FOLLOW_ALL);
69 AddChild(fView, NULL);
70 }
71
72 void Quit() final
73 {
74 be_app_messenger.SendMessage(B_QUIT_REQUESTED);
75 BWindow::Quit();
76 }
77
78};
79
80class TestApplication final: public BApplication {
81private:
82 TestWindow *fWnd;
83
84public:
85 TestApplication(): BApplication("application/x-vnd.Test-App")
86 {
87 }
88
89 void ReadyToRun() final
90 {
91 fWnd = new TestWindow(BRect(0, 0, 64*3 + 8*4 - 1, 64 + 8*2 - 1).OffsetByCopy(64, 64));
92 fWnd->Show();
93 }
94};
95
96
97int main()
98{
99 TestApplication app;
100 app.Run();
101 return 0;
102}