touchscreen: Integrate gesture API with action system

Provide a default gesture object in the action system which will
be kept up to date with touch events automatically. This reduces
the boilerplate needed to handle touch input.

Change-Id: I76f51ac2c3e3a0da204707d62e91a175c5f8c76a
This commit is contained in:
Aidan MacDonald 2022-07-12 13:38:02 +01:00 committed by Solomon Peachy
parent bb1e0b48a0
commit 8aae723853
2 changed files with 38 additions and 0 deletions

View file

@ -104,6 +104,7 @@ typedef struct
int ts_data; int ts_data;
long ts_start_tick; long ts_start_tick;
struct touchevent touchevent; struct touchevent touchevent;
struct gesture gesture;
#endif #endif
} action_last_t; } action_last_t;
@ -467,6 +468,9 @@ static inline bool get_action_touchscreen(action_last_t *last, action_cur_t *cur
last->touchevent.y = last->ts_data & 0xffff; last->touchevent.y = last->ts_data & 0xffff;
last->touchevent.tick = last->tick; last->touchevent.tick = last->tick;
/* Update gesture state */
gesture_process(&last->gesture, &last->touchevent);
return true; return true;
} }
else else
@ -1151,6 +1155,27 @@ int action_get_touch_event(struct touchevent *ev)
return action_last.touchevent.type; return action_last.touchevent.type;
} }
void action_gesture_reset(void)
{
gesture_reset(&action_last.gesture);
}
bool action_gesture_get_event_in_vp(struct gesture_event *gevt,
const struct viewport *vp)
{
return gesture_get_event_in_vp(&action_last.gesture, gevt, vp);
}
bool action_gesture_is_valid(void)
{
return gesture_is_valid(&action_last.gesture);
}
bool action_gesture_is_pressed(void)
{
return gesture_is_pressed(&action_last.gesture);
}
/* return BUTTON_NONE on error /* return BUTTON_NONE on error
* BUTTON_REPEAT if repeated press * BUTTON_REPEAT if repeated press
* BUTTON_REPEAT|BUTTON_REL if release after repeated press * BUTTON_REPEAT|BUTTON_REL if release after repeated press

View file

@ -23,6 +23,7 @@
#include "stdbool.h" #include "stdbool.h"
#include "button.h" #include "button.h"
#include "viewport.h" #include "viewport.h"
#include "gesture.h"
#define TIMEOUT_BLOCK -1 #define TIMEOUT_BLOCK -1
#define TIMEOUT_NOBLOCK 0 #define TIMEOUT_NOBLOCK 0
@ -418,6 +419,18 @@ intptr_t get_action_data(void);
/* Return a touch event and screen coordinates of the touch. */ /* Return a touch event and screen coordinates of the touch. */
int action_get_touch_event(struct touchevent *ev); int action_get_touch_event(struct touchevent *ev);
/* Action system gesture recognition */
void action_gesture_reset(void);
bool action_gesture_get_event_in_vp(struct gesture_event *gevt,
const struct viewport *vp);
bool action_gesture_is_valid(void);
bool action_gesture_is_pressed(void);
static inline bool action_gesture_get_event(struct gesture_event *gevt)
{
return action_gesture_get_event_in_vp(gevt, NULL);
}
/* DEPRECATED, do not use these anymore */ /* DEPRECATED, do not use these anymore */
int action_get_touchscreen_press(short *x, short *y); int action_get_touchscreen_press(short *x, short *y);
int action_get_touchscreen_press_in_vp(short *x1, short *y1, struct viewport *vp); int action_get_touchscreen_press_in_vp(short *x1, short *y1, struct viewport *vp);