Skip to content
This repository
Browse code

[win32] use generic touch input (adds swipe, rotate and zoom gestures)

  • Loading branch information...
commit b941ff3a1b87e73a8315c93f5e88060a29a640d3 1 parent 7cb5e1a
Sascha Montellese authored March 31, 2013
14  project/VS2010Express/XBMC.vcxproj
@@ -701,6 +701,9 @@
701 701
     <ClCompile Include="..\..\xbmc\input\KeyboardLayoutConfiguration.cpp" />
702 702
     <ClCompile Include="..\..\xbmc\input\KeyboardStat.cpp" />
703 703
     <ClCompile Include="..\..\xbmc\input\MouseStat.cpp" />
  704
+    <ClCompile Include="..\..\xbmc\input\touch\generic\GenericTouchActionHandler.cpp" />
  705
+    <ClCompile Include="..\..\xbmc\input\touch\generic\GenericTouchSwipeDetector.cpp" />
  706
+    <ClCompile Include="..\..\xbmc\input\touch\ITouchInputHandling.cpp" />
704 707
     <ClCompile Include="..\..\xbmc\input\windows\IRServerSuite.cpp" />
705 708
     <ClCompile Include="..\..\xbmc\input\windows\IrssMessage.cpp" />
706 709
     <ClCompile Include="..\..\xbmc\input\windows\WINJoystick.cpp" />
@@ -1048,6 +1051,13 @@
1048 1051
     <ClInclude Include="..\..\xbmc\guilib\GUIKeyboardFactory.h" />
1049 1052
     <ClInclude Include="..\..\xbmc\guilib\iimage.h" />
1050 1053
     <ClInclude Include="..\..\xbmc\guilib\imagefactory.h" />
  1054
+    <ClInclude Include="..\..\xbmc\input\touch\generic\GenericTouchActionHandler.h" />
  1055
+    <ClInclude Include="..\..\xbmc\input\touch\generic\GenericTouchSwipeDetector.h" />
  1056
+    <ClInclude Include="..\..\xbmc\input\touch\generic\IGenericTouchGestureDetector.h" />
  1057
+    <ClInclude Include="..\..\xbmc\input\touch\ITouchActionHandler.h" />
  1058
+    <ClInclude Include="..\..\xbmc\input\touch\ITouchInputHandler.h" />
  1059
+    <ClInclude Include="..\..\xbmc\input\touch\ITouchInputHandling.h" />
  1060
+    <ClInclude Include="..\..\xbmc\input\touch\TouchTypes.h" />
1051 1061
     <ClInclude Include="..\..\xbmc\input\windows\WINJoystick.h" />
1052 1062
     <ClInclude Include="..\..\xbmc\interfaces\json-rpc\PVROperations.h" />
1053 1063
     <ClInclude Include="..\..\xbmc\interfaces\legacy\Addon.h" />
@@ -1114,6 +1124,7 @@
1114 1124
     <ClInclude Include="..\..\xbmc\settings\windows\GUIWindowTestPattern.h" />
1115 1125
     <ClInclude Include="..\..\xbmc\utils\IRssObserver.h" />
1116 1126
     <ClInclude Include="..\..\xbmc\utils\RssManager.h" />
  1127
+    <ClInclude Include="..\..\xbmc\utils\Vector.h" />
1117 1128
     <ClInclude Include="..\..\xbmc\video\FFmpegVideoDecoder.h" />
1118 1129
     <ClInclude Include="..\..\xbmc\interfaces\python\swig.h" />
1119 1130
     <ClInclude Include="..\..\xbmc\interfaces\python\XBPython.h" />
@@ -1257,6 +1268,7 @@
1257 1268
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release (OpenGL)|Win32'">true</ExcludedFromBuild>
1258 1269
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Template|Win32'">true</ExcludedFromBuild>
1259 1270
     </ClCompile>
  1271
+    <ClCompile Include="..\..\xbmc\utils\Vector.cpp" />
1260 1272
     <ClCompile Include="..\..\xbmc\video\VideoThumbLoader.cpp" />
