//****************************************************************
        // Event Handling - Methods for handling events
        //
        // The dispatch manager updates the focus nodes based on the
        // incoming events, and dispatches those events to the appropriate
        // focus nodes.
        //****************************************************************

        /// <summary>
        /// Create a new PInputEvent based on the next windows event and dispatch it to Piccolo.
        /// </summary>
        public virtual void ProcessInput()
        {
            if (nextInput == null)
            {
                return;
            }

            PInputEventArgs e = new PInputEventArgs(this, nextInput, nextType);

            //The EventArgs object for a Click event does not provide the position, so
            //we just ignore it here.
            //if (e.IsMouseEvent || e.IsDragDropEvent) {
            if (e.IsMouseEvent)
            {
                lastCanvasPosition = currentCanvasPosition;

                //if (e.IsMouseEvent) {
                currentCanvasPosition = new PointF(((MouseEventArgs)nextInput).X, ((MouseEventArgs)nextInput).Y);
                //} else {
                //	Point pt = new Point((int)((DragEventArgs)nextInput).X, (int)((DragEventArgs)nextInput).Y);
                //	currentCanvasPosition = nextWindowsSource.PointToClient(pt);
                //}

                //if (e.Type == PInputType.MouseMove || e.Type == PInputType.MouseDrag || e.Type == PInputType.DragOver){
                PPickPath pickPath = nextInputSource.Pick(currentCanvasPosition.X, currentCanvasPosition.Y, 1);
                MouseOver = pickPath;
                //}
            }

            nextInput       = null;
            nextInputSource = null;

            Dispatch(e);
        }
 /// <summary>
 /// Process the given windows event from the camera.
 /// </summary>
 /// <param name="e">The windows event to be processed.</param>
 /// <param name="type">The type of windows event being processed.</param>
 /// <param name="camera">The camera from which to process the windows event.</param>
 /// <param name="canvas">The source of the windows event being processed.</param>
 public virtual void ProcessEventFromCamera(EventArgs e, PInputType type, PCamera camera, PCanvas canvas)
 {
     nextInput         = e;
     nextType          = type;
     nextInputSource   = camera;
     nextWindowsSource = canvas;
     camera.Root.ProcessInputs();
 }
Пример #3
0
        /// <summary>
        /// Remove the camera at the given index from this layer's camera list.
        /// </summary>
        /// <param name="index">The index of the camera to remove.</param>
        /// <returns>The removed camera.</returns>
        public virtual PCamera RemoveCamera(int index)
        {
            PCamera camera = cameras[index];

            cameras.RemoveAt(index);
            InvalidatePaint();
            return(camera);
        }
Пример #4
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 ();
        }
Пример #5
0
        //****************************************************************
        // Event Handling - Methods for handling events
        //
        // The dispatch manager updates the focus nodes based on the
        // incoming events, and dispatches those events to the appropriate
        // focus nodes.
        //****************************************************************
        /// <summary>
        /// Create a new PInputEvent based on the next windows event and dispatch it to Piccolo.
        /// </summary>
        public virtual void ProcessInput()
        {
            if (nextInput == null) return;

            PInputEventArgs e = new PInputEventArgs(this, nextInput, nextType);

            //The EventArgs object for a Click event does not provide the position, so
            //we just ignore it here.
            //if (e.IsMouseEvent || e.IsDragDropEvent) {
            if (e.IsMouseEvent) {
                lastCanvasPosition = currentCanvasPosition;

                //if (e.IsMouseEvent) {
                    currentCanvasPosition = new PointF(((MouseEventArgs)nextInput).X, ((MouseEventArgs)nextInput).Y);
                //} else {
                //	Point pt = new Point((int)((DragEventArgs)nextInput).X, (int)((DragEventArgs)nextInput).Y);
                //	currentCanvasPosition = nextWindowsSource.PointToClient(pt);
                //}

                //if (e.Type == PInputType.MouseMove || e.Type == PInputType.MouseDrag || e.Type == PInputType.DragOver){
                    PPickPath pickPath = nextInputSource.Pick(currentCanvasPosition.X, currentCanvasPosition.Y, 1);
                    MouseOver = pickPath;
                //}
            }

            nextInput = null;
            nextInputSource = null;

            Dispatch(e);
        }
