1 // main.cpp 2 3 #include <stdio.h> 4 5 #include <Application.h> 6 #include <View.h> 7 #include <Window.h> 8 9 class TestView : public BView { 10 11 public: 12 TestView(BRect frame, const char* name, 13 uint32 resizeFlags, uint32 flags); 14 15 virtual void Draw(BRect updateRect); 16 virtual void MouseDown(BPoint where); 17 18 private: 19 BList fMouseSamples; 20 }; 21 22 // constructor 23 TestView::TestView(BRect frame, const char* name, 24 uint32 resizeFlags, uint32 flags) 25 : BView(frame, name, resizeFlags, flags), 26 fMouseSamples(128) 27 { 28 } 29 30 // Draw 31 void 32 TestView::Draw(BRect updateRect) 33 { 34 int32 count = fMouseSamples.CountItems(); 35 if (count > 0) { 36 BPoint* p = (BPoint*)fMouseSamples.ItemAtFast(0); 37 MovePenTo(*p); 38 } 39 40 for (int32 i = 0; i < count; i++) { 41 BPoint* p = (BPoint*)fMouseSamples.ItemAtFast(i); 42 StrokeLine(*p); 43 } 44 } 45 46 // MouseDown 47 void 48 TestView::MouseDown(BPoint where) 49 { 50 // clear previous stroke 51 int32 count = fMouseSamples.CountItems(); 52 for (int32 i = 0; i < count; i++) 53 delete (BPoint*)fMouseSamples.ItemAtFast(i); 54 fMouseSamples.MakeEmpty(); 55 FillRect(Bounds(), B_SOLID_LOW); 56 57 // sample new stroke 58 uint32 buttons; 59 GetMouse(&where, &buttons); 60 MovePenTo(where); 61 while (buttons) { 62 63 StrokeLine(where); 64 fMouseSamples.AddItem(new BPoint(where)); 65 66 snooze(20000); 67 GetMouse(&where, &buttons); 68 } 69 } 70 71 72 // main 73 int 74 main(int argc, char** argv) 75 { 76 BApplication app("application/x.vnd-Haiku.BitmapBounds"); 77 78 BRect frame(50.0, 50.0, 300.0, 250.0); 79 BWindow* window = new BWindow(frame, "Bitmap Bounds", B_TITLED_WINDOW, 80 B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE); 81 82 BView* view = new TestView(window->Bounds(), "test", 83 B_FOLLOW_ALL, B_WILL_DRAW); 84 window->AddChild(view); 85 86 window->Show(); 87 88 app.Run(); 89 90 return 0; 91 } 92