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
12class BView;
13class BHandler;
14class BMessageRunner;
15
16namespace BPrivate {
17
18class LowPassFilter {
19public:
20						LowPassFilter(uint32 size);
21						~LowPassFilter();
22
23			void	    Input(const BPoint& p);
24			BPoint		Output() const;
25private:
26	BPoint* fPoints;
27	uint32	fSize;
28	BPoint	fSum;
29};
30
31
32class ShakeTrackingFilter : public BMessageFilter {
33public:
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
44private:
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
59using BPrivate::ShakeTrackingFilter;
60using BPrivate::LowPassFilter;
61
62#endif	// SHAKE_TRACKING_FILTER_H
63