MCPcopy Create free account
hub / github.com/diasurgical/devilution / preprocess_finger_motion

Function preprocess_finger_motion

SourceX/controls/touch.cpp:233–359  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

231}
232
233static void preprocess_finger_motion(SDL_Event *event)
234{
235 // front (0) or back (1) panel
236 SDL_TouchID port = event->tfinger.touchId;
237 // id (for multitouch)
238 SDL_FingerID id = event->tfinger.fingerId;
239
240 // find out how many fingers were down before this event
241 int num_fingers_down = 0;
242 for (int i = 0; i < MAX_NUM_FINGERS; i++) {
243 if (finger[port][i].id >= 0) {
244 num_fingers_down++;
245 }
246 }
247
248 if (num_fingers_down == 0) {
249 return;
250 }
251
252 if (num_fingers_down >= 1) {
253 int x = mouse_x;
254 int y = mouse_y;
255 int xrel = 0;
256 int yrel = 0;
257
258 if (direct_touch) {
259 x = event->tfinger.x * visible_width + x_borderwidth;
260 y = event->tfinger.y * visible_height + y_borderwidth;
261 dvl::OutputToLogical(&x, &y);
262 } else {
263 // for relative mode, use the pointer speed setting
264 float speedFactor = 1.0;
265
266 // convert touch events to relative mouse pointer events
267 // Whenever an SDL_event involving the mouse is processed,
268 x = (mouse_x + (event->tfinger.dx * 1.25 * speedFactor * dvl::GetOutputSurface()->w));
269 y = (mouse_y + (event->tfinger.dy * 1.25 * speedFactor * dvl::GetOutputSurface()->h));
270 }
271
272 x = clip(x, 0, dvl::GetOutputSurface()->w);
273 y = clip(y, 0, dvl::GetOutputSurface()->h);
274 xrel = x - mouse_x;
275 yrel = y - mouse_y;
276
277 // update the current finger's coordinates so we can track it later
278 for (int i = 0; i < MAX_NUM_FINGERS; i++) {
279 if (finger[port][i].id != id)
280 continue;
281 finger[port][i].last_x = x;
282 finger[port][i].last_y = y;
283 }
284
285 // If we are starting a multi-finger drag, start holding down the mouse button
286 if (num_fingers_down >= 2 && !multi_finger_dragging[port]) {
287 // only start a multi-finger drag if at least two fingers have been down long enough
288 int num_fingers_downlong = 0;
289 for (int i = 0; i < MAX_NUM_FINGERS; i++) {
290 if (finger[port][i].id == NO_TOUCH) {

Callers 1

preprocess_eventsFunction · 0.85

Calls 5

OutputToLogicalFunction · 0.85
GetOutputSurfaceFunction · 0.85
clipFunction · 0.85
set_mouse_button_eventFunction · 0.85
set_mouse_motion_eventFunction · 0.85

Tested by

no test coverage detected