1 | #include <Application.h>
|
---|
2 | #include <Window.h>
|
---|
3 | #include <View.h>
|
---|
4 | #include <Rect.h>
|
---|
5 | #include <stdio.h>
|
---|
6 |
|
---|
7 | class TestView: public BView
|
---|
8 | {
|
---|
9 | private:
|
---|
10 | float fWidth, fHeight;
|
---|
11 |
|
---|
12 | public:
|
---|
13 | TestView(BRect frame, const char *name): BView(frame, name, B_FOLLOW_NONE, B_FULL_UPDATE_ON_RESIZE | B_WILL_DRAW | B_SUBPIXEL_PRECISE | B_FRAME_EVENTS)
|
---|
14 | {
|
---|
15 | SetViewColor(0xff - 0x44, 0xff - 0x44, 0xff - 0x44);
|
---|
16 | }
|
---|
17 |
|
---|
18 | void AttachedToWindow()
|
---|
19 | {
|
---|
20 | fWidth = Bounds().Width();
|
---|
21 | fHeight = Bounds().Height();
|
---|
22 | }
|
---|
23 |
|
---|
24 | void FrameResized(float newWidth, float newHeight)
|
---|
25 | {
|
---|
26 | fWidth = newWidth;
|
---|
27 | fHeight = newHeight;
|
---|
28 | }
|
---|
29 |
|
---|
30 | void Draw(BRect dirty)
|
---|
31 | {
|
---|
32 | if (fWidth != Bounds().Width() || fHeight != Bounds().Height())
|
---|
33 | printf("Size don't match: (%g, %g), (%g, %g)\n", fWidth, fHeight, Bounds().Width(), Bounds().Height());
|
---|
34 |
|
---|
35 | BRect rect = Frame().OffsetToCopy(B_ORIGIN);
|
---|
36 | rect.left += 1; rect.top += 1;
|
---|
37 | PushState();
|
---|
38 | SetHighColor(0x44, 0x44, 0x44);
|
---|
39 | SetPenSize(2);
|
---|
40 | StrokeRect(rect, B_SOLID_HIGH);
|
---|
41 | SetPenSize(1);
|
---|
42 | StrokeLine(rect.LeftTop(), rect.RightBottom());
|
---|
43 | StrokeLine(rect.RightTop(), rect.LeftBottom());
|
---|
44 | PopState();
|
---|
45 | }
|
---|
46 | };
|
---|
47 |
|
---|
48 | class TestWindow: public BWindow
|
---|
49 | {
|
---|
50 | private:
|
---|
51 | TestView *fView;
|
---|
52 | public:
|
---|
53 | TestWindow(BRect frame): BWindow(frame, "TestApp", B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS)
|
---|
54 | {
|
---|
55 | fView = new TestView(frame.OffsetToCopy(B_ORIGIN), "view");
|
---|
56 | fView->SetResizingMode(B_FOLLOW_ALL);
|
---|
57 | AddChild(fView, NULL);
|
---|
58 | }
|
---|
59 |
|
---|
60 | void Quit()
|
---|
61 | {
|
---|
62 | be_app_messenger.SendMessage(B_QUIT_REQUESTED);
|
---|
63 | BWindow::Quit();
|
---|
64 | }
|
---|
65 |
|
---|
66 | };
|
---|
67 |
|
---|
68 | class TestApplication: public BApplication
|
---|
69 | {
|
---|
70 | private:
|
---|
71 | TestWindow *fWnd;
|
---|
72 | public:
|
---|
73 | TestApplication(): BApplication("application/x-vnd.test.app")
|
---|
74 | {
|
---|
75 | }
|
---|
76 |
|
---|
77 | void ReadyToRun() {
|
---|
78 | fWnd = new TestWindow(BRect(0, 0, 255, 255).OffsetByCopy(64, 64));
|
---|
79 | fWnd->Show();
|
---|
80 | }
|
---|
81 | };
|
---|
82 |
|
---|
83 |
|
---|
84 | int main()
|
---|
85 | {
|
---|
86 | TestApplication app;
|
---|
87 | app.Run();
|
---|
88 | return 0;
|
---|
89 | }
|
---|