1 #include <Application.h>
2 #include <Bitmap.h>
3 #include <Region.h>
4 #include <View.h>
5 #include <Window.h>
6 #include <stdio.h>
7
8
9 class ClippingView : public BView {
10 public:
11 ClippingView(BRect frame);
12
13 virtual void Draw(BRect updateRect);
14 virtual void MouseDown(BPoint where);
15 virtual void KeyDown(const char *bytes, int32 numBytes);
16
17 private:
18 BWindow * fFloatingWindow;
19 };
20
21
22 class ClippingWindow : public BWindow {
23 public:
24 ClippingWindow(BRect frame);
25
26 private:
27 ClippingView * fView;
28 };
29
30
31 class ClippingApp : public BApplication {
32 public:
33 ClippingApp();
34
35 private:
36 ClippingWindow * fWindow;
37 };
38
39
ClippingApp()40 ClippingApp::ClippingApp()
41 : BApplication("application/x.vnd-Haiku.ClippingPlusRedraw")
42 {
43 fWindow = new ClippingWindow(BRect(200, 200, 500, 400));
44 fWindow->Show();
45 }
46
47
ClippingWindow(BRect frame)48 ClippingWindow::ClippingWindow(BRect frame)
49 : BWindow(frame, "Window", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE)
50 {
51 fView = new ClippingView(frame.OffsetToSelf(0, 0));
52 AddChild(fView);
53 fView->MakeFocus();
54 }
55
56
ClippingView(BRect frame)57 ClippingView::ClippingView(BRect frame)
58 : BView(frame, "View", B_FOLLOW_ALL, B_WILL_DRAW),
59 fFloatingWindow(NULL)
60 {
61 }
62
63
64 void
Draw(BRect updateRect)65 ClippingView::Draw(BRect updateRect)
66 {
67 printf("got draw with update rect: %f, %f, %f, %f\n",
68 updateRect.left, updateRect.top, updateRect.right, updateRect.bottom);
69
70 SetHighColor(0, 255, 0);
71 FillRect(Bounds(), B_SOLID_HIGH);
72 }
73
74
75 void
MouseDown(BPoint where)76 ClippingView::MouseDown(BPoint where)
77 {
78 if (fFloatingWindow == NULL) {
79 BPoint leftTop = ConvertToScreen(BPoint(50, 50));
80 fFloatingWindow = new BWindow(BRect(leftTop, leftTop + BPoint(100, 50)),
81 "Floating", B_FLOATING_WINDOW, B_AVOID_FOCUS);
82 fFloatingWindow->Show();
83 } else {
84 fFloatingWindow->Lock();
85 fFloatingWindow->Quit();
86 fFloatingWindow = NULL;
87 }
88 }
89
90
91 void
KeyDown(const char * bytes,int32 numBytes)92 ClippingView::KeyDown(const char *bytes, int32 numBytes)
93 {
94 SetHighColor(0, 0, 255);
95 FillRect(Bounds(), B_SOLID_HIGH);
96
97 BRegion region(BRect(200, 100, 250, 150));
98 ConstrainClippingRegion(®ion);
99
100 SetHighColor(255, 0, 0);
101 FillRect(Bounds(), B_SOLID_HIGH);
102 }
103
104
105 int
main(int argc,const char * argv[])106 main(int argc, const char *argv[])
107 {
108 ClippingApp *app = new ClippingApp();
109 app->Run();
110 delete app;
111 return 0;
112 }
113