MCPcopy Index your code
hub / github.com/benfry/processing4 / handleMouseEvent

Method handleMouseEvent

core/src/processing/core/PApplet.java:2279–2386  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

2277 * overloaded to do something more useful.
2278 */
2279 protected void handleMouseEvent(MouseEvent event) {
2280 // https://processing.org/bugs/bugzilla/170.html
2281 // also prevents mouseExited() on the mac from hosing the mouse
2282 // position, because x/y are bizarre values on the exit event.
2283 // see also the id check below... both of these go together.
2284 // Not necessary to set mouseX/Y on RELEASE events because the
2285 // actual position will have been set by a PRESS or DRAG event.
2286 // However, PRESS events might come without a preceding move,
2287 // if the sketch window gains focus on that PRESS.
2288 final int action = event.getAction();
2289 if (action == MouseEvent.DRAG ||
2290 action == MouseEvent.MOVE ||
2291 action == MouseEvent.PRESS) {
2292 pmouseX = emouseX;
2293 pmouseY = emouseY;
2294 if (windowRatio) {
2295 rmouseX = floor((event.getX() - ratioLeft) / ratioScale);
2296 rmouseY = floor((event.getY() - ratioTop) / ratioScale);
2297 }
2298 mouseX = event.getX();
2299 mouseY = event.getY();
2300 }
2301
2302 int button = event.getButton();
2303
2304 // If running on macOS, allow ctrl-click as right mouse click.
2305 // Handled inside PApplet so that the same logic need not be redone
2306 // for each Surface independently, since the code seems to be identical:
2307 // no native code backing Surface objects (AWT, JavaFX, JOGL) handle it.
2308 if (PApplet.platform == PConstants.MACOS &&
2309 button == PConstants.LEFT) {
2310 if (action == MouseEvent.PRESS && event.isControlDown()) {
2311 // The ctrl key may only be down during the press, but we need to store
2312 // it so that the drag or release still is considered a right-click.
2313 macosCtrlClick = true;
2314 }
2315 if (macosCtrlClick) {
2316 button = PConstants.RIGHT;
2317 // Recreate the Event object as a right-click, and unset the CTRL flag,
2318 // since it's not a ctrl-right-click, it's just a right click.
2319 int modifiers = event.getModifiers() & ~Event.CTRL;
2320 event = new MouseEvent(event.getNative(), event.getMillis(),
2321 event.getAction(), modifiers,
2322 event.getX(), event.getY(),
2323 button, event.getCount());
2324 }
2325 if (action == MouseEvent.CLICK) {
2326 // Un-set the variable for the next time around.
2327 // (This won't affect the current event being handled.)
2328 // Changed to CLICK instead of RELEASE for 4.0a6, because the click
2329 // event will fire after the press/drag/release events have fired.
2330 macosCtrlClick = false;
2331 }
2332 }
2333
2334 // Get the (already processed) button code
2335 mouseButton = button;
2336

Callers 1

dequeueEventsMethod · 0.95

Calls 15

floorMethod · 0.95
handleMethodsMethod · 0.95
mousePressedMethod · 0.95
mouseReleasedMethod · 0.95
mouseClickedMethod · 0.95
mouseDraggedMethod · 0.95
mouseMovedMethod · 0.95
mouseEnteredMethod · 0.95
mouseExitedMethod · 0.95
mouseWheelMethod · 0.95
getXMethod · 0.80
getYMethod · 0.80

Tested by

no test coverage detected