From 16c294e0625a72c21960baf97b5b2dcd9f7f1d22 Mon Sep 17 00:00:00 2001 From: lucklyisgood <30568622+lucklyisgood@users.noreply.github.com> Date: Fri, 19 May 2023 14:07:17 +0800 Subject: [PATCH 1/4] Fix issue with subgraph inputs and outputs not being clickable in custom canvas size --- src/litegraph.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/litegraph.js b/src/litegraph.js index 81a451cc9..e1249cc8b 100755 --- a/src/litegraph.js +++ b/src/litegraph.js @@ -5806,7 +5806,7 @@ LGraphNode.prototype.executeAction = function(action) this.mouse[1] = e.clientY; this.graph_mouse[0] = e.canvasX; this.graph_mouse[1] = e.canvasY; - this.last_click_position = [this.mouse[0],this.mouse[1]]; + this.last_click_position = [this.graph_mouse[0],this.graph_mouse[1]]; if (this.pointer_is_down && is_primary ){ this.pointer_is_double = true; @@ -8100,11 +8100,10 @@ LGraphNode.prototype.executeAction = function(action) bgcolor = bgcolor || LiteGraph.NODE_DEFAULT_COLOR; hovercolor = hovercolor || "#555"; textcolor = textcolor || LiteGraph.NODE_TEXT_COLOR; - var yFix = y + LiteGraph.NODE_TITLE_HEIGHT + 2; // fix the height with the title - var pos = this.mouse; - var hover = LiteGraph.isInsideRectangle( pos[0], pos[1], x,yFix,w,h ); + var pos = this.graph_mouse; + var hover = LiteGraph.isInsideRectangle( pos[0], pos[1], x,y,w,h ); pos = this.last_click_position; - var clicked = pos && LiteGraph.isInsideRectangle( pos[0], pos[1], x,yFix,w,h ); + var clicked = pos && LiteGraph.isInsideRectangle( pos[0], pos[1], x,y,w,h ); ctx.fillStyle = hover ? hovercolor : bgcolor; if(clicked) From bdde19b014ad2fdecf22f34527ce10d82760cc28 Mon Sep 17 00:00:00 2001 From: lucklyisgood <30568622+lucklyisgood@users.noreply.github.com> Date: Fri, 19 May 2023 09:45:57 +0000 Subject: [PATCH 2/4] fix mouse pos detection in LGraphCanvas.drawButton --- src/litegraph.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/litegraph.js b/src/litegraph.js index e1249cc8b..abe5e501e 100755 --- a/src/litegraph.js +++ b/src/litegraph.js @@ -5806,7 +5806,7 @@ LGraphNode.prototype.executeAction = function(action) this.mouse[1] = e.clientY; this.graph_mouse[0] = e.canvasX; this.graph_mouse[1] = e.canvasY; - this.last_click_position = [this.graph_mouse[0],this.graph_mouse[1]]; + this.last_click_position = [this.mouse[0],this.mouse[1]]; if (this.pointer_is_down && is_primary ){ this.pointer_is_double = true; @@ -8100,7 +8100,7 @@ LGraphNode.prototype.executeAction = function(action) bgcolor = bgcolor || LiteGraph.NODE_DEFAULT_COLOR; hovercolor = hovercolor || "#555"; textcolor = textcolor || LiteGraph.NODE_TEXT_COLOR; - var pos = this.graph_mouse; + var pos = this.ds.convertOffsetToCanvas(this.graph_mouse); var hover = LiteGraph.isInsideRectangle( pos[0], pos[1], x,y,w,h ); pos = this.last_click_position; var clicked = pos && LiteGraph.isInsideRectangle( pos[0], pos[1], x,y,w,h ); From 676bb3617aba31af0c71533f0680fb1394226093 Mon Sep 17 00:00:00 2001 From: lucklyisgood <30568622+lucklyisgood@users.noreply.github.com> Date: Fri, 19 May 2023 12:33:51 +0000 Subject: [PATCH 3/4] Refactor LGraphCanvas drawButton click logic --- src/litegraph.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/litegraph.js b/src/litegraph.js index abe5e501e..443d8d0e3 100755 --- a/src/litegraph.js +++ b/src/litegraph.js @@ -8103,6 +8103,11 @@ LGraphNode.prototype.executeAction = function(action) var pos = this.ds.convertOffsetToCanvas(this.graph_mouse); var hover = LiteGraph.isInsideRectangle( pos[0], pos[1], x,y,w,h ); pos = this.last_click_position; + if(pos) { + var rect = this.canvas.getBoundingClientRect(); + pos[0] -= rect.left; + pos[1] -= rect.top; + } var clicked = pos && LiteGraph.isInsideRectangle( pos[0], pos[1], x,y,w,h ); ctx.fillStyle = hover ? hovercolor : bgcolor; From 9936e3de5d4d1faff9842a4c90498d63fc254fdf Mon Sep 17 00:00:00 2001 From: lucklyisgood <30568622+lucklyisgood@users.noreply.github.com> Date: Fri, 19 May 2023 13:04:37 +0000 Subject: [PATCH 4/4] Refactor LGraphCanvas drawButton click logic(2) --- src/litegraph.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/litegraph.js b/src/litegraph.js index 443d8d0e3..ba0b1ee9b 100755 --- a/src/litegraph.js +++ b/src/litegraph.js @@ -8102,7 +8102,7 @@ LGraphNode.prototype.executeAction = function(action) textcolor = textcolor || LiteGraph.NODE_TEXT_COLOR; var pos = this.ds.convertOffsetToCanvas(this.graph_mouse); var hover = LiteGraph.isInsideRectangle( pos[0], pos[1], x,y,w,h ); - pos = this.last_click_position; + pos = this.last_click_position ? [this.last_click_position[0], this.last_click_position[1]] : null; if(pos) { var rect = this.canvas.getBoundingClientRect(); pos[0] -= rect.left;