Пример #1
0
        public override void OnMouseDragBegin(MouseEventArgs e)
        {
            Point2I mousePos  = new Point2I(e.X, e.Y);
            Point2I tileCoord = LevelDisplayControl.SampleLevelTileCoordinates(mousePos);
            Point2I point     = LevelDisplayControl.SampleLevelPixelPosition(mousePos);

            if (isCreatingSelectionBox || isMovingSelectionBox)
            {
                return;
            }

            // Draw a new selecion box.
            if (e.Button == MouseButtons.Left)
            {
                if (EditorControl.Level == LevelDisplayControl.SelectionGridLevel &&
                    LevelDisplayControl.SelectionBox.Contains(point))
                {
                    // Begin moving the selection box.
                    isMovingSelectionBox   = true;
                    dragBeginPoint         = point;
                    dragBeginTileCoord     = tileCoord;
                    selectionBoxBeginPoint = LevelDisplayControl.SelectionGridArea.Point;
                    //LevelDisplayControl.PickupSelectionGrid();

                    // Duplicate selection if holding Ctrl.
                    if (System.Windows.Forms.Control.ModifierKeys.HasFlag(KEYMOD_DUPLICATE))
                    {
                        LevelDisplayControl.DuplicateSelectionGrid();
                    }
                }
                else
                {
                    LevelDisplayControl.PlaceSelectionGrid();

                    // Create a new selection box.
                    isCreatingSelectionBox = true;
                    dragBeginPoint         = point;
                    dragBeginTileCoord     = tileCoord;

                    Rectangle2I selectionBox;
                    Level       level = EditorControl.Level;

                    if (System.Windows.Forms.Control.ModifierKeys.HasFlag(KEYMOD_ROOM_MODE))
                    {
                        selectionBox = new Rectangle2I(level.GetRoomLocation(
                                                           (LevelTileCoord)dragBeginTileCoord), Point2I.One);
                        Rectangle2I levelBounds = new Rectangle2I(Point2I.Zero, level.Dimensions);
                        selectionBox        = Rectangle2I.Intersect(selectionBox, levelBounds);
                        selectionBox.Point *= level.RoomSize;
                        selectionBox.Size  *= level.RoomSize;
                    }
                    else
                    {
                        selectionBox = new Rectangle2I(dragBeginTileCoord, Point2I.One);
                        Rectangle2I levelBounds = new Rectangle2I(Point2I.Zero, level.RoomSize * level.Dimensions);
                        selectionBox = Rectangle2I.Intersect(selectionBox, levelBounds);
                    }

                    LevelDisplayControl.SetSelectionGridArea(selectionBox, level);
                }
            }
        }
Пример #2
0
 public override void OnEnd()
 {
     LevelDisplayControl.PlaceSelectionGrid();
 }