fixed two bugs

This commit is contained in:
tamat
2015-12-27 19:41:06 +01:00
parent 2c5717aace
commit 4d3e472a19
3 changed files with 17 additions and 9 deletions

View File

@@ -1884,6 +1884,7 @@ LGraphNode.prototype.disconnectOutput = function(slot, target_node)
if(!output.links || output.links.length == 0)
return false;
//one of the links
if(target_node)
{
if(target_node.constructor === Number)
@@ -1906,7 +1907,7 @@ LGraphNode.prototype.disconnectOutput = function(slot, target_node)
}
}
}
else
else //all the links
{
for(var i = 0, l = output.links.length; i < l; i++)
{
@@ -1916,6 +1917,7 @@ LGraphNode.prototype.disconnectOutput = function(slot, target_node)
var target_node = this.graph.getNodeById( link_info.target_id );
if(target_node)
target_node.inputs[ link_info.target_slot ].link = null; //remove other side link
delete this.graph.links[ link_id ]; //remove the link from the links pool
}
output.links = null;
}
@@ -4779,11 +4781,13 @@ LiteGraph.createContextualMenu = function(values,options, ref_window)
root.addEventListener("mouseout", function(e) {
//console.log("OUT!");
var aux = e.toElement;
//check if mouse leave a inner element
var aux = e.relatedTarget || e.toElement;
while(aux != this && aux != ref_window.document)
aux = aux.parentNode;
if(aux == this) return;
if(aux == this)
return;
this.mouse_inside = false;
if(!this.block_close)
this.closeMenu();

View File

@@ -48,7 +48,7 @@ LGraphNode.prototype.connect=function(a,b,c){c=c||0;if(a.constructor===String){i
console.log("Connect: Error, no slot of name "+c),!1}else if(!b.inputs||c>=b.inputs.length)return LiteGraph.debug&&console.log("Connect: Error, slot number not found"),!1;-1!=c&&null!=b.inputs[c].link&&b.disconnectInput(c);this.setDirtyCanvas(!1,!0);this.graph.onConnectionChange();var d=this.outputs[a];if(b.onConnectInput&&!1===b.onConnectInput(c,d.type,d))return!1;-1==c?(null==d.links&&(d.links=[]),d.links.push({id:b.id,slot:-1})):d.type&&b.inputs[c].type&&d.type.toLowerCase()!=b.inputs[c].type.toLowerCase()||
(a={id:this.graph.last_link_id++,origin_id:this.id,origin_slot:a,target_id:b.id,target_slot:c},this.graph.links[a.id]=a,null==d.links&&(d.links=[]),d.links.push(a.id),b.inputs[c].link=a.id);return!0};
LGraphNode.prototype.disconnectOutput=function(a,b){if(a.constructor===String){if(a=this.findOutputSlot(a),-1==a)return LiteGraph.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.outputs||a>=this.outputs.length)return LiteGraph.debug&&console.log("Connect: Error, slot number not found"),!1;var c=this.outputs[a];if(!c.links||0==c.links.length)return!1;if(b){b.constructor===Number&&(b=this.graph.getNodeById(b));if(!b)throw"Target Node not found";for(var d=0,e=c.links.length;d<
e;d++){var f=c.links[d],g=this.graph.links[f];if(g.target_id==b.id){c.links.splice(d,1);b.inputs[g.target_slot].link=null;delete this.graph.links[f];break}}}else{d=0;for(e=c.links.length;d<e;d++)if(f=c.links[d],g=this.graph.links[f],b=this.graph.getNodeById(g.target_id))b.inputs[g.target_slot].link=null;c.links=null}this.setDirtyCanvas(!1,!0);this.graph.onConnectionChange();return!0};
e;d++){var f=c.links[d],g=this.graph.links[f];if(g.target_id==b.id){c.links.splice(d,1);b.inputs[g.target_slot].link=null;delete this.graph.links[f];break}}}else{d=0;for(e=c.links.length;d<e;d++){f=c.links[d];g=this.graph.links[f];if(b=this.graph.getNodeById(g.target_id))b.inputs[g.target_slot].link=null;delete this.graph.links[f]}c.links=null}this.setDirtyCanvas(!1,!0);this.graph.onConnectionChange();return!0};
LGraphNode.prototype.disconnectInput=function(a){if(a.constructor===String){if(a=this.findInputSlot(a),-1==a)return LiteGraph.debug&&console.log("Connect: Error, no slot of name "+a),!1}else if(!this.inputs||a>=this.inputs.length)return LiteGraph.debug&&console.log("Connect: Error, slot number not found"),!1;if(!this.inputs[a])return!1;var b=this.inputs[a].link;this.inputs[a].link=null;if(b=this.graph.links[b]){a=this.graph.getNodeById(b.origin_id);if(!a)return!1;a=a.outputs[b.origin_slot];if(!a||
!a.links||0==a.links.length)return!1;for(var c=0,d=a.links.length;c<d;c++)if(b=a.links[c],b=this.graph.links[b],b.target_id==this.id){a.links.splice(c,1);break}}this.setDirtyCanvas(!1,!0);this.graph.onConnectionChange();return!0};
LGraphNode.prototype.getConnectionPos=function(a,b){return this.flags.collapsed?a?[this.pos[0],this.pos[1]-0.5*LiteGraph.NODE_TITLE_HEIGHT]:[this.pos[0]+LiteGraph.NODE_COLLAPSED_WIDTH,this.pos[1]-0.5*LiteGraph.NODE_TITLE_HEIGHT]:a&&-1==b?[this.pos[0]+10,this.pos[1]+10]:a&&this.inputs.length>b&&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]]:
@@ -140,8 +140,8 @@ function isInsideBounding(a,b){return a[0]<b[0][0]||a[1]<b[0][1]||a[0]>b[1][0]||
function num2hex(a){for(var b="#",c,d,e=0;3>e;e++)c=a[e]/16,d=a[e]%16,b+="0123456789ABCDEF".charAt(c)+"0123456789ABCDEF".charAt(d);return b}
LiteGraph.createContextualMenu=function(a,b,c){function d(a){var c=!0;b.callback&&(a=b.callback.call(e,this.data,a),void 0!==a&&(c=a));c&&LiteGraph.closeAllContextualMenus()}this.options=b=b||{};c=c||window;b.from||LiteGraph.closeAllContextualMenus();var e=c.document.createElement("div");e.className="graphcontextualmenu graphmenubar-panel";this.root=e;var f=e.style;f.minWidth="100px";f.minHeight="20px";f.position="fixed";f.top="100px";f.left="100px";f.color="#AAF";f.padding="2px";f.borderBottom="2px solid #AAF";
f.backgroundColor="#444";b.title&&(f=document.createElement("div"),f.className="graphcontextualmenu-title",f.innerHTML=b.title,e.appendChild(f));e.addEventListener("contextmenu",function(a){a.preventDefault();return!1});for(var g in a){var h=a[g],f=c.document.createElement("div");f.className="graphmenu-entry";null==h?f.className="graphmenu-entry separator":(h.is_menu&&(f.className+=" submenu"),h.disabled&&(f.className+=" disabled"),f.style.cursor="pointer",f.dataset.value="string"==typeof h?h:h.value,
f.data=h,f.innerHTML="string"==typeof h?a.constructor==Array?a[g]:g:h.content?h.content:g,f.addEventListener("click",d));e.appendChild(f)}e.addEventListener("mouseover",function(a){this.mouse_inside=!0});e.addEventListener("mouseout",function(a){for(a=a.toElement;a!=this&&a!=c.document;)a=a.parentNode;a!=this&&(this.mouse_inside=!1,this.block_close||this.closeMenu())});c.document.body.appendChild(e);a=e.getClientRects()[0];b.from&&(b.from.block_close=!0);h=b.left||0;g=b.top||0;b.event&&(h=b.event.pageX-
10,g=b.event.pageY-10,b.left&&(h=b.left),f=c.document.body.getClientRects()[0],b.from&&(h=b.from.getClientRects()[0],h=h.left+h.width),h>f.width-a.width-10&&(h=f.width-a.width-10),g>f.height-a.height-10&&(g=f.height-a.height-10));e.style.left=h+"px";e.style.top=g+"px";e.closeMenu=function(){b.from&&(b.from.block_close=!1,b.from.mouse_inside||b.from.closeMenu());this.parentNode&&c.document.body.removeChild(this)};return e};
f.data=h,f.innerHTML="string"==typeof h?a.constructor==Array?a[g]:g:h.content?h.content:g,f.addEventListener("click",d));e.appendChild(f)}e.addEventListener("mouseover",function(a){this.mouse_inside=!0});e.addEventListener("mouseout",function(a){for(a=a.relatedTarget||a.toElement;a!=this&&a!=c.document;)a=a.parentNode;a!=this&&(this.mouse_inside=!1,this.block_close||this.closeMenu())});c.document.body.appendChild(e);a=e.getClientRects()[0];b.from&&(b.from.block_close=!0);h=b.left||0;g=b.top||0;b.event&&
(h=b.event.pageX-10,g=b.event.pageY-10,b.left&&(h=b.left),f=c.document.body.getClientRects()[0],b.from&&(h=b.from.getClientRects()[0],h=h.left+h.width),h>f.width-a.width-10&&(h=f.width-a.width-10),g>f.height-a.height-10&&(g=f.height-a.height-10));e.style.left=h+"px";e.style.top=g+"px";e.closeMenu=function(){b.from&&(b.from.block_close=!1,b.from.mouse_inside||b.from.closeMenu());this.parentNode&&c.document.body.removeChild(this)};return e};
LiteGraph.closeAllContextualMenus=function(){var a=document.querySelectorAll(".graphcontextualmenu");if(a.length){for(var b=[],c=0;c<a.length;c++)b.push(a[c]);for(c in b)b[c].parentNode&&b[c].parentNode.removeChild(b[c])}};
LiteGraph.extendClass=function(a,b){for(var c in b)a.hasOwnProperty(c)||(a[c]=b[c]);if(b.prototype)for(c in b.prototype)b.prototype.hasOwnProperty(c)&&!a.prototype.hasOwnProperty(c)&&(b.prototype.__lookupGetter__(c)?a.prototype.__defineGetter__(c,b.prototype.__lookupGetter__(c)):a.prototype[c]=b.prototype[c],b.prototype.__lookupSetter__(c)&&a.prototype.__defineSetter__(c,b.prototype.__lookupSetter__(c)))};
window.requestAnimationFrame||(window.requestAnimationFrame=window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)});

