2 * Copyright 2008, Stephan Aßmus <superstippi@gmx.de>
3 * Distributed under the terms of the MIT License.
7 #include <Application.h>
14 class View
: public BView
{
16 View(BRect rect
, const char* name
, uint32 followMode
,
17 uint8 red
, uint8 green
, uint8 blue
);
20 virtual void Draw(BRect updateRect
);
22 virtual void MouseDown(BPoint where
);
23 virtual void MouseMoved(BPoint where
, uint32 transit
,
24 const BMessage
* dragMessage
);
27 void _SetTransit(uint32 transit
);
33 View::View(BRect rect
, const char* name
, uint32 followMode
,
34 uint8 red
, uint8 green
, uint8 blue
)
35 : BView(rect
, name
, followMode
, B_WILL_DRAW
),
36 fLastTransit(B_OUTSIDE_VIEW
)
38 SetViewUIColor(B_PANEL_BACKGROUND_COLOR
);
39 SetHighColor(red
, green
, blue
);
49 View::Draw(BRect updateRect
)
51 if (fLastTransit
== B_INSIDE_VIEW
|| fLastTransit
== B_ENTERED_VIEW
)
57 View::MouseDown(BPoint where
)
61 GetMouse(&where
, &buttons
);
62 } while (buttons
!= 0);
67 View::MouseMoved(BPoint where
, uint32 transit
, const BMessage
* dragMessage
)
74 View::_SetTransit(uint32 transit
)
76 if (transit
== fLastTransit
)
81 if (fLastTransit
== B_INSIDE_VIEW
)
82 printf("%s, B_ENTERED_VIEW, but already inside!\n", Name());
86 if (fLastTransit
== B_OUTSIDE_VIEW
)
87 printf("%s, B_EXITED_VIEW, but already outside!\n", Name());
91 if (fLastTransit
== B_OUTSIDE_VIEW
)
92 printf("%s, B_INSIDE_VIEW, but never entered!\n", Name());
93 if (fLastTransit
== B_EXITED_VIEW
)
94 printf("%s, B_INSIDE_VIEW, but just exited!\n", Name());
98 if (fLastTransit
== B_INSIDE_VIEW
)
99 printf("%s, B_OUTSIDE_VIEW, but never exited!\n", Name());
100 if (fLastTransit
== B_ENTERED_VIEW
)
101 printf("%s, B_OUTSIDE_VIEW, but just entered!\n", Name());
105 fLastTransit
= transit
;
114 main(int argc
, char **argv
)
116 BApplication
app("application/x-vnd.haiku-view_transit");
118 BWindow
* window
= new BWindow(BRect(100, 100, 400, 400),
119 "ViewTransit-Test", B_TITLED_WINDOW
,
120 B_ASYNCHRONOUS_CONTROLS
| B_QUIT_ON_WINDOW_CLOSE
);
122 BRect frame
= window
->Bounds();
124 window
->AddChild(new View(frame
, "L ", B_FOLLOW_ALL
, 255, 0, 0));
125 frame
.left
= frame
.right
+ 1;
126 frame
.right
= window
->Bounds().right
;
127 View
* view
= new View(frame
, "R", B_FOLLOW_TOP_BOTTOM
| B_FOLLOW_RIGHT
,
129 window
->AddChild(view
);
130 view
->SetEventMask(B_POINTER_EVENTS
, B_NO_POINTER_HISTORY
);