Improvement for Dragger RaiseSelectionChanged

Nov 20, 2010 at 9:41 PM

Hi Kirill,

I noticed a small issue when trying to detect if an object is selected.  I narrowed it down to whether or not the coordinatesOnMouseDown were equal to the Coordinates of the MouseUp event.  I found that by reducing the accuracy it was more reliable since a user could easily move the cursor just a tiny bit.  By introducing the following code I found the "SelectionChange" event became more reliable.  Does this sound reasonable to introduce to LG?

        public override void MouseUp(object sender, MouseButtonEventArgs e)
        {
            //CR decreased accuracy of points being equal ... accounts for slight movement of cursor from down to up
            //if (Coordinates(e) == coordinatesOnMouseDown)
            if (PointsApproxEqual(Coordinates(e), coordinatesOnMouseDown))
            {
                UpdateSelection();
                Drawing.RaiseSelectionChanged(Drawing.GetSelectedFigures());
            }

            startedMoving = false;
            moving = null;
            found = null;
        }

        private bool PointsApproxEqual(Point pointUp, Point pointDown)
        {
            return Math.Round(pointUp.X, 1) == Math.Round(pointDown.X, 1) && Math.Round(pointUp.Y, 1) == Math.Round(pointDown.Y, 1);
        }

Best regards,

Chris