Esempio n. 1
0
        private ITileMapSelection ChooseSelection()
        {
            ITileMapSelection result = null;

            if (DesignControl.AltKeyHeld)
            {
                var firstIndex = TileMap1D.GetTileIndex(
                    FirstGridTile,
                    TileMap.GridWidth);

                var activeIndex = TileMap1D.GetTileIndex(
                    ActiveGridTile,
                    TileMap.GridWidth);

                var originIndex = Min(firstIndex, activeIndex);
                var endIndex    = Max(firstIndex, activeIndex);
                var count       = endIndex - originIndex + 1;
                result = new LinearTileMapSelection(
                    firstIndex < activeIndex ? FirstGridTile : ActiveGridTile,
                    count,
                    TileMap.GridWidth);
            }
            else
            {
                var origin = new Point(
                    Min(FirstGridTile.X, ActiveGridTile.X),
                    Min(FirstGridTile.Y, ActiveGridTile.Y));

                var end = new Point(
                    Max(FirstGridTile.X, ActiveGridTile.X),
                    Max(FirstGridTile.Y, ActiveGridTile.Y));

                var size = new Size(
                    end.X + 1 - origin.X,
                    end.Y + 1 - origin.Y);
                result = new BoxTileMapSelection(
                    origin,
                    size,
                    TileMap.GridWidth);
            }

            if (DesignControl.ControlKeyHeld && CurrentSelection != null)
            {
                result = new EnumerableTileMapSelection(
                    CurrentSelection.Union(result),
                    TileMap.GridWidth);
            }

            return(result);
        }