ocanvas
ocanvas copied to clipboard
transformPointerPosition gives incorrect coordinates when the context is scaled
When the 2D rendering context is scaled, (here is a reason for scaling) things like .dragAndDrop() fails. Example setup:
let ratio = 0.8 // some value other than 1
let canvas = document.createElement('CANVAS')
let context = cnv.getContext('2d')
document.body.appendChild(canvas)
context.scale(ratio, ratio)
let oc = oCanvas.create({
canvas: canvas
})
Since the ratio is different from 1, mouse position in terms of document pixels and mouse position in terms of canvas pixels becomes two separate things, x and y values that transformPointerPosition should be multiplied accordingly, to the context scaling ratio.
I just made the following pull request for the issue: https://github.com/koggdal/ocanvas/pull/163 By the way your library is awesome :)