FIX: [droid] Handle mouse wheel
authorChris "Koying" Browet <cbro@semperpax.com>
Wed, 13 Nov 2013 12:57:04 +0000 (13:57 +0100)
committerChris "Koying" Browet <cbro@semperpax.com>
Sat, 16 Nov 2013 08:37:54 +0000 (09:37 +0100)
xbmc/android/activity/AndroidExtra.h
xbmc/android/activity/AndroidJoyStick.cpp
xbmc/android/activity/AndroidMouse.cpp
xbmc/android/activity/AndroidMouse.h
xbmc/android/activity/EventLoop.cpp
xbmc/input/MouseStat.h

index 178fb07..ea1b1f0 100644 (file)
  
  /*** 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
index ba9efcf..ece5692 100644 (file)
@@ -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()
index 2027823..a25c255 100644 (file)
  */
 
 #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);
+}
+
index 11fe606..f1746a6 100644 (file)
@@ -34,4 +34,5 @@ protected:
 private:
   void MouseMove(float x, float y);
   void MouseButton(float x, float y, int32_t type);
+  void MouseWheel(float x, float y, float value);
 };
index 7c19a73..851ff51 100644 (file)
 #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)
   {
index c1b45d0..d4db959 100644 (file)
@@ -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
 };