1/*
2 * Copyright 2008, Stephan Aßmus <superstippi@gmx.de>
3 * Distributed under the terms of the MIT License.
4 */
5
6
7#include <Application.h>
8#include <Window.h>
9#include <View.h>
10
11#include <stdio.h>
12
13
14class View : public BView {
15public:
16						View(BRect rect, const char* name, uint32 followMode,
17							uint8 red, uint8 green, uint8 blue);
18		virtual			~View();
19
20		virtual void	Draw(BRect updateRect);
21
22		virtual	void	MouseDown(BPoint where);
23		virtual	void	MouseMoved(BPoint where, uint32 transit,
24							const BMessage* dragMessage);
25
26private:
27				void	_SetTransit(uint32 transit);
28
29				uint32	fLastTransit;
30};
31
32
33View::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)
37{
38	SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
39	SetHighColor(red, green, blue);
40}
41
42
43View::~View()
44{
45}
46
47
48void
49View::Draw(BRect updateRect)
50{
51	if (fLastTransit == B_INSIDE_VIEW || fLastTransit == B_ENTERED_VIEW)
52		FillRect(updateRect);
53}
54
55
56void
57View::MouseDown(BPoint where)
58{
59	uint32 buttons;
60	do {
61		GetMouse(&where, &buttons);
62	} while (buttons != 0);
63}
64
65
66void
67View::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage)
68{
69	_SetTransit(transit);
70}
71
72
73void
74View::_SetTransit(uint32 transit)
75{
76	if (transit == fLastTransit)
77		return;
78
79	switch (transit) {
80		case B_ENTERED_VIEW:
81			if (fLastTransit == B_INSIDE_VIEW)
82				printf("%s, B_ENTERED_VIEW, but already inside!\n", Name());
83			break;
84
85		case B_EXITED_VIEW:
86			if (fLastTransit == B_OUTSIDE_VIEW)
87				printf("%s, B_EXITED_VIEW, but already outside!\n", Name());
88			break;
89
90		case B_INSIDE_VIEW:
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());
95			break;
96
97		case B_OUTSIDE_VIEW:
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());
102			break;
103	}
104
105	fLastTransit = transit;
106	Invalidate();
107}
108
109
110//	#pragma mark -
111
112
113int
114main(int argc, char **argv)
115{
116	BApplication app("application/x-vnd.haiku-view_transit");
117
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);
121
122	BRect frame = window->Bounds();
123	frame.right /= 2;
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,
128		0, 255, 0);
129	window->AddChild(view);
130	view->SetEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY);
131
132	window->Show();
133
134	app.Run();
135	return 0;
136}
137