UMD.HCIL.Piccolo.PNode.Position C# (CSharp) Method

Position() public method

Animate this node's matrix to one that will make this node appear at the specified position relative to the specified bounding box.
The source point specifies a point in the unit square (0, 0) - (1, 1) that represents an anchor point on the corresponding node to this matrox. The destination point specifies an anchor point on the reference node. The position method then computes the matrix that results in transforming this node so that the source anchor point coincides with the reference anchor point. This can be useful for layout algorithms as it is straightforward to position one object relative to another.

For example, If you have two nodes, A and B, and you call PointF srcPt = new PointF(1.0f, 0.0f); PointF destPt = new PointF(0.0f, 0.0f); A.Position(srcPt, destPt, B.GlobalBounds, 750); The result is that A will move so that its upper-right corner is at the same place as the upper-left corner of B, and the transition will be smoothly animated over a period of 750 milliseconds.

public Position ( PointF srcPt, PointF destPt, RectangleF destBounds, int millis ) : void
srcPt System.Drawing.PointF
destPt System.Drawing.PointF
destBounds System.Drawing.RectangleF
millis int
return void
		public virtual void Position(PointF srcPt, PointF destPt, RectangleF destBounds, int millis) {
			float srcx, srcy;
			float destx, desty;
			float dx, dy;
			PointF pt1, pt2;

			if (parent != null) {
				// First compute translation amount in global coordinates
				RectangleF srcBounds = GlobalFullBounds;
				srcx  = Lerp(srcPt.X,  srcBounds.X,  srcBounds.X +  srcBounds.Width);
				srcy  = Lerp(srcPt.Y,  srcBounds.Y,  srcBounds.Y +  srcBounds.Height);
				destx = Lerp(destPt.X, destBounds.X, destBounds.X + destBounds.Width);
				desty = Lerp(destPt.Y, destBounds.Y, destBounds.Y + destBounds.Height);

				// Convert vector to local coordinates
				pt1 = new PointF(srcx, srcy);
				pt1 = GlobalToLocal(pt1);
				pt2 = new PointF(destx, desty);
				pt2 = GlobalToLocal(pt2);
				dx = (pt2.X - pt1.X);
				dy = (pt2.Y - pt1.Y);

				// Finally, animate change
				PMatrix matrix = new PMatrix(MatrixReference.MatrixReference);
				matrix.TranslateBy(dx, dy);
				AnimateToMatrix(matrix, millis);
			}
		}