From 2869c82aa7486b37d9e873dbc7757d22362f5743 Mon Sep 17 00:00:00 2001 From: David Sanders Date: Sat, 7 Nov 2015 15:31:35 -0800 Subject: [PATCH] Add 'isTouch' to force touchscreen mode --- src/controlP5/ControlP5.java | 2 ++ src/controlP5/ControlWindow.java | 26 ++++++++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/controlP5/ControlP5.java b/src/controlP5/ControlP5.java index 5ba4747..ad3b875 100755 --- a/src/controlP5/ControlP5.java +++ b/src/controlP5/ControlP5.java @@ -148,6 +148,8 @@ public class ControlP5 extends ControlP5Base { protected boolean isAnnotation; boolean isAndroid = false; + public boolean isTouch = false; + /** * Create a new instance of controlP5. * diff --git a/src/controlP5/ControlWindow.java b/src/controlP5/ControlWindow.java index 5c329ca..a43a8fe 100755 --- a/src/controlP5/ControlWindow.java +++ b/src/controlP5/ControlWindow.java @@ -451,18 +451,32 @@ public final class ControlWindow { */ public void mouseEvent( MouseEvent theMouseEvent ) { if ( isMouse ) { + final int action = theMouseEvent.getAction(); + + if ( cp5.isTouch ) { + // Ignore certain events when touch-enabled + if ( action == MouseEvent.CLICK || action == MouseEvent.MOVE ) { + return; + } + } + mouseX = theMouseEvent.getX( ) - cp5.pgx - cp5.ox; mouseY = theMouseEvent.getY( ) - cp5.pgy - cp5.oy; - if ( theMouseEvent.getAction( ) == MouseEvent.PRESS ) { + + if ( cp5.isTouch && ( action == MouseEvent.PRESS || action == MouseEvent.RELEASE ) ) { + // Use 'Android Mode' which is really just touchscreen support + mouseEvent( theMouseEvent.getX( ), theMouseEvent.getY( ), action == MouseEvent.PRESS ); + return; + } + + if ( action == MouseEvent.PRESS ) { mousePressedEvent( ); } - if ( theMouseEvent.getAction( ) == MouseEvent.RELEASE ) { + if ( action == MouseEvent.RELEASE ) { mouseReleasedEvent( ); } - if ( theMouseEvent.getAction( ) == MouseEvent.WHEEL ) { - + if ( action == MouseEvent.WHEEL ) { setMouseWheelRotation( theMouseEvent.getCount( ) ); - } } } @@ -531,7 +545,7 @@ public final class ControlWindow { if ( cp5.blockDraw == false ) { if ( cp5.isAndroid ) { mouseEvent( cp5.papplet.mouseX , cp5.papplet.mouseY , cp5.papplet.mousePressed ); - } else { + } else if ( !cp5.isTouch ) { updateEvents( ); } if ( isVisible ) {