[Windows] Remove redundant DirectSound error codes
[xbmc.git] / xbmc / platform / android / activity / AndroidMouse.cpp
blob39bfc170d3b5a53c68f157c3a2eea0ebc1b88da6
1 /*
2 * Copyright (C) 2012-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "AndroidMouse.h"
11 #include "ServiceBroker.h"
12 #include "XBMCApp.h"
13 #include "application/AppInboundProtocol.h"
14 #include "input/mouse/MouseStat.h"
15 #include "windowing/android/WinSystemAndroid.h"
17 //#define DEBUG_VERBOSE
19 bool CAndroidMouse::onMouseEvent(AInputEvent* event)
21 if (event == NULL)
22 return false;
24 int32_t eventAction = AMotionEvent_getAction(event);
25 int8_t mouseAction = eventAction & AMOTION_EVENT_ACTION_MASK;
26 size_t mousePointerIdx = eventAction >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
28 #ifdef DEBUG_VERBOSE
29 int32_t mousePointerId = AMotionEvent_getPointerId(event, mousePointerIdx);
30 CXBMCApp::android_printf("%s idx:%i, id:%i", __PRETTY_FUNCTION__, mousePointerIdx, mousePointerId);
31 #endif
32 float x = AMotionEvent_getX(event, mousePointerIdx);
33 float y = AMotionEvent_getY(event, mousePointerIdx);
35 switch (mouseAction)
37 case AMOTION_EVENT_ACTION_UP:
38 case AMOTION_EVENT_ACTION_DOWN:
39 MouseButton(x,y,mouseAction,AMotionEvent_getButtonState(event));
40 return true;
41 case AMOTION_EVENT_ACTION_SCROLL:
42 MouseWheel(x, y, AMotionEvent_getAxisValue(event, AMOTION_EVENT_AXIS_VSCROLL, mousePointerIdx));
43 return true;
44 default:
45 MouseMove(x,y);
46 return true;
48 return false;
51 void CAndroidMouse::MouseMove(float x, float y)
53 #ifdef DEBUG_VERBOSE
54 CXBMCApp::android_printf("%s: x:%f, y:%f", __PRETTY_FUNCTION__, x, y);
55 #endif
56 XBMC_Event newEvent = {};
58 newEvent.type = XBMC_MOUSEMOTION;
59 newEvent.motion.x = x;
60 newEvent.motion.y = y;
61 std::shared_ptr<CAppInboundProtocol> appPort = CServiceBroker::GetAppPort();
62 if (appPort)
63 appPort->OnEvent(newEvent);
66 void CAndroidMouse::MouseButton(float x, float y, int32_t action, int32_t buttons)
68 #ifdef DEBUG_VERBOSE
69 CXBMCApp::android_printf("%s: x:%f, y:%f, action:%i, buttons:%i", __PRETTY_FUNCTION__, x, y, action, buttons);
70 #endif
71 XBMC_Event newEvent = {};
73 int32_t checkButtons = buttons;
74 if (action == AMOTION_EVENT_ACTION_UP)
75 checkButtons = m_lastButtonState;
77 newEvent.type = (action == AMOTION_EVENT_ACTION_DOWN) ? XBMC_MOUSEBUTTONDOWN : XBMC_MOUSEBUTTONUP;
78 newEvent.button.x = x;
79 newEvent.button.y = y;
80 if (checkButtons & AMOTION_EVENT_BUTTON_PRIMARY)
81 newEvent.button.button = XBMC_BUTTON_LEFT;
82 else if (checkButtons & AMOTION_EVENT_BUTTON_SECONDARY)
83 newEvent.button.button = XBMC_BUTTON_RIGHT;
84 else if (checkButtons & AMOTION_EVENT_BUTTON_TERTIARY)
85 newEvent.button.button = XBMC_BUTTON_MIDDLE;
87 std::shared_ptr<CAppInboundProtocol> appPort = CServiceBroker::GetAppPort();
88 if (appPort)
89 appPort->OnEvent(newEvent);
91 m_lastButtonState = buttons;
94 void CAndroidMouse::MouseWheel(float x, float y, float value)
96 #ifdef DEBUG_VERBOSE
97 CXBMCApp::android_printf("%s: val:%f", __PRETTY_FUNCTION__, value);
98 #endif
99 XBMC_Event newEvent = {};
101 if (value > 0.0f)
103 newEvent.type = XBMC_MOUSEBUTTONDOWN;
104 newEvent.button.button = XBMC_BUTTON_WHEELUP;
106 else if (value < 0.0f)
108 newEvent.type = XBMC_MOUSEBUTTONDOWN;
109 newEvent.button.button = XBMC_BUTTON_WHEELDOWN;
111 else
112 return;
114 newEvent.button.x = x;
115 newEvent.button.y = y;
117 std::shared_ptr<CAppInboundProtocol> appPort = CServiceBroker::GetAppPort();
118 if (appPort)
119 appPort->OnEvent(newEvent);
121 newEvent.type = XBMC_MOUSEBUTTONUP;
123 dynamic_cast<CWinSystemAndroid*>(CServiceBroker::GetWinSystem())->MessagePush(&newEvent);