Fixed invalid left button press event for USB mouse, added mousewheel events

This commit is contained in:
pelya
2012-08-02 16:38:40 +03:00
parent a89e0bf89d
commit a6eb841030
7 changed files with 100 additions and 8 deletions

3
.gitmodules vendored
View File

@@ -22,3 +22,6 @@
[submodule "project/jni/application/openarena/engine"]
path = project/jni/application/openarena/engine
url = https://github.com/pelya/openarena-engine.git
[submodule "project/jni/application/scummvm/scummvm"]
path = project/jni/application/scummvm/scummvm
url = https://github.com/scummvm/scummvm.git

View File

@@ -397,7 +397,6 @@ abstract class DifferentTouchInput
public void process(final MotionEvent event)
{
//System.out.println("Got motion event, type " + (int)(event.getAction()) + " X " + (int)event.getX() + " Y " + (int)event.getY() + " buttons " + buttonState + " source " + event.getSource());
super.process(event); // Push mouse coordinate first
int buttonStateNew = event.getButtonState();
if( buttonStateNew != buttonState )
{
@@ -408,6 +407,19 @@ abstract class DifferentTouchInput
}
buttonState = buttonStateNew;
}
super.process(event); // Push mouse coordinate first
}
public void processGenericEvent(final MotionEvent event)
{
// Process mousewheel
if( event.getAction() == MotionEvent.ACTION_SCROLL )
{
int scrollX = Math.round(event.getAxisValue(MotionEvent.AXIS_HSCROLL));
int scrollY = Math.round(event.getAxisValue(MotionEvent.AXIS_VSCROLL));
DemoGLSurfaceView.nativeMouseWheel(scrollX, scrollY);
return;
}
super.processGenericEvent(event);
}
}
private static class GalaxyNoteIcsTouchInput extends IcsTouchInput
@@ -720,7 +732,7 @@ class DemoGLSurfaceView extends GLSurfaceView_SDL {
public static native void initJavaCallbacks();
public static native void nativeHardwareMouseDetected( int detected );
public static native void nativeMouseButtonsPressed( int buttonId, int pressedState );
public static native void nativeMouseWheel(int scrollX, int scrollY);
}

View File

@@ -593,7 +593,7 @@ int main(int argc, char* argv[])
if( b & SDL_BUTTON_RMASK )
color |= 0x1f0;
if( b & SDL_BUTTON_MMASK )
color |= 0x1f;
color |= 0x0f;
}
r.x = mx;
r.y = my;
@@ -613,6 +613,12 @@ int main(int argc, char* argv[])
if(evt.key.keysym.sym == SDLK_ESCAPE)
return 0;
}
if(evt.type == SDL_MOUSEBUTTONUP || evt.type == SDL_MOUSEBUTTONDOWN)
{
__android_log_print(ANDROID_LOG_INFO, "Ballfield", "SDL mouse button event: evt %s state %s button %d coords %d:%d", evt.type == SDL_MOUSEBUTTONUP ? "UP " : "DOWN" , evt.button.state == SDL_PRESSED ? "PRESSED " : "RELEASED", (int)evt.button.button, (int)evt.button.x, (int)evt.button.y);
if(evt.key.keysym.sym == SDLK_ESCAPE)
return 0;
}
if(evt.type == SDL_VIDEORESIZE)
__android_log_print(ANDROID_LOG_INFO, "Ballfield", "SDL resize event: %d x %d", evt.resize.w, evt.resize.h);
if(evt.type == SDL_ACTIVEEVENT)

View File

@@ -14,6 +14,8 @@ SwVideoMode=y
SdlVideoResize=y
SdlVideoResizeKeepAspect=n
CompatibilityHacks=n
CompatibilityHacksStaticInit=n
CompatibilityHacksTextInputEmulatesHwKeyboard=n
AppUsesMouse=y
AppNeedsTwoButtonMouse=y
ShowMouseCursor=n

View File