View File

@@ -1883,6 +1883,7 @@ LGraphNode.prototype.disconnectOutput = function(slot, target_node)
if(!output.links || output.links.length == 0)
return false;
//one of the links
if(target_node)
{
if(target_node.constructor === Number)
@@ -1905,7 +1906,7 @@ LGraphNode.prototype.disconnectOutput = function(slot, target_node)
}
}
}
else
else //all the links
{
for(var i = 0, l = output.links.length; i < l; i++)
{
@@ -1915,6 +1916,7 @@ LGraphNode.prototype.disconnectOutput = function(slot, target_node)
var target_node = this.graph.getNodeById( link_info.target_id );
if(target_node)
target_node.inputs[ link_info.target_slot ].link = null; //remove other side link
delete this.graph.links[ link_id ]; //remove the link from the links pool
}
output.links = null;
}
@@ -4778,11 +4780,13 @@ LiteGraph.createContextualMenu = function(values,options, ref_window)
root.addEventListener("mouseout", function(e) {
//console.log("OUT!");
var aux = e.toElement;
//check if mouse leave a inner element
var aux = e.relatedTarget || e.toElement;
while(aux != this && aux != ref_window.document)
aux = aux.parentNode;
if(aux == this) return;
if(aux == this)
return;
this.mouse_inside = false;
if(!this.block_close)
this.closeMenu();