فهرست منبع

hapticFeedback

Michael 2 سال پیش
والد
کامیت
a5fe6cc80b
2فایلهای تغییر یافته به همراه15 افزوده شده و 0 حذف شده
  1. 13 0
      client/eventsSDL/InputSourceTouch.cpp
  2. 2 0
      client/eventsSDL/InputSourceTouch.h

+ 13 - 0
client/eventsSDL/InputSourceTouch.cpp

@@ -22,6 +22,10 @@
 #include "../gui/MouseButton.h"
 #include "../gui/WindowHandler.h"
 
+#ifdef VCMI_ANDROID
+#include "../../lib/CAndroidVMHelper.h"
+#endif
+
 #include <SDL_events.h>
 #include <SDL_hints.h>
 #include <SDL_timer.h>
@@ -166,6 +170,7 @@ void InputSourceTouch::handleEventFingerUp(const SDL_TouchFingerEvent & tfinger)
 			GH.input().setCursorPosition(convertTouchToMouse(tfinger));
 			GH.events().dispatchMouseLeftButtonPressed(convertTouchToMouse(tfinger));
 			GH.events().dispatchMouseLeftButtonReleased(convertTouchToMouse(tfinger));
+			hapticFeedback();
 			state = TouchState::IDLE;
 			break;
 		}
@@ -215,6 +220,7 @@ void InputSourceTouch::handleUpdate()
 		if (currentTime > lastTapTimeTicks + params.longTouchTimeMilliseconds)
 		{
 			GH.events().dispatchShowPopup(GH.getCursorPosition());
+			hapticFeedback();
 
 			if (GH.windows().isTopWindowPopup())
 				state = TouchState::TAP_DOWN_LONG;
@@ -287,3 +293,10 @@ void InputSourceTouch::emitPinchEvent(const SDL_TouchFingerEvent & tfinger)
 	if (distanceOld > params.pinchSensitivityThreshold)
 		GH.events().dispatchGesturePinch(lastTapPosition, distanceNew / distanceOld);
 }
+
+void InputSourceTouch::hapticFeedback() {
+#if defined(VCMI_ANDROID)
+    CAndroidVMHelper vmHelper;
+    vmHelper.callStaticVoidMethod(CAndroidVMHelper::NATIVE_METHODS_DEFAULT_CLASS, "hapticFeedback");
+#endif
+}

+ 2 - 0
client/eventsSDL/InputSourceTouch.h

@@ -94,6 +94,8 @@ class InputSourceTouch
 
 	void emitPanningEvent(const SDL_TouchFingerEvent & tfinger);
 	void emitPinchEvent(const SDL_TouchFingerEvent & tfinger);
+	
+	void hapticFeedback();
 
 public:
 	InputSourceTouch();