* A mouse shake detecting BMessageFilter that's easily integrated in any app.
* A test app for it. I added a src/test/kits/shared folder as i found it was the most logical place for it. Shake it up. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32602 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright 2009, Alexandre Deckner, [email protected]
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef SHAKE_TRACKING_FILTER_H
|
||||
#define SHAKE_TRACKING_FILTER_H
|
||||
|
||||
|
||||
#include <MessageFilter.h>
|
||||
#include <Point.h>
|
||||
|
||||
class BView;
|
||||
class BHandler;
|
||||
class BMessageRunner;
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
class LowPassFilter {
|
||||
public:
|
||||
LowPassFilter(uint32 size);
|
||||
~LowPassFilter();
|
||||
|
||||
void Input(const BPoint& p);
|
||||
BPoint Output() const;
|
||||
private:
|
||||
BPoint* fPoints;
|
||||
uint32 fSize;
|
||||
BPoint fSum;
|
||||
};
|
||||
|
||||
|
||||
class ShakeTrackingFilter : public BMessageFilter {
|
||||
public:
|
||||
ShakeTrackingFilter(
|
||||
BView* targetView,
|
||||
uint32 messageWhat,
|
||||
uint32 countThreshold = 2,
|
||||
bigtime_t timeTreshold = 400000);
|
||||
|
||||
~ShakeTrackingFilter();
|
||||
|
||||
filter_result Filter(BMessage* message, BHandler** _target);
|
||||
|
||||
private:
|
||||
BView* fTargetView;
|
||||
uint32 fMessageWhat;
|
||||
|
||||
BMessageRunner* fCancelRunner;
|
||||
LowPassFilter fLowPass;
|
||||
BPoint fLastDelta;
|
||||
BPoint fLastPosition;
|
||||
uint32 fCounter;
|
||||
uint32 fCountThreshold;
|
||||
bigtime_t fTimeThreshold;
|
||||
};
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
using BPrivate::ShakeTrackingFilter;
|
||||
using BPrivate::LowPassFilter;
|
||||
|
||||
#endif // SHAKE_TRACKING_FILTER_H
|
||||
Reference in New Issue
Block a user