MCPcopy Create free account
hub / github.com/melonjs/melonJS / normalizeEvent

Function normalizeEvent

packages/melonjs/src/input/pointerevent.ts:468–511  ·  view source on GitHub ↗

* translate event coordinates * @ignore

(originalEvent: any)

Source from the content-addressed store, hash-verified

466 * @ignore
467 */
468function normalizeEvent(originalEvent: any): Pointer[] {
469 let _pointer: Pointer;
470
471 // PointerEvent or standard Mouse event
472 if (device.touchEvent && originalEvent.changedTouches) {
473 // iOS/Android Touch event
474 for (let i = 0, l = originalEvent.changedTouches.length; i < l; i++) {
475 const touchEvent = originalEvent.changedTouches[i];
476 _pointer = T_POINTERS.pop()!;
477 _pointer.setEvent(
478 originalEvent,
479 touchEvent.pageX,
480 touchEvent.pageY,
481 touchEvent.clientX,
482 touchEvent.clientY,
483 touchEvent.identifier,
484 );
485 normalizedEvents.push(_pointer);
486 }
487 } else {
488 // Mouse or PointerEvent
489 _pointer = T_POINTERS.pop()!;
490 _pointer.setEvent(
491 originalEvent,
492 originalEvent.pageX,
493 originalEvent.pageY,
494 originalEvent.clientX,
495 originalEvent.clientY,
496 originalEvent.pointerId,
497 );
498 normalizedEvents.push(_pointer);
499 }
500
501 // if event.isPrimary is defined and false, return
502 if (originalEvent.isPrimary === false) {
503 return normalizedEvents;
504 }
505
506 // else use the first entry to simulate mouse event
507 normalizedEvents[0].isPrimary = true;
508 Object.assign(pointer, normalizedEvents[0]);
509
510 return normalizedEvents;
511}
512
513/**
514 * mouse/touch/pointer event management (move)

Callers 2

onMoveEventFunction · 0.85
onPointerEventFunction · 0.85

Calls 2

setEventMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected