From 9fbedb3e1162e37c4a21938260d829f296ceadc6 Mon Sep 17 00:00:00 2001 From: tamat Date: Wed, 4 Jul 2018 23:13:50 +0200 Subject: [PATCH] added searchbox --- build/litegraph.js | 366 ++++++++++++++++++++++++++++++++++------- build/litegraph.min.js | 331 ++++++++++++++++++------------------- css/litegraph.css | 10 ++ src/litegraph.js | 346 +++++++++++++++++++++++++++++++------- src/nodes/base.js | 17 +- src/nodes/interface.js | 3 + 6 files changed, 788 insertions(+), 285 deletions(-) diff --git a/build/litegraph.js b/build/litegraph.js index aa1ee51ed2..18b656df46 100644 --- a/build/litegraph.js +++ b/build/litegraph.js @@ -385,14 +385,18 @@ else * * @class LGraph * @constructor +* @param {Object} o data from previous serialization [optional] */ -function LGraph() +function LGraph( o ) { if (LiteGraph.debug) console.log("Graph created"); this.list_of_graphcanvas = null; this.clear(); + + if(o) + this.configure(o); } global.LGraph = LiteGraph.LGraph = LGraph; @@ -415,7 +419,11 @@ LGraph.prototype.clear = function() { this.stop(); this.status = LGraph.STATUS_STOPPED; + this.last_node_id = 0; + this.last_link_id = 0; + + this._version = -1; //used to detect changes //nodes this._nodes = []; @@ -424,14 +432,13 @@ LGraph.prototype.clear = function() this._nodes_executable = null; //nodes that contain onExecute //links - this.last_link_id = 0; this.links = {}; //container with all the links //iterations this.iteration = 0; - this.config = { - }; + //custom data + this.config = {}; //timing this.globaltime = 0; @@ -448,9 +455,7 @@ LGraph.prototype.clear = function() this.global_inputs = {}; this.global_outputs = {}; - //this.graph = {}; - this.debug = true; - + //notify canvas to redraw this.change(); this.sendActionToCanvas("clear"); @@ -480,7 +485,6 @@ LGraph.prototype.attachCanvas = function(graphcanvas) * @method detachCanvas * @param {GraphCanvas} graph_canvas */ - LGraph.prototype.detachCanvas = function(graphcanvas) { if(!this.list_of_graphcanvas) @@ -903,17 +907,13 @@ LGraph.prototype.add = function(node, skip_compute_order) else if (this.last_node_id < node.id) this.last_node_id = node.id; + node.graph = this; + this._version++; this._nodes.push(node); this._nodes_by_id[node.id] = node; - /* - // rendering stuf... - if(node.bgImageUrl) - node.bgImage = node.loadImage(node.bgImageUrl); - */ - if(node.onAdded) node.onAdded( this ); @@ -973,6 +973,7 @@ LGraph.prototype.remove = function(node) node.onRemoved(); node.graph = null; + this._version++; //remove from canvas render if(this.list_of_graphcanvas) @@ -1097,6 +1098,7 @@ LGraph.prototype.getNodeOnPos = function(x,y, nodes_list) LGraph.prototype.addGlobalInput = function(name, type, value) { this.global_inputs[name] = { name: name, type: type, value: value }; + this._version++; if(this.onGlobalInputAdded) this.onGlobalInputAdded(name, type); @@ -1164,6 +1166,7 @@ LGraph.prototype.renameGlobalInput = function(old_name, name) this.global_inputs[name] = this.global_inputs[old_name]; delete this.global_inputs[old_name]; + this._version++; if(this.onGlobalInputRenamed) this.onGlobalInputRenamed(old_name, name); @@ -1183,10 +1186,11 @@ LGraph.prototype.changeGlobalInputType = function(name, type) if(!this.global_inputs[name]) return false; - if(this.global_inputs[name].type.toLowerCase() == type.toLowerCase() ) + if(this.global_inputs[name].type == type || this.global_inputs[name].type.toLowerCase() == type.toLowerCase() ) return; this.global_inputs[name].type = type; + this._version++; if(this.onGlobalInputTypeChanged) this.onGlobalInputTypeChanged(name, type); } @@ -1203,6 +1207,7 @@ LGraph.prototype.removeGlobalInput = function(name) return false; delete this.global_inputs[name]; + this._version++; if(this.onGlobalInputRemoved) this.onGlobalInputRemoved(name); @@ -1222,6 +1227,7 @@ LGraph.prototype.removeGlobalInput = function(name) LGraph.prototype.addGlobalOutput = function(name, type, value) { this.global_outputs[name] = { name: name, type: type, value: value }; + this._version++; if(this.onGlobalOutputAdded) this.onGlobalOutputAdded(name, type); @@ -1286,6 +1292,7 @@ LGraph.prototype.renameGlobalOutput = function(old_name, name) this.global_outputs[name] = this.global_outputs[old_name]; delete this.global_outputs[old_name]; + this._version++; if(this.onGlobalOutputRenamed) this.onGlobalOutputRenamed(old_name, name); @@ -1309,6 +1316,7 @@ LGraph.prototype.changeGlobalOutputType = function(name, type) return; this.global_outputs[name].type = type; + this._version++; if(this.onGlobalOutputTypeChanged) this.onGlobalOutputTypeChanged(name, type); } @@ -1323,6 +1331,7 @@ LGraph.prototype.removeGlobalOutput = function(name) if(!this.global_outputs[name]) return false; delete this.global_outputs[name]; + this._version++; if(this.onGlobalOutputRemoved) this.onGlobalOutputRemoved(name); @@ -1352,6 +1361,7 @@ LGraph.prototype.connectionChange = function( node ) this.updateExecutionOrder(); if( this.onConnectionChange ) this.onConnectionChange( node ); + this._version++; this.sendActionToCanvas("onConnectionChange"); } @@ -1374,14 +1384,12 @@ LGraph.prototype.isLive = function() return false; } -/* Called when something visually changed */ +/* Called when something visually changed (not the graph!) */ LGraph.prototype.change = function() { if(LiteGraph.debug) console.log("Graph changed"); - this.sendActionToCanvas("setDirty",[true,true]); - if(this.on_change) this.on_change(this); } @@ -1412,13 +1420,11 @@ LGraph.prototype.serialize = function() } var data = { - iteration: this.iteration, - frame: this.frame, last_node_id: this.last_node_id, last_link_id: this.last_link_id, - links: links, //LiteGraph.cloneObject( this.links ), + nodes: nodes_info, + links: links, config: this.config, - nodes: nodes_info }; return data; @@ -1429,9 +1435,13 @@ LGraph.prototype.serialize = function() * Configure a graph from a JSON string * @method configure * @param {String} str configure a graph from a JSON string +* @param {Boolean} returns if there was any error parsing */ -LGraph.prototype.configure = function(data, keep_old) +LGraph.prototype.configure = function( data, keep_old ) { + if(!data) + return; + if(!keep_old) this.clear(); @@ -1440,7 +1450,7 @@ LGraph.prototype.configure = function(data, keep_old) //decode links info (they are very verbose) if(data.links && data.links.constructor === Array) { - var links = {}; + var links = []; for(var i = 0; i < data.links.length; ++i) { var link = data.links[i]; @@ -1457,32 +1467,36 @@ LGraph.prototype.configure = function(data, keep_old) //create nodes this._nodes = []; - for(var i = 0, l = nodes.length; i < l; ++i) + if(nodes) { - var n_info = nodes[i]; //stored info - var node = LiteGraph.createNode( n_info.type, n_info.title ); - if(!node) + for(var i = 0, l = nodes.length; i < l; ++i) { - if(LiteGraph.debug) - console.log("Node not found: " + n_info.type); - error = true; - continue; + var n_info = nodes[i]; //stored info + var node = LiteGraph.createNode( n_info.type, n_info.title ); + if(!node) + { + if(LiteGraph.debug) + console.log("Node not found: " + n_info.type); + error = true; + continue; + } + + node.id = n_info.id; //id it or it will create a new id + this.add(node, true); //add before configure, otherwise configure cannot create links } - node.id = n_info.id; //id it or it will create a new id - this.add(node, true); //add before configure, otherwise configure cannot create links - } - - //configure nodes afterwards so they can reach each other - for(var i = 0, l = nodes.length; i < l; ++i) - { - var n_info = nodes[i]; - var node = this.getNodeById( n_info.id ); - if(node) - node.configure( n_info ); + //configure nodes afterwards so they can reach each other + for(var i = 0, l = nodes.length; i < l; ++i) + { + var n_info = nodes[i]; + var node = this.getNodeById( n_info.id ); + if(node) + node.configure( n_info ); + } } this.updateExecutionOrder(); + this._version++; this.setDirtyCanvas(true,true); return error; } @@ -1618,6 +1632,9 @@ LGraphNode.prototype._ctor = function( title ) */ LGraphNode.prototype.configure = function(info) { + if(this.graph) + this.graph._version++; + for (var j in info) { if(j == "console") @@ -1658,7 +1675,7 @@ LGraphNode.prototype.configure = function(info) for(var i = 0; i < this.inputs.length; ++i) { var input = this.inputs[i]; - var link_info = this.graph.links[ input.link ]; + var link_info = this.graph ? this.graph.links[ input.link ] : null; this.onConnectionsChange( LiteGraph.INPUT, i, true, link_info, input ); //link_info has been created now, so its updated } @@ -1670,7 +1687,7 @@ LGraphNode.prototype.configure = function(info) continue; for(var j = 0; j < output.links.length; ++j) { - var link_info = this.graph.links[ output.links[j] ]; + var link_info = this.graph ? this.graph.links[ output.links[j] ] : null; this.onConnectionsChange( LiteGraph.OUTPUT, i, true, link_info, output ); //link_info has been created now, so its updated } } @@ -1686,6 +1703,7 @@ LGraphNode.prototype.configure = function(info) if(typeof(link) != "object") continue; input.link = link[0]; + if(this.graph) this.graph.links[ link[0] ] = { id: link[0], origin_id: link[1], @@ -2360,6 +2378,9 @@ LGraphNode.prototype.computeSize = function( minHeight, out ) size[0] = Math.max( input_width + output_width + 10, title_width ); size[0] = Math.max( size[0], LiteGraph.NODE_WIDTH ); + if(this.onResize) + this.onResize(size); + function compute_text_size( text ) { if(!text) @@ -2577,7 +2598,8 @@ LGraphNode.prototype.connect = function( slot, target_node, target_slot ) output.links.push( link_info.id ); //connect in input target_node.inputs[target_slot].link = link_info.id; - + if(this.graph) + this.graph._version++; if(this.onConnectionsChange) this.onConnectionsChange( LiteGraph.OUTPUT, slot, true, link_info, output ); //link_info has been created now, so its updated if(target_node.onConnectionsChange) @@ -2641,6 +2663,8 @@ LGraphNode.prototype.disconnectOutput = function( slot, target_node ) var input = target_node.inputs[ link_info.target_slot ]; input.link = null; //remove there delete this.graph.links[ link_id ]; //remove the link from the links pool + if(this.graph) + this.graph._version++; if(target_node.onConnectionsChange) target_node.onConnectionsChange( LiteGraph.INPUT, link_info.target_slot, false, link_info, input ); //link_info hasnt been modified so its ok if(this.onConnectionsChange) @@ -2660,6 +2684,8 @@ LGraphNode.prototype.disconnectOutput = function( slot, target_node ) var target_node = this.graph.getNodeById( link_info.target_id ); var input = null; + if(this.graph) + this.graph._version++; if(target_node) { input = target_node.inputs[ link_info.target_slot ]; @@ -2736,7 +2762,8 @@ LGraphNode.prototype.disconnectInput = function( slot ) } delete this.graph.links[ link_id ]; //remove from the pool - + if(this.graph) + this.graph._version++; if( this.onConnectionsChange ) this.onConnectionsChange( LiteGraph.INPUT, slot, false, link_info, input ); if( target_node.onConnectionsChange ) @@ -2763,7 +2790,6 @@ LGraphNode.prototype.getConnectionPos = function(is_input, slot_number) return [this.pos[0], this.pos[1] - LiteGraph.NODE_TITLE_HEIGHT * 0.5]; else return [this.pos[0] + LiteGraph.NODE_COLLAPSED_WIDTH, this.pos[1] - LiteGraph.NODE_TITLE_HEIGHT * 0.5]; - //return [this.pos[0] + this.size[0] * 0.5, this.pos[1] + this.size[1] * 0.5]; } if(is_input && slot_number == -1) @@ -2888,6 +2914,7 @@ LGraphNode.prototype.captureInput = function(v) **/ LGraphNode.prototype.collapse = function() { + this.graph._version++; if(!this.flags.collapsed) this.flags.collapsed = true; else @@ -2902,6 +2929,7 @@ LGraphNode.prototype.collapse = function() LGraphNode.prototype.pin = function(v) { + this.graph._version++; if(v === undefined) this.flags.pinned = !this.flags.pinned; else @@ -2968,6 +2996,7 @@ function LGraphCanvas( canvas, graph, options ) this.allow_dragcanvas = true; this.allow_dragnodes = true; this.allow_interaction = true; //allow to control widgets, buttons, collapse, etc + this.allow_searchbox = true; this.drag_mode = false; this.dragging_rectangle = null; @@ -2978,8 +3007,20 @@ function LGraphCanvas( canvas, graph, options ) this.render_curved_connections = true; this.render_connection_arrows = true; + //to personalize the search box + this.onSearchBox = null; + this.onSearchBoxSelection = null; + this.connections_width = 3; + this.gui_mouse = { + node: null, + blocked: false, + position: [0,0], + click: false + }; + this.current_node = null; + //link canvas and graph if(graph) graph.attachCanvas(this); @@ -3432,6 +3473,7 @@ LGraphCanvas.prototype.processMouseDown = function(e) var ref_window = this.getCanvasWindow(); var document = ref_window.document; LGraphCanvas.active_canvas = this; + var that = this; //move mouse move event to the window in case it drags outside of the canvas this.canvas.removeEventListener("mousemove", this._mousemove_callback ); @@ -3441,6 +3483,7 @@ LGraphCanvas.prototype.processMouseDown = function(e) var n = this.graph.getNodeOnPos( e.canvasX, e.canvasY, this.visible_nodes ); var skip_dragging = false; var skip_action = false; + var now = LiteGraph.getTime(); LiteGraph.closeAllContextMenus( ref_window ); @@ -3524,8 +3567,16 @@ LGraphCanvas.prototype.processMouseDown = function(e) { var block_drag_node = false; + //widgets + this.gui_mouse.node = n; + this.gui_mouse.position[0] = e.canvasX - n.pos[0]; + this.gui_mouse.position[1] = e.canvasY - n.pos[1]; + this.gui_mouse.clicked = true; + + if( this.gui_mouse.blocked ) + block_drag_node = true; + //double clicking - var now = LiteGraph.getTime(); if ((now - this.last_mouseclick) < 300 && this.selected_nodes[n.id]) { //double click node @@ -3557,8 +3608,12 @@ LGraphCanvas.prototype.processMouseDown = function(e) this.dirty_canvas = true; } } - else + else //clicked outside of nodes + { clicking_canvas_bg = true; + if ( (now - this.last_mouseclick) < 300 && this.allow_searchbox ) + setTimeout( function(){ that.showSearchBox(e); },10 ); + } if(!skip_action && clicking_canvas_bg && this.allow_dragcanvas) { @@ -4464,6 +4519,7 @@ LGraphCanvas.prototype.drawFrontCanvas = function() ctx.start2D(); var canvas = this.canvas; + this.gui_mouse.blocked = false; //reset in case of error ctx.restore(); @@ -4579,6 +4635,8 @@ LGraphCanvas.prototype.drawFrontCanvas = function() ctx.finish2D(); this.dirty_canvas = false; + this.gui_mouse.node = null; + this.gui_mouse.clicked = false; } LGraphCanvas.prototype.renderInfo = function( ctx, x, y ) @@ -4595,7 +4653,7 @@ LGraphCanvas.prototype.renderInfo = function( ctx, x, y ) { ctx.fillText( "T: " + this.graph.globaltime.toFixed(2)+"s",5,13*1 ); ctx.fillText( "I: " + this.graph.iteration,5,13*2 ); - ctx.fillText( "F: " + this.frame,5,13*3 ); + ctx.fillText( "V: " + this.graph._version,5,13*3 ); ctx.fillText( "FPS:" + this.fps.toFixed(2),5,13*4 ); } else @@ -4727,6 +4785,7 @@ var temp_vec2 = new Float32Array(2); LGraphCanvas.prototype.drawNode = function(node, ctx ) { var glow = false; + this.current_node = node; var color = node.color || LiteGraph.NODE_DEFAULT_COLOR; //if (this.selected) color = "#88F"; @@ -4765,10 +4824,8 @@ LGraphCanvas.prototype.drawNode = function(node, ctx ) if(!node.flags.collapsed) { ctx.shadowColor = "transparent"; - //if(node.onDrawBackground) - // node.onDrawBackground(ctx); if(node.onDrawForeground) - node.onDrawForeground(ctx); + node.onDrawForeground(ctx, this); } return; @@ -4921,7 +4978,7 @@ LGraphCanvas.prototype.drawNode = function(node, ctx ) ctx.globalAlpha = 1; if(node.onDrawForeground) - node.onDrawForeground(ctx); + node.onDrawForeground( ctx, this ); }//!collapsed if(node.flags.clip_area) @@ -4986,8 +5043,8 @@ LGraphCanvas.prototype.drawNodeShape = function(node, ctx, size, fgcolor, bgcolo if(node.bgImageUrl && !node.bgImage) node.bgImage = node.loadImage(node.bgImageUrl); - if(node.onDrawBackground) - node.onDrawBackground(ctx); + if( node.onDrawBackground ) + node.onDrawBackground( ctx, this ); //title bg (remember, it is rendered ABOVE the node if(!no_title) @@ -5261,6 +5318,30 @@ LGraphCanvas.prototype.computeConnectionPoint = function(a,b,t) return [x,y]; } +LGraphCanvas.prototype.guiButton = function( ctx, rect, text, callback ) +{ + var mouse = this.gui_mouse; + + var mouse_over = mouse.position[0] >= rect[0] && mouse.position[1] >= rect[1] && mouse.position[0] < rect[0] + rect[2] && mouse.position[1] < rect[1] + rect[3]; + //if(mouse_over) this.setDirty(true,false); + var clicked = mouse.node == this.current_node && mouse.clicked && mouse_over; + + ctx.fillStyle = clicked ? "#AAA" : ( mouse_over ? "#555" : "#333" ); + ctx.fillRect( rect[0], rect[1], rect[2], rect[3] ); + ctx.strokeStyle = "#AAA"; + ctx.strokeRect( rect[0] + 0.5, rect[1] + 0.5, rect[2], rect[3] ); + ctx.textAlign = "center"; + ctx.fillStyle = clicked ? "#000" : "#AAA"; + ctx.fillText( text, rect[0] + rect[2] * 0.5, rect[1] + rect[3] * 0.75 ); + + if(clicked) + { + mouse.blocked = true; + if(callback) + setTimeout( function(){ callback(this.current_node,text,mouse); }),1; + } +} + /* LGraphCanvas.prototype.resizeCanvas = function(width,height) { @@ -5662,6 +5743,154 @@ LGraphCanvas.onShowTitleEditor = function( value, options, e, menu, node ) } } +LGraphCanvas.prototype.showSearchBox = function(event) +{ + var that = this; + var input_html = ""; + + var dialog = document.createElement("div"); + dialog.className = "graphdialog"; + dialog.innerHTML = "Search
"; + dialog.close = function() + { + that.search_box = null; + dialog.parentNode.removeChild( dialog ); + } + + dialog.addEventListener("mouseleave",function(e){ + dialog.close(); + }); + + if(that.search_box) + that.search_box.close(); + that.search_box = dialog; + + var helper = dialog.querySelector(".helper"); + + var first = null; + var timeout = null; + var selected = null; + + var input = dialog.querySelector("input"); + if(input) + { + input.addEventListener("keydown", function(e){ + + if(e.keyCode == 38) //UP + changeSelection(false); + else if(e.keyCode == 40) //DOWN + changeSelection(true); + else if(e.keyCode == 27) //ESC + dialog.close(); + else if(e.keyCode == 13) + { + if(selected) + select( selected.innerHTML ) + else if(first) + select(first); + else + dialog.close(); + } + else + { + if(timeout) + clearInterval(timeout); + timeout = setTimeout( refreshHelper, 10 ); + return; + } + e.preventDefault(); + e.stopPropagation(); + }); + } + + var graphcanvas = LGraphCanvas.active_canvas; + var canvas = graphcanvas.canvas; + + var rect = canvas.getBoundingClientRect(); + var offsetx = -20; + var offsety = -20; + if(rect) + { + offsetx -= rect.left; + offsety -= rect.top; + } + + if( event ) + { + dialog.style.left = (event.pageX + offsetx) + "px"; + dialog.style.top = (event.pageY + offsety)+ "px"; + } + else + { + dialog.style.left = (canvas.width * 0.5 + offsetx) + "px"; + dialog.style.top = (canvas.height * 0.5 + offsety) + "px"; + } + + canvas.parentNode.appendChild( dialog ); + input.focus(); + + function select( name ) + { + if(name) + { + if( that.onSearchBoxSelection ) + that.onSearchBoxSelection( name, event, graphcanvas ); + else + { + var node = LiteGraph.createNode( name ); + if(node) + { + node.pos = graphcanvas.convertEventToCanvas( event ); + graphcanvas.graph.add( node ); + } + } + } + + dialog.close(); + } + + function changeSelection( forward ) + { + if(selected) + selected.classList.remove("selected"); + if(!selected) + selected = helper.childNodes[0]; + else + selected = forward ? selected.nextSibling : selected.previousSibling; + if(!selected) + return; + selected.classList.add("selected"); + } + + function refreshHelper() + { + timeout = null; + var str = input.value; + first = null; + helper.innerHTML = ""; + if(!str) + return; + + if( that.onSearchBox ) + that.onSearchBox( help, str, graphcanvas ); + else + for( var i in LiteGraph.registered_node_types ) + if(i.indexOf(str) != -1) + { + var help = document.createElement("div"); + if(!first) first = i; + help.innerText = i; + help.className = "help-item"; + help.addEventListener("click", function(e){ + select( this.innerText ); + }); + helper.appendChild(help); + } + } + + return dialog; +} + LGraphCanvas.prototype.showEditPropertyValue = function( node, property, options ) { if(!node || node.properties[ property ] === undefined ) @@ -5762,7 +5991,8 @@ LGraphCanvas.prototype.showEditPropertyValue = function( node, property, options if(typeof( node.properties[ property ] ) == "number") value = Number(value); node.properties[ property ] = value; - + if(node._graph) + node._graph._version++; if(node.onPropertyChanged) node.onPropertyChanged( property, value ); dialog.close(); @@ -6658,7 +6888,7 @@ LiteGraph.registerNodeType("basic/time", Time); function Subgraph() { var that = this; - this.size = [120,60]; + this.size = [120,80]; //create inner graph this.subgraph = new LGraph(); @@ -6673,7 +6903,7 @@ function Subgraph() this.subgraph.onGlobalOutputRenamed = this.onSubgraphRenamedGlobalOutput.bind(this); this.subgraph.onGlobalOutputTypeChanged = this.onSubgraphTypeChangeGlobalOutput.bind(this); - this.bgcolor = "#663"; + this.bgcolor = "#353"; } Subgraph.title = "Subgraph"; @@ -6740,6 +6970,19 @@ Subgraph.prototype.getExtraMenuOptions = function(graphcanvas) }]; } +Subgraph.prototype.onDrawForeground = function( ctx, graphcanvas ) +{ + var node = this; + ctx.globalAlpha = 0.75; + graphcanvas.guiButton(ctx, [0,this.size[1] - 20,this.size[0],19], "Open", function(){ graphcanvas.openSubgraph(node.subgraph); }); + ctx.globalAlpha = 1; +} + +Subgraph.prototype.onResize = function(size) +{ + size[1] += 20; +} + Subgraph.prototype.onExecute = function() { //send inputs to subgraph global inputs @@ -7382,6 +7625,7 @@ var LiteGraph = global.LiteGraph; if(local_pos[0] > 1 && local_pos[1] > 1 && local_pos[0] < (this.size[0] - 2) && local_pos[1] < (this.size[1] - 2) ) { this.properties.value = !this.properties.value; + this.graph._version++; this.trigger( "e", this.properties.value ); return true; } @@ -7469,6 +7713,7 @@ var LiteGraph = global.LiteGraph; var v = Math.clamp( this.properties.value + steps * this.properties.step, this.properties.min, this.properties.max ); this.properties.value = v; + this.graph._version++; this.setDirtyCanvas(true); } @@ -7478,6 +7723,7 @@ var LiteGraph = global.LiteGraph; { var steps = pos[1] > this.size[1] * 0.5 ? -1 : 1; this.properties.value = Math.clamp( this.properties.value + steps * this.properties.step, this.properties.min, this.properties.max ); + this.graph._version++; this.setDirtyCanvas(true); } diff --git a/build/litegraph.min.js b/build/litegraph.min.js index 1eeb91a9b8..481881f665 100755 --- a/build/litegraph.min.js +++ b/build/litegraph.min.js @@ -1,176 +1,177 @@ (function(u){function g(){l.debug&&console.log("Graph created");this.list_of_graphcanvas=null;this.clear()}function e(a){this._ctor(a)}function h(a,b,d){d=d||{};this.background_image="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII="; a&&a.constructor===String&&(a=document.querySelector(a));this.max_zoom=10;this.min_zoom=0.1;this.zoom_modify_alpha=!0;this.title_text_font="bold 14px Arial";this.inner_text_font="normal 12px Arial";this.node_title_color=l.NODE_TITLE_COLOR;this.default_link_color="#AAC";this.default_connection_color={input_off:"#AAB",input_on:"#7F7",output_off:"#AAB",output_on:"#7F7"};this.highquality_render=!0;this.editor_alpha=1;this.pause_rendering=!1;this.render_only_selected=this.clear_background=this.render_shadows= -!0;this.live_mode=!1;this.allow_interaction=this.allow_dragnodes=this.allow_dragcanvas=this.show_info=!0;this.drag_mode=!1;this.dragging_rectangle=null;this.always_render_background=!1;this.render_canvas_border=!0;this.render_connections_shadows=!1;this.render_connection_arrows=this.render_curved_connections=this.render_connections_border=!0;this.connections_width=3;b&&b.attachCanvas(this);this.setCanvas(a);this.clear();d.skip_render||this.startRendering();this.autoresize=d.autoresize}function m(a, -b){return Math.sqrt((b[0]-a[0])*(b[0]-a[0])+(b[1]-a[1])*(b[1]-a[1]))}function p(a,b,d,c,f,n){return da&&cb?!0:!1}function q(a,b){var d=a[0]+a[2],c=a[1]+a[3],f=b[1]+b[3];return a[0]>b[0]+b[2]||a[1]>f||dt.width-e.width-10&&(n=t.width-e.width-10);k>t.height-e.height-10&&(k=t.height-e.height-10)}f.style.left=n+"px";f.style.top=k+"px"}var l=u.LiteGraph={NODE_TITLE_HEIGHT:16,NODE_SLOT_HEIGHT:15,NODE_WIDTH:140,NODE_MIN_WIDTH:50,NODE_COLLAPSED_RADIUS:10,NODE_COLLAPSED_WIDTH:80,CANVAS_GRID_SIZE:10,NODE_TITLE_COLOR:"#222",NODE_DEFAULT_COLOR:"#999",NODE_DEFAULT_BGCOLOR:"#444",NODE_DEFAULT_BOXCOLOR:"#AEF",NODE_DEFAULT_SHAPE:"box",MAX_NUMBER_OF_NODES:1E3,DEFAULT_POSITION:[100,100],node_images_path:"",VALID_SHAPES:["box", -"round"],BOX_SHAPE:1,ROUND_SHAPE:2,CIRCLE_SHAPE:3,INPUT:1,OUTPUT:2,EVENT:-1,ACTION:-1,ALWAYS:0,ON_EVENT:1,NEVER:2,ON_TRIGGER:3,proxy:null,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;l.debug&&console.log("Node registered: "+a);a.split("/");var d=b.name,c=a.lastIndexOf("/");b.category=a.substr(0,c);b.title|| -(b.title=d);if(b.prototype)for(var f in e.prototype)b.prototype[f]||(b.prototype[f]=e.prototype[f]);Object.defineProperty(b.prototype,"shape",{set:function(a){switch(a){case "box":this._shape=l.BOX_SHAPE;break;case "round":this._shape=l.ROUND_SHAPE;break;case "circle":this._shape=l.CIRCLE_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[d]=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(f in b.supported_extensions)this.node_types_by_file_extension[b.supported_extensions[f].toLowerCase()]=b},wrapFunctionAsNode:function(a,b,d,c){for(var f=Array(b.length),n="",k=l.getParameterNames(b),t=0;tk&&(k=f.size[0]),e+=f.size[1]+a;b+=k+a}this.setDirtyCanvas(!0,!0)};g.prototype.getTime=function(){return this.globaltime};g.prototype.getFixedTime=function(){return this.fixedtime};g.prototype.getElapsedTime=function(){return this.elapsed_time};g.prototype.sendEventToAllNodes=function(a,b,d){d=d||l.ALWAYS;var c=this._nodes_in_order?this._nodes_in_order:this._nodes;if(c)for(var f=0,n=c.length;f< -n;++f){var k=c[f];if(k[a]&&k.mode==d)if(void 0===b)k[a]();else if(b&&b.constructor===Array)k[a].apply(k,b);else k[a](b)}};g.prototype.sendActionToCanvas=function(a,b){if(this.list_of_graphcanvas)for(var d=0;d= -l.MAX_NUMBER_OF_NODES)throw"LiteGraph: max number of nodes in a graph reached";null==a.id||-1==a.id?a.id=++this.last_node_id:this.last_node_id!a.length||(this._pos[0]=a[0],this._pos[1]=a[1])},get:function(){return this._pos},enumerable:!0});this.id=-1;this.type=null;this.inputs=[];this.outputs=[];this.connections=[];this.properties={};this.properties_info=[];this.data=null;this.flags={}};e.prototype.configure=function(a){for(var b in a)if("console"!=b)if("properties"==b)for(var d in a.properties){if(this.properties[d]=a.properties[d],this.onPropertyChanged)this.onPropertyChanged(d,a.properties[d])}else null!= -a[b]&&("object"==typeof a[b]?this[b]&&this[b].configure?this[b].configure(a[b]):this[b]=l.cloneObject(a[b],this[b]):this[b]=a[b]);a.title||(this.title=this.constructor.title);if(this.onConnectionsChange){if(this.inputs)for(var c=0;c=this.outputs.length)){var d=this.outputs[a];if(d&&(d._data=b,this.outputs[a].links))for(d=0;d=this.inputs.length||null==this.inputs[a].link)){var d=this.graph.links[this.inputs[a].link];if(!d)return null;if(!b)return d.data;var c=this.graph.getNodeById(d.origin_id);if(!c)return d.data;if(c.updateOutputData)c.updateOutputData(d.origin_slot); -else if(c.onExecute)c.onExecute();return d.data}};e.prototype.getInputDataByName=function(a,b){var d=this.findInputSlot(a);return-1==d?null:this.getInputData(d,b)};e.prototype.isInputConnected=function(a){return this.inputs?a=this.inputs.length)return null;a=this.inputs[a];return a&&a.link? -(a=this.graph.links[a.link])?this.graph.getNodeById(a.origin_id):null:null};e.prototype.getInputOrProperty=function(a){if(!this.inputs||!this.inputs.length)return this.properties?this.properties[a]:null;for(var b=0,d=this.inputs.length;b=this.outputs.length?null:this.outputs[a]._data};e.prototype.getOutputInfo=function(a){return this.outputs? -a=this.outputs.length)return null;a=this.outputs[a]; -if(!a.links||0==a.links.length)return null;for(var b=[],d=0;da&&this.pos[1]-c-db)return!0;return!1};e.prototype.getSlotInPosition=function(a,b){if(this.inputs)for(var d=0,c=this.inputs.length;d=this.outputs.length)return l.debug&&console.log("Connect: Error, slot number not found"),!1;b&&b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"Node not found";if(b==this)return!1;if(d.constructor===String){if(d=b.findInputSlot(d),-1==d)return l.debug&&console.log("Connect: Error, no slot of name "+d),!1}else{if(d===l.EVENT)return!1;if(!b.inputs||d>=b.inputs.length)return l.debug&&console.log("Connect: Error, slot number not found"),!1}null!=b.inputs[d].link&&b.disconnectInput(d); -this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);var c=this.outputs[a];if(b.onConnectInput&&!1===b.onConnectInput(d,c.type,c))return!1;var f=b.inputs[d];if(l.isValidConnection(c.type,f.type)){var n={id:this.graph.last_link_id++,type:f.type,origin_id:this.id,origin_slot:a,target_id:b.id,target_slot:d};this.graph.links[n.id]=n;null==c.links&&(c.links=[]);c.links.push(n.id);b.inputs[d].link=n.id;if(this.onConnectionsChange)this.onConnectionsChange(l.OUTPUT,a,!0,n,c);if(b.onConnectionsChange)b.onConnectionsChange(l.INPUT, -d,!0,n,f)}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};e.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return l.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return l.debug&&console.log("Connect: Error, slot number not found"),!1;var d=this.outputs[a];if(!d.links||0==d.links.length)return!1;if(b){b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"Target Node not found"; -for(var c=0,f=d.links.length;c=this.inputs.length)return l.debug&&console.log("Connect: Error, slot number not found"), -!1;var b=this.inputs[a];if(!b)return!1;var d=this.inputs[a].link;this.inputs[a].link=null;var c=this.graph.links[d];if(c){var f=this.graph.getNodeById(c.origin_id);if(!f)return!1;var n=f.outputs[c.origin_slot];if(!n||!n.links||0==n.links.length)return!1;for(var k=0,e=n.links.length;kb&&this.inputs[b].pos?[this.pos[0]+this.inputs[b].pos[0],this.pos[1]+this.inputs[b].pos[1]]:!a&&this.outputs.length>b&&this.outputs[b].pos?[this.pos[0]+this.outputs[b].pos[0],this.pos[1]+this.outputs[b].pos[1]]: -a?[this.pos[0],this.pos[1]+10+b*l.NODE_SLOT_HEIGHT]:[this.pos[0]+this.size[0]+1,this.pos[1]+10+b*l.NODE_SLOT_HEIGHT]};e.prototype.alignToGrid=function(){this.pos[0]=l.CANVAS_GRID_SIZE*Math.round(this.pos[0]/l.CANVAS_GRID_SIZE);this.pos[1]=l.CANVAS_GRID_SIZE*Math.round(this.pos[1]/l.CANVAS_GRID_SIZE)};e.prototype.trace=function(a){this.console||(this.console=[]);this.console.push(a);this.console.length>e.MAX_CONSOLE&&this.console.shift();this.graph.onNodeTrace(this,a)};e.prototype.setDirtyCanvas=function(a, -b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};e.prototype.loadImage=function(a){var b=new Image;b.src=l.node_images_path+a;b.ready=!1;var d=this;b.onload=function(){this.ready=!0;d.setDirtyCanvas(!0)};return b};e.prototype.captureInput=function(a){if(this.graph&&this.graph.list_of_graphcanvas)for(var b=this.graph.list_of_graphcanvas,d=0;d element, you passed a "+a.localName;throw"This browser doesnt support Canvas"; -}null==(this.ctx=a.getContext("2d"))&&(console.warn("This canvas seems to be WebGL, enabling WebGL renderer"),this.enableWebGL());this._mousemove_callback=this.processMouseMove.bind(this);this._mouseup_callback=this.processMouseUp.bind(this);b||this.bindEvents()}};h.prototype._doNothing=function(a){a.preventDefault();return!1};h.prototype._doReturnTrue=function(a){a.preventDefault();return!0};h.prototype.bindEvents=function(){if(this._events_binded)console.warn("LGraphCanvas: events already binded"); -else{var a=this.canvas,b=this.getCanvasWindow().document;this._mousedown_callback=this.processMouseDown.bind(this);this._mousewheel_callback=this.processMouseWheel.bind(this);a.addEventListener("mousedown",this._mousedown_callback,!0);a.addEventListener("mousemove",this._mousemove_callback);a.addEventListener("mousewheel",this._mousewheel_callback,!1);a.addEventListener("contextmenu",this._doNothing);a.addEventListener("DOMMouseScroll",this._mousewheel_callback,!1);a.addEventListener("touchstart", -this.touchHandler,!0);a.addEventListener("touchmove",this.touchHandler,!0);a.addEventListener("touchend",this.touchHandler,!0);a.addEventListener("touchcancel",this.touchHandler,!0);this._key_callback=this.processKey.bind(this);a.addEventListener("keydown",this._key_callback,!0);b.addEventListener("keyup",this._key_callback,!0);this._ondrop_callback=this.processDrop.bind(this);a.addEventListener("dragover",this._doNothing,!1);a.addEventListener("dragend",this._doNothing,!1);a.addEventListener("drop", -this._ondrop_callback,!1);a.addEventListener("dragenter",this._doReturnTrue,!1);this._events_binded=!0}};h.prototype.unbindEvents=function(){if(this._events_binded){var a=this.getCanvasWindow().document;this.canvas.removeEventListener("mousedown",this._mousedown_callback);this.canvas.removeEventListener("mousewheel",this._mousewheel_callback);this.canvas.removeEventListener("DOMMouseScroll",this._mousewheel_callback);this.canvas.removeEventListener("keydown",this._key_callback);a.removeEventListener("keyup", -this._key_callback);this.canvas.removeEventListener("contextmenu",this._doNothing);this.canvas.removeEventListener("drop",this._ondrop_callback);this.canvas.removeEventListener("dragenter",this._doReturnTrue);this.canvas.removeEventListener("touchstart",this.touchHandler);this.canvas.removeEventListener("touchmove",this.touchHandler);this.canvas.removeEventListener("touchend",this.touchHandler);this.canvas.removeEventListener("touchcancel",this.touchHandler);this._ondrop_callback=this._key_callback= -this._mousewheel_callback=this._mousedown_callback=null;this._events_binded=!1}else console.warn("LGraphCanvas: no events binded")};h.getFileExtension=function(a){var b=a.indexOf("?");-1!=b&&(a=a.substr(0,b));b=a.lastIndexOf(".");return-1==b?"":a.substr(b+1).toLowerCase()};h.prototype.enableWebGL=function(){if(void 0===typeof GL)throw"litegl.js must be included to use a WebGL canvas";if(void 0===typeof enableWebGLCanvas)throw"webglCanvas.js must be included to use this feature";this.gl=this.ctx=enableWebGLCanvas(this.canvas); -this.ctx.webgl=!0;this.bgcanvas=this.canvas;this.bgctx=this.gl};h.prototype.setDirty=function(a,b){a&&(this.dirty_canvas=!0);b&&(this.dirty_bgcanvas=!0)};h.prototype.getCanvasWindow=function(){if(!this.canvas)return window;var a=this.canvas.ownerDocument;return a.defaultView||a.parentWindow};h.prototype.startRendering=function(){function a(){this.pause_rendering||this.draw();var b=this.getCanvasWindow();this.is_rendering&&b.requestAnimationFrame(a.bind(this))}this.is_rendering||(this.is_rendering= -!0,a.call(this))};h.prototype.stopRendering=function(){this.is_rendering=!1};h.prototype.processMouseDown=function(a){if(this.graph){this.adjustMouseEvent(a);var b=this.getCanvasWindow();h.active_canvas=this;this.canvas.removeEventListener("mousemove",this._mousemove_callback);b.document.addEventListener("mousemove",this._mousemove_callback,!0);b.document.addEventListener("mouseup",this._mouseup_callback,!0);var d=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes),c=!1;l.closeAllContextMenus(b); -if(1==a.which){a.ctrlKey&&(this.dragging_rectangle=new Float32Array(4),this.dragging_rectangle[0]=a.canvasX,this.dragging_rectangle[1]=a.canvasY,this.dragging_rectangle[2]=1,this.dragging_rectangle[3]=1,c=!0);var f=!1;if(d&&this.allow_interaction&&!c){this.live_mode||d.flags.pinned||this.bringToFront(d);if(!this.connecting_node&&!d.flags.collapsed&&!this.live_mode){if(d.outputs)for(var n=0,k=d.outputs.length;nl.getTime()-this.last_mouseclick&&this.selected_nodes[d.id]){if(d.onDblClick)d.onDblClick(a);this.processNodeDblClicked(d);n=!0}d.onMouseDown&&d.onMouseDown(a,[a.canvasX-d.pos[0],a.canvasY-d.pos[1]])?n=!0:this.live_mode&&(n=f=!0);n||(this.allow_dragnodes&&(this.node_dragged=d),this.selected_nodes[d.id]||this.processNodeSelected(d,a));this.dirty_canvas=!0}}else f=!0;!c&&f&&this.allow_dragcanvas&& -(this.dragging_canvas=!0)}else 2!=a.which&&3==a.which&&this.processContextMenu(d,a);this.last_mouse[0]=a.localX;this.last_mouse[1]=a.localY;this.last_mouseclick=l.getTime();this.canvas_mouse=[a.canvasX,a.canvasY];this.graph.change();(!b.document.activeElement||"input"!=b.document.activeElement.nodeName.toLowerCase()&&"textarea"!=b.document.activeElement.nodeName.toLowerCase())&&a.preventDefault();a.stopPropagation();if(this.onMouseDown)this.onMouseDown(a);return!1}};h.prototype.processMouseMove=function(a){this.autoresize&& -this.resize();if(this.graph){h.active_canvas=this;this.adjustMouseEvent(a);var b=[a.localX,a.localY],d=[b[0]-this.last_mouse[0],b[1]-this.last_mouse[1]];this.last_mouse=b;this.canvas_mouse=[a.canvasX,a.canvasY];if(this.dragging_rectangle)this.dragging_rectangle[2]=a.canvasX-this.dragging_rectangle[0],this.dragging_rectangle[3]=a.canvasY-this.dragging_rectangle[1],this.dirty_canvas=!0;else if(this.dragging_canvas)this.offset[0]+=d[0]/this.scale,this.offset[1]+=d[1]/this.scale,this.dirty_bgcanvas=this.dirty_canvas= -!0;else if(this.allow_interaction){this.connecting_node&&(this.dirty_canvas=!0);for(var b=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes),c=0,f=this.graph._nodes.length;cthis.dragging_rectangle[2]&&(this.dragging_rectangle[0]+=this.dragging_rectangle[2]);0>this.dragging_rectangle[3]&&(this.dragging_rectangle[1]+=this.dragging_rectangle[3]); -this.dragging_rectangle[2]=Math.abs(this.dragging_rectangle[2]*this.scale);this.dragging_rectangle[3]=Math.abs(this.dragging_rectangle[3]*this.scale);for(var f=0;fa.click_time&&this.deselectAllNodes();this.dirty_canvas= -!0;this.dragging_canvas=!1;if(this.node_over&&this.node_over.onMouseUp)this.node_over.onMouseUp(a,[a.canvasX-this.node_over.pos[0],a.canvasY-this.node_over.pos[1]]);if(this.node_capturing_input&&this.node_capturing_input.onMouseUp)this.node_capturing_input.onMouseUp(a,[a.canvasX-this.node_capturing_input.pos[0],a.canvasY-this.node_capturing_input.pos[1]])}else 2==a.which?(this.dirty_canvas=!0,this.dragging_canvas=!1):3==a.which&&(this.dirty_canvas=!0,this.dragging_canvas=!1);this.graph.change();a.stopPropagation(); -a.preventDefault();return!1}};h.prototype.processMouseWheel=function(a){if(this.graph&&this.allow_dragcanvas){var b=null!=a.wheelDeltaY?a.wheelDeltaY:-60*a.detail;this.adjustMouseEvent(a);var d=this.scale;0b&&(d*=1/1.1);this.setZoom(d,[a.localX,a.localY]);this.graph.change();a.preventDefault();return!1}};h.prototype.isOverNodeBox=function(a,b,d){var c=l.NODE_TITLE_HEIGHT;return p(b,d,a.pos[0]+2,a.pos[1]+2-c,c-4,c-4)?!0:!1};h.prototype.isOverNodeInput=function(a,b,d,c){if(a.inputs)for(var f= -0,n=a.inputs.length;fthis.max_zoom?this.scale=this.max_zoom:this.scaled-this.graph._last_trigger_time)&&this.drawBackCanvas();(this.dirty_canvas||a)&&this.drawFrontCanvas();this.fps=this.render_time?1/this.render_time:0;this.frame+=1}};h.prototype.drawFrontCanvas=function(){this.ctx||(this.ctx=this.bgcanvas.getContext("2d")); -var a=this.ctx;if(a){a.start2D&&a.start2D();var b=this.canvas;a.restore();a.setTransform(1,0,0,1,0,0);this.dirty_area&&(a.save(),a.beginPath(),a.rect(this.dirty_area[0],this.dirty_area[1],this.dirty_area[2],this.dirty_area[3]),a.clip());this.clear_background&&a.clearRect(0,0,b.width,b.height);this.bgcanvas==this.canvas?this.drawBackCanvas():a.drawImage(this.bgcanvas,0,0);if(this.onRender)this.onRender(b,a);this.show_info&&this.renderInfo(a);if(this.graph){a.save();a.scale(this.scale,this.scale);a.translate(this.offset[0], -this.offset[1]);for(var b=this.computeVisibleNodes(null,this.visible_nodes),d=0;db-k._last_time&&(g=2-0.002*(b-k._last_time),m="rgba(255,255,255, "+g.toFixed(2)+")",this.renderLink(a,p,f.getConnectionPos(!0,h),k,!0,g,m))}}}}a.globalAlpha=1};h.prototype.renderLink=function(a,b,c,e,f,g,k){if(this.highquality_render){var t=m(b,c);this.render_connections_border&&0.6b[1]?0:Math.PI,a.save(),a.translate(e[0],e[1]),a.rotate(k),a.beginPath(),a.moveTo(-5,-5),a.lineTo(0,5),a.lineTo(5,-5),a.fill(),a.restore());if(g)for(g=0;5>g;++g)e=(0.001*l.getTime()+0.2*g)%1,e=this.computeConnectionPoint(b,c,e),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()};h.prototype.computeConnectionPoint=function(a,b,c){var e=m(a,b),f=[a[0]+0.25*e,a[1]],e=[b[0]-0.25*e,b[1]],h=(1-c)*(1-c)*(1-c),k=3*(1-c)*(1-c)*c,g=3*(1-c)*c*c;c*=c*c;return[h*a[0]+k*f[0]+g*e[0]+c*b[0],h*a[1]+k*f[1]+g*e[1]+c*b[1]]};h.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)};h.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 e=setInterval(function(){b.editor_alpha*=c;b.dirty_canvas=!0;b.dirty_bgcanvas=!0;1>c&&0.01>b.editor_alpha&&(clearInterval(e),1>c&&(b.live_mode=!0));1"+p+""+ -a+"",value:p});if(m.length)return new l.ContextMenu(m,{event:c,callback:g,parentMenu:e,allow_html:!0,node:f},b),!1}};h.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};h.onResizeNode=function(a,b,c,e,f){f&&(f.size=f.computeSize(),f.setDirtyCanvas(!0,!0))};h.onShowTitleEditor=function(a,b,c,e,f){function g(){f.title=m.value;k.parentNode.removeChild(k);f.setDirtyCanvas(!0,!0)}var k=document.createElement("div");k.className="graphdialog";k.innerHTML= -"Title";var m=k.querySelector("input");m&&(m.value=f.title,m.addEventListener("keydown",function(a){13==a.keyCode&&(g(),a.preventDefault(),a.stopPropagation())}));a=h.active_canvas.canvas;b=a.getBoundingClientRect();e=c=-20;b&&(c-=b.left,e-=b.top);event?(k.style.left=event.pageX+c+"px",k.style.top=event.pageY+e+"px"):(k.style.left=0.5*a.width+c+"px",k.style.top=0.5*a.height+e+"px");k.querySelector("button").addEventListener("click", -g);a.parentNode.appendChild(k)};h.prototype.showEditPropertyValue=function(a,b,c){function e(){f(q.value)}function f(c){"number"==typeof a.properties[b]&&(c=Number(c));a.properties[b]=c;if(a.onPropertyChanged)a.onPropertyChanged(b,c);p.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){c=c||{};var h="string";null!==a.properties[b]&&(h=typeof a.properties[b]);var k=null;a.getPropertyInfo&&(k=a.getPropertyInfo(b));if(a.properties_info)for(var g=0;g";else if("enum"==h&&k.values){m=""}else"boolean"==h&&(m="");var p=this.createDialog(""+b+""+m+"",c);if("enum"==h&&k.values){var q=p.querySelector("select");q.addEventListener("change",function(a){f(a.target.value)})}else if("boolean"==h)(q=p.querySelector("input"))&&q.addEventListener("click",function(a){f(!!q.checked)});else if(q=p.querySelector("input"))q.value=void 0!==a.properties[b]?a.properties[b]:"",q.addEventListener("keydown",function(a){13==a.keyCode&&(e(),a.preventDefault(),a.stopPropagation())}); -p.querySelector("button").addEventListener("click",e)}};h.prototype.createDialog=function(a,b){b=b||{};var c=document.createElement("div");c.className="graphdialog";c.innerHTML=a;var e=this.canvas.getBoundingClientRect(),f=-20,h=-20;e&&(f-=e.left,h-=e.top);b.position?(f+=b.position[0],h+=b.position[1]):b.event?(f+=b.event.pageX,h+=b.event.pageY):(f+=0.5*this.canvas.width,h+=0.5*this.canvas.height);c.style.left=f+"px";c.style.top=h+"px";this.canvas.parentNode.appendChild(c);c.close=function(){this.parentNode&& -this.parentNode.removeChild(this)};return c};h.onMenuNodeCollapse=function(a,b,c,e,f){f.flags.collapsed=!f.flags.collapsed;f.setDirtyCanvas(!0,!0)};h.onMenuNodePin=function(a,b,c,e,f){f.pin()};h.onMenuNodeMode=function(a,b,c,e,f){new l.ContextMenu(["Always","On Event","On Trigger","Never"],{event:c,callback:function(a){if(f)switch(a){case "On Event":f.mode=l.ON_EVENT;break;case "On Trigger":f.mode=l.ON_TRIGGER;break;case "Never":f.mode=l.NEVER;break;default:f.mode=l.ALWAYS}},parentMenu:e,node:f}); -return!1};h.onMenuNodeColors=function(a,b,c,e,f){if(!f)throw"no node for color";b=[];for(var g in h.node_colors)a=h.node_colors[g],a={value:g,content:""+g+""},b.push(a);new l.ContextMenu(b,{event:c,callback:function(a){f&&(a=h.node_colors[a.value])&&(f.color=a.color,f.bgcolor=a.bgcolor,f.setDirtyCanvas(!0))},parentMenu:e,node:f});return!1};h.onMenuNodeShapes=function(a,b,c,e,f){if(!f)throw"no node passed";new l.ContextMenu(l.VALID_SHAPES, -{event:c,callback:function(a){f&&(f.shape=a,f.setDirtyCanvas(!0))},parentMenu:e,node:f});return!1};h.onMenuNodeRemove=function(a,b,c,e,f){if(!f)throw"no node passed";!1!=f.removable&&(f.graph.remove(f),f.setDirtyCanvas(!0,!0))};h.onMenuNodeClone=function(a,b,c,e,f){!1!=f.clonable&&(a=f.clone())&&(a.pos=[f.pos[0]+5,f.pos[1]+5],f.graph.add(a),f.setDirtyCanvas(!0,!0))};h.node_colors={red:{color:"#FAA",bgcolor:"#944"},green:{color:"#AFA",bgcolor:"#494"},blue:{color:"#AAF",bgcolor:"#449"},cyan:{color:"#AFF", -bgcolor:"#499"},purple:{color:"#FAF",bgcolor:"#949"},yellow:{color:"#FFA",bgcolor:"#994"},black:{color:"#777",bgcolor:"#000"},white:{color:"#FFF",bgcolor:"#AAA"}};h.prototype.getCanvasMenuOptions=function(){var a=null;this.getMenuOptions?a=this.getMenuOptions():(a=[{content:"Add Node",has_submenu:!0,callback:h.onMenuAdd}],this._graph_stack&&0Name", -f),g=h.querySelector("input");h.querySelector("button").addEventListener("click",function(b){if(g.value){if(b=k.input?a.getInputInfo(k.slot):a.getOutputInfo(k.slot))b.label=g.value;c.setDirty(!0)}h.close()})}},node:a},k=null;a&&(k=a.getSlotInPosition(b.canvasX,b.canvasY),h.active_node=a);k?(f=[],f.push(k.locked?"Cannot remove":{content:"Remove Slot",slot:k}),f.push({content:"Rename Slot",slot:k}),g.title=(k.input?k.input.type:k.output.type)||"*",k.input&&k.input.type==l.ACTION&&(g.title="Action"), -k.output&&k.output.type==l.EVENT&&(g.title="Event")):f=a?this.getNodeMenuOptions(a):this.getCanvasMenuOptions();f&&new l.ContextMenu(f,g,e)};this.CanvasRenderingContext2D&&(CanvasRenderingContext2D.prototype.roundRect=function(a,b,c,e,f,h){void 0===f&&(f=5);void 0===h&&(h=f);this.beginPath();this.moveTo(a+f,b);this.lineTo(a+c-f,b);this.quadraticCurveTo(a+c,b,a+c,b+f);this.lineTo(a+c,b+e-h);this.quadraticCurveTo(a+c,b+e,a+c-h,b+e);this.lineTo(a+h,b+e);this.quadraticCurveTo(a,b+e,a,b+e-h);this.lineTo(a, -b+f);this.quadraticCurveTo(a,b,a+f,b)});l.compareObjects=function(a,b){for(var c in a)if(a[c]!=b[c])return!1;return!0};l.distance=m;l.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")+")"};l.isInsideRectangle=p;l.growBounding=function(a,b,c){ba[2]&&(a[2]=b);ca[3]&&(a[3]=c)};l.isInsideBounding=function(a,b){return a[0]b[1][0]||a[1]>b[1][1]?!1:!0};l.overlapBounding=q;l.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),c=0,e,f,h=0;6>h;h+=2)e="0123456789ABCDEF".indexOf(a.charAt(h)),f="0123456789ABCDEF".indexOf(a.charAt(h+1)),b[c]=16*e+f,c++;return b};l.num2hex=function(a){for(var b="#",c,e,f=0;3>f;f++)c=a[f]/16,e=a[f]%16,b+="0123456789ABCDEF".charAt(c)+"0123456789ABCDEF".charAt(e);return b};r.prototype.addItem=function(a,b,c){function e(a){var b=this.value;b&&b.has_submenu&& -f.call(this,a)}function f(a){var b=this.value,f=!0;h.current_submenu&&h.current_submenu.close(a);if(c.callback){var e=c.callback.call(this,b,c,a,h,c.node);!0===e&&(f=!1)}if(b&&(b.callback&&!c.ignore_item_callbacks&&!0!==b.disabled&&(e=b.callback.call(this,b,c,a,h,c.node),!0===e&&(f=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new h.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:h,ignore_item_callbacks:b.submenu.ignore_item_callbacks, -title:b.submenu.title,autoopen:c.autoopen});f=!1}f&&!h.lock&&h.close()}var h=this;c=c||{};var k=document.createElement("div");k.className="litemenu-entry submenu";var g=!1;if(null===b)k.classList.add("separator");else{k.innerHTML=b&&b.title?b.title:a;if(k.value=b)b.disabled&&(g=!0,k.classList.add("disabled")),(b.submenu||b.has_submenu)&&k.classList.add("has_submenu");"function"==typeof b?(k.dataset.value=a,k.onclick_callback=b):k.dataset.value=b;b.className&&(k.className+=" "+b.className)}this.root.appendChild(k); -g||k.addEventListener("click",f);c.autoopen&&k.addEventListener("mouseenter",e);return k};r.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&&!r.isCursorOverElement(a,this.parentMenu.root)&&r.trigger(this.parentMenu.root,"mouseleave",a));this.current_submenu&&this.current_submenu.close(a,!0)};r.trigger=function(a,b,c,e){var f=document.createEvent("CustomEvent"); -f.initCustomEvent(b,!0,!0,c);f.srcElement=e;a.dispatchEvent?a.dispatchEvent(f):a.__events&&a.__events.dispatchEvent(f);return f};r.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this};r.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event};r.isCursorOverElement=function(a,b){var c=a.pageX,e=a.pageY,f=b.getBoundingClientRect();return f?e>f.top&&ef.left&&c< -f.left+f.width?!0:!1:!1};l.ContextMenu=r;l.closeAllContextMenus=function(a){a=a||window;a=a.document.querySelectorAll(".litecontextmenu");if(a.length){for(var b=[],c=0;ca?b:ca&&cb?!0:!1}function q(a,b){var d=a[0]+a[2],c=a[1]+a[3],f=b[1]+b[3];return a[0]>b[0]+b[2]||a[1]>f||dt.width-e.width-10&&(n=t.width-e.width-10);k>t.height-e.height-10&&(k=t.height-e.height-10)}f.style.left=n+"px";f.style.top=k+"px"}var l=u.LiteGraph={NODE_TITLE_HEIGHT:16,NODE_SLOT_HEIGHT:15,NODE_WIDTH:140,NODE_MIN_WIDTH:50,NODE_COLLAPSED_RADIUS:10,NODE_COLLAPSED_WIDTH:80,CANVAS_GRID_SIZE:10,NODE_TITLE_COLOR:"#222",NODE_DEFAULT_COLOR:"#999",NODE_DEFAULT_BGCOLOR:"#444",NODE_DEFAULT_BOXCOLOR:"#AEF",NODE_DEFAULT_SHAPE:"box", +MAX_NUMBER_OF_NODES:1E3,DEFAULT_POSITION:[100,100],node_images_path:"",VALID_SHAPES:["box","round"],BOX_SHAPE:1,ROUND_SHAPE:2,CIRCLE_SHAPE:3,INPUT:1,OUTPUT:2,EVENT:-1,ACTION:-1,ALWAYS:0,ON_EVENT:1,NEVER:2,ON_TRIGGER:3,proxy:null,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;l.debug&&console.log("Node registered: "+ +a);a.split("/");var d=b.name,c=a.lastIndexOf("/");b.category=a.substr(0,c);b.title||(b.title=d);if(b.prototype)for(var f in e.prototype)b.prototype[f]||(b.prototype[f]=e.prototype[f]);Object.defineProperty(b.prototype,"shape",{set:function(a){switch(a){case "box":this._shape=l.BOX_SHAPE;break;case "round":this._shape=l.ROUND_SHAPE;break;case "circle":this._shape=l.CIRCLE_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[d]=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(f in b.supported_extensions)this.node_types_by_file_extension[b.supported_extensions[f].toLowerCase()]=b},wrapFunctionAsNode:function(a,b,d,c){for(var f=Array(b.length),n="",k=l.getParameterNames(b),t=0;tk&&(k=f.size[0]),e+=f.size[1]+a;b+=k+a}this.setDirtyCanvas(!0,!0)};g.prototype.getTime=function(){return this.globaltime};g.prototype.getFixedTime=function(){return this.fixedtime};g.prototype.getElapsedTime=function(){return this.elapsed_time}; +g.prototype.sendEventToAllNodes=function(a,b,d){d=d||l.ALWAYS;var c=this._nodes_in_order?this._nodes_in_order:this._nodes;if(c)for(var f=0,n=c.length;f=l.MAX_NUMBER_OF_NODES)throw"LiteGraph: max number of nodes in a graph reached";null==a.id||-1==a.id?a.id=++this.last_node_id:this.last_node_id!a.length||(this._pos[0]=a[0],this._pos[1]=a[1])},get:function(){return this._pos},enumerable:!0});this.id=-1;this.type=null;this.inputs=[];this.outputs=[];this.connections=[];this.properties={};this.properties_info=[];this.data=null;this.flags={}};e.prototype.configure=function(a){for(var b in a)if("console"!= +b)if("properties"==b)for(var d in a.properties){if(this.properties[d]=a.properties[d],this.onPropertyChanged)this.onPropertyChanged(d,a.properties[d])}else null!=a[b]&&("object"==typeof a[b]?this[b]&&this[b].configure?this[b].configure(a[b]):this[b]=l.cloneObject(a[b],this[b]):this[b]=a[b]);a.title||(this.title=this.constructor.title);if(this.onConnectionsChange){if(this.inputs)for(var c=0;c=this.outputs.length)){var d=this.outputs[a];if(d&&(d._data=b,this.outputs[a].links))for(d=0;d=this.inputs.length|| +null==this.inputs[a].link)){var d=this.graph.links[this.inputs[a].link];if(!d)return null;if(!b)return d.data;var c=this.graph.getNodeById(d.origin_id);if(!c)return d.data;if(c.updateOutputData)c.updateOutputData(d.origin_slot);else if(c.onExecute)c.onExecute();return d.data}};e.prototype.getInputDataByName=function(a,b){var d=this.findInputSlot(a);return-1==d?null:this.getInputData(d,b)};e.prototype.isInputConnected=function(a){return this.inputs?a=this.inputs.length)return null;a=this.inputs[a];return a&&a.link?(a=this.graph.links[a.link])?this.graph.getNodeById(a.origin_id):null:null};e.prototype.getInputOrProperty=function(a){if(!this.inputs||!this.inputs.length)return this.properties?this.properties[a]:null;for(var b=0,d=this.inputs.length;b=this.outputs.length?null:this.outputs[a]._data};e.prototype.getOutputInfo=function(a){return this.outputs?a=this.outputs.length)return null;a=this.outputs[a];if(!a.links||0==a.links.length)return null;for(var b=[],d=0;da&&this.pos[1]-c-db)return!0;return!1};e.prototype.getSlotInPosition=function(a,b){if(this.inputs)for(var d=0,c=this.inputs.length;d=this.outputs.length)return l.debug&&console.log("Connect: Error, slot number not found"),!1;b&&b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"Node not found";if(b==this)return!1;if(d.constructor===String){if(d=b.findInputSlot(d),-1==d)return l.debug&&console.log("Connect: Error, no slot of name "+ +d),!1}else{if(d===l.EVENT)return!1;if(!b.inputs||d>=b.inputs.length)return l.debug&&console.log("Connect: Error, slot number not found"),!1}null!=b.inputs[d].link&&b.disconnectInput(d);this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);var c=this.outputs[a];if(b.onConnectInput&&!1===b.onConnectInput(d,c.type,c))return!1;var f=b.inputs[d];if(l.isValidConnection(c.type,f.type)){var n={id:this.graph.last_link_id++,type:f.type,origin_id:this.id,origin_slot:a,target_id:b.id,target_slot:d};this.graph.links[n.id]= +n;null==c.links&&(c.links=[]);c.links.push(n.id);b.inputs[d].link=n.id;if(this.onConnectionsChange)this.onConnectionsChange(l.OUTPUT,a,!0,n,c);if(b.onConnectionsChange)b.onConnectionsChange(l.INPUT,d,!0,n,f)}this.setDirtyCanvas(!1,!0);this.graph.connectionChange(this);return!0};e.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return l.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return l.debug&& +console.log("Connect: Error, slot number not found"),!1;var d=this.outputs[a];if(!d.links||0==d.links.length)return!1;if(b){b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"Target Node not found";for(var c=0,f=d.links.length;c=this.inputs.length)return l.debug&&console.log("Connect: Error, slot number not found"),!1;var b=this.inputs[a];if(!b)return!1;var d=this.inputs[a].link;this.inputs[a].link=null;var c=this.graph.links[d];if(c){var f=this.graph.getNodeById(c.origin_id);if(!f)return!1;var n=f.outputs[c.origin_slot];if(!n||!n.links||0==n.links.length)return!1;for(var k=0,e=n.links.length;kb&&this.inputs[b].pos?[this.pos[0]+this.inputs[b].pos[0],this.pos[1]+this.inputs[b].pos[1]]:!a&&this.outputs.length>b&&this.outputs[b].pos?[this.pos[0]+this.outputs[b].pos[0],this.pos[1]+this.outputs[b].pos[1]]:a?[this.pos[0],this.pos[1]+10+b*l.NODE_SLOT_HEIGHT]:[this.pos[0]+this.size[0]+1,this.pos[1]+10+b*l.NODE_SLOT_HEIGHT]};e.prototype.alignToGrid=function(){this.pos[0]=l.CANVAS_GRID_SIZE*Math.round(this.pos[0]/l.CANVAS_GRID_SIZE);this.pos[1]=l.CANVAS_GRID_SIZE*Math.round(this.pos[1]/ +l.CANVAS_GRID_SIZE)};e.prototype.trace=function(a){this.console||(this.console=[]);this.console.push(a);this.console.length>e.MAX_CONSOLE&&this.console.shift();this.graph.onNodeTrace(this,a)};e.prototype.setDirtyCanvas=function(a,b){this.graph&&this.graph.sendActionToCanvas("setDirty",[a,b])};e.prototype.loadImage=function(a){var b=new Image;b.src=l.node_images_path+a;b.ready=!1;var d=this;b.onload=function(){this.ready=!0;d.setDirtyCanvas(!0)};return b};e.prototype.captureInput=function(a){if(this.graph&& +this.graph.list_of_graphcanvas)for(var b=this.graph.list_of_graphcanvas,d=0;d element, you passed a "+a.localName;throw"This browser doesnt support Canvas";}null==(this.ctx=a.getContext("2d"))&&(console.warn("This canvas seems to be WebGL, enabling WebGL renderer"),this.enableWebGL());this._mousemove_callback=this.processMouseMove.bind(this);this._mouseup_callback=this.processMouseUp.bind(this);b||this.bindEvents()}};h.prototype._doNothing= +function(a){a.preventDefault();return!1};h.prototype._doReturnTrue=function(a){a.preventDefault();return!0};h.prototype.bindEvents=function(){if(this._events_binded)console.warn("LGraphCanvas: events already binded");else{var a=this.canvas,b=this.getCanvasWindow().document;this._mousedown_callback=this.processMouseDown.bind(this);this._mousewheel_callback=this.processMouseWheel.bind(this);a.addEventListener("mousedown",this._mousedown_callback,!0);a.addEventListener("mousemove",this._mousemove_callback); +a.addEventListener("mousewheel",this._mousewheel_callback,!1);a.addEventListener("contextmenu",this._doNothing);a.addEventListener("DOMMouseScroll",this._mousewheel_callback,!1);a.addEventListener("touchstart",this.touchHandler,!0);a.addEventListener("touchmove",this.touchHandler,!0);a.addEventListener("touchend",this.touchHandler,!0);a.addEventListener("touchcancel",this.touchHandler,!0);this._key_callback=this.processKey.bind(this);a.addEventListener("keydown",this._key_callback,!0);b.addEventListener("keyup", +this._key_callback,!0);this._ondrop_callback=this.processDrop.bind(this);a.addEventListener("dragover",this._doNothing,!1);a.addEventListener("dragend",this._doNothing,!1);a.addEventListener("drop",this._ondrop_callback,!1);a.addEventListener("dragenter",this._doReturnTrue,!1);this._events_binded=!0}};h.prototype.unbindEvents=function(){if(this._events_binded){var a=this.getCanvasWindow().document;this.canvas.removeEventListener("mousedown",this._mousedown_callback);this.canvas.removeEventListener("mousewheel", +this._mousewheel_callback);this.canvas.removeEventListener("DOMMouseScroll",this._mousewheel_callback);this.canvas.removeEventListener("keydown",this._key_callback);a.removeEventListener("keyup",this._key_callback);this.canvas.removeEventListener("contextmenu",this._doNothing);this.canvas.removeEventListener("drop",this._ondrop_callback);this.canvas.removeEventListener("dragenter",this._doReturnTrue);this.canvas.removeEventListener("touchstart",this.touchHandler);this.canvas.removeEventListener("touchmove", +this.touchHandler);this.canvas.removeEventListener("touchend",this.touchHandler);this.canvas.removeEventListener("touchcancel",this.touchHandler);this._ondrop_callback=this._key_callback=this._mousewheel_callback=this._mousedown_callback=null;this._events_binded=!1}else console.warn("LGraphCanvas: no events binded")};h.getFileExtension=function(a){var b=a.indexOf("?");-1!=b&&(a=a.substr(0,b));b=a.lastIndexOf(".");return-1==b?"":a.substr(b+1).toLowerCase()};h.prototype.enableWebGL=function(){if(void 0=== +typeof GL)throw"litegl.js must be included to use a WebGL canvas";if(void 0===typeof enableWebGLCanvas)throw"webglCanvas.js must be included to use this feature";this.gl=this.ctx=enableWebGLCanvas(this.canvas);this.ctx.webgl=!0;this.bgcanvas=this.canvas;this.bgctx=this.gl};h.prototype.setDirty=function(a,b){a&&(this.dirty_canvas=!0);b&&(this.dirty_bgcanvas=!0)};h.prototype.getCanvasWindow=function(){if(!this.canvas)return window;var a=this.canvas.ownerDocument;return a.defaultView||a.parentWindow}; +h.prototype.startRendering=function(){function a(){this.pause_rendering||this.draw();var b=this.getCanvasWindow();this.is_rendering&&b.requestAnimationFrame(a.bind(this))}this.is_rendering||(this.is_rendering=!0,a.call(this))};h.prototype.stopRendering=function(){this.is_rendering=!1};h.prototype.processMouseDown=function(a){if(this.graph){this.adjustMouseEvent(a);var b=this.getCanvasWindow();h.active_canvas=this;this.canvas.removeEventListener("mousemove",this._mousemove_callback);b.document.addEventListener("mousemove", +this._mousemove_callback,!0);b.document.addEventListener("mouseup",this._mouseup_callback,!0);var d=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes),c=!1;l.closeAllContextMenus(b);if(1==a.which){a.ctrlKey&&(this.dragging_rectangle=new Float32Array(4),this.dragging_rectangle[0]=a.canvasX,this.dragging_rectangle[1]=a.canvasY,this.dragging_rectangle[2]=1,this.dragging_rectangle[3]=1,c=!0);var f=!1;if(d&&this.allow_interaction&&!c){this.live_mode||d.flags.pinned||this.bringToFront(d);if(!this.connecting_node&& +!d.flags.collapsed&&!this.live_mode){if(d.outputs)for(var n=0,k=d.outputs.length;nl.getTime()-this.last_mouseclick&&this.selected_nodes[d.id]){if(d.onDblClick)d.onDblClick(a); +this.processNodeDblClicked(d);n=!0}d.onMouseDown&&d.onMouseDown(a,[a.canvasX-d.pos[0],a.canvasY-d.pos[1]])?n=!0:this.live_mode&&(n=f=!0);n||(this.allow_dragnodes&&(this.node_dragged=d),this.selected_nodes[d.id]||this.processNodeSelected(d,a));this.dirty_canvas=!0}}else f=!0;!c&&f&&this.allow_dragcanvas&&(this.dragging_canvas=!0)}else 2!=a.which&&3==a.which&&this.processContextMenu(d,a);this.last_mouse[0]=a.localX;this.last_mouse[1]=a.localY;this.last_mouseclick=l.getTime();this.canvas_mouse=[a.canvasX, +a.canvasY];this.graph.change();(!b.document.activeElement||"input"!=b.document.activeElement.nodeName.toLowerCase()&&"textarea"!=b.document.activeElement.nodeName.toLowerCase())&&a.preventDefault();a.stopPropagation();if(this.onMouseDown)this.onMouseDown(a);return!1}};h.prototype.processMouseMove=function(a){this.autoresize&&this.resize();if(this.graph){h.active_canvas=this;this.adjustMouseEvent(a);var b=[a.localX,a.localY],d=[b[0]-this.last_mouse[0],b[1]-this.last_mouse[1]];this.last_mouse=b;this.canvas_mouse= +[a.canvasX,a.canvasY];if(this.dragging_rectangle)this.dragging_rectangle[2]=a.canvasX-this.dragging_rectangle[0],this.dragging_rectangle[3]=a.canvasY-this.dragging_rectangle[1],this.dirty_canvas=!0;else if(this.dragging_canvas)this.offset[0]+=d[0]/this.scale,this.offset[1]+=d[1]/this.scale,this.dirty_bgcanvas=this.dirty_canvas=!0;else if(this.allow_interaction){this.connecting_node&&(this.dirty_canvas=!0);for(var b=this.graph.getNodeOnPos(a.canvasX,a.canvasY,this.visible_nodes),c=0,f=this.graph._nodes.length;c< +f;++c)if(this.graph._nodes[c].mouseOver&&b!=this.graph._nodes[c]){this.graph._nodes[c].mouseOver=!1;if(this.node_over&&this.node_over.onMouseLeave)this.node_over.onMouseLeave(a);this.node_over=null;this.dirty_canvas=!0}if(b){if(!b.mouseOver&&(b.mouseOver=!0,this.node_over=b,this.dirty_canvas=!0,b.onMouseEnter))b.onMouseEnter(a);if(b.onMouseMove)b.onMouseMove(a);if(this.connecting_node&&(f=this._highlight_input||[0,0],!this.isOverNodeBox(b,a.canvasX,a.canvasY))){var n=this.isOverNodeInput(b,a.canvasX, +a.canvasY,f);-1!=n&&b.inputs[n]?l.isValidConnection(this.connecting_output.type,b.inputs[n].type)&&(this._highlight_input=f):this._highlight_input=null}p(a.canvasX,a.canvasY,b.pos[0]+b.size[0]-5,b.pos[1]+b.size[1]-5,5,5)?this.canvas.style.cursor="se-resize":this.canvas.style.cursor=null}else this.canvas.style.cursor=null;if(this.node_capturing_input&&this.node_capturing_input!=b&&this.node_capturing_input.onMouseMove)this.node_capturing_input.onMouseMove(a);if(this.node_dragged&&!this.live_mode){for(c in this.selected_nodes)b= +this.selected_nodes[c],b.pos[0]+=d[0]/this.scale,b.pos[1]+=d[1]/this.scale;this.dirty_bgcanvas=this.dirty_canvas=!0}this.resizing_node&&!this.live_mode&&(this.resizing_node.size[0]+=d[0]/this.scale,this.resizing_node.size[1]+=d[1]/this.scale,d=Math.max(this.resizing_node.inputs?this.resizing_node.inputs.length:0,this.resizing_node.outputs?this.resizing_node.outputs.length:0),this.resizing_node.size[1]this.dragging_rectangle[2]&&(this.dragging_rectangle[0]+=this.dragging_rectangle[2]);0>this.dragging_rectangle[3]&&(this.dragging_rectangle[1]+=this.dragging_rectangle[3]);this.dragging_rectangle[2]=Math.abs(this.dragging_rectangle[2]*this.scale);this.dragging_rectangle[3]=Math.abs(this.dragging_rectangle[3]*this.scale); +for(var f=0;fa.click_time&&this.deselectAllNodes();this.dirty_canvas=!0;this.dragging_canvas=!1;if(this.node_over&&this.node_over.onMouseUp)this.node_over.onMouseUp(a,[a.canvasX-this.node_over.pos[0],a.canvasY-this.node_over.pos[1]]); +if(this.node_capturing_input&&this.node_capturing_input.onMouseUp)this.node_capturing_input.onMouseUp(a,[a.canvasX-this.node_capturing_input.pos[0],a.canvasY-this.node_capturing_input.pos[1]])}else 2==a.which?(this.dirty_canvas=!0,this.dragging_canvas=!1):3==a.which&&(this.dirty_canvas=!0,this.dragging_canvas=!1);this.graph.change();a.stopPropagation();a.preventDefault();return!1}};h.prototype.processMouseWheel=function(a){if(this.graph&&this.allow_dragcanvas){var b=null!=a.wheelDeltaY?a.wheelDeltaY: +-60*a.detail;this.adjustMouseEvent(a);var d=this.scale;0b&&(d*=1/1.1);this.setZoom(d,[a.localX,a.localY]);this.graph.change();a.preventDefault();return!1}};h.prototype.isOverNodeBox=function(a,b,d){var c=l.NODE_TITLE_HEIGHT;return p(b,d,a.pos[0]+2,a.pos[1]+2-c,c-4,c-4)?!0:!1};h.prototype.isOverNodeInput=function(a,b,d,c){if(a.inputs)for(var f=0,n=a.inputs.length;fthis.max_zoom?this.scale=this.max_zoom:this.scaled-this.graph._last_trigger_time)&& +this.drawBackCanvas();(this.dirty_canvas||a)&&this.drawFrontCanvas();this.fps=this.render_time?1/this.render_time:0;this.frame+=1}};h.prototype.drawFrontCanvas=function(){this.ctx||(this.ctx=this.bgcanvas.getContext("2d"));var a=this.ctx;if(a){a.start2D&&a.start2D();var b=this.canvas;a.restore();a.setTransform(1,0,0,1,0,0);this.dirty_area&&(a.save(),a.beginPath(),a.rect(this.dirty_area[0],this.dirty_area[1],this.dirty_area[2],this.dirty_area[3]),a.clip());this.clear_background&&a.clearRect(0,0,b.width, +b.height);this.bgcanvas==this.canvas?this.drawBackCanvas():a.drawImage(this.bgcanvas,0,0);if(this.onRender)this.onRender(b,a);this.show_info&&this.renderInfo(a);if(this.graph){a.save();a.scale(this.scale,this.scale);a.translate(this.offset[0],this.offset[1]);for(var b=this.computeVisibleNodes(null,this.visible_nodes),d=0;db-k._last_time&&(g=2-0.002*(b-k._last_time),m="rgba(255,255,255, "+ +g.toFixed(2)+")",this.renderLink(a,p,f.getConnectionPos(!0,h),k,!0,g,m))}}}}a.globalAlpha=1};h.prototype.renderLink=function(a,b,c,e,f,g,k){if(this.highquality_render){var t=m(b,c);this.render_connections_border&&0.6b[1]?0:Math.PI,a.save(),a.translate(e[0],e[1]),a.rotate(k),a.beginPath(),a.moveTo(-5,-5),a.lineTo(0,5),a.lineTo(5,-5),a.fill(),a.restore());if(g)for(g=0;5>g;++g)e=(0.001*l.getTime()+0.2*g)%1,e=this.computeConnectionPoint(b,c,e),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()};h.prototype.computeConnectionPoint=function(a,b,c){var e=m(a,b),f=[a[0]+0.25*e,a[1]],e=[b[0]-0.25*e,b[1]],h=(1- +c)*(1-c)*(1-c),k=3*(1-c)*(1-c)*c,g=3*(1-c)*c*c;c*=c*c;return[h*a[0]+k*f[0]+g*e[0]+c*b[0],h*a[1]+k*f[1]+g*e[1]+c*b[1]]};h.prototype.guiButton=function(a,b,c,e){e=this.gui_mouse;var f=e.clicked&&e.position[0]>=b[0]&&e.position[1]>=b[1]&&e.position[0] +c&&0.01>b.editor_alpha&&(clearInterval(e),1>c&&(b.live_mode=!0));1"+p+""+a+"",value:p});if(m.length)return new l.ContextMenu(m,{event:c,callback:g,parentMenu:e,allow_html:!0,node:f},b),!1}};h.decodeHTML=function(a){var b=document.createElement("div");b.innerText=a;return b.innerHTML};h.onResizeNode=function(a,b,c,e,f){f&&(f.size=f.computeSize(),f.setDirtyCanvas(!0,!0))};h.onShowTitleEditor=function(a,b,c,e,f){function g(){f.title=m.value; +k.parentNode.removeChild(k);f.setDirtyCanvas(!0,!0)}var k=document.createElement("div");k.className="graphdialog";k.innerHTML="Title";var m=k.querySelector("input");m&&(m.value=f.title,m.addEventListener("keydown",function(a){13==a.keyCode&&(g(),a.preventDefault(),a.stopPropagation())}));a=h.active_canvas.canvas;b=a.getBoundingClientRect();e=c=-20;b&&(c-=b.left,e-=b.top);event?(k.style.left=event.pageX+c+"px", +k.style.top=event.pageY+e+"px"):(k.style.left=0.5*a.width+c+"px",k.style.top=0.5*a.height+e+"px");k.querySelector("button").addEventListener("click",g);a.parentNode.appendChild(k)};h.prototype.showEditPropertyValue=function(a,b,c){function e(){f(q.value)}function f(c){"number"==typeof a.properties[b]&&(c=Number(c));a.properties[b]=c;if(a.onPropertyChanged)a.onPropertyChanged(b,c);p.close();a.setDirtyCanvas(!0,!0)}if(a&&void 0!==a.properties[b]){c=c||{};var h="string";null!==a.properties[b]&&(h=typeof a.properties[b]); +var k=null;a.getPropertyInfo&&(k=a.getPropertyInfo(b));if(a.properties_info)for(var g=0;g";else if("enum"==h&&k.values){m=""}else"boolean"==h&&(m="");var p=this.createDialog(""+b+""+m+"",c);if("enum"==h&&k.values){var q=p.querySelector("select");q.addEventListener("change",function(a){f(a.target.value)})}else if("boolean"==h)(q=p.querySelector("input"))&&q.addEventListener("click",function(a){f(!!q.checked)});else if(q=p.querySelector("input"))q.value= +void 0!==a.properties[b]?a.properties[b]:"",q.addEventListener("keydown",function(a){13==a.keyCode&&(e(),a.preventDefault(),a.stopPropagation())});p.querySelector("button").addEventListener("click",e)}};h.prototype.createDialog=function(a,b){b=b||{};var c=document.createElement("div");c.className="graphdialog";c.innerHTML=a;var e=this.canvas.getBoundingClientRect(),f=-20,h=-20;e&&(f-=e.left,h-=e.top);b.position?(f+=b.position[0],h+=b.position[1]):b.event?(f+=b.event.pageX,h+=b.event.pageY):(f+=0.5* +this.canvas.width,h+=0.5*this.canvas.height);c.style.left=f+"px";c.style.top=h+"px";this.canvas.parentNode.appendChild(c);c.close=function(){this.parentNode&&this.parentNode.removeChild(this)};return c};h.onMenuNodeCollapse=function(a,b,c,e,f){f.flags.collapsed=!f.flags.collapsed;f.setDirtyCanvas(!0,!0)};h.onMenuNodePin=function(a,b,c,e,f){f.pin()};h.onMenuNodeMode=function(a,b,c,e,f){new l.ContextMenu(["Always","On Event","On Trigger","Never"],{event:c,callback:function(a){if(f)switch(a){case "On Event":f.mode= +l.ON_EVENT;break;case "On Trigger":f.mode=l.ON_TRIGGER;break;case "Never":f.mode=l.NEVER;break;default:f.mode=l.ALWAYS}},parentMenu:e,node:f});return!1};h.onMenuNodeColors=function(a,b,c,e,f){if(!f)throw"no node for color";b=[];for(var g in h.node_colors)a=h.node_colors[g],a={value:g,content:""+g+""},b.push(a);new l.ContextMenu(b,{event:c,callback:function(a){f&&(a=h.node_colors[a.value])&&(f.color=a.color,f.bgcolor= +a.bgcolor,f.setDirtyCanvas(!0))},parentMenu:e,node:f});return!1};h.onMenuNodeShapes=function(a,b,c,e,f){if(!f)throw"no node passed";new l.ContextMenu(l.VALID_SHAPES,{event:c,callback:function(a){f&&(f.shape=a,f.setDirtyCanvas(!0))},parentMenu:e,node:f});return!1};h.onMenuNodeRemove=function(a,b,c,e,f){if(!f)throw"no node passed";!1!=f.removable&&(f.graph.remove(f),f.setDirtyCanvas(!0,!0))};h.onMenuNodeClone=function(a,b,c,e,f){!1!=f.clonable&&(a=f.clone())&&(a.pos=[f.pos[0]+5,f.pos[1]+5],f.graph.add(a), +f.setDirtyCanvas(!0,!0))};h.node_colors={red:{color:"#FAA",bgcolor:"#944"},green:{color:"#AFA",bgcolor:"#494"},blue:{color:"#AAF",bgcolor:"#449"},cyan:{color:"#AFF",bgcolor:"#499"},purple:{color:"#FAF",bgcolor:"#949"},yellow:{color:"#FFA",bgcolor:"#994"},black:{color:"#777",bgcolor:"#000"},white:{color:"#FFF",bgcolor:"#AAA"}};h.prototype.getCanvasMenuOptions=function(){var a=null;this.getMenuOptions?a=this.getMenuOptions():(a=[{content:"Add Node",has_submenu:!0,callback:h.onMenuAdd}],this._graph_stack&& +0Name",f),g=h.querySelector("input");h.querySelector("button").addEventListener("click",function(b){if(g.value){if(b=k.input?a.getInputInfo(k.slot):a.getOutputInfo(k.slot))b.label=g.value;c.setDirty(!0)}h.close()})}},node:a},k=null;a&&(k=a.getSlotInPosition(b.canvasX, +b.canvasY),h.active_node=a);k?(f=[],f.push(k.locked?"Cannot remove":{content:"Remove Slot",slot:k}),f.push({content:"Rename Slot",slot:k}),g.title=(k.input?k.input.type:k.output.type)||"*",k.input&&k.input.type==l.ACTION&&(g.title="Action"),k.output&&k.output.type==l.EVENT&&(g.title="Event")):f=a?this.getNodeMenuOptions(a):this.getCanvasMenuOptions();f&&new l.ContextMenu(f,g,e)};this.CanvasRenderingContext2D&&(CanvasRenderingContext2D.prototype.roundRect=function(a,b,c,e,f,h){void 0===f&&(f=5);void 0=== +h&&(h=f);this.beginPath();this.moveTo(a+f,b);this.lineTo(a+c-f,b);this.quadraticCurveTo(a+c,b,a+c,b+f);this.lineTo(a+c,b+e-h);this.quadraticCurveTo(a+c,b+e,a+c-h,b+e);this.lineTo(a+h,b+e);this.quadraticCurveTo(a,b+e,a,b+e-h);this.lineTo(a,b+f);this.quadraticCurveTo(a,b,a+f,b)});l.compareObjects=function(a,b){for(var c in a)if(a[c]!=b[c])return!1;return!0};l.distance=m;l.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")+")"};l.isInsideRectangle=p;l.growBounding=function(a,b,c){ba[2]&&(a[2]=b);ca[3]&&(a[3]=c)};l.isInsideBounding=function(a,b){return a[0]b[1][0]||a[1]>b[1][1]?!1:!0};l.overlapBounding=q;l.hex2num=function(a){"#"==a.charAt(0)&&(a=a.slice(1));a=a.toUpperCase();for(var b=Array(3),c=0,e,f,h=0;6>h;h+=2)e="0123456789ABCDEF".indexOf(a.charAt(h)),f="0123456789ABCDEF".indexOf(a.charAt(h+1)),b[c]=16*e+f,c++;return b}; +l.num2hex=function(a){for(var b="#",c,e,f=0;3>f;f++)c=a[f]/16,e=a[f]%16,b+="0123456789ABCDEF".charAt(c)+"0123456789ABCDEF".charAt(e);return b};r.prototype.addItem=function(a,b,c){function e(a){var b=this.value;b&&b.has_submenu&&f.call(this,a)}function f(a){var b=this.value,e=!0;h.current_submenu&&h.current_submenu.close(a);if(c.callback){var f=c.callback.call(this,b,c,a,h,c.node);!0===f&&(e=!1)}if(b&&(b.callback&&!c.ignore_item_callbacks&&!0!==b.disabled&&(f=b.callback.call(this,b,c,a,h,c.node),!0=== +f&&(e=!1)),b.submenu)){if(!b.submenu.options)throw"ContextMenu submenu needs options";new h.constructor(b.submenu.options,{callback:b.submenu.callback,event:a,parentMenu:h,ignore_item_callbacks:b.submenu.ignore_item_callbacks,title:b.submenu.title,autoopen:c.autoopen});e=!1}e&&!h.lock&&h.close()}var h=this;c=c||{};var k=document.createElement("div");k.className="litemenu-entry submenu";var g=!1;if(null===b)k.classList.add("separator");else{k.innerHTML=b&&b.title?b.title:a;if(k.value=b)b.disabled&& +(g=!0,k.classList.add("disabled")),(b.submenu||b.has_submenu)&&k.classList.add("has_submenu");"function"==typeof b?(k.dataset.value=a,k.onclick_callback=b):k.dataset.value=b;b.className&&(k.className+=" "+b.className)}this.root.appendChild(k);g||k.addEventListener("click",f);c.autoopen&&k.addEventListener("mouseenter",e);return k};r.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&&!r.isCursorOverElement(a,this.parentMenu.root)&&r.trigger(this.parentMenu.root,"mouseleave",a));this.current_submenu&&this.current_submenu.close(a,!0)};r.trigger=function(a,b,c,e){var f=document.createEvent("CustomEvent");f.initCustomEvent(b,!0,!0,c);f.srcElement=e;a.dispatchEvent?a.dispatchEvent(f):a.__events&&a.__events.dispatchEvent(f);return f};r.prototype.getTopMenu=function(){return this.options.parentMenu?this.options.parentMenu.getTopMenu():this}; +r.prototype.getFirstEvent=function(){return this.options.parentMenu?this.options.parentMenu.getFirstEvent():this.options.event};r.isCursorOverElement=function(a,b){var c=a.pageX,e=a.pageY,f=b.getBoundingClientRect();return f?e>f.top&&ef.left&&ca?b:c= rect[0] && mouse.position[1] >= rect[1] && mouse.position[0] < rect[0] + rect[2] && mouse.position[1] < rect[1] + rect[3]; + //if(mouse_over) this.setDirty(true,false); + var clicked = mouse.node == this.current_node && mouse.clicked && mouse_over; + + ctx.fillStyle = clicked ? "#AAA" : ( mouse_over ? "#555" : "#333" ); + ctx.fillRect( rect[0], rect[1], rect[2], rect[3] ); + ctx.strokeStyle = "#AAA"; + ctx.strokeRect( rect[0] + 0.5, rect[1] + 0.5, rect[2], rect[3] ); + ctx.textAlign = "center"; + ctx.fillStyle = clicked ? "#000" : "#AAA"; + ctx.fillText( text, rect[0] + rect[2] * 0.5, rect[1] + rect[3] * 0.75 ); + + if(clicked) + { + mouse.blocked = true; + if(callback) + setTimeout( function(){ callback(this.current_node,text,mouse); }),1; + } +} + /* LGraphCanvas.prototype.resizeCanvas = function(width,height) { @@ -5660,6 +5741,154 @@ LGraphCanvas.onShowTitleEditor = function( value, options, e, menu, node ) } } +LGraphCanvas.prototype.showSearchBox = function(event) +{ + var that = this; + var input_html = ""; + + var dialog = document.createElement("div"); + dialog.className = "graphdialog"; + dialog.innerHTML = "Search
"; + dialog.close = function() + { + that.search_box = null; + dialog.parentNode.removeChild( dialog ); + } + + dialog.addEventListener("mouseleave",function(e){ + dialog.close(); + }); + + if(that.search_box) + that.search_box.close(); + that.search_box = dialog; + + var helper = dialog.querySelector(".helper"); + + var first = null; + var timeout = null; + var selected = null; + + var input = dialog.querySelector("input"); + if(input) + { + input.addEventListener("keydown", function(e){ + + if(e.keyCode == 38) //UP + changeSelection(false); + else if(e.keyCode == 40) //DOWN + changeSelection(true); + else if(e.keyCode == 27) //ESC + dialog.close(); + else if(e.keyCode == 13) + { + if(selected) + select( selected.innerHTML ) + else if(first) + select(first); + else + dialog.close(); + } + else + { + if(timeout) + clearInterval(timeout); + timeout = setTimeout( refreshHelper, 10 ); + return; + } + e.preventDefault(); + e.stopPropagation(); + }); + } + + var graphcanvas = LGraphCanvas.active_canvas; + var canvas = graphcanvas.canvas; + + var rect = canvas.getBoundingClientRect(); + var offsetx = -20; + var offsety = -20; + if(rect) + { + offsetx -= rect.left; + offsety -= rect.top; + } + + if( event ) + { + dialog.style.left = (event.pageX + offsetx) + "px"; + dialog.style.top = (event.pageY + offsety)+ "px"; + } + else + { + dialog.style.left = (canvas.width * 0.5 + offsetx) + "px"; + dialog.style.top = (canvas.height * 0.5 + offsety) + "px"; + } + + canvas.parentNode.appendChild( dialog ); + input.focus(); + + function select( name ) + { + if(name) + { + if( that.onSearchBoxSelection ) + that.onSearchBoxSelection( name, event, graphcanvas ); + else + { + var node = LiteGraph.createNode( name ); + if(node) + { + node.pos = graphcanvas.convertEventToCanvas( event ); + graphcanvas.graph.add( node ); + } + } + } + + dialog.close(); + } + + function changeSelection( forward ) + { + if(selected) + selected.classList.remove("selected"); + if(!selected) + selected = helper.childNodes[0]; + else + selected = forward ? selected.nextSibling : selected.previousSibling; + if(!selected) + return; + selected.classList.add("selected"); + } + + function refreshHelper() + { + timeout = null; + var str = input.value; + first = null; + helper.innerHTML = ""; + if(!str) + return; + + if( that.onSearchBox ) + that.onSearchBox( help, str, graphcanvas ); + else + for( var i in LiteGraph.registered_node_types ) + if(i.indexOf(str) != -1) + { + var help = document.createElement("div"); + if(!first) first = i; + help.innerText = i; + help.className = "help-item"; + help.addEventListener("click", function(e){ + select( this.innerText ); + }); + helper.appendChild(help); + } + } + + return dialog; +} + LGraphCanvas.prototype.showEditPropertyValue = function( node, property, options ) { if(!node || node.properties[ property ] === undefined ) @@ -5760,7 +5989,8 @@ LGraphCanvas.prototype.showEditPropertyValue = function( node, property, options if(typeof( node.properties[ property ] ) == "number") value = Number(value); node.properties[ property ] = value; - + if(node._graph) + node._graph._version++; if(node.onPropertyChanged) node.onPropertyChanged( property, value ); dialog.close(); diff --git a/src/nodes/base.js b/src/nodes/base.js index ef9d59395c..93219c93a0 100755 --- a/src/nodes/base.js +++ b/src/nodes/base.js @@ -25,7 +25,7 @@ LiteGraph.registerNodeType("basic/time", Time); function Subgraph() { var that = this; - this.size = [120,60]; + this.size = [120,80]; //create inner graph this.subgraph = new LGraph(); @@ -40,7 +40,7 @@ function Subgraph() this.subgraph.onGlobalOutputRenamed = this.onSubgraphRenamedGlobalOutput.bind(this); this.subgraph.onGlobalOutputTypeChanged = this.onSubgraphTypeChangeGlobalOutput.bind(this); - this.bgcolor = "#663"; + this.bgcolor = "#353"; } Subgraph.title = "Subgraph"; @@ -107,6 +107,19 @@ Subgraph.prototype.getExtraMenuOptions = function(graphcanvas) }]; } +Subgraph.prototype.onDrawForeground = function( ctx, graphcanvas ) +{ + var node = this; + ctx.globalAlpha = 0.75; + graphcanvas.guiButton(ctx, [0,this.size[1] - 20,this.size[0],19], "Open", function(){ graphcanvas.openSubgraph(node.subgraph); }); + ctx.globalAlpha = 1; +} + +Subgraph.prototype.onResize = function(size) +{ + size[1] += 20; +} + Subgraph.prototype.onExecute = function() { //send inputs to subgraph global inputs diff --git a/src/nodes/interface.js b/src/nodes/interface.js index 1c5e6e08eb..1d0233d625 100755 --- a/src/nodes/interface.js +++ b/src/nodes/interface.js @@ -115,6 +115,7 @@ var LiteGraph = global.LiteGraph; if(local_pos[0] > 1 && local_pos[1] > 1 && local_pos[0] < (this.size[0] - 2) && local_pos[1] < (this.size[1] - 2) ) { this.properties.value = !this.properties.value; + this.graph._version++; this.trigger( "e", this.properties.value ); return true; } @@ -202,6 +203,7 @@ var LiteGraph = global.LiteGraph; var v = Math.clamp( this.properties.value + steps * this.properties.step, this.properties.min, this.properties.max ); this.properties.value = v; + this.graph._version++; this.setDirtyCanvas(true); } @@ -211,6 +213,7 @@ var LiteGraph = global.LiteGraph; { var steps = pos[1] > this.size[1] * 0.5 ? -1 : 1; this.properties.value = Math.clamp( this.properties.value + steps * this.properties.step, this.properties.min, this.properties.max ); + this.graph._version++; this.setDirtyCanvas(true); }