* Parses a standard JavaScript mouse event into a TinyPilot-specific object * containing information about the mouse event. * * The mouse event data in TinyPilot-specific format. * * @typedef {Object} MouseEventData * @property {number} buttons - A bitmask representing which mouse buttons are
(evt)
| 221 | * @returns {MouseEventData} |
| 222 | */ |
| 223 | function parseMouseEvent(evt) { |
| 224 | const boundingRect = evt.target.getBoundingClientRect(); |
| 225 | const cursorX = Math.max(0, evt.clientX - boundingRect.left); |
| 226 | const cursorY = Math.max(0, evt.clientY - boundingRect.top); |
| 227 | const width = boundingRect.right - boundingRect.left; |
| 228 | const height = boundingRect.bottom - boundingRect.top; |
| 229 | |
| 230 | return { |
| 231 | buttons: evt.buttons, |
| 232 | relativeX: Math.min(1.0, Math.max(0.0, cursorX / width)), |
| 233 | relativeY: Math.min(1.0, Math.max(0.0, cursorY / height)), |
| 234 | verticalWheelDelta: normalizeWheelDelta(evt.deltaY), |
| 235 | horizontalWheelDelta: normalizeWheelDelta(evt.deltaX), |
| 236 | }; |
| 237 | } |
no test coverage detected