Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- snapToGrid(options) {
- let grid = 50;//this.grid;
- const target = options.target;
- let incrementOriginX = 0;
- let incrementOriginY = 0;
- if (target.originX == 'center') incrementOriginX = (target.width / 2);
- if (target.originY == 'center') incrementOriginY = (target.height / 2);
- if (target.padding > 0) {
- incrementOriginX += target.padding / 2;
- incrementOriginY += target.padding / 2;
- }
- let left = target.left - incrementOriginX;
- let top = target.top - incrementOriginY;
- let gridX = 50, gridY = 50;
- const canvas = options?.target?.canvas || false;
- if (canvas) {
- gridX = (canvas.getWidth() / canvas.getZoom()) / 30;
- gridY = (canvas.getHeight() / canvas.getZoom()) / 30;
- }
- let opts = false;
- if (Math.round(left / gridX * 4) % 4 == 0) {
- opts = { ...opts, left: (Math.round(left / gridX) * gridX) + incrementOriginX };
- }
- if (Math.round(top / gridY * 4) % 4 == 0) {
- opts = { ...opts, top: (Math.round(top / gridY) * gridY) + incrementOriginY };
- }
- if(opts) options.target.set(opts).setCoords();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement