示例#1
0
        public override void OnMouseDragMove(MouseEventArgs e)
        {
            Point2I mousePos     = new Point2I(e.X, e.Y);
            Point2I pointInLevel = LevelDisplayControl.SampleLevelPixelPosition(mousePos);

            // Update selection box.
            if (e.Button == MouseButtons.Left && isCreatingSelectionBox)
            {
                Point2I     tileCoord = LevelDisplayControl.SampleLevelTileCoordinates(mousePos);
                Level       level     = EditorControl.Level;
                Rectangle2I selectionBox;

                if (System.Windows.Forms.Control.ModifierKeys.HasFlag(KEYMOD_ROOM_MODE))
                {
                    Point2I roomCoord1   = level.GetRoomLocation((LevelTileCoord)dragBeginTileCoord);
                    Point2I roomCoord2   = level.GetRoomLocation((LevelTileCoord)tileCoord);
                    Point2I roomCoordMin = GMath.Min(roomCoord1, roomCoord2);
                    Point2I roomCoordMax = GMath.Max(roomCoord1, roomCoord2);

                    Rectangle2I levelDimensions = new Rectangle2I(Point2I.Zero, level.Dimensions);
                    selectionBox        = new Rectangle2I(roomCoordMin, roomCoordMax - roomCoordMin + Point2I.One);
                    selectionBox        = Rectangle2I.Intersect(selectionBox, levelDimensions);
                    selectionBox.Point *= level.RoomSize;
                    selectionBox.Size  *= level.RoomSize;
                }
                else
                {
                    Point2I minCoord = GMath.Min(dragBeginTileCoord, tileCoord);
                    Point2I maxCoord = GMath.Max(dragBeginTileCoord, tileCoord);

                    Rectangle2I levelBounds = new Rectangle2I(Point2I.Zero, level.RoomSize * level.Dimensions);
                    selectionBox = new Rectangle2I(minCoord, maxCoord - minCoord + Point2I.One);
                    //selectionBox = Rectangle2I.Intersect(selectionBox, levelBounds);
                }

                LevelDisplayControl.SetSelectionGridArea(selectionBox, level);
            }
            else if (e.Button == MouseButtons.Left && isMovingSelectionBox)
            {
                Point2I moveAmount;

                if (System.Windows.Forms.Control.ModifierKeys.HasFlag(KEYMOD_ROOM_MODE))
                {
                    moveAmount  = pointInLevel - dragBeginPoint;
                    moveAmount  = (Point2I)GMath.Round((Vector2F)moveAmount / (editorControl.Level.RoomSize * GameSettings.TILE_SIZE));
                    moveAmount *= editorControl.Level.RoomSize;
                }
                else
                {
                    moveAmount = pointInLevel - dragBeginPoint;
                    moveAmount = (Point2I)GMath.Round((Vector2F)moveAmount / GameSettings.TILE_SIZE);
                }

                Point2I selectionBoxPoint = selectionBoxBeginPoint + moveAmount;
                LevelDisplayControl.MoveSelectionGridArea(selectionBoxPoint);
            }
        }