Gesture Library
zoom.c
Go to the documentation of this file.
1 #include "zoom.h"
2 
3 #include "math.h"
4 #include "multidrag.h"
5 
7 void (*on_zoom)(const zoom_t*) = 0;
8 
9 void init_zoom() {
10  for (int i = 0; i < MAX_TOUCHES; i++) {
12  zoom_d[i].uid = 0;
13  zoom_d[i].size = 0;
14  zoom_d[i].scale = 1;
15  zoom_d[i].zoomed = 0;
16  }
17 }
18 
19 void recognize_zoom(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  zoom_t previous = zoom_d[index];
26  zoom_d[index].uid = multidrags[index].uid;
27  zoom_d[index].size = multidrags[index].size;
28  zoom_d[index].scale = multidrags[index].scale;
29  if (!zoom_d[index].zoomed && fabsf(1 - multidrags[index].scale) > ZOOM_SCALE_MIN) {
30  zoom_d[index].zoomed = 1;
31  }
32  if (multidrags[index].state == RECOGNIZER_STATE_COMPLETED) {
34  if (zoom_d[index].zoomed) {
36  } else {
38  }
39  }
40  } else {
41  if (zoom_d[index].state == RECOGNIZER_STATE_POSSIBLE &&
42  multidrags[index].state == RECOGNIZER_STATE_IN_PROGRESS) {
43  zoom_d[index].zoomed = 0;
44  }
45  zoom_d[index].state = multidrags[index].state;
46  }
47  if (on_zoom && (previous.uid != zoom_d[index].uid || previous.state != zoom_d[index].state ||
48  previous.size != zoom_d[index].size || previous.scale != zoom_d[index].scale)) {
49  on_zoom(zoom_d + index);
50  }
51  }
52 }
53 
54 const zoom_t* get_zoom() {
55  return zoom_d;
56 }
57 
58 int set_on_zoom(void (*listener)(const zoom_t*)) {
59  if (on_zoom) {
60  on_zoom = listener;
61  return 0;
62  } else {
63  on_zoom = listener;
64  return 1;
65  }
66 }
float ZOOM_SCALE_MIN
Definition: gestureparams.c:17
#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
Data structure for multidrag gesture data.
Definition: multidrag.h:8
float scale
Definition: multidrag.h:21
int size
Definition: multidrag.h:14
state_t state
Definition: multidrag.h:10
int uid
Definition: multidrag.h:12
To use the gesture library, users create touch events and fill in the appropriate fields.
Definition: gesturelib.h:17
Data structure for zoom gesture data.
Definition: zoom.h:7
float scale
Definition: zoom.h:15
int size
Definition: zoom.h:13
state_t state
Definition: zoom.h:9
int uid
Definition: zoom.h:11
char zoomed
Definition: zoom.h:17
void(* on_zoom)(const zoom_t *)=0
Definition: zoom.c:7
int set_on_zoom(void(*listener)(const zoom_t *))
Subscribe listener to zoom gesture updates.
Definition: zoom.c:58
zoom_t zoom_d[MAX_TOUCHES]
Definition: zoom.c:6
void init_zoom()
Initialize zoom data structures.
Definition: zoom.c:9
void recognize_zoom(const touch_event_t *event)
Recognize zoom gesture. This gesture locks the number of fingers once any finger starts moving.
Definition: zoom.c:19
const zoom_t * get_zoom()
Access array of zoom_t of size MAX_TOUCHES.
Definition: zoom.c:54