Skip to content

Instantly share code, notes, and snippets.

@richarddprasad
Last active March 26, 2020 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richarddprasad/954b74bf65a57b38cbe01fa5845d8b13 to your computer and use it in GitHub Desktop.
Save richarddprasad/954b74bf65a57b38cbe01fa5845d8b13 to your computer and use it in GitHub Desktop.
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