| | |
| | | /* |
| | | Simple DirectMedia Layer |
| | | Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org> |
| | | Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> |
| | | |
| | | This software is provided 'as-is', without any express or implied |
| | | warranty. In no event will the authors be held liable for any damages |
| | |
| | | |
| | | #define MAXPATHSIZE 1024 |
| | | |
| | | #define DOLLARNPOINTS 64 |
| | | #define DOLLARSIZE 256 |
| | | |
| | | #define ENABLE_DOLLAR |
| | | |
| | | #define PHI 0.618033989 |
| | | #define DOLLARNPOINTS 64 |
| | | |
| | | #if defined(ENABLE_DOLLAR) |
| | | # define DOLLARSIZE 256 |
| | | # define PHI 0.618033989 |
| | | #endif |
| | | |
| | | typedef struct { |
| | | float x,y; |
| | |
| | | } |
| | | |
| | | |
| | | #if defined(ENABLE_DOLLAR) |
| | | static float dollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ,float ang) |
| | | { |
| | | /* SDL_FloatPoint p[DOLLARNPOINTS]; */ |
| | |
| | | } |
| | | |
| | | /* DollarPath contains raw points, plus (possibly) the calculated length */ |
| | | static int dollarNormalize(const SDL_DollarPath *path,SDL_FloatPoint *points) |
| | | static int dollarNormalize(const SDL_DollarPath *path,SDL_FloatPoint *points, SDL_bool is_recording) |
| | | { |
| | | int i; |
| | | float interval; |
| | |
| | | dist += d; |
| | | } |
| | | if (numPoints < DOLLARNPOINTS-1) { |
| | | SDL_SetError("ERROR: NumPoints = %i", numPoints); |
| | | if (is_recording) { |
| | | SDL_SetError("ERROR: NumPoints = %i", numPoints); |
| | | } |
| | | return 0; |
| | | } |
| | | /* copy the last point */ |
| | |
| | | |
| | | SDL_memset(points, 0, sizeof(points)); |
| | | |
| | | dollarNormalize(path,points); |
| | | dollarNormalize(path, points, SDL_FALSE); |
| | | |
| | | /* PrintPath(points); */ |
| | | *bestTempl = -1; |
| | |
| | | } |
| | | return bestDiff; |
| | | } |
| | | #endif |
| | | |
| | | int SDL_GestureAddTouch(SDL_TouchID touchId) |
| | | { |
| | |
| | | return NULL; |
| | | } |
| | | |
| | | static int SDL_SendGestureMulti(SDL_GestureTouch* touch,float dTheta,float dDist) |
| | | static void SDL_SendGestureMulti(SDL_GestureTouch* touch,float dTheta,float dDist) |
| | | { |
| | | SDL_Event event; |
| | | event.mgesture.type = SDL_MULTIGESTURE; |
| | | event.mgesture.touchId = touch->id; |
| | | event.mgesture.x = touch->centroid.x; |
| | | event.mgesture.y = touch->centroid.y; |
| | | event.mgesture.dTheta = dTheta; |
| | | event.mgesture.dDist = dDist; |
| | | event.mgesture.numFingers = touch->numDownFingers; |
| | | return SDL_PushEvent(&event) > 0; |
| | | if (SDL_GetEventState(SDL_MULTIGESTURE) == SDL_ENABLE) { |
| | | SDL_Event event; |
| | | event.mgesture.type = SDL_MULTIGESTURE; |
| | | event.mgesture.touchId = touch->id; |
| | | event.mgesture.x = touch->centroid.x; |
| | | event.mgesture.y = touch->centroid.y; |
| | | event.mgesture.dTheta = dTheta; |
| | | event.mgesture.dDist = dDist; |
| | | event.mgesture.numFingers = touch->numDownFingers; |
| | | SDL_PushEvent(&event); |
| | | } |
| | | } |
| | | |
| | | static int SDL_SendGestureDollar(SDL_GestureTouch* touch, |
| | | #if defined(ENABLE_DOLLAR) |
| | | static void SDL_SendGestureDollar(SDL_GestureTouch* touch, |
| | | SDL_GestureID gestureId,float error) |
| | | { |
| | | SDL_Event event; |
| | | event.dgesture.type = SDL_DOLLARGESTURE; |
| | | event.dgesture.touchId = touch->id; |
| | | event.dgesture.x = touch->centroid.x; |
| | | event.dgesture.y = touch->centroid.y; |
| | | event.dgesture.gestureId = gestureId; |
| | | event.dgesture.error = error; |
| | | /* A finger came up to trigger this event. */ |
| | | event.dgesture.numFingers = touch->numDownFingers + 1; |
| | | return SDL_PushEvent(&event) > 0; |
| | | if (SDL_GetEventState(SDL_DOLLARGESTURE) == SDL_ENABLE) { |
| | | SDL_Event event; |
| | | event.dgesture.type = SDL_DOLLARGESTURE; |
| | | event.dgesture.touchId = touch->id; |
| | | event.dgesture.x = touch->centroid.x; |
| | | event.dgesture.y = touch->centroid.y; |
| | | event.dgesture.gestureId = gestureId; |
| | | event.dgesture.error = error; |
| | | /* A finger came up to trigger this event. */ |
| | | event.dgesture.numFingers = touch->numDownFingers + 1; |
| | | SDL_PushEvent(&event); |
| | | } |
| | | } |
| | | |
| | | |
| | | static int SDL_SendDollarRecord(SDL_GestureTouch* touch,SDL_GestureID gestureId) |
| | | static void SDL_SendDollarRecord(SDL_GestureTouch* touch,SDL_GestureID gestureId) |
| | | { |
| | | SDL_Event event; |
| | | event.dgesture.type = SDL_DOLLARRECORD; |
| | | event.dgesture.touchId = touch->id; |
| | | event.dgesture.gestureId = gestureId; |
| | | return SDL_PushEvent(&event) > 0; |
| | | if (SDL_GetEventState(SDL_DOLLARRECORD) == SDL_ENABLE) { |
| | | SDL_Event event; |
| | | event.dgesture.type = SDL_DOLLARRECORD; |
| | | event.dgesture.touchId = touch->id; |
| | | event.dgesture.gestureId = gestureId; |
| | | SDL_PushEvent(&event); |
| | | } |
| | | } |
| | | #endif |
| | | |
| | | |
| | | void SDL_GestureProcessEvent(SDL_Event* event) |
| | | { |
| | | float x,y; |
| | | #if defined(ENABLE_DOLLAR) |
| | | int index; |
| | | int i; |
| | | float pathDx, pathDy; |
| | | #endif |
| | | SDL_FloatPoint lastP; |
| | | SDL_FloatPoint lastCentroid; |
| | | float lDist; |
| | |
| | | |
| | | /* Finger Up */ |
| | | if (event->type == SDL_FINGERUP) { |
| | | #if defined(ENABLE_DOLLAR) |
| | | SDL_FloatPoint path[DOLLARNPOINTS]; |
| | | #endif |
| | | |
| | | inTouch->numDownFingers--; |
| | | |
| | | #ifdef ENABLE_DOLLAR |
| | | #if defined(ENABLE_DOLLAR) |
| | | if (inTouch->recording) { |
| | | inTouch->recording = SDL_FALSE; |
| | | dollarNormalize(&inTouch->dollarPath,path); |
| | | dollarNormalize(&inTouch->dollarPath, path, SDL_TRUE); |
| | | /* PrintPath(path); */ |
| | | if (recordAll) { |
| | | index = SDL_AddDollarGesture(NULL,path); |
| | |
| | | else if (event->type == SDL_FINGERMOTION) { |
| | | float dx = event->tfinger.dx; |
| | | float dy = event->tfinger.dy; |
| | | #ifdef ENABLE_DOLLAR |
| | | #if defined(ENABLE_DOLLAR) |
| | | SDL_DollarPath* path = &inTouch->dollarPath; |
| | | if (path->numPoints < MAXPATHSIZE) { |
| | | path->p[path->numPoints].x = inTouch->centroid.x; |
| | |
| | | /* printf("Finger Down: (%f,%f). Centroid: (%f,%f\n",x,y, |
| | | inTouch->centroid.x,inTouch->centroid.y); */ |
| | | |
| | | #ifdef ENABLE_DOLLAR |
| | | #if defined(ENABLE_DOLLAR) |
| | | inTouch->dollarPath.length = 0; |
| | | inTouch->dollarPath.p[0].x = x; |
| | | inTouch->dollarPath.p[0].y = y; |