Пример #6
0
 /// <summary>
 /// Process the given windows event from the camera.
 /// </summary>
 /// <param name="e">The windows event to be processed.</param>
 /// <param name="type">The type of windows event being processed.</param>
 /// <param name="camera">The camera from which to process the windows event.</param>
 /// <param name="canvas">The source of the windows event being processed.</param>
 public virtual void ProcessEventFromCamera(EventArgs e, PInputType type, PCamera camera, PCanvas canvas)
 {
     nextInput = e;
     nextType = type;
     nextInputSource = camera;
     nextWindowsSource = canvas;
     camera.Root.ProcessInputs();
 }
Пример #7
0
 /// <summary>
 /// Remove the camera from this layer's camera list.
 /// </summary>
 /// <param name="camera">The camera to remove.</param>
 /// <returns>The removed camera.</returns>
 public virtual PCamera RemoveCamera(PCamera camera)
 {
     return(RemoveCamera(cameras.IndexOf(camera)));
 }
Пример #8
0
 /// <summary>
 /// Add a camera to this layer's camera list.
 /// </summary>
 /// <param name="camera">The new camera to add.</param>
 /// <remarks>
 /// This method it called automatically when a layer is added to a camera.
 /// </remarks>
 public virtual void AddCamera(PCamera camera)
 {
     AddCamera(CameraCount, camera);
 }
Пример #9
0
 /// <summary>
 /// Creates a pick path with the given Camera and pickbounds and adds this node.
 /// </summary>
 /// <param name="aCamera">The camera to use when creating the pick path.</param>
 /// <param name="pickBounds">The pick bounds to use when creating the pick path.</param>
 /// <returns>
 /// A pick path with the given camera and pickbounds that contains this node
 /// </returns>
 public virtual PPickPath ToPickPath(PCamera aCamera, RectangleF pickBounds)
 {
     PPickPath pickPath = new PPickPath(aCamera, pickBounds);
     pickPath.PushNode(this);
     return pickPath;
 }
Пример #10
0
 /// <summary>
 /// Remove the camera from this layer's camera list.
 /// </summary>
 /// <param name="camera">The camera to remove.</param>
 /// <returns>The removed camera.</returns>
 public virtual PCamera RemoveCamera(PCamera camera)
 {
     return RemoveCamera(cameras.IndexOf(camera));
 }
        /// <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 (!PUtil.RectangleContainsRectangle(rootBounds, 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);
            }
        }
        /// <summary>
        /// Animate the camera's view matrix from its current value when the activity
        /// starts to the new destination matrix value.
        /// </summary>
        /// <param name="aCamera">The camera whose view matrix will be animated.</param>
        /// <param name="aMatrix">The final matrix value.</param>
        /// <param name="duration">
        /// The amount of time that the animation should take.
        /// </param>
        /// <returns>
        /// The newly scheduled activity, if the duration is greater than 0; else null.
        /// </returns>
        protected virtual PActivity AnimateCameraViewMatrixTo(PCamera aCamera, PMatrix aMatrix, int duration)
        {
            bool wasOldAnimation = false;

            // first stop any old animations.
            if (navigationActivity != null) {
                navigationActivity.Terminate();
                wasOldAnimation = true;
            }

            if (duration == 0) {
                aCamera.ViewMatrix = aMatrix;
                return null;
            }

            PMatrix source = aCamera.ViewMatrixReference;

            //if (!source.MatrixReference.Equals(aMatrix.MatrixReference)) {
            if (!source.Equals(aMatrix)) {
                navigationActivity = aCamera.AnimateViewToMatrix(aMatrix, duration);
                ((PTransformActivity)navigationActivity).SlowInSlowOut = !wasOldAnimation;
                return navigationActivity;
            }

            return null;
        }
        /// <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);
        }
Пример #14
0
 public PCameraTransformTarget(PCamera target)
 {
     this.target = target;
 }
Пример #15
0
 /// <summary>
 /// Add a camera to this layer's camera list.
 /// </summary>
 /// <param name="camera">The new camera to add.</param>
 /// <remarks>
 /// This method it called automatically when a layer is added to a camera.
 /// </remarks>
 public virtual void AddCamera(PCamera camera)
 {
     AddCamera(CameraCount, camera);
 }
Пример #16
0
 /// <summary>
 /// Add a camera to this layer's camera list at the specified index.
 /// </summary>
 /// <param name="index">The index at which to add the new layer.</param>
 /// <param name="camera">The new camera to add.</param>
 /// <remarks>
 /// This method it called automatically when a layer is added to a camera.
 /// </remarks>
 public virtual void AddCamera(int index, PCamera camera)
 {
     cameras.Insert(index, camera);
     InvalidatePaint();
 }
