public override void Initialize() { PLayer l = new PLayer(); PEllipse n = new PEllipse(); n.SetBounds(0, 0, 100, 80); n.Brush = new SolidBrush(Color.Red); PBoundsHandle.AddBoundsHandlesTo(n); l.AddChild(n); n.TranslateBy(100, 100); PCamera c = new PCamera(); c.SetBounds(0, 0, 100, 80); c.ScaleViewBy(0.1f); c.AddLayer(l); PBoundsHandle.AddBoundsHandlesTo(c); c.Brush = new SolidBrush(Color.Yellow); Canvas.Layer.AddChild(l); Canvas.Layer.AddChild(c); base.Initialize (); }
/// <summary> /// Animates the camera's view to keep the focus node on the screen and at 100 /// percent scale with minimal view movement. /// </summary> /// <param name="aCamera">The camera whose view will be animated.</param> /// <param name="aFocusNode">The focus node to animate to.</param> /// <param name="duration">The length of the animation.</param> /// <returns> /// The activity that animates the camera's view to the focus node. /// </returns> public virtual PActivity DirectCameraViewToFocus(PCamera aCamera, PNode aFocusNode, int duration) { PMatrix originalViewMatrix = aCamera.ViewMatrix; // Scale the canvas to include SizeF s = new SizeF(1, 0); s = focusNode.GlobalToLocal(s); float scaleFactor = s.Width / aCamera.ViewScale; PointF scalePoint = PUtil.CenterOfRectangle(focusNode.GlobalFullBounds); if (scaleFactor != 1) { aCamera.ScaleViewBy(scaleFactor, scalePoint.X, scalePoint.Y); } // Pan the canvas to include the view bounds with minimal canvas // movement. aCamera.AnimateViewToPanToBounds(focusNode.GlobalFullBounds, 0); // Get rid of any white space. The canvas may be panned and // zoomed in to do this. But make sure not stay constrained by max // magnification. //FillViewWhiteSpace(aCamera); PMatrix resultingMatrix = aCamera.ViewMatrix; aCamera.ViewMatrix = originalViewMatrix; // Animate the canvas so that it ends up with the given // view transform. return AnimateCameraViewMatrixTo(aCamera, resultingMatrix, duration); }