Last active
March 26, 2020 18:38
-
-
Save richarddprasad/954b74bf65a57b38cbe01fa5845d8b13 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
React.useEffect(() => { | |
let mouseDown: boolean = false; | |
let start: Coordinates = { x: 0, y: 0 }; | |
let end: Coordinates = { x: 0, y: 0 }; | |
let canvasOffsetLeft: number = 0; | |
let canvasOffsetTop: number = 0; | |
function handleMouseDown(evt: MouseEvent) { | |
mouseDown = true; | |
} | |
function handleMouseUp(evt: MouseEvent) { | |
mouseDown = false; | |
} | |
function handleMouseMove(evt: MouseEvent) { | |
} | |
if (canvasRef.current) { | |
const renderCtx = canvasRef.current.getContext('2d'); | |
if (renderCtx) { | |
canvasRef.current.addEventListener('mousedown', handleMouseDown); | |
canvasRef.current.addEventListener('mouseup', handleMouseUp); | |
canvasRef.current.addEventListener('mousemove', handleMouseMove); | |
canvasOffsetLeft = canvasRef.current.offsetLeft; | |
canvasOffsetTop = canvasRef.current.offsetTop; | |
setContext(renderCtx); | |
} | |
} | |
// Draw a rectangle | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment