Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

touchscreen: Add gesture velocity helper

Add a helper for computing the motion velocity during a touchscreen press.

Change-Id: I1ef7452ba9815897fd3ec01f8980c89aeef5418f

authored by

Aidan MacDonald and committed by
Solomon Peachy
bb1e0b48 7aa82321

+76
+62
apps/gesture.c
··· 119 119 120 120 return !vp || viewport_point_within_vp(vp, g->ox, g->oy); 121 121 } 122 + 123 + /* 124 + * gesture velocity helper 125 + */ 126 + 127 + void gesture_vel_reset(struct gesture_vel *gv) 128 + { 129 + gv->idx = 0; 130 + gv->cnt = 0; 131 + } 132 + 133 + void gesture_vel_process(struct gesture_vel *gv, const struct touchevent *ev) 134 + { 135 + if (ev->type != TOUCHEVENT_PRESS && 136 + ev->type != TOUCHEVENT_CONTACT) 137 + return; 138 + 139 + gv->xsamp[gv->idx] = ev->x; 140 + gv->ysamp[gv->idx] = ev->y; 141 + gv->tsamp[gv->idx] = ev->tick; 142 + 143 + gv->idx++; 144 + gv->cnt++; 145 + 146 + if (gv->idx >= ARRAYLEN(gv->xsamp)) 147 + gv->idx = 0; 148 + } 149 + 150 + bool gesture_vel_get(struct gesture_vel *gv, int *xvel, int *yvel) 151 + { 152 + if (gv->cnt <= 1) { 153 + *xvel = 0; 154 + *yvel = 0; 155 + return false; 156 + } 157 + 158 + int dx = 0, dy = 0, dt = 0; 159 + size_t n = MIN(gv->cnt, ARRAYLEN(gv->xsamp)) - 1; 160 + size_t i = gv->cnt < ARRAYLEN(gv->xsamp) ? 0 : gv->idx; 161 + size_t ip = i + 1; 162 + while (n-- > 0) { 163 + if (ip >= ARRAYLEN(gv->xsamp)) 164 + ip = 0; 165 + 166 + dx += gv->xsamp[ip] - gv->xsamp[i]; 167 + dy += gv->ysamp[ip] - gv->ysamp[i]; 168 + dt += gv->tsamp[ip] - gv->tsamp[i]; 169 + 170 + i = ip; 171 + ip++; 172 + } 173 + 174 + if (dt == 0) { 175 + *xvel = 0; 176 + *yvel = 0; 177 + } else { 178 + *xvel = dx * HZ / dt; 179 + *yvel = dy * HZ / dt; 180 + } 181 + 182 + return gv->cnt >= ARRAYLEN(gv->xsamp); 183 + }
+14
apps/gesture.h
··· 120 120 return !!(g->flags & GESTURE_F_PRESSED); 121 121 } 122 122 123 + /* Helper for computing velocity vectors */ 124 + struct gesture_vel 125 + { 126 + size_t idx; 127 + size_t cnt; 128 + short xsamp[4]; 129 + short ysamp[4]; 130 + long tsamp[4]; 131 + }; 132 + 133 + void gesture_vel_reset(struct gesture_vel *gv); 134 + void gesture_vel_process(struct gesture_vel *gv, const struct touchevent *ev); 135 + bool gesture_vel_get(struct gesture_vel *gv, int *xvel, int *yvel); 136 + 123 137 #endif /* _GESTURE_H_ */