Mouse constructor

Mouse(
  1. HTMLCanvasElement _canvas
)

Creates a Mouse instance and attaches event listeners to the provided _canvas. Typically, you don't instantiate this class yourself. Instead, you use the app.mouse member provided by the App class.

Implementation

Mouse(this._canvas) {
  // NOTE:
  // https://developer.mozilla.org/de/docs/Web/API/EventTarget/addEventListener
  // In Safari for wheel and touch events the passive default value is true, so
  // we force it to false, because else preventEvent doesn't work
  var opt = AddEventListenerOptions(passive: false);

  _canvas.addEventListener('wheel', _onWheel.toJS, opt);
  _canvas.addEventListener('contextmenu', _onContextMenu.toJS);
  _canvas.addEventListener('touchstart', _onTouchStart.toJS, opt);
  _canvas.addEventListener('touchmove', _onTouchMove.toJS, opt);
  _canvas.addEventListener('touchend', _onTouchEnd.toJS, opt);
  _canvas.addEventListener('fullscreenchange', _onFullscreenChange.toJS);

  window.addEventListener('resize', _onResize.toJS);

  window.addEventListener('mousedown', _onMouseDown.toJS);
  window.addEventListener('mouseup', _onMouseUp.toJS);
  window.addEventListener('mousemove', _onMouseMove.toJS);

  _canvas.addEventListener('click', _onClick.toJS);
  _updateSize();
}