1 #include <OS.h> 2 #include <Application.h> 3 #include <Window.h> 4 #include <View.h> 5 #include <Region.h> 6 #include <Rect.h> 7 8 #include <stdio.h> 9 #include <stdlib.h> 10 11 #include "MyView.h" 12 #include "Layer.h" 13 #include "WinBorder.h" 14 15 #define ApplicationSignature "application/x-vnd.generic-SkeletonApplication" 16 17 BWindow *wind = NULL; 18 19 class clsApp 20 : 21 public BApplication 22 { 23 public: 24 clsApp(); 25 ~clsApp(); 26 virtual void ReadyToRun(); 27 }; 28 29 class clsMainWindow 30 : 31 public BWindow 32 { 33 public: 34 clsMainWindow(const char *uWindowTitle); 35 ~clsMainWindow(); 36 37 virtual bool QuitRequested(); 38 void test1(); 39 private: 40 MyView *fView; 41 }; 42 43 clsApp::clsApp() : BApplication(ApplicationSignature) 44 { 45 srand(real_time_clock_usecs()); 46 } 47 48 clsApp::~clsApp() 49 { 50 } 51 52 void clsApp::ReadyToRun() 53 { 54 } 55 56 57 clsMainWindow::clsMainWindow(const char *uWindowTitle) 58 : 59 BWindow( 60 BRect(50, 50, 800, 650), 61 uWindowTitle, 62 B_TITLED_WINDOW_LOOK, 63 B_NORMAL_WINDOW_FEEL, 64 0 ) 65 { 66 wind = this; 67 fView = new MyView(Bounds(), "emu", B_FOLLOW_ALL, B_WILL_DRAW); 68 AddChild(fView); 69 fView->MakeFocus(true); 70 } 71 72 clsMainWindow::~clsMainWindow() 73 { 74 } 75 76 bool clsMainWindow::QuitRequested() 77 { 78 be_app->PostMessage(B_QUIT_REQUESTED); 79 return BWindow::QuitRequested(); 80 } 81 82 void clsMainWindow::test1() 83 { 84 Layer *topLayer = fView->topLayer; 85 86 rgb_color c; 87 88 c.red = rand()/256; 89 c.green = rand()/256; 90 c.blue = rand()/256; 91 // Layer *lay1 92 // = new Layer(BRect(20,20,300,220), "lay1", B_FOLLOW_NONE, 0, c); 93 // = new WinBorder(BRect(20,20,300,220), "lay1", B_FOLLOW_NONE, 0, c); 94 // topLayer->AddLayer(lay1); 95 // ------ 96 WinBorder *wb1 = new WinBorder(BRect(20,20,300,220), "wb1", B_FOLLOW_NONE, B_FULL_UPDATE_ON_RESIZE, c); 97 topLayer->AddLayer(wb1); 98 // same size as wb1 99 Layer *lay1 = new Layer(BRect(0,0,280,200), "lay1", B_FOLLOW_ALL, 0, c); 100 wb1->AddLayer(lay1); 101 // ------ 102 c.red = rand()/256; 103 c.green = rand()/256; 104 c.blue = rand()/256; 105 Layer *lay2 = new Layer(BRect(20,20,150,150), "lay2", 106 B_FOLLOW_NONE, 107 B_FULL_UPDATE_ON_RESIZE, c); 108 lay1->AddLayer(lay2); 109 110 c.red = rand()/256; 111 c.green = rand()/256; 112 c.blue = rand()/256; 113 Layer *lay3 = new Layer(BRect(20,20,100,100), "lay3", 114 B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, 115 0, c); 116 lay2->AddLayer(lay3); 117 118 c.red = rand()/256; 119 c.green = rand()/256; 120 c.blue = rand()/256; 121 Layer *lay12 = new Layer(BRect(170,20,290,150), "lay12", 122 B_FOLLOW_LEFT | B_FOLLOW_TOP, 123 // B_FOLLOW_NONE, 124 0, c); 125 lay1->AddLayer(lay12); 126 127 c.red = rand()/256; 128 c.green = rand()/256; 129 c.blue = rand()/256; 130 Layer *lay13 = new Layer(BRect(20,20,100,100), "lay13", 131 // B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, 132 B_FOLLOW_RIGHT | B_FOLLOW_TOP, 133 // B_FOLLOW_LEFT | B_FOLLOW_V_CENTER, 134 // B_FOLLOW_H_CENTER | B_FOLLOW_TOP, 135 0, c); 136 lay12->AddLayer(lay13); 137 138 c.red = rand()/256; 139 c.green = rand()/256; 140 c.blue = rand()/256; 141 Layer *lay102 = new Layer(BRect(200,20,420,250), "lay102", 142 // B_FOLLOW_NONE, 143 B_FOLLOW_TOP_BOTTOM, 144 // B_FULL_UPDATE_ON_RESIZE, c); 145 0, c); 146 lay1->AddLayer(lay102); 147 148 c.red = rand()/256; 149 c.green = rand()/256; 150 c.blue = rand()/256; 151 Layer *lay103 = new Layer(BRect(0,0,100,50), "lay103", 152 B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, 153 // B_FOLLOW_LEFT | B_FOLLOW_TOP, 154 0, c); 155 lay102->AddLayer(lay103); 156 157 c.red = rand()/256; 158 c.green = rand()/256; 159 c.blue = rand()/256; 160 Layer *lay104 = new Layer(BRect(0,51,100,130), "lay104", 161 // B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, 162 B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM, 163 0, c); 164 lay102->AddLayer(lay104); 165 166 c.red = rand()/256; 167 c.green = rand()/256; 168 c.blue = rand()/256; 169 Layer *lay106 = new Layer(BRect(0,140,100, 200), "lay104", 170 // B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, 171 B_FOLLOW_RIGHT | B_FOLLOW_TOP, 172 0, c); 173 lay102->AddLayer(lay106); 174 175 c.red = rand()/256; 176 c.green = rand()/256; 177 c.blue = rand()/256; 178 Layer *lay105 = new Layer(BRect(105,51,150,130), "lay104", 179 // B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, 180 B_FOLLOW_H_CENTER | B_FOLLOW_BOTTOM, 181 0, c); 182 lay102->AddLayer(lay105); 183 184 //--------- 185 c.red = rand()/256; 186 c.green = rand()/256; 187 c.blue = rand()/256; 188 WinBorder *wb2 = new WinBorder(BRect(280,120,600,420), "wb2", B_FOLLOW_NONE, B_FULL_UPDATE_ON_RESIZE, c); 189 topLayer->AddLayer(wb2); 190 Layer *lay21 = new Layer(wb2->Bounds().OffsetToCopy(0,0), "lay21", B_FOLLOW_NONE, 0, c); 191 wb2->AddLayer(lay21); 192 193 c.red = rand()/256; 194 c.green = rand()/256; 195 c.blue = rand()/256; 196 Layer *lay22 = new Layer(BRect(20,20,150,150), "lay22", 197 B_FOLLOW_NONE, 198 0, c); 199 lay21->AddLayer(lay22); 200 201 //--------- 202 203 BRegion temp; 204 wb1->GetWantedRegion(temp); 205 topLayer->RebuildVisibleRegions(temp, wb1); 206 207 wb2->GetWantedRegion(temp); 208 topLayer->RebuildVisibleRegions(temp, wb2); 209 210 fView->RequestRedraw(); 211 212 snooze(1000000); 213 214 wb1->Hide(); 215 216 snooze(1000000); 217 218 wb1->Show(); 219 220 /* 221 222 snooze(2000000); 223 224 lay2->MoveBy(25,35); 225 226 snooze(2000000); 227 228 lay2->ResizeBy(45,55); 229 230 snooze(2000000); 231 232 lay2->ResizeBy(-45, -55); 233 234 235 snooze(2000000); 236 237 lay1->ScrollBy(0,50); 238 239 snooze(2000000); 240 241 lay2->Hide(); 242 243 snooze(2000000); 244 245 lay2->Show(); 246 247 snooze(2000000); 248 249 lay1->Invalidate(BRect(0,0,500,500)); 250 */ 251 } 252 253 int main() 254 { 255 new clsApp(); 256 clsMainWindow *win = new clsMainWindow("clipping"); 257 win->Show(); 258 259 win->test1(); 260 261 be_app->Run(); 262 delete be_app; 263 return 0; 264 } 265