public void MouseUp(MouseEventArgs e)
 {
     if (IsActive)
     {
         DeactivateTool();
         TransformCommand cmd = new TransformCommand(this.Controller, origin, scalex, scaley, transformers);
         this.Controller.UndoManager.AddUndoCommand(cmd);
     }
 }
示例#2
0
 public void MouseUp(MouseEventArgs e)
 {
     if (IsActive)
     {
         DeactivateTool();
         //Controller.View.CurrentCursor = Cursors.Default;
         cursorChanged  = false;
         previousCursor = null;
         TransformCommand cmd = new TransformCommand(
             this.Controller,
             origin,
             scalex,
             scaley,
             transformers);
         this.Controller.UndoManager.AddUndoCommand(cmd);
     }
 }
        /// <summary>
        /// Resizes the selected entities.
        /// <remarks>The whole logic and geometry behind the resizing is quite involved, there is a detailed Visio diagram
        /// showing the elements of the calculations and how the various switch cases are linked together.
        /// </remarks>
        /// </summary>
        /// <param name="e">The <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
        public void MouseMove(MouseEventArgs e)
        {
            #region Checking the incoming data
            if (e == null)
            {
                throw new ArgumentNullException("The argument object is 'null'");
            }
            #endregion

            #region Definition to make the code more readable

            //some annoying but necessary type conversions here to double precision
            double lastLength = 0;                           //the diagonal length of the current rectangle we are resizing
            double eX = e.X, eY = e.Y;                       //the vector corresponding to the mouse location
            double lx = lastPoint.X, ly = lastPoint.Y;       // the lastpoint vector
            double iX = initialPoint.X, iY = initialPoint.Y; // the vactor when the motion started

            double mx, my;                                   //the motion vector
            double rx = 0, ry = 0;                           //the resulting vector

            double sign = 1;
            #endregion

            if (IsActive)
            {
                #region The current motion vector is computed
                mx = eX - lx;
                my = eY - ly;
                #endregion

                #region Switching between the different compass directions of the grips
                //the transform is the compass direction of the grip used to resize the entities
                switch (transform)
                {
                    #region NW
                case TransformTypes.NW:



                    //the region above the X-Y=0 diagonal uses the horizontal to project the motion vector onto the diagonal
                    if (mx - my < 0)
                    {
                        scale = (ox - (double)e.X) / (ox - (double)initialPoint.X);
                    }
                    else
                    {
                        scale = (oy - (double)e.Y) / (oy - (double)initialPoint.Y);
                    }
                    //now we can pass the info the the scaling method of the selected entities
                    scalex = scale;
                    scaley = scale;
                    break;
                    #endregion

                    #region N
                case TransformTypes.N:
                    //remember that the coordinate system has its Y-axis pointing downwards
                    scale = (oy - (double)e.Y) / (oy - (double)initialPoint.Y);

                    //now we can pass the info the the scaling method of the selected entities
                    scalex = 1F;
                    scaley = scale;
                    break;
                    #endregion

                    #region NE
                case TransformTypes.NE:
                    //the region above the X-Y=0 diagonal uses the horizontal to project the motion vector onto the diagonal
                    if (mx + my > 0)
                    {
                        scale = ((double)e.X - ox) / ((double)initialPoint.X - ox);
                    }
                    else
                    {
                        scale = ((double)e.Y - oy) / ((double)initialPoint.Y - oy);
                    }
                    //now we can pass the info the the scaling method of the selected entities
                    scalex = scale;
                    scaley = scale;
                    break;
                    #endregion

                    #region E
                case TransformTypes.E:
                    //remember that the coordinate system has its Y-axis pointing downwards
                    scale = ((double)e.X - ox) / ((double)initialPoint.X - ox);

                    //now we can pass the info the the scaling method of the selected entities
                    scalex = scale;
                    scaley = 1F;
                    break;
                    #endregion

                    #region SE
                case TransformTypes.SE:
                    //I'd call this the Visio effect...
                    if (mx - my > 0)
                    {
                        scale = ((double)e.X - ox) / ((double)initialPoint.X - ox);
                    }
                    else
                    {
                        scale = ((double)e.Y - oy) / ((double)initialPoint.Y - oy);
                    }

                    scalex = scale;
                    scaley = scale;
                    break;
                    #endregion

                    #region S
                case TransformTypes.S:
                    //remember that the coordinate system has its Y-axis pointing downwards
                    scale = ((double)e.Y - oy) / ((double)initialPoint.Y - oy);

                    //now we can pass the info the the scaling method of the selected entities
                    scalex = 1F;
                    scaley = scale;
                    break;
                    #endregion

                    #region SW
                case TransformTypes.SW:

                    //the region above the X-Y=0 diagonal uses the horizontal to project the motion vector onto the diagonal
                    if (mx + my < 0)
                    {
                        scale = ((double)e.X - ox) / ((double)initialPoint.X - ox);
                    }
                    else
                    {
                        scale = ((double)e.Y - oy) / ((double)initialPoint.Y - oy);
                    }
                    //now we can pass the info the the scaling method of the selected entities
                    scalex = scale;
                    scaley = scale;
                    break;
                    #endregion

                    #region W
                case TransformTypes.W:
                    //remember that the coordinate system has its Y-axis pointing downwards
                    scale = (ox - (double)e.X) / (ox - (double)initialPoint.X);

                    //now we can pass the info the the scaling method of the selected entities
                    scalex = scale;
                    scaley = 1F;
                    break;
                    #endregion
                }
                #endregion

                #region Scale the selected entities
                //block scaling below some minimum
                if (lastLength <= 70 && sign == -1)
                {
                    return;
                }
                //no need to use the rounding Convert method since the ox and oy doubles are really integers
                //but the calculations above requires double data types.
                origin = new Point(Convert.ToInt32(ox), Convert.ToInt32(oy));
                //update the location of the last point
                lastPoint.Offset(Convert.ToInt32(rx), Convert.ToInt32(ry));

                TransformCommand.Transform(origin, scalex, scaley, transformers);

                #endregion

                //since we used the flattened selection the group shapes are unaware of the the resize, so we
                //have to recalculate the group rectangles
                foreach (IDiagramEntity entity in Selection.SelectedItems)
                {
                    //the calculation will cascade to subgroups if necessary
                    if (entity is IGroup)
                    {
                        (entity as IGroup).CalculateRectangle();
                    }
                }
                //update the state of the tracker, i.e show it again and it'll be recalculated
                this.Controller.View.ShowTracker();
            }
        }
示例#4
0
 public void MouseUp(MouseEventArgs e) {
   if (IsActive) {
     DeactivateTool();
     //Controller.View.CurrentCursor = Cursors.Default;
     cursorChanged = false;
     previousCursor = null;
     TransformCommand cmd = new TransformCommand(
         this.Controller,
         origin,
         scalex,
         scaley,
         transformers);
     this.Controller.UndoManager.AddUndoCommand(cmd);
   }
 }
 public void MouseUp(MouseEventArgs e)
 {
     if (IsActive)
     {
         DeactivateTool();
         TransformCommand cmd = new TransformCommand(this.Controller, origin, scalex, scaley, transformers);
         this.Controller.UndoManager.AddUndoCommand(cmd);
     }
 }