fix: Update node.getBounding box to support collapsed nodes and shadows

This commit is contained in:
Michael Poutre
2023-07-28 20:22:12 -07:00
parent 23c300b7ac
commit beee147000
2 changed files with 32 additions and 10 deletions

7
src/litegraph.d.ts vendored
View File

@@ -825,9 +825,12 @@ export declare class LGraphNode {
/**
* returns the bounding of the object, used for rendering purposes
* @return [x, y, width, height]
* @method getBounding
* @param out [optional] a place to store the output, to free garbage
* @param compute_outer [optional] set to true to include the shadow and connection points in the bounding calculation
* @return the bounding box in format of [topleft_cornerx, topleft_cornery, width, height]
*/
getBounding(): Vector4;
getBounding(out?: Vector4, compute_outer?: boolean): Vector4;
/** checks if a point is inside the shape of a node */
isPointInside(
x: number,

View File

@@ -3773,16 +3773,35 @@
/**
* returns the bounding of the object, used for rendering purposes
* bounding is: [topleft_cornerx, topleft_cornery, width, height]
* @method getBounding
* @return {Float32Array[4]} the total size
* @param out {Float32Array[4]?} [optional] a place to store the output, to free garbage
* @param compute_outer {boolean?} [optional] set to true to include the shadow and connection points in the bounding calculation
* @return {Float32Array[4]} the bounding box in format of [topleft_cornerx, topleft_cornery, width, height]
*/
LGraphNode.prototype.getBounding = function(out) {
LGraphNode.prototype.getBounding = function(out, compute_outer) {
out = out || new Float32Array(4);
out[0] = this.pos[0] - 4;
out[1] = this.pos[1] - LiteGraph.NODE_TITLE_HEIGHT;
out[2] = this.size[0] + 4;
out[3] = this.flags.collapsed ? LiteGraph.NODE_TITLE_HEIGHT : this.size[1] + LiteGraph.NODE_TITLE_HEIGHT;
const nodePos = this.pos;
const nodeFlags = this.flags;
const nodeSize = this.size;
// 4 offset for collapsed node connection points
const left_offset = compute_outer ? 4 : 0;
// 6 offset for right shadow and collapsed node connection points, 1 offset due to how nodes are rendered
const right_offset = compute_outer ? 6 + left_offset : 1 ;
// 4 offset for collapsed nodes top connection points
const top_offset = compute_outer ? 4 : 0;
// 5 offset for bottom shadow and collapsed node connection points
const bottom_offset = compute_outer ? 5 + top_offset : 0;
out[0] = nodePos[0] - left_offset;
out[1] = nodePos[1] - LiteGraph.NODE_TITLE_HEIGHT - top_offset;
out[2] = nodeFlags.collapsed ?
(this._collapsed_width || LiteGraph.NODE_COLLAPSED_WIDTH) + right_offset :
nodeSize[0] + right_offset;
out[3] = nodeFlags.collapsed ?
LiteGraph.NODE_TITLE_HEIGHT + bottom_offset :
nodeSize[1] + LiteGraph.NODE_TITLE_HEIGHT + bottom_offset;
if (this.onBounding) {
this.onBounding(out);
@@ -7667,7 +7686,7 @@ LGraphNode.prototype.executeAction = function(action)
continue;
}
if (!overlapBounding(this.visible_area, n.getBounding(temp))) {
if (!overlapBounding(this.visible_area, n.getBounding(temp, true))) {
continue;
} //out of the visible area