Gesture Library
hold_and_drag.c
Go to the documentation of this file.
1 #include "hold_and_drag.h"
2 
3 #include "drag.h"
4 #include "hold.h"
5 #include "math.h"
6 #include "utils.h"
7 
8 // data[group1, group2, group3, group4, group5]
9 
11 void (*on_hold_and_drag)(const hold_and_drag_t*) = 0;
12 
14  for (int i = 0; i < MAX_TOUCHES; i++) {
16  hold_and_drag_d[i].x0 = 0;
17  hold_and_drag_d[i].y0 = 0;
18  hold_and_drag_d[i].x = 0;
19  hold_and_drag_d[i].y = 0;
20  hold_and_drag_d[i].vx = 0;
21  hold_and_drag_d[i].vy = 0;
22  }
23  on_hold_and_drag = 0;
24 }
25 
26 static void update_hold_and_drag(hold_and_drag_t* hold_and_drag, const hold_t* hold, const drag_t* drag);
27 
29  (void)event;
30  const hold_t* hold_d = get_hold();
31  const drag_t* drag_d = get_drag();
32  for (int index = 0; index < MAX_TOUCHES; index++) {
33  update_hold_and_drag(hold_and_drag_d + index, hold_d + index, drag_d + index);
34  }
35 }
36 
38  return hold_and_drag_d;
39 }
40 
41 int set_on_hold_and_drag(void (*listener)(const hold_and_drag_t*)) {
42  if (on_hold_and_drag) {
43  on_hold_and_drag = listener;
44  return 0;
45  } else {
46  on_hold_and_drag = listener;
47  return 1;
48  }
49 }
50 
51 static void update_hold_and_drag(hold_and_drag_t* hold_and_drag, const hold_t* hold, const drag_t* drag) {
54  hold_and_drag->x = drag->x;
55  hold_and_drag->y = drag->y;
56  hold_and_drag->vx = drag->vx;
57  hold_and_drag->vy = drag->vy;
58  if (on_hold_and_drag) {
60  }
61  } else {
64  hold_and_drag->x0 = hold->x0;
65  hold_and_drag->y0 = hold->y0;
66  hold_and_drag->x = hold->x;
67  hold_and_drag->y = hold->y;
68  if (on_hold_and_drag) {
70  }
71  }
72  }
73 }
drag_t drag_d[MAX_TOUCHES]
Definition: drag.c:7
const drag_t * get_drag()
Access drag data array of size MAX_TOUCHES.
Definition: drag.c:30
#define HOLD_TIME_MIN
Definition: gestureparams.h:22
#define MAX_TOUCHES
Definition: gestureparams.h:5
const hold_t * get_hold()
Access hold data array of size MAX_TOUCHES.
Definition: hold.c:44
hold_t hold_d[MAX_TOUCHES]
Definition: hold.c:9
void(* on_hold_and_drag)(const hold_and_drag_t *)=0
Definition: hold_and_drag.c:11
void recognize_hold_and_drag(const touch_event_t *event)
Recognize hold and drag gesture.
Definition: hold_and_drag.c:28
void init_hold_and_drag()
Initialize hold and drag data structures.
Definition: hold_and_drag.c:13
const hold_and_drag_t * get_hold_and_drag()
Access hold and drag data array of size MAX_TOUCHES.
Definition: hold_and_drag.c:37
hold_and_drag_t hold_and_drag_d[MAX_TOUCHES]
Definition: hold_and_drag.c:10
int set_on_hold_and_drag(void(*listener)(const hold_and_drag_t *))
Subscribe listener to hold and drag gesture updates.
Definition: hold_and_drag.c:41
@ RECOGNIZER_STATE_IN_PROGRESS
Definition: recognizer.h:10
@ RECOGNIZER_STATE_NULL
Definition: recognizer.h:6
Data structure for drag gesture data.
Definition: drag.h:7
state_t state
Definition: drag.h:9
float vy
Definition: drag.h:24
float vx
Definition: drag.h:23
float y
Definition: drag.h:20
float x
Definition: drag.h:19
Data structure for hold and drag data.
Definition: hold_and_drag.h:8
state_t state
Definition: hold_and_drag.h:9
Data structure for hold data.
Definition: hold.h:8
float x0
Definition: hold.h:12
state_t state
Definition: hold.h:9
float t0
Definition: hold.h:14
float y
Definition: hold.h:18
float x
Definition: hold.h:17
float y0
Definition: hold.h:13
float t
Definition: hold.h:19
To use the gesture library, users create touch events and fill in the appropriate fields.
Definition: gesturelib.h:17