protected override void OnMouseMove(DrawingMark sender, MouseEventArgs e)
        {
            //0   1
            //  4
            //2   3
            if (sender.Parent == null)
            {
                return;
            }
            switch (sender.Index)
            {
            case 0:
                ptStart.Y = designer.Marks[0].Y - Page.AutoScrollPosition.Y;
                ptStart.X = designer.Marks[0].X - Page.AutoScrollPosition.X;
                break;

            case 1:
                ptControl1.Y = designer.Marks[1].Y - Page.AutoScrollPosition.Y;
                ptControl1.X = designer.Marks[1].X - Page.AutoScrollPosition.X;
                break;

            case 2:
                ptControl2.Y = designer.Marks[2].Y - Page.AutoScrollPosition.Y;
                ptControl2.X = designer.Marks[2].X - Page.AutoScrollPosition.X;
                break;

            case 3:
                ptEnd.Y = designer.Marks[3].Y - Page.AutoScrollPosition.Y;
                ptEnd.X = designer.Marks[3].X - Page.AutoScrollPosition.X;
                break;

            case 4:
                int dx = designer.Marks[4].X - x0 - Page.AutoScrollPosition.X;
                int dy = designer.Marks[4].Y - y0 - Page.AutoScrollPosition.Y;
                for (int i = 0; i < 4; i++)
                {
                    designer.Marks[i].X += dx;
                    designer.Marks[i].Y += dy;
                }
                ptStart.Y    = designer.Marks[0].Y - Page.AutoScrollPosition.Y;
                ptStart.X    = designer.Marks[0].X - Page.AutoScrollPosition.X;
                ptControl1.Y = designer.Marks[1].Y - Page.AutoScrollPosition.Y;
                ptControl1.X = designer.Marks[1].X - Page.AutoScrollPosition.X;
                ptControl2.Y = designer.Marks[2].Y - Page.AutoScrollPosition.Y;
                ptControl2.X = designer.Marks[2].X - Page.AutoScrollPosition.X;
                ptEnd.Y      = designer.Marks[3].Y - Page.AutoScrollPosition.Y;
                ptEnd.X      = designer.Marks[3].X - Page.AutoScrollPosition.X;
                x0           = (ptStart.X + ptEnd.X) / 2;
                y0           = (ptStart.Y + ptEnd.Y) / 2;
                break;
            }
            if (sender.Index != 4)
            {
                x0 = (ptStart.X + ptEnd.X) / 2;
                y0 = (ptStart.Y + ptEnd.Y) / 2;
                designer.Marks[4].X = x0 + Page.AutoScrollPosition.X;
                designer.Marks[4].Y = y0 + Page.AutoScrollPosition.Y;
            }
            sender.Parent.Invalidate();
        }
 protected override void OnMouseMove(DrawingMark sender, MouseEventArgs e)
 {
     if (sender.Index == 0)
     {
         p1.X = designer.Marks[0].X - Page.AutoScrollPosition.X;
         p1.Y = designer.Marks[0].Y - Page.AutoScrollPosition.Y;
         designer.Marks[1].X = (p1.X + p2.X) / 2 + Page.AutoScrollPosition.X;
         designer.Marks[1].Y = (p1.Y + p2.Y) / 2 + Page.AutoScrollPosition.Y;
     }
     else if (sender.Index == 1)
     {
         /*calculate the increases of x and y: dx, dy
          * new line: (x10,y10) - (x20,y20). new center: (x0,y0)
          * New center already know. Find (x10,y10) and (x20,y20)
          *	x0 = (x10 + X20)/2
          *      y0 = (y10 + y20)/2
          *      x1 + dx = x10
          *      y1 + dy = y10
          *      x2 + dx = x20
          *      y2 + dy = y20
          *      Calculate new points:
          *      x0 = (x1 + dx + x2 + dx)/2 = (x1 + x2)/2 + dx
          *      y0 = (y1 + dy + y2 + dy)/2 = (y1 + y2)/2 + dy
          *      dx = x0 - (x1 + x2)/2
          *      dy = y0 - (y1 + y2)/2
          */
         int dx = designer.Marks[1].X - (designer.Marks[0].X + designer.Marks[2].X) / 2;
         int dy = designer.Marks[1].Y - (designer.Marks[0].Y + designer.Marks[2].Y) / 2;
         p1.X += dx;
         p1.Y += dy;
         p2.X += dx;
         p2.Y += dy;
         designer.Marks[0].X = p1.X + Page.AutoScrollPosition.X;
         designer.Marks[0].Y = p1.Y + Page.AutoScrollPosition.Y;
         designer.Marks[2].X = p2.X + Page.AutoScrollPosition.X;
         designer.Marks[2].Y = p2.Y + Page.AutoScrollPosition.Y;
     }
     else if (sender.Index == 2)
     {
         p2.X = designer.Marks[2].X - Page.AutoScrollPosition.X;
         p2.Y = designer.Marks[2].Y - Page.AutoScrollPosition.Y;
         designer.Marks[1].X = (p1.X + p2.X) / 2 + Page.AutoScrollPosition.X;
         designer.Marks[1].Y = (p1.Y + p2.Y) / 2 + Page.AutoScrollPosition.Y;
     }
     calculateAttr();
     sender.Parent.Invalidate();
 }
        protected override void OnMouseMove(DrawingMark sender, MouseEventArgs e)
        {
            if (sender.Parent == null)
            {
                return;
            }
            Point ap = this.GetAbsolutePosition();
            int   dx = ap.X - pos.X;
            int   dy = ap.Y - pos.Y;

            switch (sender.Index)
            {
            case 0:
                double xo = designer.Marks[0].X - _size.Width / 2;
                double yo = designer.Marks[0].Y - _size.Height / 2;
                pos.X = (int)Math.Round(xo - Page.AutoScrollPosition.X, 0) - dx;
                pos.Y = (int)Math.Round(yo - Page.AutoScrollPosition.Y, 0) - dy;
                break;

            case 1:
                int x0 = designer.Marks[1].X - designer.Marks[0].X;
                int y0 = designer.Marks[1].Y - designer.Marks[0].Y;
                if (x0 != 0 || y0 != 0)
                {
                    if (x0 >= 0 && y0 >= 0)
                    {
                        if (y0 == 0)
                        {
                            Angle = 0;
                        }
                        else if (x0 == 0)
                        {
                            Angle = 90;
                        }
                        else
                        {
                            Angle = Math.Atan((double)y0 / (double)x0) * 180.0 / Math.PI;
                        }
                    }
                    else if (x0 < 0 && y0 >= 0)
                    {
                        if (y0 == 0)
                        {
                            Angle = 180;
                        }
                        else
                        {
                            Angle = 180 - Math.Atan((double)y0 / (-(double)x0)) * 180.0 / Math.PI;
                        }
                    }
                    else if (x0 >= 0 && y0 < 0)
                    {
                        y0    = -y0;
                        Angle = -Math.Atan((double)y0 / (double)x0) * 180.0 / Math.PI;
                    }
                    else
                    {
                        Angle = 180 + Math.Atan((double)y0 / (double)x0) * 180.0 / Math.PI;
                    }
                }
                break;
            }
            if (sender.Index != 1)
            {
                double angle = (Angle / 180) * Math.PI;
                designer.Marks[1].X = designer.Marks[0].X + (int)((_size.Width / 2.0) * Math.Cos(angle));
                designer.Marks[1].Y = designer.Marks[0].Y + (int)((_size.Width / 2.0) * Math.Sin(angle));
            }
            sender.Parent.Invalidate(Bounds);
        }
