Toggle navigation
Toggle navigation
This project
Loading...
Sign in
강동현
/
nodejs-game
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Overnap
2021-06-08 06:16:58 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
764e194ab9df7e4fc2c2c3c70c39878437d09175
764e194a
1 parent
de7e6e65
유틸 콜백 추가
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
0 deletions
web/src/components/room/Canvas.tsx
web/src/components/room/Canvas.tsx
View file @
764e194
...
...
@@ -4,6 +4,35 @@ import { Vector } from './types';
export const Canvas: React.FC = () => {
const canvasRef = useRef<HTMLCanvasElement>(null);
const getCoordinates = useCallback((event: MouseEvent): Vector | undefined => {
if (!canvasRef.current) {
return;
} else {
return {
x: event.pageX - canvasRef.current.offsetLeft,
y: event.pageY - canvasRef.current.offsetTop
};
}
}, []);
const drawLine = useCallback((prev: Vector, current: Vector) => {
if (canvasRef.current) {
const context = canvasRef.current!.getContext('2d');
if (context) {
context.strokeStyle = 'black';
context.lineJoin = 'round';
context.lineWidth = 5;
context.beginPath();
context.moveTo(prev.x, prev.y);
context.lineTo(current.x, current.y);
context.closePath();
context.stroke();
}
}
}, []);
return (
<div className='mx-3 px-2 py-1 rounded shadow'>
<canvas ref={canvasRef} width='512' height='384' />
...
...
Please
register
or
login
to post a comment