Exemple #1
0
 protected override void OnMouseDown(MouseEventArgs e)
 {
     base.OnMouseDown(e);
     clicked  = true;
     dragging = false;  // Do not allow direct dragging. Instead, allow dragging only in the sliders.
     if (e.Button == MouseButtons.Left)
     {
         // 20160701
         if (moveActive)
         {
             movePoint = new PointF(e.X, e.Y);
             selectedPointInformation = new List <Tuple <int, int> >();
             OnAllPointsDeSelected();
             Refresh();
         }
         else
         {
             if (CheckSelectedPointClicked(e.X, e.Y))
             {
                 selectionClicked = true;
                 if (dragSplineIndex >= 0)  // If not, the user has not clicked on a SELECTED (red) point.
                 {
                     dragPoint = new Point(e.X, e.Y);
                 }
             }
             else
             {
                 selectionClicked = false;
                 selecting        = true;
                 selectionCorner1 = new PointF(e.X, e.Y);
                 selectionCorner2 = new PointF(e.X, e.Y);
                 // Make sure that selections are only allowed on ONE side of the symmetry axis:
                 if (selectionSide == SelectionSide.None)
                 {
                     float symmetryAxisPlotX = GetPlotXAtX(bezierCurve.SplineList[0].ControlPointList[0].CoordinateList[0]);
                     if (selectionCorner1.X <= symmetryAxisPlotX)
                     {
                         selectionSide = SelectionSide.Left;
                     }
                     else
                     {
                         selectionSide = SelectionSide.Right;
                     }
                 }
                 else
                 {
                     SelectionSide attemptedSelectionSide = SelectionSide.None;
                     float         symmetryAxisPlotX      = GetPlotXAtX(bezierCurve.SplineList[0].ControlPointList[0].CoordinateList[0]);
                     if (selectionCorner1.X <= symmetryAxisPlotX)
                     {
                         attemptedSelectionSide = SelectionSide.Left;
                     }
                     else
                     {
                         attemptedSelectionSide = SelectionSide.Right;
                     }
                     if (attemptedSelectionSide != selectionSide)
                     {
                         selecting = false;
                     }
                 }
             }
         }
     }
     else
     {
         if (CheckDeSelection(e.X, e.Y))
         {
             Refresh();
         }
         else
         {
             selectionClicked         = false;
             selectedPointInformation = new List <Tuple <int, int> >();
             selectionSide            = SelectionSide.None;
             OnAllPointsDeSelected();
             Refresh();
         }
     }
 }
Exemple #2
0
        private Boolean CheckDeSelection(float pixelX, float pixelY)
        {
            Boolean selectionChanged = false;

            if (bezierCurve == null)
            {
                return(selectionChanged);
            }
            int    splineIndex        = -1;
            int    controlPointIndex  = -1;
            int    splineIndex2       = -1;
            int    controlPointIndex2 = -1;
            double minimumDistance    = double.MaxValue;

            for (int ii = 0; ii < bezierCurve.SplineList.Count; ii++)
            {
                for (int jj = 0; jj < bezierCurve.SplineList[ii].ControlPointList.Count; jj++)
                {
                    float  plotX           = GetPlotXAtX(bezierCurve.SplineList[ii].ControlPointList[jj].CoordinateList[0]);
                    double plotY           = GetPlotYAtY(bezierCurve.SplineList[ii].ControlPointList[jj].CoordinateList[1]);
                    double distanceSquared = (pixelX - plotX) * (pixelX - plotX) + (pixelY - plotY) * (pixelY - plotY);
                    if (distanceSquared < minimumDistance)
                    {
                        minimumDistance   = distanceSquared;
                        splineIndex       = ii;
                        controlPointIndex = jj;
                    }
                }
            }
            if (minimumDistance < clickTolerance)
            {
                // Find the underlying point from the connected spline, if any
                selectionChanged = true;
                if (controlPointIndex == 0)
                {
                    splineIndex2 = splineIndex - 1;
                    if (splineIndex2 < 0)
                    {
                        splineIndex2 = bezierCurve.SplineList.Count - 1;
                    }
                    controlPointIndex2 = 3;
                }
                else if (controlPointIndex == 3)
                {
                    splineIndex2       = (splineIndex + 1) % bezierCurve.SplineList.Count;
                    controlPointIndex2 = 0;
                }
                int selectionIndex = selectedPointInformation.FindIndex(t => (t.Item1 == splineIndex) && (t.Item2 == controlPointIndex));
                if (selectionIndex >= 0) // select the point and any underlying points (from the next or previous spline)
                {
                    selectionClicked = false;
                    selectedPointInformation.RemoveAt(selectionIndex);
                    if (splineIndex2 >= 0)
                    {
                        int selectionIndex2 = selectedPointInformation.FindIndex(t => (t.Item1 == splineIndex2) && (t.Item2 == controlPointIndex2));
                        selectedPointInformation.RemoveAt(selectionIndex2);
                    }
                }
            }
            if (selectedPointInformation.Count == 0)
            {
                OnAllPointsDeSelected();
                selectionSide = SelectionSide.None;
            }
            return(selectionChanged);
        }