Exemple #1
0
        /// <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));
        }
Exemple #2
0
        public override void Initialize()
        {
            PCanvas c   = Canvas;
            PLayer  l   = c.Layer;
            PCamera cam = c.Camera;

            cam.ScaleViewBy(2.0f);
            PPath path = PPath.CreateRectangle(0, 0, 100, 100);

            l.AddChild(path);
            path.TranslateBy(100, 10);
            path.ScaleBy(0.2f);
            cam.AnimateViewToCenterBounds(path.GlobalFullBounds, true, 1000);
        }
Exemple #3
0
        /// <summary>
        /// Animates the camera's view to keep the control 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="aControlNode">The control node to animate to.</param>
        /// <param name="path">The pick path through which the control node was picked.</param>
        /// <param name="duration">The length of the animation.</param>
        /// <returns>
        /// The activity that animates the camera's view to the control node.
        /// </returns>
        public virtual PActivity DirectCameraViewToControl(PCamera aCamera, PControl aControlNode, PPickPath path, int duration)
        {
            Matrix originalViewMatrix = aCamera.ViewMatrix;

            // Scale the canvas to include
            SizeFx s = new SizeFx(1, 0);

            s = aControlNode.GlobalToLocal(s);

            float   scaleFactor = s.Width / aCamera.ViewScale;
            PointFx scalePoint  = PUtil.CenterOfRectangle(aControlNode.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(aControlNode.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);

            Matrix resultingMatrix = aCamera.ViewMatrix;

            aCamera.ViewMatrix = originalViewMatrix;

            PControl controlNode = (PControl)aControlNode;

            // Animate the canvas so that it ends up with the given
            // view transform.
            PActivity animateCameraViewActivity = AnimateCameraViewMatrixTo(aCamera, resultingMatrix, duration);

            aCamera.Root.WaitForActivities();

            Matrix  pathTransform = path.GetPathTransformTo(controlNode);
            PointFx point         = new PointFx(controlNode.X, controlNode.Y);
            PointFx pf            = MatrixExtensions.Transform(pathTransform, point);

            controlNode.ControlLocation = new System.Drawing.Point((int)pf.X, (int)pf.Y);
            controlNode.CurrentCanvas   = path.TopCamera.Canvas;
            controlNode.Editing         = true;

            return(animateCameraViewActivity);
        }
Exemple #4
0
        private void scaleView(float scaleDelta, PointF p)
        {
            float currentScale = camera.ViewScale;
            float newScale     = currentScale * scaleDelta;

            if (newScale < MIN_SCALE)
            {
                camera.ViewScale = MIN_SCALE;
                return;
            }
            if ((MAX_SCALE > 0) && (newScale > MAX_SCALE))
            {
                camera.ViewScale = MAX_SCALE;
                return;
            }
            camera.ScaleViewBy(scaleDelta, p.X, p.Y);
        }
 public void OnMouseWheel(object o, PInputEventArgs ea)
 {
     float currentScale = camera.ViewScale;
     float scaleDelta = (1.0f + (0.001f * ea.WheelDelta));
     float newScale = currentScale * scaleDelta;
     if (newScale < MIN_SCALE)
     {
         camera.ViewScale = MIN_SCALE;
         return;
     }
     if ((MAX_SCALE > 0) && (newScale > MAX_SCALE))
     {
         camera.ViewScale = MAX_SCALE;
         return;
     }
     PointF pos = ea.Position;
     camera.ScaleViewBy(scaleDelta, pos.X, pos.Y);
 }
Exemple #6
0
        public override void Initialize()
        {
            PLayer l = new PLayer();
            PPath  n = PPath.CreateEllipse(0, 0, 100, 80);

            n.Brush = Brushes.Red;
            n.Pen   = null;
            PBoundsHandle.AddBoundsHandlesTo(n);
            l.AddChild(n);
            n.TranslateBy(200, 200);

            PCamera c = new PCamera();

            c.SetBounds(0, 0, 100, 80);
            c.ScaleViewBy(0.1f);
            c.AddLayer(l);
            PBoundsHandle.AddBoundsHandlesTo(c);
            c.Brush = Brushes.Yellow;

            Canvas.Layer.AddChild(l);
            Canvas.Layer.AddChild(c);
        }
        /// <summary>
        /// Overridden.  See <see cref="PDragSequenceEventHandler.OnDragActivityStep">
        /// PDragSequenceEventHandler.OnDragActivityStep</see>.
        /// </summary>
        protected override void OnDragActivityStep(object sender, PInputEventArgs e)
        {
            base.OnDragActivityStep(sender, e);

            PCamera camera     = e.Camera;
            float   dx         = e.CanvasPosition.X - MousePressedCanvasPoint.X;
            float   scaleDelta = (1.0f + (0.001f * dx));

            float currentScale = camera.ViewScale;
            float newScale     = currentScale * scaleDelta;

            if (newScale < minScale)
            {
                scaleDelta = minScale / currentScale;
            }

            if ((maxScale > 0) && (newScale > maxScale))
            {
                scaleDelta = maxScale / currentScale;
            }

            camera.ScaleViewBy(scaleDelta, viewZoomPoint.X, viewZoomPoint.Y);
        }
Exemple #8
0
        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();
        }
