You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How to modify it to scale based on the pinch location
importtype{Canvas}from'fabric'importHammerfrom'hammerjs'exportdefaultclassFabricHammer{currentScale: number|null=nullcurrentScaleX: number|null=nullcurrentScaleY: number|null=nullcurrentRotation: number|null=nulladjustScale=1adjustScaleX=1adjustScaleY=1adjustRotation=0constructor(privatereadonlycanvas: Canvas){consthammer=newHammer.Manager(canvas.upperCanvasEl)constrotate=newHammer.Rotate()constpinch=newHammer.Pinch()hammer.add([pinch,rotate])hammer.get('rotate').set({enable: true})hammer.get('pinch').set({enable: true})hammer.on('pinchstart rotatestart',(e)=>{// console.log('start')this.adjustRotation-=e.rotationconstobject=canvas.getActiveObject()if(object){this.adjustScaleX=object.scaleXthis.adjustScaleY=object.scaleY}})hammer.on('pinchmove rotatemove',(e)=>{this.currentRotation=this.adjustRotation+e.rotationthis.currentScale=this.adjustScale*e.scaleconstobject=canvas.getActiveObject()if(object){this.currentScaleX=this.adjustScaleX*e.scalethis.currentScaleY=this.adjustScaleY*e.scale// Blocks object from being resized too small (and maintains aspect ratio)if(!(this.currentScaleX>object.minScaleLimit&&this.currentScaleY>object.minScaleLimit)){this.currentScaleX=object.scaleXthis.currentScaleY=object.scaleY}object.set({lockMovementX: true,lockMovementY: true})object.set('scaleX',this.currentScaleX)object.set('scaleY',this.currentScaleY)object.rotate(this.currentRotation!)object.setCoords()canvas.renderAll()}})hammer.on('pinchend rotateend',()=>{this.adjustScale=this.currentScale!this.adjustRotation=this.currentRotation!this.adjustScaleX=this.currentScaleX!this.adjustScaleY=this.currentScaleY!constobject=canvas.getActiveObject()if(object){// Timeout is to smooth out jitteryness, especially on iOS (iPad)setTimeout(function(){object.set({lockMovementX: false,lockMovementY: false})},300)}canvas.renderAll()})}}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
How to modify it to scale based on the pinch location
Beta Was this translation helpful? Give feedback.
All reactions