Example #1
0
        //mouse button is released
        public override void OnMouseUp(Canvas drawArea, MouseEventArgs e)
        {
            if (selectMode == SelectionMode.MulitSelection)
            {
                return;
            }

            int zoom = drawArea.Document.Zoom;

            if (selectMode == SelectionMode.NetSelection)
            {
                // Group selection
                drawArea.Document.SelectInRectangle(drawArea.NetRectangle);

                selectMode = SelectionMode.None;
                drawArea.DrawNetRectangle = false;

                UndoService.Commit();
            }
            if (resizedObject != null ||
                selectMode == SelectionMode.Size
                )
            {
                // after resizing
                if (resizedObject != null)
                {
                    resizedObject.BeginEdit();
                    if (resizedObject is ShapePaint)
                    {
                        ; // resizedObject.SetVirtualBounds();
                    }
                    else
                    {
                        resizedObject.VirtualBounds = resizedObject.FormatBoundsByZoom(resizedObject.VirtualBounds, zoom);
                    }

                    resizedObject.EndEdit();
                    resizedObject = null;
                }

                selectMode = SelectionMode.None;
                UndoService.Commit();
            }

            if (selectMode == SelectionMode.Move)
            {
                foreach (ShapeBase sb in drawArea.Document.SelectedShapes)
                {
                    sb.BeginEdit();
                    if (sb is ShapeFigure
                        //|| sb is ShapeLine
                        )
                    {
                        sb.SetVirtualBounds();
                    }
                    else if (sb.Type != ShapeType.Line)
                    {
                        sb.VirtualBounds = sb.FormatBoundsByZoom(sb.VirtualBounds, zoom);
                    }

                    sb.EndEdit();
                }
                selectMode = SelectionMode.None;

                Point point = drawArea.BackTrackMouse(new Point(e.X, e.Y));
                for (int i = drawArea.Document.Count - 1; i >= 0; i--)
                {
                    if (drawArea.Document[i].HitTest(point) == 0)
                    {
                        ShapeBase so = drawArea.Document[i];
                        if (so != null)
                        {
                            // Unselect all if Ctrl is not pressed and clicked object is not selected yet
                            if ((Control.ModifierKeys != Keys.Control || Control.ModifierKeys != Keys.Shift) && so.IsSelected && startPoint == lastPoint)
                            {
                                drawArea.Document.CancelSelect(true);
                                so.IsSelected = true;
                            }
                        }
                        break;
                    }
                }

                UndoService.Commit();
            }

            drawArea.Capture = false;
            drawArea.Refresh();
            lastPoint = drawArea.BackTrackMouse(e.Location);
        }