From 8aae723853a73a69c334514f6b283fe3cfdee810 Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Tue, 12 Jul 2022 13:38:02 +0100 Subject: [PATCH] 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 --- apps/action.c | 25 +++++++++++++++++++++++++ apps/action.h | 13 +++++++++++++ 2 files changed, 38 insertions(+) diff --git a/apps/action.c b/apps/action.c index 3bd5d062f1..aa21a61222 100644 --- a/apps/action.c +++ b/apps/action.c @@ -104,6 +104,7 @@ typedef struct int ts_data; long ts_start_tick; struct touchevent touchevent; + struct gesture gesture; #endif } 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.tick = last->tick; + /* Update gesture state */ + gesture_process(&last->gesture, &last->touchevent); + return true; } else @@ -1151,6 +1155,27 @@ int action_get_touch_event(struct touchevent *ev) 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 * BUTTON_REPEAT if repeated press * BUTTON_REPEAT|BUTTON_REL if release after repeated press diff --git a/apps/action.h b/apps/action.h index d4ceefb3c5..36f5901b84 100644 --- a/apps/action.h +++ b/apps/action.h @@ -23,6 +23,7 @@ #include "stdbool.h" #include "button.h" #include "viewport.h" +#include "gesture.h" #define TIMEOUT_BLOCK -1 #define TIMEOUT_NOBLOCK 0 @@ -418,6 +419,18 @@ intptr_t get_action_data(void); /* Return a touch event and screen coordinates of the touch. */ 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 */ int action_get_touchscreen_press(short *x, short *y); int action_get_touchscreen_press_in_vp(short *x1, short *y1, struct viewport *vp);