Fix widget buttons registering clicks twice

This commit is contained in:
RobTheFiveNine
2021-06-15 14:37:17 +01:00
parent 40907189f3
commit d0eedf7232
7 changed files with 63 additions and 67 deletions

View File

@@ -210,8 +210,8 @@ c,.5,n,r);d&&d._pos&&(d._pos[0]=e[0],d._pos[1]=e[1]);.6<=this.ds.scale&&this.hig
case "number":case "combo":c.textAlign="left";c.strokeStyle=r;c.fillStyle=h;c.beginPath();n?c.roundRect(15,b,m-30,g,.5*g):c.rect(15,b,m-30,g);c.fill();n&&(y.disabled||c.stroke(),c.fillStyle=k,y.disabled||(c.beginPath(),c.moveTo(31,b+5),c.lineTo(21,b+.5*g),c.lineTo(31,b+g-5),c.fill(),c.beginPath(),c.moveTo(m-15-16,b+5),c.lineTo(m-15-6,b+.5*g),c.lineTo(m-15-16,b+g-5),c.fill()),c.fillStyle=p,c.fillText(y.name,35,t+.7*g),c.fillStyle=k,c.textAlign="right","number"==y.type?c.fillText(Number(y.value).toFixed(void 0!==
y.options.precision?y.options.precision:3),m-30-20,t+.7*g):(q=y.value,y.options.values&&(w=y.options.values,w.constructor===Function&&(w=w()),w&&w.constructor!==Array&&(q=w[y.value])),c.fillText(q,m-30-20,t+.7*g)));break;case "string":case "text":c.textAlign="left";c.strokeStyle=r;c.fillStyle=h;c.beginPath();n?c.roundRect(15,b,m-30,g,.5*g):c.rect(15,b,m-30,g);c.fill();n&&(y.disabled||c.stroke(),c.save(),c.beginPath(),c.rect(15,b,m-30,g),c.clip(),c.fillStyle=p,null!=y.name&&c.fillText(y.name,30,t+
.7*g),c.fillStyle=k,c.textAlign="right",c.fillText(String(y.value).substr(0,30),m-30,t+.7*g),c.restore());break;default:y.draw&&y.draw(c,a,m,t,g)}b+=(y.computeSize?y.computeSize(m)[1]:g)+4;c.globalAlpha=this.editor_alpha}c.restore();c.textAlign="left"};h.prototype.processNodeWidgets=function(a,b,c,d){function e(d,e){d.value=e;d.options&&d.options.property&&void 0!==a.properties[d.options.property]&&a.setProperty(d.options.property,e);d.callback&&d.callback(d.value,r,a,b,c)}if(!a.widgets||!a.widgets.length)return null;
for(var f=b[0]-a.pos[0],g=b[1]-a.pos[1],n=a.size[0],r=this,h=this.getCanvasWindow(),k=0;k<a.widgets.length;++k){var p=a.widgets[k];if(p&&!p.disabled){var z=p.computeSize?p.computeSize(n)[1]:l.NODE_WIDGET_HEIGHT,t=p.width||n;if(p==d||!(6>f||f>t-12||g<p.last_y||g>p.last_y+z||void 0===p.last_y)){d=p.value;switch(p.type){case "button":if("mousemove"===c.type)break;p.callback&&setTimeout(function(){p.callback(p,r,a,b,c)},20);this.dirty_canvas=p.clicked=!0;break;case "slider":h=Math.clamp((f-15)/(t-30),
0,1);p.value=p.options.min+(p.options.max-p.options.min)*h;p.callback&&setTimeout(function(){e(p,p.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":d=p.value;if("mousemove"==c.type&&"number"==p.type)p.value+=.1*c.deltaX*(p.options.step||1),null!=p.options.min&&p.value<p.options.min&&(p.value=p.options.min),null!=p.options.max&&p.value>p.options.max&&(p.value=p.options.max);else if("mousedown"==c.type){var m=p.options.values;m&&m.constructor===Function&&(m=p.options.values(p,a));var q=
for(var f=b[0]-a.pos[0],g=b[1]-a.pos[1],n=a.size[0],r=this,h=this.getCanvasWindow(),k=0;k<a.widgets.length;++k){var p=a.widgets[k];if(p&&!p.disabled){var z=p.computeSize?p.computeSize(n)[1]:l.NODE_WIDGET_HEIGHT,t=p.width||n;if(p==d||!(6>f||f>t-12||g<p.last_y||g>p.last_y+z||void 0===p.last_y)){d=p.value;switch(p.type){case "button":"mousedown"===c.type&&(p.callback&&setTimeout(function(){p.callback(p,r,a,b,c)},20),this.dirty_canvas=p.clicked=!0);break;case "slider":h=Math.clamp((f-15)/(t-30),0,1);
p.value=p.options.min+(p.options.max-p.options.min)*h;p.callback&&setTimeout(function(){e(p,p.value)},20);this.dirty_canvas=!0;break;case "number":case "combo":d=p.value;if("mousemove"==c.type&&"number"==p.type)p.value+=.1*c.deltaX*(p.options.step||1),null!=p.options.min&&p.value<p.options.min&&(p.value=p.options.min),null!=p.options.max&&p.value>p.options.max&&(p.value=p.options.max);else if("mousedown"==c.type){var m=p.options.values;m&&m.constructor===Function&&(m=p.options.values(p,a));var q=
null;"number"!=p.type&&(q=m.constructor===Array?m:Object.keys(m));f=40>f?-1:f>t-40?1:0;if("number"==p.type)p.value+=.1*f*(p.options.step||1),null!=p.options.min&&p.value<p.options.min&&(p.value=p.options.min),null!=p.options.max&&p.value>p.options.max&&(p.value=p.options.max);else if(f)h=-1,this.last_mouseclick=0,h=m.constructor===Object?q.indexOf(String(p.value))+f:q.indexOf(p.value)+f,h>=q.length&&(h=q.length-1),0>h&&(h=0),p.value=m.constructor===Array?m[h]:h;else{var w=m!=q?Object.values(m):m;
new l.ContextMenu(w,{scale:Math.max(1,this.ds.scale),event:c,className:"dark",callback:function(a,b,c){m!=q&&(a=w.indexOf(a));this.value=a;e(this,a);r.dirty_canvas=!0;return!1}.bind(p)},h)}}else"mouseup"==c.type&&"number"==p.type&&(f=40>f?-1:f>t-40?1:0,200>c.click_time&&0==f&&this.prompt("Value",p.value,function(a){this.value=Number(a);e(this,this.value)}.bind(p),c));d!=p.value&&setTimeout(function(){e(this,this.value)}.bind(p),20);this.dirty_canvas=!0;break;case "toggle":"mousedown"==c.type&&(p.value=
!p.value,setTimeout(function(){e(p,p.value)},20));break;case "string":case "text":"mousedown"==c.type&&this.prompt("Value",p.value,function(a){this.value=a;e(this,a)}.bind(p),c,p.options?p.options.multiline:!1);break;default:p.mouse&&(this.dirty_canvas=p.mouse(c,[f,g],a))}if(d!=p.value){if(a.onWidgetChanged)a.onWidgetChanged(p.name,p.value,d,p);a.graph._version++}return p}}}return null};h.prototype.drawGroups=function(a,b){if(this.graph){a=this.graph._groups;b.save();b.globalAlpha=.5*this.editor_alpha;
@@ -345,7 +345,7 @@ break;case 13:k.buttons[q].pressed&&(t.hat+="down",t.hatmap|=m.DOWN);break;case
k.strokeRect(.5*(m[0]+1)*this.size[0]-4,.5*(m[1]+1)*this.size[1]-4,8,8);t=this.size[1]/this._current_buttons.length;k.fillStyle="#AEB";for(m=0;m<this._current_buttons.length;++m)this._current_buttons[m]&&k.fillRect(0,t*m,6,t)}};m.prototype.onGetOutputs=function(){return[["left_axis","vec2"],["right_axis","vec2"],["left_x_axis","number"],["left_y_axis","number"],["right_x_axis","number"],["right_y_axis","number"],["trigger_left","number"],["trigger_right","number"],["a_button","number"],["b_button",
"number"],["x_button","number"],["y_button","number"],["lb_button","number"],["rb_button","number"],["ls_button","number"],["rs_button","number"],["start_button","number"],["back_button","number"],["a_button_event",q.EVENT],["b_button_event",q.EVENT],["x_button_event",q.EVENT],["y_button_event",q.EVENT],["lb_button_event",q.EVENT],["rb_button_event",q.EVENT],["ls_button_event",q.EVENT],["rs_button_event",q.EVENT],["start_button_event",q.EVENT],["back_button_event",q.EVENT],["hat_left","number"],["hat_right",
"number"],["hat_up","number"],["hat_down","number"],["hat","number"],["button_pressed",q.EVENT]]};q.registerNodeType("input/gamepad",m)})(this);
(function(v){function m(){this.addInput("in","*");this.addOutput("out");this.size=[80,30]}function q(){this.addInput("in");this.addOutput("out");this.size=[80,30]}function k(){this.addInput("in");this.addOutput("out")}function t(){this.addInput("in","number",{locked:!0});this.addOutput("out","number",{locked:!0});this.addOutput("clamped","number",{locked:!0});this.addProperty("in",0);this.addProperty("in_min",0);this.addProperty("in_max",1);this.addProperty("out_min",0);this.addProperty("out_max",
(function(v){function m(){this.addInput("in","");this.addOutput("out");this.size=[80,30]}function q(){this.addInput("in");this.addOutput("out");this.size=[80,30]}function k(){this.addInput("in");this.addOutput("out")}function t(){this.addInput("in","number",{locked:!0});this.addOutput("out","number",{locked:!0});this.addOutput("clamped","number",{locked:!0});this.addProperty("in",0);this.addProperty("in_min",0);this.addProperty("in_max",1);this.addProperty("out_min",0);this.addProperty("out_max",
1);this.size=[120,50]}function w(){this.addOutput("value","number");this.addProperty("min",0);this.addProperty("max",1);this.size=[80,30]}function h(){this.addInput("in","number");this.addOutput("out","number");this.addProperty("min",0);this.addProperty("max",1);this.addProperty("smooth",!0);this.addProperty("seed",0);this.addProperty("octaves",1);this.addProperty("persistence",.8);this.addProperty("speed",1);this.size=[90,30]}function E(){this.addOutput("out","number");this.addProperty("min_time",
1);this.addProperty("max_time",2);this.addProperty("duration",.2);this.size=[90,30];this._blink_time=this._remaining_time=0}function C(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30];this.addProperty("min",0);this.addProperty("max",1)}function B(){this.properties={f:.5};this.addInput("A","number");this.addInput("B","number");this.addOutput("out","number")}function x(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30]}function I(){this.addInput("in",
"number");this.addOutput("out","number");this.size=[80,30]}function l(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30]}function L(){this.addInput("in","number");this.addOutput("out","number");this.size=[80,30];this.properties={A:0,B:1}}function G(){this.addInput("in","number",{label:""});this.addOutput("out","number",{label:""});this.size=[80,30];this.addProperty("factor",1)}function A(){this.addInput("v","boolean");this.addInput("A");this.addInput("B");this.addOutput("out")}