libroot_debug: Merge guarded heap into libroot_debug.
[haiku.git] / src / tests / servers / app / lagging_get_mouse / main.cpp
blob78429f8a6b7d07eb8be60833e560c4d947b59e0f
1 // main.cpp
3 #include <stdio.h>
5 #include <Application.h>
6 #include <View.h>
7 #include <Window.h>
9 class TestView : public BView {
11 public:
12 TestView(BRect frame, const char* name,
13 uint32 resizeFlags, uint32 flags);
15 virtual void Draw(BRect updateRect);
16 virtual void MouseDown(BPoint where);
18 private:
19 BList fMouseSamples;
22 // constructor
23 TestView::TestView(BRect frame, const char* name,
24 uint32 resizeFlags, uint32 flags)
25 : BView(frame, name, resizeFlags, flags),
26 fMouseSamples(128)
30 // Draw
31 void
32 TestView::Draw(BRect updateRect)
34 int32 count = fMouseSamples.CountItems();
35 if (count > 0) {
36 BPoint* p = (BPoint*)fMouseSamples.ItemAtFast(0);
37 MovePenTo(*p);
40 for (int32 i = 0; i < count; i++) {
41 BPoint* p = (BPoint*)fMouseSamples.ItemAtFast(i);
42 StrokeLine(*p);
46 // MouseDown
47 void
48 TestView::MouseDown(BPoint where)
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);
57 // sample new stroke
58 uint32 buttons;
59 GetMouse(&where, &buttons);
60 MovePenTo(where);
61 while (buttons) {
63 StrokeLine(where);
64 fMouseSamples.AddItem(new BPoint(where));
66 snooze(20000);
67 GetMouse(&where, &buttons);
72 // main
73 int
74 main(int argc, char** argv)
76 BApplication app("application/x.vnd-Haiku.BitmapBounds");
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);
82 BView* view = new TestView(window->Bounds(), "test",
83 B_FOLLOW_ALL, B_WILL_DRAW);
84 window->AddChild(view);
86 window->Show();
88 app.Run();
90 return 0;