Defined in
- ../src/litegraph.js:196
+ ../src/litegraph.js:226
@@ -406,7 +410,7 @@
diff --git a/doc/data.json b/doc/data.json
index a8d3cd4c1..57ea0a337 100644
--- a/doc/data.json
+++ b/doc/data.json
@@ -39,7 +39,7 @@
"plugin_for": [],
"extension_for": [],
"file": "../src/litegraph.js",
- "line": 328,
+ "line": 378,
"description": "LGraph is the class that contain a full graph. We instantiate one and add nodes to it, and then we can run the execution loop.",
"is_constructor": 1
},
@@ -52,7 +52,7 @@
"plugin_for": [],
"extension_for": [],
"file": "../src/litegraph.js",
- "line": 1379,
+ "line": 1487,
"description": "Base Class for all the node type classes",
"params": [
{
@@ -71,7 +71,7 @@
"plugin_for": [],
"extension_for": [],
"file": "../src/litegraph.js",
- "line": 3074,
+ "line": 3203,
"description": "marks as dirty the canvas, this way it will be rendered again",
"is_constructor": 1,
"params": [
@@ -102,7 +102,7 @@
"plugin_for": [],
"extension_for": [],
"file": "../src/litegraph.js",
- "line": 5814,
+ "line": 6083,
"description": "ContextMenu from LiteGUI",
"is_constructor": 1,
"params": [
@@ -144,6 +144,36 @@
{
"file": "../src/litegraph.js",
"line": 135,
+ "description": "Create a new node type by passing a function, it wraps it with a propper class and generates inputs according to the parameters of the function.\nUseful to wrap simple methods that do not require properties, and that only process some input to generate an output.",
+ "itemtype": "method",
+ "name": "wrapFunctionAsNode",
+ "params": [
+ {
+ "name": "name",
+ "description": "node name with namespace (p.e.: 'math/sum')",
+ "type": "String"
+ },
+ {
+ "name": "func",
+ "description": "",
+ "type": "Function"
+ },
+ {
+ "name": "param_types",
+ "description": "[optional] an array containing the type of every parameter, otherwise parameters will accept any type",
+ "type": "Array"
+ },
+ {
+ "name": "return_type",
+ "description": "[optional] string with the return type, otherwise it will be generic",
+ "type": "String"
+ }
+ ],
+ "class": "LiteGraph"
+ },
+ {
+ "file": "../src/litegraph.js",
+ "line": 165,
"description": "Adds this method to all nodetypes, existing and to be created\n(You can add it to LGraphNode.prototype but then existing node types wont have it)",
"itemtype": "method",
"name": "addNodeMethod",
@@ -158,7 +188,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 153,
+ "line": 183,
"description": "Create a node of a given type with a name. The node is not attached to any graph yet.",
"itemtype": "method",
"name": "createNode",
@@ -183,7 +213,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 196,
+ "line": 226,
"description": "Returns a registered node type with a given name",
"itemtype": "method",
"name": "getNodeType",
@@ -202,7 +232,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 209,
+ "line": 239,
"description": "Returns a list of node types matching one category",
"itemtype": "method",
"name": "getNodeType",
@@ -221,7 +251,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 231,
+ "line": 261,
"description": "Returns a list with all the node type categories",
"itemtype": "method",
"name": "getNodeTypesCategories",
@@ -233,7 +263,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 352,
+ "line": 404,
"description": "Removes all nodes from this graph",
"itemtype": "method",
"name": "clear",
@@ -241,7 +271,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 401,
+ "line": 453,
"description": "Attach Canvas to this graph",
"itemtype": "method",
"name": "attachCanvas",
@@ -256,7 +286,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 420,
+ "line": 472,
"description": "Detach Canvas from this graph",
"itemtype": "method",
"name": "detachCanvas",
@@ -271,7 +301,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 438,
+ "line": 490,
"description": "Starts running this graph every interval milliseconds.",
"itemtype": "method",
"name": "start",
@@ -286,7 +316,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 466,
+ "line": 518,
"description": "Stops the execution loop of the graph",
"itemtype": "method",
"name": "stop execution",
@@ -294,7 +324,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 488,
+ "line": 540,
"description": "Run N steps (cycles) of the graph",
"itemtype": "method",
"name": "runStep",
@@ -309,7 +339,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 567,
+ "line": 619,
"description": "Updates the graph execution order according to relevance of the nodes (nodes with only outputs have more relevance than\nnodes with only inputs.",
"itemtype": "method",
"name": "updateExecutionOrder",
@@ -317,7 +347,15 @@
},
{
"file": "../src/litegraph.js",
- "line": 671,
+ "line": 736,
+ "description": "Positions every node in a more readable manner",
+ "itemtype": "method",
+ "name": "arrange",
+ "class": "LGraph"
+ },
+ {
+ "file": "../src/litegraph.js",
+ "line": 780,
"description": "Returns the amount of time the graph has been running in milliseconds",
"itemtype": "method",
"name": "getTime",
@@ -329,7 +367,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 682,
+ "line": 790,
"description": "Returns the amount of time accumulated using the fixedtime_lapse var. This is used in context where the time increments should be constant",
"itemtype": "method",
"name": "getFixedTime",
@@ -341,7 +379,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 693,
+ "line": 801,
"description": "Returns the amount of time it took to compute the latest iteration. Take into account that this number could be not correct\nif the nodes are using graphical actions",
"itemtype": "method",
"name": "getElapsedTime",
@@ -353,7 +391,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 705,
+ "line": 813,
"description": "Sends an event to all the nodes, useful to trigger stuff",
"itemtype": "method",
"name": "sendEventToAllNodes",
@@ -373,7 +411,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 748,
+ "line": 856,
"description": "Adds a new node instasnce to this graph",
"itemtype": "method",
"name": "add",
@@ -388,7 +426,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 804,
+ "line": 912,
"description": "Removes a node from the graph",
"itemtype": "method",
"name": "remove",
@@ -403,7 +441,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 873,
+ "line": 981,
"description": "Returns a node by its id.",
"itemtype": "method",
"name": "getNodeById",
@@ -418,7 +456,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 886,
+ "line": 994,
"description": "Returns a list of nodes that matches a class",
"itemtype": "method",
"name": "findNodesByClass",
@@ -437,7 +475,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 902,
+ "line": 1010,
"description": "Returns a list of nodes that matches a type",
"itemtype": "method",
"name": "findNodesByType",
@@ -456,7 +494,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 919,
+ "line": 1027,
"description": "Returns a list of nodes that matches a name",
"itemtype": "method",
"name": "findNodesByName",
@@ -475,7 +513,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 935,
+ "line": 1043,
"description": "Returns the top-most node in this position of the canvas",
"itemtype": "method",
"name": "getNodeOnPos",
@@ -504,7 +542,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 1122,
+ "line": 1230,
"description": "Assigns a value to all the nodes that matches this name. This is used to create global variables of the node that\ncan be easily accesed from the outside of the graph",
"itemtype": "method",
"name": "setInputData",
@@ -524,7 +562,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 1137,
+ "line": 1245,
"description": "Returns the value of the first node with this name. This is used to access global variables of the graph from the outside",
"itemtype": "method",
"name": "setInputData",
@@ -543,7 +581,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 1177,
+ "line": 1285,
"description": "returns if the graph is in live mode",
"itemtype": "method",
"name": "isLive",
@@ -551,7 +589,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 1214,
+ "line": 1322,
"description": "Creates a Object containing all the info about this graph, it can be serialized",
"itemtype": "method",
"name": "serialize",
@@ -563,7 +601,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 1247,
+ "line": 1355,
"description": "Configure a graph from a JSON string",
"itemtype": "method",
"name": "configure",
@@ -578,7 +616,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 1432,
+ "line": 1542,
"description": "configure a node from an object containing the serialized info",
"itemtype": "method",
"name": "configure",
@@ -586,7 +624,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 1528,
+ "line": 1638,
"description": "serialize the content",
"itemtype": "method",
"name": "serialize",
@@ -594,7 +632,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 1604,
+ "line": 1714,
"description": "serialize and stringify",
"itemtype": "method",
"name": "toString",
@@ -602,7 +640,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 1616,
+ "line": 1726,
"description": "get the title string",
"itemtype": "method",
"name": "getTitle",
@@ -610,7 +648,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 1629,
+ "line": 1739,
"description": "sets the output data",
"itemtype": "method",
"name": "setOutputData",
@@ -630,7 +668,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 1665,
+ "line": 1775,
"description": "retrieves the input data (data traveling through the connection) from one slot",
"itemtype": "method",
"name": "getInputData",
@@ -654,7 +692,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 1701,
+ "line": 1811,
"description": "tells you if there is a connection in one input slot",
"itemtype": "method",
"name": "isInputConnected",
@@ -673,7 +711,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 1714,
+ "line": 1824,
"description": "tells you info about an input connection (which node, type, etc)",
"itemtype": "method",
"name": "getInputInfo",
@@ -692,7 +730,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 1729,
+ "line": 1839,
"description": "returns the node connected in the input slot",
"itemtype": "method",
"name": "getInputNode",
@@ -711,7 +749,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 1750,
+ "line": 1860,
"description": "tells you the last output data that went in that slot",
"itemtype": "method",
"name": "getOutputData",
@@ -730,7 +768,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 1768,
+ "line": 1878,
"description": "tells you info about an output connection (which node, type, etc)",
"itemtype": "method",
"name": "getOutputInfo",
@@ -749,7 +787,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 1784,
+ "line": 1894,
"description": "tells you if there is a connection in one output slot",
"itemtype": "method",
"name": "isOutputConnected",
@@ -768,7 +806,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 1797,
+ "line": 1907,
"description": "retrieves all the nodes connected to this output slot",
"itemtype": "method",
"name": "getOutputNodes",
@@ -787,7 +825,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 1830,
+ "line": 1940,
"description": "Triggers an event in this node, this will trigger any output with the same name",
"itemtype": "method",
"name": "trigger",
@@ -807,7 +845,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 1853,
+ "line": 1963,
"description": "Triggers an slot event in this node",
"itemtype": "method",
"name": "triggerSlot",
@@ -827,7 +865,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 1900,
+ "line": 2010,
"description": "add a new property to this node",
"itemtype": "method",
"name": "addProperty",
@@ -857,7 +895,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 1926,
+ "line": 2036,
"description": "add a new output slot to use in this node",
"itemtype": "method",
"name": "addOutput",
@@ -882,7 +920,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 1949,
+ "line": 2059,
"description": "add a new output slot to use in this node",
"itemtype": "method",
"name": "addOutputs",
@@ -897,7 +935,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 1974,
+ "line": 2084,
"description": "remove an existing output slot",
"itemtype": "method",
"name": "removeOutput",
@@ -912,7 +950,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 1988,
+ "line": 2098,
"description": "add a new input slot to use in this node",
"itemtype": "method",
"name": "addInput",
@@ -937,7 +975,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 2012,
+ "line": 2122,
"description": "add several new input slots in this node",
"itemtype": "method",
"name": "addInputs",
@@ -952,7 +990,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 2037,
+ "line": 2147,
"description": "remove an existing input slot",
"itemtype": "method",
"name": "removeInput",
@@ -967,7 +1005,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 2051,
+ "line": 2161,
"description": "add an special connection to this node (used for special kinds of graphs)",
"itemtype": "method",
"name": "addConnection",
@@ -997,7 +1035,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 2072,
+ "line": 2182,
"description": "computes the size of a node according to its inputs and output slots",
"itemtype": "method",
"name": "computeSize",
@@ -1016,8 +1054,8 @@
},
{
"file": "../src/litegraph.js",
- "line": 2123,
- "description": "returns the bounding of the object, used for rendering purposes",
+ "line": 2233,
+ "description": "returns the bounding of the object, used for rendering purposes\nbounding is: [topleft_cornerx, topleft_cornery, width, height]",
"itemtype": "method",
"name": "getBounding",
"return": {
@@ -1028,7 +1066,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 2133,
+ "line": 2249,
"description": "checks if a point is inside the shape of a node",
"itemtype": "method",
"name": "isPointInsideNode",
@@ -1052,7 +1090,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 2157,
+ "line": 2273,
"description": "checks if a point is inside a node slot, and returns info about which slot",
"itemtype": "method",
"name": "getSlotInPosition",
@@ -1076,7 +1114,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 2188,
+ "line": 2304,
"description": "returns the input slot with a given name (used for dynamic slots), -1 if not found",
"itemtype": "method",
"name": "findInputSlot",
@@ -1095,7 +1133,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 2204,
+ "line": 2320,
"description": "returns the output slot with a given name (used for dynamic slots), -1 if not found",
"itemtype": "method",
"name": "findOutputSlot",
@@ -1114,7 +1152,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 2219,
+ "line": 2335,
"description": "connect this node output to the input of another node",
"itemtype": "method",
"name": "connect",
@@ -1143,7 +1181,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 2337,
+ "line": 2453,
"description": "disconnect one output to an specific node",
"itemtype": "method",
"name": "disconnectOutput",
@@ -1167,7 +1205,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 2427,
+ "line": 2543,
"description": "disconnect one input",
"itemtype": "method",
"name": "disconnectInput",
@@ -1186,7 +1224,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 2496,
+ "line": 2611,
"description": "returns the center of a connection point in canvas coords",
"itemtype": "method",
"name": "getConnectionPos",
@@ -1210,7 +1248,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 2630,
+ "line": 2745,
"description": "Collapse the node to make it smaller on the canvas",
"itemtype": "method",
"name": "collapse",
@@ -1218,7 +1256,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 2643,
+ "line": 2758,
"description": "Forces the node to do not move or realign on Z",
"itemtype": "method",
"name": "pin",
@@ -1226,7 +1264,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 2733,
+ "line": 2852,
"description": "clears all the data inside",
"itemtype": "method",
"name": "clear",
@@ -1234,7 +1272,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 2768,
+ "line": 2891,
"description": "assigns a graph, you can reasign graphs to the same canvas",
"itemtype": "method",
"name": "setGraph",
@@ -1249,7 +1287,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 2799,
+ "line": 2922,
"description": "opens a graph contained inside a node in the current graph",
"itemtype": "method",
"name": "openSubgraph",
@@ -1264,7 +1302,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 2826,
+ "line": 2949,
"description": "closes a subgraph contained inside a node",
"itemtype": "method",
"name": "closeSubgraph",
@@ -1279,7 +1317,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 2842,
+ "line": 2966,
"description": "assigns a canvas",
"itemtype": "method",
"name": "setCanvas",
@@ -1294,7 +1332,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 3090,
+ "line": 3219,
"description": "Used to attach the canvas in a popup",
"itemtype": "method",
"name": "getCanvasWindow",
@@ -1306,7 +1344,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 3104,
+ "line": 3233,
"description": "starts rendering the content of the canvas when needed",
"itemtype": "method",
"name": "startRendering",
@@ -1314,7 +1352,7 @@
},
{
"file": "../src/litegraph.js",
- "line": 3128,
+ "line": 3257,
"description": "stops rendering the content of the canvas (to save resources)",
"itemtype": "method",
"name": "stopRendering",
diff --git a/doc/files/.._src_litegraph.js.html b/doc/files/.._src_litegraph.js.html
index 159b941e9..0eda72bcf 100644
--- a/doc/files/.._src_litegraph.js.html
+++ b/doc/files/.._src_litegraph.js.html
@@ -126,7 +126,7 @@ var LiteGraph = global.LiteGraph = {
DEFAULT_POSITION: [100,100],//default node position
node_images_path: "",
- VALID_SHAPES: ["box","round","circle"],
+ VALID_SHAPES: ["box","round"], //,"circle"
BOX_SHAPE: 1,
ROUND_SHAPE: 2,
@@ -218,6 +218,36 @@ var LiteGraph = global.LiteGraph = {
}
},
+ /**
+ * Create a new node type by passing a function, it wraps it with a propper class and generates inputs according to the parameters of the function.
+ * Useful to wrap simple methods that do not require properties, and that only process some input to generate an output.
+ * @method wrapFunctionAsNode
+ * @param {String} name node name with namespace (p.e.: 'math/sum')
+ * @param {Function} func
+ * @param {Array} param_types [optional] an array containing the type of every parameter, otherwise parameters will accept any type
+ * @param {String} return_type [optional] string with the return type, otherwise it will be generic
+ */
+ wrapFunctionAsNode: function( name, func, param_types, return_type )
+ {
+ var params = Array(func.length);
+ var code = "";
+ var names = LiteGraph.getParameterNames( func );
+ for(var i = 0; i < names.length; ++i)
+ code += "this.addInput('"+names[i]+"',"+(param_types && param_types[i] ? "'" + param_types[i] + "'" : "0") + ");\n";
+ code += "this.addOutput('out',"+( return_type ? "'" + return_type + "'" : 0 )+");\n";
+ var classobj = Function(code);
+ classobj.title = name.split("/").pop();
+ classobj.desc = "Generated from " + func.name;
+ classobj.prototype.onExecute = function onExecute()
+ {
+ for(var i = 0; i < params.length; ++i)
+ params[i] = this.getInputData(i);
+ var r = func.apply( this, params );
+ this.setOutputData(0,r);
+ }
+ this.registerNodeType( name, classobj );
+ },
+
/**
* Adds this method to all nodetypes, existing and to be created
* (You can add it to LGraphNode.prototype but then existing node types wont have it)
@@ -258,7 +288,7 @@ var LiteGraph = global.LiteGraph = {
title = title || base_class.title || type;
- var node = new base_class( name );
+ var node = new base_class( title );
node.type = type;
if(!node.title) node.title = title;
@@ -391,16 +421,36 @@ var LiteGraph = global.LiteGraph = {
if( !type_a || //generic output
!type_b || //generic input
type_a == type_b || //same type (is valid for triggers)
- (type_a !== LiteGraph.EVENT && type_b !== LiteGraph.EVENT && type_a.toLowerCase() == type_b.toLowerCase()) ) //same type
- return true;
+ type_a == LiteGraph.EVENT && type_b == LiteGraph.ACTION )
+ return true;
+
+ type_a = type_a.toLowerCase();
+ type_b = type_b.toLowerCase();
+ if( type_a.indexOf(",") == -1 && type_b.indexOf(",") == -1 )
+ return type_a == type_b;
+
+ var supported_types_a = type_a.split(",");
+ var supported_types_b = type_b.split(",");
+ for(var i = 0; i < supported_types_a.length; ++i)
+ for(var j = 0; j < supported_types_b.length; ++j)
+ if( supported_types_a[i] == supported_types_b[i] )
+ return true;
return false;
}
};
+//timer that works everywhere
if(typeof(performance) != "undefined")
- LiteGraph.getTime = function getTime() { return performance.now(); }
+ LiteGraph.getTime = performance.now.bind(performance);
+else if(typeof(Date) != "undefined" && Date.now)
+ LiteGraph.getTime = Date.now.bind(Date);
+else if(typeof(process) != "undefined")
+ LiteGraph.getTime = function(){
+ var t = process.hrtime();
+ return t[0]*0.001 + t[1]*(1e-6);
+ }
else
- LiteGraph.getTime = function getTime() { return Date.now(); }
+ LiteGraph.getTime = function getTime() { return (new Date).getTime(); }
@@ -418,7 +468,7 @@ else
* @constructor
*/
-global.LGraph = LiteGraph.LGraph = function LGraph()
+function LGraph()
{
if (LiteGraph.debug)
console.log("Graph created");
@@ -426,6 +476,8 @@ global.LGraph = LiteGraph.LGraph = function LGraph()
this.clear();
}
+global.LGraph = LiteGraph.LGraph = LGraph;
+
//default supported types
LGraph.supported_types = ["number","string","boolean"];
@@ -665,7 +717,7 @@ LGraph.prototype.updateExecutionOrder = function()
}
//This is more internal, it computes the order and returns it
-LGraph.prototype.computeExecutionOrder = function( only_onExecute )
+LGraph.prototype.computeExecutionOrder = function( only_onExecute, set_level )
{
var L = [];
var S = [];
@@ -676,22 +728,30 @@ LGraph.prototype.computeExecutionOrder = function( only_onExecute )
//search for the nodes without inputs (starting nodes)
for (var i = 0, l = this._nodes.length; i < l; ++i)
{
- var n = this._nodes[i];
- if( only_onExecute && !n.onExecute )
+ var node = this._nodes[i];
+ if( only_onExecute && !node.onExecute )
continue;
- M[n.id] = n; //add to pending nodes
+ M[node.id] = node; //add to pending nodes
var num = 0; //num of input connections
- if(n.inputs)
- for(var j = 0, l2 = n.inputs.length; j < l2; j++)
- if(n.inputs[j] && n.inputs[j].link != null)
+ if(node.inputs)
+ for(var j = 0, l2 = node.inputs.length; j < l2; j++)
+ if(node.inputs[j] && node.inputs[j].link != null)
num += 1;
if(num == 0) //is a starting node
- S.push(n);
+ {
+ S.push(node);
+ if(set_level)
+ node._level = 1;
+ }
else //num of input links
- remaining_links[n.id] = num;
+ {
+ if(set_level)
+ node._level = 0;
+ remaining_links[node.id] = num;
+ }
}
while(true)
@@ -700,43 +760,49 @@ LGraph.prototype.computeExecutionOrder = function( only_onExecute )
break;
//get an starting node
- var n = S.shift();
- L.push(n); //add to ordered list
- delete M[n.id]; //remove from the pending nodes
+ var node = S.shift();
+ L.push(node); //add to ordered list
+ delete M[node.id]; //remove from the pending nodes
+
+ if(!node.outputs)
+ continue;
//for every output
- if(n.outputs)
- for(var i = 0; i < n.outputs.length; i++)
+ for(var i = 0; i < node.outputs.length; i++)
+ {
+ var output = node.outputs[i];
+ //not connected
+ if(output == null || output.links == null || output.links.length == 0)
+ continue;
+
+ //for every connection
+ for(var j = 0; j < output.links.length; j++)
{
- var output = n.outputs[i];
- //not connected
- if(output == null || output.links == null || output.links.length == 0)
+ var link_id = output.links[j];
+ var link = this.links[link_id];
+ if(!link)
continue;
- //for every connection
- for(var j = 0; j < output.links.length; j++)
+ //already visited link (ignore it)
+ if(visited_links[ link.id ])
+ continue;
+
+ var target_node = this.getNodeById( link.target_id );
+ if(target_node == null)
{
- var link_id = output.links[j];
- var link = this.links[link_id];
- if(!link) continue;
-
- //already visited link (ignore it)
- if(visited_links[ link.id ])
- continue;
-
- var target_node = this.getNodeById( link.target_id );
- if(target_node == null)
- {
- visited_links[ link.id ] = true;
- continue;
- }
-
- visited_links[link.id] = true; //mark as visited
- remaining_links[target_node.id] -= 1; //reduce the number of links remaining
- if (remaining_links[target_node.id] == 0)
- S.push(target_node); //if no more links, then add to Starters array
+ visited_links[ link.id ] = true;
+ continue;
}
+
+ if(set_level && (!target_node._level || target_node._level <= node._level))
+ target_node._level = node._level + 1;
+
+ visited_links[link.id] = true; //mark as visited
+ remaining_links[target_node.id] -= 1; //reduce the number of links remaining
+ if (remaining_links[ target_node.id ] == 0)
+ S.push(target_node); //if no more links, then add to starters array
}
+ }
}
//the remaining ones (loops)
@@ -753,13 +819,55 @@ LGraph.prototype.computeExecutionOrder = function( only_onExecute )
return L;
}
+/**
+* Positions every node in a more readable manner
+* @method arrange
+*/
+LGraph.prototype.arrange = function( margin )
+{
+ margin = margin || 40;
+
+ var nodes = this.computeExecutionOrder( false, true );
+ var columns = [];
+ for(var i = 0; i < nodes.length; ++i)
+ {
+ var node = nodes[i];
+ var col = node._level || 1;
+ if(!columns[col])
+ columns[col] = [];
+ columns[col].push( node );
+ }
+
+ var x = margin;
+
+ for(var i = 0; i < columns.length; ++i)
+ {
+ var column = columns[i];
+ if(!column)
+ continue;
+ var max_size = 100;
+ var y = margin;
+ for(var j = 0; j < column.length; ++j)
+ {
+ var node = column[j];
+ node.pos[0] = x;
+ node.pos[1] = y;
+ if(node.size[0] > max_size)
+ max_size = node.size[0];
+ y += node.size[1] + margin;
+ }
+ x += max_size + margin;
+ }
+
+ this.setDirtyCanvas(true,true);
+}
+
/**
* Returns the amount of time the graph has been running in milliseconds
* @method getTime
* @return {number} number of milliseconds the graph has been running
*/
-
LGraph.prototype.getTime = function()
{
return this.globaltime;
@@ -1468,11 +1576,13 @@ LGraph.prototype.onNodeTrace = function(node, msg, color)
* @param {String} name a name for the node
*/
-global.LGraphNode = LiteGraph.LGraphNode = function LGraphNode(title)
+function LGraphNode(title)
{
this._ctor();
}
+global.LGraphNode = LiteGraph.LGraphNode = LGraphNode;
+
LGraphNode.prototype._ctor = function( title )
{
this.title = title || "Unnamed";
@@ -2208,12 +2318,18 @@ LGraphNode.prototype.computeSize = function( minHeight, out )
/**
* returns the bounding of the object, used for rendering purposes
+* bounding is: [topleft_cornerx, topleft_cornery, width, height]
* @method getBounding
* @return {Float32Array[4]} the total size
*/
-LGraphNode.prototype.getBounding = function()
+LGraphNode.prototype.getBounding = function( out )
{
- return new Float32Array([this.pos[0] - 4, this.pos[1] - LiteGraph.NODE_TITLE_HEIGHT, this.pos[0] + this.size[0] + 4, this.pos[1] + this.size[1] + LGraph.NODE_TITLE_HEIGHT]);
+ out = out || new Float32Array(4);
+ out[0] = this.pos[0] - 4;
+ out[1] = this.pos[1] - LiteGraph.NODE_TITLE_HEIGHT;
+ out[2] = this.size[0] + 4;
+ out[3] = this.size[1] + LiteGraph.NODE_TITLE_HEIGHT;
+ return out;
}
/**
@@ -2558,8 +2674,7 @@ LGraphNode.prototype.disconnectInput = function( slot )
//search in the inputs list for this link
for(var i = 0, l = output.links.length; i < l; i++)
{
- var link_id = output.links[i];
- if( link_info.target_id == this.id )
+ if( output.links[i] == link_id )
{
output.links.splice(i,1);
break;
@@ -2761,13 +2876,13 @@ LGraphNode.prototype.localToScreen = function(x,y, graphcanvas)
* @param {LGraph} graph [optional]
* @param {Object} options [optional] { skip_rendering, autoresize }
*/
-global.LGraphCanvas = LiteGraph.LGraphCanvas = function LGraphCanvas( canvas, graph, options )
+function LGraphCanvas( canvas, graph, options )
{
options = options || {};
//if(graph === undefined)
// throw ("No graph assigned");
- this.background_image = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII='
+ this.background_image = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII='
if(canvas && canvas.constructor === String )
canvas = document.querySelector( canvas );
@@ -2791,6 +2906,8 @@ global.LGraphCanvas = LiteGraph.LGraphCanvas = function LGraphCanvas( canvas, gr
this.allow_dragcanvas = true;
this.allow_dragnodes = true;
this.allow_interaction = true; //allow to control widgets, buttons, collapse, etc
+ this.drag_mode = false;
+ this.dragging_rectangle = null;
this.always_render_background = false;
this.render_connections_shadows = false; //too much cpu
@@ -2813,6 +2930,8 @@ global.LGraphCanvas = LiteGraph.LGraphCanvas = function LGraphCanvas( canvas, gr
this.autoresize = options.autoresize;
}
+global.LGraphCanvas = LiteGraph.LGraphCanvas = LGraphCanvas;
+
LGraphCanvas.link_type_colors = {"-1":"#F85",'number':"#AAC","node":"#DCA"};
@@ -2831,11 +2950,15 @@ LGraphCanvas.prototype.clear = function()
this.scale = 1;
this.offset = [0,0];
+ this.dragging_rectangle = null;
+
this.selected_nodes = {};
+ this.visible_nodes = [];
this.node_dragged = null;
this.node_over = null;
this.node_capturing_input = null;
this.connecting_node = null;
+ this.highlighted_links = {};
this.dirty_canvas = true;
this.dirty_bgcanvas = true;
@@ -2921,6 +3044,7 @@ LGraphCanvas.prototype.closeSubgraph = function()
return;
var graph = this._graph_stack.pop();
this.selected_nodes = {};
+ this.highlighted_links = {};
graph.attachCanvas(this);
this.setDirty(true,true);
}
@@ -3008,6 +3132,8 @@ LGraphCanvas.prototype.bindEvents = function()
}
var canvas = this.canvas;
+ var ref_window = this.getCanvasWindow();
+ var document = ref_window.document; //hack used when moving canvas between windows
this._mousedown_callback = this.processMouseDown.bind(this);
this._mousewheel_callback = this.processMouseWheel.bind(this);
@@ -3031,8 +3157,8 @@ LGraphCanvas.prototype.bindEvents = function()
//Keyboard ******************
this._key_callback = this.processKey.bind(this);
- canvas.addEventListener("keydown", this._key_callback );
- canvas.addEventListener("keyup", this._key_callback );
+ canvas.addEventListener("keydown", this._key_callback, true );
+ document.addEventListener("keyup", this._key_callback, true ); //in document, otherwise it doesnt fire keyup
//Droping Stuff over nodes ************************************
this._ondrop_callback = this.processDrop.bind(this);
@@ -3053,11 +3179,14 @@ LGraphCanvas.prototype.unbindEvents = function()
return;
}
+ var ref_window = this.getCanvasWindow();
+ var document = ref_window.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 );
- this.canvas.removeEventListener( "keyup", this._key_callback );
+ document.removeEventListener( "keyup", this._key_callback );
this.canvas.removeEventListener( "contextmenu", this._doNothing );
this.canvas.removeEventListener( "drop", this._ondrop_callback );
this.canvas.removeEventListener( "dragenter", this._doReturnTrue );
@@ -3248,34 +3377,30 @@ 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;
LiteGraph.closeAllContextMenus( ref_window );
if(e.which == 1) //left button mouse
{
- if(!e.shiftKey) //REFACTOR: integrate with function
+ if( e.ctrlKey )
{
- //no node or another node selected
- if (!n || !this.selected_nodes[n.id]) {
-
- var todeselect = [];
- for (var i in this.selected_nodes)
- if (this.selected_nodes[i] != n)
- todeselect.push(this.selected_nodes[i]);
- //two passes to avoid problems modifying the container
- for (var i in todeselect)
- this.processNodeDeselected(todeselect[i]);
- }
+ this.dragging_rectangle = new Float32Array(4);
+ this.dragging_rectangle[0] = e.canvasX;
+ this.dragging_rectangle[1] = e.canvasY;
+ this.dragging_rectangle[2] = 1;
+ this.dragging_rectangle[3] = 1;
+ skip_action = true;
}
+
var clicking_canvas_bg = false;
//when clicked on top of a node
//and it is not interactive
- if(n && this.allow_interaction )
+ if( n && this.allow_interaction && !skip_action )
{
if(!this.live_mode && !n.flags.pinned)
this.bringToFront(n); //if it wasnt selected?
- var skip_action = false;
//not dragging mouse to connect two slots
if(!this.connecting_node && !n.flags.collapsed && !this.live_mode)
@@ -3372,7 +3497,7 @@ LGraphCanvas.prototype.processMouseDown = function(e)
else
clicking_canvas_bg = true;
- if(clicking_canvas_bg && this.allow_dragcanvas)
+ if(!skip_action && clicking_canvas_bg && this.allow_dragcanvas)
{
this.dragging_canvas = true;
}
@@ -3428,7 +3553,13 @@ LGraphCanvas.prototype.processMouseMove = function(e)
this.last_mouse = mouse;
this.canvas_mouse = [e.canvasX, e.canvasY];
- if(this.dragging_canvas)
+ if( this.dragging_rectangle )
+ {
+ this.dragging_rectangle[2] = e.canvasX - this.dragging_rectangle[0];
+ this.dragging_rectangle[3] = e.canvasY - this.dragging_rectangle[1];
+ this.dirty_canvas = true;
+ }
+ else if(this.dragging_canvas)
{
this.offset[0] += delta[0] / this.scale;
this.offset[1] += delta[1] / this.scale;
@@ -3441,7 +3572,7 @@ LGraphCanvas.prototype.processMouseMove = function(e)
this.dirty_canvas = true;
//get node over
- var n = this.graph.getNodeOnPos(e.canvasX, e.canvasY, this.visible_nodes);
+ var n = this.graph.getNodeOnPos( e.canvasX, e.canvasY, this.visible_nodes );
//remove mouseover flag
for(var i = 0, l = this.graph._nodes.length; i < l; ++i)
@@ -3580,8 +3711,32 @@ LGraphCanvas.prototype.processMouseUp = function(e)
if (e.which == 1) //left button
{
- //dragging a connection
- if(this.connecting_node)
+ if( this.dragging_rectangle )
+ {
+ if(this.graph)
+ {
+ var nodes = this.graph._nodes;
+ var node_bounding = new Float32Array(4);
+ this.deselectAllNodes();
+ if( this.dragging_rectangle[2] < 0 ) //flip if negative width
+ this.dragging_rectangle[0] += this.dragging_rectangle[2];
+ if( this.dragging_rectangle[3] < 0 ) //flip if negative height
+ this.dragging_rectangle[1] += this.dragging_rectangle[3];
+ this.dragging_rectangle[2] = Math.abs( this.dragging_rectangle[2] * this.scale ); //abs to convert negative width
+ this.dragging_rectangle[3] = Math.abs( this.dragging_rectangle[3] * this.scale ); //abs to convert negative height
+
+ for(var i = 0; i < nodes.length; ++i)
+ {
+ var node = nodes[i];
+ node.getBounding( node_bounding );
+ if(!overlapBounding( this.dragging_rectangle, node_bounding ))
+ continue; //out of the visible area
+ this.selectNode( node, true );
+ }
+ }
+ this.dragging_rectangle = null;
+ }
+ else if(this.connecting_node) //dragging a connection
{
this.dirty_canvas = true;
this.dirty_bgcanvas = true;
@@ -3610,8 +3765,8 @@ LGraphCanvas.prototype.processMouseUp = function(e)
if(this.connecting_output.type == LiteGraph.EVENT)
this.connecting_node.connect( this.connecting_slot, node, LiteGraph.EVENT );
else
- if(input && !input.link && input.type == this.connecting_output.type) //toLowerCase missing
- this.connecting_node.connect(this.connecting_slot, node, 0);
+ if(input && !input.link && LiteGraph.isValidConnection( input.type && this.connecting_output.type ) )
+ this.connecting_node.connect( this.connecting_slot, node, 0 );
}
}
}
@@ -3640,6 +3795,13 @@ LGraphCanvas.prototype.processMouseUp = function(e)
}
else //no node being dragged
{
+ //get node over
+ var node = this.graph.getNodeOnPos( e.canvasX, e.canvasY, this.visible_nodes );
+
+ var now = LiteGraph.getTime();
+ if ( !node && (now - this.last_mouseclick) < 300 )
+ this.deselectAllNodes();
+
this.dirty_canvas = true;
this.dragging_canvas = false;
@@ -3738,17 +3900,23 @@ LGraphCanvas.prototype.processKey = function(e)
return;
var block_default = false;
+ //console.log(e); //debug
if(e.target.localName == "input")
return;
if(e.type == "keydown")
{
- console.log(e);
+ if(e.keyCode == 32)
+ {
+ this.dragging_canvas = true;
+ block_default = true;
+ }
+
//select all Control A
if(e.keyCode == 65 && e.ctrlKey)
{
- this.selectAllNodes();
+ this.selectNodes();
block_default = true;
}
@@ -3756,36 +3924,16 @@ LGraphCanvas.prototype.processKey = function(e)
{
if(this.selected_nodes)
{
- var nodes_data = [];
- for(var i in this.selected_nodes)
- nodes_data.push( this.selected_nodes[i].serialize() );
- localStorage.setItem( "litegrapheditor_clipboard", JSON.stringify(nodes_data) );
+ this.copyToClipboard();
block_default = true;
}
}
if(e.code == "KeyV" && (e.metaKey || e.ctrlKey) && !e.shiftKey ) //paste
{
- var data = localStorage.getItem( "litegrapheditor_clipboard" );
- if(data)
- {
- var nodes_data = JSON.parse(data);
- for(var i = 0; i < nodes_data.length; ++i)
- {
- var node_data = nodes_data[i];
- var node = LiteGraph.createNode( node_data.type );
- if(node)
- {
- node.configure(node_data);
- node.pos[0] += 5;
- node.pos[1] += 5;
- this.graph.add( node );
- }
- }
- }
+ this.pasteFromClipboard();
}
-
//delete or backspace
if(e.keyCode == 46 || e.keyCode == 8)
{
@@ -3804,6 +3952,9 @@ LGraphCanvas.prototype.processKey = function(e)
}
else if( e.type == "keyup" )
{
+ if(e.keyCode == 32)
+ this.dragging_canvas = false;
+
if(this.selected_nodes)
for (var i in this.selected_nodes)
if(this.selected_nodes[i].onKeyUp)
@@ -3819,6 +3970,79 @@ LGraphCanvas.prototype.processKey = function(e)
}
}
+LGraphCanvas.prototype.copyToClipboard = function()
+{
+ var clipboard_info = {
+ nodes: [],
+ links: []
+ };
+ var index = 0;
+ var selected_nodes_array = [];
+ for(var i in this.selected_nodes)
+ {
+ var node = this.selected_nodes[i];
+ node._relative_id = index;
+ selected_nodes_array.push( node );
+ index += 1;
+ }
+
+ for(var i = 0; i < selected_nodes_array.length; ++i)
+ {
+ var node = selected_nodes_array[i];
+ clipboard_info.nodes.push( node.clone().serialize() );
+ if(node.inputs && node.inputs.length)
+ for(var j = 0; j < node.inputs.length; ++j)
+ {
+ var input = node.inputs[j];
+ if(!input || input.link == null)
+ continue;
+ var link_info = this.graph.links[ input.link ];
+ if(!link_info)
+ continue;
+ var target_node = this.graph.getNodeById( link_info.origin_id );
+ if(!target_node || !this.selected_nodes[ target_node.id ] ) //improve this by allowing connections to non-selected nodes
+ continue; //not selected
+ clipboard_info.links.push([ target_node._relative_id, j, node._relative_id, link_info.target_slot ]);
+ }
+ }
+ localStorage.setItem( "litegrapheditor_clipboard", JSON.stringify( clipboard_info ) );
+}
+
+LGraphCanvas.prototype.pasteFromClipboard = function()
+{
+ var data = localStorage.getItem( "litegrapheditor_clipboard" );
+ if(!data)
+ return;
+
+ //create nodes
+ var clipboard_info = JSON.parse(data);
+ var nodes = [];
+ for(var i = 0; i < clipboard_info.nodes.length; ++i)
+ {
+ var node_data = clipboard_info.nodes[i];
+ var node = LiteGraph.createNode( node_data.type );
+ if(node)
+ {
+ node.configure(node_data);
+ node.pos[0] += 5;
+ node.pos[1] += 5;
+ this.graph.add( node );
+ nodes.push( node );
+ }
+ }
+
+ //create links
+ for(var i = 0; i < clipboard_info.links.length; ++i)
+ {
+ var link_info = clipboard_info.links[i];
+ var origin_node = nodes[ link_info[0] ];
+ var target_node = nodes[ link_info[2] ];
+ origin_node.connect( link_info[1], target_node, link_info[3] );
+ }
+
+ this.selectNodes( nodes );
+}
+
LGraphCanvas.prototype.processDrop = function(e)
{
e.preventDefault();
@@ -3908,42 +4132,6 @@ LGraphCanvas.prototype.checkDropItem = function(e)
}
-LGraphCanvas.prototype.processNodeSelected = function(n,e)
-{
- n.selected = true;
- if (n.onSelected)
- n.onSelected();
-
- if(e && e.shiftKey) //add to selection
- this.selected_nodes[n.id] = n;
- else
- {
- this.selected_nodes = {};
- this.selected_nodes[ n.id ] = n;
- }
-
- this.dirty_canvas = true;
-
- if(this.onNodeSelected)
- this.onNodeSelected(n);
-
- //if(this.node_in_panel) this.showNodePanel(n);
-}
-
-LGraphCanvas.prototype.processNodeDeselected = function(n)
-{
- n.selected = false;
- if(n.onDeselected)
- n.onDeselected();
-
- delete this.selected_nodes[n.id];
-
- if(this.onNodeDeselected)
- this.onNodeDeselected(n);
-
- this.dirty_canvas = true;
-}
-
LGraphCanvas.prototype.processNodeDblClicked = function(n)
{
if(this.onShowNodePanel)
@@ -3955,44 +4143,100 @@ LGraphCanvas.prototype.processNodeDblClicked = function(n)
this.setDirty(true);
}
-LGraphCanvas.prototype.selectNode = function(node)
+LGraphCanvas.prototype.processNodeSelected = function(node,e)
{
- this.deselectAllNodes();
-
- if(!node)
- return;
-
- if(!node.selected && node.onSelected)
- node.onSelected();
- node.selected = true;
- this.selected_nodes[ node.id ] = node;
- this.setDirty(true);
+ this.selectNode( node, e && e.shiftKey );
+ if(this.onNodeSelected)
+ this.onNodeSelected(node);
}
-LGraphCanvas.prototype.selectAllNodes = function()
+LGraphCanvas.prototype.processNodeDeselected = function(node)
{
- for(var i = 0; i < this.graph._nodes.length; ++i)
+ this.deselectNode(node);
+ if(this.onNodeDeselected)
+ this.onNodeDeselected(node);
+}
+
+LGraphCanvas.prototype.selectNode = function( node, add_to_current_selection )
+{
+ if(node == null)
+ this.deselectAllNodes();
+ else
+ this.selectNodes([node], add_to_current_selection );
+}
+
+LGraphCanvas.prototype.selectNodes = function( nodes, add_to_current_selection )
+{
+ if(!add_to_current_selection)
+ this.deselectAllNodes();
+
+ nodes = nodes || this.graph._nodes;
+ for(var i = 0; i < nodes.length; ++i)
{
- var n = this.graph._nodes[i];
- if(!n.selected && n.onSelected)
- n.onSelected();
- n.selected = true;
- this.selected_nodes[this.graph._nodes[i].id] = n;
+ var node = nodes[i];
+ if(node.selected)
+ continue;
+
+ if( !node.selected && node.onSelected )
+ node.onSelected();
+ node.selected = true;
+ this.selected_nodes[ node.id ] = node;
+
+ if(node.inputs)
+ for(var i = 0; i < node.inputs.length; ++i)
+ this.highlighted_links[ node.inputs[i].link ] = true;
+ if(node.outputs)
+ for(var i = 0; i < node.outputs.length; ++i)
+ {
+ var out = node.outputs[i];
+ if( out.links )
+ for(var j = 0; j < out.links.length; ++j)
+ this.highlighted_links[ out.links[j] ] = true;
+ }
+
}
this.setDirty(true);
}
+LGraphCanvas.prototype.deselectNode = function( node )
+{
+ if(!node.selected)
+ return;
+ if(node.onDeselected)
+ node.onDeselected();
+ node.selected = false;
+
+ //remove highlighted
+ if(node.inputs)
+ for(var i = 0; i < node.inputs.length; ++i)
+ delete this.highlighted_links[ node.inputs[i].link ];
+ if(node.outputs)
+ for(var i = 0; i < node.outputs.length; ++i)
+ {
+ var out = node.outputs[i];
+ if( out.links )
+ for(var j = 0; j < out.links.length; ++j)
+ delete this.highlighted_links[ out.links[j] ];
+ }
+}
+
LGraphCanvas.prototype.deselectAllNodes = function()
{
- for(var i in this.selected_nodes)
+ if(!this.graph)
+ return;
+ var nodes = this.graph._nodes;
+ for(var i = 0, l = nodes.length; i < l; ++i)
{
- var n = this.selected_nodes;
- if(n.onDeselected)
- n.onDeselected();
- n.selected = false;
+ var node = nodes[i];
+ if(!node.selected)
+ continue;
+ if(node.onDeselected)
+ node.onDeselected();
+ node.selected = false;
}
this.selected_nodes = {};
+ this.highlighted_links = {};
this.setDirty(true);
}
@@ -4005,6 +4249,7 @@ LGraphCanvas.prototype.deleteSelectedNodes = function()
this.graph.remove(m);
}
this.selected_nodes = {};
+ this.highlighted_links = {};
this.setDirty(true);
}
@@ -4049,20 +4294,25 @@ LGraphCanvas.prototype.setZoom = function(value, zooming_center)
this.dirty_bgcanvas = true;
}
-LGraphCanvas.prototype.convertOffsetToCanvas = function(pos)
+LGraphCanvas.prototype.convertOffsetToCanvas = function( pos, out )
{
- return [pos[0] / this.scale - this.offset[0], pos[1] / this.scale - this.offset[1]];
+ out = out || [];
+ out[0] = pos[0] / this.scale - this.offset[0];
+ out[1] = pos[1] / this.scale - this.offset[1];
+ return out;
}
-LGraphCanvas.prototype.convertCanvasToOffset = function(pos)
+LGraphCanvas.prototype.convertCanvasToOffset = function( pos, out )
{
- return [(pos[0] + this.offset[0]) * this.scale,
- (pos[1] + this.offset[1]) * this.scale ];
+ out = out || [];
+ out[0] = (pos[0] + this.offset[0]) * this.scale;
+ out[1] = (pos[1] + this.offset[1]) * this.scale;
+ return out;
}
LGraphCanvas.prototype.convertEventToCanvas = function(e)
{
- var rect = this.canvas.getClientRects()[0];
+ var rect = this.canvas.getBoundingClientRect();
return this.convertOffsetToCanvas([e.pageX - rect.left,e.pageY - rect.top]);
}
@@ -4089,19 +4339,22 @@ LGraphCanvas.prototype.sendToBack = function(n)
/* LGraphCanvas render */
+var temp = new Float32Array(4);
-LGraphCanvas.prototype.computeVisibleNodes = function()
+LGraphCanvas.prototype.computeVisibleNodes = function( nodes, out )
{
- var visible_nodes = [];
- for(var i = 0, l = this.graph._nodes.length; i < l; ++i)
+ var visible_nodes = out || [];
+ visible_nodes.length = 0;
+ nodes = nodes || this.graph._nodes;
+ for(var i = 0, l = nodes.length; i < l; ++i)
{
- var n = this.graph._nodes[i];
+ var n = nodes[i];
//skip rendering nodes in live mode
if(this.live_mode && !n.onDrawBackground && !n.onDrawForeground)
continue;
- if(!overlapBounding(this.visible_area, n.getBounding() ))
+ if(!overlapBounding( this.visible_area, n.getBounding( temp ) ))
continue; //out of the visible area
visible_nodes.push(n);
@@ -4123,7 +4376,7 @@ LGraphCanvas.prototype.draw = function(force_canvas, force_bgcanvas)
{
var start = [-this.offset[0], -this.offset[1] ];
var end = [start[0] + this.canvas.width / this.scale, start[1] + this.canvas.height / this.scale];
- this.visible_area = new Float32Array([start[0],start[1],end[0],end[1]]);
+ this.visible_area = new Float32Array([ start[0], start[1], end[0] - start[0], end[1] - start[1] ]);
}
if(this.dirty_bgcanvas || force_bgcanvas || this.always_render_background || (this.graph && this.graph._last_trigger_time && (now - this.graph._last_trigger_time) < 1000) )
@@ -4190,8 +4443,7 @@ LGraphCanvas.prototype.drawFrontCanvas = function()
//draw nodes
var drawn_nodes = 0;
- var visible_nodes = this.computeVisibleNodes();
- this.visible_nodes = visible_nodes;
+ var visible_nodes = this.computeVisibleNodes( null, this.visible_nodes );
for (var i = 0; i < visible_nodes.length; ++i)
{
@@ -4243,6 +4495,14 @@ LGraphCanvas.prototype.drawFrontCanvas = function()
ctx.fill();
}
}
+
+ if( this.dragging_rectangle )
+ {
+ ctx.strokeStyle = "#FFF";
+ ctx.strokeRect( this.dragging_rectangle[0], this.dragging_rectangle[1], this.dragging_rectangle[2], this.dragging_rectangle[3] );
+ }
+
+
ctx.restore();
}
@@ -4347,7 +4607,7 @@ LGraphCanvas.prototype.drawBackCanvas = function()
if(pattern)
{
ctx.fillStyle = pattern;
- ctx.fillRect(this.visible_area[0],this.visible_area[1],this.visible_area[2]-this.visible_area[0],this.visible_area[3]-this.visible_area[1]);
+ ctx.fillRect(this.visible_area[0],this.visible_area[1],this.visible_area[2],this.visible_area[3]);
ctx.fillStyle = "transparent";
}
@@ -4360,7 +4620,7 @@ LGraphCanvas.prototype.drawBackCanvas = function()
//DEBUG: show clipping area
//ctx.fillStyle = "red";
- //ctx.fillRect( this.visible_area[0] + 10, this.visible_area[1] + 10, this.visible_area[2] - this.visible_area[0] - 20, this.visible_area[3] - this.visible_area[1] - 20);
+ //ctx.fillRect( this.visible_area[0] + 10, this.visible_area[1] + 10, this.visible_area[2] - 20, this.visible_area[3] - 20);
//bg
ctx.strokeStyle = "#235";
@@ -4838,6 +5098,9 @@ LGraphCanvas.prototype.renderLink = function( ctx, a, b, link, skip_border, flow
if(!color)
color = this.default_link_color;
+ if( link != null && this.highlighted_links[ link.id ] )
+ color = "#FFF";
+
//begin line shape
ctx.beginPath();
@@ -5447,7 +5710,7 @@ LGraphCanvas.prototype.createDialog = function( html, options )
dialog.className = "graphdialog";
dialog.innerHTML = html;
- var rect = this.canvas.getClientRects()[0];
+ var rect = this.canvas.getBoundingClientRect();
var offsetx = -20;
var offsety = -20;
if(rect)
@@ -5583,7 +5846,8 @@ LGraphCanvas.onMenuNodeClone = function( value, options, e, menu, node )
{
if(node.clonable == false) return;
var newnode = node.clone();
- if(!newnode) return;
+ if(!newnode)
+ return;
newnode.pos = [node.pos[0]+5,node.pos[1]+5];
node.graph.add(newnode);
node.setDirtyCanvas(true,true);
@@ -5845,13 +6109,18 @@ function isInsideBounding(p,bb)
}
LiteGraph.isInsideBounding = isInsideBounding;
-//boundings overlap, format: [start,end]
+//boundings overlap, format: [ startx, starty, width, height ]
function overlapBounding(a,b)
{
- if ( a[0] > b[2] ||
- a[1] > b[3] ||
- a[2] < b[0] ||
- a[3] < b[1])
+ var A_end_x = a[0] + a[2];
+ var A_end_y = a[1] + a[3];
+ var B_end_x = b[0] + b[2];
+ var B_end_y = b[1] + b[3];
+
+ if ( a[0] > B_end_x ||
+ a[1] > B_end_y ||
+ A_end_x < b[0] ||
+ A_end_y < b[1])
return false;
return true;
}
@@ -6256,15 +6525,17 @@ LiteGraph.extendClass = function ( target, origin )
}
}
-/*
-LiteGraph.createNodetypeWrapper = function( class_object )
-{
- //create Nodetype object
-}
-//LiteGraph.registerNodeType("scene/global", LGraphGlobal );
-*/
+LiteGraph.getParameterNames = function(func) {
+ return (func + '')
+ .replace(/[/][/].*$/mg,'') // strip single-line comments
+ .replace(/\s+/g, '') // strip white space
+ .replace(/[/][*][^/*]*[*][/]/g, '') // strip multi-line comments /**/
+ .split('){', 1)[0].replace(/^[^(]*[(]/, '') // extract the parameters
+ .replace(/=[^,]+/g, '') // strip any ES6 defaults
+ .split(',').filter(Boolean); // split & filter [""]
+}
-if(typeof(window) !== undefined && !window["requestAnimationFrame"] )
+if( typeof(window) != "undefined" && !window["requestAnimationFrame"] )
{
window.requestAnimationFrame = window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
@@ -6274,6 +6545,9 @@ if(typeof(window) !== undefined && !window["requestAnimationFrame&q
}
})(this);
+
+if(typeof(exports) != "undefined")
+ exports.LiteGraph = this.LiteGraph;
diff --git a/src/litegraph-editor.js b/src/litegraph-editor.js
index 8df40aab6..35c9f027b 100755
--- a/src/litegraph-editor.js
+++ b/src/litegraph-editor.js
@@ -184,6 +184,7 @@ Editor.prototype.addMiniWindow = function(w,h)
var canvas = miniwindow.querySelector("canvas");
var graphcanvas = new LGraphCanvas(canvas, this.graph);
+ graphcanvas.show_info = false;
graphcanvas.background_image = "imgs/grid.png";
graphcanvas.scale = 0.25;
graphcanvas.allow_dragnodes = false;
diff --git a/src/litegraph.js b/src/litegraph.js
index 592f1ebc6..c023cb2ad 100755
--- a/src/litegraph.js
+++ b/src/litegraph.js
@@ -98,7 +98,7 @@ var LiteGraph = global.LiteGraph = {
for(var i in LGraphNode.prototype)
if(!base_class.prototype[i])
base_class.prototype[i] = LGraphNode.prototype[i];
-
+
Object.defineProperty( base_class.prototype, "shape",{
set: function(v) {
switch(v)
@@ -132,6 +132,36 @@ var LiteGraph = global.LiteGraph = {
}
},
+ /**
+ * Create a new node type by passing a function, it wraps it with a propper class and generates inputs according to the parameters of the function.
+ * Useful to wrap simple methods that do not require properties, and that only process some input to generate an output.
+ * @method wrapFunctionAsNode
+ * @param {String} name node name with namespace (p.e.: 'math/sum')
+ * @param {Function} func
+ * @param {Array} param_types [optional] an array containing the type of every parameter, otherwise parameters will accept any type
+ * @param {String} return_type [optional] string with the return type, otherwise it will be generic
+ */
+ wrapFunctionAsNode: function( name, func, param_types, return_type )
+ {
+ var params = Array(func.length);
+ var code = "";
+ var names = LiteGraph.getParameterNames( func );
+ for(var i = 0; i < names.length; ++i)
+ code += "this.addInput('"+names[i]+"',"+(param_types && param_types[i] ? "'" + param_types[i] + "'" : "0") + ");\n";
+ code += "this.addOutput('out',"+( return_type ? "'" + return_type + "'" : 0 )+");\n";
+ var classobj = Function(code);
+ classobj.title = name.split("/").pop();
+ classobj.desc = "Generated from " + func.name;
+ classobj.prototype.onExecute = function onExecute()
+ {
+ for(var i = 0; i < params.length; ++i)
+ params[i] = this.getInputData(i);
+ var r = func.apply( this, params );
+ this.setOutputData(0,r);
+ }
+ this.registerNodeType( name, classobj );
+ },
+
/**
* Adds this method to all nodetypes, existing and to be created
* (You can add it to LGraphNode.prototype but then existing node types wont have it)
@@ -305,8 +335,20 @@ var LiteGraph = global.LiteGraph = {
if( !type_a || //generic output
!type_b || //generic input
type_a == type_b || //same type (is valid for triggers)
- (type_a !== LiteGraph.EVENT && type_b !== LiteGraph.EVENT && type_a.toLowerCase() == type_b.toLowerCase()) ) //same type
- return true;
+ type_a == LiteGraph.EVENT && type_b == LiteGraph.ACTION )
+ return true;
+
+ type_a = type_a.toLowerCase();
+ type_b = type_b.toLowerCase();
+ if( type_a.indexOf(",") == -1 && type_b.indexOf(",") == -1 )
+ return type_a == type_b;
+
+ var supported_types_a = type_a.split(",");
+ var supported_types_b = type_b.split(",");
+ for(var i = 0; i < supported_types_a.length; ++i)
+ for(var j = 0; j < supported_types_b.length; ++j)
+ if( supported_types_a[i] == supported_types_b[j] )
+ return true;
return false;
}
};
@@ -589,7 +631,7 @@ LGraph.prototype.updateExecutionOrder = function()
}
//This is more internal, it computes the order and returns it
-LGraph.prototype.computeExecutionOrder = function( only_onExecute )
+LGraph.prototype.computeExecutionOrder = function( only_onExecute, set_level )
{
var L = [];
var S = [];
@@ -600,22 +642,30 @@ LGraph.prototype.computeExecutionOrder = function( only_onExecute )
//search for the nodes without inputs (starting nodes)
for (var i = 0, l = this._nodes.length; i < l; ++i)
{
- var n = this._nodes[i];
- if( only_onExecute && !n.onExecute )
+ var node = this._nodes[i];
+ if( only_onExecute && !node.onExecute )
continue;
- M[n.id] = n; //add to pending nodes
+ M[node.id] = node; //add to pending nodes
var num = 0; //num of input connections
- if(n.inputs)
- for(var j = 0, l2 = n.inputs.length; j < l2; j++)
- if(n.inputs[j] && n.inputs[j].link != null)
+ if(node.inputs)
+ for(var j = 0, l2 = node.inputs.length; j < l2; j++)
+ if(node.inputs[j] && node.inputs[j].link != null)
num += 1;
if(num == 0) //is a starting node
- S.push(n);
+ {
+ S.push(node);
+ if(set_level)
+ node._level = 1;
+ }
else //num of input links
- remaining_links[n.id] = num;
+ {
+ if(set_level)
+ node._level = 0;
+ remaining_links[node.id] = num;
+ }
}
while(true)
@@ -624,43 +674,49 @@ LGraph.prototype.computeExecutionOrder = function( only_onExecute )
break;
//get an starting node
- var n = S.shift();
- L.push(n); //add to ordered list
- delete M[n.id]; //remove from the pending nodes
+ var node = S.shift();
+ L.push(node); //add to ordered list
+ delete M[node.id]; //remove from the pending nodes
+
+ if(!node.outputs)
+ continue;
//for every output
- if(n.outputs)
- for(var i = 0; i < n.outputs.length; i++)
+ for(var i = 0; i < node.outputs.length; i++)
+ {
+ var output = node.outputs[i];
+ //not connected
+ if(output == null || output.links == null || output.links.length == 0)
+ continue;
+
+ //for every connection
+ for(var j = 0; j < output.links.length; j++)
{
- var output = n.outputs[i];
- //not connected
- if(output == null || output.links == null || output.links.length == 0)
+ var link_id = output.links[j];
+ var link = this.links[link_id];
+ if(!link)
continue;
- //for every connection
- for(var j = 0; j < output.links.length; j++)
+ //already visited link (ignore it)
+ if(visited_links[ link.id ])
+ continue;
+
+ var target_node = this.getNodeById( link.target_id );
+ if(target_node == null)
{
- var link_id = output.links[j];
- var link = this.links[link_id];
- if(!link) continue;
-
- //already visited link (ignore it)
- if(visited_links[ link.id ])
- continue;
-
- var target_node = this.getNodeById( link.target_id );
- if(target_node == null)
- {
- visited_links[ link.id ] = true;
- continue;
- }
-
- visited_links[link.id] = true; //mark as visited
- remaining_links[target_node.id] -= 1; //reduce the number of links remaining
- if (remaining_links[target_node.id] == 0)
- S.push(target_node); //if no more links, then add to Starters array
+ visited_links[ link.id ] = true;
+ continue;
}
+
+ if(set_level && (!target_node._level || target_node._level <= node._level))
+ target_node._level = node._level + 1;
+
+ visited_links[link.id] = true; //mark as visited
+ remaining_links[target_node.id] -= 1; //reduce the number of links remaining
+ if (remaining_links[ target_node.id ] == 0)
+ S.push(target_node); //if no more links, then add to starters array
}
+ }
}
//the remaining ones (loops)
@@ -677,13 +733,55 @@ LGraph.prototype.computeExecutionOrder = function( only_onExecute )
return L;
}
+/**
+* Positions every node in a more readable manner
+* @method arrange
+*/
+LGraph.prototype.arrange = function( margin )
+{
+ margin = margin || 40;
+
+ var nodes = this.computeExecutionOrder( false, true );
+ var columns = [];
+ for(var i = 0; i < nodes.length; ++i)
+ {
+ var node = nodes[i];
+ var col = node._level || 1;
+ if(!columns[col])
+ columns[col] = [];
+ columns[col].push( node );
+ }
+
+ var x = margin;
+
+ for(var i = 0; i < columns.length; ++i)
+ {
+ var column = columns[i];
+ if(!column)
+ continue;
+ var max_size = 100;
+ var y = margin;
+ for(var j = 0; j < column.length; ++j)
+ {
+ var node = column[j];
+ node.pos[0] = x;
+ node.pos[1] = y;
+ if(node.size[0] > max_size)
+ max_size = node.size[0];
+ y += node.size[1] + margin;
+ }
+ x += max_size + margin;
+ }
+
+ this.setDirtyCanvas(true,true);
+}
+
/**
* Returns the amount of time the graph has been running in milliseconds
* @method getTime
* @return {number} number of milliseconds the graph has been running
*/
-
LGraph.prototype.getTime = function()
{
return this.globaltime;
@@ -2134,6 +2232,7 @@ LGraphNode.prototype.computeSize = function( minHeight, out )
/**
* returns the bounding of the object, used for rendering purposes
+* bounding is: [topleft_cornerx, topleft_cornery, width, height]
* @method getBounding
* @return {Float32Array[4]} the total size
*/
@@ -2142,8 +2241,8 @@ LGraphNode.prototype.getBounding = function( out )
out = out || new Float32Array(4);
out[0] = this.pos[0] - 4;
out[1] = this.pos[1] - LiteGraph.NODE_TITLE_HEIGHT;
- out[2] = this.pos[0] + this.size[0] + 4;
- out[3] = this.pos[1] + this.size[1] + LGraph.NODE_TITLE_HEIGHT;
+ out[2] = this.size[0] + 4;
+ out[3] = this.size[1] + LiteGraph.NODE_TITLE_HEIGHT;
return out;
}
@@ -2489,8 +2588,7 @@ LGraphNode.prototype.disconnectInput = function( slot )
//search in the inputs list for this link
for(var i = 0, l = output.links.length; i < l; i++)
{
- var link_id = output.links[i];
- if( link_info.target_id == this.id )
+ if( output.links[i] == link_id )
{
output.links.splice(i,1);
break;
@@ -2698,7 +2796,7 @@ function LGraphCanvas( canvas, graph, options )
//if(graph === undefined)
// throw ("No graph assigned");
- this.background_image = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII='
+ this.background_image = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAIAAAD/gAIDAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQBJREFUeNrs1rEKwjAUhlETUkj3vP9rdmr1Ysammk2w5wdxuLgcMHyptfawuZX4pJSWZTnfnu/lnIe/jNNxHHGNn//HNbbv+4dr6V+11uF527arU7+u63qfa/bnmh8sWLBgwYJlqRf8MEptXPBXJXa37BSl3ixYsGDBMliwFLyCV/DeLIMFCxYsWLBMwSt4Be/NggXLYMGCBUvBK3iNruC9WbBgwYJlsGApeAWv4L1ZBgsWLFiwYJmCV/AK3psFC5bBggULloJX8BpdwXuzYMGCBctgwVLwCl7Be7MMFixYsGDBsu8FH1FaSmExVfAxBa/gvVmwYMGCZbBg/W4vAQYA5tRF9QYlv/QAAAAASUVORK5CYII='
if(canvas && canvas.constructor === String )
canvas = document.querySelector( canvas );
@@ -2722,6 +2820,8 @@ 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.drag_mode = false;
+ this.dragging_rectangle = null;
this.always_render_background = false;
this.render_connections_shadows = false; //too much cpu
@@ -2764,11 +2864,15 @@ LGraphCanvas.prototype.clear = function()
this.scale = 1;
this.offset = [0,0];
+ this.dragging_rectangle = null;
+
this.selected_nodes = {};
+ this.visible_nodes = [];
this.node_dragged = null;
this.node_over = null;
this.node_capturing_input = null;
this.connecting_node = null;
+ this.highlighted_links = {};
this.dirty_canvas = true;
this.dirty_bgcanvas = true;
@@ -2854,6 +2958,7 @@ LGraphCanvas.prototype.closeSubgraph = function()
return;
var graph = this._graph_stack.pop();
this.selected_nodes = {};
+ this.highlighted_links = {};
graph.attachCanvas(this);
this.setDirty(true,true);
}
@@ -2941,6 +3046,8 @@ LGraphCanvas.prototype.bindEvents = function()
}
var canvas = this.canvas;
+ var ref_window = this.getCanvasWindow();
+ var document = ref_window.document; //hack used when moving canvas between windows
this._mousedown_callback = this.processMouseDown.bind(this);
this._mousewheel_callback = this.processMouseWheel.bind(this);
@@ -2964,8 +3071,8 @@ LGraphCanvas.prototype.bindEvents = function()
//Keyboard ******************
this._key_callback = this.processKey.bind(this);
- canvas.addEventListener("keydown", this._key_callback );
- canvas.addEventListener("keyup", this._key_callback );
+ canvas.addEventListener("keydown", this._key_callback, true );
+ document.addEventListener("keyup", this._key_callback, true ); //in document, otherwise it doesnt fire keyup
//Droping Stuff over nodes ************************************
this._ondrop_callback = this.processDrop.bind(this);
@@ -2986,11 +3093,14 @@ LGraphCanvas.prototype.unbindEvents = function()
return;
}
+ var ref_window = this.getCanvasWindow();
+ var document = ref_window.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 );
- this.canvas.removeEventListener( "keyup", this._key_callback );
+ document.removeEventListener( "keyup", this._key_callback );
this.canvas.removeEventListener( "contextmenu", this._doNothing );
this.canvas.removeEventListener( "drop", this._ondrop_callback );
this.canvas.removeEventListener( "dragenter", this._doReturnTrue );
@@ -3181,34 +3291,30 @@ 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;
LiteGraph.closeAllContextMenus( ref_window );
if(e.which == 1) //left button mouse
{
- if(!e.shiftKey) //REFACTOR: integrate with function
+ if( e.ctrlKey )
{
- //no node or another node selected
- if (!n || !this.selected_nodes[n.id]) {
-
- var todeselect = [];
- for (var i in this.selected_nodes)
- if (this.selected_nodes[i] != n)
- todeselect.push(this.selected_nodes[i]);
- //two passes to avoid problems modifying the container
- for (var i in todeselect)
- this.processNodeDeselected(todeselect[i]);
- }
+ this.dragging_rectangle = new Float32Array(4);
+ this.dragging_rectangle[0] = e.canvasX;
+ this.dragging_rectangle[1] = e.canvasY;
+ this.dragging_rectangle[2] = 1;
+ this.dragging_rectangle[3] = 1;
+ skip_action = true;
}
+
var clicking_canvas_bg = false;
//when clicked on top of a node
//and it is not interactive
- if(n && this.allow_interaction )
+ if( n && this.allow_interaction && !skip_action )
{
if(!this.live_mode && !n.flags.pinned)
this.bringToFront(n); //if it wasnt selected?
- var skip_action = false;
//not dragging mouse to connect two slots
if(!this.connecting_node && !n.flags.collapsed && !this.live_mode)
@@ -3305,7 +3411,7 @@ LGraphCanvas.prototype.processMouseDown = function(e)
else
clicking_canvas_bg = true;
- if(clicking_canvas_bg && this.allow_dragcanvas)
+ if(!skip_action && clicking_canvas_bg && this.allow_dragcanvas)
{
this.dragging_canvas = true;
}
@@ -3361,7 +3467,13 @@ LGraphCanvas.prototype.processMouseMove = function(e)
this.last_mouse = mouse;
this.canvas_mouse = [e.canvasX, e.canvasY];
- if(this.dragging_canvas)
+ if( this.dragging_rectangle )
+ {
+ this.dragging_rectangle[2] = e.canvasX - this.dragging_rectangle[0];
+ this.dragging_rectangle[3] = e.canvasY - this.dragging_rectangle[1];
+ this.dirty_canvas = true;
+ }
+ else if(this.dragging_canvas)
{
this.offset[0] += delta[0] / this.scale;
this.offset[1] += delta[1] / this.scale;
@@ -3374,7 +3486,7 @@ LGraphCanvas.prototype.processMouseMove = function(e)
this.dirty_canvas = true;
//get node over
- var n = this.graph.getNodeOnPos(e.canvasX, e.canvasY, this.visible_nodes);
+ var n = this.graph.getNodeOnPos( e.canvasX, e.canvasY, this.visible_nodes );
//remove mouseover flag
for(var i = 0, l = this.graph._nodes.length; i < l; ++i)
@@ -3513,8 +3625,32 @@ LGraphCanvas.prototype.processMouseUp = function(e)
if (e.which == 1) //left button
{
- //dragging a connection
- if(this.connecting_node)
+ if( this.dragging_rectangle )
+ {
+ if(this.graph)
+ {
+ var nodes = this.graph._nodes;
+ var node_bounding = new Float32Array(4);
+ this.deselectAllNodes();
+ if( this.dragging_rectangle[2] < 0 ) //flip if negative width
+ this.dragging_rectangle[0] += this.dragging_rectangle[2];
+ if( this.dragging_rectangle[3] < 0 ) //flip if negative height
+ this.dragging_rectangle[1] += this.dragging_rectangle[3];
+ this.dragging_rectangle[2] = Math.abs( this.dragging_rectangle[2] * this.scale ); //abs to convert negative width
+ this.dragging_rectangle[3] = Math.abs( this.dragging_rectangle[3] * this.scale ); //abs to convert negative height
+
+ for(var i = 0; i < nodes.length; ++i)
+ {
+ var node = nodes[i];
+ node.getBounding( node_bounding );
+ if(!overlapBounding( this.dragging_rectangle, node_bounding ))
+ continue; //out of the visible area
+ this.selectNode( node, true );
+ }
+ }
+ this.dragging_rectangle = null;
+ }
+ else if(this.connecting_node) //dragging a connection
{
this.dirty_canvas = true;
this.dirty_bgcanvas = true;
@@ -3543,8 +3679,8 @@ LGraphCanvas.prototype.processMouseUp = function(e)
if(this.connecting_output.type == LiteGraph.EVENT)
this.connecting_node.connect( this.connecting_slot, node, LiteGraph.EVENT );
else
- if(input && !input.link && input.type == this.connecting_output.type) //toLowerCase missing
- this.connecting_node.connect(this.connecting_slot, node, 0);
+ if(input && !input.link && LiteGraph.isValidConnection( input.type && this.connecting_output.type ) )
+ this.connecting_node.connect( this.connecting_slot, node, 0 );
}
}
}
@@ -3573,6 +3709,13 @@ LGraphCanvas.prototype.processMouseUp = function(e)
}
else //no node being dragged
{
+ //get node over
+ var node = this.graph.getNodeOnPos( e.canvasX, e.canvasY, this.visible_nodes );
+
+ var now = LiteGraph.getTime();
+ if ( !node && (now - this.last_mouseclick) < 300 )
+ this.deselectAllNodes();
+
this.dirty_canvas = true;
this.dragging_canvas = false;
@@ -3671,17 +3814,23 @@ LGraphCanvas.prototype.processKey = function(e)
return;
var block_default = false;
+ //console.log(e); //debug
if(e.target.localName == "input")
return;
if(e.type == "keydown")
{
- console.log(e);
+ if(e.keyCode == 32)
+ {
+ this.dragging_canvas = true;
+ block_default = true;
+ }
+
//select all Control A
if(e.keyCode == 65 && e.ctrlKey)
{
- this.selectAllNodes();
+ this.selectNodes();
block_default = true;
}
@@ -3689,36 +3838,16 @@ LGraphCanvas.prototype.processKey = function(e)
{
if(this.selected_nodes)
{
- var nodes_data = [];
- for(var i in this.selected_nodes)
- nodes_data.push( this.selected_nodes[i].serialize() );
- localStorage.setItem( "litegrapheditor_clipboard", JSON.stringify(nodes_data) );
+ this.copyToClipboard();
block_default = true;
}
}
if(e.code == "KeyV" && (e.metaKey || e.ctrlKey) && !e.shiftKey ) //paste
{
- var data = localStorage.getItem( "litegrapheditor_clipboard" );
- if(data)
- {
- var nodes_data = JSON.parse(data);
- for(var i = 0; i < nodes_data.length; ++i)
- {
- var node_data = nodes_data[i];
- var node = LiteGraph.createNode( node_data.type );
- if(node)
- {
- node.configure(node_data);
- node.pos[0] += 5;
- node.pos[1] += 5;
- this.graph.add( node );
- }
- }
- }
+ this.pasteFromClipboard();
}
-
//delete or backspace
if(e.keyCode == 46 || e.keyCode == 8)
{
@@ -3737,6 +3866,9 @@ LGraphCanvas.prototype.processKey = function(e)
}
else if( e.type == "keyup" )
{
+ if(e.keyCode == 32)
+ this.dragging_canvas = false;
+
if(this.selected_nodes)
for (var i in this.selected_nodes)
if(this.selected_nodes[i].onKeyUp)
@@ -3752,6 +3884,79 @@ LGraphCanvas.prototype.processKey = function(e)
}
}
+LGraphCanvas.prototype.copyToClipboard = function()
+{
+ var clipboard_info = {
+ nodes: [],
+ links: []
+ };
+ var index = 0;
+ var selected_nodes_array = [];
+ for(var i in this.selected_nodes)
+ {
+ var node = this.selected_nodes[i];
+ node._relative_id = index;
+ selected_nodes_array.push( node );
+ index += 1;
+ }
+
+ for(var i = 0; i < selected_nodes_array.length; ++i)
+ {
+ var node = selected_nodes_array[i];
+ clipboard_info.nodes.push( node.clone().serialize() );
+ if(node.inputs && node.inputs.length)
+ for(var j = 0; j < node.inputs.length; ++j)
+ {
+ var input = node.inputs[j];
+ if(!input || input.link == null)
+ continue;
+ var link_info = this.graph.links[ input.link ];
+ if(!link_info)
+ continue;
+ var target_node = this.graph.getNodeById( link_info.origin_id );
+ if(!target_node || !this.selected_nodes[ target_node.id ] ) //improve this by allowing connections to non-selected nodes
+ continue; //not selected
+ clipboard_info.links.push([ target_node._relative_id, j, node._relative_id, link_info.target_slot ]);
+ }
+ }
+ localStorage.setItem( "litegrapheditor_clipboard", JSON.stringify( clipboard_info ) );
+}
+
+LGraphCanvas.prototype.pasteFromClipboard = function()
+{
+ var data = localStorage.getItem( "litegrapheditor_clipboard" );
+ if(!data)
+ return;
+
+ //create nodes
+ var clipboard_info = JSON.parse(data);
+ var nodes = [];
+ for(var i = 0; i < clipboard_info.nodes.length; ++i)
+ {
+ var node_data = clipboard_info.nodes[i];
+ var node = LiteGraph.createNode( node_data.type );
+ if(node)
+ {
+ node.configure(node_data);
+ node.pos[0] += 5;
+ node.pos[1] += 5;
+ this.graph.add( node );
+ nodes.push( node );
+ }
+ }
+
+ //create links
+ for(var i = 0; i < clipboard_info.links.length; ++i)
+ {
+ var link_info = clipboard_info.links[i];
+ var origin_node = nodes[ link_info[0] ];
+ var target_node = nodes[ link_info[2] ];
+ origin_node.connect( link_info[1], target_node, link_info[3] );
+ }
+
+ this.selectNodes( nodes );
+}
+
LGraphCanvas.prototype.processDrop = function(e)
{
e.preventDefault();
@@ -3841,42 +4046,6 @@ LGraphCanvas.prototype.checkDropItem = function(e)
}
-LGraphCanvas.prototype.processNodeSelected = function(n,e)
-{
- n.selected = true;
- if (n.onSelected)
- n.onSelected();
-
- if(e && e.shiftKey) //add to selection
- this.selected_nodes[n.id] = n;
- else
- {
- this.selected_nodes = {};
- this.selected_nodes[ n.id ] = n;
- }
-
- this.dirty_canvas = true;
-
- if(this.onNodeSelected)
- this.onNodeSelected(n);
-
- //if(this.node_in_panel) this.showNodePanel(n);
-}
-
-LGraphCanvas.prototype.processNodeDeselected = function(n)
-{
- n.selected = false;
- if(n.onDeselected)
- n.onDeselected();
-
- delete this.selected_nodes[n.id];
-
- if(this.onNodeDeselected)
- this.onNodeDeselected(n);
-
- this.dirty_canvas = true;
-}
-
LGraphCanvas.prototype.processNodeDblClicked = function(n)
{
if(this.onShowNodePanel)
@@ -3888,44 +4057,100 @@ LGraphCanvas.prototype.processNodeDblClicked = function(n)
this.setDirty(true);
}
-LGraphCanvas.prototype.selectNode = function(node)
+LGraphCanvas.prototype.processNodeSelected = function(node,e)
{
- this.deselectAllNodes();
-
- if(!node)
- return;
-
- if(!node.selected && node.onSelected)
- node.onSelected();
- node.selected = true;
- this.selected_nodes[ node.id ] = node;
- this.setDirty(true);
+ this.selectNode( node, e && e.shiftKey );
+ if(this.onNodeSelected)
+ this.onNodeSelected(node);
}
-LGraphCanvas.prototype.selectAllNodes = function()
+LGraphCanvas.prototype.processNodeDeselected = function(node)
{
- for(var i = 0; i < this.graph._nodes.length; ++i)
+ this.deselectNode(node);
+ if(this.onNodeDeselected)
+ this.onNodeDeselected(node);
+}
+
+LGraphCanvas.prototype.selectNode = function( node, add_to_current_selection )
+{
+ if(node == null)
+ this.deselectAllNodes();
+ else
+ this.selectNodes([node], add_to_current_selection );
+}
+
+LGraphCanvas.prototype.selectNodes = function( nodes, add_to_current_selection )
+{
+ if(!add_to_current_selection)
+ this.deselectAllNodes();
+
+ nodes = nodes || this.graph._nodes;
+ for(var i = 0; i < nodes.length; ++i)
{
- var n = this.graph._nodes[i];
- if(!n.selected && n.onSelected)
- n.onSelected();
- n.selected = true;
- this.selected_nodes[this.graph._nodes[i].id] = n;
+ var node = nodes[i];
+ if(node.selected)
+ continue;
+
+ if( !node.selected && node.onSelected )
+ node.onSelected();
+ node.selected = true;
+ this.selected_nodes[ node.id ] = node;
+
+ if(node.inputs)
+ for(var i = 0; i < node.inputs.length; ++i)
+ this.highlighted_links[ node.inputs[i].link ] = true;
+ if(node.outputs)
+ for(var i = 0; i < node.outputs.length; ++i)
+ {
+ var out = node.outputs[i];
+ if( out.links )
+ for(var j = 0; j < out.links.length; ++j)
+ this.highlighted_links[ out.links[j] ] = true;
+ }
+
}
this.setDirty(true);
}
+LGraphCanvas.prototype.deselectNode = function( node )
+{
+ if(!node.selected)
+ return;
+ if(node.onDeselected)
+ node.onDeselected();
+ node.selected = false;
+
+ //remove highlighted
+ if(node.inputs)
+ for(var i = 0; i < node.inputs.length; ++i)
+ delete this.highlighted_links[ node.inputs[i].link ];
+ if(node.outputs)
+ for(var i = 0; i < node.outputs.length; ++i)
+ {
+ var out = node.outputs[i];
+ if( out.links )
+ for(var j = 0; j < out.links.length; ++j)
+ delete this.highlighted_links[ out.links[j] ];
+ }
+}
+
LGraphCanvas.prototype.deselectAllNodes = function()
{
- for(var i in this.selected_nodes)
+ if(!this.graph)
+ return;
+ var nodes = this.graph._nodes;
+ for(var i = 0, l = nodes.length; i < l; ++i)
{
- var n = this.selected_nodes;
- if(n.onDeselected)
- n.onDeselected();
- n.selected = false;
+ var node = nodes[i];
+ if(!node.selected)
+ continue;
+ if(node.onDeselected)
+ node.onDeselected();
+ node.selected = false;
}
this.selected_nodes = {};
+ this.highlighted_links = {};
this.setDirty(true);
}
@@ -3938,6 +4163,7 @@ LGraphCanvas.prototype.deleteSelectedNodes = function()
this.graph.remove(m);
}
this.selected_nodes = {};
+ this.highlighted_links = {};
this.setDirty(true);
}
@@ -3982,20 +4208,25 @@ LGraphCanvas.prototype.setZoom = function(value, zooming_center)
this.dirty_bgcanvas = true;
}
-LGraphCanvas.prototype.convertOffsetToCanvas = function(pos)
+LGraphCanvas.prototype.convertOffsetToCanvas = function( pos, out )
{
- return [pos[0] / this.scale - this.offset[0], pos[1] / this.scale - this.offset[1]];
+ out = out || [];
+ out[0] = pos[0] / this.scale - this.offset[0];
+ out[1] = pos[1] / this.scale - this.offset[1];
+ return out;
}
-LGraphCanvas.prototype.convertCanvasToOffset = function(pos)
+LGraphCanvas.prototype.convertCanvasToOffset = function( pos, out )
{
- return [(pos[0] + this.offset[0]) * this.scale,
- (pos[1] + this.offset[1]) * this.scale ];
+ out = out || [];
+ out[0] = (pos[0] + this.offset[0]) * this.scale;
+ out[1] = (pos[1] + this.offset[1]) * this.scale;
+ return out;
}
LGraphCanvas.prototype.convertEventToCanvas = function(e)
{
- var rect = this.canvas.getClientRects()[0];
+ var rect = this.canvas.getBoundingClientRect();
return this.convertOffsetToCanvas([e.pageX - rect.left,e.pageY - rect.top]);
}
@@ -4022,14 +4253,16 @@ LGraphCanvas.prototype.sendToBack = function(n)
/* LGraphCanvas render */
+var temp = new Float32Array(4);
-LGraphCanvas.prototype.computeVisibleNodes = function()
+LGraphCanvas.prototype.computeVisibleNodes = function( nodes, out )
{
- var temp = new Float32Array(4);
- var visible_nodes = [];
- for(var i = 0, l = this.graph._nodes.length; i < l; ++i)
+ var visible_nodes = out || [];
+ visible_nodes.length = 0;
+ nodes = nodes || this.graph._nodes;
+ for(var i = 0, l = nodes.length; i < l; ++i)
{
- var n = this.graph._nodes[i];
+ var n = nodes[i];
//skip rendering nodes in live mode
if(this.live_mode && !n.onDrawBackground && !n.onDrawForeground)
@@ -4057,7 +4290,7 @@ LGraphCanvas.prototype.draw = function(force_canvas, force_bgcanvas)
{
var start = [-this.offset[0], -this.offset[1] ];
var end = [start[0] + this.canvas.width / this.scale, start[1] + this.canvas.height / this.scale];
- this.visible_area = new Float32Array([start[0],start[1],end[0],end[1]]);
+ this.visible_area = new Float32Array([ start[0], start[1], end[0] - start[0], end[1] - start[1] ]);
}
if(this.dirty_bgcanvas || force_bgcanvas || this.always_render_background || (this.graph && this.graph._last_trigger_time && (now - this.graph._last_trigger_time) < 1000) )
@@ -4124,8 +4357,7 @@ LGraphCanvas.prototype.drawFrontCanvas = function()
//draw nodes
var drawn_nodes = 0;
- var visible_nodes = this.computeVisibleNodes();
- this.visible_nodes = visible_nodes;
+ var visible_nodes = this.computeVisibleNodes( null, this.visible_nodes );
for (var i = 0; i < visible_nodes.length; ++i)
{
@@ -4177,6 +4409,14 @@ LGraphCanvas.prototype.drawFrontCanvas = function()
ctx.fill();
}
}
+
+ if( this.dragging_rectangle )
+ {
+ ctx.strokeStyle = "#FFF";
+ ctx.strokeRect( this.dragging_rectangle[0], this.dragging_rectangle[1], this.dragging_rectangle[2], this.dragging_rectangle[3] );
+ }
+
+
ctx.restore();
}
@@ -4281,7 +4521,7 @@ LGraphCanvas.prototype.drawBackCanvas = function()
if(pattern)
{
ctx.fillStyle = pattern;
- ctx.fillRect(this.visible_area[0],this.visible_area[1],this.visible_area[2]-this.visible_area[0],this.visible_area[3]-this.visible_area[1]);
+ ctx.fillRect(this.visible_area[0],this.visible_area[1],this.visible_area[2],this.visible_area[3]);
ctx.fillStyle = "transparent";
}
@@ -4294,7 +4534,7 @@ LGraphCanvas.prototype.drawBackCanvas = function()
//DEBUG: show clipping area
//ctx.fillStyle = "red";
- //ctx.fillRect( this.visible_area[0] + 10, this.visible_area[1] + 10, this.visible_area[2] - this.visible_area[0] - 20, this.visible_area[3] - this.visible_area[1] - 20);
+ //ctx.fillRect( this.visible_area[0] + 10, this.visible_area[1] + 10, this.visible_area[2] - 20, this.visible_area[3] - 20);
//bg
ctx.strokeStyle = "#235";
@@ -4772,6 +5012,9 @@ LGraphCanvas.prototype.renderLink = function( ctx, a, b, link, skip_border, flow
if(!color)
color = this.default_link_color;
+ if( link != null && this.highlighted_links[ link.id ] )
+ color = "#FFF";
+
//begin line shape
ctx.beginPath();
@@ -5381,7 +5624,7 @@ LGraphCanvas.prototype.createDialog = function( html, options )
dialog.className = "graphdialog";
dialog.innerHTML = html;
- var rect = this.canvas.getClientRects()[0];
+ var rect = this.canvas.getBoundingClientRect();
var offsetx = -20;
var offsety = -20;
if(rect)
@@ -5517,7 +5760,8 @@ LGraphCanvas.onMenuNodeClone = function( value, options, e, menu, node )
{
if(node.clonable == false) return;
var newnode = node.clone();
- if(!newnode) return;
+ if(!newnode)
+ return;
newnode.pos = [node.pos[0]+5,node.pos[1]+5];
node.graph.add(newnode);
node.setDirtyCanvas(true,true);
@@ -5683,7 +5927,7 @@ LGraphCanvas.prototype.processContextMenu = function( node, event )
if( slot_info )
slot_info.label = input.value;
that.setDirty(true);
- }
+ }
dialog.close();
});
}
@@ -5779,13 +6023,18 @@ function isInsideBounding(p,bb)
}
LiteGraph.isInsideBounding = isInsideBounding;
-//boundings overlap, format: [start,end]
+//boundings overlap, format: [ startx, starty, width, height ]
function overlapBounding(a,b)
{
- if ( a[0] > b[2] ||
- a[1] > b[3] ||
- a[2] < b[0] ||
- a[3] < b[1])
+ var A_end_x = a[0] + a[2];
+ var A_end_y = a[1] + a[3];
+ var B_end_x = b[0] + b[2];
+ var B_end_y = b[1] + b[3];
+
+ if ( a[0] > B_end_x ||
+ a[1] > B_end_y ||
+ A_end_x < b[0] ||
+ A_end_y < b[1])
return false;
return true;
}
@@ -6190,13 +6439,15 @@ LiteGraph.extendClass = function ( target, origin )
}
}
-/*
-LiteGraph.createNodetypeWrapper = function( class_object )
-{
- //create Nodetype object
+LiteGraph.getParameterNames = function(func) {
+ return (func + '')
+ .replace(/[/][/].*$/mg,'') // strip single-line comments
+ .replace(/\s+/g, '') // strip white space
+ .replace(/[/][*][^/*]*[*][/]/g, '') // strip multi-line comments /**/
+ .split('){', 1)[0].replace(/^[^(]*[(]/, '') // extract the parameters
+ .replace(/=[^,]+/g, '') // strip any ES6 defaults
+ .split(',').filter(Boolean); // split & filter [""]
}
-//LiteGraph.registerNodeType("scene/global", LGraphGlobal );
-*/
if( typeof(window) != "undefined" && !window["requestAnimationFrame"] )
{
diff --git a/src/nodes/base.js b/src/nodes/base.js
index 5b612dd13..4bb795861 100755
--- a/src/nodes/base.js
+++ b/src/nodes/base.js
@@ -363,6 +363,24 @@ Watch.prototype.onDrawBackground = function(ctx)
LiteGraph.registerNodeType("basic/watch", Watch);
+//Watch a value in the editor
+function Pass()
+{
+ this.addInput("in",0);
+ this.addOutput("out",0);
+ this.size = [40,20];
+}
+
+Pass.title = "Pass";
+Pass.desc = "Allows to connect different types";
+
+Pass.prototype.onExecute = function()
+{
+ this.setOutputData( 0, this.getInputData(0) );
+}
+
+LiteGraph.registerNodeType("basic/pass", Pass);
+
//Show value inside the debug console
function Console()
diff --git a/src/nodes/interface.js b/src/nodes/interface.js
index 58262e889..861a53f16 100755
--- a/src/nodes/interface.js
+++ b/src/nodes/interface.js
@@ -210,7 +210,7 @@ var LiteGraph = global.LiteGraph;
{
//this.oldmouse = null;
}
-
+
WidgetKnob.prototype.onWidget = function(e,widget)
{
if(widget.name=="increase")
@@ -252,7 +252,7 @@ var LiteGraph = global.LiteGraph;
WidgetHSlider.title = "H.Slider";
WidgetHSlider.desc = "Linear slider controller";
- WidgetHSlider.prototype.onInit = function()
+ WidgetHSlider.prototype.onAdded = function()
{
this.value = 0.5;
this.imgfg = this.loadImage("imgs/slider_fg.png");
@@ -278,7 +278,7 @@ var LiteGraph = global.LiteGraph;
WidgetHSlider.prototype.onDrawImage = function(ctx)
{
- if(!this.imgfg || !this.imgfg.width)
+ if(!this.imgfg || !this.imgfg.width)
return;
//border
@@ -405,8 +405,8 @@ var LiteGraph = global.LiteGraph;
createGradient: function(ctx)
{
- this.lineargradient = ctx.createLinearGradient(0,0,0,this.size[1]);
- this.lineargradient.addColorStop(0,this.properties["bgcolorTop"]);
+ this.lineargradient = ctx.createLinearGradient(0,0,0,this.size[1]);
+ this.lineargradient.addColorStop(0,this.properties["bgcolorTop"]);
this.lineargradient.addColorStop(1,this.properties["bgcolorBottom"]);
},
@@ -463,7 +463,7 @@ var LiteGraph = global.LiteGraph;
if(!this.oldmouse) return;
var m = [ e.canvasX - this.pos[0], e.canvasY - this.pos[1] ];
-
+
this.properties.x = m[0] / this.size[0];
this.properties.y = m[1] / this.size[1];
@@ -505,8 +505,8 @@ var LiteGraph = global.LiteGraph;
createGradient: function(ctx)
{
- this.lineargradient = ctx.createLinearGradient(0,0,0,this.size[1]);
- this.lineargradient.addColorStop(0,this.properties["bgcolorTop"]);
+ this.lineargradient = ctx.createLinearGradient(0,0,0,this.size[1]);
+ this.lineargradient.addColorStop(0,this.properties["bgcolorTop"]);
this.lineargradient.addColorStop(1,this.properties["bgcolorBottom"]);
},
@@ -514,7 +514,7 @@ var LiteGraph = global.LiteGraph;
{
ctx.fillStyle = this.mouseOver ? this.properties["color"] : "#AAA";
- if(this.clicking)
+ if(this.clicking)
ctx.fillStyle = "#FFF";
ctx.strokeStyle = "#AAA";
@@ -544,7 +544,7 @@ var LiteGraph = global.LiteGraph;
this.createGradient(ctx);
ctx.fillStyle = this.mouseOver ? this.properties["color"] : this.lineargradient;
- if(this.clicking)
+ if(this.clicking)
ctx.fillStyle = "#444";
ctx.strokeStyle = "#FFF";
@@ -575,7 +575,7 @@ var LiteGraph = global.LiteGraph;
}
else if(module && module.onTrigger)
{
- module.onTrigger();
+ module.onTrigger();
}
},
@@ -732,8 +732,8 @@ var LiteGraph = global.LiteGraph;
return;
}
- this.lineargradient = ctx.createLinearGradient(0,0,0,this.size[1]);
- this.lineargradient.addColorStop(0,this.properties["bgcolorTop"]);
+ this.lineargradient = ctx.createLinearGradient(0,0,0,this.size[1]);
+ this.lineargradient.addColorStop(0,this.properties["bgcolorTop"]);
this.lineargradient.addColorStop(1,this.properties["bgcolorBottom"]);
}