xref: /haiku/headers/private/shared/ShakeTrackingFilter.h (revision 8e43b9e35e9ea39d427336d2ccf7953aa70c1d35)
1 /*
2  * Copyright 2009, Alexandre Deckner, alex@zappotek.com
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef SHAKE_TRACKING_FILTER_H
6 #define SHAKE_TRACKING_FILTER_H
7 
8 
9 #include <MessageFilter.h>
10 #include <Point.h>
11 
12 class BView;
13 class BHandler;
14 class BMessageRunner;
15 
16 namespace BPrivate {
17 
18 class LowPassFilter {
19 public:
20 						LowPassFilter(uint32 size);
21 						~LowPassFilter();
22 
23 			void	    Input(const BPoint& p);
24 			BPoint		Output() const;
25 private:
26 	BPoint* fPoints;
27 	uint32	fSize;
28 	BPoint	fSum;
29 };
30 
31 
32 class ShakeTrackingFilter : public BMessageFilter {
33 public:
34 								ShakeTrackingFilter(
35 									BView* targetView,
36 									uint32 messageWhat,
37 									uint32 countThreshold = 2,
38 									bigtime_t timeTreshold = 400000);
39 
40 								~ShakeTrackingFilter();
41 
42 			filter_result		Filter(BMessage* message, BHandler** _target);
43 
44 private:
45 			BView*				fTargetView;
46 			uint32				fMessageWhat;
47 
48 			BMessageRunner*		fCancelRunner;
49 			LowPassFilter		fLowPass;
50 			BPoint				fLastDelta;
51 			BPoint				fLastPosition;
52 			uint32				fCounter;
53 			uint32				fCountThreshold;
54 			bigtime_t			fTimeThreshold;
55 };
56 
57 }	// namespace BPrivate
58 
59 using BPrivate::ShakeTrackingFilter;
60 using BPrivate::LowPassFilter;
61 
62 #endif	// SHAKE_TRACKING_FILTER_H
63