CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/Common/Input/GestureDetector.h
Views: 1401
1
#pragma once
2
3
#include <cstdint>
4
#include "Common/Input/InputState.h"
5
#include "Common/Math/geom2d.h"
6
7
// Mainly for detecting (multi-)touch gestures but also useable for left button mouse dragging etc.
8
// Currently only supports simple scroll-drags with inertia.
9
// TODO: Two-finger zoom/rotate etc.
10
11
enum Gesture {
12
GESTURE_DRAG_VERTICAL = 1,
13
GESTURE_DRAG_HORIZONTAL = 2,
14
GESTURE_TWO_FINGER_ZOOM = 4,
15
GESTURE_TWO_FINGER_ZOOM_ROTATE = 8,
16
};
17
18
// May track multiple gestures at the same time. You simply call GetGestureInfo
19
// with the gesture you are interested in.
20
class GestureDetector {
21
public:
22
GestureDetector();
23
TouchInput Update(const TouchInput &touch, const Bounds &bounds);
24
void UpdateFrame();
25
bool IsGestureActive(Gesture gesture, int touchId) const;
26
bool GetGestureInfo(Gesture gesture, int touchId, float info[4]) const;
27
28
private:
29
enum Locals {
30
MAX_PTRS = 10,
31
};
32
33
struct Pointer {
34
bool down;
35
double downTime;
36
float lastX;
37
float lastY;
38
float downX;
39
float downY;
40
float deltaX;
41
float deltaY;
42
float distanceX;
43
float distanceY;
44
float estimatedInertiaX;
45
float estimatedInertiaY;
46
47
uint32_t active;
48
};
49
50
Pointer pointers[MAX_PTRS]{};
51
};
52
53