Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

bounding-box.tsx 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import * as React from "react"
  2. import { Edge, Corner } from "types"
  3. import { useSelector } from "state"
  4. import { getSelectedShapes, isMobile } from "utils/utils"
  5. import CenterHandle from "./center-handle"
  6. import CornerHandle from "./corner-handle"
  7. import EdgeHandle from "./edge-handle"
  8. import RotateHandle from "./rotate-handle"
  9. export default function Bounds() {
  10. const isBrushing = useSelector((s) => s.isIn("brushSelecting"))
  11. const isSelecting = useSelector((s) => s.isIn("selecting"))
  12. const zoom = useSelector((s) => s.data.camera.zoom)
  13. const bounds = useSelector((s) => s.values.selectedBounds)
  14. const rotation = useSelector(({ data }) =>
  15. data.selectedIds.size === 1 ? getSelectedShapes(data)[0].rotation : 0
  16. )
  17. if (!bounds) return null
  18. if (!isSelecting) return null
  19. const size = (isMobile().any ? 16 : 8) / zoom // Touch target size
  20. return (
  21. <g
  22. pointerEvents={isBrushing ? "none" : "all"}
  23. transform={`
  24. rotate(${rotation * (180 / Math.PI)},
  25. ${(bounds.minX + bounds.maxX) / 2},
  26. ${(bounds.minY + bounds.maxY) / 2})
  27. translate(${bounds.minX},${bounds.minY})`}
  28. >
  29. <CenterHandle bounds={bounds} />
  30. <EdgeHandle size={size} bounds={bounds} edge={Edge.Top} />
  31. <EdgeHandle size={size} bounds={bounds} edge={Edge.Right} />
  32. <EdgeHandle size={size} bounds={bounds} edge={Edge.Bottom} />
  33. <EdgeHandle size={size} bounds={bounds} edge={Edge.Left} />
  34. <CornerHandle size={size} bounds={bounds} corner={Corner.TopLeft} />
  35. <CornerHandle size={size} bounds={bounds} corner={Corner.TopRight} />
  36. <CornerHandle size={size} bounds={bounds} corner={Corner.BottomRight} />
  37. <CornerHandle size={size} bounds={bounds} corner={Corner.BottomLeft} />
  38. <RotateHandle size={size} bounds={bounds} />
  39. </g>
  40. )
  41. }