@@ -574,7 +574,8 @@ JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMotionEvent) ( JNIEnv* env, jobject t
if( leftClickMethod == LEFT_CLICK_NORMAL )
{
SDL_ANDROID_MainThreadPushMouseMotion(x, y);
SDL_ANDROID_MainThreadPushMouseButton( SDL_PRESSED, SDL_BUTTON_LEFT );
if( !hardwareMouseDetected || currentMouseButtons == 0 )
SDL_ANDROID_MainThreadPushMouseButton( SDL_PRESSED, SDL_BUTTON_LEFT );
}
else
{
@@ -995,6 +996,52 @@ JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMouseButtonsPressed) (JNIEnv* env, jobj
SDL_ANDROID_MainThreadPushMouseButton( pressedState ? SDL_PRESSED : SDL_RELEASED, btn );
}
JNIEXPORT void JNICALL
JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMouseWheel) (JNIEnv* env, jobject thiz, jint scrollX, jint scrollY)
{
#if SDL_VERSION_ATLEAST(1,3,0)
SDL_ANDROID_MainThreadPushMouseWheel( scrollX, scrollY );
#else
// TODO: direction might get inverted
for( ; scrollX > 0; scrollX-- )
{
SDL_ANDROID_MainThreadPushKeyboardKey( SDL_PRESSED, TranslateKey(KEYCODE_DPAD_RIGHT) );
SDL_ANDROID_MainThreadPushKeyboardKey( SDL_RELEASED, TranslateKey(KEYCODE_DPAD_RIGHT) );
}
for( ; scrollX < 0; scrollX++ )
{
SDL_ANDROID_MainThreadPushKeyboardKey( SDL_PRESSED, TranslateKey(KEYCODE_DPAD_LEFT) );
SDL_ANDROID_MainThreadPushKeyboardKey( SDL_RELEASED, TranslateKey(KEYCODE_DPAD_LEFT) );
}
for( ; scrollY > 0; scrollY-- )
{
if(!isMouseUsed)
{
SDL_ANDROID_MainThreadPushKeyboardKey( SDL_PRESSED, TranslateKey(KEYCODE_DPAD_DOWN) );
SDL_ANDROID_MainThreadPushKeyboardKey( SDL_RELEASED, TranslateKey(KEYCODE_DPAD_DOWN) );
}
else
{
SDL_ANDROID_MainThreadPushMouseButton( SDL_PRESSED, SDL_BUTTON_WHEELDOWN );
SDL_ANDROID_MainThreadPushMouseButton( SDL_RELEASED, SDL_BUTTON_WHEELDOWN );
}
}
for( ; scrollY < 0; scrollY++ )
{
if(!isMouseUsed)
{
SDL_ANDROID_MainThreadPushKeyboardKey( SDL_PRESSED, TranslateKey(KEYCODE_DPAD_UP) );
SDL_ANDROID_MainThreadPushKeyboardKey( SDL_RELEASED, TranslateKey(KEYCODE_DPAD_UP) );
}
else
{
SDL_ANDROID_MainThreadPushMouseButton( SDL_PRESSED, SDL_BUTTON_WHEELUP );
SDL_ANDROID_MainThreadPushMouseButton( SDL_RELEASED, SDL_BUTTON_WHEELUP );
}
}
#endif
}
JNIEXPORT void JNICALL
JAVA_EXPORT_NAME(Settings_nativeSetJoystickUsed) (JNIEnv* env, jobject thiz)
{
@@ -1443,7 +1490,7 @@ extern void SDL_ANDROID_PumpEvents()
switch( ev.type )
{
case SDL_MOUSEMOTION:
SDL_SendMouseMotion(ANDROID_CurrentWindow, 0, ev.motion.x, ev.motion.y);
SDL_SendMouseMotion( ANDROID_CurrentWindow, 0, ev.motion.x, ev.motion.y );
break;
case SDL_MOUSEBUTTONDOWN:
if( ((oldMouseButtons & SDL_BUTTON(ev.button.button)) != 0) != ev.button.state )
@@ -1478,6 +1525,9 @@ extern void SDL_ANDROID_PumpEvents()
case SDL_TEXTINPUT:
SDL_SendKeyboardText(ev.text.text);
break;
case SDL_MOUSEWHEEL:
SDL_SendMouseWheel( ANDROID_CurrentWindow, ev.wheel.x, ev.wheel.y );
break;
#endif
}
@@ -1764,6 +1814,24 @@ extern void SDL_ANDROID_MainThreadPushMultitouchMotion(int id, int x, int y, int
#endif
};
extern void SDL_ANDROID_MainThreadPushMouseWheel(int x, int y)
{
#if SDL_VERSION_ATLEAST(1,3,0)
int nextEvent = getNextEventAndLock();
if( nextEvent == -1 )
return;
SDL_Event * ev = &BufferedEvents[BufferedEventsEnd];
ev->type = SDL_MOUSEWHEEL;
ev->wheel.x = x;
ev->wheel.y = y;
BufferedEventsEnd = nextEvent;
SDL_mutexV(BufferedEventsMutex);
#endif
}
enum { DEFERRED_TEXT_COUNT = 256 };
static struct { int scancode; int unicode; int down; } deferredText[DEFERRED_TEXT_COUNT];
static int deferredTextIdx1 = 0;

View File

@@ -194,12 +194,12 @@ extern int SDL_ANDROID_isTouchscreenKeyboardUsed;
extern void SDL_ANDROID_MainThreadPushMouseMotion(int x, int y);
extern void SDL_ANDROID_MainThreadPushMouseButton(int pressed, int button);
extern void SDL_ANDROID_MainThreadPushKeyboardKey(int pressed, SDL_scancode key);
extern void SDL_ANDROID_MainThreadPushMultitouchButton(int id, int pressed, int x, int y, int force);
extern void SDL_ANDROID_MainThreadPushMultitouchMotion(int id, int x, int y, int force);
extern void SDL_ANDROID_MainThreadPushMultitouchButton(int id, int pressed, int x, int y, int force); // SDL 1.3 only
extern void SDL_ANDROID_MainThreadPushMultitouchMotion(int id, int x, int y, int force); // SDL 1.3 only
extern void SDL_ANDROID_MainThreadPushJoystickAxis(int joy, int axis, int value);
extern void SDL_ANDROID_MainThreadPushJoystickButton(int joy, int button, int pressed);
extern void SDL_ANDROID_MainThreadPushJoystickBall(int joy, int ball, int x, int y);
extern void SDL_ANDROID_MainThreadPushText( int ascii, int unicode );
extern void SDL_android_init_keymap(SDLKey *SDL_android_keymap);
extern void SDL_ANDROID_MainThreadPushMouseWheel( int x, int y ); // SDL 1.3 only
#endif