/*** 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
#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)
// trigger left, right
#define AMOTION_EVENT_AXIS_LTRIGGER 17
#define AMOTION_EVENT_AXIS_RTRIGGER 18
+// mouse vertical wheel
+#define AMOTION_EVENT_AXIS_VSCROLL 0x09
#include <math.h>
-#include <dlfcn.h>
//#define DEBUG_VERBOSE
{ 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)
, 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()
*/
#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()
{
}
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);
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;
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));
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));
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);
+}
+
private:
void MouseMove(float x, float y);
void MouseButton(float x, float y, int32_t type);
+ void MouseWheel(float x, float y, float value);
};
#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),
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)
{
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
};