Commit 2201f165 authored by Neil Fraser's avatar Neil Fraser

Angle field tweaks.

parent bafb3016
......@@ -1165,8 +1165,8 @@ Blockly.FieldAngle.prototype.setChangeHandler=function(a){Blockly.FieldAngle.sup
Blockly.FieldAngle.prototype.dispose_=function(){var a=this;return function(){Blockly.FieldAngle.superClass_.dispose_.call(a)();a.gauge_=null;a.clickWrapper_&&Blockly.unbindEvent_(a.clickWrapper_);a.moveWrapper1_&&Blockly.unbindEvent_(a.moveWrapper1_);a.moveWrapper2_&&Blockly.unbindEvent_(a.moveWrapper2_)}};
Blockly.FieldAngle.prototype.showEditor_=function(){Blockly.FieldAngle.superClass_.showEditor_.call(this,goog.userAgent.MOBILE||goog.userAgent.ANDROID||goog.userAgent.IPAD);var a=Blockly.WidgetDiv.DIV;if(a.firstChild){var a=Blockly.createSvgElement("svg",{xmlns:"http://www.w3.org/2000/svg","xmlns:html":"http://www.w3.org/1999/xhtml","xmlns:xlink":"http://www.w3.org/1999/xlink",version:"1.1",height:2*Blockly.FieldAngle.HALF+"px",width:2*Blockly.FieldAngle.HALF+"px"},a),b=Blockly.createSvgElement("circle",
{cx:Blockly.FieldAngle.HALF,cy:Blockly.FieldAngle.HALF,r:Blockly.FieldAngle.RADIUS,"class":"blocklyAngleCircle"},a);this.gauge_=Blockly.createSvgElement("path",{"class":"blocklyAngleGauge"},a);this.line_=Blockly.createSvgElement("line",{x1:Blockly.FieldAngle.HALF,y1:Blockly.FieldAngle.HALF,"class":"blocklyAngleLine"},a);for(var c=0;360>c;c+=15)Blockly.createSvgElement("line",{x1:Blockly.FieldAngle.HALF+Blockly.FieldAngle.RADIUS,y1:Blockly.FieldAngle.HALF,x2:Blockly.FieldAngle.HALF+Blockly.FieldAngle.RADIUS-
(0==c%45?10:5),y2:Blockly.FieldAngle.HALF,"class":"blocklyAngleMarks",transform:"rotate("+c+", "+Blockly.FieldAngle.HALF+", "+Blockly.FieldAngle.HALF+")"},a);a.style.marginLeft="-35px";this.clickWrapper_=Blockly.bindEvent_(a,"click",this,Blockly.WidgetDiv.hide);this.moveWrapper1_=Blockly.bindEvent_(b,"mousemove",this,this.onMouseMove);this.moveWrapper2_=Blockly.bindEvent_(this.gauge_,"mousemove",this,this.onMouseMove);this.updateGraph_()}};
Blockly.FieldAngle.prototype.onMouseMove=function(a){var b=this.gauge_.ownerSVGElement.getBoundingClientRect(),c=a.clientX-b.left-Blockly.FieldAngle.HALF;a=a.clientY-b.top-Blockly.FieldAngle.HALF;b=Math.atan(-a/c);isNaN(b)||(b=goog.math.toDegrees(b),0>c?b+=180:0<a&&(b+=360),Blockly.FieldAngle.ROUND&&(b=Math.round(b/Blockly.FieldAngle.ROUND)*Blockly.FieldAngle.ROUND),360<=b&&(b-=360),b=String(b),Blockly.FieldTextInput.htmlInput_.value=b,this.setText(b))};
(0==c%45?10:5),y2:Blockly.FieldAngle.HALF,"class":"blocklyAngleMarks",transform:"rotate("+c+", "+Blockly.FieldAngle.HALF+", "+Blockly.FieldAngle.HALF+")"},a);a.style.marginLeft=15-Blockly.FieldAngle.RADIUS+"px";this.clickWrapper_=Blockly.bindEvent_(a,"click",this,Blockly.WidgetDiv.hide);this.moveWrapper1_=Blockly.bindEvent_(b,"mousemove",this,this.onMouseMove);this.moveWrapper2_=Blockly.bindEvent_(this.gauge_,"mousemove",this,this.onMouseMove);this.updateGraph_()}};
Blockly.FieldAngle.prototype.onMouseMove=function(a){var b=this.gauge_.ownerSVGElement.getBoundingClientRect(),c=a.clientX-b.left-Blockly.FieldAngle.HALF;a=a.clientY-b.top-Blockly.FieldAngle.HALF;b=Math.atan(-a/c);isNaN(b)||(b=goog.math.toDegrees(b),0>c?b+=180:0<a&&(b+=360),Blockly.FieldAngle.ROUND&&(b=Math.round(b/Blockly.FieldAngle.ROUND)*Blockly.FieldAngle.ROUND),360<=b&&(b-=360),b=String(b),Blockly.FieldTextInput.htmlInput_.value=b,this.setText(b),this.validate_())};
Blockly.FieldAngle.prototype.setText=function(a){Blockly.FieldAngle.superClass_.setText.call(this,a);this.textElement_&&(this.updateGraph_(),this.sourceBlock_.RTL?this.textElement_.insertBefore(this.symbol_,this.textElement_.firstChild):this.textElement_.appendChild(this.symbol_),this.size_.width=0)};
Blockly.FieldAngle.prototype.updateGraph_=function(){if(this.gauge_){var a=goog.math.toRadians(Number(this.getText()));if(isNaN(a))this.gauge_.setAttribute("d","M "+Blockly.FieldAngle.HALF+", "+Blockly.FieldAngle.HALF),this.line_.setAttribute("x2",Blockly.FieldAngle.HALF),this.line_.setAttribute("y2",Blockly.FieldAngle.HALF);else{var b=Blockly.FieldAngle.HALF+Math.cos(a)*Blockly.FieldAngle.RADIUS,c=Blockly.FieldAngle.HALF+Math.sin(a)*-Blockly.FieldAngle.RADIUS;this.gauge_.setAttribute("d","M "+Blockly.FieldAngle.HALF+
", "+Blockly.FieldAngle.HALF+" h "+Blockly.FieldAngle.RADIUS+" A "+Blockly.FieldAngle.RADIUS+","+Blockly.FieldAngle.RADIUS+" 0 "+(a>Math.PI?1:0)+" 0 "+b+","+c+" z");this.line_.setAttribute("x2",b);this.line_.setAttribute("y2",c)}}};Blockly.FieldAngle.angleValidator=function(a){a=Blockly.FieldTextInput.numberValidator(a);null!==a&&(a%=360,0>a&&(a+=360),a=String(a));return a};
......
......@@ -166,7 +166,7 @@ Blockly.FieldAngle.prototype.showEditor_ = function() {
Blockly.FieldAngle.HALF + ', ' + Blockly.FieldAngle.HALF + ')'
}, svg);
}
svg.style.marginLeft = '-35px';
svg.style.marginLeft = (15 - Blockly.FieldAngle.RADIUS) + 'px';
this.clickWrapper_ =
Blockly.bindEvent_(svg, 'click', this, Blockly.WidgetDiv.hide);
this.moveWrapper1_ =
......@@ -207,6 +207,7 @@ Blockly.FieldAngle.prototype.onMouseMove = function(e) {
angle = String(angle);
Blockly.FieldTextInput.htmlInput_.value = angle;
this.setText(angle);
this.validate_();
};
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment