Skip to content
Browse files

Merge pull request #3658 from koying/fixdroidmousewheel

FIX: [droid] Handle mouse wheel
  • Loading branch information...
2 parents fa91832 + 083dbea commit c5fdafe8378bbdda15cc5b225935fe1c1e1b0393 @koying koying committed Nov 18, 2013
View
10 xbmc/android/activity/AndroidExtra.h
@@ -21,6 +21,11 @@
/*** Extra's not found in the Android NDK ***/
+// missing in early NDKs, is present in r9b+
+extern float AMotionEvent_getAxisValue(const AInputEvent* motion_event, int32_t axis, size_t pointer_index);
+extern typeof(AMotionEvent_getAxisValue) *p_AMotionEvent_getAxisValue;
+#define AMotionEvent_getAxisValue (*p_AMotionEvent_getAxisValue)
+
//Additional defines from android.view.KeyEvent (http://developer.android.com/reference/android/view/KeyEvent.html)
#define AKEYCODE_ESCAPE 111
#define AKEYCODE_FORWARD_DEL 112
@@ -33,6 +38,9 @@
#define AKEYCODE_MEDIA_PLAY 126
#define AKEYCODE_MEDIA_EJECT 129
+//Additional defines from android.view.MotionEvent (http://developer.android.com/reference/android/view/MotionEvent.html)
+#define AMOTION_EVENT_ACTION_SCROLL 0x08
+
#define AINPUT_SOURCE_CLASS_JOYSTICK 0x00000010
#define AINPUT_SOURCE_GAMEPAD (0x00000400 | AINPUT_SOURCE_CLASS_BUTTON)
@@ -50,3 +58,5 @@
// trigger left, right
#define AMOTION_EVENT_AXIS_LTRIGGER 17
#define AMOTION_EVENT_AXIS_RTRIGGER 18
+// mouse vertical wheel
+#define AMOTION_EVENT_AXIS_VSCROLL 0x09
View
8 xbmc/android/activity/AndroidJoyStick.cpp
@@ -32,7 +32,6 @@
#include <math.h>
-#include <dlfcn.h>
//#define DEBUG_VERBOSE
@@ -72,11 +71,6 @@ static const KeyMap ButtonMap[] = {
{ AKEYCODE_BUTTON_Z , 52 },
};
-// missing in early NDKs, is present in r9b+
-extern float AMotionEvent_getAxisValue(const AInputEvent* motion_event, int32_t axis, size_t pointer_index);
-static typeof(AMotionEvent_getAxisValue) *p_AMotionEvent_getAxisValue;
-#define AMotionEvent_getAxisValue (*p_AMotionEvent_getAxisValue)
-
/************************************************************************/
/************************************************************************/
static float AxisClampAsButton(const APP_InputDeviceAxis &axis, float value)
@@ -205,8 +199,6 @@ CAndroidJoyStick::CAndroidJoyStick()
, m_prev_button(0)
, m_prev_holdtime(0)
{
- p_AMotionEvent_getAxisValue = (typeof(AMotionEvent_getAxisValue)*) dlsym(RTLD_DEFAULT, "AMotionEvent_getAxisValue");
- CXBMCApp::android_printf("CAndroidJoystick: AMotionEvent_getAxisValue: %p", p_AMotionEvent_getAxisValue);
}
CAndroidJoyStick::~CAndroidJoyStick()
View
50 xbmc/android/activity/AndroidMouse.cpp
@@ -19,12 +19,15 @@
*/
#include "AndroidMouse.h"
+#include "AndroidExtra.h"
#include "XBMCApp.h"
#include "Application.h"
#include "guilib/GUIWindowManager.h"
#include "windowing/WinEvents.h"
#include "input/MouseStat.h"
+//#define DEBUG_VERBOSE
+
CAndroidMouse::CAndroidMouse()
{
}
@@ -42,7 +45,9 @@ bool CAndroidMouse::onMouseEvent(AInputEvent* event)
int8_t mouseAction = eventAction & AMOTION_EVENT_ACTION_MASK;
size_t mousePointer = eventAction >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
+#ifdef DEBUG_VERBOSE
CXBMCApp::android_printf("%s pointer:%i", __PRETTY_FUNCTION__, mousePointer);
+#endif
float x = AMotionEvent_getX(event, mousePointer);
float y = AMotionEvent_getY(event, mousePointer);
@@ -52,6 +57,9 @@ bool CAndroidMouse::onMouseEvent(AInputEvent* event)
case AMOTION_EVENT_ACTION_DOWN:
MouseButton(x,y,mouseAction);
return true;
+ case AMOTION_EVENT_ACTION_SCROLL:
+ MouseWheel(x, y, AMotionEvent_getAxisValue(event, AMOTION_EVENT_AXIS_VSCROLL, mousePointer));
+ return true;
default:
MouseMove(x,y);
return true;
@@ -61,7 +69,9 @@ bool CAndroidMouse::onMouseEvent(AInputEvent* event)
void CAndroidMouse::MouseMove(float x, float y)
{
+#ifdef DEBUG_VERBOSE
CXBMCApp::android_printf("%s: x:%f, y:%f", __PRETTY_FUNCTION__, x, y);
+#endif
XBMC_Event newEvent;
memset(&newEvent, 0, sizeof(newEvent));
@@ -79,7 +89,9 @@ void CAndroidMouse::MouseMove(float x, float y)
void CAndroidMouse::MouseButton(float x, float y, int32_t action)
{
+#ifdef DEBUG_VERBOSE
CXBMCApp::android_printf("%s: x:%f, y:%f, action:%i", __PRETTY_FUNCTION__, x, y, action);
+#endif
XBMC_Event newEvent;
memset(&newEvent, 0, sizeof(newEvent));
@@ -92,3 +104,41 @@ void CAndroidMouse::MouseButton(float x, float y, int32_t action)
newEvent.button.button = XBMC_BUTTON_LEFT;
CWinEvents::MessagePush(&newEvent);
}
+
+void CAndroidMouse::MouseWheel(float x, float y, float value)
+{
+#ifdef DEBUG_VERBOSE
+ CXBMCApp::android_printf("%s: val:%f", __PRETTY_FUNCTION__, value);
+#endif
+ XBMC_Event newEvent;
+
+ memset(&newEvent, 0, sizeof(newEvent));
+
+ if (value > 0.0f)
+ {
+ newEvent.type = XBMC_MOUSEBUTTONDOWN;
+ newEvent.button.state = XBMC_PRESSED;
+ newEvent.button.button = XBMC_BUTTON_WHEELUP;
+ }
+ else if (value < 0.0f)
+ {
+ newEvent.type = XBMC_MOUSEBUTTONDOWN;
+ newEvent.button.state = XBMC_PRESSED;
+ newEvent.button.button = XBMC_BUTTON_WHEELDOWN;
+ }
+ else
+ return;
+
+ newEvent.button.type = newEvent.type;
+ newEvent.button.x = x;
+ newEvent.button.y = y;
+
+ CWinEvents::MessagePush(&newEvent);
+
+ newEvent.type = XBMC_MOUSEBUTTONUP;
+ newEvent.button.state = XBMC_RELEASED;
+ newEvent.button.type = newEvent.type;
+
+ CWinEvents::MessagePush(&newEvent);
+}
+
View
1 xbmc/android/activity/AndroidMouse.h
@@ -34,4 +34,5 @@ class CAndroidMouse
private:
void MouseMove(float x, float y);
void MouseButton(float x, float y, int32_t type);
+ void MouseWheel(float x, float y, float value);
};
View
8 xbmc/android/activity/EventLoop.cpp
@@ -22,6 +22,10 @@
#include "XBMCApp.h"
#include "AndroidExtra.h"
+#include <dlfcn.h>
+
+typeof(AMotionEvent_getAxisValue) *p_AMotionEvent_getAxisValue;
+
CEventLoop::CEventLoop(android_app* application)
: m_enabled(false),
m_application(application),
@@ -44,6 +48,10 @@ void CEventLoop::run(IActivityHandler &activityHandler, IInputHandler &inputHand
m_activityHandler = &activityHandler;
m_inputHandler = &inputHandler;
+ // missing in early NDKs, is present in r9b+
+ p_AMotionEvent_getAxisValue = (typeof(AMotionEvent_getAxisValue)*) dlsym(RTLD_DEFAULT, "AMotionEvent_getAxisValue");
+ CXBMCApp::android_printf("CEventLoop: AMotionEvent_getAxisValue: %p", p_AMotionEvent_getAxisValue);
+
CXBMCApp::android_printf("CEventLoop: starting event loop");
while (1)
{
View
2 xbmc/input/MouseStat.h
@@ -52,7 +52,7 @@ struct MouseState
int y; // y location
int16_t dx; // change in x
int16_t dy; // change in y
- char dz; // change in z (wheel)
+ int8_t dz; // change in z (wheel)
bool button[5]; // current state of the buttons
bool active; // true if the mouse is active
};

0 comments on commit c5fdafe

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