1261 1273
     <ClCompile Include="..\..\xbmc\music\MusicThumbLoader.cpp" />
1262 1274
     <ClCompile Include="..\..\xbmc\ThumbnailCache.cpp" />
@@ -2963,4 +2975,4 @@
2963 2975
     </VisualStudio>
2964 2976
   </ProjectExtensions>
2965 2977
   <Import Project="$(SolutionDir)\$(ProjectFileName).targets.user" Condition="Exists('$(SolutionDir)\$(ProjectFileName).targets.user')" />
2966  
-</Project>
  2978
+</Project>
44  project/VS2010Express/XBMC.vcxproj.filters
@@ -295,6 +295,12 @@
295 295
     <Filter Include="profiles\windows">
296 296
       <UniqueIdentifier>{b5a6d872-7e56-4976-81c5-47baad252337}</UniqueIdentifier>
297 297
     </Filter>
  298
+    <Filter Include="input\touch">
  299
+      <UniqueIdentifier>{4e236b17-3720-4ed8-89af-90cb86bf9b03}</UniqueIdentifier>
  300
+    </Filter>
  301
+    <Filter Include="input\touch\generic">
  302
+      <UniqueIdentifier>{d062c356-66f2-49e7-9510-b216701d2298}</UniqueIdentifier>
  303
+    </Filter>
298 304
   </ItemGroup>
299 305
   <ItemGroup>
300 306
     <ClCompile Include="..\..\xbmc\win32\pch.cpp">
@@ -3000,6 +3006,18 @@
3000 3006
     <ClCompile Include="..\..\xbmc\profiles\ProfilesManager.cpp">
3001 3007
       <Filter>profiles</Filter>
3002 3008
     </ClCompile>
  3009
+    <ClCompile Include="..\..\xbmc\input\touch\generic\GenericTouchActionHandler.cpp">
  3010
+      <Filter>input\touch\generic</Filter>
  3011
+    </ClCompile>
  3012
+    <ClCompile Include="..\..\xbmc\input\touch\generic\GenericTouchSwipeDetector.cpp">
  3013
+      <Filter>input\touch\generic</Filter>
  3014
+    </ClCompile>
  3015
+    <ClCompile Include="..\..\xbmc\input\touch\ITouchInputHandling.cpp">
  3016
+      <Filter>input\touch</Filter>
  3017
+    </ClCompile>
  3018
+    <ClCompile Include="..\..\xbmc\utils\Vector.cpp">
  3019
+      <Filter>utils</Filter>
  3020
+    </ClCompile>
3003 3021
   </ItemGroup>
3004 3022
   <ItemGroup>
3005 3023
     <ClInclude Include="..\..\xbmc\win32\pch.h">
@@ -5858,6 +5876,30 @@
5858 5876
     <ClInclude Include="..\..\xbmc\profiles\ProfilesManager.h">
5859 5877
       <Filter>profiles</Filter>
5860 5878
     </ClInclude>
  5879
+    <ClInclude Include="..\..\xbmc\input\touch\ITouchActionHandler.h">
  5880
+      <Filter>input\touch</Filter>
  5881
+    </ClInclude>
  5882
+    <ClInclude Include="..\..\xbmc\input\touch\generic\GenericTouchActionHandler.h">
  5883
+      <Filter>input\touch\generic</Filter>
  5884
+    </ClInclude>
  5885
+    <ClInclude Include="..\..\xbmc\input\touch\TouchTypes.h">
  5886
+      <Filter>input\touch</Filter>
  5887
+    </ClInclude>
  5888
+    <ClInclude Include="..\..\xbmc\input\touch\generic\GenericTouchSwipeDetector.h">
  5889
+      <Filter>input\touch\generic</Filter>
  5890
+    </ClInclude>
  5891
+    <ClInclude Include="..\..\xbmc\input\touch\generic\IGenericTouchGestureDetector.h">
  5892
+      <Filter>input\touch\generic</Filter>
  5893
+    </ClInclude>
  5894
+    <ClInclude Include="..\..\xbmc\input\touch\ITouchInputHandler.h">
  5895
+      <Filter>input\touch</Filter>
  5896