Пример #17
0
 /// <summary>
 /// Determines whether the list contains a specific camera.
 /// </summary>
 /// <param name="camera">The camera to locate in the list.</param>
 /// <returns>
 /// True if the camera is found in the list; otherwise, false.
 /// </returns>
 public bool Contains(PCamera camera)
 {
     return List.Contains(camera);
 }
Пример #18
0
 /// <summary>
 /// Adds sticky bounds handles (with respect to the given camera) to the specified node.
 /// </summary>
 /// <param name="aNode">The node to add sticky bounds handles to.</param>
 /// <param name="camera">The camera to stick the bounds handles to.</param>
 /// <remarks>
 /// Sticky bounds handles are not affected by the view transform of the camera.  That
 /// is, they will remain a constant size as the view is zoomed in and out.
 /// </remarks>
 public static void AddStickyBoundsHandlesTo(PNode aNode, PCamera camera)
 {
     camera.AddChild(new PBoundsHandle(PBoundsLocator.CreateEastLocator(aNode)));
     camera.AddChild(new PBoundsHandle(PBoundsLocator.CreateWestLocator(aNode)));
     camera.AddChild(new PBoundsHandle(PBoundsLocator.CreateNorthLocator(aNode)));
     camera.AddChild(new PBoundsHandle(PBoundsLocator.CreateSouthLocator(aNode)));
     camera.AddChild(new PBoundsHandle(PBoundsLocator.CreateNorthEastLocator(aNode)));
     camera.AddChild(new PBoundsHandle(PBoundsLocator.CreateNorthWestLocator(aNode)));
     camera.AddChild(new PBoundsHandle(PBoundsLocator.CreateSouthEastLocator(aNode)));
     camera.AddChild(new PBoundsHandle(PBoundsLocator.CreateSouthWestLocator(aNode)));
 }
Пример #19
0
 /// <summary>
 /// Determines the index of a specific camera in the list.
 /// </summary>
 /// <param name="camera">The camera to locate in the list.</param>
 /// <returns>
 /// The index of the camera if found in the list; otherwise, -1.
 /// </returns>
 public int IndexOf(PCamera camera)
 {
     return List.IndexOf(camera);
 }
Пример #20
0
 public PCameraTransformTarget(PCamera target)
 {
     this.target = target;
 }
Пример #21
0
 /// <summary>
 /// Inserts a camera to the list at the specified position.
 /// </summary>
 /// <param name="index">
 /// The zero-based index at which the camera should be inserted.
 /// </param>
 /// <param name="camera">The camera to insert into the list.</param>
 public void Insert(int index, PCamera camera)
 {
     List.Insert(index, camera);
 }
Пример #22
0
 /// <summary>
 /// Add a camera to this layer's camera list at the specified index.
 /// </summary>
 /// <param name="index">The index at which to add the new layer.</param>
 /// <param name="camera">The new camera to add.</param>
 /// <remarks>
 /// This method it called automatically when a layer is added to a camera.
 /// </remarks>
 public virtual void AddCamera(int index, PCamera camera)
 {
     cameras.Insert(index, camera);
     InvalidatePaint();
 }
Пример #23
0
 /// <summary>
 /// Removes the first occurrence of a specific camera from the list.
 /// </summary>
 /// <param name="camera">The camera to remove from the list.</param>
 public void Remove(PCamera camera)
 {
     List.Remove(camera);
 }
Пример #24
0
 /// <summary>
 /// Adds a camera to the list.
 /// </summary>
 /// <param name="camera">The camera to add.</param>
 /// <returns>The position into which the new camera was inserted.</returns>
 public int Add(PCamera camera)
 {
     return List.Add(camera);
 }
Пример #25
0
        /// <summary>
        /// Creates a basic scene graph.
        /// </summary>
        /// <returns>The main camera node in the new scene graph.</returns>
        /// <remarks>
        /// The scene graph will consist of  root node with two children, a layer and a
        /// camera.  Additionally, The camera will be set to view the layer.  Typically,
        /// you will want to add new nodes to the layer.
        /// </remarks>
        public static PCamera CreateBasicScenegraph()
        {
            PRoot r = new PRoot();
            PLayer l = new PLayer();
            PCamera c = new PCamera();

            r.AddChild(c);
            r.AddChild(l);
            c.AddLayer(l);

            return c;
        }