How do I properly transform entire canvas in fabric.js / change fabric's origin?

走远了吗. 提交于 2019-12-08 07:45:00

问题


I'm trying to set fabric up so the origin is bottom left instead of top left. Currently I'm using setViewportTransform and it transforms everything as I want, except for the selection box. (doesn't seem to get the transformation) I made a fiddle & you can see how if you rotate the rectangle, the selection box rotates the wrong way.

So my question is, how do I set fabric.js' origin to the bottom left?

http://jsfiddle.net/39up3jcm/105/


回答1:


The simplest solution I found was to:

  1. Change the view by adding transform: scaleY(-1) to the canvas CSS
  2. Change the inputs by redefining fabric.Canvas.prototype.getPointer but replace pointer.y = pointer.y - this._offset.top with pointer.y = bounds.height - pointer.y + this._offset.top

** Fabric version 1.7.20



来源:https://stackoverflow.com/questions/50283319/how-do-i-properly-transform-entire-canvas-in-fabric-js-change-fabrics-origin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!