Nez.UI.Element.parentToLocalCoordinates C# (CSharp) Method

parentToLocalCoordinates() public method

Converts the coordinates given in the parent's coordinate system to this element's coordinate system.
public parentToLocalCoordinates ( Vector2 parentCoords ) : Vector2
parentCoords Vector2 Parent coords.
return Vector2
		public Vector2 parentToLocalCoordinates( Vector2 parentCoords )
		{
			if( rotation == 0 )
			{
				if( scaleX == 1 && scaleY == 1 )
				{
					parentCoords.X -= x;
					parentCoords.Y -= y;
				}
				else
				{
					parentCoords.X = ( parentCoords.X - x - originX ) / scaleX + originX;
					parentCoords.Y = ( parentCoords.Y - y - originY ) / scaleY + originY;
				}
			}
			else
			{
				var cos = Mathf.cos( MathHelper.ToRadians( rotation ) );
				var sin = Mathf.sin( MathHelper.ToRadians( rotation ) );
				var tox = parentCoords.X - x - originX;
				var toy = parentCoords.Y - y - originY;
				parentCoords.X = ( tox * cos + toy * sin ) / scaleX + originX;
				parentCoords.Y = ( tox * -sin + toy * cos ) / scaleY + originY;
			}

			return parentCoords;
		}