+    </ClInclude>
  5897
+    <ClInclude Include="..\..\xbmc\input\touch\ITouchInputHandling.h">
  5898
+      <Filter>input\touch</Filter>
  5899
+    </ClInclude>
  5900
+    <ClInclude Include="..\..\xbmc\utils\Vector.h">
  5901
+      <Filter>utils</Filter>
  5902
+    </ClInclude>
5861 5903
   </ItemGroup>
5862 5904
   <ItemGroup>
5863 5905
     <ResourceCompile Include="..\..\xbmc\win32\XBMC_PC.rc">
@@ -5889,4 +5931,4 @@
5889 5931
       <Filter>interfaces\swig</Filter>
5890 5932
     </None>
5891 5933
   </ItemGroup>
5892  
-</Project>
  5934
+</Project>
6  xbmc/input/touch/generic/GenericTouchSwipeDetector.cpp
@@ -161,6 +161,12 @@ bool CGenericTouchSwipeDetector::OnTouchMove(unsigned int index, const Pointer &
161 161
     else if (deltaYabs > m_dpi * SWIPE_MIN_DISTANCE)
162 162
       m_swipeDetected = true;
163 163
   }
  164
+
  165
+  if (m_directions == TouchMoveDirectionNone)
  166
+  {
  167
+    m_done = true;
  168
+    return false;
  169
+  }
164 170
   
165 171
   return true;
166 172
 }
140  xbmc/windowing/windows/WinEventsWin32.cpp
@@ -18,6 +18,11 @@
18 18
 *
19 19
 */
20 20
 
  21
+#ifndef _USE_MATH_DEFINES
  22
+#define _USE_MATH_DEFINES
  23
+#endif
  24
+#include <math.h>
  25
+
21 26
 #include "utils/log.h"
22 27
 #include "Windowsx.h"
23 28
 #include "windowing/WinEvents.h"
@@ -26,6 +31,8 @@
26 31
 #include "Application.h"
27 32
 #include "input/XBMC_vkeys.h"
28 33
 #include "input/MouseStat.h"
  34
+#include "input/touch/generic/GenericTouchActionHandler.h"
  35
+#include "input/touch/generic/GenericTouchSwipeDetector.h"
29 36
 #include "input/windows/WINJoystick.h"
30 37
 #include "storage/MediaManager.h"
31 38
 #include "windowing/WindowingFactory.h"
@@ -49,6 +56,12 @@ using namespace PERIPHERALS;
49 56
 
50 57
 HWND g_hWnd = NULL;
51 58
 
  59
+#ifndef LODWORD
  60
+#define LODWORD(longval) ((DWORD)((DWORDLONG)(longval)))
  61
+#endif
  62
+
  63
+#define ROTATE_ANGLE_DEGREE(arg) GID_ROTATE_ANGLE_FROM_ARGUMENT(LODWORD(arg)) * 180 / M_PI
  64
+
52 65
 #define XBMC_arraysize(array)	(sizeof(array)/sizeof(array[0]))
53 66
 
54 67
 /* Masks for processing the windows KEYDOWN and KEYUP messages */
@@ -65,8 +78,9 @@ uint32_t g_uQueryCancelAutoPlay = 0;
65 78
 int XBMC_TranslateUNICODE = 1;
66 79
 
67 80
 PHANDLE_EVENT_FUNC CWinEventsWin32::m_pEventFunc = NULL;
68  
-int CWinEventsWin32::m_lastGesturePosX = 0;
69  
-int CWinEventsWin32::m_lastGesturePosY = 0;
  81
+int CWinEventsWin32::m_originalZoomDistance = 0;
  82
+Pointer CWinEventsWin32::m_touchPointer;
  83
+CGenericTouchSwipeDetector* CWinEventsWin32::m_touchSwipeDetector = NULL;
70 84
 
71 85
 // register to receive SD card events (insert/remove)
72 86
 // seen at http://www.codeproject.com/Messages/2897423/Re-No-message-triggered-on-SD-card-insertion-remov.aspx
