Просмотр исходного кода

Added functions to remove one recorded touch gesture, or all touch gestures.

Lasse Öörni 11 лет назад
Родитель
Сommit
6b7f1d842c

+ 10 - 0
Source/Engine/Input/Input.cpp

@@ -605,6 +605,16 @@ unsigned Input::LoadGestures(Deserializer& source)
     return SDL_LoadDollarTemplates(-1, wrapper.GetRWOps());
 }
 
+bool Input::RemoveGesture(unsigned gestureID)
+{
+    return SDL_RemoveDollarTemplate(gestureID);
+}
+
+void Input::RemoveAllGestures()
+{
+    SDL_RemoveAllDollarTemplates();
+}
+
 SDL_JoystickID Input::OpenJoystick(unsigned index)
 {
     SDL_Joystick* joystick = SDL_JoystickOpen(index);

+ 4 - 0
Source/Engine/Input/Input.h

@@ -154,6 +154,10 @@ public:
     bool SaveGesture(Serializer& dest, unsigned gestureID);
     /// Load touch gestures from a file. Return number of loaded gestures, or 0 on failure.
     unsigned LoadGestures(Deserializer& source);
+    /// Remove an in-memory gesture by ID. Return true if was found.
+    bool RemoveGesture(unsigned gestureID);
+    /// Remove all in-memory gestures.
+    void RemoveAllGestures();
 
     /// Return keycode from key name.
     int GetKeyFromName(const String& name) const;

+ 2 - 0
Source/Engine/LuaScript/pkgs/Input/Input.pkg

@@ -52,6 +52,8 @@ class Input : public Object
     tolua_outside bool InputSaveGestures @ SaveGestures(const String fileName);
     tolua_outside bool InputSaveGesture @ SaveGesture(const String fileName, unsigned gestureID);
     tolua_outside unsigned InputLoadGestures @ LoadGestures(const String fileName);
+    bool RemoveGesture(unsigned gestureID);
+    void RemoveAllGestures();
 
     int GetKeyFromName(const String name) const;
     int GetKeyFromScancode(int scancode) const;

+ 2 - 0
Source/Engine/Script/InputAPI.cpp

@@ -493,6 +493,8 @@ static void RegisterInput(asIScriptEngine* engine)
     engine->RegisterObjectMethod("Input", "bool SaveGesture(VectorBuffer&, uint)", asFUNCTION(InputSaveGestureVectorBuffer), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod("Input", "uint LoadGestures(File@+)", asFUNCTION(InputLoadGestures), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod("Input", "uint LoadGestures(VectorBuffer&)", asFUNCTION(InputLoadGesturesVectorBuffer), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectMethod("Input", "bool RemoveGesture(uint)", asMETHOD(Input, RemoveGesture), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Input", "void RemoveAllGestures()", asMETHOD(Input, RemoveAllGestures), asCALL_THISCALL);
     engine->RegisterObjectMethod("Input", "int GetKeyFromName(const String&in) const", asMETHOD(Input, GetKeyFromName), asCALL_THISCALL);
     engine->RegisterObjectMethod("Input", "int GetKeyFromScancode(int) const", asMETHOD(Input, GetKeyFromScancode), asCALL_THISCALL);
     engine->RegisterObjectMethod("Input", "String GetKeyName(int) const", asMETHOD(Input, GetKeyName), asCALL_THISCALL);

+ 6 - 0
Source/ThirdParty/SDL/include/SDL_gesture.h

@@ -19,6 +19,8 @@
   3. This notice may not be removed or altered from any source distribution.
 */
 
+// Modified by Lasse Oorni for Urho3D
+
 /**
  *  \file SDL_gesture.h
  *
@@ -76,6 +78,10 @@ extern DECLSPEC int SDLCALL SDL_SaveDollarTemplate(SDL_GestureID gestureId,SDL_R
 extern DECLSPEC int SDLCALL SDL_LoadDollarTemplates(SDL_TouchID touchId, SDL_RWops *src);
 
 
+// Urho3d: added functions
+extern DECLSPEC int SDLCALL SDL_RemoveDollarTemplate(SDL_GestureID gestureId);
+extern DECLSPEC void SDLCALL SDL_RemoveAllDollarTemplates(void);
+
 /* Ends C function definitions when using C++ */
 #ifdef __cplusplus
 }

+ 47 - 0
Source/ThirdParty/SDL/src/events/SDL_gesture.c

@@ -161,6 +161,53 @@ int SDL_SaveDollarTemplate(SDL_GestureID gestureId, SDL_RWops *dst)
     return SDL_SetError("Unknown gestureId");
 }
 
+// Urho3D: added function
+static void SDL_RemoveDollarTemplate_one(SDL_GestureTouch* inTouch, int index)
+{
+    if (index < inTouch->numDollarTemplates - 1) {
+        SDL_memmove(&inTouch->dollarTemplate[index], &inTouch->dollarTemplate[index + 1],
+            (inTouch->numDollarTemplates - 1 - index) * sizeof(SDL_DollarTemplate));
+    }
+    if (inTouch->numDollarTemplates > 1) {
+        inTouch->dollarTemplate = SDL_realloc(inTouch->dollarTemplate,
+            (inTouch->numDollarTemplates - 1) * sizeof(SDL_DollarTemplate));
+    }
+    else {
+        SDL_free(inTouch->dollarTemplate);
+        inTouch->dollarTemplate = NULL;
+    }
+    --inTouch->numDollarTemplates;
+}
+
+// Urho3D: added function
+int SDL_RemoveDollarTemplate(SDL_GestureID gestureId)
+{
+    int i,j,ret = 0;
+    for (i = 0; i < SDL_numGestureTouches; i++) {
+        SDL_GestureTouch* touch = &SDL_gestureTouch[i];
+        for (j = 0; j < touch->numDollarTemplates; j++) {
+            // Urho3D: gesture IDs are stored as 32bit, so check the low bits only
+            if ((touch->dollarTemplate[j].hash & 0xffffffff) == (gestureId & 0xffffffff)) {
+                SDL_RemoveDollarTemplate_one(touch, j);
+                ret = 1;
+            }
+        }
+    }
+    return ret;
+}
+
+// Urho3D: added function
+void SDL_RemoveAllDollarTemplates(void)
+{
+    int i;
+    for (i = 0; i < SDL_numGestureTouches; i++) {
+        SDL_GestureTouch* touch = &SDL_gestureTouch[i];
+        SDL_free(touch->dollarTemplate);
+        touch->dollarTemplate = NULL;
+        touch->numDollarTemplates = 0;
+    }
+}
+
 /* path is an already sampled set of points
 Returns the index of the gesture on success, or -1 */
 static int SDL_AddDollarGesture_one(SDL_GestureTouch* inTouch, SDL_FloatPoint* path)