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, 0, 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", 98 B_FOLLOW_NONE, 99 B_FULL_UPDATE_ON_RESIZE, c); 100 lay1->AddLayer(lay2); 101 102 c.red = rand()/256; 103 c.green = rand()/256; 104 c.blue = rand()/256; 105 Layer *lay3 = new Layer(BRect(20,20,100,100), "lay3", 106 B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, 107 0, c); 108 lay2->AddLayer(lay3); 109 110 temp = lay1->Bounds(); 111 lay1->ConvertToScreen2(&temp); 112 topLayer->RebuildVisibleRegions(BRegion(temp), lay1); 113 114 wind->Lock(); 115 fView->Invalidate(); 116 wind->Unlock(); 117 118 119 snooze(2000000); 120 121 lay2->MoveBy(25,35); 122 123 snooze(2000000); 124 125 lay2->ResizeBy(45,55); 126 127 snooze(2000000); 128 129 lay2->ResizeBy(-45, -55); 130 131 /* 132 snooze(2000000); 133 134 lay1->ScrollBy(0,50); 135 136 snooze(2000000); 137 138 lay2->Hide(); 139 140 snooze(2000000); 141 142 lay2->Show(); 143 144 snooze(2000000); 145 146 lay1->Invalidate(BRect(0,0,500,500)); 147 */ 148 } 149 150 int main() 151 { 152 new clsApp(); 153 clsMainWindow *win = new clsMainWindow("clipping"); 154 win->Show(); 155 156 win->test1(); 157 158 be_app->Run(); 159 delete be_app; 160 return 0; 161 } 162