Actually take action based on a mouse event. Internally updates mouseX, mouseY, mousePressed, and mouseEvent. Then it calls the event type with no params, i.e. mousePressed() or mouseReleased() that the user may have overloaded to do something more useful.
(MouseEvent event)
| 2671 | * overloaded to do something more useful. |
| 2672 | */ |
| 2673 | protected void handleMouseEvent(MouseEvent event) { |
| 2674 | // http://dev.processing.org/bugs/show_bug.cgi?id=170 |
| 2675 | // also prevents mouseExited() on the mac from hosing the mouse |
| 2676 | // position, because x/y are bizarre values on the exit event. |
| 2677 | // see also the id check below.. both of these go together. |
| 2678 | // Not necessary to set mouseX/Y on RELEASE events because the |
| 2679 | // actual position will have been set by a PRESS or DRAG event. |
| 2680 | // However, PRESS events might come without a preceeding move, |
| 2681 | // if the sketch window gains focus on that PRESS. |
| 2682 | final int action = event.getAction(); |
| 2683 | if (action == MouseEvent.DRAG || |
| 2684 | action == MouseEvent.MOVE || |
| 2685 | action == MouseEvent.PRESS) { |
| 2686 | pmouseX = emouseX; |
| 2687 | pmouseY = emouseY; |
| 2688 | mouseX = event.getX(); |
| 2689 | mouseY = event.getY(); |
| 2690 | } |
| 2691 | |
| 2692 | int button = event.getButton(); |
| 2693 | |
| 2694 | // If running on Mac OS, allow ctrl-click as right mouse. |
| 2695 | if (PApplet.platform == PConstants.MACOSX && event.getButton() == PConstants.LEFT) { |
| 2696 | if (action == MouseEvent.PRESS && event.isControlDown()) { |
| 2697 | macosxLeftButtonWithCtrlPressed = true; |
| 2698 | } |
| 2699 | if (macosxLeftButtonWithCtrlPressed) { |
| 2700 | button = PConstants.RIGHT; |
| 2701 | event = new MouseEvent(event.getNative(), event.getMillis(), |
| 2702 | event.getAction(), event.getModifiers(), |
| 2703 | event.getX(), event.getY(), |
| 2704 | button, event.getCount()); |
| 2705 | } |
| 2706 | if (action == MouseEvent.RELEASE) { |
| 2707 | macosxLeftButtonWithCtrlPressed = false; |
| 2708 | } |
| 2709 | } |
| 2710 | |
| 2711 | // Get the (already processed) button code |
| 2712 | mouseButton = button; |
| 2713 | |
| 2714 | /* |
| 2715 | // Compatibility for older code (these have AWT object params, not P5) |
| 2716 | if (mouseEventMethods != null) { |
| 2717 | // Probably also good to check this, in case anyone tries to call |
| 2718 | // postEvent() with an artificial event they've created. |
| 2719 | if (event.getNative() != null) { |
| 2720 | mouseEventMethods.handle(new Object[] { event.getNative() }); |
| 2721 | } |
| 2722 | } |
| 2723 | */ |
| 2724 | |
| 2725 | // this used to only be called on mouseMoved and mouseDragged |
| 2726 | // change it back if people run into trouble |
| 2727 | if (firstMouse) { |
| 2728 | pmouseX = mouseX; |
| 2729 | pmouseY = mouseY; |
| 2730 | dmouseX = mouseX; |
no test coverage detected