GetPositionRelativeTo() public method

Return the mouse position relative to a given node on the pick path.
public GetPositionRelativeTo ( PNode nodeOnPath ) : PointF
nodeOnPath PNode /// The returned position will be in the local coordinate system of this node. ///
return System.Drawing.PointF
        /// <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;
            RectangleF b = c.Bounds;
            PointF     l = e.GetPositionRelativeTo(c);

            PUtil.OutCode outcode = PUtil.RectangleOutCode(l, b);
            SizeF         delta   = SizeF.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);
            }
        }
Beispiel #2
0
			/// <summary>
			/// Overridden.  See <see cref="PDragSequenceEventHandler.OnEndDrag">
			/// PDragSequenceEventHandler.OnEndDrag</see>.
			/// </summary>
			protected override void OnEndDrag(object sender, PInputEventArgs e) {
				base.OnEndDrag (sender, e);
				handle.OnEndHandleDrag(sender, e.GetPositionRelativeTo(handle), e);
			}
			protected override void OnDrag(object sender, PInputEventArgs e) {
				base.OnDrag (sender, e);

				PointF start = canvas.Camera.LocalToView((PointF)MousePressedCanvasPoint);
				PointF current = e.GetPositionRelativeTo(canvas.Layer);
				PointF dest = PointF.Empty;

				dest.X = nodeStartPosition.X + (current.X - start.X);
				dest.Y = nodeStartPosition.Y + (current.Y - start.Y);

				dest.X = dest.X - (dest.X % gridSpacing);
				dest.Y = dest.Y - (dest.Y % gridSpacing);

				draggedNode.SetOffset(dest.X, dest.Y);
			}
		/// <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;
			RectangleF b = c.Bounds;
			PointF l = e.GetPositionRelativeTo(c);
			PUtil.OutCode outcode = PUtil.RectangleOutCode(l, b);
			SizeF delta = SizeF.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);
			}
		}