ocanvas icon indicating copy to clipboard operation
ocanvas copied to clipboard

transformPointerPosition gives incorrect coordinates when the context is scaled

Open onurkerimov opened this issue 5 years ago • 1 comments

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.

onurkerimov avatar Dec 24 '18 23:12 onurkerimov

I just made the following pull request for the issue: https://github.com/koggdal/ocanvas/pull/163 By the way your library is awesome :)

onurkerimov avatar Dec 25 '18 00:12 onurkerimov