From 06427279bfc68c19b456d91a502879a1b98296dc Mon Sep 17 00:00:00 2001 From: benfry Date: Tue, 13 Nov 2012 12:59:10 +0000 Subject: [PATCH] working on mouse event handling --- core/src/processing/core/PApplet.java | 66 ++++++++++++++++++++++----- core/todo.txt | 5 +- 2 files changed, 58 insertions(+), 13 deletions(-) diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java index 49ddb6204..131b166e2 100644 --- a/core/src/processing/core/PApplet.java +++ b/core/src/processing/core/PApplet.java @@ -2425,7 +2425,11 @@ public class PApplet extends Applet // Compatibility for older code if (mouseEventMethods != null) { - mouseEventMethods.handle(new Object[] { event.getNative() }); + // Probably also good to check this, in case anyone tries to call + // postEvent() with an artificial event they've created. + if (event.getNative() != null) { + mouseEventMethods.handle(new Object[] { event.getNative() }); + } } // this used to only be called on mouseMoved and mouseDragged @@ -2439,15 +2443,28 @@ public class PApplet extends Applet } mouseEvent = event; - handleMethods("mouseEvent", new Object[] { event }); + + // Do this up here in case a registered method relies on the + // boolean for mousePressed. switch (event.getAction()) { case MouseEvent.PRESSED: mousePressed = true; - mousePressed(); break; case MouseEvent.RELEASED: mousePressed = false; + break; + } + + handleMethods("mouseEvent", new Object[] { event }); + + switch (event.getAction()) { + case MouseEvent.PRESSED: +// mousePressed = true; + mousePressed(); + break; + case MouseEvent.RELEASED: +// mousePressed = false; mouseReleased(); break; case MouseEvent.CLICKED: @@ -2459,6 +2476,12 @@ public class PApplet extends Applet case MouseEvent.MOVED: mouseMoved(); break; + case MouseEvent.ENTERED: + mouseEntered(); + break; + case MouseEvent.EXITED: + mouseExited(); + break; } if ((event.getAction() == MouseEvent.DRAGGED) || @@ -2500,7 +2523,10 @@ public class PApplet extends Applet break; } - int modifiers = nativeEvent.getModifiersEx(); + System.out.println(nativeEvent); + + //int modifiers = nativeEvent.getModifiersEx(); + int modifiers = nativeEvent.getModifiers(); int peModifiers = modifiers & (InputEvent.SHIFT_DOWN_MASK | @@ -2515,19 +2541,30 @@ public class PApplet extends Applet // The fix for which led to a regression (fixed here by checking both): // http://code.google.com/p/processing/issues/detail?id=1332 int peButton = 0; - if ((modifiers & InputEvent.BUTTON1_MASK) != 0 || - (modifiers & InputEvent.BUTTON1_DOWN_MASK) != 0) { +// if ((modifiers & InputEvent.BUTTON1_MASK) != 0 || +// (modifiers & InputEvent.BUTTON1_DOWN_MASK) != 0) { +// peButton = LEFT; +// } else if ((modifiers & InputEvent.BUTTON2_MASK) != 0 || +// (modifiers & InputEvent.BUTTON2_DOWN_MASK) != 0) { +// peButton = CENTER; +// } else if ((modifiers & InputEvent.BUTTON3_MASK) != 0 || +// (modifiers & InputEvent.BUTTON3_DOWN_MASK) != 0) { +// peButton = RIGHT; +// } + if ((modifiers & InputEvent.BUTTON1_MASK) != 0) { peButton = LEFT; - } else if ((modifiers & InputEvent.BUTTON2_MASK) != 0 || - (modifiers & InputEvent.BUTTON2_DOWN_MASK) != 0) { + } else if ((modifiers & InputEvent.BUTTON2_MASK) != 0) { peButton = CENTER; - } else if ((modifiers & InputEvent.BUTTON3_MASK) != 0 || - (modifiers & InputEvent.BUTTON3_DOWN_MASK) != 0) { + } else if ((modifiers & InputEvent.BUTTON3_MASK) != 0) { peButton = RIGHT; } - // if running on macos, allow ctrl-click as right mouse + + // If running on macos, allow ctrl-click as right mouse. Prior to 0215, + // this used isPopupTrigger() on the native event, but that doesn't work + // for mouseClicked and mouseReleased (or others). if (platform == MACOSX) { - if (nativeEvent.isPopupTrigger()) { + //if (nativeEvent.isPopupTrigger()) { + if ((modifiers & InputEvent.CTRL_DOWN_MASK) != 0) { peButton = RIGHT; } } @@ -2690,6 +2727,11 @@ public class PApplet extends Applet */ public void mouseMoved() { } + public void mouseEntered() { } + + public void mouseExited() { } + + ////////////////////////////////////////////////////////////// diff --git a/core/todo.txt b/core/todo.txt index b914aa8c3..1656ac676 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -6,8 +6,11 @@ X change translate() and rotate() to use x, y, z as param names cleaning o remove screenBlend(), textureBlend() from PGraphics et al o have andres take over all current GL issues in the tracker +X Support 'black' as color for SVG files (PhiLho fix) +X http://code.google.com/p/processing/issues/detail?id=1010 events +_ make sure alt/ctl/meta/etc all work _ finish postEvent() _ need to make events interleave _ http://code.google.com/p/processing/issues/detail?id=79 @@ -17,7 +20,7 @@ _ mouseButton is 0 in mouseReleased() on OS X _ http://code.google.com/p/processing/issues/detail?id=1373 _ unconfirmed: keyEvent works only using JAVA2D _ http://code.google.com/p/processing/issues/detail?id=1279 -_ mouseEntered/Exited? +_ mouseEntered/Exited? (they're caught but not handled) _ http://code.google.com/p/processing/issues/detail?id=500 _ also look into Android issues with this stuff _ this only works for awt events... switch to using internal event code