vfs: check userland buffers before reading them.
[haiku.git] / src / tests / servers / app / constrain_clipping_region / main.cpp
blobc806461f72c9948d643c839d89af4735062c7949
1 // main.cpp
3 #include <stdio.h>
5 #include <Application.h>
6 #include <Region.h>
7 #include <View.h>
8 #include <Window.h>
10 class TestView1 : public BView {
12 public:
13 TestView1(BRect frame, const char* name, uint32 resizeFlags, uint32 flags)
14 : BView(frame, name, resizeFlags, flags)
16 SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
17 SetHighColor(ViewColor());
20 virtual void Draw(BRect updateRect)
22 BRegion region;
23 region.Include(BRect(20, 20, 40, 40));
24 region.Include(BRect(30, 30, 80, 80));
25 ConstrainClippingRegion(&region);
27 SetHighColor(255, 0, 0, 255);
28 FillRect(BRect(0, 0, 100, 100));
30 ConstrainClippingRegion(NULL);
32 SetHighColor(0, 0, 0, 255);
33 StrokeLine(BPoint(2, 2), BPoint(80, 80));
37 class TestView2 : public BView {
39 public:
40 TestView2(BRect frame, const char* name, uint32 resizeFlags, uint32 flags)
41 : BView(frame, name, resizeFlags, flags)
43 SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
44 SetHighColor(ViewColor());
47 virtual void AttachedToWindow()
49 SetOrigin(20, 20);
52 virtual void Draw(BRect updateRect)
54 // SetOrigin(20, 20);
56 BRegion region;
57 region.Include(BRect(20, 20, 40, 40));
58 region.Include(BRect(30, 30, 80, 80));
59 ConstrainClippingRegion(&region);
61 SetHighColor(255, 128, 0, 255);
62 FillRect(BRect(0, 0, 100, 100));
64 ConstrainClippingRegion(NULL);
66 SetHighColor(0, 0, 0, 255);
67 StrokeLine(BPoint(2, 2), BPoint(80, 80));
71 class TestView3 : public BView {
73 public:
74 TestView3(BRect frame, const char* name, uint32 resizeFlags, uint32 flags)
75 : BView(frame, name, resizeFlags, flags)
77 SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
78 SetHighColor(ViewColor());
81 virtual void AttachedToWindow()
83 SetOrigin(20, 20);
86 virtual void Draw(BRect updateRect)
88 BRegion region;
89 region.Include(BRect(20, 20, 40, 40));
90 region.Include(BRect(30, 30, 80, 80));
91 ConstrainClippingRegion(&region);
93 SetHighColor(55, 255, 128, 255);
94 FillRect(BRect(0, 0, 100, 100));
96 PushState();
97 SetOrigin(15, 15);
99 ConstrainClippingRegion(&region);
101 SetHighColor(155, 255, 128, 255);
102 FillRect(BRect(0, 0, 100, 100));
104 // ConstrainClippingRegion(NULL);
106 SetHighColor(0, 0, 0, 255);
107 StrokeLine(BPoint(2, 2), BPoint(80, 80));
108 SetHighColor(255, 0, 0, 255);
109 StrokeLine(BPoint(2, 2), BPoint(4, 2));
110 PopState();
112 SetHighColor(0, 0, 0, 255);
113 StrokeLine(BPoint(4, 2), BPoint(82, 80));
117 class TestView4 : public BView {
119 public:
120 TestView4(BRect frame, const char* name, uint32 resizeFlags, uint32 flags)
121 : BView(frame, name, resizeFlags, flags)
123 SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
124 SetHighColor(ViewColor());
127 virtual void AttachedToWindow()
129 SetOrigin(20, 20);
132 virtual void Draw(BRect updateRect)
134 BRegion region;
135 region.Include(BRect(20, 20, 40, 40));
136 region.Include(BRect(30, 30, 140, 140));
137 ConstrainClippingRegion(&region);
139 SetHighColor(55, 255, 128, 255);
140 FillRect(BRect(0, 0, 200, 200));
142 // NOTE: This exposes broken behavior of the ZETA
143 // (probably R5 too) app_server. The new origin
144 // is not taken into account
145 PushState();
147 ConstrainClippingRegion(&region);
148 SetOrigin(15, 15);
149 SetScale(1.5);
151 SetHighColor(155, 255, 128, 255);
152 FillRect(BRect(0, 0, 200, 200));
154 ConstrainClippingRegion(NULL);
156 SetHighColor(0, 0, 0, 255);
157 SetDrawingMode(B_OP_OVER);
158 DrawString("Text is scaled.", BPoint(20, 30));
160 SetScale(1.2);
161 DrawString("Text is scaled.", BPoint(20, 30));
163 StrokeLine(BPoint(2, 2), BPoint(80, 80));
165 PopState();
167 SetHighColor(0, 0, 0, 255);
168 StrokeLine(BPoint(4, 2), BPoint(82, 80));
172 class TestView5 : public BView {
174 public:
175 TestView5(BRect frame, const char* name, uint32 resizeFlags, uint32 flags)
176 : BView(frame, name, resizeFlags, flags)
178 SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
179 SetHighColor(ViewColor());
182 virtual void AttachedToWindow()
186 virtual void Draw(BRect updateRect)
188 BRegion region;
189 region.Include(BRect(0, 0, 40, 40));
190 region.Include(BRect(30, 30, 140, 140));
191 ConstrainClippingRegion(&region);
193 SetHighColor(55, 255, 128, 255);
194 FillRect(BRect(0, 0, 200, 200));
196 PushState();
197 ConstrainClippingRegion(&region);
198 SetOrigin(50, 10);
200 SetHighColor(155, 55, 128, 255);
201 FillRect(BRect(0, 0, 200, 200));
202 PopState();
204 SetHighColor(255, 0, 0);
205 StrokeLine(Bounds().LeftTop(), Bounds().RightBottom());
210 class TestView6 : public BView {
212 public:
213 TestView6(BRect frame, const char* name, uint32 resizeFlags, uint32 flags)
214 : BView(frame, name, resizeFlags, flags)
216 SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
217 SetHighColor(ViewColor());
220 virtual void AttachedToWindow()
224 virtual void Draw(BRect updateRect)
226 BRegion region;
227 region.Include(BRect(0, 0, 40, 40));
228 region.Include(BRect(30, 30, 140, 140));
229 ConstrainClippingRegion(&region);
231 SetHighColor(55, 255, 128, 255);
232 FillRect(BRect(0, 0, 200, 200));
234 PushState();
235 SetOrigin(50, 10);
236 ConstrainClippingRegion(&region);
238 SetHighColor(155, 55, 128, 255);
239 FillRect(BRect(0, 0, 200, 200));
240 PopState();
242 SetHighColor(255, 0, 0);
243 StrokeLine(Bounds().LeftTop(), Bounds().RightBottom());
247 // main
249 main(int argc, char** argv)
251 BApplication* app = new BApplication(
252 "application/x.vnd-Haiku.ClippingRegion");
254 BRect frame(50.0, 50.0, 300.0, 250.0);
255 BWindow* window;
256 BView* view;
258 // window = new BWindow(frame, "Test1", B_TITLED_WINDOW,
259 // B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE);
261 // view = new TestView1(window->Bounds(), "test1", B_FOLLOW_ALL,
262 // B_WILL_DRAW);
263 // window->AddChild(view);
264 // window->Show();
266 // frame.OffsetBy(20, 20);
267 // window = new BWindow(frame, "Test2", B_TITLED_WINDOW,
268 // B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE);
270 // view = new TestView2(window->Bounds(), "test2", B_FOLLOW_ALL,
271 // B_WILL_DRAW);
272 // window->AddChild(view);
273 // window->Show();
275 // frame.OffsetBy(20, 20);
276 // window = new BWindow(frame, "Test3", B_TITLED_WINDOW,
277 // B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE);
279 // view = new TestView3(window->Bounds(), "test3", B_FOLLOW_ALL,
280 // B_WILL_DRAW);
281 // window->AddChild(view);
282 // window->Show();
284 // frame.OffsetBy(20, 20);
285 // window = new BWindow(frame, "Test4", B_TITLED_WINDOW,
286 // B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE);
288 // view = new TestView4(window->Bounds(), "test4", B_FOLLOW_ALL,
289 // B_WILL_DRAW);
290 // window->AddChild(view);
291 // window->Show();
294 frame.OffsetBy(20, 20);
295 window = new BWindow(frame, "Test5", B_TITLED_WINDOW,
296 B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE);
298 view = new TestView5(window->Bounds(), "test5", B_FOLLOW_ALL,
299 B_WILL_DRAW);
300 window->AddChild(view);
301 window->Show();
303 frame.OffsetBy(20, 20);
304 window = new BWindow(frame, "Test6", B_TITLED_WINDOW,
305 B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE);
307 view = new TestView6(window->Bounds(), "test6", B_FOLLOW_ALL,
308 B_WILL_DRAW);
309 window->AddChild(view);
310 window->Show();
312 app->Run();
314 delete app;
315 return 0;