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 14 #define ApplicationSignature "application/x-vnd.generic-SkeletonApplication" 15 16 BWindow *wind = NULL; 17 18 class clsApp 19 : 20 public BApplication 21 { 22 public: 23 clsApp(); 24 ~clsApp(); 25 virtual void ReadyToRun(); 26 }; 27 28 class clsMainWindow 29 : 30 public BWindow 31 { 32 public: 33 clsMainWindow(const char *uWindowTitle); 34 ~clsMainWindow(); 35 36 virtual bool QuitRequested(); 37 void test1(); 38 private: 39 MyView *fView; 40 }; 41 42 clsApp::clsApp() : BApplication(ApplicationSignature) 43 { 44 srand(real_time_clock_usecs()); 45 } 46 47 clsApp::~clsApp() 48 { 49 } 50 51 void clsApp::ReadyToRun() 52 { 53 } 54 55 56 clsMainWindow::clsMainWindow(const char *uWindowTitle) 57 : 58 BWindow( 59 BRect(50, 50, 500, 450), 60 uWindowTitle, 61 B_TITLED_WINDOW_LOOK, 62 B_NORMAL_WINDOW_FEEL, 63 0 ) 64 { 65 wind = this; 66 fView = new MyView(Bounds(), "emu", B_FOLLOW_ALL, B_WILL_DRAW); 67 AddChild(fView); 68 } 69 70 clsMainWindow::~clsMainWindow() 71 { 72 } 73 74 bool clsMainWindow::QuitRequested() 75 { 76 be_app->PostMessage(B_QUIT_REQUESTED); 77 return BWindow::QuitRequested(); 78 } 79 80 void clsMainWindow::test1() 81 { 82 Layer *topLayer = fView->topLayer; 83 // Layer *parent; 84 85 rgb_color c; 86 BRect temp; 87 88 c.red = rand()/256; 89 c.green = rand()/256; 90 c.blue = rand()/256; 91 Layer *lay1 = new Layer(BRect(20,20,300,220), "lay1", B_FOLLOW_NONE, c); 92 topLayer->AddLayer(lay1); 93 94 c.red = rand()/256; 95 c.green = rand()/256; 96 c.blue = rand()/256; 97 Layer *lay2 = new Layer(BRect(20,20,150,150), "lay2", B_FOLLOW_NONE, c); 98 lay1->AddLayer(lay2); 99 100 c.red = rand()/256; 101 c.green = rand()/256; 102 c.blue = rand()/256; 103 Layer *lay3 = new Layer(BRect(20,20,100,100), "lay3", B_FOLLOW_NONE, c); 104 lay2->AddLayer(lay3); 105 106 temp = lay1->Bounds(); 107 lay1->ConvertToScreen2(&temp); 108 topLayer->RebuildVisibleRegions(BRegion(temp), lay1); 109 110 wind->Lock(); 111 fView->Invalidate(); 112 wind->Unlock(); 113 /* 114 snooze(2000000); 115 116 temp = lay2->Bounds(); 117 lay2->ConvertToScreen2(&temp); 118 parent = lay2->Parent(); 119 if (parent) 120 { 121 parent->RemLayer(lay2); 122 parent->RebuildVisibleRegions(BRegion(temp), lay2); 123 } 124 125 wind->Lock(); 126 fView->Invalidate(); 127 wind->Unlock(); 128 */ 129 snooze(2000000); 130 131 lay2->MoveBy(25,35); 132 133 snooze(2000000); 134 135 lay2->ResizeBy(45,55); 136 137 snooze(2000000); 138 139 lay1->ScrollBy(0,50); 140 141 } 142 143 int main() 144 { 145 new clsApp(); 146 clsMainWindow *win = new clsMainWindow("clipping"); 147 win->Show(); 148 149 win->test1(); 150 151 be_app->Run(); 152 delete be_app; 153 return 0; 154 } 155