Skip to content

Commit 84e6e99

Browse files
DrJKLgithub-actions
andauthored
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 <[email protected]>
1 parent abf2b3b commit 84e6e99

File tree

13 files changed

+50
-66
lines changed

13 files changed

+50
-66
lines changed
-4 Bytes
Loading
-16 Bytes
Loading
-35 Bytes
Loading
-49 Bytes
Loading
567 Bytes
Loading
108 Bytes
Loading

src/components/graph/GraphCanvas.vue

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ import { useGlobalLitegraph } from '@/composables/useGlobalLitegraph'
103103
import { usePaste } from '@/composables/usePaste'
104104
import { useVueFeatureFlags } from '@/composables/useVueFeatureFlags'
105105
import { i18n, t } from '@/i18n'
106+
import { LiteGraph } from '@/lib/litegraph/src/litegraph'
106107
import { useLitegraphSettings } from '@/platform/settings/composables/useLitegraphSettings'
107108
import { CORE_SETTINGS } from '@/platform/settings/constants/coreSettings'
108109
import { useSettingStore } from '@/platform/settings/settingStore'
@@ -143,6 +144,8 @@ const workspaceStore = useWorkspaceStore()
143144
const canvasStore = useCanvasStore()
144145
const executionStore = useExecutionStore()
145146
const toastStore = useToastStore()
147+
const colorPaletteStore = useColorPaletteStore()
148+
const colorPaletteService = useColorPaletteService()
146149
const canvasInteractions = useCanvasInteractions()
147150
148151
const betaMenuEnabled = computed(
@@ -192,6 +195,15 @@ const allNodes = computed((): VueNodeData[] =>
192195
Array.from(vueNodeLifecycle.nodeManager.value?.vueNodeData?.values() ?? [])
193196
)
194197
198+
watchEffect(() => {
199+
LiteGraph.nodeOpacity = settingStore.get('Comfy.Node.Opacity')
200+
})
201+
watchEffect(() => {
202+
LiteGraph.nodeLightness = colorPaletteStore.completedActivePalette.light_theme
203+
? 0.5
204+
: undefined
205+
})
206+
195207
watchEffect(() => {
196208
nodeDefStore.showDeprecated = settingStore.get('Comfy.Node.ShowDeprecated')
197209
})
@@ -238,8 +250,6 @@ watch(
238250
}
239251
)
240252
241-
const colorPaletteService = useColorPaletteService()
242-
const colorPaletteStore = useColorPaletteStore()
243253
watch(
244254
[() => canvasStore.canvas, () => settingStore.get('Comfy.ColorPalette')],
245255
async ([canvas, currentPaletteId]) => {

src/lib/litegraph/src/LGraphCanvas.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5194,10 +5194,9 @@ export class LGraphCanvas
51945194
const color = node.renderingColor
51955195
const bgcolor = node.renderingBgColor
51965196

5197-
const { low_quality, editor_alpha } = this
5198-
ctx.globalAlpha = editor_alpha
5197+
ctx.globalAlpha = this.getNodeModeAlpha(node)
51995198

5200-
if (this.render_shadows && !low_quality) {
5199+
if (this.render_shadows && !this.low_quality) {
52015200
ctx.shadowColor = LiteGraph.DEFAULT_SHADOW_COLOR
52025201
ctx.shadowOffsetX = 2 * this.ds.scale
52035202
ctx.shadowOffsetY = 2 * this.ds.scale
@@ -5259,7 +5258,7 @@ export class LGraphCanvas
52595258
}
52605259
}
52615260

5262-
if (!low_quality) {
5261+
if (!this.low_quality) {
52635262
node.drawBadges(ctx)
52645263
}
52655264

@@ -5693,6 +5692,14 @@ export class LGraphCanvas
56935692
ctx.globalAlpha = 1
56945693
}
56955694

5695+
private getNodeModeAlpha(node: LGraphNode) {
5696+
return node.mode === LGraphEventMode.BYPASS
5697+
? 0.2
5698+
: node.mode === LGraphEventMode.NEVER
5699+
? 0.4
5700+
: this.editor_alpha
5701+
}
5702+
56965703
#renderFloatingLinks(
56975704
ctx: CanvasRenderingContext2D,
56985705
graph: LGraph,
@@ -6044,7 +6051,7 @@ export class LGraphCanvas
60446051
): void {
60456052
node.drawWidgets(ctx, {
60466053
lowQuality: this.low_quality,
6047-
editorAlpha: this.editor_alpha
6054+
editorAlpha: this.getNodeModeAlpha(node)
60486055
})
60496056
}
60506057

src/lib/litegraph/src/LGraphNode.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from '@/renderer/core/canvas/litegraph/slotCalculations'
88
import { useLayoutMutations } from '@/renderer/core/layout/operations/layoutMutations'
99
import { LayoutSource } from '@/renderer/core/layout/types'
10+
import { type ColorAdjustOptions, adjustColor } from '@/utils/colorUtil'
1011

1112
import type { DragAndScale } from './DragAndScale'
1213
import type { LGraph } from './LGraph'
@@ -302,13 +303,25 @@ export class LGraphNode
302303

303304
/** The fg color used to render the node. */
304305
get renderingColor(): string {
305-
return this.color || this.constructor.color || LiteGraph.NODE_DEFAULT_COLOR
306+
const baseColor =
307+
this.color || this.constructor.color || LiteGraph.NODE_DEFAULT_COLOR
308+
return adjustColor(baseColor, { lightness: LiteGraph.nodeLightness })
306309
}
307310

308311
/** The bg color used to render the node. */
309312
get renderingBgColor(): string {
310-
return (
313+
const baseBgColor =
311314
this.bgcolor || this.constructor.bgcolor || LiteGraph.NODE_DEFAULT_BGCOLOR
315+
const adjustments: ColorAdjustOptions = {
316+
opacity: LiteGraph.nodeOpacity,
317+
lightness: LiteGraph.nodeLightness
318+
}
319+
320+
return adjustColor(
321+
this.mode === LGraphEventMode.BYPASS
322+
? LiteGraph.NODE_DEFAULT_BYPASS_COLOR
323+
: baseBgColor,
324+
adjustments
312325
)
313326
}
314327

src/lib/litegraph/src/LiteGraphGlobal.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ export class LiteGraphGlobal {
6060
NODE_BOX_OUTLINE_COLOR = '#FFF'
6161
NODE_ERROR_COLOUR = '#E00'
6262
NODE_FONT = 'Arial'
63+
NODE_DEFAULT_BYPASS_COLOR = '#FF00FF'
64+
NODE_OPACITY = 0.9
6365

6466
DEFAULT_FONT = 'Arial'
6567
DEFAULT_SHADOW_COLOR = 'rgba(0,0,0,0.5)'
@@ -348,6 +350,10 @@ export class LiteGraphGlobal {
348350
*/
349351
vueNodesMode: boolean = false
350352

353+
// Special Rendering Values pulled out of app.ts patches
354+
nodeOpacity = 1
355+
nodeLightness: number | undefined = undefined
356+
351357
// TODO: Remove legacy accessors
352358
LGraph = LGraph
353359
LLink = LLink

0 commit comments

Comments
 (0)