Created
September 5, 2016 19:23
-
-
Save Ell/530e9c1f4b087ec049c650079638fcc0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
renderCanvas () { | |
const {ctx, img, offset, zoom} = this.state; | |
const {width, height} = this.props; | |
const cappedZoom = Math.max(1, zoom); | |
const imgSize = Math.min(img.width, img.height); | |
const left = (img.width - imgSize) / 2; | |
const top = (img.height - imgSize) / 2; | |
let hMovement = (-(cappedZoom - 1) * height) - offset.x; | |
let vMovement = (-(cappedZoom - 1) * width) - offset.y; | |
console.log('movement', `x: ${hMovement}, y: ${vMovement}`); | |
ctx.clearRect(0, 0, width, height); | |
ctx.setTransform(cappedZoom, 0, 0, cappedZoom, hMovement, vMovement); | |
ctx.drawImage(img, left, top, imgSize, imgSize, 0, 0, width, height); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment