kangax/fabric.js — Issue #82: Mouse coordinates are reported incorrectly when canvas is contained in a scrollview
Author: mindjuice
Created: 2011-11-22 01:42:54+00:00
State: open

The two "getPointer" methods do not return correct coordinates if the canvas element is contained in a parent div that is too small to show the entire canvas, and the canvas is scrolled down or to the right.

A quick experiment with adding parent.scrollTop to the y value and parent.scrollLeft to the x value gave correct results for the fabric.Canvas.getPointer method. This allowed for clicking and dragging of selection handles.

The click-and-drag to draw a selection rectangle uses a different global getPointer() function though, and I was not able to figure out how to fix this yet.

Also, it would be better if there was only one place in the code that did the view-to-canvas coordinate transformation.