5 #include "Application.h"
15 class TestView
: public BView
{
18 TestView(BRect frame
, const char* name
,
19 uint32 resizeFlags
, uint32 flags
)
20 : BView(frame
, name
, resizeFlags
, flags
),
22 fLastMousePos(0.0, 0.0)
24 SetViewUIColor(B_PANEL_BACKGROUND_COLOR
);
25 SetLowUIColor(ViewUIColor());
28 virtual void MessageReceived(BMessage
* message
);
30 virtual void Draw(BRect updateRect
);
32 virtual void MouseDown(BPoint where
);
33 virtual void MouseUp(BPoint where
);
34 virtual void MouseMoved(BPoint where
, uint32 transit
,
35 const BMessage
* dragMessage
);
45 TestView::MessageReceived(BMessage
* message
)
47 if (message
->what
== MSG_RESET
)
50 BView::MessageReceived(message
);
55 TestView::Draw(BRect updateRect
)
58 SetHighColor(200, 90, 0, 100);
59 StrokeEllipse(BPoint(80.0, 50.0), 70.0, 40.0);
61 SetDrawingMode(B_OP_ALPHA
);
64 SetHighColor(20, 40, 180, 150);
65 StrokeEllipse(BPoint(230.0, 90.0), 14.0, 60.0);
68 SetHighColor(60, 20, 110, 100);
69 StrokeEllipse(BPoint(100.0, 180.0), 35.0, 25.0);
72 SetHighColor(0, 0, 0, 255);
73 SetDrawingMode(B_OP_OVER
);
74 const char* message
= "Click and drag to scroll this view!";
75 DrawString(message
, BPoint(0.0, 30.0));
80 TestView::MouseDown(BPoint where
)
83 fLastMousePos
= where
;
84 SetMouseEventMask(B_POINTER_EVENTS
);
89 TestView::MouseUp(BPoint where
)
96 TestView::MouseMoved(BPoint where
, uint32 transit
,
97 const BMessage
* dragMessage
)
100 BPoint offset
= fLastMousePos
- where
;
101 ScrollBy(offset
.x
, offset
.y
);
102 fLastMousePos
= where
+ offset
;
110 show_window(BRect frame
, const char* name
)
112 BWindow
* window
= new BWindow(frame
, name
,
114 B_ASYNCHRONOUS_CONTROLS
| B_QUIT_ON_WINDOW_CLOSE
);
116 BView
* view
= new TestView(window
->Bounds(), "test", B_FOLLOW_ALL
,
117 B_WILL_DRAW
/* | B_FULL_UPDATE_ON_RESIZE*/);
119 window
->AddChild(view
);
120 BRect
b(0.0, 0.0, 60.0, 15.0);
121 b
.OffsetTo(5.0, view
->Bounds().bottom
- (b
.Height() + 15.0));
122 BButton
* control
= new BButton(b
, "button", "Reset", new BMessage(MSG_RESET
));
123 view
->AddChild(control
);
124 control
->SetTarget(view
);
131 main(int argc
, char** argv
)
133 BApplication
* app
= new BApplication("application/x.vnd-Haiku.Scrolling");
135 BRect
frame(50.0, 50.0, 300.0, 250.0);
136 show_window(frame
, "Scrolling Test");