MCPcopy Create free account
hub / github.com/Comfy-Org/litegraph.js / drawSnapGuide

Method drawSnapGuide

src/LGraphCanvas.ts:4954–4993  ·  view source on GitHub ↗

* Draws a snap guide for a Positionable item. * * Initial design was a simple white rectangle representing the location the * item would land if dropped. * @param ctx The 2D canvas context to draw on * @param item The item to draw a snap guide for * @param shape The shape o

(
    ctx: CanvasRenderingContext2D,
    item: Positionable,
    shape = RenderShape.ROUND,
  )

Source from the content-addressed store, hash-verified

4952 * @todo Shapes
4953 */
4954 drawSnapGuide(
4955 ctx: CanvasRenderingContext2D,
4956 item: Positionable,
4957 shape = RenderShape.ROUND,
4958 ) {
4959 const snapGuide = LGraphCanvas.#temp
4960 snapGuide.set(item.boundingRect)
4961
4962 // Not all items have pos equal to top-left of bounds
4963 const { pos } = item
4964 const offsetX = pos[0] - snapGuide[0]
4965 const offsetY = pos[1] - snapGuide[1]
4966
4967 // Normalise boundingRect to pos to snap
4968 snapGuide[0] += offsetX
4969 snapGuide[1] += offsetY
4970 if (this.#snapToGrid) snapPoint(snapGuide, this.#snapToGrid)
4971 snapGuide[0] -= offsetX
4972 snapGuide[1] -= offsetY
4973
4974 const { globalAlpha } = ctx
4975 ctx.globalAlpha = 1
4976 ctx.beginPath()
4977 const [x, y, w, h] = snapGuide
4978 if (shape === RenderShape.CIRCLE) {
4979 const midX = x + (w * 0.5)
4980 const midY = y + (h * 0.5)
4981 const radius = Math.min(w * 0.5, h * 0.5)
4982 ctx.arc(midX, midY, radius, 0, Math.PI * 2)
4983 } else {
4984 ctx.rect(x, y, w, h)
4985 }
4986
4987 ctx.lineWidth = 0.5
4988 ctx.strokeStyle = "#FFFFFF66"
4989 ctx.fillStyle = "#FFFFFF22"
4990 ctx.fill()
4991 ctx.stroke()
4992 ctx.globalAlpha = globalAlpha
4993 }
4994
4995 drawConnections(ctx: CanvasRenderingContext2D): void {
4996 this.renderedPaths.clear()

Callers 3

drawFrontCanvasMethod · 0.95
drawConnectionsMethod · 0.95
drawGroupsMethod · 0.95

Calls 2

snapPointFunction · 0.90
setMethod · 0.80

Tested by

no test coverage detected