@@ -815,33 +829,41 @@ void CWinEventsWin32::OnGestureNotify(HWND hWnd, LPARAM lParam)
815 829
   POINT point = { gn->ptsLocation.x, gn->ptsLocation.y };
816 830
   WindowFromScreenCoords(hWnd, &point);
817 831
 
818  
-  // by default that we want no gestures
  832
+  // by default we only want twofingertap and pressandtap gestures
  833
+  // the other gestures are enabled best on supported gestures
819 834
   GESTURECONFIG gc[] = {{ GID_ZOOM, 0, GC_ZOOM},
820 835
                         { GID_ROTATE, 0, GC_ROTATE},
821 836
                         { GID_PAN, 0, GC_PAN},
822  
-                        { GID_TWOFINGERTAP, 0, GC_TWOFINGERTAP },
823  
-                        { GID_PRESSANDTAP, 0, GC_PRESSANDTAP }};
  837
+                        { GID_TWOFINGERTAP, GC_TWOFINGERTAP, GC_TWOFINGERTAP },
  838
+                        { GID_PRESSANDTAP, GC_PRESSANDTAP, GC_PRESSANDTAP }};
824 839
 
825 840
   // send a message to see if a control wants any
826  
-  CGUIMessage message(GUI_MSG_GESTURE_NOTIFY, 0, 0, point.x, point.y);
827  
-  if (g_windowManager.SendMessage(message))
  841
+  int gestures = 0;
  842
+  if ((gestures = CGenericTouchActionHandler::Get().QuerySupportedGestures((float)point.x, (float)point.y)) != EVENT_RESULT_UNHANDLED)
828 843
   {
829  
-    int gestures = message.GetParam1();
830 844
     if (gestures & EVENT_RESULT_ZOOM)
831 845
       gc[0].dwWant |= GC_ZOOM;
832 846
     if (gestures & EVENT_RESULT_ROTATE)
833 847
       gc[1].dwWant |= GC_ROTATE;
834 848
     if (gestures & EVENT_RESULT_PAN_VERTICAL)
835  
-      gc[2].dwWant |= GC_PAN_WITH_SINGLE_FINGER_VERTICALLY | GC_PAN_WITH_GUTTER | GC_PAN_WITH_INERTIA;
  849
+      gc[2].dwWant |= GC_PAN | GC_PAN_WITH_SINGLE_FINGER_VERTICALLY | GC_PAN_WITH_GUTTER | GC_PAN_WITH_INERTIA;
836 850
     if (gestures & EVENT_RESULT_PAN_VERTICAL_WITHOUT_INERTIA)
837  
-      gc[2].dwWant |= GC_PAN_WITH_SINGLE_FINGER_VERTICALLY;
  851
+      gc[2].dwWant |= GC_PAN | GC_PAN_WITH_SINGLE_FINGER_VERTICALLY;
838 852
     if (gestures & EVENT_RESULT_PAN_HORIZONTAL)
839  
-      gc[2].dwWant |= GC_PAN_WITH_SINGLE_FINGER_HORIZONTALLY | GC_PAN_WITH_GUTTER | GC_PAN_WITH_INERTIA;
  853
+      gc[2].dwWant |= GC_PAN | GC_PAN_WITH_SINGLE_FINGER_HORIZONTALLY | GC_PAN_WITH_GUTTER | GC_PAN_WITH_INERTIA;
840 854
     if (gestures & EVENT_RESULT_PAN_HORIZONTAL_WITHOUT_INERTIA)
841  
-      gc[2].dwWant |= GC_PAN_WITH_SINGLE_FINGER_HORIZONTALLY;
842  
-    gc[0].dwBlock = gc[0].dwWant ^ 1;
843  
-    gc[1].dwBlock = gc[1].dwWant ^ 1;
844  
-    gc[2].dwBlock = gc[2].dwWant ^ 30;
  855
+      gc[2].dwWant |= GC_PAN | GC_PAN_WITH_SINGLE_FINGER_HORIZONTALLY;
  856
+    if (gestures & EVENT_RESULT_SWIPE)
  857
+    {
  858
+      gc[2].dwWant |= GC_PAN | GC_PAN_WITH_SINGLE_FINGER_VERTICALLY | GC_PAN_WITH_SINGLE_FINGER_HORIZONTALLY | GC_PAN_WITH_GUTTER;
  859
+
  860
+      // create a new touch swipe detector
  861
+      m_touchSwipeDetector = new CGenericTouchSwipeDetector(&CGenericTouchActionHandler::Get(), 160.0f);
  862
+    }
  863
+
  864
+    gc[0].dwBlock = gc[0].dwWant ^ 0x01;
  865
+    gc[1].dwBlock = gc[1].dwWant ^ 0x01;
  866
+    gc[2].dwBlock = gc[2].dwWant ^ 0x1F;
845 867
   }
