Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit b941ff3a1b87e73a8315c93f5e88060a29a640d3 1 parent 7cb5e1a
@Montellese Montellese authored
View
14 project/VS2010Express/XBMC.vcxproj
@@ -701,6 +701,9 @@
<ClCompile Include="..\..\xbmc\input\KeyboardLayoutConfiguration.cpp" />
<ClCompile Include="..\..\xbmc\input\KeyboardStat.cpp" />
<ClCompile Include="..\..\xbmc\input\MouseStat.cpp" />
+ <ClCompile Include="..\..\xbmc\input\touch\generic\GenericTouchActionHandler.cpp" />
+ <ClCompile Include="..\..\xbmc\input\touch\generic\GenericTouchSwipeDetector.cpp" />
+ <ClCompile Include="..\..\xbmc\input\touch\ITouchInputHandling.cpp" />
<ClCompile Include="..\..\xbmc\input\windows\IRServerSuite.cpp" />
<ClCompile Include="..\..\xbmc\input\windows\IrssMessage.cpp" />
<ClCompile Include="..\..\xbmc\input\windows\WINJoystick.cpp" />
@@ -1048,6 +1051,13 @@
<ClInclude Include="..\..\xbmc\guilib\GUIKeyboardFactory.h" />
<ClInclude Include="..\..\xbmc\guilib\iimage.h" />
<ClInclude Include="..\..\xbmc\guilib\imagefactory.h" />
+ <ClInclude Include="..\..\xbmc\input\touch\generic\GenericTouchActionHandler.h" />
+ <ClInclude Include="..\..\xbmc\input\touch\generic\GenericTouchSwipeDetector.h" />
+ <ClInclude Include="..\..\xbmc\input\touch\generic\IGenericTouchGestureDetector.h" />
+ <ClInclude Include="..\..\xbmc\input\touch\ITouchActionHandler.h" />
+ <ClInclude Include="..\..\xbmc\input\touch\ITouchInputHandler.h" />
+ <ClInclude Include="..\..\xbmc\input\touch\ITouchInputHandling.h" />
+ <ClInclude Include="..\..\xbmc\input\touch\TouchTypes.h" />
<ClInclude Include="..\..\xbmc\input\windows\WINJoystick.h" />
<ClInclude Include="..\..\xbmc\interfaces\json-rpc\PVROperations.h" />
<ClInclude Include="..\..\xbmc\interfaces\legacy\Addon.h" />
@@ -1114,6 +1124,7 @@
<ClInclude Include="..\..\xbmc\settings\windows\GUIWindowTestPattern.h" />
<ClInclude Include="..\..\xbmc\utils\IRssObserver.h" />
<ClInclude Include="..\..\xbmc\utils\RssManager.h" />
+ <ClInclude Include="..\..\xbmc\utils\Vector.h" />
<ClInclude Include="..\..\xbmc\video\FFmpegVideoDecoder.h" />
<ClInclude Include="..\..\xbmc\interfaces\python\swig.h" />
<ClInclude Include="..\..\xbmc\interfaces\python\XBPython.h" />
@@ -1257,6 +1268,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release (OpenGL)|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Template|Win32'">true</ExcludedFromBuild>
</ClCompile>
+ <ClCompile Include="..\..\xbmc\utils\Vector.cpp" />
<ClCompile Include="..\..\xbmc\video\VideoThumbLoader.cpp" />
<ClCompile Include="..\..\xbmc\music\MusicThumbLoader.cpp" />
<ClCompile Include="..\..\xbmc\ThumbnailCache.cpp" />
@@ -2963,4 +2975,4 @@
</VisualStudio>
</ProjectExtensions>
<Import Project="$(SolutionDir)\$(ProjectFileName).targets.user" Condition="Exists('$(SolutionDir)\$(ProjectFileName).targets.user')" />
-</Project>
+</Project>
View
44 project/VS2010Express/XBMC.vcxproj.filters
@@ -295,6 +295,12 @@
<Filter Include="profiles\windows">
<UniqueIdentifier>{b5a6d872-7e56-4976-81c5-47baad252337}</UniqueIdentifier>
</Filter>
+ <Filter Include="input\touch">
+ <UniqueIdentifier>{4e236b17-3720-4ed8-89af-90cb86bf9b03}</UniqueIdentifier>
+ </Filter>
+ <Filter Include="input\touch\generic">
+ <UniqueIdentifier>{d062c356-66f2-49e7-9510-b216701d2298}</UniqueIdentifier>
+ </Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\xbmc\win32\pch.cpp">
@@ -3000,6 +3006,18 @@
<ClCompile Include="..\..\xbmc\profiles\ProfilesManager.cpp">
<Filter>profiles</Filter>
</ClCompile>
+ <ClCompile Include="..\..\xbmc\input\touch\generic\GenericTouchActionHandler.cpp">
+ <Filter>input\touch\generic</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\xbmc\input\touch\generic\GenericTouchSwipeDetector.cpp">
+ <Filter>input\touch\generic</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\xbmc\input\touch\ITouchInputHandling.cpp">
+ <Filter>input\touch</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\xbmc\utils\Vector.cpp">
+ <Filter>utils</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\xbmc\win32\pch.h">
@@ -5858,6 +5876,30 @@
<ClInclude Include="..\..\xbmc\profiles\ProfilesManager.h">
<Filter>profiles</Filter>
</ClInclude>
+ <ClInclude Include="..\..\xbmc\input\touch\ITouchActionHandler.h">
+ <Filter>input\touch</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\xbmc\input\touch\generic\GenericTouchActionHandler.h">
+ <Filter>input\touch\generic</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\xbmc\input\touch\TouchTypes.h">
+ <Filter>input\touch</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\xbmc\input\touch\generic\GenericTouchSwipeDetector.h">
+ <Filter>input\touch\generic</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\xbmc\input\touch\generic\IGenericTouchGestureDetector.h">
+ <Filter>input\touch\generic</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\xbmc\input\touch\ITouchInputHandler.h">
+ <Filter>input\touch</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\xbmc\input\touch\ITouchInputHandling.h">
+ <Filter>input\touch</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\xbmc\utils\Vector.h">
+ <Filter>utils</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\..\xbmc\win32\XBMC_PC.rc">
@@ -5889,4 +5931,4 @@
<Filter>interfaces\swig</Filter>
</None>
</ItemGroup>
-</Project>
+</Project>
View
6 xbmc/input/touch/generic/GenericTouchSwipeDetector.cpp
@@ -161,6 +161,12 @@ bool CGenericTouchSwipeDetector::OnTouchMove(unsigned int index, const Pointer &
else if (deltaYabs > m_dpi * SWIPE_MIN_DISTANCE)
m_swipeDetected = true;
}
+
+ if (m_directions == TouchMoveDirectionNone)
+ {
+ m_done = true;
+ return false;
+ }
return true;
}
View
140 xbmc/windowing/windows/WinEventsWin32.cpp
@@ -18,6 +18,11 @@
*
*/
+#ifndef _USE_MATH_DEFINES
+#define _USE_MATH_DEFINES
+#endif
+#include <math.h>
+
#include "utils/log.h"
#include "Windowsx.h"
#include "windowing/WinEvents.h"
@@ -26,6 +31,8 @@
#include "Application.h"
#include "input/XBMC_vkeys.h"
#include "input/MouseStat.h"
+#include "input/touch/generic/GenericTouchActionHandler.h"
+#include "input/touch/generic/GenericTouchSwipeDetector.h"
#include "input/windows/WINJoystick.h"
#include "storage/MediaManager.h"
#include "windowing/WindowingFactory.h"
@@ -49,6 +56,12 @@ using namespace PERIPHERALS;
HWND g_hWnd = NULL;
+#ifndef LODWORD
+#define LODWORD(longval) ((DWORD)((DWORDLONG)(longval)))
+#endif
+
+#define ROTATE_ANGLE_DEGREE(arg) GID_ROTATE_ANGLE_FROM_ARGUMENT(LODWORD(arg)) * 180 / M_PI
+
#define XBMC_arraysize(array) (sizeof(array)/sizeof(array[0]))
/* Masks for processing the windows KEYDOWN and KEYUP messages */
@@ -65,8 +78,9 @@ uint32_t g_uQueryCancelAutoPlay = 0;
int XBMC_TranslateUNICODE = 1;
PHANDLE_EVENT_FUNC CWinEventsWin32::m_pEventFunc = NULL;
-int CWinEventsWin32::m_lastGesturePosX = 0;
-int CWinEventsWin32::m_lastGesturePosY = 0;
+int CWinEventsWin32::m_originalZoomDistance = 0;
+Pointer CWinEventsWin32::m_touchPointer;
+CGenericTouchSwipeDetector* CWinEventsWin32::m_touchSwipeDetector = NULL;
// register to receive SD card events (insert/remove)
// 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)
POINT point = { gn->ptsLocation.x, gn->ptsLocation.y };
WindowFromScreenCoords(hWnd, &point);
- // by default that we want no gestures
+ // by default we only want twofingertap and pressandtap gestures
+ // the other gestures are enabled best on supported gestures
GESTURECONFIG gc[] = {{ GID_ZOOM, 0, GC_ZOOM},
{ GID_ROTATE, 0, GC_ROTATE},
{ GID_PAN, 0, GC_PAN},
- { GID_TWOFINGERTAP, 0, GC_TWOFINGERTAP },
- { GID_PRESSANDTAP, 0, GC_PRESSANDTAP }};
+ { GID_TWOFINGERTAP, GC_TWOFINGERTAP, GC_TWOFINGERTAP },
+ { GID_PRESSANDTAP, GC_PRESSANDTAP, GC_PRESSANDTAP }};
// send a message to see if a control wants any
- CGUIMessage message(GUI_MSG_GESTURE_NOTIFY, 0, 0, point.x, point.y);
- if (g_windowManager.SendMessage(message))
+ int gestures = 0;
+ if ((gestures = CGenericTouchActionHandler::Get().QuerySupportedGestures((float)point.x, (float)point.y)) != EVENT_RESULT_UNHANDLED)
{
- int gestures = message.GetParam1();
if (gestures & EVENT_RESULT_ZOOM)
gc[0].dwWant |= GC_ZOOM;
if (gestures & EVENT_RESULT_ROTATE)
gc[1].dwWant |= GC_ROTATE;
if (gestures & EVENT_RESULT_PAN_VERTICAL)
- gc[2].dwWant |= GC_PAN_WITH_SINGLE_FINGER_VERTICALLY | GC_PAN_WITH_GUTTER | GC_PAN_WITH_INERTIA;
+ gc[2].dwWant |= GC_PAN | GC_PAN_WITH_SINGLE_FINGER_VERTICALLY | GC_PAN_WITH_GUTTER | GC_PAN_WITH_INERTIA;
if (gestures & EVENT_RESULT_PAN_VERTICAL_WITHOUT_INERTIA)
- gc[2].dwWant |= GC_PAN_WITH_SINGLE_FINGER_VERTICALLY;
+ gc[2].dwWant |= GC_PAN | GC_PAN_WITH_SINGLE_FINGER_VERTICALLY;
if (gestures & EVENT_RESULT_PAN_HORIZONTAL)
- gc[2].dwWant |= GC_PAN_WITH_SINGLE_FINGER_HORIZONTALLY | GC_PAN_WITH_GUTTER | GC_PAN_WITH_INERTIA;
+ gc[2].dwWant |= GC_PAN | GC_PAN_WITH_SINGLE_FINGER_HORIZONTALLY | GC_PAN_WITH_GUTTER | GC_PAN_WITH_INERTIA;
if (gestures & EVENT_RESULT_PAN_HORIZONTAL_WITHOUT_INERTIA)
- gc[2].dwWant |= GC_PAN_WITH_SINGLE_FINGER_HORIZONTALLY;
- gc[0].dwBlock = gc[0].dwWant ^ 1;
- gc[1].dwBlock = gc[1].dwWant ^ 1;
- gc[2].dwBlock = gc[2].dwWant ^ 30;
+ gc[2].dwWant |= GC_PAN | GC_PAN_WITH_SINGLE_FINGER_HORIZONTALLY;
+ if (gestures & EVENT_RESULT_SWIPE)
+ {
+ gc[2].dwWant |= GC_PAN | GC_PAN_WITH_SINGLE_FINGER_VERTICALLY | GC_PAN_WITH_SINGLE_FINGER_HORIZONTALLY | GC_PAN_WITH_GUTTER;
+
+ // create a new touch swipe detector
+ m_touchSwipeDetector = new CGenericTouchSwipeDetector(&CGenericTouchActionHandler::Get(), 160.0f);
+ }
+
+ gc[0].dwBlock = gc[0].dwWant ^ 0x01;
+ gc[1].dwBlock = gc[1].dwWant ^ 0x01;
+ gc[2].dwBlock = gc[2].dwWant ^ 0x1F;
}
if (g_Windowing.PtrSetGestureConfig)
g_Windowing.PtrSetGestureConfig(hWnd, 0, 5, gc, sizeof(GESTURECONFIG));
@@ -859,35 +881,99 @@ void CWinEventsWin32::OnGesture(HWND hWnd, LPARAM lParam)
// convert to window coordinates
POINT point = { gi.ptsLocation.x, gi.ptsLocation.y };
WindowFromScreenCoords(hWnd, &point);
+
+ if (gi.dwID == GID_BEGIN)
+ m_touchPointer.reset();
+
+ // if there's a "current" touch from a previous event, copy it to "last"
+ if (m_touchPointer.current.valid())
+ m_touchPointer.last = m_touchPointer.current;
+
+ // set the "current" touch
+ m_touchPointer.current.x = (float)point.x;
+ m_touchPointer.current.y = (float)point.y;
+ m_touchPointer.current.time = time(NULL);
+
switch (gi.dwID)
{
case GID_BEGIN:
{
- m_lastGesturePosX = point.x;
- m_lastGesturePosY = point.y;
- g_application.OnAction(CAction(ACTION_GESTURE_BEGIN, 0, (float)point.x, (float)point.y, 0, 0));
+ // set the "down" touch
+ m_touchPointer.down = m_touchPointer.current;
+ m_originalZoomDistance = 0;
+
+ CGenericTouchActionHandler::Get().OnTouchGestureStart((float)point.x, (float)point.y);
}
break;
+
case GID_END:
- {
- g_application.OnAction(CAction(ACTION_GESTURE_END));
- }
+ CGenericTouchActionHandler::Get().OnTouchGestureEnd((float)point.x, (float)point.y, 0.0f, 0.0f, 0.0f, 0.0f);
break;
+
case GID_PAN:
{
- g_application.OnAction(CAction(ACTION_GESTURE_PAN, 0, (float)point.x, (float)point.y,
- (float)(point.x - m_lastGesturePosX), (float)(point.y - m_lastGesturePosY)));
- m_lastGesturePosX = point.x;
- m_lastGesturePosY = point.y;
+ if (!m_touchPointer.moving)
+ m_touchPointer.moving = true;
+
+ // calculate the velocity of the pan gesture
+ float velocityX, velocityY;
+ m_touchPointer.velocity(velocityX, velocityY);
+
+ CGenericTouchActionHandler::Get().OnTouchGesturePan(m_touchPointer.current.x, m_touchPointer.current.y,
+ m_touchPointer.current.x - m_touchPointer.last.x, m_touchPointer.current.y - m_touchPointer.last.y,
+ velocityX, velocityY);
+
+ if (m_touchSwipeDetector != NULL)
+ {
+ if (gi.dwFlags & GF_BEGIN)
+ {
+ m_touchPointer.down = m_touchPointer.current;
+ m_touchSwipeDetector->OnTouchDown(0, m_touchPointer);
+ }
+ else if (gi.dwFlags & GF_END)
+ {
+ m_touchSwipeDetector->OnTouchUp(0, m_touchPointer);
+
+ delete m_touchSwipeDetector;
+ m_touchSwipeDetector = NULL;
+ }
+ else
+ m_touchSwipeDetector->OnTouchMove(0, m_touchPointer);
+ }
}
break;
+
case GID_ROTATE:
- CLog::Log(LOGDEBUG, "%s - Rotating", __FUNCTION__);
+ {
+ if (gi.dwFlags == GF_BEGIN)
+ break;
+
+ CGenericTouchActionHandler::Get().OnRotate((float)point.x, (float)point.y,
+ -(float)ROTATE_ANGLE_DEGREE(gi.ullArguments));
+ }
break;
+
case GID_ZOOM:
- CLog::Log(LOGDEBUG, "%s - Zooming", __FUNCTION__);
+ {
+ if (gi.dwFlags == GF_BEGIN)
+ {
+ m_originalZoomDistance = (int)LODWORD(gi.ullArguments);
+ break;
+ }
+
+ // avoid division by 0
+ if (m_originalZoomDistance == 0)
+ break;
+
+ CGenericTouchActionHandler::Get().OnZoomPinch((float)point.x, (float)point.y,
+ (float)LODWORD(gi.ullArguments) / (float)m_originalZoomDistance);
+ }
break;
+
case GID_TWOFINGERTAP:
+ CGenericTouchActionHandler::Get().OnTap((float)point.x, (float)point.y, 2);
+ break;
+
case GID_PRESSANDTAP:
default:
// You have encountered an unknown gesture
View
14 xbmc/windowing/windows/WinEventsWin32.h
@@ -23,7 +23,11 @@
#pragma once
-#include "WinEvents.h"
+#include "windowing/WinEvents.h"
+#include "input/MouseStat.h"
+#include "input/touch/TouchTypes.h"
+
+class CGenericTouchSwipeDetector;
class CWinEventsWin32 : public CWinEventsBase
{
@@ -31,15 +35,17 @@ class CWinEventsWin32 : public CWinEventsBase
static void MessagePush(XBMC_Event *newEvent);
static bool MessagePump();
static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
- static PHANDLE_EVENT_FUNC m_pEventFunc;
+
private:
static void RegisterDeviceInterfaceToHwnd(GUID InterfaceClassGuid, HWND hWnd, HDEVNOTIFY *hDeviceNotify);
static void WindowFromScreenCoords(HWND hWnd, POINT *point);
static void OnGestureNotify(HWND hWnd, LPARAM lParam);
static void OnGesture(HWND hWnd, LPARAM lParam);
- static int m_lastGesturePosX;
- static int m_lastGesturePosY;
+ static PHANDLE_EVENT_FUNC m_pEventFunc;
+ static int m_originalZoomDistance;
+ static Pointer m_touchPointer;
+ static CGenericTouchSwipeDetector *m_touchSwipeDetector;
};
#endif // WINDOW_EVENTS_WIN32_H
Please sign in to comment.
Something went wrong with that request. Please try again.