ANDROID: Add support for joystick motion

This commit is contained in:
Marcus Comstedt 2013-08-08 14:53:36 +02:00
parent 1b69f8aede
commit a50ede203b
5 changed files with 51 additions and 1 deletions

View File

@ -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();

View File

@ -231,6 +231,7 @@ private:
int _touchpad_scale;
int _trackball_scale;
int _dpad_scale;
int _joystick_scale;
int _fingersDown;
void clipMouse(Common::Point &p);

View File

@ -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;

View File

@ -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)

View File

@ -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() {