Esempio n. 4
0
        protected override void OnMouseMove(DrawingMark sender, MouseEventArgs e)
        {
            //0   1
            //  4
            //2   3
            if (sender.Parent == null)
            {
                return;
            }
            switch (sender.Index)
            {
            case 0:
                designer.Marks[1].Y = designer.Marks[0].Y;
                designer.Marks[2].X = designer.Marks[0].X;
                designer.Marks[4].X = (designer.Marks[0].X + designer.Marks[3].X) / 2;
                designer.Marks[4].Y = (designer.Marks[0].Y + designer.Marks[3].Y) / 2;
                center.X            = designer.Marks[4].X - Page.AutoScrollPosition.X;
                center.Y            = designer.Marks[4].Y - Page.AutoScrollPosition.Y;
                if (designer.Marks[0].X > designer.Marks[4].X)
                {
                    radius = designer.Marks[0].X - designer.Marks[4].X;
                }
                else
                {
                    radius = designer.Marks[4].X - designer.Marks[0].X;
                }
                break;

            case 1:
                designer.Marks[0].Y = designer.Marks[1].Y;
                designer.Marks[3].X = designer.Marks[1].X;
                designer.Marks[4].X = (designer.Marks[0].X + designer.Marks[3].X) / 2;
                designer.Marks[4].Y = (designer.Marks[0].Y + designer.Marks[3].Y) / 2;
                center.X            = designer.Marks[4].X - Page.AutoScrollPosition.X;
                center.Y            = designer.Marks[4].Y - Page.AutoScrollPosition.Y;
                if (designer.Marks[0].X > designer.Marks[4].X)
                {
                    radius = designer.Marks[0].X - designer.Marks[4].X;
                }
                else
                {
                    radius = designer.Marks[4].X - designer.Marks[0].X;
                }
                break;

            case 2:
                designer.Marks[0].X = designer.Marks[2].X;
                designer.Marks[3].Y = designer.Marks[2].Y;
                designer.Marks[4].X = (designer.Marks[0].X + designer.Marks[3].X) / 2;
                designer.Marks[4].Y = (designer.Marks[0].Y + designer.Marks[3].Y) / 2;
                center.X            = designer.Marks[4].X - Page.AutoScrollPosition.X;
                center.Y            = designer.Marks[4].Y - Page.AutoScrollPosition.Y;
                if (designer.Marks[0].X > designer.Marks[4].X)
                {
                    radius = designer.Marks[0].X - designer.Marks[4].X;
                }
                else
                {
                    radius = designer.Marks[4].X - designer.Marks[0].X;
                }
                break;

            case 3:
                designer.Marks[1].X = designer.Marks[3].X;
                designer.Marks[2].Y = designer.Marks[3].Y;
                designer.Marks[4].X = (designer.Marks[0].X + designer.Marks[3].X) / 2;
                designer.Marks[4].Y = (designer.Marks[0].Y + designer.Marks[3].Y) / 2;
                center.X            = designer.Marks[4].X - Page.AutoScrollPosition.X;
                center.Y            = designer.Marks[4].Y - Page.AutoScrollPosition.Y;
                if (designer.Marks[0].X > designer.Marks[4].X)
                {
                    radius = designer.Marks[0].X - designer.Marks[4].X;
                }
                else
                {
                    radius = designer.Marks[4].X - designer.Marks[0].X;
                }
                break;

            case 4:
                designer.Marks[0].X = designer.Marks[4].X - radius;
                designer.Marks[0].Y = designer.Marks[4].Y - radius;
                designer.Marks[1].X = designer.Marks[4].X + radius;
                designer.Marks[1].Y = designer.Marks[4].Y - radius;
                designer.Marks[2].X = designer.Marks[4].X - radius;
                designer.Marks[2].Y = designer.Marks[4].Y + radius;
                designer.Marks[3].X = designer.Marks[4].X + radius;
                designer.Marks[3].Y = designer.Marks[4].Y + radius;
                center.X            = designer.Marks[4].X - Page.AutoScrollPosition.X;
                center.Y            = designer.Marks[4].Y - Page.AutoScrollPosition.Y;
                break;
            }
            sender.Parent.Invalidate();
        }
 protected override void OnMouseMove(DrawingMark sender, MouseEventArgs e)
 {
     if (sender.Parent == null || pts == null)
     {
         return;
     }
     if (sender.Index == 0)
     {
         //move
         double dx = designer.Marks[0].X - x0 - Page.AutoScrollPosition.X;
         double dy = designer.Marks[0].Y - y0 - Page.AutoScrollPosition.Y;
         for (int i = 0; i < pts.Length; i++)
         {
             pts[i].X += (int)dx;
             pts[i].Y += (int)dy;
             designer.Marks[i + nBaseIndex].X = pts[i].X + Page.AutoScrollPosition.X;
             designer.Marks[i + nBaseIndex].Y = pts[i].Y + Page.AutoScrollPosition.Y;
         }
         designer.Marks[1].X += (int)dx;
         designer.Marks[1].Y += (int)dy;
         x0 = designer.Marks[0].X - Page.AutoScrollPosition.X;
         y0 = designer.Marks[0].Y - Page.AutoScrollPosition.Y;
         calculateBrounds();
     }
     else if (sender.Index == 1)
     {
         //set rotate angle
         double dx = designer.Marks[1].X - designer.Marks[0].X;
         double dy = designer.Marks[1].Y - designer.Marks[0].Y;
         double dd = 0;
         if (Math.Abs(dx) < 0.0001)
         {
             if (dy > 0)
             {
                 dd = 90;
             }
             else
             {
                 dd = 270;
             }
         }
         else
         {
             dd = (Math.Atan(Math.Abs(dy / dx)) / Math.PI) * 180.0;
             if (dx > 0)
             {
                 if (dy < 0)
                 {
                     dd = 360 - dd;
                 }
             }
             else
             {
                 if (dy > 0)
                 {
                     dd = 180 - dd;
                 }
                 else
                 {
                     dd = 180 + dd;
                 }
             }
         }
         if (Angle != dd)
         {
             double angle = dd - Angle;
             nMinX = 20000;
             nMaxX = 0;
             nMinY = 20000;
             nMaxY = 0;
             //
             //angle = (angle/180)*Math.PI;
             double xc = designer.Marks[0].X;
             double yc = designer.Marks[0].Y;
             double xo;
             double yo;
             if (pts != null)
             {
                 for (int i = 0; i < pts.Length; i++)
                 {
                     xo = designer.Marks[i + nBaseIndex].X;
                     yo = designer.Marks[i + nBaseIndex].Y;
                     DrawingItem.Rotate(xo, yo, xc, yc, -angle, out xo, out yo);
                     designer.Marks[i + nBaseIndex].X = (int)Math.Round(xo, 0);
                     designer.Marks[i + nBaseIndex].Y = (int)Math.Round(yo, 0);
                     pts[i].X = (int)Math.Round(xo - Page.AutoScrollPosition.X, 0);
                     pts[i].Y = (int)Math.Round(yo - Page.AutoScrollPosition.Y, 0);
                     if (nMinX > pts[i].X)
                     {
                         nMinX = pts[i].X;
                     }
                     if (nMaxX < pts[i].X)
                     {
                         nMaxX = pts[i].X;
                     }
                     if (nMinY > pts[i].Y)
                     {
                         nMinY = pts[i].Y;
                     }
                     if (nMaxY < pts[i].Y)
                     {
                         nMaxY = pts[i].Y;
                     }
                 }
             }
             Angle = dd;
         }
     }
     else
     {
         //drag corner point
         pts[sender.Index - nBaseIndex].X = designer.Marks[sender.Index].X - Page.AutoScrollPosition.X;
         pts[sender.Index - nBaseIndex].Y = designer.Marks[sender.Index].Y - Page.AutoScrollPosition.Y;
         calculateBrounds();
     }
     if (sender.Index >= nBaseIndex)
     {
         x0 = 0;
         y0 = 0;
         for (int i = 0; i < pts.Length; i++)
         {
             x0 += pts[i].X;
             y0 += pts[i].Y;
         }
         x0 /= pts.Length;
         y0 /= pts.Length;
         designer.Marks[0].X = x0 + Page.AutoScrollPosition.X;
         designer.Marks[0].Y = y0 + Page.AutoScrollPosition.Y;
         calculateBrounds();
     }
     sender.Parent.Invalidate(Bounds);
 }
        protected override void OnMouseMove(DrawingMark sender, MouseEventArgs e)
        {
            //0   1
            //  4
            //2   3
            if (sender.Parent == null)
            {
                return;
            }
            switch (sender.Index)
            {
            case 0:
                designer.Marks[1].Y = designer.Marks[0].Y;
                designer.Marks[2].X = designer.Marks[0].X;
                designer.Marks[4].X = (designer.Marks[0].X + designer.Marks[3].X) / 2;
                designer.Marks[4].Y = (designer.Marks[0].Y + designer.Marks[3].Y) / 2;
                if (designer.Marks[0].X > designer.Marks[1].X)
                {
                    rc.X = designer.Marks[1].X - Page.AutoScrollPosition.X;
                }
                else
                {
                    rc.X = designer.Marks[0].X - Page.AutoScrollPosition.X;
                }
                if (designer.Marks[0].Y > designer.Marks[3].Y)
                {
                    rc.Y = designer.Marks[3].Y - Page.AutoScrollPosition.Y;
                }
                else
                {
                    rc.Y = designer.Marks[0].Y - Page.AutoScrollPosition.Y;
                }
                rc.Width  = Math.Abs(designer.Marks[0].X - designer.Marks[1].X);
                rc.Height = Math.Abs(designer.Marks[0].Y - designer.Marks[2].Y);
                break;

            case 1:
                designer.Marks[0].Y = designer.Marks[1].Y;
                designer.Marks[3].X = designer.Marks[1].X;
                designer.Marks[4].X = (designer.Marks[0].X + designer.Marks[3].X) / 2;
                designer.Marks[4].Y = (designer.Marks[0].Y + designer.Marks[3].Y) / 2;
                if (designer.Marks[0].X > designer.Marks[1].X)
                {
                    rc.X = designer.Marks[1].X - Page.AutoScrollPosition.X;
                }
                else
                {
                    rc.X = designer.Marks[0].X - Page.AutoScrollPosition.X;
                }
                if (designer.Marks[0].Y > designer.Marks[3].Y)
                {
                    rc.Y = designer.Marks[3].Y - Page.AutoScrollPosition.Y;
                }
                else
                {
                    rc.Y = designer.Marks[0].Y - Page.AutoScrollPosition.Y;
                }
                rc.Width  = Math.Abs(designer.Marks[0].X - designer.Marks[1].X);
                rc.Height = Math.Abs(designer.Marks[0].Y - designer.Marks[2].Y);
                break;

            case 2:
                designer.Marks[3].Y = designer.Marks[2].Y;
                designer.Marks[0].X = designer.Marks[2].X;
                designer.Marks[4].X = (designer.Marks[0].X + designer.Marks[3].X) / 2;
                designer.Marks[4].Y = (designer.Marks[0].Y + designer.Marks[3].Y) / 2;
                if (designer.Marks[0].X > designer.Marks[1].X)
                {
                    rc.X = designer.Marks[1].X - Page.AutoScrollPosition.X;
                }
                else
                {
                    rc.X = designer.Marks[0].X - Page.AutoScrollPosition.X;
                }
                if (designer.Marks[0].Y > designer.Marks[3].Y)
                {
                    rc.Y = designer.Marks[3].Y - Page.AutoScrollPosition.Y;
                }
                else
                {
                    rc.Y = designer.Marks[0].Y - Page.AutoScrollPosition.Y;
                }
                rc.Width  = Math.Abs(designer.Marks[0].X - designer.Marks[1].X);
                rc.Height = Math.Abs(designer.Marks[0].Y - designer.Marks[2].Y);
                break;

            case 3:
                designer.Marks[2].Y = designer.Marks[3].Y;
                designer.Marks[1].X = designer.Marks[3].X;
                designer.Marks[4].X = (designer.Marks[0].X + designer.Marks[3].X) / 2;
                designer.Marks[4].Y = (designer.Marks[0].Y + designer.Marks[3].Y) / 2;
                if (designer.Marks[0].X > designer.Marks[1].X)
                {
                    rc.X = designer.Marks[1].X - Page.AutoScrollPosition.X;
                }
                else
                {
                    rc.X = designer.Marks[0].X - Page.AutoScrollPosition.X;
                }
                if (designer.Marks[0].Y > designer.Marks[3].Y)
                {
                    rc.Y = designer.Marks[3].Y - Page.AutoScrollPosition.Y;
                }
                else
                {
                    rc.Y = designer.Marks[0].Y - Page.AutoScrollPosition.Y;
                }
                rc.Width  = Math.Abs(designer.Marks[0].X - designer.Marks[1].X);
                rc.Height = Math.Abs(designer.Marks[0].Y - designer.Marks[2].Y);
                break;

            case 4:
                designer.Marks[0].X = designer.Marks[4].X - rc.Width / 2;
                designer.Marks[0].Y = designer.Marks[4].Y - rc.Height / 2;
                designer.Marks[1].X = designer.Marks[4].X + rc.Width / 2;
                designer.Marks[1].Y = designer.Marks[4].Y - rc.Height / 2;
                designer.Marks[2].X = designer.Marks[4].X - rc.Width / 2;
                designer.Marks[2].Y = designer.Marks[4].Y + rc.Height / 2;
                designer.Marks[3].X = designer.Marks[4].X + rc.Width / 2;
                designer.Marks[3].Y = designer.Marks[4].Y + rc.Height / 2;
                if (designer.Marks[0].X > designer.Marks[1].X)
                {
                    rc.X = designer.Marks[1].X - Page.AutoScrollPosition.X;
                }
                else
                {
                    rc.X = designer.Marks[0].X - Page.AutoScrollPosition.X;
                }
                if (designer.Marks[0].Y > designer.Marks[3].Y)
                {
                    rc.Y = designer.Marks[3].Y - Page.AutoScrollPosition.Y;
                }
                else
                {
                    rc.Y = designer.Marks[0].Y - Page.AutoScrollPosition.Y;
                }
                break;
            }
            sender.Parent.Invalidate();
        }