Gesture Library
gesturelib.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "gestureparams.h"
4 #include "stdint.h"
5 
7 typedef enum event_type {
8  // This type of touch event indicates a pointer starting to contact the surface.
10  // This type of touch event indicates an update to a pointer already contacting the surface.
12  // This type of touch event indicates a pointer already contacting the surface stops contact.
15 
17 typedef struct touch_event {
18  // This is the type of the touch event; see the enum event_type_t.
20  // This is the horizontal position of the touch event; adjust distance values in gestureparams.h to reflect
21  // appropriate units used for this.
22  float x;
23  // This is the vertical position of the touch event; adjust distance values in gestureparams.h to reflect
24  // appropriate units used for this.
25  float y;
26  // This is the time of the touch event in seconds. Timestamps can be relative to any fixed time point, but should be
27  // consistent for a single gesture.
28  float t;
29  // Touch event groups indicate which finger a touch event originates from, ranging from 0 to MAX_TOUCHES. Set this
30  // to TOUCH_GROUP_UNDEFINED to let the library assign it automatically.
31  unsigned int group;
32  // Touch event uids indicate which touch events should be processed as part of the same multi-finger gesture. Touch
33  // events that share a uid will be processed into one multi-finger gesture while touch events that do not share a
34  // uid will always be processed separately.
35  int uid;
37 
39 typedef struct gesture_recognizer {
40  // The library uses this flag to track whether a recognizer is enabled.
41  char enabled;
42  // This is the recognizer function itself.
43  void (*recognize)(const touch_event_t*);
44  // This is the recognizer initialization function. This function is invoked when a recognizer is added and when the
45  // library is initialized.
46  void (*init)(void);
48 
49 // This is the current number of recognizers the library holds. Declared in gesturelib.c
50 extern int num_recognizers;
51 // This is the last processed touch event of each group. Indices correspond to groups. Declared in gesturelib.c
53 
56 int init_gesturelib();
57 
63 
68 int add_recognizer(void (*recognizer)(const touch_event_t*), void (*init)(void));
69 
75 
79 int enable_recognizer(int recognizer);
80 
84 int disable_recognizer(int recognizer);
int disable_recognizer(int recognizer)
Disable a recognizer already in the library.
Definition: gesturelib.c:148
gesture_recognizer_t remove_recognizer(int recognizer)
Remove a recognizer in the library.
Definition: gesturelib.c:123
struct touch_event touch_event_t
To use the gesture library, users create touch events and fill in the appropriate fields.
event_type
This is the type of touch event. There are only 3 supported types.
Definition: gesturelib.h:7
@ TOUCH_EVENT_MOVE
Definition: gesturelib.h:11
@ TOUCH_EVENT_UP
Definition: gesturelib.h:13
@ TOUCH_EVENT_DOWN
Definition: gesturelib.h:9
int init_gesturelib()
This function should be called by the user before passing touch events to the library....
Definition: gesturelib.c:29
int enable_recognizer(int recognizer)
Enable a recognizer already in the library.
Definition: gesturelib.c:137
touch_event_t latest_touch_events[]
set containing most recent touch within finger group
Definition: gesturelib.c:19
int add_recognizer(void(*recognizer)(const touch_event_t *), void(*init)(void))
Register a recognizer via a recognition function.
Definition: gesturelib.c:111
void process_touch_event(touch_event_t *touch_event)
Users call this function with a generated touch event to let the library process it....
Definition: gesturelib.c:51
enum event_type event_type_t
This is the type of touch event. There are only 3 supported types.
struct gesture_recognizer gesture_recognizer_t
The user may create their own gesture recognizer to add to the library.
int num_recognizers
Definition: gesturelib.c:16
The user may create their own gesture recognizer to add to the library.
Definition: gesturelib.h:39
void(* init)(void)
Definition: gesturelib.h:46
void(* recognize)(const touch_event_t *)
Definition: gesturelib.h:43
To use the gesture library, users create touch events and fill in the appropriate fields.
Definition: gesturelib.h:17
event_type_t type
Definition: gesturelib.h:19
unsigned int group
Definition: gesturelib.h:31