Revert "Add canvas update events (#297)" (#310)

This reverts commit 0e8f02f32f.
This commit is contained in:
Chenlei Hu
2024-11-16 17:32:53 -05:00
committed by GitHub
parent 0e8f02f32f
commit f26f7dbe2c
2 changed files with 7 additions and 42 deletions

View File

@@ -137,7 +137,6 @@ export class LGraph implements LinkNetwork, Serialisable<SerialisableGraph> {
onExecuteStep?(): void onExecuteStep?(): void
onNodeAdded?(node: LGraphNode): void onNodeAdded?(node: LGraphNode): void
onNodeRemoved?(node: LGraphNode): void onNodeRemoved?(node: LGraphNode): void
onNodeUpdated?(node: LGraphNode): void
onTrigger?(action: string, param: unknown): void onTrigger?(action: string, param: unknown): void
onInputRenamed?(old_name: string, name: string): void onInputRenamed?(old_name: string, name: string): void
onInputTypeChanged?(name: string, type: string): void onInputTypeChanged?(name: string, type: string): void
@@ -146,8 +145,8 @@ export class LGraph implements LinkNetwork, Serialisable<SerialisableGraph> {
onOutputRenamed?(old_name: string, name: string): void onOutputRenamed?(old_name: string, name: string): void
onOutputTypeChanged?(name: string, type: string): void onOutputTypeChanged?(name: string, type: string): void
onOutputRemoved?(name: string): void onOutputRemoved?(name: string): void
onBeforeChange?(graph: LGraph, node?: LGraphNode): void onBeforeChange?(graph: LGraph, info?: LGraphNode): void
onAfterChange?(graph: LGraph, node?: LGraphNode): void onAfterChange?(graph: LGraph, info?: LGraphNode): void
onConnectionChange?(node: LGraphNode): void onConnectionChange?(node: LGraphNode): void
on_change?(graph: LGraph): void on_change?(graph: LGraph): void
onSerialize?(data: ISerialisedGraph | SerialisableGraph): void onSerialize?(data: ISerialisedGraph | SerialisableGraph): void
@@ -1206,19 +1205,15 @@ export class LGraph implements LinkNetwork, Serialisable<SerialisableGraph> {
} }
} }
//used for undo, called before any change is made to the graph //used for undo, called before any change is made to the graph
beforeChange(node?: LGraphNode): void { beforeChange(info?: LGraphNode): void {
this.onBeforeChange?.(this, node) this.onBeforeChange?.(this, info)
this.canvasAction(c => c.onBeforeChange?.(this)) this.canvasAction(c => c.onBeforeChange?.(this))
} }
//used to resend actions, called after any change is made to the graph //used to resend actions, called after any change is made to the graph
afterChange(node?: LGraphNode): void { afterChange(info?: LGraphNode): void {
this.onAfterChange?.(this, node) this.onAfterChange?.(this, info)
this.canvasAction(c => c.onAfterChange?.(this)) this.canvasAction(c => c.onAfterChange?.(this))
} }
nodeUpdate(node?: LGraphNode): void {
this.onNodeUpdated?.(node)
this.canvasAction(c => c.onNodeUpdated?.(node))
}
connectionChange(node: LGraphNode): void { connectionChange(node: LGraphNode): void {
this.updateExecutionOrder() this.updateExecutionOrder()
this.onConnectionChange?.(node) this.onConnectionChange?.(node)

View File

@@ -370,8 +370,6 @@ export class LGraphCanvas {
onBeforeChange?(graph: LGraph): void onBeforeChange?(graph: LGraph): void
/** called after modifying the graph */ /** called after modifying the graph */
onAfterChange?(graph: LGraph): void onAfterChange?(graph: LGraph): void
onPositionChanged?: (offset: Point) => void
onZoomChanged?: (scale: number) => void
onClear?: () => void onClear?: () => void
/** called after moving a node */ /** called after moving a node */
onNodeMoved?: (node_dragged: LGraphNode) => void onNodeMoved?: (node_dragged: LGraphNode) => void
@@ -386,8 +384,6 @@ export class LGraphCanvas {
onShowNodePanel?: (n: LGraphNode) => void onShowNodePanel?: (n: LGraphNode) => void
onNodeSelected?: (node: LGraphNode) => void onNodeSelected?: (node: LGraphNode) => void
onNodeDeselected?: (node: LGraphNode) => void onNodeDeselected?: (node: LGraphNode) => void
onNodeUpdated?: (node: LGraphNode) => void
onNodeWidgetChanged?: (node: LGraphNode, name: string, value: unknown, widget: IWidget) => void
onRender?: (canvas: HTMLCanvasElement, ctx: CanvasRenderingContext2D) => void onRender?: (canvas: HTMLCanvasElement, ctx: CanvasRenderingContext2D) => void
/** Implement this function to allow conversion of widget types to input types, e.g. number -> INT or FLOAT for widget link validation checks */ /** Implement this function to allow conversion of widget types to input types, e.g. number -> INT or FLOAT for widget link validation checks */
getWidgetLinkType?: (widget: IWidget, node: LGraphNode) => string | null | undefined getWidgetLinkType?: (widget: IWidget, node: LGraphNode) => string | null | undefined
@@ -2361,10 +2357,6 @@ export class LGraphCanvas {
this.ds.offset[0] += delta[0] / this.ds.scale this.ds.offset[0] += delta[0] / this.ds.scale
this.ds.offset[1] += delta[1] / this.ds.scale this.ds.offset[1] += delta[1] / this.ds.scale
this.#dirty() this.#dirty()
if (this.onPositionChanged) {
this.onPositionChanged(this.ds.offset)
}
} else if ((this.allow_interaction || (node && node.flags.allow_interaction)) && !this.read_only) { } else if ((this.allow_interaction || (node && node.flags.allow_interaction)) && !this.read_only) {
if (this.connecting_links) this.dirty_canvas = true if (this.connecting_links) this.dirty_canvas = true
@@ -2808,14 +2800,6 @@ export class LGraphCanvas {
this.ds.changeScale(scale, [e.clientX, e.clientY]) this.ds.changeScale(scale, [e.clientX, e.clientY])
if (this.onZoomChanged) {
this.onZoomChanged(scale)
}
if (this.onPositionChanged) {
this.onPositionChanged(this.ds.offset)
}
this.graph.change() this.graph.change()
e.preventDefault() e.preventDefault()
@@ -3510,10 +3494,6 @@ export class LGraphCanvas {
node.size[1] * 0.5 + node.size[1] * 0.5 +
(this.canvas.height * 0.5) / (this.ds.scale * dpi) (this.canvas.height * 0.5) / (this.ds.scale * dpi)
this.setDirty(true, true) this.setDirty(true, true)
if (this.onPositionChanged) {
this.onPositionChanged(this.ds.offset)
}
} }
/** /**
* adds some useful properties to a mouse event, like the position in graph coordinates * adds some useful properties to a mouse event, like the position in graph coordinates
@@ -5947,9 +5927,7 @@ export class LGraphCanvas {
if (event.type === LiteGraph.pointerevents_method + "down") { if (event.type === LiteGraph.pointerevents_method + "down") {
if (w.callback) { if (w.callback) {
setTimeout(function () { setTimeout(function () {
that.onNodeWidgetChanged?.(node, w.name, w.value, w) w.callback(w, that, node, pos, event)
node.onWidgetChanged?.(w.name, w.value, old_value, w)
w.callback(w, that, node, pos, event)
}, 20) }, 20)
} }
w.clicked = true w.clicked = true
@@ -6089,7 +6067,6 @@ export class LGraphCanvas {
//value changed //value changed
if (old_value != w.value) { if (old_value != w.value) {
that.onNodeWidgetChanged?.(node, w.name, w.value, w)
node.onWidgetChanged?.(w.name, w.value, old_value, w) node.onWidgetChanged?.(w.name, w.value, old_value, w)
node.graph._version++ node.graph._version++
} }
@@ -6100,9 +6077,6 @@ export class LGraphCanvas {
function inner_value_change(widget: IWidget, value: TWidgetValue) { function inner_value_change(widget: IWidget, value: TWidgetValue) {
const v = widget.type === "number" ? Number(value) : value const v = widget.type === "number" ? Number(value) : value
widget.value = v widget.value = v
that.onNodeWidgetChanged?.(node, widget.name, widget.value, widget)
if (widget.options?.property && node.properties[widget.options.property] !== undefined) { if (widget.options?.property && node.properties[widget.options.property] !== undefined) {
node.setProperty(widget.options.property, v) node.setProperty(widget.options.property, v)
} }
@@ -8189,10 +8163,6 @@ export class LGraphCanvas {
this.setDirty(true, true) this.setDirty(true, true)
if (this.onPositionChanged) {
this.onPositionChanged(this.ds.offset)
}
if (progress < 1) { if (progress < 1) {
animationId = requestAnimationFrame(animate) animationId = requestAnimationFrame(animate)
} else { } else {