You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import styled from "styles"
  2. import React, { useCallback, useRef } from "react"
  3. import useZoomEvents from "hooks/useZoomEvents"
  4. import useCamera from "hooks/useCamera"
  5. import Page from "./page"
  6. import Brush from "./brush"
  7. import state from "state"
  8. import Bounds from "./bounds"
  9. import BoundsBg from "./bounds-bg"
  10. import inputs from "state/inputs"
  11. export default function Canvas() {
  12. const rCanvas = useRef<SVGSVGElement>(null)
  13. const rGroup = useRef<SVGGElement>(null)
  14. const events = useZoomEvents(rCanvas)
  15. useCamera(rGroup)
  16. const handlePointerDown = useCallback((e: React.PointerEvent) => {
  17. rCanvas.current.setPointerCapture(e.pointerId)
  18. state.send("POINTED_CANVAS", inputs.pointerDown(e, "canvas"))
  19. }, [])
  20. const handlePointerMove = useCallback((e: React.PointerEvent) => {
  21. state.send("MOVED_POINTER", inputs.pointerMove(e))
  22. }, [])
  23. const handlePointerUp = useCallback((e: React.PointerEvent) => {
  24. rCanvas.current.releasePointerCapture(e.pointerId)
  25. state.send("STOPPED_POINTING", { id: "canvas", ...inputs.pointerUp(e) })
  26. }, [])
  27. return (
  28. <MainSVG
  29. ref={rCanvas}
  30. {...events}
  31. onPointerDown={handlePointerDown}
  32. onPointerMove={handlePointerMove}
  33. onPointerUp={handlePointerUp}
  34. >
  35. <MainGroup ref={rGroup}>
  36. <BoundsBg />
  37. <Page />
  38. <Bounds />
  39. <Brush />
  40. </MainGroup>
  41. </MainSVG>
  42. )
  43. }
  44. const MainSVG = styled("svg", {
  45. position: "fixed",
  46. top: 0,
  47. left: 0,
  48. width: "100%",
  49. height: "100%",
  50. touchAction: "none",
  51. zIndex: 100,
  52. })
  53. const MainGroup = styled("g", {})