Skip to content

Commit

Permalink
Merge pull request xbmc#2135 from Montellese/touch_input
Browse files Browse the repository at this point in the history
generic & user-mappable touch input system
  • Loading branch information
Montellese committed Mar 7, 2013
2 parents ad6733b + 967c20b commit e46bb02
Show file tree
Hide file tree
Showing 39 changed files with 2,622 additions and 1,314 deletions.
2 changes: 2 additions & 0 deletions Makefile.in
Expand Up @@ -126,6 +126,8 @@ DIRECTORY_ARCHIVES += xbmc/windowing/osx/windowing_osx.a
else
ifeq (@USE_ANDROID@,1)
DIRECTORY_ARCHIVES += xbmc/input/linux/input_linux.a
DIRECTORY_ARCHIVES += xbmc/input/touch/input_touch.a
DIRECTORY_ARCHIVES += xbmc/input/touch/generic/input_touch_generic.a
DIRECTORY_ARCHIVES += xbmc/network/linux/network_linux.a
DIRECTORY_ARCHIVES += xbmc/powermanagement/android/powermanagement_android.a
DIRECTORY_ARCHIVES += xbmc/storage/android/storage_android.a
Expand Down
40 changes: 40 additions & 0 deletions XBMC-IOS.xcodeproj/project.pbxproj
Expand Up @@ -17,6 +17,9 @@
18B700F613A6A7850009C1AF /* AddonVersion.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 18B700F413A6A7850009C1AF /* AddonVersion.cpp */; };
18E7CAD71578C691001D4554 /* CDDARipJob.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 18E7CAD51578C691001D4554 /* CDDARipJob.cpp */; };
18ECC99D13CF17D200A9ED6C /* StreamUtils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 18ECC99B13CF17D200A9ED6C /* StreamUtils.cpp */; };
1D04C1DA16E67B5A0001BA1E /* Vector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1D04C1D816E67B5A0001BA1E /* Vector.cpp */; };
1D04C23B16E67BA20001BA1E /* GenericTouchActionHandler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1D04C22916E67BA20001BA1E /* GenericTouchActionHandler.cpp */; };
1D04C24116E67BA20001BA1E /* ITouchInputHandling.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1D04C23716E67BA20001BA1E /* ITouchInputHandling.cpp */; };
1D638120161E20F2003603ED /* PeripheralImon.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1D63811E161E20F2003603ED /* PeripheralImon.cpp */; };
3255316612B2D02400837CD2 /* CoreAudio.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3255316512B2D02400837CD2 /* CoreAudio.framework */; };
3291892B1423A9B700E878CD /* JpegIO.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 329189291423A9B700E878CD /* JpegIO.cpp */; };
Expand Down Expand Up @@ -1055,6 +1058,15 @@
18E7CAD61578C691001D4554 /* CDDARipJob.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDDARipJob.h; sourceTree = "<group>"; };
18ECC99B13CF17D200A9ED6C /* StreamUtils.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StreamUtils.cpp; sourceTree = "<group>"; };
18ECC99C13CF17D200A9ED6C /* StreamUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StreamUtils.h; sourceTree = "<group>"; };
1D04C1D816E67B5A0001BA1E /* Vector.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Vector.cpp; sourceTree = "<group>"; };
1D04C1D916E67B5A0001BA1E /* Vector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Vector.h; sourceTree = "<group>"; };
1D04C22916E67BA20001BA1E /* GenericTouchActionHandler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GenericTouchActionHandler.cpp; sourceTree = "<group>"; };
1D04C22A16E67BA20001BA1E /* GenericTouchActionHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GenericTouchActionHandler.h; sourceTree = "<group>"; };
1D04C23516E67BA20001BA1E /* ITouchActionHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ITouchActionHandler.h; sourceTree = "<group>"; };
1D04C23616E67BA20001BA1E /* ITouchInputHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ITouchInputHandler.h; sourceTree = "<group>"; };
1D04C23716E67BA20001BA1E /* ITouchInputHandling.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ITouchInputHandling.cpp; sourceTree = "<group>"; };
1D04C23816E67BA20001BA1E /* ITouchInputHandling.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ITouchInputHandling.h; sourceTree = "<group>"; };
1D04C23A16E67BA20001BA1E /* TouchTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TouchTypes.h; sourceTree = "<group>"; };
1D63811E161E20F2003603ED /* PeripheralImon.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PeripheralImon.cpp; sourceTree = "<group>"; };
1D63811F161E20F2003603ED /* PeripheralImon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PeripheralImon.h; sourceTree = "<group>"; };
3255316512B2D02400837CD2 /* CoreAudio.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreAudio.framework; path = System/Library/Frameworks/CoreAudio.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -3300,6 +3312,28 @@
name = Products;
sourceTree = "<group>";
};
1D04C22716E67BA20001BA1E /* touch */ = {
isa = PBXGroup;
children = (
1D04C22816E67BA20001BA1E /* generic */,
1D04C23516E67BA20001BA1E /* ITouchActionHandler.h */,
1D04C23616E67BA20001BA1E /* ITouchInputHandler.h */,
1D04C23716E67BA20001BA1E /* ITouchInputHandling.cpp */,
1D04C23816E67BA20001BA1E /* ITouchInputHandling.h */,
1D04C23A16E67BA20001BA1E /* TouchTypes.h */,
);
path = touch;
sourceTree = "<group>";
};
1D04C22816E67BA20001BA1E /* generic */ = {
isa = PBXGroup;
children = (
1D04C22916E67BA20001BA1E /* GenericTouchActionHandler.cpp */,
1D04C22A16E67BA20001BA1E /* GenericTouchActionHandler.h */,
);
path = generic;
sourceTree = "<group>";
};
83D619BA13C0D23400418A0F /* Documentation */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -5615,6 +5649,7 @@
F56C8536131F42E9000AD0F6 /* input */ = {
isa = PBXGroup;
children = (
1D04C22716E67BA20001BA1E /* touch */,
F56C8537131F42E9000AD0F6 /* ButtonTranslator.cpp */,
F56C8538131F42E9000AD0F6 /* ButtonTranslator.h */,
DFAB04AE13F8383300B70BFB /* InertialScrollingHandler.cpp */,
Expand Down Expand Up @@ -6226,6 +6261,8 @@
36A9467715CF20A500727135 /* UrlOptions.h */,
F56C875D131F42EC000AD0F6 /* Variant.cpp */,
F56C875E131F42EC000AD0F6 /* Variant.h */,
1D04C1D816E67B5A0001BA1E /* Vector.cpp */,
1D04C1D916E67B5A0001BA1E /* Vector.h */,
F56C875F131F42EC000AD0F6 /* Weather.cpp */,
F56C8760131F42EC000AD0F6 /* Weather.h */,
F56C8763131F42EC000AD0F6 /* WindowsShortcut.h */,
Expand Down Expand Up @@ -7695,6 +7732,9 @@
F56352F916E5440300D21BAD /* GUIDialogProfileSettings.cpp in Sources */,
F56352FA16E5440300D21BAD /* GUIDialogSettings.cpp in Sources */,
F56352FD16E5441600D21BAD /* AppParamParser.cpp in Sources */,
1D04C1DA16E67B5A0001BA1E /* Vector.cpp in Sources */,
1D04C23B16E67BA20001BA1E /* GenericTouchActionHandler.cpp in Sources */,
1D04C24116E67BA20001BA1E /* ITouchInputHandling.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
21 changes: 21 additions & 0 deletions system/keymaps/touchscreen.xml
@@ -0,0 +1,21 @@
<keymap>
<global>
<touch>
<tap>LeftClick</tap>
<longpress>RightClick</longpress>
<tap pointers="2">RightClick</tap>
<pan>PanGesture</pan>
<swipe direction="left">SwipeLeft</swipe>
<swipe direction="left" pointers="2">Back</swipe>
<swipe direction="right">SwipeRight</swipe>
<swipe direction="up">SwipeUp</swipe>
<swipe direction="down">SwipeDown</swipe>
</touch>
</global>
<SlideShow>
<touch>
<zoom>ZoomGesture</zoom>
<rotate>RotateGesture</rotate>
</touch>
</SlideShow>
</keymap>
13 changes: 13 additions & 0 deletions xbmc/Application.cpp
Expand Up @@ -519,6 +519,19 @@ bool CApplication::OnEvent(XBMC_Event& newEvent)
break;
case XBMC_APPCOMMAND:
return g_application.OnAppCommand(newEvent.appcommand.action);
case XBMC_TOUCH:
{
int windowId = g_windowManager.GetActiveWindow() & WINDOW_ID_MASK;
int actionId = 0;
if (newEvent.touch.action == ACTION_GESTURE_BEGIN || newEvent.touch.action == ACTION_GESTURE_END)
actionId = newEvent.touch.action;
else if (!CButtonTranslator::GetInstance().TranslateTouchAction(windowId, newEvent.touch.action, newEvent.touch.pointers, actionId) ||
actionId <= 0)
return false;

CApplicationMessenger::Get().SendAction(CAction(actionId, 0, newEvent.touch.x, newEvent.touch.y, newEvent.touch.x2, newEvent.touch.y2), WINDOW_INVALID, false);
break;
}
}
return true;
}
Expand Down
123 changes: 14 additions & 109 deletions xbmc/android/activity/AndroidTouch.cpp
Expand Up @@ -19,24 +19,22 @@
*/

#include "AndroidTouch.h"
#include "XBMCApp.h"
#include "guilib/GUIWindowManager.h"
#include "windowing/WinEvents.h"
#include "ApplicationMessenger.h"
#include "android/activity/XBMCApp.h"
#include "input/touch/generic/GenericTouchActionHandler.h"
#include "input/touch/generic/GenericTouchInputHandler.h"

CAndroidTouch::CAndroidTouch() : m_dpi(160)
{
CTouchInput::Get().RegisterHandler(this);
CGenericTouchInputHandler::Get().RegisterHandler(&CGenericTouchActionHandler::Get());
}

CAndroidTouch::~CAndroidTouch()
{
CTouchInput::Get().UnregisterHandler();
CGenericTouchInputHandler::Get().UnregisterHandler();
}

bool CAndroidTouch::onTouchEvent(AInputEvent* event)
{
CXBMCApp::android_printf("%s", __PRETTY_FUNCTION__);
if (event == NULL)
return false;

Expand All @@ -54,21 +52,21 @@ bool CAndroidTouch::onTouchEvent(AInputEvent* event)
int8_t touchAction = eventAction & AMOTION_EVENT_ACTION_MASK;
size_t touchPointer = eventAction >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;

CTouchInput::TouchEvent touchEvent = CTouchInput::TouchEventAbort;
TouchInput touchEvent = TouchInputAbort;
switch (touchAction)
{
case AMOTION_EVENT_ACTION_DOWN:
case AMOTION_EVENT_ACTION_POINTER_DOWN:
touchEvent = CTouchInput::TouchEventDown;
touchEvent = TouchInputDown;
break;

case AMOTION_EVENT_ACTION_UP:
case AMOTION_EVENT_ACTION_POINTER_UP:
touchEvent = CTouchInput::TouchEventUp;
touchEvent = TouchInputUp;
break;

case AMOTION_EVENT_ACTION_MOVE:
touchEvent = CTouchInput::TouchEventMove;
touchEvent = TouchInputMove;
break;

case AMOTION_EVENT_ACTION_OUTSIDE:
Expand All @@ -84,112 +82,19 @@ bool CAndroidTouch::onTouchEvent(AInputEvent* event)

// first update all touch pointers
for (unsigned int pointer = 0; pointer < numPointers; pointer++)
CTouchInput::Get().Update(pointer, AMotionEvent_getX(event, pointer), AMotionEvent_getY(event, pointer),
CGenericTouchInputHandler::Get().UpdateTouchPointer(pointer, AMotionEvent_getX(event, pointer), AMotionEvent_getY(event, pointer),
AMotionEvent_getEventTime(event), m_dpi / 16.0f);

// now send the event
return CTouchInput::Get().Handle(touchEvent, x, y, time, touchPointer, size);
}

bool CAndroidTouch::OnSingleTouchStart(float x, float y)
{
// Send a mouse motion event for getting the current guiitem selected
XBMC_Touch(XBMC_MOUSEMOTION, 0, (uint16_t)x, (uint16_t)y);

return true;
}

bool CAndroidTouch::OnMultiTouchStart(float x, float y, int32_t pointers /* = 2 */)
{
XBMC_TouchGesture(ACTION_GESTURE_BEGIN, x, y, 0.0f, 0.0f);

return true;
}

bool CAndroidTouch::OnMultiTouchEnd(float x, float y, int32_t pointers /* = 2 */)
{
XBMC_TouchGesture(ACTION_GESTURE_END, 0.0f, 0.0f, 0.0f, 0.0f);

return true;
}

bool CAndroidTouch::OnTouchGesturePanStart(float x, float y)
{
XBMC_TouchGesture(ACTION_GESTURE_BEGIN, x, y, 0.0f, 0.0f);

return true;
}

bool CAndroidTouch::OnTouchGesturePan(float x, float y, float offsetX, float offsetY, float velocityX, float velocityY)
{
XBMC_TouchGesture(ACTION_GESTURE_PAN, x, y, offsetX, offsetY);

return true;
}

bool CAndroidTouch::OnTouchGesturePanEnd(float x, float y, float offsetX, float offsetY, float velocityX, float velocityY)
{
XBMC_TouchGesture(ACTION_GESTURE_END, velocityX, velocityY, x, y);

// unfocus the focused GUI item
g_windowManager.SendMessage(GUI_MSG_UNFOCUS_ALL, 0, 0, 0, 0);

return true;
}

void CAndroidTouch::OnSingleTap(float x, float y)
{
XBMC_Touch(XBMC_MOUSEBUTTONDOWN, XBMC_BUTTON_LEFT, (uint16_t)x, (uint16_t)y);
XBMC_Touch(XBMC_MOUSEBUTTONUP, XBMC_BUTTON_LEFT, (uint16_t)x, (uint16_t)y);
}

void CAndroidTouch::OnSingleLongPress(float x, float y)
{
// we send a right-click for this
XBMC_Touch(XBMC_MOUSEBUTTONDOWN, XBMC_BUTTON_RIGHT, (uint16_t)x, (uint16_t)y);
XBMC_Touch(XBMC_MOUSEBUTTONUP, XBMC_BUTTON_RIGHT, (uint16_t)x, (uint16_t)y);
}

void CAndroidTouch::OnZoomPinch(float centerX, float centerY, float zoomFactor)
{
XBMC_TouchGesture(ACTION_GESTURE_ZOOM, centerX, centerY, zoomFactor, 0);
}

void CAndroidTouch::OnRotate(float centerX, float centerY, float angle)
{
XBMC_TouchGesture(ACTION_GESTURE_ROTATE, centerX, centerY, angle, 0);
return CGenericTouchInputHandler::Get().HandleTouchInput(touchEvent, x, y, time, touchPointer, size);
}

void CAndroidTouch::setDPI(uint32_t dpi)
{
if (dpi != 0)
{
m_dpi = dpi;
}

void CAndroidTouch::XBMC_Touch(uint8_t type, uint8_t button, uint16_t x, uint16_t y)
{
XBMC_Event newEvent;
memset(&newEvent, 0, sizeof(newEvent));

newEvent.type = type;
newEvent.button.type = type;
newEvent.button.button = button;
newEvent.button.x = x;
newEvent.button.y = y;

CXBMCApp::android_printf("XBMC_Touch(%u, %u, %u, %u)", type, button, x, y);
CWinEvents::MessagePush(&newEvent);
}

void CAndroidTouch::XBMC_TouchGesture(int32_t action, float posX, float posY, float offsetX, float offsetY)
{
CXBMCApp::android_printf("XBMC_TouchGesture(%d, %f, %f, %f, %f)", action, posX, posY, offsetX, offsetY);
if (action == ACTION_GESTURE_BEGIN)
CApplicationMessenger::Get().SendAction(CAction(action, 0, posX, posY, 0, 0), WINDOW_INVALID, false);
else if (action == ACTION_GESTURE_PAN)
CApplicationMessenger::Get().SendAction(CAction(action, 0, posX, posY, offsetX, offsetY), WINDOW_INVALID, false);
else if (action == ACTION_GESTURE_END)
CApplicationMessenger::Get().SendAction(CAction(action, 0, posX, posY, offsetX, offsetY), WINDOW_INVALID, false);
else if (action == ACTION_GESTURE_ZOOM || action == ACTION_GESTURE_ROTATE)
CApplicationMessenger::Get().SendAction(CAction(action, 0, posX, posY, offsetX, 0), WINDOW_INVALID, false);
CGenericTouchInputHandler::Get().SetScreenDPI(m_dpi);
}
}
21 changes: 1 addition & 20 deletions xbmc/android/activity/AndroidTouch.h
Expand Up @@ -21,9 +21,7 @@
#include <android/input.h>
#include <math.h>

#include "input/TouchInput.h"

class CAndroidTouch : protected ITouchHandler
class CAndroidTouch
{

public:
Expand All @@ -32,25 +30,8 @@ class CAndroidTouch : protected ITouchHandler
bool onTouchEvent(AInputEvent* event);

protected:
virtual bool OnSingleTouchStart(float x, float y);

virtual bool OnMultiTouchStart(float x, float y, int32_t pointers = 2);
virtual bool OnMultiTouchEnd(float x, float y, int32_t pointers = 2);

virtual bool OnTouchGesturePanStart(float x, float y);
virtual bool OnTouchGesturePan(float x, float y, float offsetX, float offsetY, float velocityX, float velocityY);
virtual bool OnTouchGesturePanEnd(float x, float y, float offsetX, float offsetY, float velocityX, float velocityY);

virtual void OnSingleTap(float x, float y);
virtual void OnSingleLongPress(float x, float y);
virtual void OnZoomPinch(float centerX, float centerY, float zoomFactor);
virtual void OnRotate(float centerX, float centerY, float angle);

virtual void setDPI(uint32_t dpi);

private:
void XBMC_Touch(uint8_t type, uint8_t button, uint16_t x, uint16_t y);
void XBMC_TouchGesture(int32_t action, float posX, float posY, float offsetX, float offsetY);

uint32_t m_dpi;
};
18 changes: 10 additions & 8 deletions xbmc/guilib/GUIControl.h
Expand Up @@ -56,14 +56,16 @@ class CControlState
\brief Results of OnMouseEvent()
Any value not equal to EVENT_RESULT_UNHANDLED indicates that the event was handled.
*/
enum EVENT_RESULT { EVENT_RESULT_UNHANDLED = 0,
EVENT_RESULT_HANDLED,
EVENT_RESULT_PAN_HORIZONTAL,
EVENT_RESULT_PAN_VERTICAL,
EVENT_RESULT_PAN_VERTICAL_WITHOUT_INERTIA,
EVENT_RESULT_PAN_HORIZONTAL_WITHOUT_INERTIA,
EVENT_RESULT_ROTATE,
EVENT_RESULT_ZOOM };
enum EVENT_RESULT { EVENT_RESULT_UNHANDLED = 0x00,
EVENT_RESULT_HANDLED = 0x01,
EVENT_RESULT_PAN_HORIZONTAL = 0x02,
EVENT_RESULT_PAN_VERTICAL = 0x04,
EVENT_RESULT_PAN_VERTICAL_WITHOUT_INERTIA = 0x08,
EVENT_RESULT_PAN_HORIZONTAL_WITHOUT_INERTIA = 0x10,
EVENT_RESULT_ROTATE = 0x20,
EVENT_RESULT_ZOOM = 0x40,
EVENT_RESULT_SWIPE = 0x80
};

/*!
\ingroup controls
Expand Down

0 comments on commit e46bb02

Please sign in to comment.