6 #include <Application.h>
17 TRACKING_RIGHT_BOTTOM
,
20 class TestView
: public BView
{
23 TestView(BRect frame
, const char* name
,
24 uint32 resizeFlags
, uint32 flags
)
25 : BView(frame
, name
, resizeFlags
, flags
),
26 fTracking(TRACKING_NONE
),
27 fLastMousePos(0.0, 0.0)
30 color
.red
= rand() / 256;
31 color
.green
= rand() / 256;
32 color
.blue
= rand() / 256;
38 virtual void Draw(BRect updateRect
);
40 virtual void MouseDown(BPoint where
);
41 virtual void MouseUp(BPoint where
);
42 virtual void MouseMoved(BPoint where
, uint32 transit
,
43 const BMessage
* dragMessage
);
53 TestView::Draw(BRect updateRect
)
56 SetHighColor(0, 0, 0, 255);
57 const char* message
= "Click and drag to move this view!";
58 DrawString(message
, BPoint(20.0, 30.0));
63 StrokeLine(r
.RightTop(), BPoint(r
.right
, Bounds().bottom
));
64 StrokeLine(r
.LeftBottom(), BPoint(Bounds().right
, r
.bottom
));
69 TestView::MouseDown(BPoint where
)
74 if (r
.Contains(where
))
75 fTracking
= TRACKING_ALL
;
76 else if (r
.bottom
< where
.y
&& r
.right
< where
.x
)
77 fTracking
= TRACKING_RIGHT_BOTTOM
;
78 else if (r
.bottom
< where
.y
)
79 fTracking
= TRACKING_BOTTOM
;
80 else if (r
.right
< where
.x
)
81 fTracking
= TRACKING_RIGHT
;
83 fLastMousePos
= where
;
84 SetMouseEventMask(B_POINTER_EVENTS
, B_LOCK_WINDOW_FOCUS
);
89 TestView::MouseUp(BPoint where
)
91 fTracking
= TRACKING_NONE
;
96 TestView::MouseMoved(BPoint where
, uint32 transit
,
97 const BMessage
* dragMessage
)
99 BPoint offset
= where
- fLastMousePos
;
102 MoveBy(offset
.x
, offset
.y
);
103 // fLastMousePos stays fixed
106 ResizeBy(offset
.x
, 0.0);
107 fLastMousePos
= where
;
109 case TRACKING_BOTTOM
:
110 ResizeBy(0.0, offset
.y
);
111 fLastMousePos
= where
;
113 case TRACKING_RIGHT_BOTTOM
:
114 ResizeBy(offset
.x
, offset
.y
);
115 fLastMousePos
= where
;
124 show_window(BRect frame
, const char* name
)
126 BWindow
* window
= new BWindow(frame
, name
,
128 B_ASYNCHRONOUS_CONTROLS
| B_QUIT_ON_WINDOW_CLOSE
);
130 BView
* view
= new TestView(window
->Bounds(), "test 1", B_FOLLOW_ALL
,
131 B_WILL_DRAW
| B_FULL_UPDATE_ON_RESIZE
);
133 window
->AddChild(view
);
135 BRect bounds
= view
->Bounds();
136 bounds
.InsetBy(20, 20);
137 BView
* view1
= new TestView(bounds
, "test 2", B_FOLLOW_RIGHT
| B_FOLLOW_BOTTOM
,
138 B_WILL_DRAW
| B_FULL_UPDATE_ON_RESIZE
);
139 view
->AddChild(view1
);
141 bounds
= view1
->Bounds();
142 bounds
.InsetBy(20, 20);
143 BView
* view2
= new TestView(bounds
, "test 3", B_FOLLOW_NONE
,
144 B_WILL_DRAW
| B_FULL_UPDATE_ON_RESIZE
);
145 view1
->AddChild(view2
);
153 main(int argc
, char** argv
)
155 BApplication
* app
= new BApplication("application/x.vnd-Haiku.Following");
157 BRect
frame(50.0, 50.0, 300.0, 250.0);
158 show_window(frame
, "Following Test");