Skip to content

Commit

Permalink
Up getMouseRelativePos
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed Oct 3, 2023
1 parent 30341c2 commit bb6f152
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/canvas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,27 +470,25 @@ export default class CanvasModule extends Module<CanvasConfig> {
* @private
*/
getMouseRelativePos(e: any, opts: any = {}) {
var addTop = 0;
var addLeft = 0;
var subWinOffset = opts.subWinOffset;
var doc = e.target.ownerDocument;
var win = doc.defaultView || doc.parentWindow;
var frame = win.frameElement;
var yOffset = subWinOffset ? win.pageYOffset : 0;
var xOffset = subWinOffset ? win.pageXOffset : 0;
const subWinOffset = opts.subWinOffset;
const doc = e.target.ownerDocument;
const win = doc.defaultView || doc.parentWindow;
const frame = win.frameElement;
const yOffset = subWinOffset ? win.pageYOffset : 0;
const xOffset = subWinOffset ? win.pageXOffset : 0;
const zoomMlt = this.getZoomMultiplier();
let addTop = 0;
let addLeft = 0;

if (frame) {
var frameRect = frame.getBoundingClientRect();
addTop = frameRect.top || 0;
addLeft = frameRect.left || 0;
}

const zoom = this.getZoomDecimal();
const zoomOffset = 1 / zoom;

return {
y: (e.clientY + addTop - yOffset) * zoomOffset,
x: (e.clientX + addLeft - xOffset) * zoomOffset,
y: (e.clientY + addTop - yOffset) * zoomMlt,
x: (e.clientX + addLeft - xOffset) * zoomMlt,
};
}

Expand Down

0 comments on commit bb6f152

Please sign in to comment.