Ejemplo n.º 1
0
        /// <summary>
        /// A handler for mouse down events
        /// </summary>
        /// <param name="sender">the object that generated the event</param>
        /// <param name="e">the mouse event data</param>
        public override void MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Left) return;

            foreach (var f in _canvas.SelectedFigures)
            {
                foreach (var h in f.Handles)
                {
                    if (h.Touches(e.X, e.Y))
                        _selectedHandle = h;
                }
            }
            if (_selectedHandle != null) // mouse was pressed over a handle
            {
                _selectedHandle.Selected = true;
            }
            else
            {
                _canvas.ClearSelected();
                _selectedFigure = _canvas.FindFigureAtPoint(e.Location);
                if (_selectedFigure != null) // mouse was pressed over a figure
                {
                    _selectedFigure.Selected = true;
                    _canvas.TopFigure = _selectedFigure;
                    _figureLocator = _selectedFigure.RelativeLocator(e.Location);
                }
                else // just on the canvas, so make a selection rectangle
                {
                    _startPoint = e.Location;
                    _selectionBox = new Rectangle(e.Location, Size.Empty);
                    _canvas.SelectionRectangle = _selectionBox;
                    _canvas.Repaint(Rectangle.Inflate(_selectionBox, 1, 1));
                }
            }
        }