xref: /haiku/src/tests/servers/app/no_pointer_history/NoPointerHistory.cpp (revision 68ea01249e1e2088933cb12f9c28d4e5c5d1c9ef)
1 
2 #include <Application.h>
3 #include <View.h>
4 #include <Window.h>
5 
6 
7 class MouseView : public BView {
8 public:
9 	MouseView(BRect frame, bool noHistory);
10 	~MouseView();
11 
12 	virtual void AttachedToWindow();
13 	virtual void MouseMoved(BPoint point, uint32 transit,
14 		const BMessage *message);
15 	virtual void MouseDown(BPoint point);
16 	virtual void MouseUp(BPoint point);
17 
18 private:
19 	bool	fNoHistory;
20 };
21 
22 
23 MouseView::MouseView(BRect frame, bool noHistory)
24 	: BView(frame, "MouseView", B_FOLLOW_ALL, B_WILL_DRAW),
25 	fNoHistory(noHistory)
26 {
27 	SetViewColor(255, 255, 200);
28 	if (noHistory)
29 		SetHighColor(200, 0, 0);
30 	else
31 		SetHighColor(0, 200, 0);
32 }
33 
34 
35 MouseView::~MouseView()
36 {
37 }
38 
39 
40 void
41 MouseView::AttachedToWindow()
42 {
43 	if (fNoHistory)
44 		SetEventMask(0, B_NO_POINTER_HISTORY);
45 }
46 
47 
48 void
49 MouseView::MouseDown(BPoint point)
50 {
51 	SetMouseEventMask(0, B_NO_POINTER_HISTORY);
52 	SetHighColor(0, 0, 200);
53 }
54 
55 
56 void
57 MouseView::MouseUp(BPoint point)
58 {
59 	if (fNoHistory)
60 		SetHighColor(200, 0, 0);
61 	else
62 		SetHighColor(0, 200, 0);
63 }
64 
65 
66 void
67 MouseView::MouseMoved(BPoint point, uint32 transit, const BMessage *message)
68 {
69 	FillRect(BRect(point - BPoint(1, 1), point + BPoint(1, 1)));
70 	snooze(25000);
71 }
72 
73 
74 //	#pragma mark -
75 
76 
77 int
78 main(int argc, char** argv)
79 {
80 	BApplication app("application/x-vnd.Simon-NoPointerHistory");
81 
82 	BWindow* window = new BWindow(BRect(100, 100, 700, 400), "Window",
83 		B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE);
84 	window->AddChild(new MouseView(BRect(10, 10, 295, 290), true));
85 	window->AddChild(new MouseView(BRect(305, 10, 590, 290), false));
86 	window->Show();
87 
88 	app.Run();
89 	return 0;
90 }
91 
92