Figure out how to process a mouse event. When loop() has been called, the events will be queued up until drawing is complete. If noLoop() has been called, then events will happen immediately.
(java.awt.event.MouseEvent nativeEvent)
| 1100 | * If noLoop() has been called, then events will happen immediately. |
| 1101 | */ |
| 1102 | protected void nativeMouseEvent(java.awt.event.MouseEvent nativeEvent) { |
| 1103 | // the 'amount' is the number of button clicks for a click event, |
| 1104 | // or the number of steps/clicks on the wheel for a mouse wheel event. |
| 1105 | int peCount = nativeEvent.getClickCount(); |
| 1106 | |
| 1107 | int peAction = 0; |
| 1108 | switch (nativeEvent.getID()) { |
| 1109 | case java.awt.event.MouseEvent.MOUSE_PRESSED: |
| 1110 | peAction = MouseEvent.PRESS; |
| 1111 | break; |
| 1112 | case java.awt.event.MouseEvent.MOUSE_RELEASED: |
| 1113 | peAction = MouseEvent.RELEASE; |
| 1114 | break; |
| 1115 | case java.awt.event.MouseEvent.MOUSE_CLICKED: |
| 1116 | peAction = MouseEvent.CLICK; |
| 1117 | break; |
| 1118 | case java.awt.event.MouseEvent.MOUSE_DRAGGED: |
| 1119 | peAction = MouseEvent.DRAG; |
| 1120 | break; |
| 1121 | case java.awt.event.MouseEvent.MOUSE_MOVED: |
| 1122 | peAction = MouseEvent.MOVE; |
| 1123 | break; |
| 1124 | case java.awt.event.MouseEvent.MOUSE_ENTERED: |
| 1125 | peAction = MouseEvent.ENTER; |
| 1126 | break; |
| 1127 | case java.awt.event.MouseEvent.MOUSE_EXITED: |
| 1128 | peAction = MouseEvent.EXIT; |
| 1129 | break; |
| 1130 | //case java.awt.event.MouseWheelEvent.WHEEL_UNIT_SCROLL: |
| 1131 | case java.awt.event.MouseEvent.MOUSE_WHEEL: |
| 1132 | peAction = MouseEvent.WHEEL; |
| 1133 | /* |
| 1134 | if (preciseWheelMethod != null) { |
| 1135 | try { |
| 1136 | peAmount = ((Double) preciseWheelMethod.invoke(nativeEvent, (Object[]) null)).floatValue(); |
| 1137 | } catch (Exception e) { |
| 1138 | preciseWheelMethod = null; |
| 1139 | } |
| 1140 | } |
| 1141 | */ |
| 1142 | peCount = ((MouseWheelEvent) nativeEvent).getWheelRotation(); |
| 1143 | break; |
| 1144 | } |
| 1145 | |
| 1146 | // Switching to getModifiersEx() for 4.0a2 because of Java 9 deprecation. |
| 1147 | // Had trouble with this in the past and rolled it back because it was |
| 1148 | // optional at the time. This time around, just need to iron out the issue. |
| 1149 | // https://github.com/processing/processing/issues/1332 |
| 1150 | // https://github.com/processing/processing/issues/1370 |
| 1151 | int modifiers = nativeEvent.getModifiersEx(); |
| 1152 | |
| 1153 | int peButton = 0; |
| 1154 | // Because there isn't a button "press" associated with drag, |
| 1155 | // pass this over to SwingUtilities to properly decode the button. |
| 1156 | // https://github.com/processing/processing4/issues/281 |
| 1157 | if (SwingUtilities.isLeftMouseButton(nativeEvent)) { |
| 1158 | peButton = PConstants.LEFT; |
| 1159 | } else if (SwingUtilities.isMiddleMouseButton(nativeEvent)) { |
no test coverage detected