mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-03 14:54:37 +00:00
fix in shadows
This commit is contained in:
@@ -43,6 +43,7 @@ var LiteGraph = global.LiteGraph = {
|
||||
NODE_DEFAULT_BGCOLOR: "#444",
|
||||
NODE_DEFAULT_BOXCOLOR: "#666",
|
||||
NODE_DEFAULT_SHAPE: "box",
|
||||
DEFAULT_SHADOW_COLOR: "rgba(0,0,0,0.5)",
|
||||
|
||||
LINK_COLOR: "#AAD",
|
||||
EVENT_LINK_COLOR: "#F85",
|
||||
@@ -5250,16 +5251,12 @@ LGraphCanvas.prototype.drawNode = function(node, ctx )
|
||||
return;
|
||||
}
|
||||
|
||||
//custom draw collapsed method
|
||||
if(node.flags.collapsed && node.onDrawCollaped && node.onDrawCollapsed(ctx, this) == true)
|
||||
return;
|
||||
|
||||
var editor_alpha = this.editor_alpha;
|
||||
ctx.globalAlpha = editor_alpha;
|
||||
|
||||
if(this.render_shadows)
|
||||
{
|
||||
ctx.shadowColor = "rgba(0,0,0,0.5)";
|
||||
ctx.shadowColor = LiteGraph.DEFAULT_SHADOW_COLOR;
|
||||
ctx.shadowOffsetX = 2 * this.scale;
|
||||
ctx.shadowOffsetY = 2 * this.scale;
|
||||
ctx.shadowBlur = 3 * this.scale;
|
||||
@@ -5267,6 +5264,10 @@ LGraphCanvas.prototype.drawNode = function(node, ctx )
|
||||
else
|
||||
ctx.shadowColor = "transparent";
|
||||
|
||||
//custom draw collapsed method (draw after shadows because they are affected)
|
||||
if(node.flags.collapsed && node.onDrawCollaped && node.onDrawCollapsed(ctx, this) == true)
|
||||
return;
|
||||
|
||||
//clip if required (mask)
|
||||
var shape = node._shape || LiteGraph.BOX_SHAPE;
|
||||
var size = temp_vec2;
|
||||
@@ -5564,6 +5565,9 @@ LGraphCanvas.prototype.drawNodeShape = function( node, ctx, size, fgcolor, bgcol
|
||||
//title bar
|
||||
if(title_mode != LiteGraph.TRANSPARENT_TITLE) //!node.flags.collapsed)
|
||||
{
|
||||
if(node.flags.collapsed)
|
||||
ctx.shadowColor = LiteGraph.DEFAULT_SHADOW_COLOR;
|
||||
|
||||
//* gradient test
|
||||
if(this.use_gradients)
|
||||
{
|
||||
@@ -5593,15 +5597,7 @@ LGraphCanvas.prototype.drawNodeShape = function( node, ctx, size, fgcolor, bgcol
|
||||
ctx.roundRect(0,-title_height,size[0]+1, title_height, this.round_radius, node.flags.collapsed ? this.round_radius : 0);
|
||||
ctx.fill();
|
||||
}
|
||||
|
||||
/*
|
||||
else if (shape == LiteGraph.CIRCLE_SHAPE)
|
||||
{
|
||||
ctx.beginPath();
|
||||
ctx.arc(title_height *0.5, title_height * -0.5, (title_height - 6) *0.5,0,Math.PI*2);
|
||||
ctx.fill();
|
||||
}
|
||||
*/
|
||||
ctx.shadowColor = "transparent";
|
||||
}
|
||||
|
||||
//title box
|
||||
@@ -6026,7 +6022,8 @@ LGraphCanvas.prototype.drawNodeWidgets = function( node, posY, ctx, active_widge
|
||||
ctx.fill();
|
||||
ctx.stroke();
|
||||
ctx.fillStyle = "#999";
|
||||
ctx.fillText( w.title || "Value", 20, y + H*0.7 );
|
||||
if(w.name != null)
|
||||
ctx.fillText( w.name, 20, y + H*0.7 );
|
||||
ctx.fillStyle = "#DDD";
|
||||
ctx.textAlign = "right";
|
||||
ctx.fillText( w.value, width - 20, y + H*0.7 );
|
||||
|
||||
150
build/litegraph.min.js
vendored
150
build/litegraph.min.js
vendored
@@ -6,8 +6,8 @@ a[1]>e||f<b[0]||c<b[1]?!1:!0}function u(a,b){function f(a){var b=parseInt(e.styl
|
||||
(console.error("Event passed to ContextMenu is not of type MouseEvent or CustomEvent. Ignoring it."),b.event=null);var e=document.createElement("div");e.className="litegraph litecontextmenu litemenubar-panel";e.style.minWidth=100;e.style.minHeight=100;e.style.pointerEvents="none";setTimeout(function(){e.style.pointerEvents="auto"},100);e.addEventListener("mouseup",function(a){a.preventDefault();return!0},!0);e.addEventListener("contextmenu",function(a){if(2!=a.button)return!1;a.preventDefault();return!1},
|
||||
!0);e.addEventListener("mousedown",function(a){if(2==a.button)return c.close(),a.preventDefault(),!0},!0);e.addEventListener("wheel",f,!0);e.addEventListener("mousewheel",f,!0);this.root=e;if(b.title){var l=document.createElement("div");l.className="litemenu-title";l.innerHTML=b.title;e.appendChild(l)}var l=0,n;for(n in a){var k=a.constructor==Array?a[n]:n;null!=k&&k.constructor!==String&&(k=void 0===k.content?String(k):k.content);this.addItem(k,a[n],b);l++}e.addEventListener("mouseleave",function(a){c.lock||
|
||||
c.close(a)});n=document;b.event&&(n=b.event.target.ownerDocument);n||(n=document);n.body.appendChild(e);l=b.left||0;n=b.top||0;if(b.event){l=b.event.pageX-10;n=b.event.pageY-10;b.title&&(n-=20);b.parentMenu&&(l=b.parentMenu.root.getBoundingClientRect(),l=l.left+l.width);var k=document.body.getBoundingClientRect(),g=e.getBoundingClientRect();l>k.width-g.width-10&&(l=k.width-g.width-10);n>k.height-g.height-10&&(n=k.height-g.height-10)}e.style.left=l+"px";e.style.top=n+"px"}var k=t.LiteGraph={CANVAS_GRID_SIZE:10,
|
||||
NODE_TITLE_HEIGHT:20,NODE_SLOT_HEIGHT:15,NODE_WIDGET_HEIGHT:20,NODE_WIDTH:140,NODE_MIN_WIDTH:50,NODE_COLLAPSED_RADIUS:10,NODE_COLLAPSED_WIDTH:80,NODE_TITLE_COLOR:"#999",NODE_TEXT_SIZE:14,NODE_TEXT_COLOR:"#AAA",NODE_SUBTEXT_SIZE:12,NODE_DEFAULT_COLOR:"#333",NODE_DEFAULT_BGCOLOR:"#444",NODE_DEFAULT_BOXCOLOR:"#666",NODE_DEFAULT_SHAPE:"box",LINK_COLOR:"#AAD",EVENT_LINK_COLOR:"#F85",CONNECTING_LINK_COLOR:"#AFA",MAX_NUMBER_OF_NODES:1E3,DEFAULT_POSITION:[100,100],VALID_SHAPES:["default","box","round","card"],
|
||||
BOX_SHAPE:1,ROUND_SHAPE:2,CIRCLE_SHAPE:3,CARD_SHAPE:4,ARROW_SHAPE:5,INPUT:1,OUTPUT:2,EVENT:-1,ACTION:-1,ALWAYS:0,ON_EVENT:1,NEVER:2,ON_TRIGGER:3,UP:1,DOWN:2,LEFT:3,RIGHT:4,CENTER:5,NORMAL_TITLE:0,NO_TITLE:1,TRANSPARENT_TITLE:2,AUTOHIDE_TITLE:3,proxy:null,node_images_path:"",debug:!1,throw_errors:!0,allow_scripts:!0,registered_node_types:{},node_types_by_file_extension:{},Nodes:{},registerNodeType:function(a,b){if(!b.prototype)throw"Cannot register a simple object, it must be a class with a prototype";
|
||||
NODE_TITLE_HEIGHT:20,NODE_SLOT_HEIGHT:15,NODE_WIDGET_HEIGHT:20,NODE_WIDTH:140,NODE_MIN_WIDTH:50,NODE_COLLAPSED_RADIUS:10,NODE_COLLAPSED_WIDTH:80,NODE_TITLE_COLOR:"#999",NODE_TEXT_SIZE:14,NODE_TEXT_COLOR:"#AAA",NODE_SUBTEXT_SIZE:12,NODE_DEFAULT_COLOR:"#333",NODE_DEFAULT_BGCOLOR:"#444",NODE_DEFAULT_BOXCOLOR:"#666",NODE_DEFAULT_SHAPE:"box",DEFAULT_SHADOW_COLOR:"rgba(0,0,0,0.5)",LINK_COLOR:"#AAD",EVENT_LINK_COLOR:"#F85",CONNECTING_LINK_COLOR:"#AFA",MAX_NUMBER_OF_NODES:1E3,DEFAULT_POSITION:[100,100],VALID_SHAPES:["default",
|
||||
"box","round","card"],BOX_SHAPE:1,ROUND_SHAPE:2,CIRCLE_SHAPE:3,CARD_SHAPE:4,ARROW_SHAPE:5,INPUT:1,OUTPUT:2,EVENT:-1,ACTION:-1,ALWAYS:0,ON_EVENT:1,NEVER:2,ON_TRIGGER:3,UP:1,DOWN:2,LEFT:3,RIGHT:4,CENTER:5,NORMAL_TITLE:0,NO_TITLE:1,TRANSPARENT_TITLE:2,AUTOHIDE_TITLE:3,proxy:null,node_images_path:"",debug:!1,throw_errors:!0,allow_scripts:!0,registered_node_types:{},node_types_by_file_extension:{},Nodes:{},registerNodeType:function(a,b){if(!b.prototype)throw"Cannot register a simple object, it must be a class with a prototype";
|
||||
b.type=a;k.debug&&console.log("Node registered: "+a);a.split("/");var f=b.name,c=a.lastIndexOf("/");b.category=a.substr(0,c);b.title||(b.title=f);if(b.prototype)for(var e in d.prototype)b.prototype[e]||(b.prototype[e]=d.prototype[e]);Object.defineProperty(b.prototype,"shape",{set:function(a){switch(a){case "default":delete this._shape;break;case "box":this._shape=k.BOX_SHAPE;break;case "round":this._shape=k.ROUND_SHAPE;break;case "circle":this._shape=k.CIRCLE_SHAPE;break;case "card":this._shape=k.CARD_SHAPE;
|
||||
break;default:this._shape=a}},get:function(a){return this._shape},enumerable:!0});this.registered_node_types[a]=b;b.constructor.name&&(this.Nodes[f]=b);b.prototype.onPropertyChange&&console.warn("LiteGraph node class "+a+" has onPropertyChange method, it must be called onPropertyChanged with d at the end");if(b.supported_extensions)for(e in b.supported_extensions)this.node_types_by_file_extension[b.supported_extensions[e].toLowerCase()]=b},wrapFunctionAsNode:function(a,b,f,c){for(var e=Array(b.length),
|
||||
l="",n=k.getParameterNames(b),g=0;g<n.length;++g)l+="this.addInput('"+n[g]+"',"+(f&&f[g]?"'"+f[g]+"'":"0")+");\n";f=Function(l+("this.addOutput('out',"+(c?"'"+c+"'":0)+");\n"));f.title=a.split("/").pop();f.desc="Generated from "+b.name;f.prototype.onExecute=function(){for(var a=0;a<e.length;++a)e[a]=this.getInputData(a);a=b.apply(this,e);this.setOutputData(0,a)};this.registerNodeType(a,f)},addNodeMethod:function(a,b){d.prototype[a]=b;for(var f in this.registered_node_types){var c=this.registered_node_types[f];
|
||||
@@ -126,71 +126,71 @@ this.graph._version,5,39),a.fillText("FPS:"+this.fps.toFixed(2),5,52)):a.fillTex
|
||||
this._graph_stack[this._graph_stack.length-1].bgcolor,b.lineWidth=10,b.strokeRect(1,1,a.width-2,a.height-2),b.lineWidth=1);var c=!1;this.onRenderBackground&&(c=this.onRenderBackground(a,b));b.restore();b.setTransform(1,0,0,1,0,0);if(this.graph){b.save();b.scale(this.scale,this.scale);b.translate(this.offset[0],this.offset[1]);if(this.background_image&&0.5<this.scale&&!c){b.globalAlpha=this.zoom_modify_alpha?(1-0.5/this.scale)*this.editor_alpha:this.editor_alpha;b.imageSmoothingEnabled=b.mozImageSmoothingEnabled=
|
||||
b.imageSmoothingEnabled=!1;if(!this._bg_img||this._bg_img.name!=this.background_image){this._bg_img=new Image;this._bg_img.name=this.background_image;this._bg_img.src=this.background_image;var g=this;this._bg_img.onload=function(){g.draw(!0,!0)}}c=null;null==this._pattern&&0<this._bg_img.width?(c=b.createPattern(this._bg_img,"repeat"),this._pattern_img=this._bg_img,this._pattern=c):c=this._pattern;c&&(b.fillStyle=c,b.fillRect(this.visible_area[0],this.visible_area[1],this.visible_area[2],this.visible_area[3]),
|
||||
b.fillStyle="transparent");b.globalAlpha=1;b.imageSmoothingEnabled=b.mozImageSmoothingEnabled=b.imageSmoothingEnabled=!0}this.graph._groups.length&&!this.live_mode&&this.drawGroups(a,b);if(this.onBackgroundRender)this.onBackgroundRender(a,b);this.render_canvas_border&&(b.strokeStyle="#235",b.strokeRect(0,0,a.width,a.height));this.render_connections_shadows?(b.shadowColor="#000",b.shadowOffsetX=0,b.shadowOffsetY=0,b.shadowBlur=6):b.shadowColor="rgba(0,0,0,0)";this.live_mode||this.drawConnections(b);
|
||||
b.shadowColor="rgba(0,0,0,0)";b.restore()}b.finish&&b.finish();this.dirty_bgcanvas=!1;this.dirty_canvas=!0};var c=new Float32Array(2);g.prototype.drawNode=function(a,b){this.current_node=a;var f=a.color||a.constructor.color||k.NODE_DEFAULT_COLOR,g=a.bgcolor||a.constructor.bgcolor||k.NODE_DEFAULT_BGCOLOR;if(this.live_mode){if(!a.flags.collapsed&&(b.shadowColor="transparent",a.onDrawForeground))a.onDrawForeground(b,this)}else if(!a.flags.collapsed||!a.onDrawCollaped||!0!=a.onDrawCollapsed(b,this)){var e=
|
||||
this.editor_alpha;b.globalAlpha=e;this.render_shadows?(b.shadowColor="rgba(0,0,0,0.5)",b.shadowOffsetX=2*this.scale,b.shadowOffsetY=2*this.scale,b.shadowBlur=3*this.scale):b.shadowColor="transparent";var l=a._shape||k.BOX_SHAPE;c.set(a.size);if(a.flags.collapsed){b.font=this.inner_text_font;var n=a.getTitle?a.getTitle():a.title;a._collapsed_width=Math.min(a.size[0],b.measureText(n).width+40);c[0]=a._collapsed_width;c[1]=0}a.flags.clip_area&&(b.save(),b.beginPath(),l==k.BOX_SHAPE?b.rect(0,0,c[0],c[1]):
|
||||
l==k.ROUND_SHAPE?b.roundRect(0,0,c[0],c[1],10):l==k.CIRCLE_SHAPE&&b.arc(0.5*c[0],0.5*c[1],0.5*c[0],0,2*Math.PI),b.clip());this.drawNodeShape(a,b,c,f,g,a.selected,a.mouseOver);b.shadowColor="transparent";b.textAlign=a.flags.horizontal?"center":"left";b.font=this.inner_text_font;f=0.6<this.scale;g=this.connecting_output;b.lineWidth=1;l=0;if(a.flags.collapsed){if(a.inputs)for(n=0;n<a.inputs.length;n++)if(m=a.inputs[n],null!=m.link){b.fillStyle=m.color_on||this.default_connection_color.input_on;b.beginPath();
|
||||
m.type===k.EVENT||m.shape===k.BOX_SHAPE?b.rect(0.5,4-k.NODE_TITLE_HEIGHT+0.5,14,k.NODE_TITLE_HEIGHT-8):m.shape===k.ARROW_SHAPE?(b.moveTo(8,-0.5*k.NODE_TITLE_HEIGHT),b.lineTo(-4,-0.8*k.NODE_TITLE_HEIGHT),b.lineTo(-4,-0.2*k.NODE_TITLE_HEIGHT),b.closePath()):b.arc(0,-0.5*k.NODE_TITLE_HEIGHT,4,0,2*Math.PI);b.fill();break}if(a.outputs)for(n=0;n<a.outputs.length;n++)m=a.outputs[n],m.links&&m.links.length&&(b.fillStyle=m.color_on||this.default_connection_color.output_on,b.strokeStyle="black",b.beginPath(),
|
||||
m.type===k.EVENT||m.shape===k.BOX_SHAPE?b.rect(a._collapsed_width-4+0.5,4-k.NODE_TITLE_HEIGHT+0.5,14,k.NODE_TITLE_HEIGHT-8):m.shape===k.ARROW_SHAPE?(b.moveTo(a._collapsed_width+6,-0.5*k.NODE_TITLE_HEIGHT),b.lineTo(a._collapsed_width-6,-0.8*k.NODE_TITLE_HEIGHT),b.lineTo(a._collapsed_width-6,-0.2*k.NODE_TITLE_HEIGHT),b.closePath()):b.arc(a._collapsed_width,-0.5*k.NODE_TITLE_HEIGHT,4,0,2*Math.PI),b.fill(),b.stroke())}else{if(a.inputs)for(n=0;n<a.inputs.length;n++){var m=a.inputs[n];b.globalAlpha=e;this.connecting_node&&
|
||||
k.isValidConnection(m.type&&g.type)&&(b.globalAlpha=0.4*e);b.fillStyle=null!=m.link?m.color_on||this.default_connection_color.input_on:m.color_off||this.default_connection_color.input_off;var d=a.getConnectionPos(!0,n);d[0]-=a.pos[0];d[1]-=a.pos[1];l<d[1]+0.5*k.NODE_SLOT_HEIGHT&&(l=d[1]+0.5*k.NODE_SLOT_HEIGHT);b.beginPath();m.type===k.EVENT||m.shape===k.BOX_SHAPE?b.rect(d[0]-6+0.5,d[1]-5+0.5,14,10):m.shape===k.ARROW_SHAPE?(b.moveTo(d[0]+8,d[1]+0.5),b.lineTo(d[0]-4,d[1]+6+0.5),b.lineTo(d[0]-4,d[1]-
|
||||
6+0.5),b.closePath()):b.arc(d[0],d[1],4,0,2*Math.PI);b.fill();if(f){var h=null!=m.label?m.label:m.name;h&&(b.fillStyle=k.NODE_TEXT_COLOR,a.flags.horizontal||m.dir==k.UP?b.fillText(h,d[0],d[1]-10):b.fillText(h,d[0]+10,d[1]+5))}}this.connecting_node&&(b.globalAlpha=0.4*e);b.textAlign=a.flags.horizontal?"center":"right";b.strokeStyle="black";if(a.outputs)for(n=0;n<a.outputs.length;n++)if(m=a.outputs[n],d=a.getConnectionPos(!1,n),d[0]-=a.pos[0],d[1]-=a.pos[1],l<d[1]+0.5*k.NODE_SLOT_HEIGHT&&(l=d[1]+0.5*
|
||||
k.NODE_SLOT_HEIGHT),b.fillStyle=m.links&&m.links.length?m.color_on||this.default_connection_color.output_on:m.color_off||this.default_connection_color.output_off,b.beginPath(),m.type===k.EVENT||m.shape===k.BOX_SHAPE?b.rect(d[0]-6+0.5,d[1]-5+0.5,14,10):m.shape===k.ARROW_SHAPE?(b.moveTo(d[0]+8,d[1]+0.5),b.lineTo(d[0]-4,d[1]+6+0.5),b.lineTo(d[0]-4,d[1]-6+0.5),b.closePath()):b.arc(d[0],d[1],4,0,2*Math.PI),b.fill(),b.stroke(),f&&(h=null!=m.label?m.label:m.name))b.fillStyle=k.NODE_TEXT_COLOR,a.flags.horizontal||
|
||||
m.dir==k.DOWN?b.fillText(h,d[0],d[1]-8):b.fillText(h,d[0]-10,d[1]+5);b.textAlign="left";b.globalAlpha=1;if(a.widgets){if(a.flags.horizontal||a.flags.widgets_up)l=2;this.drawNodeWidgets(a,l,b,this.node_widget&&this.node_widget[0]==a?this.node_widget[1]:null)}a.onDrawForeground&&(a.gui_rects&&(a.gui_rects.length=0),a.onDrawForeground(b,this))}a.flags.clip_area&&b.restore();b.globalAlpha=1}};g.prototype.drawNodeShape=function(a,b,c,m,e,l,n){b.strokeStyle=m;b.fillStyle=e;e=k.NODE_TITLE_HEIGHT;var d=a._shape||
|
||||
a.constructor.shape||k.BOX_SHAPE,h=a.constructor.title_mode,x=!0;h==k.TRANSPARENT_TITLE?x=!1:h==k.AUTOHIDE_TITLE&&n&&(x=!0);n=x?-e:0;var q=c[0]+1,p=x?c[1]+e:c[1];a.flags.collapsed||(d==k.BOX_SHAPE||0.5>this.scale?(b.beginPath(),b.rect(0,n,q,p),b.fill()):d==k.ROUND_SHAPE||d==k.CARD_SHAPE?(b.beginPath(),b.roundRect(0,n,q,p,this.round_radius,d==k.CARD_SHAPE?0:this.round_radius),b.fill()):d==k.CIRCLE_SHAPE&&(b.beginPath(),b.arc(0.5*c[0],0.5*c[1],0.5*c[0],0,2*Math.PI),b.fill()));b.shadowColor="transparent";
|
||||
a.bgImage&&a.bgImage.width&&b.drawImage(a.bgImage,0.5*(c[0]-a.bgImage.width),0.5*(c[1]-a.bgImage.height));a.bgImageUrl&&!a.bgImage&&(a.bgImage=a.loadImage(a.bgImageUrl));a.onDrawBackground&&(a.gui_rects&&(a.gui_rects.length=0),a.onDrawBackground(b,this));if(x||h==k.TRANSPARENT_TITLE){if(h!=k.TRANSPARENT_TITLE){if(this.use_gradients){var r=g.gradients[m];r||(r=g.gradients[m]=b.createLinearGradient(0,0,400,0),r.addColorStop(0,m),r.addColorStop(1,"#000"));b.fillStyle=r}else b.fillStyle=m;r=b.globalAlpha;
|
||||
b.beginPath();if(d==k.BOX_SHAPE||0.5>this.scale)b.rect(0,-e,c[0]+1,e),b.fill();else if(d==k.ROUND_SHAPE||d==k.CARD_SHAPE)b.roundRect(0,-e,c[0]+1,e,this.round_radius,a.flags.collapsed?this.round_radius:0),b.fill()}d==k.ROUND_SHAPE||d==k.CIRCLE_SHAPE||d==k.CARD_SHAPE?(0.5<this.scale&&(b.fillStyle="black",b.beginPath(),b.arc(0.5*e,-0.5*e,0.5*(e-8),0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||k.NODE_DEFAULT_BOXCOLOR,b.beginPath(),b.arc(0.5*e,-0.5*e,0.4*(e-8),0,2*Math.PI),b.fill()):(0.5<this.scale&&
|
||||
(b.fillStyle="black",b.fillRect(4,-e+4,e-8,e-8)),b.fillStyle=a.boxcolor||k.NODE_DEFAULT_BOXCOLOR,b.fillRect(5,-e+5,e-10,e-10));b.globalAlpha=r;0.5<this.scale&&(b.font=this.title_text_font,r=a.getTitle())&&(b.fillStyle=l?"white":a.constructor.title_text_color||this.node_title_color,a.flags.collapsed?(b.textAlign="center",x=b.measureText(r),b.fillText(r,e+0.5*x.width,0.2*-e),b.textAlign="left"):(b.textAlign="left",b.fillText(r,e,0.2*-e)))}l&&(h==k.TRANSPARENT_TITLE&&(n-=e,p+=e),b.lineWidth=1,b.globalAlpha=
|
||||
0.8,b.beginPath(),d==k.BOX_SHAPE?b.rect(-6,-6+n,12+q,12+p):d==k.ROUND_SHAPE||d==k.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6,-6+n,12+q,12+p,2*this.round_radius):d==k.CARD_SHAPE?b.roundRect(-6,-6+n,12+q,12+p,2*this.round_radius,2):d==k.CIRCLE_SHAPE&&b.arc(0.5*c[0],0.5*c[1],0.5*c[0]+6,0,2*Math.PI),b.strokeStyle="#FFF",b.stroke(),b.strokeStyle=m,b.globalAlpha=1)};g.prototype.drawConnections=function(a){var b=k.getTime();a.lineWidth=this.connections_width;a.fillStyle="#AAA";a.strokeStyle="#AAA";a.globalAlpha=
|
||||
this.editor_alpha;for(var c=0,g=this.graph._nodes.length;c<g;++c){var e=this.graph._nodes[c];if(e.inputs&&e.inputs.length)for(var l=0;l<e.inputs.length;++l){var n=e.inputs[l];if(n&&null!=n.link&&(n=this.graph.links[n.link])){var d=this.graph.getNodeById(n.origin_id);if(null!=d){var m=n.origin_slot,h=null,h=-1==m?[d.pos[0]+10,d.pos[1]+10]:d.getConnectionPos(!1,m),q=e.getConnectionPos(!0,l),d=d.outputs[m].dir||(d.flags.horizontal?k.DOWN:k.RIGHT),m=e.inputs[l].dir||(e.flags.horizontal?k.UP:k.LEFT);this.renderLink(a,
|
||||
h,q,n,!1,0,null,d,m);if(n&&n._last_time&&1E3>b-n._last_time){var p=2-0.002*(b-n._last_time),r="rgba(255,255,255, "+p.toFixed(2)+")";this.renderLink(a,h,q,n,!0,p,r,d,m)}}}}}a.globalAlpha=1};g.prototype.renderLink=function(a,b,c,d,e,l,n,m,h){if(this.highquality_render){m=m||k.RIGHT;h=h||k.LEFT;var x=r(b,c);this.render_connections_border&&0.6<this.scale&&(a.lineWidth=this.connections_width+4);!n&&d&&(n=g.link_type_colors[d.type]);n||(n=this.default_link_color);null!=d&&this.highlighted_links[d.id]&&
|
||||
(n="#FFF");a.beginPath();if(this.render_curved_connections){a.moveTo(b[0],b[1]);var q=d=0,p=0,s=0;switch(m){case k.LEFT:d=-0.25*x;break;case k.RIGHT:d=0.25*x;break;case k.UP:q=-0.25*x;break;case k.DOWN:q=0.25*x}switch(h){case k.LEFT:p=-0.25*x;break;case k.RIGHT:p=0.25*x;break;case k.UP:s=-0.25*x;break;case k.DOWN:s=0.25*x}a.bezierCurveTo(b[0]+d,b[1]+q,c[0]+p,c[1]+s,c[0],c[1])}else a.moveTo(b[0]+10,b[1]),a.lineTo(0.5*(b[0]+10+(c[0]-10)),b[1]),a.lineTo(0.5*(b[0]+10+(c[0]-10)),c[1]),a.lineTo(c[0]-10,
|
||||
c[1]);this.render_connections_border&&0.6<this.scale&&!e&&(a.strokeStyle="rgba(0,0,0,0.5)",a.stroke());a.lineWidth=this.connections_width;a.fillStyle=a.strokeStyle=n;a.stroke();this.render_connection_arrows&&0.6<=this.scale&&this.render_connection_arrows&&0.6<this.scale&&(e=this.computeConnectionPoint(b,c,0.5,m,h),n=this.computeConnectionPoint(b,c,0.51,m,h),x=0,x=this.render_curved_connections?-Math.atan2(n[0]-e[0],n[1]-e[1]):c[1]>b[1]?0:Math.PI,a.save(),a.translate(e[0],e[1]),a.rotate(x),a.beginPath(),
|
||||
a.moveTo(-5,-5),a.lineTo(0,5),a.lineTo(5,-5),a.fill(),a.restore());if(l)for(l=0;5>l;++l)e=(0.001*k.getTime()+0.2*l)%1,e=this.computeConnectionPoint(b,c,e,m,h),a.beginPath(),a.arc(e[0],e[1],5,0,2*Math.PI),a.fill()}else a.beginPath(),a.moveTo(b[0],b[1]),a.lineTo(c[0],c[1]),a.stroke()};g.prototype.computeConnectionPoint=function(a,b,c,g,e){g=g||k.RIGHT;e=e||k.LEFT;var l=r(a,b),n=[a[0],a[1]],d=[b[0],b[1]];switch(g){case k.LEFT:n[0]+=-0.25*l;break;case k.RIGHT:n[0]+=0.25*l;break;case k.UP:n[1]+=-0.25*
|
||||
l;break;case k.DOWN:n[1]+=0.25*l}switch(e){case k.LEFT:d[0]+=-0.25*l;break;case k.RIGHT:d[0]+=0.25*l;break;case k.UP:d[1]+=-0.25*l;break;case k.DOWN:d[1]+=0.25*l}g=(1-c)*(1-c)*(1-c);e=3*(1-c)*(1-c)*c;l=3*(1-c)*c*c;c*=c*c;return[g*a[0]+e*n[0]+l*d[0]+c*b[0],g*a[1]+e*n[1]+l*d[1]+c*b[1]]};g.prototype.drawExecutionOrder=function(a){a.shadowColor="transparent";a.globalAlpha=0.25;a.textAlign="center";a.strokeStyle="white";a.globalAlpha=0.75;for(var b=this.visible_nodes,c=0;c<b.length;++c){var g=b[c];a.fillStyle=
|
||||
"black";a.fillRect(g.pos[0]-k.NODE_TITLE_HEIGHT,g.pos[1]-k.NODE_TITLE_HEIGHT,k.NODE_TITLE_HEIGHT,k.NODE_TITLE_HEIGHT);0==g.order&&a.strokeRect(g.pos[0]-k.NODE_TITLE_HEIGHT+0.5,g.pos[1]-k.NODE_TITLE_HEIGHT+0.5,k.NODE_TITLE_HEIGHT,k.NODE_TITLE_HEIGHT);a.fillStyle="#FFF";a.fillText(g.order,g.pos[0]+-0.5*k.NODE_TITLE_HEIGHT,g.pos[1]-6)}a.globalAlpha=1};g.prototype.drawNodeWidgets=function(a,b,c,g){if(!a.widgets||!a.widgets.length)return 0;var e=a.size[0];a=a.widgets;b+=2;for(var l=k.NODE_WIDGET_HEIGHT,
|
||||
n=0.5<this.scale,d=0;d<a.length;++d){var m=a[d],h=b;m.y&&(h=m.y);m.last_y=h;c.strokeStyle="#AAA";c.fillStyle="#222";c.textAlign="left";switch(m.type){case "button":m.clicked&&(c.fillStyle="#AAA",m.clicked=!1,this.dirty_canvas=!0);c.fillRect(10,h,e-20,l);c.strokeRect(10,h,e-20,l);n&&(c.textAlign="center",c.fillStyle="#AAA",c.fillText(m.name,0.5*e,h+0.7*l));break;case "slider":c.fillStyle="#111";c.fillRect(10,h,e-20,l);var q=(m.value-m.options.min)/(m.options.max-m.options.min);c.fillStyle=g==m?"#89A":
|
||||
"#678";c.fillRect(10,h,q*(e-20),l);c.strokeRect(10,h,e-20,l);n&&(c.textAlign="center",c.fillStyle="#DDD",c.fillText(m.name+" "+Number(m.value).toFixed(3),0.5*e,h+0.7*l));break;case "number":case "combo":c.textAlign="left";c.strokeStyle="#AAA";c.fillStyle="#111";c.beginPath();c.roundRect(10,b,e-20,l,0.5*l);c.fill();c.stroke();c.fillStyle="#AAA";c.beginPath();c.moveTo(26,b+5);c.lineTo(16,b+0.5*l);c.lineTo(26,b+l-5);c.moveTo(e-26,b+5);c.lineTo(e-16,b+0.5*l);c.lineTo(e-26,b+l-5);c.fill();n&&(c.fillStyle=
|
||||
"#999",c.fillText(m.name,30,h+0.7*l),c.fillStyle="#DDD",c.textAlign="right","number"==m.type?c.fillText(Number(m.value).toFixed(void 0!==m.options.precision?m.options.precision:3),e-40,h+0.7*l):c.fillText(m.value,e-40,h+0.7*l));break;case "text":c.textAlign="left",c.strokeStyle="#AAA",c.fillStyle="#111",c.beginPath(),c.roundRect(10,b,e-20,l,0.5*l),c.fill(),c.stroke(),c.fillStyle="#999",c.fillText(m.title||"Value",20,h+0.7*l),c.fillStyle="#DDD",c.textAlign="right",c.fillText(m.value,e-20,h+0.7*l)}b+=
|
||||
l+4}c.textAlign="left"};g.prototype.processNodeWidgets=function(a,b,c,g){if(!a.widgets||!a.widgets.length)return null;for(var e=b[0]-a.pos[0],l=b[1]-a.pos[1],n=a.size[0],d=this,m=0;m<a.widgets.length;++m){var h=a.widgets[m];if(h==g||6<e&&e<n-12&&l>h.last_y&&l<h.last_y+k.NODE_WIDGET_HEIGHT){switch(h.type){case "button":h.callback&&setTimeout(function(){h.callback(h,d,a,b)},20);this.dirty_canvas=h.clicked=!0;break;case "slider":c=Math.clamp((e-10)/(n-20),0,1);h.value=h.options.min+(h.options.max-h.options.min)*
|
||||
c;h.callback&&setTimeout(function(){h.callback(h.value,d,a,b)},20);this.dirty_canvas=!0;break;case "number":case "combo":"mousemove"==c.type&&"number"==h.type?(h.value+=0.1*c.deltaX*(h.options.step||1),null!=h.options.min&&h.value<h.options.min&&(h.value=h.options.min),null!=h.options.max&&h.value>h.options.max&&(h.value=h.options.max)):"mousedown"==c.type&&(c=40>e?-1:e>n-40?1:0,"number"==h.type?(h.value+=0.1*c*(h.options.step||1),null!=h.options.min&&h.value<h.options.min&&(h.value=h.options.min),
|
||||
null!=h.options.max&&h.value>h.options.max&&(h.value=h.options.max)):c&&(c=h.options.values.indexOf(h.value)+c,c>=h.options.values.length&&(c=0),0>c&&(c=h.options.values.length-1),h.value=h.options.values[c]));h.callback&&setTimeout(function(){this.callback(this.value,d,a,b)}.bind(h),20);this.dirty_canvas=!0;break;case "text":"mousedown"==c.type&&this.prompt("Value",h.value,function(a){this.value=a}.bind(h),c)}return h}}return null};g.prototype.drawGroups=function(a,b){if(this.graph){var c=this.graph._groups;
|
||||
b.save();b.globalAlpha=0.5;b.font="24px Arial";for(var g=0;g<c.length;++g){var e=c[g];if(s(this.visible_area,e._bounding)){b.fillStyle=e.color||"#335";b.strokeStyle=e.color||"#335";var l=e._pos,n=e._size;b.globalAlpha=0.25;b.beginPath();b.rect(l[0]+0.5,l[1]+0.5,n[0],n[1]);b.fill();b.globalAlpha=1;b.stroke();b.beginPath();b.moveTo(l[0]+n[0],l[1]+n[1]);b.lineTo(l[0]+n[0]-10,l[1]+n[1]);b.lineTo(l[0]+n[0],l[1]+n[1]-10);b.fill();b.fillText(e.title,l[0]+4,l[1]+24)}}b.restore()}};g.prototype.resize=function(a,
|
||||
b){if(!a&&!b){var c=this.canvas.parentNode;a=c.offsetWidth;b=c.offsetHeight}if(this.canvas.width!=a||this.canvas.height!=b)this.canvas.width=a,this.canvas.height=b,this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height,this.setDirty(!0,!0)};g.prototype.switchLiveMode=function(a){if(a){var b=this,c=this.live_mode?1.1:0.9;this.live_mode&&(this.live_mode=!1,this.editor_alpha=0.1);var g=setInterval(function(){b.editor_alpha*=c;b.dirty_canvas=!0;b.dirty_bgcanvas=!0;1>c&&0.01>b.editor_alpha&&
|
||||
(clearInterval(g),1>c&&(b.live_mode=!0));1<c&&0.99<b.editor_alpha&&(clearInterval(g),b.editor_alpha=1)},1)}else this.live_mode=!this.live_mode,this.dirty_bgcanvas=this.dirty_canvas=!0};g.prototype.onNodeSelectionChange=function(a){};g.prototype.touchHandler=function(a){var b=a.changedTouches[0],c="";switch(a.type){case "touchstart":c="mousedown";break;case "touchmove":c="mousemove";break;case "touchend":c="mouseup";break;default:return}var g=this.getCanvasWindow(),e=g.document.createEvent("MouseEvent");
|
||||
e.initMouseEvent(c,!0,!0,g,1,b.screenX,b.screenY,b.clientX,b.clientY,!1,!1,!1,!1,0,null);b.target.dispatchEvent(e);a.preventDefault()};g.onGroupAdd=function(a,b,c){a=g.active_canvas;a.getCanvasWindow();b=new k.LGraphGroup;b.pos=a.convertEventToCanvas(c);a.graph.add(b)};g.onMenuAdd=function(a,b,c,d){function e(a,b){var c=d.getFirstEvent(),f=k.createNode(a.value);f&&(f.pos=l.convertEventToCanvas(c),l.graph.add(f))}var l=g.active_canvas,n=l.getCanvasWindow();a=k.getNodeTypesCategories();b=[];for(var m in a)a[m]&&
|
||||
b.push({value:a[m],content:a[m],has_submenu:!0});var h=new k.ContextMenu(b,{event:c,callback:function(a,b,c){a=k.getNodeTypesInCategory(a.value,l.filter);b=[];for(var f in a)b.push({content:a[f].title,value:a[f].type});new k.ContextMenu(b,{event:c,callback:e,parentMenu:h},n);return!1},parentMenu:d},n);return!1};g.onMenuCollapseAll=function(){};g.onMenuNodeEdit=function(){};g.showMenuNodeOptionalInputs=function(a,b,c,m,e){function l(a,b,c){e&&(a.callback&&a.callback.call(n,e,a,b,c),a.value&&(e.addInput(a.value[0],
|
||||
a.value[1],a.value[2]),e.setDirtyCanvas(!0,!0)))}if(e){var n=this;a=g.active_canvas.getCanvasWindow();b=e.optional_inputs;e.onGetInputs&&(b=e.onGetInputs());var d=[];if(b)for(var h in b){var q=b[h];if(q){var p=q[0];q[2]&&q[2].label&&(p=q[2].label);p={content:p,value:q};q[1]==k.ACTION&&(p.className="event");d.push(p)}else d.push(null)}this.onMenuNodeInputs&&(d=this.onMenuNodeInputs(d));if(d.length)return new k.ContextMenu(d,{event:c,callback:l,parentMenu:m,node:e},a),!1}};g.showMenuNodeOptionalOutputs=
|
||||
function(a,b,c,d,e){function l(a,b,c){if(e&&(a.callback&&a.callback.call(m,e,a,b,c),a.value))if(c=a.value[1],!c||c.constructor!==Object&&c.constructor!==Array)e.addOutput(a.value[0],a.value[1],a.value[2]),e.setDirtyCanvas(!0,!0);else{a=[];for(var f in c)a.push({content:f,value:c[f]});new k.ContextMenu(a,{event:b,callback:l,parentMenu:d,node:e});return!1}}if(e){var m=this;a=g.active_canvas.getCanvasWindow();b=e.optional_outputs;e.onGetOutputs&&(b=e.onGetOutputs());var h=[];if(b)for(var q in b){var p=
|
||||
b[q];if(!p)h.push(null);else if(!e.flags||!e.flags.skip_repeated_outputs||-1==e.findOutputSlot(p[0])){var r=p[0];p[2]&&p[2].label&&(r=p[2].label);r={content:r,value:p};p[1]==k.EVENT&&(r.className="event");h.push(r)}}this.onMenuNodeOutputs&&(h=this.onMenuNodeOutputs(h));if(h.length)return new k.ContextMenu(h,{event:c,callback:l,parentMenu:d,node:e},a),!1}};g.onShowMenuNodeProperties=function(a,b,c,d,e){function l(a,b,c,f){e&&(b=this.getBoundingClientRect(),m.showEditPropertyValue(e,a.value,{position:[b.left,
|
||||
b.top]}))}if(e&&e.properties){var m=g.active_canvas;b=m.getCanvasWindow();var h=[],q;for(q in e.properties)a=void 0!==e.properties[q]?e.properties[q]:" ",a=g.decodeHTML(a),h.push({content:"<span class='property_name'>"+q+"</span><span class='property_value'>"+a+"</span>",value:q});if(h.length)return new k.ContextMenu(h,{event:c,callback:l,parentMenu:d,allow_html:!0,node:e},b),!1}};g.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};g.onResizeNode=function(a,
|
||||
b,c,g,e){e&&(e.size=e.computeSize(),e.setDirtyCanvas(!0,!0))};g.onShowTitleEditor=function(a,b,c,d,e){function l(){e.title=h.value;m.parentNode.removeChild(m);e.setDirtyCanvas(!0,!0)}var m=document.createElement("div");m.className="graphdialog";m.innerHTML="<span class='name'>Title</span><input autofocus type='text' class='value'/><button>OK</button>";var h=m.querySelector("input");h&&(h.value=e.title,h.addEventListener("keydown",function(a){13==a.keyCode&&(l(),a.preventDefault(),a.stopPropagation())}));
|
||||
a=g.active_canvas.canvas;b=a.getBoundingClientRect();d=c=-20;b&&(c-=b.left,d-=b.top);event?(m.style.left=event.pageX+c+"px",m.style.top=event.pageY+d+"px"):(m.style.left=0.5*a.width+c+"px",m.style.top=0.5*a.height+d+"px");m.querySelector("button").addEventListener("click",l);a.parentNode.appendChild(m)};g.prototype.prompt=function(a,b,c,m){var e=this;a=a||"";var l=document.createElement("div");l.className="graphdialog rounded";l.innerHTML="<span class='name'></span> <input autofocus type='text' class='value'/><button class='rounded'>OK</button>";
|
||||
l.close=function(){e.prompt_box=null;l.parentNode.removeChild(l)};l.addEventListener("mouseleave",function(a){l.close()});e.prompt_box&&e.prompt_box.close();e.prompt_box=l;l.querySelector(".name").innerText=a;l.querySelector(".value").value=b;var d=l.querySelector("input");d.addEventListener("keydown",function(a){if(27==a.keyCode)l.close();else if(13==a.keyCode)c&&c(this.value),l.close();else return;a.preventDefault();a.stopPropagation()});l.querySelector("button").addEventListener("click",function(a){c&&
|
||||
c(d.value);e.setDirty(!0);l.close()});a=g.active_canvas.canvas;b=a.getBoundingClientRect();var h=-20,k=-20;b&&(h-=b.left,k-=b.top);m?(l.style.left=m.pageX+h+"px",l.style.top=m.pageY+k+"px"):(l.style.left=0.5*a.width+h+"px",l.style.top=0.5*a.height+k+"px");a.parentNode.appendChild(l);setTimeout(function(){d.focus()},10);return l};g.prototype.showSearchBox=function(a){function b(b){if(b)if(e.onSearchBoxSelection)e.onSearchBoxSelection(b,a,s);else if(b=k.createNode(b))b.pos=s.convertEventToCanvas(a),
|
||||
s.graph.add(b);l.close()}function c(a){var b=p;p&&p.classList.remove("selected");p?(p=a?p.nextSibling:p.previousSibling)||(p=b):p=a?d.childNodes[0]:d.childNodes[d.childNodes.length];p&&(p.classList.add("selected"),p.scrollIntoView())}function m(){q=null;var a=r.value;h=null;d.innerHTML="";if(a)if(e.onSearchBox)e.onSearchBox(f,a,s);else for(var c in k.registered_node_types)if(-1!=c.indexOf(a)){var f=document.createElement("div");h||(h=c);f.innerText=c;f.className="help-item";f.addEventListener("click",
|
||||
function(a){b(this.innerText)});d.appendChild(f)}}var e=this,l=document.createElement("div");l.className="graphdialog rounded";l.innerHTML="<span class='name'>Search</span> <input autofocus type='text' class='value rounded'/><div class='helper'></div>";l.close=function(){e.search_box=null;l.parentNode.removeChild(l)};l.addEventListener("mouseleave",function(a){l.close()});e.search_box&&e.search_box.close();e.search_box=l;var d=l.querySelector(".helper"),h=null,q=null,p=null,r=l.querySelector("input");
|
||||
r&&r.addEventListener("keydown",function(a){if(38==a.keyCode)c(!1);else if(40==a.keyCode)c(!0);else if(27==a.keyCode)l.close();else if(13==a.keyCode)p?b(p.innerHTML):h?b(h):l.close();else{q&&clearInterval(q);q=setTimeout(m,10);return}a.preventDefault();a.stopPropagation()});var s=g.active_canvas,u=s.canvas,t=u.getBoundingClientRect(),z=-20,E=-20;t&&(z-=t.left,E-=t.top);a?(l.style.left=a.pageX+z+"px",l.style.top=a.pageY+E+"px"):(l.style.left=0.5*u.width+z+"px",l.style.top=0.5*u.height+E+"px");u.parentNode.appendChild(l);
|
||||
setTimeout(function(){r.focus()},10);return l};g.prototype.showEditPropertyValue=function(a,b,c){function g(){e(p.value)}function e(c){"number"==typeof a.properties[b]&&(c=Number(c));"array"==l&&(c=c.split(",").map(Number));a.properties[b]=c;a._graph&&a._graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,c);q.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){c=c||{};var l="string";null!==a.properties[b]&&(l=typeof a.properties[b]);"object"==l&&a.properties[b].length&&(l="array");
|
||||
var d=null;a.getPropertyInfo&&(d=a.getPropertyInfo(b));if(a.properties_info)for(var m=0;m<a.properties_info.length;++m)if(a.properties_info[m].name==b){d=a.properties_info[m];break}void 0!==d&&null!==d&&d.type&&(l=d.type);var h="";if("string"==l||"number"==l||"array"==l)h="<input autofocus type='text' class='value'/>";else if("enum"==l&&d.values){h="<select autofocus type='text' class='value'>";for(m in d.values)var k=d.values.constructor===Array?d.values[m]:m,h=h+("<option value='"+k+"' "+(k==a.properties[b]?
|
||||
"selected":"")+">"+d.values[m]+"</option>");h+="</select>"}else if("boolean"==l)h="<input autofocus type='checkbox' class='value' "+(a.properties[b]?"checked":"")+"/>";else{console.warn("unknown type: "+l);return}var q=this.createDialog("<span class='name'>"+b+"</span>"+h+"<button>OK</button>",c);if("enum"==l&&d.values){var p=q.querySelector("select");p.addEventListener("change",function(a){e(a.target.value)})}else if("boolean"==l)(p=q.querySelector("input"))&&p.addEventListener("click",function(a){e(!!p.checked)});
|
||||
else if(p=q.querySelector("input"))p.value=void 0!==a.properties[b]?a.properties[b]:"",p.addEventListener("keydown",function(a){13==a.keyCode&&(g(),a.preventDefault(),a.stopPropagation())});q.querySelector("button").addEventListener("click",g)}};g.prototype.createDialog=function(a,b){b=b||{};var c=document.createElement("div");c.className="graphdialog";c.innerHTML=a;var g=this.canvas.getBoundingClientRect(),e=-20,l=-20;g&&(e-=g.left,l-=g.top);b.position?(e+=b.position[0],l+=b.position[1]):b.event?
|
||||
(e+=b.event.pageX,l+=b.event.pageY):(e+=0.5*this.canvas.width,l+=0.5*this.canvas.height);c.style.left=e+"px";c.style.top=l+"px";this.canvas.parentNode.appendChild(c);c.close=function(){this.parentNode&&this.parentNode.removeChild(this)};return c};g.onMenuNodeCollapse=function(a,b,c,g,e){e.collapse()};g.onMenuNodePin=function(a,b,c,g,e){e.pin()};g.onMenuNodeMode=function(a,b,c,g,e){new k.ContextMenu(["Always","On Event","On Trigger","Never"],{event:c,callback:function(a){if(e)switch(a){case "On Event":e.mode=
|
||||
k.ON_EVENT;break;case "On Trigger":e.mode=k.ON_TRIGGER;break;case "Never":e.mode=k.NEVER;break;default:e.mode=k.ALWAYS}},parentMenu:g,node:e});return!1};g.onMenuNodeColors=function(a,b,c,d,e){if(!e)throw"no node for color";b=[];b.push({value:null,content:"<span style='display: block; padding-left: 4px;'>No color</span>"});for(var l in g.node_colors)a=g.node_colors[l],a={value:l,content:"<span style='display: block; color: #999; padding-left: 4px; border-left: 8px solid "+a.color+"; background-color:"+
|
||||
a.bgcolor+"'>"+l+"</span>"},b.push(a);new k.ContextMenu(b,{event:c,callback:function(a){e&&((a=a.value?g.node_colors[a.value]:null)?e.constructor===k.LGraphGroup?e.color=a.groupcolor:(e.color=a.color,e.bgcolor=a.bgcolor):(delete e.color,delete e.bgcolor),e.setDirtyCanvas(!0,!0))},parentMenu:d,node:e});return!1};g.onMenuNodeShapes=function(a,b,c,g,e){if(!e)throw"no node passed";new k.ContextMenu(k.VALID_SHAPES,{event:c,callback:function(a){e&&(e.shape=a,e.setDirtyCanvas(!0))},parentMenu:g,node:e});
|
||||
return!1};g.onMenuNodeRemove=function(a,b,c,g,e){if(!e)throw"no node passed";!1!==e.removable&&(e.graph.remove(e),e.setDirtyCanvas(!0,!0))};g.onMenuNodeClone=function(a,b,c,g,e){!1!=e.clonable&&(a=e.clone())&&(a.pos=[e.pos[0]+5,e.pos[1]+5],e.graph.add(a),e.setDirtyCanvas(!0,!0))};g.node_colors={red:{color:"#322",bgcolor:"#533",groupcolor:"#A88"},brown:{color:"#332922",bgcolor:"#593930",groupcolor:"#b06634"},green:{color:"#232",bgcolor:"#353",groupcolor:"#8A8"},blue:{color:"#223",bgcolor:"#335",groupcolor:"#88A"},
|
||||
pale_blue:{color:"#2a363b",bgcolor:"#3f5159",groupcolor:"#3f789e"},cyan:{color:"#233",bgcolor:"#355",groupcolor:"#8AA"},purple:{color:"#323",bgcolor:"#535",groupcolor:"#a1309b"},yellow:{color:"#432",bgcolor:"#653",groupcolor:"#b58b2a"},black:{color:"#222",bgcolor:"#000",groupcolor:"#444"}};g.prototype.getCanvasMenuOptions=function(){var a=null;this.getMenuOptions?a=this.getMenuOptions():(a=[{content:"Add Node",has_submenu:!0,callback:g.onMenuAdd},{content:"Add Group",callback:g.onGroupAdd}],this._graph_stack&&
|
||||
0<this._graph_stack.length&&(a=[{content:"Close subgraph",callback:this.closeSubgraph.bind(this)},null].concat(a)));if(this.getExtraMenuOptions){var b=this.getExtraMenuOptions(this,a);b&&(a=a.concat(b))}return a};g.prototype.getNodeMenuOptions=function(a){var b=null,b=a.getMenuOptions?a.getMenuOptions(this):[{content:"Inputs",has_submenu:!0,disabled:!0,callback:g.showMenuNodeOptionalInputs},{content:"Outputs",has_submenu:!0,disabled:!0,callback:g.showMenuNodeOptionalOutputs},null,{content:"Properties",
|
||||
has_submenu:!0,callback:g.onShowMenuNodeProperties},null,{content:"Title",callback:g.onShowTitleEditor},{content:"Mode",has_submenu:!0,callback:g.onMenuNodeMode},{content:"Resize",callback:g.onResizeNode},{content:"Collapse",callback:g.onMenuNodeCollapse},{content:"Pin",callback:g.onMenuNodePin},{content:"Colors",has_submenu:!0,callback:g.onMenuNodeColors},{content:"Shapes",has_submenu:!0,callback:g.onMenuNodeShapes},null];if(a.getExtraMenuOptions){var c=a.getExtraMenuOptions(this);c&&(c.push(null),
|
||||
b=c.concat(b))}!1!==a.clonable&&b.push({content:"Clone",callback:g.onMenuNodeClone});!1!==a.removable&&b.push(null,{content:"Remove",callback:g.onMenuNodeRemove});a.onGetInputs&&(c=a.onGetInputs())&&c.length&&(b[0].disabled=!1);a.onGetOutputs&&(c=a.onGetOutputs())&&c.length&&(b[1].disabled=!1);if(a.graph&&a.graph.onGetNodeMenuOptions)a.graph.onGetNodeMenuOptions(b,a);return b};g.prototype.getGroupMenuOptions=function(a){return[{content:"Title",callback:g.onShowTitleEditor},{content:"Color",has_submenu:!0,
|
||||
callback:g.onMenuNodeColors},null,{content:"Remove",callback:g.onMenuNodeRemove}]};g.prototype.processContextMenu=function(a,b){var c=this,d=g.active_canvas.getCanvasWindow(),e=null,l={event:b,callback:function(b,e,l){if(b)if("Remove Slot"==b.content){var g=b.slot;g.input?a.removeInput(g.slot):g.output&&a.removeOutput(g.slot)}else if("Rename Slot"==b.content){var g=b.slot,m=c.createDialog("<span class='name'>Name</span><input type='text'/><button>OK</button>",e),d=m.querySelector("input");m.querySelector("button").addEventListener("click",
|
||||
function(b){if(d.value){if(b=g.input?a.getInputInfo(g.slot):a.getOutputInfo(g.slot))b.label=d.value;c.setDirty(!0)}m.close()})}},extra:a},m=null;a&&(m=a.getSlotInPosition(b.canvasX,b.canvasY),g.active_node=a);m?(e=[],e.push(m.locked?"Cannot remove":{content:"Remove Slot",slot:m}),e.push({content:"Rename Slot",slot:m}),l.title=(m.input?m.input.type:m.output.type)||"*",m.input&&m.input.type==k.ACTION&&(l.title="Action"),m.output&&m.output.type==k.EVENT&&(l.title="Event")):a?e=this.getNodeMenuOptions(a):
|
||||
(e=this.getCanvasMenuOptions(),(m=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&e.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:m,options:this.getGroupMenuOptions(m)}}));e&&new k.ContextMenu(e,l,d)};this.CanvasRenderingContext2D&&(CanvasRenderingContext2D.prototype.roundRect=function(a,b,c,g,e,l){void 0===e&&(e=5);void 0===l&&(l=e);this.moveTo(a+e,b);this.lineTo(a+c-e,b);this.quadraticCurveTo(a+c,b,a+c,b+e);this.lineTo(a+c,b+g-l);this.quadraticCurveTo(a+c,b+g,a+c-l,
|
||||
b+g);this.lineTo(a+l,b+g);this.quadraticCurveTo(a,b+g,a,b+g-l);this.lineTo(a,b+e);this.quadraticCurveTo(a,b,a+e,b)});k.compareObjects=function(a,b){for(var c in a)if(a[c]!=b[c])return!1;return!0};k.distance=r;k.colorToString=function(a){return"rgba("+Math.round(255*a[0]).toFixed()+","+Math.round(255*a[1]).toFixed()+","+Math.round(255*a[2]).toFixed()+","+(4==a.length?a[3].toFixed(2):"1.0")+")"};k.isInsideRectangle=p;k.growBounding=function(a,b,c){b<a[0]?a[0]=b:b>a[2]&&(a[2]=b);c<a[1]?a[1]=c:c>a[3]&&
|
||||
(a[3]=c)};k.isInsideBounding=function(a,b){return a[0]<b[0][0]||a[1]<b[0][1]||a[0]>b[1][0]||a[1]>b[1][1]?!1:!0};k.overlapBounding=s;k.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),c=0,g,e,l=0;6>l;l+=2)g="0123456789ABCDEF".indexOf(a.charAt(l)),e="0123456789ABCDEF".indexOf(a.charAt(l+1)),b[c]=16*g+e,c++;return b};k.num2hex=function(a){for(var b="#",c,g,e=0;3>e;e++)c=a[e]/16,g=a[e]%16,b+="0123456789ABCDEF".charAt(c)+"0123456789ABCDEF".charAt(g);return b};u.prototype.addItem=
|
||||
function(a,b,c){function g(a){var b=this.value;b&&b.has_submenu&&e.call(this,a)}function e(a){var b=this.value,e=!0;l.current_submenu&&l.current_submenu.close(a);if(c.callback){var g=c.callback.call(this,b,c,a,l,c.node);!0===g&&(e=!1)}if(b&&(b.callback&&!c.ignore_item_callbacks&&!0!==b.disabled&&(g=b.callback.call(this,b,c,a,l,c.extra),!0===g&&(e=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new l.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,
|
||||
parentMenu:l,ignore_item_callbacks:b.submenu.ignore_item_callbacks,title:b.submenu.title,extra:b.submenu.extra,autoopen:c.autoopen});e=!1}e&&!l.lock&&l.close()}var l=this;c=c||{};var m=document.createElement("div");m.className="litemenu-entry submenu";var d=!1;if(null===b)m.classList.add("separator");else{m.innerHTML=b&&b.title?b.title:a;if(m.value=b)b.disabled&&(d=!0,m.classList.add("disabled")),(b.submenu||b.has_submenu)&&m.classList.add("has_submenu");"function"==typeof b?(m.dataset.value=a,m.onclick_callback=
|
||||
b):m.dataset.value=b;b.className&&(m.className+=" "+b.className)}this.root.appendChild(m);d||m.addEventListener("click",e);c.autoopen&&m.addEventListener("mouseenter",g);return m};u.prototype.close=function(a,b){this.root.parentNode&&this.root.parentNode.removeChild(this.root);this.parentMenu&&!b&&(this.parentMenu.lock=!1,this.parentMenu.current_submenu=null,void 0===a?this.parentMenu.close():a&&!u.isCursorOverElement(a,this.parentMenu.root)&&u.trigger(this.parentMenu.root,"mouseleave",a));this.current_submenu&&
|
||||
this.current_submenu.close(a,!0)};u.trigger=function(a,b,c,g){var e=document.createEvent("CustomEvent");e.initCustomEvent(b,!0,!0,c);e.srcElement=g;a.dispatchEvent?a.dispatchEvent(e):a.__events&&a.__events.dispatchEvent(e);return e};u.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};u.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event};u.isCursorOverElement=function(a,
|
||||
b){var c=a.pageX,g=a.pageY,e=b.getBoundingClientRect();return e?g>e.top&&g<e.top+e.height&&c>e.left&&c<e.left+e.width?!0:!1:!1};k.ContextMenu=u;k.closeAllContextMenus=function(a){a=a||window;a=a.document.querySelectorAll(".litecontextmenu");if(a.length){for(var b=[],c=0;c<a.length;c++)b.push(a[c]);for(c in b)b[c].close?b[c].close():b[c].parentNode&&b[c].parentNode.removeChild(b[c])}};k.extendClass=function(a,b){for(var c in b)a.hasOwnProperty(c)||(a[c]=b[c]);if(b.prototype)for(c in b.prototype)b.prototype.hasOwnProperty(c)&&
|
||||
b.shadowColor="rgba(0,0,0,0)";b.restore()}b.finish&&b.finish();this.dirty_bgcanvas=!1;this.dirty_canvas=!0};var c=new Float32Array(2);g.prototype.drawNode=function(a,b){this.current_node=a;var f=a.color||a.constructor.color||k.NODE_DEFAULT_COLOR,g=a.bgcolor||a.constructor.bgcolor||k.NODE_DEFAULT_BGCOLOR;if(this.live_mode){if(!a.flags.collapsed&&(b.shadowColor="transparent",a.onDrawForeground))a.onDrawForeground(b,this)}else{var e=this.editor_alpha;b.globalAlpha=e;this.render_shadows?(b.shadowColor=
|
||||
k.DEFAULT_SHADOW_COLOR,b.shadowOffsetX=2*this.scale,b.shadowOffsetY=2*this.scale,b.shadowBlur=3*this.scale):b.shadowColor="transparent";if(!a.flags.collapsed||!a.onDrawCollaped||!0!=a.onDrawCollapsed(b,this)){var l=a._shape||k.BOX_SHAPE;c.set(a.size);if(a.flags.collapsed){b.font=this.inner_text_font;var n=a.getTitle?a.getTitle():a.title;a._collapsed_width=Math.min(a.size[0],b.measureText(n).width+40);c[0]=a._collapsed_width;c[1]=0}a.flags.clip_area&&(b.save(),b.beginPath(),l==k.BOX_SHAPE?b.rect(0,
|
||||
0,c[0],c[1]):l==k.ROUND_SHAPE?b.roundRect(0,0,c[0],c[1],10):l==k.CIRCLE_SHAPE&&b.arc(0.5*c[0],0.5*c[1],0.5*c[0],0,2*Math.PI),b.clip());this.drawNodeShape(a,b,c,f,g,a.selected,a.mouseOver);b.shadowColor="transparent";b.textAlign=a.flags.horizontal?"center":"left";b.font=this.inner_text_font;f=0.6<this.scale;g=this.connecting_output;b.lineWidth=1;l=0;if(a.flags.collapsed){if(a.inputs)for(n=0;n<a.inputs.length;n++)if(m=a.inputs[n],null!=m.link){b.fillStyle=m.color_on||this.default_connection_color.input_on;
|
||||
b.beginPath();m.type===k.EVENT||m.shape===k.BOX_SHAPE?b.rect(0.5,4-k.NODE_TITLE_HEIGHT+0.5,14,k.NODE_TITLE_HEIGHT-8):m.shape===k.ARROW_SHAPE?(b.moveTo(8,-0.5*k.NODE_TITLE_HEIGHT),b.lineTo(-4,-0.8*k.NODE_TITLE_HEIGHT),b.lineTo(-4,-0.2*k.NODE_TITLE_HEIGHT),b.closePath()):b.arc(0,-0.5*k.NODE_TITLE_HEIGHT,4,0,2*Math.PI);b.fill();break}if(a.outputs)for(n=0;n<a.outputs.length;n++)m=a.outputs[n],m.links&&m.links.length&&(b.fillStyle=m.color_on||this.default_connection_color.output_on,b.strokeStyle="black",
|
||||
b.beginPath(),m.type===k.EVENT||m.shape===k.BOX_SHAPE?b.rect(a._collapsed_width-4+0.5,4-k.NODE_TITLE_HEIGHT+0.5,14,k.NODE_TITLE_HEIGHT-8):m.shape===k.ARROW_SHAPE?(b.moveTo(a._collapsed_width+6,-0.5*k.NODE_TITLE_HEIGHT),b.lineTo(a._collapsed_width-6,-0.8*k.NODE_TITLE_HEIGHT),b.lineTo(a._collapsed_width-6,-0.2*k.NODE_TITLE_HEIGHT),b.closePath()):b.arc(a._collapsed_width,-0.5*k.NODE_TITLE_HEIGHT,4,0,2*Math.PI),b.fill(),b.stroke())}else{if(a.inputs)for(n=0;n<a.inputs.length;n++){var m=a.inputs[n];b.globalAlpha=
|
||||
e;this.connecting_node&&k.isValidConnection(m.type&&g.type)&&(b.globalAlpha=0.4*e);b.fillStyle=null!=m.link?m.color_on||this.default_connection_color.input_on:m.color_off||this.default_connection_color.input_off;var d=a.getConnectionPos(!0,n);d[0]-=a.pos[0];d[1]-=a.pos[1];l<d[1]+0.5*k.NODE_SLOT_HEIGHT&&(l=d[1]+0.5*k.NODE_SLOT_HEIGHT);b.beginPath();m.type===k.EVENT||m.shape===k.BOX_SHAPE?b.rect(d[0]-6+0.5,d[1]-5+0.5,14,10):m.shape===k.ARROW_SHAPE?(b.moveTo(d[0]+8,d[1]+0.5),b.lineTo(d[0]-4,d[1]+6+0.5),
|
||||
b.lineTo(d[0]-4,d[1]-6+0.5),b.closePath()):b.arc(d[0],d[1],4,0,2*Math.PI);b.fill();if(f){var h=null!=m.label?m.label:m.name;h&&(b.fillStyle=k.NODE_TEXT_COLOR,a.flags.horizontal||m.dir==k.UP?b.fillText(h,d[0],d[1]-10):b.fillText(h,d[0]+10,d[1]+5))}}this.connecting_node&&(b.globalAlpha=0.4*e);b.textAlign=a.flags.horizontal?"center":"right";b.strokeStyle="black";if(a.outputs)for(n=0;n<a.outputs.length;n++)if(m=a.outputs[n],d=a.getConnectionPos(!1,n),d[0]-=a.pos[0],d[1]-=a.pos[1],l<d[1]+0.5*k.NODE_SLOT_HEIGHT&&
|
||||
(l=d[1]+0.5*k.NODE_SLOT_HEIGHT),b.fillStyle=m.links&&m.links.length?m.color_on||this.default_connection_color.output_on:m.color_off||this.default_connection_color.output_off,b.beginPath(),m.type===k.EVENT||m.shape===k.BOX_SHAPE?b.rect(d[0]-6+0.5,d[1]-5+0.5,14,10):m.shape===k.ARROW_SHAPE?(b.moveTo(d[0]+8,d[1]+0.5),b.lineTo(d[0]-4,d[1]+6+0.5),b.lineTo(d[0]-4,d[1]-6+0.5),b.closePath()):b.arc(d[0],d[1],4,0,2*Math.PI),b.fill(),b.stroke(),f&&(h=null!=m.label?m.label:m.name))b.fillStyle=k.NODE_TEXT_COLOR,
|
||||
a.flags.horizontal||m.dir==k.DOWN?b.fillText(h,d[0],d[1]-8):b.fillText(h,d[0]-10,d[1]+5);b.textAlign="left";b.globalAlpha=1;if(a.widgets){if(a.flags.horizontal||a.flags.widgets_up)l=2;this.drawNodeWidgets(a,l,b,this.node_widget&&this.node_widget[0]==a?this.node_widget[1]:null)}a.onDrawForeground&&(a.gui_rects&&(a.gui_rects.length=0),a.onDrawForeground(b,this))}a.flags.clip_area&&b.restore();b.globalAlpha=1}}};g.prototype.drawNodeShape=function(a,b,c,m,e,l,n){b.strokeStyle=m;b.fillStyle=e;e=k.NODE_TITLE_HEIGHT;
|
||||
var d=a._shape||a.constructor.shape||k.BOX_SHAPE,h=a.constructor.title_mode,x=!0;h==k.TRANSPARENT_TITLE?x=!1:h==k.AUTOHIDE_TITLE&&n&&(x=!0);n=x?-e:0;var q=c[0]+1,p=x?c[1]+e:c[1];a.flags.collapsed||(d==k.BOX_SHAPE||0.5>this.scale?(b.beginPath(),b.rect(0,n,q,p),b.fill()):d==k.ROUND_SHAPE||d==k.CARD_SHAPE?(b.beginPath(),b.roundRect(0,n,q,p,this.round_radius,d==k.CARD_SHAPE?0:this.round_radius),b.fill()):d==k.CIRCLE_SHAPE&&(b.beginPath(),b.arc(0.5*c[0],0.5*c[1],0.5*c[0],0,2*Math.PI),b.fill()));b.shadowColor=
|
||||
"transparent";a.bgImage&&a.bgImage.width&&b.drawImage(a.bgImage,0.5*(c[0]-a.bgImage.width),0.5*(c[1]-a.bgImage.height));a.bgImageUrl&&!a.bgImage&&(a.bgImage=a.loadImage(a.bgImageUrl));a.onDrawBackground&&(a.gui_rects&&(a.gui_rects.length=0),a.onDrawBackground(b,this));if(x||h==k.TRANSPARENT_TITLE){if(h!=k.TRANSPARENT_TITLE){a.flags.collapsed&&(b.shadowColor=k.DEFAULT_SHADOW_COLOR);if(this.use_gradients){var r=g.gradients[m];r||(r=g.gradients[m]=b.createLinearGradient(0,0,400,0),r.addColorStop(0,m),
|
||||
r.addColorStop(1,"#000"));b.fillStyle=r}else b.fillStyle=m;r=b.globalAlpha;b.beginPath();if(d==k.BOX_SHAPE||0.5>this.scale)b.rect(0,-e,c[0]+1,e),b.fill();else if(d==k.ROUND_SHAPE||d==k.CARD_SHAPE)b.roundRect(0,-e,c[0]+1,e,this.round_radius,a.flags.collapsed?this.round_radius:0),b.fill();b.shadowColor="transparent"}d==k.ROUND_SHAPE||d==k.CIRCLE_SHAPE||d==k.CARD_SHAPE?(0.5<this.scale&&(b.fillStyle="black",b.beginPath(),b.arc(0.5*e,-0.5*e,0.5*(e-8),0,2*Math.PI),b.fill()),b.fillStyle=a.boxcolor||k.NODE_DEFAULT_BOXCOLOR,
|
||||
b.beginPath(),b.arc(0.5*e,-0.5*e,0.4*(e-8),0,2*Math.PI),b.fill()):(0.5<this.scale&&(b.fillStyle="black",b.fillRect(4,-e+4,e-8,e-8)),b.fillStyle=a.boxcolor||k.NODE_DEFAULT_BOXCOLOR,b.fillRect(5,-e+5,e-10,e-10));b.globalAlpha=r;0.5<this.scale&&(b.font=this.title_text_font,r=a.getTitle())&&(b.fillStyle=l?"white":a.constructor.title_text_color||this.node_title_color,a.flags.collapsed?(b.textAlign="center",x=b.measureText(r),b.fillText(r,e+0.5*x.width,0.2*-e),b.textAlign="left"):(b.textAlign="left",b.fillText(r,
|
||||
e,0.2*-e)))}l&&(h==k.TRANSPARENT_TITLE&&(n-=e,p+=e),b.lineWidth=1,b.globalAlpha=0.8,b.beginPath(),d==k.BOX_SHAPE?b.rect(-6,-6+n,12+q,12+p):d==k.ROUND_SHAPE||d==k.CARD_SHAPE&&a.flags.collapsed?b.roundRect(-6,-6+n,12+q,12+p,2*this.round_radius):d==k.CARD_SHAPE?b.roundRect(-6,-6+n,12+q,12+p,2*this.round_radius,2):d==k.CIRCLE_SHAPE&&b.arc(0.5*c[0],0.5*c[1],0.5*c[0]+6,0,2*Math.PI),b.strokeStyle="#FFF",b.stroke(),b.strokeStyle=m,b.globalAlpha=1)};g.prototype.drawConnections=function(a){var b=k.getTime();
|
||||
a.lineWidth=this.connections_width;a.fillStyle="#AAA";a.strokeStyle="#AAA";a.globalAlpha=this.editor_alpha;for(var c=0,g=this.graph._nodes.length;c<g;++c){var e=this.graph._nodes[c];if(e.inputs&&e.inputs.length)for(var l=0;l<e.inputs.length;++l){var n=e.inputs[l];if(n&&null!=n.link&&(n=this.graph.links[n.link])){var d=this.graph.getNodeById(n.origin_id);if(null!=d){var m=n.origin_slot,h=null,h=-1==m?[d.pos[0]+10,d.pos[1]+10]:d.getConnectionPos(!1,m),q=e.getConnectionPos(!0,l),d=d.outputs[m].dir||
|
||||
(d.flags.horizontal?k.DOWN:k.RIGHT),m=e.inputs[l].dir||(e.flags.horizontal?k.UP:k.LEFT);this.renderLink(a,h,q,n,!1,0,null,d,m);if(n&&n._last_time&&1E3>b-n._last_time){var p=2-0.002*(b-n._last_time),r="rgba(255,255,255, "+p.toFixed(2)+")";this.renderLink(a,h,q,n,!0,p,r,d,m)}}}}}a.globalAlpha=1};g.prototype.renderLink=function(a,b,c,d,e,l,n,m,h){if(this.highquality_render){m=m||k.RIGHT;h=h||k.LEFT;var x=r(b,c);this.render_connections_border&&0.6<this.scale&&(a.lineWidth=this.connections_width+4);!n&&
|
||||
d&&(n=g.link_type_colors[d.type]);n||(n=this.default_link_color);null!=d&&this.highlighted_links[d.id]&&(n="#FFF");a.beginPath();if(this.render_curved_connections){a.moveTo(b[0],b[1]);var q=d=0,p=0,s=0;switch(m){case k.LEFT:d=-0.25*x;break;case k.RIGHT:d=0.25*x;break;case k.UP:q=-0.25*x;break;case k.DOWN:q=0.25*x}switch(h){case k.LEFT:p=-0.25*x;break;case k.RIGHT:p=0.25*x;break;case k.UP:s=-0.25*x;break;case k.DOWN:s=0.25*x}a.bezierCurveTo(b[0]+d,b[1]+q,c[0]+p,c[1]+s,c[0],c[1])}else a.moveTo(b[0]+
|
||||
10,b[1]),a.lineTo(0.5*(b[0]+10+(c[0]-10)),b[1]),a.lineTo(0.5*(b[0]+10+(c[0]-10)),c[1]),a.lineTo(c[0]-10,c[1]);this.render_connections_border&&0.6<this.scale&&!e&&(a.strokeStyle="rgba(0,0,0,0.5)",a.stroke());a.lineWidth=this.connections_width;a.fillStyle=a.strokeStyle=n;a.stroke();this.render_connection_arrows&&0.6<=this.scale&&this.render_connection_arrows&&0.6<this.scale&&(e=this.computeConnectionPoint(b,c,0.5,m,h),n=this.computeConnectionPoint(b,c,0.51,m,h),x=0,x=this.render_curved_connections?
|
||||
-Math.atan2(n[0]-e[0],n[1]-e[1]):c[1]>b[1]?0:Math.PI,a.save(),a.translate(e[0],e[1]),a.rotate(x),a.beginPath(),a.moveTo(-5,-5),a.lineTo(0,5),a.lineTo(5,-5),a.fill(),a.restore());if(l)for(l=0;5>l;++l)e=(0.001*k.getTime()+0.2*l)%1,e=this.computeConnectionPoint(b,c,e,m,h),a.beginPath(),a.arc(e[0],e[1],5,0,2*Math.PI),a.fill()}else a.beginPath(),a.moveTo(b[0],b[1]),a.lineTo(c[0],c[1]),a.stroke()};g.prototype.computeConnectionPoint=function(a,b,c,g,e){g=g||k.RIGHT;e=e||k.LEFT;var l=r(a,b),n=[a[0],a[1]],
|
||||
d=[b[0],b[1]];switch(g){case k.LEFT:n[0]+=-0.25*l;break;case k.RIGHT:n[0]+=0.25*l;break;case k.UP:n[1]+=-0.25*l;break;case k.DOWN:n[1]+=0.25*l}switch(e){case k.LEFT:d[0]+=-0.25*l;break;case k.RIGHT:d[0]+=0.25*l;break;case k.UP:d[1]+=-0.25*l;break;case k.DOWN:d[1]+=0.25*l}g=(1-c)*(1-c)*(1-c);e=3*(1-c)*(1-c)*c;l=3*(1-c)*c*c;c*=c*c;return[g*a[0]+e*n[0]+l*d[0]+c*b[0],g*a[1]+e*n[1]+l*d[1]+c*b[1]]};g.prototype.drawExecutionOrder=function(a){a.shadowColor="transparent";a.globalAlpha=0.25;a.textAlign="center";
|
||||
a.strokeStyle="white";a.globalAlpha=0.75;for(var b=this.visible_nodes,c=0;c<b.length;++c){var g=b[c];a.fillStyle="black";a.fillRect(g.pos[0]-k.NODE_TITLE_HEIGHT,g.pos[1]-k.NODE_TITLE_HEIGHT,k.NODE_TITLE_HEIGHT,k.NODE_TITLE_HEIGHT);0==g.order&&a.strokeRect(g.pos[0]-k.NODE_TITLE_HEIGHT+0.5,g.pos[1]-k.NODE_TITLE_HEIGHT+0.5,k.NODE_TITLE_HEIGHT,k.NODE_TITLE_HEIGHT);a.fillStyle="#FFF";a.fillText(g.order,g.pos[0]+-0.5*k.NODE_TITLE_HEIGHT,g.pos[1]-6)}a.globalAlpha=1};g.prototype.drawNodeWidgets=function(a,
|
||||
b,c,g){if(!a.widgets||!a.widgets.length)return 0;var e=a.size[0];a=a.widgets;b+=2;for(var l=k.NODE_WIDGET_HEIGHT,n=0.5<this.scale,d=0;d<a.length;++d){var m=a[d],h=b;m.y&&(h=m.y);m.last_y=h;c.strokeStyle="#AAA";c.fillStyle="#222";c.textAlign="left";switch(m.type){case "button":m.clicked&&(c.fillStyle="#AAA",m.clicked=!1,this.dirty_canvas=!0);c.fillRect(10,h,e-20,l);c.strokeRect(10,h,e-20,l);n&&(c.textAlign="center",c.fillStyle="#AAA",c.fillText(m.name,0.5*e,h+0.7*l));break;case "slider":c.fillStyle=
|
||||
"#111";c.fillRect(10,h,e-20,l);var q=(m.value-m.options.min)/(m.options.max-m.options.min);c.fillStyle=g==m?"#89A":"#678";c.fillRect(10,h,q*(e-20),l);c.strokeRect(10,h,e-20,l);n&&(c.textAlign="center",c.fillStyle="#DDD",c.fillText(m.name+" "+Number(m.value).toFixed(3),0.5*e,h+0.7*l));break;case "number":case "combo":c.textAlign="left";c.strokeStyle="#AAA";c.fillStyle="#111";c.beginPath();c.roundRect(10,b,e-20,l,0.5*l);c.fill();c.stroke();c.fillStyle="#AAA";c.beginPath();c.moveTo(26,b+5);c.lineTo(16,
|
||||
b+0.5*l);c.lineTo(26,b+l-5);c.moveTo(e-26,b+5);c.lineTo(e-16,b+0.5*l);c.lineTo(e-26,b+l-5);c.fill();n&&(c.fillStyle="#999",c.fillText(m.name,30,h+0.7*l),c.fillStyle="#DDD",c.textAlign="right","number"==m.type?c.fillText(Number(m.value).toFixed(void 0!==m.options.precision?m.options.precision:3),e-40,h+0.7*l):c.fillText(m.value,e-40,h+0.7*l));break;case "text":c.textAlign="left",c.strokeStyle="#AAA",c.fillStyle="#111",c.beginPath(),c.roundRect(10,b,e-20,l,0.5*l),c.fill(),c.stroke(),c.fillStyle="#999",
|
||||
null!=m.name&&c.fillText(m.name,20,h+0.7*l),c.fillStyle="#DDD",c.textAlign="right",c.fillText(m.value,e-20,h+0.7*l)}b+=l+4}c.textAlign="left"};g.prototype.processNodeWidgets=function(a,b,c,g){if(!a.widgets||!a.widgets.length)return null;for(var e=b[0]-a.pos[0],l=b[1]-a.pos[1],n=a.size[0],m=this,d=0;d<a.widgets.length;++d){var h=a.widgets[d];if(h==g||6<e&&e<n-12&&l>h.last_y&&l<h.last_y+k.NODE_WIDGET_HEIGHT){switch(h.type){case "button":h.callback&&setTimeout(function(){h.callback(h,m,a,b)},20);this.dirty_canvas=
|
||||
h.clicked=!0;break;case "slider":c=Math.clamp((e-10)/(n-20),0,1);h.value=h.options.min+(h.options.max-h.options.min)*c;h.callback&&setTimeout(function(){h.callback(h.value,m,a,b)},20);this.dirty_canvas=!0;break;case "number":case "combo":"mousemove"==c.type&&"number"==h.type?(h.value+=0.1*c.deltaX*(h.options.step||1),null!=h.options.min&&h.value<h.options.min&&(h.value=h.options.min),null!=h.options.max&&h.value>h.options.max&&(h.value=h.options.max)):"mousedown"==c.type&&(c=40>e?-1:e>n-40?1:0,"number"==
|
||||
h.type?(h.value+=0.1*c*(h.options.step||1),null!=h.options.min&&h.value<h.options.min&&(h.value=h.options.min),null!=h.options.max&&h.value>h.options.max&&(h.value=h.options.max)):c&&(c=h.options.values.indexOf(h.value)+c,c>=h.options.values.length&&(c=0),0>c&&(c=h.options.values.length-1),h.value=h.options.values[c]));h.callback&&setTimeout(function(){this.callback(this.value,m,a,b)}.bind(h),20);this.dirty_canvas=!0;break;case "text":"mousedown"==c.type&&this.prompt("Value",h.value,function(a){this.value=
|
||||
a}.bind(h),c)}return h}}return null};g.prototype.drawGroups=function(a,b){if(this.graph){var c=this.graph._groups;b.save();b.globalAlpha=0.5;b.font="24px Arial";for(var g=0;g<c.length;++g){var e=c[g];if(s(this.visible_area,e._bounding)){b.fillStyle=e.color||"#335";b.strokeStyle=e.color||"#335";var l=e._pos,n=e._size;b.globalAlpha=0.25;b.beginPath();b.rect(l[0]+0.5,l[1]+0.5,n[0],n[1]);b.fill();b.globalAlpha=1;b.stroke();b.beginPath();b.moveTo(l[0]+n[0],l[1]+n[1]);b.lineTo(l[0]+n[0]-10,l[1]+n[1]);b.lineTo(l[0]+
|
||||
n[0],l[1]+n[1]-10);b.fill();b.fillText(e.title,l[0]+4,l[1]+24)}}b.restore()}};g.prototype.resize=function(a,b){if(!a&&!b){var c=this.canvas.parentNode;a=c.offsetWidth;b=c.offsetHeight}if(this.canvas.width!=a||this.canvas.height!=b)this.canvas.width=a,this.canvas.height=b,this.bgcanvas.width=this.canvas.width,this.bgcanvas.height=this.canvas.height,this.setDirty(!0,!0)};g.prototype.switchLiveMode=function(a){if(a){var b=this,c=this.live_mode?1.1:0.9;this.live_mode&&(this.live_mode=!1,this.editor_alpha=
|
||||
0.1);var g=setInterval(function(){b.editor_alpha*=c;b.dirty_canvas=!0;b.dirty_bgcanvas=!0;1>c&&0.01>b.editor_alpha&&(clearInterval(g),1>c&&(b.live_mode=!0));1<c&&0.99<b.editor_alpha&&(clearInterval(g),b.editor_alpha=1)},1)}else this.live_mode=!this.live_mode,this.dirty_bgcanvas=this.dirty_canvas=!0};g.prototype.onNodeSelectionChange=function(a){};g.prototype.touchHandler=function(a){var b=a.changedTouches[0],c="";switch(a.type){case "touchstart":c="mousedown";break;case "touchmove":c="mousemove";
|
||||
break;case "touchend":c="mouseup";break;default:return}var g=this.getCanvasWindow(),e=g.document.createEvent("MouseEvent");e.initMouseEvent(c,!0,!0,g,1,b.screenX,b.screenY,b.clientX,b.clientY,!1,!1,!1,!1,0,null);b.target.dispatchEvent(e);a.preventDefault()};g.onGroupAdd=function(a,b,c){a=g.active_canvas;a.getCanvasWindow();b=new k.LGraphGroup;b.pos=a.convertEventToCanvas(c);a.graph.add(b)};g.onMenuAdd=function(a,b,c,m){function e(a,b){var c=m.getFirstEvent(),f=k.createNode(a.value);f&&(f.pos=l.convertEventToCanvas(c),
|
||||
l.graph.add(f))}var l=g.active_canvas,n=l.getCanvasWindow();a=k.getNodeTypesCategories();b=[];for(var d in a)a[d]&&b.push({value:a[d],content:a[d],has_submenu:!0});var h=new k.ContextMenu(b,{event:c,callback:function(a,b,c){a=k.getNodeTypesInCategory(a.value,l.filter);b=[];for(var f in a)b.push({content:a[f].title,value:a[f].type});new k.ContextMenu(b,{event:c,callback:e,parentMenu:h},n);return!1},parentMenu:m},n);return!1};g.onMenuCollapseAll=function(){};g.onMenuNodeEdit=function(){};g.showMenuNodeOptionalInputs=
|
||||
function(a,b,c,d,e){function l(a,b,c){e&&(a.callback&&a.callback.call(n,e,a,b,c),a.value&&(e.addInput(a.value[0],a.value[1],a.value[2]),e.setDirtyCanvas(!0,!0)))}if(e){var n=this;a=g.active_canvas.getCanvasWindow();b=e.optional_inputs;e.onGetInputs&&(b=e.onGetInputs());var m=[];if(b)for(var h in b){var q=b[h];if(q){var p=q[0];q[2]&&q[2].label&&(p=q[2].label);p={content:p,value:q};q[1]==k.ACTION&&(p.className="event");m.push(p)}else m.push(null)}this.onMenuNodeInputs&&(m=this.onMenuNodeInputs(m));
|
||||
if(m.length)return new k.ContextMenu(m,{event:c,callback:l,parentMenu:d,node:e},a),!1}};g.showMenuNodeOptionalOutputs=function(a,b,c,m,e){function l(a,b,c){if(e&&(a.callback&&a.callback.call(d,e,a,b,c),a.value))if(c=a.value[1],!c||c.constructor!==Object&&c.constructor!==Array)e.addOutput(a.value[0],a.value[1],a.value[2]),e.setDirtyCanvas(!0,!0);else{a=[];for(var f in c)a.push({content:f,value:c[f]});new k.ContextMenu(a,{event:b,callback:l,parentMenu:m,node:e});return!1}}if(e){var d=this;a=g.active_canvas.getCanvasWindow();
|
||||
b=e.optional_outputs;e.onGetOutputs&&(b=e.onGetOutputs());var h=[];if(b)for(var q in b){var p=b[q];if(!p)h.push(null);else if(!e.flags||!e.flags.skip_repeated_outputs||-1==e.findOutputSlot(p[0])){var r=p[0];p[2]&&p[2].label&&(r=p[2].label);r={content:r,value:p};p[1]==k.EVENT&&(r.className="event");h.push(r)}}this.onMenuNodeOutputs&&(h=this.onMenuNodeOutputs(h));if(h.length)return new k.ContextMenu(h,{event:c,callback:l,parentMenu:m,node:e},a),!1}};g.onShowMenuNodeProperties=function(a,b,c,m,e){function l(a,
|
||||
b,c,f){e&&(b=this.getBoundingClientRect(),d.showEditPropertyValue(e,a.value,{position:[b.left,b.top]}))}if(e&&e.properties){var d=g.active_canvas;b=d.getCanvasWindow();var h=[],q;for(q in e.properties)a=void 0!==e.properties[q]?e.properties[q]:" ",a=g.decodeHTML(a),h.push({content:"<span class='property_name'>"+q+"</span><span class='property_value'>"+a+"</span>",value:q});if(h.length)return new k.ContextMenu(h,{event:c,callback:l,parentMenu:m,allow_html:!0,node:e},b),!1}};g.decodeHTML=function(a){var b=
|
||||
document.createElement("div");b.innerText=a;return b.innerHTML};g.onResizeNode=function(a,b,c,g,e){e&&(e.size=e.computeSize(),e.setDirtyCanvas(!0,!0))};g.onShowTitleEditor=function(a,b,c,m,e){function l(){e.title=h.value;d.parentNode.removeChild(d);e.setDirtyCanvas(!0,!0)}var d=document.createElement("div");d.className="graphdialog";d.innerHTML="<span class='name'>Title</span><input autofocus type='text' class='value'/><button>OK</button>";var h=d.querySelector("input");h&&(h.value=e.title,h.addEventListener("keydown",
|
||||
function(a){13==a.keyCode&&(l(),a.preventDefault(),a.stopPropagation())}));a=g.active_canvas.canvas;b=a.getBoundingClientRect();m=c=-20;b&&(c-=b.left,m-=b.top);event?(d.style.left=event.pageX+c+"px",d.style.top=event.pageY+m+"px"):(d.style.left=0.5*a.width+c+"px",d.style.top=0.5*a.height+m+"px");d.querySelector("button").addEventListener("click",l);a.parentNode.appendChild(d)};g.prototype.prompt=function(a,b,c,d){var e=this;a=a||"";var l=document.createElement("div");l.className="graphdialog rounded";
|
||||
l.innerHTML="<span class='name'></span> <input autofocus type='text' class='value'/><button class='rounded'>OK</button>";l.close=function(){e.prompt_box=null;l.parentNode.removeChild(l)};l.addEventListener("mouseleave",function(a){l.close()});e.prompt_box&&e.prompt_box.close();e.prompt_box=l;l.querySelector(".name").innerText=a;l.querySelector(".value").value=b;var m=l.querySelector("input");m.addEventListener("keydown",function(a){if(27==a.keyCode)l.close();else if(13==a.keyCode)c&&c(this.value),
|
||||
l.close();else return;a.preventDefault();a.stopPropagation()});l.querySelector("button").addEventListener("click",function(a){c&&c(m.value);e.setDirty(!0);l.close()});a=g.active_canvas.canvas;b=a.getBoundingClientRect();var h=-20,k=-20;b&&(h-=b.left,k-=b.top);d?(l.style.left=d.pageX+h+"px",l.style.top=d.pageY+k+"px"):(l.style.left=0.5*a.width+h+"px",l.style.top=0.5*a.height+k+"px");a.parentNode.appendChild(l);setTimeout(function(){m.focus()},10);return l};g.prototype.showSearchBox=function(a){function b(b){if(b)if(e.onSearchBoxSelection)e.onSearchBoxSelection(b,
|
||||
a,s);else if(b=k.createNode(b))b.pos=s.convertEventToCanvas(a),s.graph.add(b);l.close()}function c(a){var b=p;p&&p.classList.remove("selected");p?(p=a?p.nextSibling:p.previousSibling)||(p=b):p=a?m.childNodes[0]:m.childNodes[m.childNodes.length];p&&(p.classList.add("selected"),p.scrollIntoView())}function d(){q=null;var a=r.value;h=null;m.innerHTML="";if(a)if(e.onSearchBox)e.onSearchBox(f,a,s);else for(var c in k.registered_node_types)if(-1!=c.indexOf(a)){var f=document.createElement("div");h||(h=
|
||||
c);f.innerText=c;f.className="help-item";f.addEventListener("click",function(a){b(this.innerText)});m.appendChild(f)}}var e=this,l=document.createElement("div");l.className="graphdialog rounded";l.innerHTML="<span class='name'>Search</span> <input autofocus type='text' class='value rounded'/><div class='helper'></div>";l.close=function(){e.search_box=null;l.parentNode.removeChild(l)};l.addEventListener("mouseleave",function(a){l.close()});e.search_box&&e.search_box.close();e.search_box=l;var m=l.querySelector(".helper"),
|
||||
h=null,q=null,p=null,r=l.querySelector("input");r&&r.addEventListener("keydown",function(a){if(38==a.keyCode)c(!1);else if(40==a.keyCode)c(!0);else if(27==a.keyCode)l.close();else if(13==a.keyCode)p?b(p.innerHTML):h?b(h):l.close();else{q&&clearInterval(q);q=setTimeout(d,10);return}a.preventDefault();a.stopPropagation()});var s=g.active_canvas,u=s.canvas,t=u.getBoundingClientRect(),z=-20,E=-20;t&&(z-=t.left,E-=t.top);a?(l.style.left=a.pageX+z+"px",l.style.top=a.pageY+E+"px"):(l.style.left=0.5*u.width+
|
||||
z+"px",l.style.top=0.5*u.height+E+"px");u.parentNode.appendChild(l);setTimeout(function(){r.focus()},10);return l};g.prototype.showEditPropertyValue=function(a,b,c){function g(){e(p.value)}function e(c){"number"==typeof a.properties[b]&&(c=Number(c));"array"==l&&(c=c.split(",").map(Number));a.properties[b]=c;a._graph&&a._graph._version++;if(a.onPropertyChanged)a.onPropertyChanged(b,c);q.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){c=c||{};var l="string";null!==a.properties[b]&&
|
||||
(l=typeof a.properties[b]);"object"==l&&a.properties[b].length&&(l="array");var m=null;a.getPropertyInfo&&(m=a.getPropertyInfo(b));if(a.properties_info)for(var d=0;d<a.properties_info.length;++d)if(a.properties_info[d].name==b){m=a.properties_info[d];break}void 0!==m&&null!==m&&m.type&&(l=m.type);var h="";if("string"==l||"number"==l||"array"==l)h="<input autofocus type='text' class='value'/>";else if("enum"==l&&m.values){h="<select autofocus type='text' class='value'>";for(d in m.values)var k=m.values.constructor===
|
||||
Array?m.values[d]:d,h=h+("<option value='"+k+"' "+(k==a.properties[b]?"selected":"")+">"+m.values[d]+"</option>");h+="</select>"}else if("boolean"==l)h="<input autofocus type='checkbox' class='value' "+(a.properties[b]?"checked":"")+"/>";else{console.warn("unknown type: "+l);return}var q=this.createDialog("<span class='name'>"+b+"</span>"+h+"<button>OK</button>",c);if("enum"==l&&m.values){var p=q.querySelector("select");p.addEventListener("change",function(a){e(a.target.value)})}else if("boolean"==
|
||||
l)(p=q.querySelector("input"))&&p.addEventListener("click",function(a){e(!!p.checked)});else if(p=q.querySelector("input"))p.value=void 0!==a.properties[b]?a.properties[b]:"",p.addEventListener("keydown",function(a){13==a.keyCode&&(g(),a.preventDefault(),a.stopPropagation())});q.querySelector("button").addEventListener("click",g)}};g.prototype.createDialog=function(a,b){b=b||{};var c=document.createElement("div");c.className="graphdialog";c.innerHTML=a;var g=this.canvas.getBoundingClientRect(),e=
|
||||
-20,l=-20;g&&(e-=g.left,l-=g.top);b.position?(e+=b.position[0],l+=b.position[1]):b.event?(e+=b.event.pageX,l+=b.event.pageY):(e+=0.5*this.canvas.width,l+=0.5*this.canvas.height);c.style.left=e+"px";c.style.top=l+"px";this.canvas.parentNode.appendChild(c);c.close=function(){this.parentNode&&this.parentNode.removeChild(this)};return c};g.onMenuNodeCollapse=function(a,b,c,g,e){e.collapse()};g.onMenuNodePin=function(a,b,c,g,e){e.pin()};g.onMenuNodeMode=function(a,b,c,g,e){new k.ContextMenu(["Always",
|
||||
"On Event","On Trigger","Never"],{event:c,callback:function(a){if(e)switch(a){case "On Event":e.mode=k.ON_EVENT;break;case "On Trigger":e.mode=k.ON_TRIGGER;break;case "Never":e.mode=k.NEVER;break;default:e.mode=k.ALWAYS}},parentMenu:g,node:e});return!1};g.onMenuNodeColors=function(a,b,c,m,e){if(!e)throw"no node for color";b=[];b.push({value:null,content:"<span style='display: block; padding-left: 4px;'>No color</span>"});for(var l in g.node_colors)a=g.node_colors[l],a={value:l,content:"<span style='display: block; color: #999; padding-left: 4px; border-left: 8px solid "+
|
||||
a.color+"; background-color:"+a.bgcolor+"'>"+l+"</span>"},b.push(a);new k.ContextMenu(b,{event:c,callback:function(a){e&&((a=a.value?g.node_colors[a.value]:null)?e.constructor===k.LGraphGroup?e.color=a.groupcolor:(e.color=a.color,e.bgcolor=a.bgcolor):(delete e.color,delete e.bgcolor),e.setDirtyCanvas(!0,!0))},parentMenu:m,node:e});return!1};g.onMenuNodeShapes=function(a,b,c,g,e){if(!e)throw"no node passed";new k.ContextMenu(k.VALID_SHAPES,{event:c,callback:function(a){e&&(e.shape=a,e.setDirtyCanvas(!0))},
|
||||
parentMenu:g,node:e});return!1};g.onMenuNodeRemove=function(a,b,c,g,e){if(!e)throw"no node passed";!1!==e.removable&&(e.graph.remove(e),e.setDirtyCanvas(!0,!0))};g.onMenuNodeClone=function(a,b,c,g,e){!1!=e.clonable&&(a=e.clone())&&(a.pos=[e.pos[0]+5,e.pos[1]+5],e.graph.add(a),e.setDirtyCanvas(!0,!0))};g.node_colors={red:{color:"#322",bgcolor:"#533",groupcolor:"#A88"},brown:{color:"#332922",bgcolor:"#593930",groupcolor:"#b06634"},green:{color:"#232",bgcolor:"#353",groupcolor:"#8A8"},blue:{color:"#223",
|
||||
bgcolor:"#335",groupcolor:"#88A"},pale_blue:{color:"#2a363b",bgcolor:"#3f5159",groupcolor:"#3f789e"},cyan:{color:"#233",bgcolor:"#355",groupcolor:"#8AA"},purple:{color:"#323",bgcolor:"#535",groupcolor:"#a1309b"},yellow:{color:"#432",bgcolor:"#653",groupcolor:"#b58b2a"},black:{color:"#222",bgcolor:"#000",groupcolor:"#444"}};g.prototype.getCanvasMenuOptions=function(){var a=null;this.getMenuOptions?a=this.getMenuOptions():(a=[{content:"Add Node",has_submenu:!0,callback:g.onMenuAdd},{content:"Add Group",
|
||||
callback:g.onGroupAdd}],this._graph_stack&&0<this._graph_stack.length&&(a=[{content:"Close subgraph",callback:this.closeSubgraph.bind(this)},null].concat(a)));if(this.getExtraMenuOptions){var b=this.getExtraMenuOptions(this,a);b&&(a=a.concat(b))}return a};g.prototype.getNodeMenuOptions=function(a){var b=null,b=a.getMenuOptions?a.getMenuOptions(this):[{content:"Inputs",has_submenu:!0,disabled:!0,callback:g.showMenuNodeOptionalInputs},{content:"Outputs",has_submenu:!0,disabled:!0,callback:g.showMenuNodeOptionalOutputs},
|
||||
null,{content:"Properties",has_submenu:!0,callback:g.onShowMenuNodeProperties},null,{content:"Title",callback:g.onShowTitleEditor},{content:"Mode",has_submenu:!0,callback:g.onMenuNodeMode},{content:"Resize",callback:g.onResizeNode},{content:"Collapse",callback:g.onMenuNodeCollapse},{content:"Pin",callback:g.onMenuNodePin},{content:"Colors",has_submenu:!0,callback:g.onMenuNodeColors},{content:"Shapes",has_submenu:!0,callback:g.onMenuNodeShapes},null];if(a.getExtraMenuOptions){var c=a.getExtraMenuOptions(this);
|
||||
c&&(c.push(null),b=c.concat(b))}!1!==a.clonable&&b.push({content:"Clone",callback:g.onMenuNodeClone});!1!==a.removable&&b.push(null,{content:"Remove",callback:g.onMenuNodeRemove});a.onGetInputs&&(c=a.onGetInputs())&&c.length&&(b[0].disabled=!1);a.onGetOutputs&&(c=a.onGetOutputs())&&c.length&&(b[1].disabled=!1);if(a.graph&&a.graph.onGetNodeMenuOptions)a.graph.onGetNodeMenuOptions(b,a);return b};g.prototype.getGroupMenuOptions=function(a){return[{content:"Title",callback:g.onShowTitleEditor},{content:"Color",
|
||||
has_submenu:!0,callback:g.onMenuNodeColors},null,{content:"Remove",callback:g.onMenuNodeRemove}]};g.prototype.processContextMenu=function(a,b){var c=this,m=g.active_canvas.getCanvasWindow(),e=null,l={event:b,callback:function(b,e,l){if(b)if("Remove Slot"==b.content){var g=b.slot;g.input?a.removeInput(g.slot):g.output&&a.removeOutput(g.slot)}else if("Rename Slot"==b.content){var g=b.slot,d=c.createDialog("<span class='name'>Name</span><input type='text'/><button>OK</button>",e),m=d.querySelector("input");
|
||||
d.querySelector("button").addEventListener("click",function(b){if(m.value){if(b=g.input?a.getInputInfo(g.slot):a.getOutputInfo(g.slot))b.label=m.value;c.setDirty(!0)}d.close()})}},extra:a},d=null;a&&(d=a.getSlotInPosition(b.canvasX,b.canvasY),g.active_node=a);d?(e=[],e.push(d.locked?"Cannot remove":{content:"Remove Slot",slot:d}),e.push({content:"Rename Slot",slot:d}),l.title=(d.input?d.input.type:d.output.type)||"*",d.input&&d.input.type==k.ACTION&&(l.title="Action"),d.output&&d.output.type==k.EVENT&&
|
||||
(l.title="Event")):a?e=this.getNodeMenuOptions(a):(e=this.getCanvasMenuOptions(),(d=this.graph.getGroupOnPos(b.canvasX,b.canvasY))&&e.push(null,{content:"Edit Group",has_submenu:!0,submenu:{title:"Group",extra:d,options:this.getGroupMenuOptions(d)}}));e&&new k.ContextMenu(e,l,m)};this.CanvasRenderingContext2D&&(CanvasRenderingContext2D.prototype.roundRect=function(a,b,c,g,e,l){void 0===e&&(e=5);void 0===l&&(l=e);this.moveTo(a+e,b);this.lineTo(a+c-e,b);this.quadraticCurveTo(a+c,b,a+c,b+e);this.lineTo(a+
|
||||
c,b+g-l);this.quadraticCurveTo(a+c,b+g,a+c-l,b+g);this.lineTo(a+l,b+g);this.quadraticCurveTo(a,b+g,a,b+g-l);this.lineTo(a,b+e);this.quadraticCurveTo(a,b,a+e,b)});k.compareObjects=function(a,b){for(var c in a)if(a[c]!=b[c])return!1;return!0};k.distance=r;k.colorToString=function(a){return"rgba("+Math.round(255*a[0]).toFixed()+","+Math.round(255*a[1]).toFixed()+","+Math.round(255*a[2]).toFixed()+","+(4==a.length?a[3].toFixed(2):"1.0")+")"};k.isInsideRectangle=p;k.growBounding=function(a,b,c){b<a[0]?
|
||||
a[0]=b:b>a[2]&&(a[2]=b);c<a[1]?a[1]=c:c>a[3]&&(a[3]=c)};k.isInsideBounding=function(a,b){return a[0]<b[0][0]||a[1]<b[0][1]||a[0]>b[1][0]||a[1]>b[1][1]?!1:!0};k.overlapBounding=s;k.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),c=0,g,e,l=0;6>l;l+=2)g="0123456789ABCDEF".indexOf(a.charAt(l)),e="0123456789ABCDEF".indexOf(a.charAt(l+1)),b[c]=16*g+e,c++;return b};k.num2hex=function(a){for(var b="#",c,g,e=0;3>e;e++)c=a[e]/16,g=a[e]%16,b+="0123456789ABCDEF".charAt(c)+
|
||||
"0123456789ABCDEF".charAt(g);return b};u.prototype.addItem=function(a,b,c){function g(a){var b=this.value;b&&b.has_submenu&&e.call(this,a)}function e(a){var b=this.value,e=!0;l.current_submenu&&l.current_submenu.close(a);if(c.callback){var g=c.callback.call(this,b,c,a,l,c.node);!0===g&&(e=!1)}if(b&&(b.callback&&!c.ignore_item_callbacks&&!0!==b.disabled&&(g=b.callback.call(this,b,c,a,l,c.extra),!0===g&&(e=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new l.constructor(b.submenu.options,
|
||||
{callback:b.submenu.callback,event:a,parentMenu:l,ignore_item_callbacks:b.submenu.ignore_item_callbacks,title:b.submenu.title,extra:b.submenu.extra,autoopen:c.autoopen});e=!1}e&&!l.lock&&l.close()}var l=this;c=c||{};var d=document.createElement("div");d.className="litemenu-entry submenu";var m=!1;if(null===b)d.classList.add("separator");else{d.innerHTML=b&&b.title?b.title:a;if(d.value=b)b.disabled&&(m=!0,d.classList.add("disabled")),(b.submenu||b.has_submenu)&&d.classList.add("has_submenu");"function"==
|
||||
typeof b?(d.dataset.value=a,d.onclick_callback=b):d.dataset.value=b;b.className&&(d.className+=" "+b.className)}this.root.appendChild(d);m||d.addEventListener("click",e);c.autoopen&&d.addEventListener("mouseenter",g);return d};u.prototype.close=function(a,b){this.root.parentNode&&this.root.parentNode.removeChild(this.root);this.parentMenu&&!b&&(this.parentMenu.lock=!1,this.parentMenu.current_submenu=null,void 0===a?this.parentMenu.close():a&&!u.isCursorOverElement(a,this.parentMenu.root)&&u.trigger(this.parentMenu.root,
|
||||
"mouseleave",a));this.current_submenu&&this.current_submenu.close(a,!0)};u.trigger=function(a,b,c,g){var e=document.createEvent("CustomEvent");e.initCustomEvent(b,!0,!0,c);e.srcElement=g;a.dispatchEvent?a.dispatchEvent(e):a.__events&&a.__events.dispatchEvent(e);return e};u.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};u.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event};
|
||||
u.isCursorOverElement=function(a,b){var c=a.pageX,g=a.pageY,e=b.getBoundingClientRect();return e?g>e.top&&g<e.top+e.height&&c>e.left&&c<e.left+e.width?!0:!1:!1};k.ContextMenu=u;k.closeAllContextMenus=function(a){a=a||window;a=a.document.querySelectorAll(".litecontextmenu");if(a.length){for(var b=[],c=0;c<a.length;c++)b.push(a[c]);for(c in b)b[c].close?b[c].close():b[c].parentNode&&b[c].parentNode.removeChild(b[c])}};k.extendClass=function(a,b){for(var c in b)a.hasOwnProperty(c)||(a[c]=b[c]);if(b.prototype)for(c in b.prototype)b.prototype.hasOwnProperty(c)&&
|
||||
!a.prototype.hasOwnProperty(c)&&(b.prototype.__lookupGetter__(c)?a.prototype.__defineGetter__(c,b.prototype.__lookupGetter__(c)):a.prototype[c]=b.prototype[c],b.prototype.__lookupSetter__(c)&&a.prototype.__defineSetter__(c,b.prototype.__lookupSetter__(c)))};k.getParameterNames=function(a){return(a+"").replace(/[/][/].*$/mg,"").replace(/\s+/g,"").replace(/[/][*][^/*]*[*][/]/g,"").split("){",1)[0].replace(/^[^(]*[(]/,"").replace(/=[^,]+/g,"").split(",").filter(Boolean)};Math.clamp=function(a,b,c){return b>
|
||||
a?b:c<a?c:a};"undefined"==typeof window||window.requestAnimationFrame||(window.requestAnimationFrame=window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)})})(this);"undefined"!=typeof exports&&(exports.LiteGraph=this.LiteGraph);
|
||||
(function(t){function h(){this.addOutput("in ms","number");this.addOutput("in sec","number")}function d(){var c=this;this.size=[120,80];this.subgraph=new LGraph;this.subgraph._subgraph_node=this;this.subgraph._is_subgraph=!0;this.subgraph.onGlobalInputAdded=this.onSubgraphNewGlobalInput.bind(this);this.subgraph.onGlobalInputRenamed=this.onSubgraphRenamedGlobalInput.bind(this);this.subgraph.onGlobalInputTypeChanged=this.onSubgraphTypeChangeGlobalInput.bind(this);this.subgraph.onGlobalOutputAdded=this.onSubgraphNewGlobalOutput.bind(this);
|
||||
@@ -254,28 +254,28 @@ this.addOutput("out","number");this.addProperty("factor",0.1);this.size=[60,20];
|
||||
"number");this.addInput("B","number");this.addOutput("out","boolean");this.addProperty("A",1);this.addProperty("B",1);this.addProperty("OP",">","string",{values:e.values});this.size=[60,40]}function l(){this.addInput("inc","number");this.addOutput("total","number");this.addProperty("increment",1);this.addProperty("value",0)}function n(){this.addInput("v","number");this.addOutput("sin","number");this.addProperty("amplitude",1);this.addProperty("offset",0);this.bgImageUrl="nodes/imgs/icon-sin.png"}
|
||||
function C(){this.addInput("vec2","vec2");this.addOutput("x","number");this.addOutput("y","number")}function y(){this.addInputs([["x","number"],["y","number"]]);this.addOutput("vec2","vec2");this.properties={x:0,y:0};this._data=new Float32Array(2)}function x(){this.addInput("vec3","vec3");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z","number")}function A(){this.addInputs([["x","number"],["y","number"],["z","number"]]);this.addOutput("vec3","vec3");this.properties={x:0,
|
||||
y:0,z:0};this._data=new Float32Array(3)}function D(){this.addInput("vec4","vec4");this.addOutput("x","number");this.addOutput("y","number");this.addOutput("z","number");this.addOutput("w","number")}function B(){this.addInputs([["x","number"],["y","number"],["z","number"],["w","number"]]);this.addOutput("vec4","vec4");this.properties={x:0,y:0,z:0,w:0};this._data=new Float32Array(4)}var v=t.LiteGraph;h.title="Converter";h.desc="type A to type B";h.prototype.onExecute=function(){var a=this.getInputData(0);
|
||||
if(null!=a&&this.outputs)for(var b=0;b<this.outputs.length;b++){var c=this.outputs[b];if(c.links&&c.links.length){var e=null;switch(c.name){case "number":e=a.length?a[0]:parseFloat(a);break;case "vec2":case "vec3":case "vec4":e=1;switch(c.name){case "vec2":e=2;break;case "vec3":e=3;break;case "vec4":e=4}e=new Float32Array(e);if(a.length)for(c=0;c<a.length&&c<e.length;c++)e[c]=a[c];else e[0]=parseFloat(a)}this.setOutputData(b,e)}}};h.prototype.onGetOutputs=function(){return[["number","number"],["vec2",
|
||||
if(null!=a&&this.outputs)for(var b=0;b<this.outputs.length;b++){var c=this.outputs[b];if(c.links&&c.links.length){var d=null;switch(c.name){case "number":d=a.length?a[0]:parseFloat(a);break;case "vec2":case "vec3":case "vec4":d=1;switch(c.name){case "vec2":d=2;break;case "vec3":d=3;break;case "vec4":d=4}d=new Float32Array(d);if(a.length)for(c=0;c<a.length&&c<d.length;c++)d[c]=a[c];else d[0]=parseFloat(a)}this.setOutputData(b,d)}}};h.prototype.onGetOutputs=function(){return[["number","number"],["vec2",
|
||||
"vec2"],["vec3","vec3"],["vec4","vec4"]]};v.registerNodeType("math/converter",h);d.title="Bypass";d.desc="removes the type";d.prototype.onExecute=function(){var a=this.getInputData(0);this.setOutputData(0,a)};v.registerNodeType("math/bypass",d);q.title="Range";q.desc="Convert a number from one range to another";q.prototype.getTitle=function(){return this.flags.collapsed?(this._last_v||0).toFixed(2):this.title};q.prototype.onExecute=function(){if(this.inputs)for(var a=0;a<this.inputs.length;a++){var b=
|
||||
this.inputs[a],c=this.getInputData(a);void 0!==c&&(this.properties[b.name]=c)}c=this.properties["in"];if(void 0===c||null===c||c.constructor!==Number)c=0;a=this.properties.in_min;b=this.properties.out_min;this._last_v=(c-a)/(this.properties.in_max-a)*(this.properties.out_max-b)+b;this.setOutputData(0,this._last_v)};q.prototype.onDrawBackground=function(a){this.outputs[0].label=this._last_v?this._last_v.toFixed(3):"?"};q.prototype.onGetInputs=function(){return[["in_min","number"],["in_max","number"],
|
||||
["out_min","number"],["out_max","number"]]};v.registerNodeType("math/range",q);g.title="Rand";g.desc="Random number";g.prototype.onExecute=function(){if(this.inputs)for(var a=0;a<this.inputs.length;a++){var b=this.inputs[a],c=this.getInputData(a);void 0!==c&&(this.properties[b.name]=c)}a=this.properties.min;b=this.properties.max;this._last_v=Math.random()*(b-a)+a;this.setOutputData(0,this._last_v)};g.prototype.onDrawBackground=function(a){this.outputs[0].label=this._last_v?this._last_v.toFixed(3):
|
||||
"?"};g.prototype.onGetInputs=function(){return[["min","number"],["max","number"]]};v.registerNodeType("math/rand",g);r.title="Clamp";r.desc="Clamp number between min and max";r.filter="shader";r.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(a=Math.max(this.properties.min,a),a=Math.min(this.properties.max,a),this.setOutputData(0,a))};r.prototype.getCode=function(a){a="";this.isInputConnected(0)&&(a+="clamp({{0}},"+this.properties.min+","+this.properties.max+")");return a};v.registerNodeType("math/clamp",
|
||||
r);p.title="Lerp";p.desc="Linear Interpolation";p.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=this.getInputData(1);null==b&&(b=0);var c=this.properties.f,e=this.getInputData(2);void 0!==e&&(c=e);this.setOutputData(0,a*(1-c)+b*c)};p.prototype.onGetInputs=function(){return[["f","number"]]};v.registerNodeType("math/lerp",p);s.title="Abs";s.desc="Absolute";s.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,Math.abs(a))};v.registerNodeType("math/abs",
|
||||
r);p.title="Lerp";p.desc="Linear Interpolation";p.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=this.getInputData(1);null==b&&(b=0);var c=this.properties.f,d=this.getInputData(2);void 0!==d&&(c=d);this.setOutputData(0,a*(1-c)+b*c)};p.prototype.onGetInputs=function(){return[["f","number"]]};v.registerNodeType("math/lerp",p);s.title="Abs";s.desc="Absolute";s.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,Math.abs(a))};v.registerNodeType("math/abs",
|
||||
s);u.title="Floor";u.desc="Floor number to remove fractional part";u.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,Math.floor(a))};v.registerNodeType("math/floor",u);k.title="Frac";k.desc="Returns fractional part";k.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a%1)};v.registerNodeType("math/frac",k);m.title="Smoothstep";m.desc="Smoothstep";m.prototype.onExecute=function(){var a=this.getInputData(0);if(void 0!==a){var b=
|
||||
this.properties.A,a=Math.clamp((a-b)/(this.properties.B-b),0,1);this.setOutputData(0,a*a*(3-2*a))}};v.registerNodeType("math/smoothstep",m);c.title="Scale";c.desc="v * factor";c.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&this.setOutputData(0,a*this.properties.factor)};v.registerNodeType("math/scale",c);a.title="Average";a.desc="Average Filter";a.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=this._values.length;this._values[this._current%b]=
|
||||
a;this._current+=1;this._current>b&&(this._current=0);for(var c=a=0;c<b;++c)a+=this._values[c];this.setOutputData(0,a/b)};a.prototype.onPropertyChanged=function(a,b){1>b&&(b=1);this.properties.samples=Math.round(b);var c=this._values;this._values=new Float32Array(this.properties.samples);c.length<=this._values.length?this._values.set(c):this._values.set(c.subarray(0,this._values.length))};v.registerNodeType("math/average",a);b.title="TendTo";b.desc="moves the output value always closer to the input";
|
||||
b.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=0);var b=this.properties.factor;this._value=null==this._value?a:this._value*(1-b)+a*b;this.setOutputData(0,this._value)};v.registerNodeType("math/tendTo",b);f.values="+-*/%^".split("");f.title="Operation";f.desc="Easy math operators";f["@OP"]={type:"enum",title:"operation",values:f.values};f.prototype.getTitle=function(){return"A "+this.properties.OP+" B"};f.prototype.setValue=function(a){"string"==typeof a&&(a=parseFloat(a));
|
||||
this.properties.value=a};f.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1);null!=a?this.properties.A=a:a=this.properties.A;null!=b?this.properties.B=b:b=this.properties.B;var c=0;switch(this.properties.OP){case "+":c=a+b;break;case "-":c=a-b;break;case "x":case "X":case "*":c=a*b;break;case "/":c=a/b;break;case "%":c=a%b;break;case "^":c=Math.pow(a,b);break;default:console.warn("Unknown operation: "+this.properties.OP)}this.setOutputData(0,c)};f.prototype.onDrawBackground=
|
||||
function(a){this.flags.collapsed||(a.font="40px Arial",a.fillStyle="#CCC",a.textAlign="center",a.fillText(this.properties.OP,0.5*this.size[0],0.35*this.size[1]+v.NODE_TITLE_HEIGHT),a.textAlign="left")};v.registerNodeType("math/operation",f);w.title="Compare";w.desc="compares between two values";w.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1);void 0!==a?this.properties.A=a:a=this.properties.A;void 0!==b?this.properties.B=b:b=this.properties.B;for(var c=0,e=this.outputs.length;c<
|
||||
e;++c){var f=this.outputs[c];if(f.links&&f.links.length){switch(f.name){case "A==B":value=a==b;break;case "A!=B":value=a!=b;break;case "A>B":value=a>b;break;case "A<B":value=a<b;break;case "A<=B":value=a<=b;break;case "A>=B":value=a>=b}this.setOutputData(c,value)}}};w.prototype.onGetOutputs=function(){return[["A==B","boolean"],["A!=B","boolean"],["A>B","boolean"],["A<B","boolean"],["A>=B","boolean"],["A<=B","boolean"]]};v.registerNodeType("math/compare",w);e.values="> < == != <= >=".split(" ");e["@OP"]=
|
||||
function(a){this.flags.collapsed||(a.font="40px Arial",a.fillStyle="#CCC",a.textAlign="center",a.fillText(this.properties.OP,0.5*this.size[0],0.35*this.size[1]+v.NODE_TITLE_HEIGHT),a.textAlign="left")};v.registerNodeType("math/operation",f);w.title="Compare";w.desc="compares between two values";w.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1);void 0!==a?this.properties.A=a:a=this.properties.A;void 0!==b?this.properties.B=b:b=this.properties.B;for(var c=0,d=this.outputs.length;c<
|
||||
d;++c){var e=this.outputs[c];if(e.links&&e.links.length){switch(e.name){case "A==B":value=a==b;break;case "A!=B":value=a!=b;break;case "A>B":value=a>b;break;case "A<B":value=a<b;break;case "A<=B":value=a<=b;break;case "A>=B":value=a>=b}this.setOutputData(c,value)}}};w.prototype.onGetOutputs=function(){return[["A==B","boolean"],["A!=B","boolean"],["A>B","boolean"],["A<B","boolean"],["A>=B","boolean"],["A<=B","boolean"]]};v.registerNodeType("math/compare",w);e.values="> < == != <= >=".split(" ");e["@OP"]=
|
||||
{type:"enum",title:"operation",values:e.values};e.title="Condition";e.desc="evaluates condition between A and B";e.prototype.onExecute=function(){var a=this.getInputData(0);void 0===a?a=this.properties.A:this.properties.A=a;var b=this.getInputData(1);void 0===b?b=this.properties.B:this.properties.B=b;var c=!0;switch(this.properties.OP){case ">":c=a>b;break;case "<":c=a<b;break;case "==":c=a==b;break;case "!=":c=a!=b;break;case "<=":c=a<=b;break;case ">=":c=a>=b}this.setOutputData(0,c)};v.registerNodeType("math/condition",
|
||||
e);l.title="Accumulate";l.desc="Increments a value every time";l.prototype.onExecute=function(){null===this.properties.value&&(this.properties.value=0);var a=this.getInputData(0);this.properties.value=null!==a?this.properties.value+a:this.properties.value+this.properties.increment;this.setOutputData(0,this.properties.value)};v.registerNodeType("math/accumulate",l);n.title="Trigonometry";n.desc="Sin Cos Tan";n.filter="shader";n.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=
|
||||
0);var b=this.properties.amplitude,c=this.findInputSlot("amplitude");-1!=c&&(b=this.getInputData(c));var e=this.properties.offset,c=this.findInputSlot("offset");-1!=c&&(e=this.getInputData(c));for(var c=0,f=this.outputs.length;c<f;++c){switch(this.outputs[c].name){case "sin":value=Math.sin(a);break;case "cos":value=Math.cos(a);break;case "tan":value=Math.tan(a);break;case "asin":value=Math.asin(a);break;case "acos":value=Math.acos(a);break;case "atan":value=Math.atan(a)}this.setOutputData(c,b*value+
|
||||
e)}};n.prototype.onGetInputs=function(){return[["v","number"],["amplitude","number"],["offset","number"]]};n.prototype.onGetOutputs=function(){return[["sin","number"],["cos","number"],["tan","number"],["asin","number"],["acos","number"],["atan","number"]]};v.registerNodeType("math/trigonometry",n);if(void 0!=typeof math){var z=function(){this.addInputs("x","number");this.addInputs("y","number");this.addOutputs("","number");this.properties={x:1,y:1,formula:"x+y"}};z.title="Formula";z.desc="Compute safe formula";
|
||||
0);var b=this.properties.amplitude,c=this.findInputSlot("amplitude");-1!=c&&(b=this.getInputData(c));var d=this.properties.offset,c=this.findInputSlot("offset");-1!=c&&(d=this.getInputData(c));for(var c=0,e=this.outputs.length;c<e;++c){switch(this.outputs[c].name){case "sin":value=Math.sin(a);break;case "cos":value=Math.cos(a);break;case "tan":value=Math.tan(a);break;case "asin":value=Math.asin(a);break;case "acos":value=Math.acos(a);break;case "atan":value=Math.atan(a)}this.setOutputData(c,b*value+
|
||||
d)}};n.prototype.onGetInputs=function(){return[["v","number"],["amplitude","number"],["offset","number"]]};n.prototype.onGetOutputs=function(){return[["sin","number"],["cos","number"],["tan","number"],["asin","number"],["acos","number"],["atan","number"]]};v.registerNodeType("math/trigonometry",n);if(void 0!=typeof math){var z=function(){this.addInputs("x","number");this.addInputs("y","number");this.addOutputs("","number");this.properties={x:1,y:1,formula:"x+y"}};z.title="Formula";z.desc="Compute safe formula";
|
||||
z.prototype.onExecute=function(){var a=this.getInputData(0),b=this.getInputData(1);null!=a?this.properties.x=a:a=this.properties.x;null!=b?this.properties.y=b:b=this.properties.y;a=math.eval(this.properties.formula,{x:a,y:b,T:this.graph.globaltime});this.setOutputData(0,a)};z.prototype.onDrawBackground=function(){this.outputs[0].label=this.properties.formula};z.prototype.onGetOutputs=function(){return[["A-B","number"],["A*B","number"],["A/B","number"]]};v.registerNodeType("math/formula",z)}C.title=
|
||||
"Vec2->XY";C.desc="vector 2 to components";C.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]))};v.registerNodeType("math3d/vec2-to-xyz",C);y.title="XY->Vec2";y.desc="components to vector2";y.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var c=this._data;c[0]=a;c[1]=b;this.setOutputData(0,c)};v.registerNodeType("math3d/xy-to-vec2",
|
||||
y);x.title="Vec3->XYZ";x.desc="vector 3 to components";x.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]),this.setOutputData(2,a[2]))};v.registerNodeType("math3d/vec3-to-xyz",x);A.title="XYZ->Vec3";A.desc="components to vector3";A.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var c=this.getInputData(2);null==c&&(c=this.properties.z);
|
||||
var e=this._data;e[0]=a;e[1]=b;e[2]=c;this.setOutputData(0,e)};v.registerNodeType("math3d/xyz-to-vec3",A);D.title="Vec4->XYZW";D.desc="vector 4 to components";D.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]),this.setOutputData(2,a[2]),this.setOutputData(3,a[3]))};v.registerNodeType("math3d/vec4-to-xyzw",D);B.title="XYZW->Vec4";B.desc="components to vector4";B.prototype.onExecute=function(){var a=this.getInputData(0);null==
|
||||
a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var c=this.getInputData(2);null==c&&(c=this.properties.z);var e=this.getInputData(3);null==e&&(e=this.properties.w);var f=this._data;f[0]=a;f[1]=b;f[2]=c;f[3]=e;this.setOutputData(0,f)};v.registerNodeType("math3d/xyzw-to-vec4",B);t.glMatrix&&(t=function(){this.addOutput("quat","quat");this.properties={x:0,y:0,z:0,w:1};this._value=quat.create()},t.title="Quaternion",t.desc="quaternion",t.prototype.onExecute=function(){this._value[0]=
|
||||
var d=this._data;d[0]=a;d[1]=b;d[2]=c;this.setOutputData(0,d)};v.registerNodeType("math3d/xyz-to-vec3",A);D.title="Vec4->XYZW";D.desc="vector 4 to components";D.prototype.onExecute=function(){var a=this.getInputData(0);null!=a&&(this.setOutputData(0,a[0]),this.setOutputData(1,a[1]),this.setOutputData(2,a[2]),this.setOutputData(3,a[3]))};v.registerNodeType("math3d/vec4-to-xyzw",D);B.title="XYZW->Vec4";B.desc="components to vector4";B.prototype.onExecute=function(){var a=this.getInputData(0);null==
|
||||
a&&(a=this.properties.x);var b=this.getInputData(1);null==b&&(b=this.properties.y);var c=this.getInputData(2);null==c&&(c=this.properties.z);var d=this.getInputData(3);null==d&&(d=this.properties.w);var e=this._data;e[0]=a;e[1]=b;e[2]=c;e[3]=d;this.setOutputData(0,e)};v.registerNodeType("math3d/xyzw-to-vec4",B);t.glMatrix&&(t=function(){this.addOutput("quat","quat");this.properties={x:0,y:0,z:0,w:1};this._value=quat.create()},t.title="Quaternion",t.desc="quaternion",t.prototype.onExecute=function(){this._value[0]=
|
||||
this.properties.x;this._value[1]=this.properties.y;this._value[2]=this.properties.z;this._value[3]=this.properties.w;this.setOutputData(0,this._value)},v.registerNodeType("math3d/quaternion",t),t=function(){this.addInputs([["degrees","number"],["axis","vec3"]]);this.addOutput("quat","quat");this.properties={angle:90,axis:vec3.fromValues(0,1,0)};this._value=quat.create()},t.title="Rotation",t.desc="quaternion rotation",t.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.angle);
|
||||
var b=this.getInputData(1);null==b&&(b=this.properties.axis);a=quat.setAxisAngle(this._value,b,0.0174532925*a);this.setOutputData(0,a)},v.registerNodeType("math3d/rotation",t),t=function(){this.addInputs([["vec3","vec3"],["quat","quat"]]);this.addOutput("result","vec3");this.properties={vec:[0,0,1]}},t.title="Rot. Vec3",t.desc="rotate a point",t.prototype.onExecute=function(){var a=this.getInputData(0);null==a&&(a=this.properties.vec);var b=this.getInputData(1);null==b?this.setOutputData(a):this.setOutputData(0,
|
||||
vec3.transformQuat(vec3.create(),a,b))},v.registerNodeType("math3d/rotate_vec3",t),t=function(){this.addInputs([["A","quat"],["B","quat"]]);this.addOutput("A*B","quat");this._value=quat.create()},t.title="Mult. Quat",t.desc="rotate quaternion",t.prototype.onExecute=function(){var a=this.getInputData(0);if(null!=a){var b=this.getInputData(1);null!=b&&(a=quat.multiply(this._value,a,b),this.setOutputData(0,a))}},v.registerNodeType("math3d/mult-quat",t),t=function(){this.addInputs([["A","quat"],["B",
|
||||
|
||||
@@ -41,6 +41,7 @@ var LiteGraph = global.LiteGraph = {
|
||||
NODE_DEFAULT_BGCOLOR: "#444",
|
||||
NODE_DEFAULT_BOXCOLOR: "#666",
|
||||
NODE_DEFAULT_SHAPE: "box",
|
||||
DEFAULT_SHADOW_COLOR: "rgba(0,0,0,0.5)",
|
||||
|
||||
LINK_COLOR: "#AAD",
|
||||
EVENT_LINK_COLOR: "#F85",
|
||||
@@ -5248,16 +5249,12 @@ LGraphCanvas.prototype.drawNode = function(node, ctx )
|
||||
return;
|
||||
}
|
||||
|
||||
//custom draw collapsed method
|
||||
if(node.flags.collapsed && node.onDrawCollaped && node.onDrawCollapsed(ctx, this) == true)
|
||||
return;
|
||||
|
||||
var editor_alpha = this.editor_alpha;
|
||||
ctx.globalAlpha = editor_alpha;
|
||||
|
||||
if(this.render_shadows)
|
||||
{
|
||||
ctx.shadowColor = "rgba(0,0,0,0.5)";
|
||||
ctx.shadowColor = LiteGraph.DEFAULT_SHADOW_COLOR;
|
||||
ctx.shadowOffsetX = 2 * this.scale;
|
||||
ctx.shadowOffsetY = 2 * this.scale;
|
||||
ctx.shadowBlur = 3 * this.scale;
|
||||
@@ -5265,6 +5262,10 @@ LGraphCanvas.prototype.drawNode = function(node, ctx )
|
||||
else
|
||||
ctx.shadowColor = "transparent";
|
||||
|
||||
//custom draw collapsed method (draw after shadows because they are affected)
|
||||
if(node.flags.collapsed && node.onDrawCollaped && node.onDrawCollapsed(ctx, this) == true)
|
||||
return;
|
||||
|
||||
//clip if required (mask)
|
||||
var shape = node._shape || LiteGraph.BOX_SHAPE;
|
||||
var size = temp_vec2;
|
||||
@@ -5562,6 +5563,9 @@ LGraphCanvas.prototype.drawNodeShape = function( node, ctx, size, fgcolor, bgcol
|
||||
//title bar
|
||||
if(title_mode != LiteGraph.TRANSPARENT_TITLE) //!node.flags.collapsed)
|
||||
{
|
||||
if(node.flags.collapsed)
|
||||
ctx.shadowColor = LiteGraph.DEFAULT_SHADOW_COLOR;
|
||||
|
||||
//* gradient test
|
||||
if(this.use_gradients)
|
||||
{
|
||||
@@ -5591,15 +5595,7 @@ LGraphCanvas.prototype.drawNodeShape = function( node, ctx, size, fgcolor, bgcol
|
||||
ctx.roundRect(0,-title_height,size[0]+1, title_height, this.round_radius, node.flags.collapsed ? this.round_radius : 0);
|
||||
ctx.fill();
|
||||
}
|
||||
|
||||
/*
|
||||
else if (shape == LiteGraph.CIRCLE_SHAPE)
|
||||
{
|
||||
ctx.beginPath();
|
||||
ctx.arc(title_height *0.5, title_height * -0.5, (title_height - 6) *0.5,0,Math.PI*2);
|
||||
ctx.fill();
|
||||
}
|
||||
*/
|
||||
ctx.shadowColor = "transparent";
|
||||
}
|
||||
|
||||
//title box
|
||||
@@ -6024,7 +6020,8 @@ LGraphCanvas.prototype.drawNodeWidgets = function( node, posY, ctx, active_widge
|
||||
ctx.fill();
|
||||
ctx.stroke();
|
||||
ctx.fillStyle = "#999";
|
||||
ctx.fillText( w.title || "Value", 20, y + H*0.7 );
|
||||
if(w.name != null)
|
||||
ctx.fillText( w.name, 20, y + H*0.7 );
|
||||
ctx.fillStyle = "#DDD";
|
||||
ctx.textAlign = "right";
|
||||
ctx.fillText( w.value, width - 20, y + H*0.7 );
|
||||
|
||||
Reference in New Issue
Block a user