summaryrefslogtreecommitdiff
path: root/include/grail.h
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@euromail.se>2011-04-28 18:42:33 +0200
committerHenrik Rydberg <rydberg@euromail.se>2011-04-28 18:42:33 +0200
commit5423ccd321c1c84b0e7736b10b2fe9eeb1833e16 (patch)
treefc12f236a865dceb6008d9bc5691b0fd0cbe582b /include/grail.h
parentd87cde46e25c058ffc76d3871ca4e2ceb3e57991 (diff)
Introduce gesture frames
This patch extends the API with parallel new/delete functions, aiming to eventually replace the open/close function. The new functions give access to the grail gesture frames, containing gestural transform information. This information is useful in its own right, and will eventually replace the internal recognizer. Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'include/grail.h')
-rw-r--r--include/grail.h204
1 files changed, 204 insertions, 0 deletions
diff --git a/include/grail.h b/include/grail.h
index b208556..d9f3937 100644
--- a/include/grail.h
+++ b/include/grail.h
@@ -44,8 +44,17 @@ extern "C" {
44#define GRAIL_STATUS_UPDATE 1 44#define GRAIL_STATUS_UPDATE 1
45#define GRAIL_STATUS_END 2 45#define GRAIL_STATUS_END 2
46 46
47#define GRAIL_EXPECT_CENTER_X 0x0001
48#define GRAIL_EXPECT_CENTER_Y 0x0002
49#define GRAIL_EXPECT_DRAG_X 0x0004
50#define GRAIL_EXPECT_DRAG_Y 0x0008
51#define GRAIL_EXPECT_SCALE 0x0010
52#define GRAIL_EXPECT_ANGLE 0x0020
53#define GRAIL_EXPECT_MASK 0x003f
54
47typedef float grail_prop_t; /* gesture properties */ 55typedef float grail_prop_t; /* gesture properties */
48typedef utouch_frame_time_t grail_time_t; /* time in milliseconds */ 56typedef utouch_frame_time_t grail_time_t; /* time in milliseconds */
57typedef struct grail *grail_handle; /* the grail instance handle */
49 58
50/** 59/**
51 * struct grail_get_version - get grail library version 60 * struct grail_get_version - get grail library version
@@ -69,6 +78,64 @@ struct grail_coord {
69 float x, y; 78 float x, y;
70}; 79};
71 80
81grail_handle GRAIL_PUBLIC grail_new_raw(utouch_frame_handle fh,
82 unsigned int num_frames,
83 void *select,
84 unsigned int version,
85 unsigned int control_size,
86 unsigned int frame_size,
87 unsigned int slot_size);
88
89/**
90 * grail_new - allocate and initialize a new grail instance
91 * @fh: utouch frame handle to use
92 * @num_frames: number of frames in cyclic buffer
93 * @select: client selection callback
94 *
95 * Initialize the internal grail structures.
96 *
97 * Returns zero in case of failure.
98 */
99#define grail_new(fh, num_frames, select) \
100 grail_new_raw(fh, num_frames, select, \
101 GRAIL_VERSION, \
102 sizeof(struct grail_control), \
103 sizeof(struct grail_frame), \
104 sizeof(struct grail_element))
105
106/**
107 * grail_delete - destroy and delete grail instance
108 * @ge: grail instance in use
109 *
110 * Deallocates all internal memory structures.
111 */
112void GRAIL_PUBLIC grail_delete(grail_handle ge);
113
114/**
115 * grail_get_control - get mutable control structure
116 * @ge: the grail device in use
117 *
118 * Return the control struct of the grail instance.
119 *
120 * The control pointer is ABI agnostic, owned by the grail instance, and
121 * has grail scope.
122 */
123struct grail_control GRAIL_PUBLIC *grail_get_control(grail_handle ge);
124
125/**
126 * grail_pump_frame - insert touch frames into grail
127 * @ge: the grail device in use
128 * @frame: the touch frame to insert
129 *
130 * Insert a new touch frame into the grail engine. If the frame induces a
131 * new gesture frame, a pointer to the frame is returned.
132 *
133 * The grail frame pointer is ABI agnostic, owned by the grail instance, and
134 * has grail scope.
135 */
136const struct grail_frame GRAIL_PUBLIC *
137grail_pump_frame(grail_handle ge, const struct utouch_frame *frame);
138
72/** 139/**
73 * struct grail_client_id - Gesture client information 140 * struct grail_client_id - Gesture client information
74 * @client: Client id 141 * @client: Client id
@@ -95,6 +162,143 @@ struct grail_client_info {
95}; 162};
96 163
97/** 164/**
165 * struct grail_control - control parameters of grail
166 * @glue_ms: minimum time to hold activation (ms)
167 * @bar_center_x: horizontal distance to activate (surface width fraction)
168 * @bar_center_y: vertical distance to activate (surface height fraction)
169 * @bar_drag_x: horizontal distance to activate (surface width fraction)
170 * @bar_drag_y: vertical distance to activate (surface height fraction)
171 * @bar_scale: minimum scaling to activate (fraction)
172 * @bar_angle: minimum angle to activate (radians)
173 * @drop_x_ms: horizontal expect timeout (ms)
174 * @drop_y_ms: vertical expect timeout (ms)
175 * @drop_scale_ms: scaling expect timeout (ms)
176 * @drop_angle_ms: rotation expect timeout (ms)
177 * @pivot_unbound: when true, the pivot is not bound to the contact area
178 *
179 * The parameters are used to tune the behavior of the gesture recognition.
180 *
181 * The moveness is a number between zero and one denoting the
182 * character of the current transform. Zero means pure rotate and
183 * scale, one means pure drag.
184 *
185 * Later versions of this struct may grow in size, but will remain
186 * binary compatible with older versions.
187 */
188struct grail_control {
189 float glue_ms;
190 float bar_center_x;
191 float bar_center_y;
192 float bar_drag_x;
193 float bar_drag_y;
194 float bar_scale;
195 float bar_angle;
196 float drop_x_ms;
197 float drop_y_ms;
198 float drop_scale_ms;
199 float drop_angle_ms;
200 int pivot_unbound;
201};
202
203/**
204 * struct grail_frame - frame of ongoing elementary transformations
205 * @prev: pointer to the previous gesture frame
206 * @touch: pointer to the touch frame triggering this gesture frame
207 * @num_ongoing: number of elements in the ongoing array
208 * @ongoing: array of ongoing transformation elements
209 * @slots: array of all transformation slots
210 *
211 * A gesture frame consists of one or several touch frames glued
212 * together into a stable transition, combined with information on
213 * ongoing elementary gestural transformations. The array of ongoing
214 * elements contains all elements with a nonzero expect mask.
215 *
216 * Later versions of this struct may grow in size, but will remain
217 * binary compatible with older versions.
218 */
219struct grail_frame {
220 const struct grail_frame *prev;
221 const struct utouch_frame *touch;
222 unsigned int num_ongoing;
223 struct grail_element **ongoing;
224 struct grail_element **slots;
225};
226
227/**
228 * struct grail_element - elementary gesture transformation
229 * @prev: respective element of previous frame
230 * @slot: the transformation slot occupied by this element
231 * @id: unique identifier of the ongoing transformation
232 * @num_touches: number of contacts of this element
233 * @touches: array of contacts of this element
234 * @start_time: start time of this element
235 * @start_center: center position at start of transform (surface units)
236 * @expect_mask: bitmask of expected gestures (grail main types)
237 * @active_mask: bitmask of activated gestures (grail main types)
238 * @center: gesture center position (surface units)
239 * @velocity: current center velocity (surface units per second)
240 * @radius: gesture radius from center (surface units)
241 * @transform: the transformation matrix of the gesture
242 * @pivot: current center of rotate and scale (surface units)
243 * @drag: accumulated transformation displacement (surface units)
244 * @scale: accumulated scale (dimensionless)
245 * @angle: accumulated rotation angle (radians)
246 *
247 * The grail element describes the ongoing gestural transformation of
248 * a particular set of contacts. The expect mask describes which
249 * gestural transformations may become active during the course of
250 * events, and the active mask describes which have passed their
251 * respective activation threshold. The set of expected gestures can
252 * change over time, for instance by exclusion or timeout.
253 *
254 * Applications handling rotation, either by transformation matrix or
255 * angle, should use the drag displacement. For other applications,
256 * the center displacement may be used instead, as to not lose
257 * movement accuracy.
258 *
259 * Later versions of this struct may grow in size, but will remain
260 * binary compatible with older versions.
261 */
262struct grail_element {
263 const struct grail_element *prev;
264 int slot;
265 int id;
266 int num_touches;
267 const struct utouch_contact **touches;
268 grail_time_t start_time;
269 struct grail_coord start_center;
270 unsigned int expect_mask;
271 unsigned int active_mask;
272 struct grail_coord center;
273 struct grail_coord velocity;
274 float radius2;
275 float transform[6];
276 float moveness;
277 struct grail_coord pivot;
278 struct grail_coord drag;
279 float scale2;
280 float angle;
281};
282
283/**
284 * grail_element_transform - transform coordinates using element
285 * @slot: the transformation element to use
286 * @q: the grail coordinate to fill
287 * @x: the grail coordinate to transform
288 *
289 * Performs the 3x3 transform *q = T *p, where T is the element
290 * transform.
291 */
292static inline void grail_element_transform(const struct grail_element *slot,
293 struct grail_coord *q,
294 const struct grail_coord *p)
295{
296 const float *T = slot->transform;
297 q->x = T[0] * p->x + T[1] * p->y + T[2];
298 q->y = T[3] * p->x + T[4] * p->y + T[5];
299}
300
301/**
98 * struct grail_event - Gesture event 302 * struct grail_event - Gesture event
99 * @type: The gesture type 303 * @type: The gesture type
100 * @id: Unique identifier foof the gesture instance 304 * @id: Unique identifier foof the gesture instance