Diffgram's 2D Annotation Editor relies heavily on calculations based on the mouse position for drawing boxes and zooming in/out.
This class provides the basic functionality to calculate the mouse position and zoom in and out of the screen.
We do NOT accumulate transformations on variables, each draw cycle does not reset the canvas unless an edit command requires it. This means that every transformation action, for example a scale, is performed in a step-like process and not accumulated in some variables.
The process for most transform operations is the following:
- Move the object of interest to origin with a translate
- Apply the operation at origin
- Return the object to original position
- Apply the current transformation matrix.
- To get the current transformation matrix of the canvas we use the getTransform() and setTransform() function provided by the Canvas 2D API. More info here: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/getTransform
Updated about 2 years ago