diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index ad80ea7f8c6..5e3d1d0db67 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -146,7 +146,8 @@ OSystem_Android::OSystem_Android(int audio_sample_rate, int audio_buffer_size) : _touchpad_scale(66), _dpad_scale(4), _fingersDown(0), - _trackball_scale(2) { + _trackball_scale(2), + _joystick_scale(10) { _fsFactory = new POSIXFilesystemFactory(); diff --git a/backends/platform/android/android.h b/backends/platform/android/android.h index b4813b3bdfb..704ce12f602 100644 --- a/backends/platform/android/android.h +++ b/backends/platform/android/android.h @@ -231,6 +231,7 @@ private: int _touchpad_scale; int _trackball_scale; int _dpad_scale; + int _joystick_scale; int _fingersDown; void clipMouse(Common::Point &p); diff --git a/backends/platform/android/events.cpp b/backends/platform/android/events.cpp index 5ad9ed825cd..4d7ef9caf20 100644 --- a/backends/platform/android/events.cpp +++ b/backends/platform/android/events.cpp @@ -65,6 +65,7 @@ enum { JE_RMB_UP = 12, JE_MOUSE_MOVE = 13, JE_GAMEPAD = 14, + JE_JOYSTICK = 15, JE_QUIT = 0x1000 }; @@ -896,6 +897,31 @@ void OSystem_Android::pushEvent(int type, int arg1, int arg2, int arg3, break; + case JE_JOYSTICK: + e.mouse = getEventManager()->getMousePos(); + + switch (arg1) { + case JACTION_MULTIPLE: + e.type = Common::EVENT_MOUSEMOVE; + + // already multiplied by 100 + e.mouse.x += arg2 * _joystick_scale / _eventScaleX; + e.mouse.y += arg3 * _joystick_scale / _eventScaleY; + + clipMouse(e.mouse); + + break; + default: + LOGE("unhandled jaction on joystick: %d", arg1); + return; + } + + lockMutex(_event_queue_lock); + _event_queue.push(e); + unlockMutex(_event_queue_lock); + + return; + case JE_QUIT: e.type = Common::EVENT_QUIT; diff --git a/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java b/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java index 829a948435a..5d041dafd21 100644 --- a/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java +++ b/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java @@ -240,6 +240,14 @@ public class ScummVMActivity extends Activity { return false; } + @Override + public boolean onGenericMotionEvent(final MotionEvent e) { + if (_events != null) + return _events.onGenericMotionEvent(e); + + return false; + } + private void showKeyboard(boolean show) { SurfaceView main_surface = (SurfaceView)findViewById(R.id.main_surface); InputMethodManager imm = (InputMethodManager) diff --git a/backends/platform/android/org/scummvm/scummvm/ScummVMEvents.java b/backends/platform/android/org/scummvm/scummvm/ScummVMEvents.java index 9278e7ff1c0..21f177f0c7f 100644 --- a/backends/platform/android/org/scummvm/scummvm/ScummVMEvents.java +++ b/backends/platform/android/org/scummvm/scummvm/ScummVMEvents.java @@ -9,6 +9,7 @@ import android.view.MotionEvent; import android.view.View; import android.view.ViewConfiguration; import android.view.GestureDetector; +import android.view.InputDevice; import android.view.inputmethod.InputMethodManager; public class ScummVMEvents implements @@ -32,6 +33,7 @@ public class ScummVMEvents implements public static final int JE_RMB_UP = 12; public static final int JE_MOUSE_MOVE = 13; public static final int JE_GAMEPAD = 14; + public static final int JE_JOYSTICK = 15; public static final int JE_QUIT = 0x1000; final protected Context _context; @@ -64,6 +66,18 @@ public class ScummVMEvents implements return true; } + public boolean onGenericMotionEvent(final MotionEvent e) { + if((e.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { + _scummvm.pushEvent(JE_JOYSTICK, e.getAction(), + (int)(e.getAxisValue(MotionEvent.AXIS_X)*100), + (int)(e.getAxisValue(MotionEvent.AXIS_Y)*100), + 0, 0); + return true; + } + + return false; + } + final static int MSG_MENU_LONG_PRESS = 1; final private Handler keyHandler = new Handler() {