shemetz / ZoomPanOptions

FoundryVTT module for zooming and panning better
MIT License
7 stars 8 forks source link

Incompatibility with Card Tokens module #45

Open shemetz opened 1 year ago

shemetz commented 1 year ago

Quoting from discord:

you are overriding MouseManager.prototype._onWheel my module just sets the events for the canvas

Hooks.on('canvasReady', (canvas)=>{
  canvas._onMouseWheel = function(event) {
    if ( event.altKey) {
      let degrees = 5;
      if (event.ctrlKey) degrees = 15;
      if (event.shiftKey) degrees = 45;
      canvas.stage.rotation = (event.delta < 0 ? (canvas.stage.rotation + Math.toRadians(degrees)) : (canvas.stage.rotation - Math.toRadians(degrees))) % (2*Math.PI);
      canvas.hud.align();
      Hooks.call('canvasPan', canvas, {});
      return;
    }
    let dz = ( event.delta < 0 ) ? 1.05 : 0.95;
    this.pan({scale: dz * canvas.stage.scale.x});
  }

  canvas.hud.align = function() {
    const hud = this.element[0];
    const {x, y} = canvas.primary.getGlobalPosition();
    const scale = canvas.stage.scale.x;
    hud.style.left = `${x}px`;
    hud.style.top = `${y}px`;
    hud.style.transform = `scale(${scale}) rotate(${Math.round(Math.toDegrees(canvas.stage.rotation)/5)*5}deg)`;
  }
});

I think your override prevents the event from ever reaching the canvas

shemetz commented 1 year ago

link to the other module link: https://github.com/xaukael/card-tokens