Fixed button event for stylus

This commit is contained in:
pelya
2012-06-15 19:07:11 +03:00
parent 37ad9e446c
commit e38ade1e6b
4 changed files with 36 additions and 51 deletions

View File

@@ -200,10 +200,10 @@ class Settings
System.out.println("android.os.Build.MODEL: " + android.os.Build.MODEL);
if( (android.os.Build.MODEL.equals("GT-N7000") || android.os.Build.MODEL.equals("SGH-I717"))
/* && android.os.Build.VERSION.SDK_INT <= android.os.Build.VERSION_CODES.GINGERBREAD_MR1 */ )
&& android.os.Build.VERSION.SDK_INT <= android.os.Build.VERSION_CODES.GINGERBREAD_MR1 )
{
// Samsung Galaxy Note generates a keypress when you hover a stylus over the screen, and that messes up OpenTTD dialogs
// And I don't know whether this is true for ICS update for Galaxy Note
// ICS update sends events in a proper way
Globals.RemapHwKeycode[112] = SDL_1_2_Keycodes.SDLK_UNKNOWN;
}

View File

@@ -343,7 +343,6 @@ abstract class DifferentTouchInput
boolean hwMouseEvent = ( event.getSource() == InputDevice.SOURCE_MOUSE ||
event.getSource() == InputDevice.SOURCE_STYLUS ||
(event.getMetaState() & KeyEvent.FLAG_TRACKING) != 0 ); // Hack to recognize Galaxy Note Gingerbread stylus
//System.out.println("Event source: " + event.getSource() + " stylus: " + hwMouseEvent + " meta " + event.getMetaState());
if( ExternalMouseDetected != hwMouseEvent )
{
ExternalMouseDetected = hwMouseEvent;
@@ -393,13 +392,18 @@ abstract class DifferentTouchInput
private int buttonState = 0;
public void process(final MotionEvent event)
{
if( event.getButtonState() != buttonState )
//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 )
{
buttonState = event.getButtonState();
//System.out.println("IcsTouchInput: button state " + buttonState);
DemoGLSurfaceView.nativeMouseButtonsPressed(buttonState);
for( int i = 1; i <= MotionEvent.BUTTON_FORWARD; i *= 2 )
{
if( (buttonStateNew & i) != (buttonState & i) )
DemoGLSurfaceView.nativeMouseButtonsPressed(i, ((buttonStateNew & i) == 0) ? 0 : 1);
}
buttonState = buttonStateNew;
}
super.process(event);
}
}
}
@@ -697,7 +701,7 @@ class DemoGLSurfaceView extends GLSurfaceView_SDL {
public static native void nativeTouchpad( int x, int y, int down, int multitouch );
public static native void initJavaCallbacks();
public static native void nativeHardwareMouseDetected( int detected );
public static native void nativeMouseButtonsPressed( int buttons );
public static native void nativeMouseButtonsPressed( int buttonId, int pressedState );
}

View File

@@ -640,6 +640,7 @@ int main(int argc, char* argv[])
}
int mx, my;
int b = SDL_GetMouseState(&mx, &my);
//__android_log_print(ANDROID_LOG_INFO, "Ballfield", "Mouse buttons: %d", b);
Uint32 color = 0xff;
if( b )
{

View File

@@ -120,7 +120,6 @@ static int currentMouseButtons = 0;
static int hardwareMouseDetected = 0;
enum { MOUSE_HW_BUTTON_LEFT = 1, MOUSE_HW_BUTTON_RIGHT = 2, MOUSE_HW_BUTTON_MIDDLE = 4, MOUSE_HW_BUTTON_BACK = 8, MOUSE_HW_BUTTON_FORWARD = 16, MOUSE_HW_BUTTON_MAX = MOUSE_HW_BUTTON_FORWARD };
static int hardwareMouseButtonsPressed = 0;
static int UnicodeToUtf8(int src, char * dest)
{
@@ -471,45 +470,7 @@ JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMotionEvent) ( JNIEnv* env, jobject t
if( !isMouseUsed )
return;
//__android_log_print(ANDROID_LOG_INFO, "libSDL", "Mouse buttons %d pointerId %d firstMousePointerId %d", hardwareMouseButtonsPressed, pointerId, firstMousePointerId);
if( pointerId == firstMousePointerId && (currentMouseButtons != hardwareMouseButtonsPressed || hardwareMouseButtonsPressed != 0) )
{
SDL_ANDROID_MainThreadPushMouseMotion(x, y);
for( i = 1; i <= MOUSE_HW_BUTTON_MAX; i *= 2 )
{
int btn = SDL_BUTTON_LEFT;
switch(i)
{
case MOUSE_HW_BUTTON_LEFT:
btn = SDL_BUTTON_LEFT;
break;
case MOUSE_HW_BUTTON_RIGHT:
btn = SDL_BUTTON_RIGHT;
break;
case MOUSE_HW_BUTTON_MIDDLE:
btn = SDL_BUTTON_MIDDLE;
break;
case MOUSE_HW_BUTTON_BACK:
btn = SDL_BUTTON_WHEELUP;
break;
case MOUSE_HW_BUTTON_FORWARD:
btn = SDL_BUTTON_WHEELDOWN;
break;
}
if( (hardwareMouseButtonsPressed & i) && !(currentMouseButtons & i) )
{
//__android_log_print(ANDROID_LOG_INFO, "libSDL", "Mouse button DOWN: %d", btn);
SDL_ANDROID_MainThreadPushMouseButton( SDL_PRESSED, btn );
}
else
if( !(hardwareMouseButtonsPressed & i) && (currentMouseButtons & i) )
{
//__android_log_print(ANDROID_LOG_INFO, "libSDL", "Mouse button UP : %d", btn);
SDL_ANDROID_MainThreadPushMouseButton( SDL_RELEASED, btn );
}
}
}
else if( pointerId == firstMousePointerId )
if( pointerId == firstMousePointerId )
{
if( relativeMovement )
{
@@ -1005,12 +966,31 @@ JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeHardwareMouseDetected) (JNIEnv* env, jo
}
JNIEXPORT void JNICALL
JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMouseButtonsPressed) (JNIEnv* env, jobject thiz, int buttons)
JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMouseButtonsPressed) (JNIEnv* env, jobject thiz, jint buttonId, jint pressedState)
{
int btn = SDL_BUTTON_LEFT;
if( !isMouseUsed )
return;
hardwareMouseButtonsPressed = buttons;
switch(buttonId)
{
case MOUSE_HW_BUTTON_LEFT:
btn = SDL_BUTTON_LEFT;
break;
case MOUSE_HW_BUTTON_RIGHT:
btn = SDL_BUTTON_RIGHT;
break;
case MOUSE_HW_BUTTON_MIDDLE:
btn = SDL_BUTTON_MIDDLE;
break;
case MOUSE_HW_BUTTON_BACK:
btn = SDL_BUTTON_WHEELUP;
break;
case MOUSE_HW_BUTTON_FORWARD:
btn = SDL_BUTTON_WHEELDOWN;
break;
}
SDL_ANDROID_MainThreadPushMouseButton( pressedState ? SDL_PRESSED : SDL_RELEASED, btn );
}
JNIEXPORT void JNICALL