846 868
   if (g_Windowing.PtrSetGestureConfig)
847 869
     g_Windowing.PtrSetGestureConfig(hWnd, 0, 5, gc, sizeof(GESTURECONFIG));
@@ -859,35 +881,99 @@ void CWinEventsWin32::OnGesture(HWND hWnd, LPARAM lParam)
859 881
   // convert to window coordinates
860 882
   POINT point = { gi.ptsLocation.x, gi.ptsLocation.y };
861 883
   WindowFromScreenCoords(hWnd, &point);
  884
+
  885
+  if (gi.dwID == GID_BEGIN)
  886
+    m_touchPointer.reset();
  887
+
  888
+  // if there's a "current" touch from a previous event, copy it to "last"
  889
+  if (m_touchPointer.current.valid())
  890
+    m_touchPointer.last = m_touchPointer.current;
  891
+
  892
+  // set the "current" touch
  893
+  m_touchPointer.current.x = (float)point.x;
  894
+  m_touchPointer.current.y = (float)point.y;
  895
+  m_touchPointer.current.time = time(NULL);
  896
+
862 897
   switch (gi.dwID)
863 898
   {
864 899
   case GID_BEGIN:
865 900
     {
866  
-      m_lastGesturePosX = point.x;
867  
-      m_lastGesturePosY = point.y;
868  
-      g_application.OnAction(CAction(ACTION_GESTURE_BEGIN, 0, (float)point.x, (float)point.y, 0, 0));
  901
+      // set the "down" touch
  902
+      m_touchPointer.down = m_touchPointer.current;
  903
+      m_originalZoomDistance = 0;
  904
+
  905
+      CGenericTouchActionHandler::Get().OnTouchGestureStart((float)point.x, (float)point.y);
869 906
     }
870 907
     break;
  908
+
871 909
   case GID_END:
872  
-    {
873  
-      g_application.OnAction(CAction(ACTION_GESTURE_END));
874  
-    }
  910
+    CGenericTouchActionHandler::Get().OnTouchGestureEnd((float)point.x, (float)point.y, 0.0f, 0.0f, 0.0f, 0.0f);
875 911
     break;
  912
+
876 913
   case GID_PAN:
877 914
     {
878  
-      g_application.OnAction(CAction(ACTION_GESTURE_PAN, 0, (float)point.x, (float)point.y,
879  
-                                    (float)(point.x - m_lastGesturePosX), (float)(point.y - m_lastGesturePosY)));
880  
-      m_lastGesturePosX = point.x;
881  
-      m_lastGesturePosY = point.y;
  915
+      if (!m_touchPointer.moving)
  916
+        m_touchPointer.moving = true;
  917
+
  918
+      // calculate the velocity of the pan gesture
  919
+      float velocityX, velocityY;
  920
+      m_touchPointer.velocity(velocityX, velocityY);
  921
+
  922
+      CGenericTouchActionHandler::Get().OnTouchGesturePan(m_touchPointer.current.x, m_touchPointer.current.y,
  923
+                                                          m_touchPointer.current.x - m_touchPointer.last.x, m_touchPointer.current.y - m_touchPointer.last.y,
  924
+                                                          velocityX, velocityY);
  925
+
  926
+      if (m_touchSwipeDetector != NULL)
  927
+      {
  928
+        if (gi.dwFlags & GF_BEGIN)
  929
+        {
  930
+          m_touchPointer.down = m_touchPointer.current;
  931
+          m_touchSwipeDetector->OnTouchDown(0, m_touchPointer);
  932
+        }
  933
+        else if (gi.dwFlags & GF_END)
  934
+        {
  935
+          m_touchSwipeDetector->OnTouchUp(0, m_touchPointer);
  936
+
  937
+          delete m_touchSwipeDetector;
  938
+          m_touchSwipeDetector = NULL;
  939
+        }
  940
+        else
  941
+          m_touchSwipeDetector->OnTouchMove(0, m_touchPointer);
  942
+      }
882 943
     }
883 944
     break;
  945
+
884 946
   case GID_ROTATE:
885  
-    CLog::Log(LOGDEBUG, "%s - Rotating", __FUNCTION__);
  947
+    {
  948
+      if (gi.dwFlags == GF_BEGIN)
  949
+        break;
  950
+
  951
+      CGenericTouchActionHandler::Get().OnRotate((float)point.x, (float)point.y,
  952
+                                                 -(float)ROTATE_ANGLE_DEGREE(gi.ullArguments));
  953
+    }
886 954
     break;
  955
+
887 956
   case GID_ZOOM:
888  
-    CLog::Log(LOGDEBUG, "%s - Zooming", __FUNCTION__);
  957
+    {
  958
+      if (gi.dwFlags == GF_BEGIN)
  959
+      {
  960
+        m_originalZoomDistance = (int)LODWORD(gi.ullArguments);
  961
+        break;
  962
+      }
  963
+
  964
+      // avoid division by 0
  965
+      if (m_originalZoomDistance == 0)
  966
+        break;
  967
+
  968
+      CGenericTouchActionHandler::Get().OnZoomPinch((float)point.x, (float)point.y,
  969
+                                                    (float)LODWORD(gi.ullArguments) / (float)m_originalZoomDistance);
  970
+    }
889 971
     break;
  972
+
890 973
   case GID_TWOFINGERTAP:
  974
+    CGenericTouchActionHandler::Get().OnTap((float)point.x, (float)point.y, 2);
  975
+    break;
  976
+
891 977
   case GID_PRESSANDTAP:
892 978
   default:
893 979
     // You have encountered an unknown gesture
14  xbmc/windowing/windows/WinEventsWin32.h
@@ -23,7 +23,11 @@
23 23
 
24 24
 #pragma once
25 25
 
26  
-#include "WinEvents.h"
  26
+#include "windowing/WinEvents.h"
  27
+#include "input/MouseStat.h"
  28
+#include "input/touch/TouchTypes.h"
  29
+
  30
+class CGenericTouchSwipeDetector;
27 31
 
28 32
 class CWinEventsWin32 : public CWinEventsBase
29 33
 {
@@ -31,15 +35,17 @@ class CWinEventsWin32 : public CWinEventsBase
31 35
   static void MessagePush(XBMC_Event *newEvent);
32 36
   static bool MessagePump();
33 37
   static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
34  
-  static PHANDLE_EVENT_FUNC m_pEventFunc;
  38
+
35 39
 private:
36 40
   static void RegisterDeviceInterfaceToHwnd(GUID InterfaceClassGuid, HWND hWnd, HDEVNOTIFY *hDeviceNotify);
37 41
   static void WindowFromScreenCoords(HWND hWnd, POINT *point);
38 42
   static void OnGestureNotify(HWND hWnd, LPARAM lParam);
39 43
   static void OnGesture(HWND hWnd, LPARAM lParam);
40 44
 
41  
-  static int m_lastGesturePosX;
42  
-  static int m_lastGesturePosY;
  45
+  static PHANDLE_EVENT_FUNC m_pEventFunc;
  46
+  static int m_originalZoomDistance;
  47
+  static Pointer m_touchPointer;
  48
+  static CGenericTouchSwipeDetector *m_touchSwipeDetector;
43 49
 };
44 50
 
45 51
 #endif // WINDOW_EVENTS_WIN32_H

0 notes on commit b941ff3

Please sign in to comment.
Something went wrong with that request. Please try again.