Gesture Library
rotate.c
Go to the documentation of this file.
1 #include "rotate.h"
2 
3 #include "math.h"
4 #include "multidrag.h"
5 
7 void (*on_rotate)(const rotate_t*) = 0;
8 
9 void init_rotate() {
10  for (int i = 0; i < MAX_TOUCHES; i++) {
12  rotate_d[i].uid = 0;
13  rotate_d[i].size = 0;
14  rotate_d[i].rotation = 0;
15  rotate_d[i].rotated = 0;
16  }
17 }
18 
19 void recognize_rotate(const touch_event_t* event) {
20  // let multidrag process the event
21  (void)event;
22 
23  const multidrag_t* multidrags = get_multidrag();
24  for (int index = 0; index < MAX_TOUCHES; index++) {
25  rotate_t previous = rotate_d[index];
26  rotate_d[index].uid = multidrags[index].uid;
27  rotate_d[index].size = multidrags[index].size;
28  rotate_d[index].rotation = multidrags[index].rotation;
29  if (!rotate_d[index].rotated && fabsf(multidrags[index].rotation) > ROTATE_ANGLE_MIN) {
30  rotate_d[index].rotated = 1;
31  }
32  if (multidrags[index].state == RECOGNIZER_STATE_COMPLETED) {
34  if (rotate_d[index].rotated) {
36  } else {
38  }
39  }
40  } else {
42  multidrags[index].state == RECOGNIZER_STATE_IN_PROGRESS) {
43  rotate_d[index].rotated = 0;
44  }
45  rotate_d[index].state = multidrags[index].state;
46  }
47  if (on_rotate && (previous.uid != rotate_d[index].uid || previous.state != rotate_d[index].state ||
48  previous.size != rotate_d[index].size || previous.rotation != rotate_d[index].rotation)) {
49  on_rotate(rotate_d + index);
50  }
51  }
52 }
53 
54 const rotate_t* get_rotate() {
55  return rotate_d;
56 }
57 
58 int set_on_rotate(void (*listener)(const rotate_t*)) {
59  if (on_rotate) {
60  on_rotate = listener;
61  return 0;
62  } else {
63  on_rotate = listener;
64  return 1;
65  }
66 }
float ROTATE_ANGLE_MIN
Definition: gestureparams.c:19
#define MAX_TOUCHES
Definition: gestureparams.h:5
const multidrag_t * get_multidrag()
Access array of multidrag_t of size MAX_TOUCHES.
Definition: multidrag.c:53
state
This represents the state of individual gesture recognizers.
Definition: recognizer.h:4
@ RECOGNIZER_STATE_IN_PROGRESS
Definition: recognizer.h:10
@ RECOGNIZER_STATE_FAILED
Definition: recognizer.h:12
@ RECOGNIZER_STATE_NULL
Definition: recognizer.h:6
@ RECOGNIZER_STATE_COMPLETED
Definition: recognizer.h:14
@ RECOGNIZER_STATE_POSSIBLE
Definition: recognizer.h:8
const rotate_t * get_rotate()
Access array of rotate_t of size MAX_TOUCHES.
Definition: rotate.c:54
void recognize_rotate(const touch_event_t *event)
Recognize rotate gesture. This gesture locks the number of fingers once any finger starts moving.
Definition: rotate.c:19
void(* on_rotate)(const rotate_t *)=0
Definition: rotate.c:7
int set_on_rotate(void(*listener)(const rotate_t *))
Subscribe listener to rotate gesture updates.
Definition: rotate.c:58
void init_rotate()
Initialize rotate data structures.
Definition: rotate.c:9
rotate_t rotate_d[MAX_TOUCHES]
Definition: rotate.c:6
Data structure for multidrag gesture data.
Definition: multidrag.h:8
float rotation
Definition: multidrag.h:19
int size
Definition: multidrag.h:14
state_t state
Definition: multidrag.h:10
int uid
Definition: multidrag.h:12
Data structure for rotate gesture data.
Definition: rotate.h:7
char rotated
Definition: rotate.h:17
float rotation
Definition: rotate.h:15
int size
Definition: rotate.h:13
state_t state
Definition: rotate.h:9
int uid
Definition: rotate.h:11
To use the gesture library, users create touch events and fill in the appropriate fields.
Definition: gesturelib.h:17