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

Method drawNodeShape

src/LGraphCanvas.ts:4835–4941  ·  view source on GitHub ↗

* Draws the shape of the given node on the canvas * @param node The node to draw * @param ctx 2D canvas rendering context used to draw * @param size Size of the background to draw, in graph units. Differs from node size if collapsed, etc. * @param fgcolor Foreground colour - used for te

(
    node: LGraphNode,
    ctx: CanvasRenderingContext2D,
    size: Size,
    fgcolor: CanvasColour,
    bgcolor: CanvasColour,
    _selected: boolean,
  )

Source from the content-addressed store, hash-verified

4833 * @param _selected Whether to render the node as selected. Likely to be removed in future, as current usage is simply the selected property of the node.
4834 */
4835 drawNodeShape(
4836 node: LGraphNode,
4837 ctx: CanvasRenderingContext2D,
4838 size: Size,
4839 fgcolor: CanvasColour,
4840 bgcolor: CanvasColour,
4841 _selected: boolean,
4842 ): void {
4843 // Rendering options
4844 ctx.strokeStyle = fgcolor
4845 ctx.fillStyle = bgcolor
4846
4847 const title_height = LiteGraph.NODE_TITLE_HEIGHT
4848 const { low_quality } = this
4849
4850 const { collapsed } = node.flags
4851 const shape = node.renderingShape
4852 const { title_mode } = node
4853
4854 const render_title = title_mode == TitleMode.TRANSPARENT_TITLE || title_mode == TitleMode.NO_TITLE
4855 ? false
4856 : true
4857
4858 // Normalised node dimensions
4859 const area = LGraphCanvas.#tmp_area
4860 area.set(node.boundingRect)
4861 area[0] -= node.pos[0]
4862 area[1] -= node.pos[1]
4863
4864 const old_alpha = ctx.globalAlpha
4865
4866 // Draw node background (shape)
4867 ctx.beginPath()
4868 if (shape == RenderShape.BOX || low_quality) {
4869 ctx.rect(area[0], area[1], area[2], area[3])
4870 } else if (shape == RenderShape.ROUND || shape == RenderShape.CARD) {
4871 ctx.roundRect(
4872 area[0],
4873 area[1],
4874 area[2],
4875 area[3],
4876 shape == RenderShape.CARD
4877 ? [LiteGraph.ROUND_RADIUS, LiteGraph.ROUND_RADIUS, 0, 0]
4878 : [LiteGraph.ROUND_RADIUS],
4879 )
4880 } else if (shape == RenderShape.CIRCLE) {
4881 ctx.arc(size[0] * 0.5, size[1] * 0.5, size[0] * 0.5, 0, Math.PI * 2)
4882 }
4883 ctx.fill()
4884
4885 // Separator - title bar <-> body
4886 if (!collapsed && render_title) {
4887 ctx.shadowColor = "transparent"
4888 ctx.fillStyle = "rgba(0,0,0,0.2)"
4889 ctx.fillRect(0, -1, area[2], 2)
4890 }
4891 ctx.shadowColor = "transparent"
4892

Callers 1

drawNodeMethod · 0.95

Calls 6

strokeShapeFunction · 0.90
setMethod · 0.80
drawTitleBoxMethod · 0.80
drawTitleTextMethod · 0.80
drawProgressBarMethod · 0.80

Tested by

no test coverage detected