示例#1
0
        private void MainForm_MouseMove(object sender, MouseEventArgs e)//
        {
            #region Cursor selection
            if (e.Button == MouseButtons.None)
            {
                if (MoverB.Visible &&
                    MoverB.X <= e.X && e.X < MoverB.X + MoverB.W &&
                    MoverB.Y <= e.Y && e.Y < MoverB.Y + MoverB.H)
                {
                    Cursor = MoverB.Cursor;
                }
                else if (MoverA.Visible &&
                         MoverA.X <= e.X && e.X < MoverA.X + MoverA.W &&
                         MoverA.Y <= e.Y && e.Y < MoverA.Y + MoverA.H)
                {
                    Cursor = MoverA.Cursor;
                }
                else if (Selection.Visible &&
                         Selection.X <= e.X && e.X < Selection.X + Selection.W &&
                         Selection.Y <= e.Y && e.Y < Selection.Y + Selection.H)
                {
                    Cursor = Cursors.Hand;
                }
                else
                {
                    Cursor = (Map.AnythingAt(Map.ScrollX + e.X, Map.ScrollY + e.Y) == null) ? Cursors.Default : Cursors.Hand;
                }
            }
            #endregion

            #region Moving/Sizing
            else
            {
                bool redraw = true;
                int  msXn   = e.X,
                     msYn   = e.Y;
                Map.SnapXY(ref msXn, ref msYn);
                int dX = msXn - msXnLast,
                    dY = msYn - msYnLast;

                #region Move B point of line / Resize box
                if (MoverB.Active)
                {
                    // Resize
                    if (Map.Selected.IsLink)
                    {
                        if (dX != 0 || dY != 0)
                        {
                            var Link = (Map.Selected as xLink);
                            Link.XB += dX;
                            Link.YB += dY;
                            TryToBindToObject(Map,
                                              Map.ScrollX + e.X, Map.ScrollY + e.Y,
                                              ref Link.ObjectB, ref Link.ObjectBID,
                                              ref Link.DotB, ref Link.DotBID,
                                              ref Link.XB, ref Link.YB);
                        }
                        else
                        {
                            redraw = false;
                        }
                    }
                    // Move
                    else if (Map.Selected.IsBox)
                    {
                        if (dX != 0 || dY != 0)
                        {
                            xBox Box = (Map.Selected as xBox);
                            Box.Width  += dX;
                            Box.Height += dY;
                            if (Box.Width < 1)
                            {
                                Box.Width = 1;
                            }
                            if (Box.Height < 1)
                            {
                                Box.Height = 1;
                            }
                        }
                        else
                        {
                            redraw = false;
                        }
                    }
                }
                #endregion

                #region Move A point of line
                else if (MoverA.Active)
                {
                    if (dX != 0 || dY != 0)
                    {
                        var Link = (Map.Selected as xLink);
                        Link.XA += dX;
                        Link.YA += dY;
                        TryToBindToObject(Map,
                                          Map.ScrollX + e.X, Map.ScrollY + e.Y,
                                          ref Link.ObjectA, ref Link.ObjectAID,
                                          ref Link.DotA, ref Link.DotAID,
                                          ref Link.XA, ref Link.YA);
                    }
                    else
                    {
                        redraw = false;
                    }
                }
                #endregion

                #region Move element
                else if (Selection.Active)
                {
                    if (dX != 0 || dY != 0)
                    {
                        if (Map.Selected.IsObject)
                        {
                            (Map.Selected as xObject).X += dX;
                            (Map.Selected as xObject).Y += dY;
                        }
                        else if (Map.Selected.IsBox)
                        {
                            (Map.Selected as xBox).Left += dX;
                            (Map.Selected as xBox).Top  += dY;
                        }
                        else
                        {
                            //...
                        }
                    }
                    else
                    {
                        redraw = false;
                    }
                }
                #endregion

                #region Map scrolling
                else
                {
                    Map.ScrollX += msXLast - e.X;
                    Map.ScrollY += msYLast - e.Y;
                    CheckScrollers();
                    redraw = false;
                }
                #endregion

                if (redraw)
                {
                    Map.Changed = true;
                    Map.UpdateTabName();
                    Map.Selected.Check();
                    if (Map.Selected.IsObject)
                    {
                        Map.CheckLinksToObject(Map.Selected.ID);
                    }
                    Map.Draw(Map.ScrollX, Map.ScrollY, Options.PortW, Options.PortH);
                }

                CheckFrames();
                Invalidate();

                msXLast  = e.X;
                msYLast  = e.Y;
                msXnLast = msXn;
                msYnLast = msYn;
            }
            #endregion
        }