2023-09-07 17:14:07 -07:00
|
|
|
#pragma once
|
|
|
|
|
|
2022-01-30 15:49:02 -08:00
|
|
|
#include <cstdint>
|
2020-10-01 09:36:43 +02:00
|
|
|
#include "Common/Input/InputState.h"
|
2020-10-04 00:25:21 +02:00
|
|
|
#include "Common/Math/geom2d.h"
|
2013-05-25 15:12:46 +02:00
|
|
|
|
|
|
|
|
// Mainly for detecting (multi-)touch gestures but also useable for left button mouse dragging etc.
|
2013-10-16 11:29:58 +02:00
|
|
|
// Currently only supports simple scroll-drags with inertia.
|
|
|
|
|
// TODO: Two-finger zoom/rotate etc.
|
2013-05-25 15:12:46 +02:00
|
|
|
|
|
|
|
|
enum Gesture {
|
|
|
|
|
GESTURE_DRAG_VERTICAL = 1,
|
|
|
|
|
GESTURE_DRAG_HORIZONTAL = 2,
|
|
|
|
|
GESTURE_TWO_FINGER_ZOOM = 4,
|
|
|
|
|
GESTURE_TWO_FINGER_ZOOM_ROTATE = 8,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// May track multiple gestures at the same time. You simply call GetGestureInfo
|
|
|
|
|
// with the gesture you are interested in.
|
2013-05-25 16:52:27 +02:00
|
|
|
class GestureDetector {
|
2013-05-25 15:12:46 +02:00
|
|
|
public:
|
2017-05-04 08:56:05 +02:00
|
|
|
GestureDetector();
|
2017-04-06 15:51:00 +02:00
|
|
|
TouchInput Update(const TouchInput &touch, const Bounds &bounds);
|
2013-08-20 11:35:54 +02:00
|
|
|
void UpdateFrame();
|
2017-04-06 15:51:00 +02:00
|
|
|
bool IsGestureActive(Gesture gesture, int touchId) const;
|
2017-04-06 09:58:08 +02:00
|
|
|
bool GetGestureInfo(Gesture gesture, int touchId, float info[4]) const;
|
2013-05-25 15:12:46 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
enum Locals {
|
2013-10-16 11:29:58 +02:00
|
|
|
MAX_PTRS = 10,
|
2013-05-25 15:12:46 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Pointer {
|
|
|
|
|
bool down;
|
|
|
|
|
double downTime;
|
|
|
|
|
float lastX;
|
|
|
|
|
float lastY;
|
|
|
|
|
float downX;
|
|
|
|
|
float downY;
|
|
|
|
|
float deltaX;
|
|
|
|
|
float deltaY;
|
|
|
|
|
float distanceX;
|
|
|
|
|
float distanceY;
|
2017-04-06 15:51:00 +02:00
|
|
|
float estimatedInertiaX;
|
|
|
|
|
float estimatedInertiaY;
|
|
|
|
|
|
|
|
|
|
uint32_t active;
|
2013-05-25 15:12:46 +02:00
|
|
|
};
|
|
|
|
|
|
2017-04-06 15:51:00 +02:00
|
|
|
Pointer pointers[MAX_PTRS]{};
|
2013-05-25 15:12:46 +02:00
|
|
|
};
|