示例#1
0
            /// <summary>
            /// Compares two nodes and returns a value indicating whether the first node's
            /// distance to the point is less than, equal to or greater than the second
            /// node's distance to the specified point.
            /// </summary>
            /// <param name="o1">The first node to compare.</param>
            /// <param name="o2">The second node to compare.</param>
            /// <returns>
            /// Less than 0, if o1's distance to the point is less than o2's distance to the
            /// point; 0 if o1's distance to the point equals 02's distance to the point;
            /// greater than 0 if o1's distance to the point is greater than o2's distance to
            /// the point.
            /// </returns>
            public int Compare(object o1, object o2)
            {
                PNode  each1       = (PNode)o1;
                PNode  each2       = (PNode)o2;
                PointF each1Center = PUtil.CenterOfRectangle(each1.GlobalFullBounds);
                PointF each2Center = PUtil.CenterOfRectangle(each2.GlobalFullBounds);

                if (!NODE_TO_GLOBAL_NODE_CENTER_MAPPING.Contains(each1))
                {
                    NODE_TO_GLOBAL_NODE_CENTER_MAPPING.Add(each1, each1Center);
                }
                if (!NODE_TO_GLOBAL_NODE_CENTER_MAPPING.Contains(each2))
                {
                    NODE_TO_GLOBAL_NODE_CENTER_MAPPING.Add(each2, each2Center);
                }

                float distance1 = PUtil.DistanceBetweenPoints(point, each1Center);
                float distance2 = PUtil.DistanceBetweenPoints(point, each2Center);

                if (distance1 < distance2)
                {
                    return(-1);
                }
                else if (distance1 == distance2)
                {
                    return(0);
                }
                else
                {
                    return(1);
                }
            }
 /// <summary>
 /// Returns true if a drag sequence should be initiated.
 /// </summary>
 /// <param name="e">A PInputEventArgs that contains the event data.</param>
 /// <returns>True if a drag sequence should be initiated; otherwise, false.</returns>
 protected virtual bool ShouldStartDragInteraction(PInputEventArgs e)
 {
     return(PUtil.DistanceBetweenPoints(MousePressedCanvasPoint, e.CanvasPosition)
            >= MinDragStartDistance);
 }