adjust the timer for touch event to work around the missing touch begin / touch end

This commit is contained in:
Sam Gateau 2015-05-03 18:40:55 -07:00
parent ae14396fd7
commit 116e29ae57
2 changed files with 13 additions and 2 deletions

View file

@ -73,16 +73,25 @@ void KeyboardMouseDevice::touchBeginEvent(const QTouchEvent* event) {
_isTouching = event->touchPointStates().testFlag(Qt::TouchPointPressed);
_lastTouch = evalAverageTouchPoints(event->touchPoints());
_lastTouchTime = _clock.now();
}
void KeyboardMouseDevice::touchEndEvent(const QTouchEvent* event) {
_isTouching = false;
_lastTouch = evalAverageTouchPoints(event->touchPoints());
_lastTouchTime = _clock.now();
}
void KeyboardMouseDevice::touchUpdateEvent(const QTouchEvent* event) {
auto currentPos = evalAverageTouchPoints(event->touchPoints());
auto currentTime = _clock.now();
auto sinceLastTouch = std::chrono::duration_cast<std::chrono::milliseconds>(currentTime - _lastTouchTime);
if (sinceLastTouch.count() > 50) {
_isTouching = false;
}
if (!_isTouching) {
_isTouching = event->touchPointStates().testFlag(Qt::TouchPointPressed);
_lastTouchTime = _clock.now();
} else {
auto currentMove = currentPos - _lastTouch;
@ -131,7 +140,7 @@ void KeyboardMouseDevice::registerToUserInputMapper(UserInputMapper& mapper) {
void KeyboardMouseDevice::assignDefaultInputMapping(UserInputMapper& mapper) {
const float BUTTON_MOVE_SPEED = 1.0f;
const float BUTTON_ROTATION_SPEED = 30.0f;
const float MOUSE_ROTATION_SPEED = 1.0f;
const float MOUSE_ROTATION_SPEED = 0.5f;
const float BUTTON_BOOM_SPEED = 0.1f;
// AWSD keys mapping

View file

@ -19,7 +19,7 @@
#include <unordered_set>
#include <functional>
#include <memory>
#include <chrono>
class UserInputMapper : public QObject {
Q_OBJECT
@ -258,6 +258,8 @@ public:
}
glm::vec2 evalAverageTouchPoints(const QList<QTouchEvent::TouchPoint>& points) const;
std::chrono::high_resolution_clock _clock;
std::chrono::high_resolution_clock::time_point _lastTouchTime;
};
#endif // hifi_UserInputMapper_h