Exemple #9
0
        public override void Initialize()
        {
            // Add a standard pnode to the scene graph.
            PNode aNode = new PNode();

            aNode.SetBounds(0, 70, 15, 15);
            aNode.Brush = Brushes.Blue;
            Canvas.Layer.AddChild(aNode);

            // Create a button.
            Button button = new Button();

            button.Text      = "Hello";
            button.Bounds    = new Rectangle(10, 10, 10, 10);
            button.BackColor = SystemColors.Control;

            // Wrap the button in a PControl and
            // add it to the scene graph.
            PControl cn = new PControl(button);

            Canvas.Layer.AddChild(cn);
            cn.SetBounds(20, 20, 70, 70);

            // Create another button.
            Button otherButton = new Button();

            otherButton.Text      = "123";
            otherButton.Bounds    = new Rectangle(0, 0, 15, 45);
            otherButton.BackColor = SystemColors.Control;

            // Wrap the second button in another PControl and
            // add it to the scene graph.
            PControl cn2 = new PControl(otherButton, PCanvas.CURRENT_PCANVAS);

            cn2.ScaleBy(1.1f);
            Canvas.Layer.AddChild(cn2);

            // Create a tabcontrol
            TabControl tabControl = new TabControl();

            tabControl.Size = new Size(60, 60);
            tabControl.TabPages.Add(new TabPage("P1"));
            tabControl.TabPages.Add(new TabPage("P2"));

            // Wrap the tabcontrol in a PControl and
            // add it the scene graph.
            PControl cn3 = new PControl(tabControl);

            cn3.ScaleBy(1.2f);
            cn3.TranslateBy(0, 100);
            Canvas.Layer.AddChild(cn3);

            // Create an internal camera that looks at the main layer.
            PCamera internalCamera = new PCamera();

            internalCamera.TranslateViewBy(145, 145);
            internalCamera.ScaleViewBy(.5f);
            internalCamera.SetBounds(130, 130, 200, 200);
            internalCamera.Brush = Brushes.Yellow;
            internalCamera.AddLayer(Canvas.Layer);
            Canvas.Camera.AddChild(internalCamera);

            Canvas.Layer.ScaleBy(1.3f);

            // Create another canvas.
            PCamera otherCamera = new PCamera();

            otherCamera.AddLayer(Canvas.Layer);
            Canvas.Root.AddChild(otherCamera);

            PCanvas other = new PCanvas();

            other.Camera = otherCamera;
            PForm result = new PForm(false, other);

            result.StartPosition = FormStartPosition.Manual;
            result.Location      = new Point(this.Location.X + this.Width, this.Location.Y);
            result.Size          = this.Size;
            result.Show();

            // Add the control event handler to both canvas' cameras.
            Canvas.Camera.AddInputEventListener(new PControlEventHandler());
            other.Camera.AddInputEventListener(new PControlEventHandler());
        }