import mx.core.UIComponent;
class RimPoint extends UIComponent {
	var angle:Number;
	function RimPoint(){
		onReleaseOutside = onRelease;
		_x = _parent.prot.radius;
		angle = Math.atan2(_y,_x);
		//trace(angle);
		doLater(this, "moveText");
	}
	function onPress() {
		//this.startDrag();
		onMouseMove = movePointToRimAtMouse;
	}
	function onRelease() {
		//this.stopDrag();
		onMouseMove = null;
		_parent._parent.my_status.text = "";
	}

	function onRollOver() {
		_parent._parent.my_status.text = "rotate rim point";
	}
	
	function draw():Void {
		movePointToRim(_x,_y);
		moveText();
	}
	
	function movePointToRimAtMouse() {
		var xm:Number = _parent._xmouse;
		var ym:Number = _parent._ymouse;
		movePointToRim(xm, ym);
	}
	
	function movePointToRim(xm:Number, ym:Number) {
		var d:Number = Math.sqrt(xm*xm+ym*ym);
		var scale:Number = _parent.prot.radius/d;
		_x = xm*scale;
		_y = ym*scale;
		
		// Keep angle in range 0..-2 pi. 
		// Since y axis points down it will appear to be in range 0.. 2pi on screen
		angle = Math.atan2(_y,_x);
		if(angle > 0) angle -= 2*Math.PI;
		
		_parent.t.draw();
		moveText();
		updateAfterEvent();
	}
	
	function moveText() {
		//trace(angle);
		_root.hyp.text = "1";
		_root.adj.text = ProtractorContainer.toDP(Math.cos(angle),2);
		_root.opp.text = ProtractorContainer.toDP(-Math.sin(angle),2);
		_root.angle.text = ProtractorContainer.toDP(-angle*180/Math.PI,0);

		var point:Object = {x:_x, y:_y/2};
		_parent.localToGlobal(point);
		_root.opp._x = point.x;
		_root.opp._y = point.y;

		point = {x:_x/2, y:0};
		_parent.localToGlobal(point);
		_root.adj._x = point.x;
		_root.adj._y = point.y;

		point = {x:_x/2, y:_y/2};
		_parent.localToGlobal(point);
		_root.hyp._x = point.x;
		_root.hyp._y = point.y;

		point = {x:20*Math.cos(angle/2), y:20*Math.sin(angle/2)-11};
		_parent.localToGlobal(point);
		_root.angle._x = point.x;
		_root.angle._y = point.y;
	}
}
