MCPcopy Create free account
hub / github.com/tiny-pilot/tinypilot / parseMouseEvent

Function parseMouseEvent

app/static/js/mouse.js:223–237  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

221 * @returns {MouseEventData}
222 */
223function 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}

Callers 4

onMouseDownMethod · 0.85
onMouseUpMethod · 0.85
onMouseMoveMethod · 0.85
onWheelMethod · 0.85

Calls 1

normalizeWheelDeltaFunction · 0.85

Tested by

no test coverage detected