2 #include <Application.h>
14 #include "WinBorder.h"
16 #define ApplicationSignature "application/x-vnd.generic-SkeletonApplication"
27 virtual void ReadyToRun();
35 clsMainWindow(const char *uWindowTitle
);
38 virtual bool QuitRequested();
39 void AddWindow(BRect frame
, const char* name
);
46 clsApp::clsApp() : BApplication(ApplicationSignature
)
48 srand(real_time_clock_usecs());
55 void clsApp::ReadyToRun()
60 clsMainWindow::clsMainWindow(const char *uWindowTitle
)
63 BRect(50, 50, 800, 650),
70 fView
= new MyView(Bounds(), "emu", B_FOLLOW_ALL
, B_WILL_DRAW
);
72 fView
->MakeFocus(true);
75 clsMainWindow::~clsMainWindow()
79 bool clsMainWindow::QuitRequested()
81 be_app
->PostMessage(B_QUIT_REQUESTED
);
82 return BWindow::QuitRequested();
88 clsMainWindow::AddWindow(BRect frame
, const char* name
)
90 Layer
* topLayer
= fView
->topLayer
;
92 WinBorder
* window
= new WinBorder(frame
, name
, B_FOLLOW_NONE
, B_FULL_UPDATE_ON_RESIZE
,
93 (rgb_color
){ 255, 203, 0, 255 });
94 topLayer
->AddLayer(window
);
96 // add a coupld children
97 frame
.OffsetTo(B_ORIGIN
);
98 frame
.InsetBy(5.0, 5.0);
99 if (frame
.IsValid()) {
100 Layer
* layer1
= new Layer(frame
, "View 1", B_FOLLOW_ALL
,
101 B_FULL_UPDATE_ON_RESIZE
, (rgb_color
){ 180, 180, 180, 255 });
103 frame
.OffsetTo(B_ORIGIN
);
104 frame
.InsetBy(15.0, 15.0);
105 if (frame
.IsValid()) {
108 f
.bottom
= f
.top
+ f
.Height() / 3 - 3;
109 f
.right
= f
.left
+ f
.Width() / 3 - 3;
113 layer
= new Layer(f
, "View", B_FOLLOW_LEFT
| B_FOLLOW_TOP
,
114 B_FULL_UPDATE_ON_RESIZE
, (rgb_color
){ 120, 120, 120, 255 });
115 layer1
->AddLayer(layer
);
117 f
.OffsetBy(f
.Width() + 6, 0);
119 layer
= new Layer(f
, "View", B_FOLLOW_LEFT_RIGHT
| B_FOLLOW_TOP
,
120 B_FULL_UPDATE_ON_RESIZE
, (rgb_color
){ 120, 120, 120, 255 });
121 layer1
->AddLayer(layer
);
123 f
.OffsetBy(f
.Width() + 6, 0);
125 layer
= new Layer(f
, "View", B_FOLLOW_RIGHT
| B_FOLLOW_TOP
,
126 B_FULL_UPDATE_ON_RESIZE
, (rgb_color
){ 120, 120, 120, 255 });
127 layer1
->AddLayer(layer
);
129 // middle row of views
131 f
.bottom
= f
.top
+ f
.Height() / 3 - 3;
132 f
.right
= f
.left
+ f
.Width() / 3 - 3;
133 f
.OffsetBy(0, f
.Height() + 6);
135 layer
= new Layer(f
, "View", B_FOLLOW_LEFT
| B_FOLLOW_TOP_BOTTOM
,
136 B_FULL_UPDATE_ON_RESIZE
, (rgb_color
){ 120, 120, 120, 255 });
137 layer1
->AddLayer(layer
);
139 f
.OffsetBy(f
.Width() + 6, 0);
141 layer
= new Layer(f
, "View", B_FOLLOW_ALL
,
142 B_FULL_UPDATE_ON_RESIZE
, (rgb_color
){ 120, 120, 120, 255 });
143 layer1
->AddLayer(layer
);
145 f
.OffsetBy(f
.Width() + 6, 0);
147 layer
= new Layer(f
, "View", B_FOLLOW_RIGHT
| B_FOLLOW_TOP_BOTTOM
,
148 B_FULL_UPDATE_ON_RESIZE
, (rgb_color
){ 120, 120, 120, 255 });
149 layer1
->AddLayer(layer
);
151 // bottom row of views
153 f
.bottom
= f
.top
+ f
.Height() / 3 - 3;
154 f
.right
= f
.left
+ f
.Width() / 3 - 3;
155 f
.OffsetBy(0, 2 * f
.Height() + 12);
157 layer
= new Layer(f
, "View", B_FOLLOW_LEFT
| B_FOLLOW_BOTTOM
,
158 B_FULL_UPDATE_ON_RESIZE
, (rgb_color
){ 120, 120, 120, 255 });
159 layer1
->AddLayer(layer
);
161 f
.OffsetBy(f
.Width() + 6, 0);
163 layer
= new Layer(f
, "View", B_FOLLOW_LEFT_RIGHT
| B_FOLLOW_BOTTOM
,
164 B_FULL_UPDATE_ON_RESIZE
, (rgb_color
){ 120, 120, 120, 255 });
165 layer1
->AddLayer(layer
);
167 f
.OffsetBy(f
.Width() + 6, 0);
169 layer
= new Layer(f
, "View", B_FOLLOW_RIGHT
| B_FOLLOW_BOTTOM
,
170 B_FULL_UPDATE_ON_RESIZE
, (rgb_color
){ 120, 120, 120, 255 });
171 layer1
->AddLayer(layer
);
174 window
->AddLayer(layer1
);
178 window
->GetWantedRegion(temp
);
179 topLayer
->RebuildVisibleRegions(temp
, window
);
184 clsMainWindow::test2()
186 BRect
frame(20, 20, 330, 230);
187 for (int32 i
= 0; i
< 20; i
++) {
188 BString
name("Window ");
189 frame
.OffsetBy(20, 15);
191 AddWindow(frame
, name
.String());
194 frame.Set(10, 80, 320, 290);
195 for (int32 i = 20; i < 40; i++) {
196 BString name("Window ");
197 frame.OffsetBy(20, 15);
199 AddWindow(frame, name.String());
202 frame.Set(20, 140, 330, 230);
203 for (int32 i = 40; i < 60; i++) {
204 BString name("Window ");
205 frame.OffsetBy(20, 15);
207 AddWindow(frame, name.String());
210 frame.Set(20, 200, 330, 230);
211 for (int32 i = 60; i < 80; i++) {
212 BString name("Window ");
213 frame.OffsetBy(20, 15);
215 AddWindow(frame, name.String());
218 frame.Set(20, 260, 330, 230);
219 // 99 windows are ok, the 100th looper does not run anymore,
220 // I guess I'm hitting a BeOS limit (max loopers per app?)
221 for (int32 i = 80; i < 99; i++) {
222 BString name("Window ");
223 frame.OffsetBy(20, 15);
225 AddWindow(frame, name.String());
228 fView
->RequestRedraw();
231 void clsMainWindow::test1()
233 Layer
*topLayer
= fView
->topLayer
;
238 c
.green
= rand()/256;
241 // = new Layer(BRect(20,20,300,220), "lay1", B_FOLLOW_NONE, 0, c);
242 // = new WinBorder(BRect(20,20,300,220), "lay1", B_FOLLOW_NONE, 0, c);
243 // topLayer->AddLayer(lay1);
245 WinBorder
*wb1
= new WinBorder(BRect(20,20,300,220), "wb1", B_FOLLOW_NONE
, B_FULL_UPDATE_ON_RESIZE
, c
);
246 topLayer
->AddLayer(wb1
);
248 Layer
*lay1
= new Layer(BRect(0,0,280,200), "lay1", B_FOLLOW_ALL
, 0, c
);
252 c
.green
= rand()/256;
254 Layer
*lay2
= new Layer(BRect(20,20,150,150), "lay2",
256 B_FULL_UPDATE_ON_RESIZE
, c
);
257 lay1
->AddLayer(lay2
);
260 c
.green
= rand()/256;
262 Layer
*lay3
= new Layer(BRect(20,20,100,100), "lay3",
263 B_FOLLOW_LEFT
| B_FOLLOW_BOTTOM
,
265 lay2
->AddLayer(lay3
);
268 c
.green
= rand()/256;
270 Layer
*lay12
= new Layer(BRect(170,20,290,150), "lay12",
271 B_FOLLOW_LEFT
| B_FOLLOW_TOP
,
274 lay1
->AddLayer(lay12
);
277 c
.green
= rand()/256;
279 Layer
*lay13
= new Layer(BRect(20,20,100,100), "lay13",
280 // B_FOLLOW_LEFT | B_FOLLOW_BOTTOM,
281 B_FOLLOW_RIGHT
| B_FOLLOW_TOP
,
282 // B_FOLLOW_LEFT | B_FOLLOW_V_CENTER,
283 // B_FOLLOW_H_CENTER | B_FOLLOW_TOP,
285 lay12
->AddLayer(lay13
);
288 c
.green
= rand()/256;
290 Layer
*lay102
= new Layer(BRect(200,20,420,250), "lay102",
293 // B_FULL_UPDATE_ON_RESIZE, c);
295 lay1
->AddLayer(lay102
);
298 c
.green
= rand()/256;
300 Layer
*lay103
= new Layer(BRect(0,0,100,50), "lay103",
301 B_FOLLOW_LEFT
| B_FOLLOW_BOTTOM
,
302 // B_FOLLOW_LEFT | B_FOLLOW_TOP,
304 lay102
->AddLayer(lay103
);
307 c
.green
= rand()/256;
309 Layer
*lay104
= new Layer(BRect(0,51,100,130), "lay104",
310 // B_FOLLOW_LEFT | B_FOLLOW_BOTTOM,
311 B_FOLLOW_RIGHT
| B_FOLLOW_BOTTOM
,
313 lay102
->AddLayer(lay104
);
316 c
.green
= rand()/256;
318 Layer
*lay106
= new Layer(BRect(0,140,100, 200), "lay104",
319 // B_FOLLOW_LEFT | B_FOLLOW_BOTTOM,
320 B_FOLLOW_RIGHT
| B_FOLLOW_TOP
,
322 lay102
->AddLayer(lay106
);
325 c
.green
= rand()/256;
327 Layer
*lay105
= new Layer(BRect(105,51,150,130), "lay104",
328 // B_FOLLOW_LEFT | B_FOLLOW_BOTTOM,
329 B_FOLLOW_H_CENTER
| B_FOLLOW_BOTTOM
,
331 lay102
->AddLayer(lay105
);
335 c
.green
= rand()/256;
337 WinBorder
*wb2
= new WinBorder(BRect(280,120,600,420), "wb2", B_FOLLOW_NONE
, B_FULL_UPDATE_ON_RESIZE
, c
);
338 topLayer
->AddLayer(wb2
);
339 Layer
*lay21
= new Layer(wb2
->Bounds().OffsetToCopy(0,0), "lay21", B_FOLLOW_NONE
, 0, c
);
340 wb2
->AddLayer(lay21
);
343 c
.green
= rand()/256;
345 Layer
*lay22
= new Layer(BRect(20,20,150,150), "lay22",
348 lay21
->AddLayer(lay22
);
351 WinBorder
*wb3
= new WinBorder(BRect(20,20,300,220), "wb3", B_FOLLOW_NONE
, B_FULL_UPDATE_ON_RESIZE
, c
);
352 topLayer
->AddLayer(wb3
);
354 lay1
= new Layer(BRect(0,0,280,200), "lay1", B_FOLLOW_ALL
, 0, c
);
357 WinBorder
*wb4
= new WinBorder(BRect(20,20,300,220), "wb4", B_FOLLOW_NONE
, B_FULL_UPDATE_ON_RESIZE
, c
);
358 topLayer
->AddLayer(wb4
);
360 lay1
= new Layer(BRect(0,0,280,200), "lay1", B_FOLLOW_ALL
, 0, c
);
363 WinBorder
*wb5
= new WinBorder(BRect(20,20,300,220), "wb5", B_FOLLOW_NONE
, B_FULL_UPDATE_ON_RESIZE
, c
);
364 topLayer
->AddLayer(wb5
);
366 lay1
= new Layer(BRect(0,0,280,200), "lay1", B_FOLLOW_ALL
, 0, c
);
369 WinBorder
*wb6
= new WinBorder(BRect(20,20,300,220), "wb6", B_FOLLOW_NONE
, B_FULL_UPDATE_ON_RESIZE
, c
);
370 topLayer
->AddLayer(wb6
);
372 lay1
= new Layer(BRect(0,0,280,200), "lay1", B_FOLLOW_ALL
, 0, c
);
375 WinBorder
*wb7
= new WinBorder(BRect(20,20,300,220), "wb7", B_FOLLOW_NONE
, B_FULL_UPDATE_ON_RESIZE
, c
);
376 topLayer
->AddLayer(wb7
);
378 lay1
= new Layer(BRect(0,0,280,200), "lay1", B_FOLLOW_ALL
, 0, c
);
381 WinBorder
*wb8
= new WinBorder(BRect(20,20,300,220), "wb8", B_FOLLOW_NONE
, B_FULL_UPDATE_ON_RESIZE
, c
);
382 topLayer
->AddLayer(wb8
);
384 lay1
= new Layer(BRect(0,0,280,200), "lay1", B_FOLLOW_ALL
, 0, c
);
387 WinBorder
*wb9
= new WinBorder(BRect(20,20,300,220), "wb9", B_FOLLOW_NONE
, B_FULL_UPDATE_ON_RESIZE
, c
);
388 topLayer
->AddLayer(wb9
);
390 lay1
= new Layer(BRect(0,0,280,200), "lay1", B_FOLLOW_ALL
, 0, c
);
393 WinBorder
*wb10
= new WinBorder(BRect(20,20,300,220), "wb10", B_FOLLOW_NONE
, B_FULL_UPDATE_ON_RESIZE
, c
);
394 topLayer
->AddLayer(wb10
);
396 lay1
= new Layer(BRect(0,0,280,200), "lay1", B_FOLLOW_ALL
, 0, c
);
397 wb10
->AddLayer(lay1
);
402 wb1
->GetWantedRegion(temp
);
403 topLayer
->RebuildVisibleRegions(temp
, wb1
);
405 wb2
->GetWantedRegion(temp
);
406 topLayer
->RebuildVisibleRegions(temp
, wb2
);
408 wb3
->GetWantedRegion(temp
);
409 topLayer
->RebuildVisibleRegions(temp
, wb3
);
411 wb4
->GetWantedRegion(temp
);
412 topLayer
->RebuildVisibleRegions(temp
, wb4
);
414 wb5
->GetWantedRegion(temp
);
415 topLayer
->RebuildVisibleRegions(temp
, wb5
);
417 wb6
->GetWantedRegion(temp
);
418 topLayer
->RebuildVisibleRegions(temp
, wb6
);
420 wb7
->GetWantedRegion(temp
);
421 topLayer
->RebuildVisibleRegions(temp
, wb7
);
423 wb8
->GetWantedRegion(temp
);
424 topLayer
->RebuildVisibleRegions(temp
, wb8
);
426 wb9
->GetWantedRegion(temp
);
427 topLayer
->RebuildVisibleRegions(temp
, wb9
);
429 wb10
->GetWantedRegion(temp
);
430 topLayer
->RebuildVisibleRegions(temp
, wb10
);
433 fView
->RequestRedraw();
451 lay2->ResizeBy(45,55);
455 lay2->ResizeBy(-45, -55);
460 lay1->ScrollBy(0,50);
472 lay1->Invalidate(BRect(0,0,500,500));
479 clsMainWindow
*win
= new clsMainWindow("clipping");