Magnifying glass when hovering finger near display

This commit is contained in:
pelya
2014-02-23 20:09:32 +02:00
parent 881a7daf70
commit 6691181f21
2 changed files with 29 additions and 19 deletions

View File

@@ -100,7 +100,6 @@ abstract class DifferentTouchInput
public static DifferentTouchInput touchInput = getInstance();
public static DifferentTouchInput getInstance()
{
boolean multiTouchAvailable1 = false;
@@ -299,21 +298,6 @@ abstract class DifferentTouchInput
}
}
}
if( (event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_HOVER_MOVE ) // Support bluetooth/USB mouse - available since Android 3.1
{
// TODO: it is possible that multiple pointers return that event, but we're handling only pointer #0
if( touchEvents[0].down )
action = Mouse.SDL_FINGER_UP;
else
action = Mouse.SDL_FINGER_HOVER;
touchEvents[0].down = false;
touchEvents[0].x = (int)event.getX();
touchEvents[0].y = (int)event.getY();
touchEvents[0].pressure = 0;
touchEvents[0].size = 0;
// MotionEvent.AXIS_DISTANCE
DemoGLSurfaceView.nativeMotionEvent( touchEvents[0].x, touchEvents[0].y, action, 0, touchEvents[0].pressure, touchEvents[0].size );
}
}
}
private static class GingerbreadTouchInput extends MultiTouchInput
@@ -338,6 +322,27 @@ abstract class DifferentTouchInput
DemoGLSurfaceView.nativeHardwareMouseDetected(hwMouseEvent);
}
super.process(event);
if( (event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_HOVER_MOVE ) // Support bluetooth/USB mouse - available since Android 3.1
{
int action;
// TODO: it is possible that multiple pointers return that event, but we're handling only pointer #0
if( touchEvents[0].down )
action = Mouse.SDL_FINGER_UP;
else
action = Mouse.SDL_FINGER_HOVER;
touchEvents[0].down = false;
touchEvents[0].x = (int)event.getX();
touchEvents[0].y = (int)event.getY();
touchEvents[0].pressure = 1024;
touchEvents[0].size = 0;
//if( event.getAxisValue(MotionEvent.AXIS_DISTANCE) != 0.0f )
InputDevice device = InputDevice.getDevice(event.getDeviceId());
if( device != null && device.getMotionRange(MotionEvent.AXIS_DISTANCE) != null &&
device.getMotionRange(MotionEvent.AXIS_DISTANCE).getRange() > 0.0f )
touchEvents[0].pressure = (int)((event.getAxisValue(MotionEvent.AXIS_DISTANCE) -
device.getMotionRange(MotionEvent.AXIS_DISTANCE).getMin()) * 1024.0f / device.getMotionRange(MotionEvent.AXIS_DISTANCE).getRange());
DemoGLSurfaceView.nativeMotionEvent( touchEvents[0].x, touchEvents[0].y, action, 0, touchEvents[0].pressure, touchEvents[0].size );
}
}
public void processGenericEvent(final MotionEvent event)
{

View File

@@ -127,7 +127,7 @@ int SDL_ANDROID_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 };
enum { MOUSE_HW_INPUT_FINGER = 0, MOUSE_HW_INPUT_STYLUS = 1, MOUSE_HW_INPUT_MOUSE = 2 };
enum { DEADZONE_HOVER_FINGER = 32, DEADZONE_HOVER_STYLUS = 64, HOVER_FREEZE_TIME = 300 };
enum { DEADZONE_HOVER_FINGER = 32, DEADZONE_HOVER_STYLUS = 64, HOVER_FREEZE_TIME = 300, HOVER_DISTANCE_MAX = 1024 };
static int hoverJitterFilter = 1;
static int hoverX, hoverY, hoverTime = 0, hoverMouseFreeze = 0, hoverDeadzone = 0;
@@ -632,7 +632,7 @@ static void ProcessMouseMultitouch( int action, int pointerId )
}
}
static void ProcessMouseHover( jint *xx, jint *yy, int action )
static void ProcessMouseHover( jint *xx, jint *yy, int action, int distance )
{
int x = *xx, y = *yy;
@@ -677,6 +677,11 @@ static void ProcessMouseHover( jint *xx, jint *yy, int action )
*yy = hoverY;
}
if( action == MOUSE_HOVER && distance < HOVER_DISTANCE_MAX / 4 )
UpdateScreenUnderFingerRect(*xx, *yy);
else
SDL_ANDROID_ShowScreenUnderFingerRect.w = SDL_ANDROID_ShowScreenUnderFingerRect.h = 0; // This is reset later by ProcessMouseMove()
#ifdef VIDEO_DEBUG
SDL_ANDROID_VideoDebugRect.x = hoverX - hoverDeadzone;
SDL_ANDROID_VideoDebugRect.y = hoverY - hoverDeadzone;
@@ -716,7 +721,7 @@ JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMotionEvent) ( JNIEnv* env, jobject t
if( !SDL_ANDROID_isMouseUsed )
return;
ProcessMouseHover( &x, &y, action );
ProcessMouseHover( &x, &y, action, force );
if( pointerId == firstMousePointerId )
{