mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-23 07:50:15 +00:00
Cleanup: Removing monkeypatches for litegraph logic (#5902)
## Summary Putting the litegraph specific pieces into litegraph itself, using the CanvasGraph and LiteGraphGlobal to coordinate options. This was one part of the Image Previews reloading/calculating with every canvas draw. ## Review Focus Is this keeping things decoupled enough? Is this the right place to put things? Are there assumptions about the options that I'm missing here? ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-5902-WIP-Removing-monkeypatches-for-litegraph-logic-2816d73d3650818b860ec73579b89b54) by [Unito](https://www.unito.io) --------- Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
@@ -5194,10 +5194,9 @@ export class LGraphCanvas
|
||||
const color = node.renderingColor
|
||||
const bgcolor = node.renderingBgColor
|
||||
|
||||
const { low_quality, editor_alpha } = this
|
||||
ctx.globalAlpha = editor_alpha
|
||||
ctx.globalAlpha = this.getNodeModeAlpha(node)
|
||||
|
||||
if (this.render_shadows && !low_quality) {
|
||||
if (this.render_shadows && !this.low_quality) {
|
||||
ctx.shadowColor = LiteGraph.DEFAULT_SHADOW_COLOR
|
||||
ctx.shadowOffsetX = 2 * this.ds.scale
|
||||
ctx.shadowOffsetY = 2 * this.ds.scale
|
||||
@@ -5259,7 +5258,7 @@ export class LGraphCanvas
|
||||
}
|
||||
}
|
||||
|
||||
if (!low_quality) {
|
||||
if (!this.low_quality) {
|
||||
node.drawBadges(ctx)
|
||||
}
|
||||
|
||||
@@ -5693,6 +5692,14 @@ export class LGraphCanvas
|
||||
ctx.globalAlpha = 1
|
||||
}
|
||||
|
||||
private getNodeModeAlpha(node: LGraphNode) {
|
||||
return node.mode === LGraphEventMode.BYPASS
|
||||
? 0.2
|
||||
: node.mode === LGraphEventMode.NEVER
|
||||
? 0.4
|
||||
: this.editor_alpha
|
||||
}
|
||||
|
||||
#renderFloatingLinks(
|
||||
ctx: CanvasRenderingContext2D,
|
||||
graph: LGraph,
|
||||
@@ -6044,7 +6051,7 @@ export class LGraphCanvas
|
||||
): void {
|
||||
node.drawWidgets(ctx, {
|
||||
lowQuality: this.low_quality,
|
||||
editorAlpha: this.editor_alpha
|
||||
editorAlpha: this.getNodeModeAlpha(node)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
} from '@/renderer/core/canvas/litegraph/slotCalculations'
|
||||
import { useLayoutMutations } from '@/renderer/core/layout/operations/layoutMutations'
|
||||
import { LayoutSource } from '@/renderer/core/layout/types'
|
||||
import { type ColorAdjustOptions, adjustColor } from '@/utils/colorUtil'
|
||||
|
||||
import type { DragAndScale } from './DragAndScale'
|
||||
import type { LGraph } from './LGraph'
|
||||
@@ -302,13 +303,25 @@ export class LGraphNode
|
||||
|
||||
/** The fg color used to render the node. */
|
||||
get renderingColor(): string {
|
||||
return this.color || this.constructor.color || LiteGraph.NODE_DEFAULT_COLOR
|
||||
const baseColor =
|
||||
this.color || this.constructor.color || LiteGraph.NODE_DEFAULT_COLOR
|
||||
return adjustColor(baseColor, { lightness: LiteGraph.nodeLightness })
|
||||
}
|
||||
|
||||
/** The bg color used to render the node. */
|
||||
get renderingBgColor(): string {
|
||||
return (
|
||||
const baseBgColor =
|
||||
this.bgcolor || this.constructor.bgcolor || LiteGraph.NODE_DEFAULT_BGCOLOR
|
||||
const adjustments: ColorAdjustOptions = {
|
||||
opacity: LiteGraph.nodeOpacity,
|
||||
lightness: LiteGraph.nodeLightness
|
||||
}
|
||||
|
||||
return adjustColor(
|
||||
this.mode === LGraphEventMode.BYPASS
|
||||
? LiteGraph.NODE_DEFAULT_BYPASS_COLOR
|
||||
: baseBgColor,
|
||||
adjustments
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -60,6 +60,8 @@ export class LiteGraphGlobal {
|
||||
NODE_BOX_OUTLINE_COLOR = '#FFF'
|
||||
NODE_ERROR_COLOUR = '#E00'
|
||||
NODE_FONT = 'Arial'
|
||||
NODE_DEFAULT_BYPASS_COLOR = '#FF00FF'
|
||||
NODE_OPACITY = 0.9
|
||||
|
||||
DEFAULT_FONT = 'Arial'
|
||||
DEFAULT_SHADOW_COLOR = 'rgba(0,0,0,0.5)'
|
||||
@@ -348,6 +350,10 @@ export class LiteGraphGlobal {
|
||||
*/
|
||||
vueNodesMode: boolean = false
|
||||
|
||||
// Special Rendering Values pulled out of app.ts patches
|
||||
nodeOpacity = 1
|
||||
nodeLightness: number | undefined = undefined
|
||||
|
||||
// TODO: Remove legacy accessors
|
||||
LGraph = LGraph
|
||||
LLink = LLink
|
||||
|
||||
Reference in New Issue
Block a user