2 * Copyright (C) 2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
21 #include "GenericTouchActionHandler.h"
22 #include "ApplicationMessenger.h"
23 #include "guilib/GUIWindowManager.h"
24 #include "guilib/Key.h"
25 #include "windowing/WinEvents.h"
27 CGenericTouchActionHandler &CGenericTouchActionHandler::Get()
29 static CGenericTouchActionHandler sTouchAction;
33 void CGenericTouchActionHandler::OnTouchAbort()
36 bool CGenericTouchActionHandler::OnSingleTouchStart(float x, float y)
43 bool CGenericTouchActionHandler::OnSingleTouchHold(float x, float y)
48 bool CGenericTouchActionHandler::OnSingleTouchMove(float x, float y, float offsetX, float offsetY, float velocityX, float velocityY)
53 bool CGenericTouchActionHandler::OnSingleTouchEnd(float x, float y)
58 bool CGenericTouchActionHandler::OnMultiTouchDown(float x, float y, int32_t pointer)
63 bool CGenericTouchActionHandler::OnMultiTouchHold(float x, float y, int32_t pointers /* = 2 */)
68 bool CGenericTouchActionHandler::OnMultiTouchMove(float x, float y, float offsetX, float offsetY, float velocityX, float velocityY, int32_t pointer)
73 bool CGenericTouchActionHandler::OnMultiTouchUp(float x, float y, int32_t pointer)
78 bool CGenericTouchActionHandler::OnTouchGestureStart(float x, float y)
80 sendEvent(ACTION_GESTURE_BEGIN, x, y, 0.0f, 0.0f);
85 bool CGenericTouchActionHandler::OnTouchGesturePan(float x, float y, float offsetX, float offsetY, float velocityX, float velocityY)
87 sendEvent(ACTION_GESTURE_PAN, x, y, offsetX, offsetY);
92 bool CGenericTouchActionHandler::OnTouchGestureEnd(float x, float y, float offsetX, float offsetY, float velocityX, float velocityY)
94 sendEvent(ACTION_GESTURE_END, velocityX, velocityY, x, y);
99 void CGenericTouchActionHandler::OnTap(float x, float y, int32_t pointers /* = 1 */)
101 if (pointers <= 0 || pointers > 10)
104 sendEvent(ACTION_TOUCH_TAP, (uint16_t)x, (uint16_t)y, 0.0f, 0.0f, pointers);
107 void CGenericTouchActionHandler::OnLongPress(float x, float y, int32_t pointers /* = 1 */)
109 if (pointers <= 0 || pointers > 10)
112 sendEvent(ACTION_TOUCH_LONGPRESS, (uint16_t)x, (uint16_t)y, 0.0f, 0.0f, pointers);
115 void CGenericTouchActionHandler::OnSwipe(TouchMoveDirection direction, float xDown, float yDown, float xUp, float yUp, float velocityX, float velocityY, int32_t pointers /* = 1 */)
117 if (pointers <= 0 || pointers > 10)
121 if (direction == TouchMoveDirectionLeft)
122 actionId = ACTION_GESTURE_SWIPE_LEFT;
123 else if (direction == TouchMoveDirectionRight)
124 actionId = ACTION_GESTURE_SWIPE_RIGHT;
125 else if (direction == TouchMoveDirectionUp)
126 actionId = ACTION_GESTURE_SWIPE_UP;
127 else if (direction == TouchMoveDirectionDown)
128 actionId = ACTION_GESTURE_SWIPE_DOWN;
132 sendEvent(actionId, xUp, yUp, velocityX, velocityY, pointers);
135 void CGenericTouchActionHandler::OnZoomPinch(float centerX, float centerY, float zoomFactor)
137 sendEvent(ACTION_GESTURE_ZOOM, centerX, centerY, zoomFactor, 0.0f);
140 void CGenericTouchActionHandler::OnRotate(float centerX, float centerY, float angle)
142 sendEvent(ACTION_GESTURE_ROTATE, centerX, centerY, angle, 0.0f);
145 int CGenericTouchActionHandler::QuerySupportedGestures(float x, float y)
147 CGUIMessage msg(GUI_MSG_GESTURE_NOTIFY, 0, 0, (int)x, (int)y);
148 if (!g_windowManager.SendMessage(msg))
151 return msg.GetParam1();
154 void CGenericTouchActionHandler::touch(uint8_t type, uint8_t button, uint16_t x, uint16_t y)
157 memset(&newEvent, 0, sizeof(newEvent));
159 newEvent.type = type;
160 newEvent.button.type = type;
161 newEvent.button.button = button;
162 newEvent.button.x = x;
163 newEvent.button.y = y;
165 CWinEvents::MessagePush(&newEvent);
168 void CGenericTouchActionHandler::sendEvent(int actionId, float x, float y, float x2 /* = 0.0f */, float y2 /* = 0.0f */, int pointers /* = 1 */)
171 memset(&newEvent, 0, sizeof(newEvent));
173 newEvent.type = XBMC_TOUCH;
174 newEvent.touch.type = XBMC_TOUCH;
175 newEvent.touch.action = actionId;
176 newEvent.touch.x = x;
177 newEvent.touch.y = y;
178 newEvent.touch.x2 = x2;
179 newEvent.touch.y2 = y2;
180 newEvent.touch.pointers = pointers;
182 CWinEvents::MessagePush(&newEvent);
185 void CGenericTouchActionHandler::focusControl(float x, float y)
188 memset(&newEvent, 0, sizeof(newEvent));
190 newEvent.type = XBMC_SETFOCUS;
191 newEvent.focus.type = XBMC_SETFOCUS;
192 newEvent.focus.x = (uint16_t)x;
193 newEvent.focus.y = (uint16_t)y;
195 CWinEvents::MessagePush(&newEvent);