DistanceF() public static method

public static DistanceF ( PointF pt1, PointF pt2 ) : float
pt1 System.Drawing.PointF
pt2 System.Drawing.PointF
return float
Exemplo n.º 1
0
 float GetMinResolution(Graphics g)
 {
     // Determine pixel size in world coordinates.
     PointF[] pts = { new PointF(0, 0), new PointF(1, 0) };
     g.TransformPoints(CoordinateSpace.World, CoordinateSpace.Device, pts);
     return(Util.DistanceF(pts[0], pts[1]));
 }
Exemplo n.º 2
0
        // Hit test against highlighted handles, return the location of the best one, or (Nan, Nan) if none.
        public PointF HitTestHandles(PointF locationTest, bool testBeziers)
        {
            return(new PointF(float.NaN, float.NaN));

#if false
            float  bestDistance = float.MaxValue;
            PointF bestPoint    = new PointF(float.NaN, float.NaN);

            if (currentHighlights == null)
            {
                return(bestPoint);
            }

            RectangleF hitBounds;

            // Compute the hit bounds rectangle. A point must be within this rectangle
            // to be considered. This is equivalent to making sure the actual handle square is clicked on
            Point     locationPixel = Util.PointFromPointF(WorldToPixel(locationTest));
            Rectangle rectPixel     = new Rectangle(locationPixel.X - HandleRadius, locationPixel.Y - HandleRadius, HandleDiameter, HandleDiameter);
            hitBounds = PixelToWorld(rectPixel);

            // Determine the closest point of those handles that were clicked on.
            for (int i = 0; i < currentHighlights.handles.Length; ++i)
            {
                PointF pt = currentHighlight.handles[i];

                // Don't check bezier handles unless requested to.
                if (!testBeziers && currentHighlight.handleKinds[i] == PointKind.BezierControl)
                {
                    continue;
                }

                if (hitBounds.Contains(pt))
                {
                    float distance = Util.DistanceF(pt, locationTest);
                    if (distance < bestDistance)
                    {
                        bestDistance = distance;
                        bestPoint    = pt;
                    }
                }
            }

            return(bestPoint);
#endif
        }
Exemplo n.º 3
0
        void PointerMoved(bool mouseInViewport, int xViewport, int yViewport)
        {
            this.mouseInView = mouseInViewport;

            if (mouseInView)
            {
                mouseLocation = PixelToWorld(new PointF(xViewport, yViewport));

                if (OnMouseEvent != null)
                {
                    OnMouseEvent(this, MouseAction.Move, -1, mouseDown, mouseLocation, mouseLocation);
                }

                ResetHoverTimer(mouseLocation);

                // See if dragging is occurring/starting for any button
                for (int buttonNumber = 0; buttonNumber < CountMouseButtons; ++buttonNumber)
                {
                    // is a drag being started?
                    if (mouseDown[buttonNumber] && !mouseDrag[buttonNumber] && canDrag[buttonNumber] &&
                        WorldToPixelDistance(Util.DistanceF(mouseLocation, downPos[buttonNumber])) >= MinDragDistance)
                    {
                        mouseDrag[buttonNumber] = true;
                        DisableHoverTimer();
                    }

                    // is a drag in progress?
                    if (OnMouseEvent != null && mouseDown[buttonNumber] && mouseDrag[buttonNumber])
                    {
                        OnMouseEvent(this, MouseAction.Drag, buttonNumber, mouseDown, mouseLocation, downPos[buttonNumber]);
                        DisableHoverTimer();
                    }
                }
            }
            else
            {
                mouseLocation = new PointF();
                DisableHoverTimer();
            }

            if (OnPointerMove != null)
            {
                OnPointerMove(this, mouseInView, mouseLocation);
            }
        }
Exemplo n.º 4
0
        void MouseButtonUp(int buttonNumber, int xViewport, int yViewport)
        {
            PointF worldMouse = PixelToWorld(new PointF(xViewport, yViewport));
            bool   wasDown    = mouseDown[buttonNumber];
            bool   wasDrag    = mouseDrag[buttonNumber];
            bool   wasClick   = false;

            if (wasDown && !wasDrag &&
                WorldToPixelDistance(Util.DistanceF(worldMouse, downPos[buttonNumber])) <= MaxClickDistance &&
                Environment.TickCount - downTime[buttonNumber] <= MaxClickTime)
            {
                wasClick = true;
            }


            mouseDown[buttonNumber] = false;
            mouseDrag[buttonNumber] = false;

            if (OnMouseEvent != null)
            {
                if (wasDrag)
                {
                    OnMouseEvent(this, MouseAction.DragEnd, buttonNumber, mouseDown, worldMouse, downPos[buttonNumber]);
                }
                else if (wasClick)
                {
                    OnMouseEvent(this, MouseAction.Click, buttonNumber, mouseDown, downPos[buttonNumber], downPos[buttonNumber]);
                }
                else if (wasDown)
                {
                    OnMouseEvent(this, MouseAction.Up, buttonNumber, mouseDown, worldMouse, downPos[buttonNumber]);
                }
            }

            return;
        }