예제 #1
0
        /// <summary>
        /// Removes any white space.  The canvas may be panned and zoomed in to do this.
        /// </summary>
        /// <param name="aCamera">The camera whose view will be adjusted.</param>
        protected virtual void FillViewWhiteSpace(PCamera aCamera)
        {
            RectangleF rootBounds = aCamera.Root.FullBounds;
            RectangleF viewBounds = aCamera.ViewBounds;

            if (!rootBounds.Contains(aCamera.ViewBounds))
            {
                aCamera.AnimateViewToPanToBounds(rootBounds, 0);
                aCamera.AnimateViewToPanToBounds(focusNode.GlobalFullBounds, 0);

                // center content.
                float dx = 0;
                float dy = 0;
                viewBounds = aCamera.ViewBounds;

                if (viewBounds.Width > rootBounds.Width)                     // then center along x axis.
                {
                    float rootBoundsMinX    = Math.Min(rootBounds.X, rootBounds.Right);
                    float viewBoundsMinX    = Math.Min(viewBounds.X, viewBounds.Right);
                    float boundsCenterX     = rootBoundsMinX + (rootBounds.Width / 2);
                    float viewBoundsCenterX = viewBoundsMinX + (viewBounds.Width / 2);
                    dx = viewBoundsCenterX - boundsCenterX;
                }

                if (viewBounds.Height > rootBounds.Height)                   // then center along y axis.
                {
                    float rootBoundsMinY    = Math.Min(rootBounds.Y, rootBounds.Right);
                    float viewBoundsMinY    = Math.Min(viewBounds.Y, viewBounds.Right);
                    float boundsCenterY     = rootBoundsMinY + (rootBounds.Height / 2);
                    float viewBoundsCenterY = viewBoundsMinY + (viewBounds.Height / 2);
                    dy = viewBoundsCenterY - boundsCenterY;
                }
                aCamera.TranslateViewBy(dx, dy);
            }
        }
예제 #2
0
        /// <summary>
        /// Pans the camera as the mouse is dragged.
        /// </summary>
        /// <param name="e">A PInputEventArgs that contains the event data.</param>
        protected virtual void Pan(PInputEventArgs e)
        {
            PCamera c = e.Camera;
            Vector2 l = new Vector2(e.Position.X, e.Position.Y);

            if (c.ViewBounds.Contains(l))
            {
                SizeFx s = e.Delta;
                c.TranslateViewBy(s.Width, s.Height);
            }
        }
        /// <summary>
        /// Pans the camera as the mouse is dragged.
        /// </summary>
        /// <param name="e">A PInputEventArgs that contains the event data.</param>
        protected virtual void Pan(PInputEventArgs e)
        {
            PCamera c = e.Camera;
            PointF  l = e.Position;

            if (c.ViewBounds.Contains(l))
            {
                SizeF s = e.Delta;
                c.TranslateViewBy(s.Width, s.Height);
            }
        }
예제 #4
0
        /// <summary>
        /// Overridden.  Do auto-panning even when the mouse is not moving.
        /// </summary>
        /// <param name="sender">The source of the drag event.</param>
        /// <param name="e">A PInputEventArgs that contains the event data.</param>
        protected override void OnDragActivityStep(object sender, PInputEventArgs e)
        {
            base.OnDragActivityStep(sender, e);

            if (!autopan)
            {
                return;
            }

            PCamera     c = e.Camera;
            RectangleFx b = c.Bounds;
            PointFx     l = e.GetPositionRelativeTo(c);

            PUtil.OutCode outcode = PUtil.RectangleOutCode(l, b);
            SizeFx        delta   = SizeFx.Empty;

            if ((outcode & PUtil.OutCode.Top) != 0)
            {
                delta.Height = ValidatePanningDelta(-1.0f - (0.5f * Math.Abs(l.Y - b.Y)));
            }
            else if ((outcode & PUtil.OutCode.Bottom) != 0)
            {
                delta.Height = ValidatePanningDelta(1.0f + (0.5f * Math.Abs(l.Y - (b.Y + b.Height))));
            }

            if ((outcode & PUtil.OutCode.Right) != 0)
            {
                delta.Width = ValidatePanningDelta(1.0f + (0.5f * Math.Abs(l.X - (b.X + b.Width))));
            }
            else if ((outcode & PUtil.OutCode.Left) != 0)
            {
                delta.Width = ValidatePanningDelta(-1.0f - (0.5f * Math.Abs(l.X - b.X)));
            }

            delta = c.LocalToView(delta);

            if (delta.Width != 0 || delta.Height != 0)
            {
                c.TranslateViewBy(delta.Width, delta.Height);
            }
        }
예제 #5
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());
        }