Exemplo n.º 1
0
        public override void AfterPaint(Graphics g)
        {
            g.TranslateTransform(_grac.Doc.PrintableBounds.X, _grac.Doc.PrintableBounds.Y);
            // finally, mark the selected objects

            if (SingleSelectedObject is IGrippableObject)
            {
                IGrippableObject gripObject = (IGrippableObject)SingleSelectedObject;
                if (null != gripObject)
                {
                    // first switch to the layer graphics context (from printable context)


                    SingleSelectedHitTestObject.ParentLayer.GraphToLayerCoordinates(g);

                    gripObject.ShowGrips(g);
                }
            }
            else if (m_SelectedObjects.Count > 0)
            {
                foreach (IHitTestObject graphObject in m_SelectedObjects)
                {
                    g.DrawPath(Pens.Blue, graphObject.SelectionPath);
                }
            }


            base.AfterPaint(g);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handles the MouseDown event when the object pointer tool is selected
        /// </summary>
        /// <param name="e">The mouse event args</param>
        /// <remarks>
        /// The strategy to handle the mousedown event is as following:
        ///
        /// Have we clicked on already selected objects?
        ///   if yes (we have clicked on already selected objects) and the shift or control key was pressed -> deselect the object and repaint
        ///   if yes (we have clicked on already selected objects) and none shift nor control key was pressed-> activate the object moving  mode
        ///   if no (we have not clicked on already selected objects) and shift or control key was pressed -> search for the object and add it to the selected objects, then aktivate moving mode
        ///   if no (we have not clicked on already selected objects) and no shift or control key pressed -> if a object was found add it to the selected objects and activate moving mode
        ///                                                                                                  if no object was found clear the selection list, deactivate moving mode
        /// </remarks>
        public override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
        {
            base.OnMouseDown(e);

            if (e.Button != MouseButtons.Left)
            {
                return; // then there is nothing to do here
            }
            // first, if we have a mousedown without shift key and the
            // position has changed with respect to the last mousedown
            // we have to deselect all objects
            bool bControlKey = (Keys.Control == (Control.ModifierKeys & Keys.Control)); // Control pressed
            bool bShiftKey   = (Keys.Shift == (Control.ModifierKeys & Keys.Shift));

            PointF mouseXY = new PointF(e.X, e.Y);                           // Mouse pixel coordinates
            PointF graphXY = _grac.PixelToPrintableAreaCoordinates(mouseXY); // Graph area coordinates


            // if we have exacly one object selected, and the one object is grippable,
            // we hit test for the grip areas
            if (SingleSelectedObject is IGrippableObject)
            {
                IGrippableObject gripObject = (IGrippableObject)SingleSelectedObject;
                // first switch to the layer graphics context (from printable context)

                PointF layerCoord = SingleSelectedHitTestObject.ParentLayer.GraphToLayerCoordinates(graphXY);

                _grip.Handle = gripObject.GripHitTest(layerCoord);

                if (_grip.Handle != null)
                {
                    _grip.Layer  = SingleSelectedHitTestObject.ParentLayer.Number;
                    _grip.Object = gripObject;
                    return; //
                }
            }



            // have we clicked on one of the already selected objects
            IHitTestObject clickedSelectedObject            = null;
            bool           bClickedOnAlreadySelectedObjects = IsPixelPositionOnAlreadySelectedObject(mouseXY, out clickedSelectedObject);

            if (bClickedOnAlreadySelectedObjects)
            {
                if (bShiftKey || bControlKey) // if shift or control is pressed, remove the selection
                {
                    m_SelectedObjects.Remove(clickedSelectedObject);
                    _grac.RefreshGraph(); // repaint the graph
                }
                else // not shift or control pressed -> so activate the object moving mode
                {
                    StartMovingObjects(mouseXY);
                }
            }    // end if bClickedOnAlreadySelectedObjects
            else // not clicked on a already selected object
            {
                // search for a object first
                IHitTestObject clickedObject;
                int            clickedLayerNumber = 0;
                _grac.FindGraphObjectAtPixelPosition(mouseXY, false, out clickedObject, out clickedLayerNumber);

                if (bShiftKey || bControlKey) // if shift or control are pressed, we add the object to the selection list and start moving mode
                {
                    if (null != clickedObject)
                    {
                        m_SelectedObjects.Add(clickedObject);

                        StartMovingObjects(mouseXY);
                        _grac.RepaintGraphArea();
                    }
                }
                else // no shift or control key pressed
                {
                    if (null != clickedObject)
                    {
                        ClearSelections();
                        m_SelectedObjects.Add(clickedObject);

                        StartMovingObjects(mouseXY);
                        _grac.RepaintGraphArea();
                    }
                    else // if clicked to nothing
                    {
                        ClearSelections(); // clear the selection list
                    }
                } // end else no shift or control
            }     // end else (not cklicked on already selected object)
        }         // end of function