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, 500, 450), 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 } 70 71 clsMainWindow::~clsMainWindow() 72 { 73 } 74 75 bool clsMainWindow::QuitRequested() 76 { 77 be_app->PostMessage(B_QUIT_REQUESTED); 78 return BWindow::QuitRequested(); 79 } 80 81 void clsMainWindow::test1() 82 { 83 Layer *topLayer = fView->topLayer; 84 85 rgb_color c; 86 87 c.red = rand()/256; 88 c.green = rand()/256; 89 c.blue = rand()/256; 90 // Layer *lay1 91 // = new Layer(BRect(20,20,300,220), "lay1", B_FOLLOW_NONE, 0, c); 92 // = new WinBorder(BRect(20,20,300,220), "lay1", B_FOLLOW_NONE, 0, c); 93 // topLayer->AddLayer(lay1); 94 // ------ 95 WinBorder *wb1 = new WinBorder(BRect(20,20,300,220), "wb1", B_FOLLOW_NONE, 0, c); 96 topLayer->AddLayer(wb1); 97 Layer *lay1 98 = new Layer(BRect(0,0,280,200), "lay1", B_FOLLOW_NONE, 0, c); 99 wb1->AddLayer(lay1); 100 // ------ 101 c.red = rand()/256; 102 c.green = rand()/256; 103 c.blue = rand()/256; 104 Layer *lay2 = new Layer(BRect(20,20,150,150), "lay2", 105 B_FOLLOW_NONE, 106 B_FULL_UPDATE_ON_RESIZE, c); 107 lay1->AddLayer(lay2); 108 109 c.red = rand()/256; 110 c.green = rand()/256; 111 c.blue = rand()/256; 112 Layer *lay3 = new Layer(BRect(20,20,100,100), "lay3", 113 B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, 114 0, c); 115 lay2->AddLayer(lay3); 116 117 BRegion temp; 118 wb1->GetWantedRegion(temp); 119 topLayer->RebuildVisibleRegions(temp, wb1); 120 121 wind->Lock(); 122 fView->Invalidate(); 123 wind->Unlock(); 124 125 126 snooze(2000000); 127 128 lay2->MoveBy(25,35); 129 130 snooze(2000000); 131 132 lay2->ResizeBy(45,55); 133 134 snooze(2000000); 135 136 lay2->ResizeBy(-45, -55); 137 138 139 snooze(2000000); 140 141 lay1->ScrollBy(0,50); 142 143 snooze(2000000); 144 145 lay2->Hide(); 146 147 snooze(2000000); 148 149 lay2->Show(); 150 151 snooze(2000000); 152 153 lay1->Invalidate(BRect(0,0,500,500)); 154 155 } 156 157 int main() 158 { 159 new clsApp(); 160 clsMainWindow *win = new clsMainWindow("clipping"); 161 win->Show(); 162 163 win->test1(); 164 165 be_app->Run(); 166 delete be_app; 167 return 0; 168 } 169