private void Map_OnMouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                selectionStarted = true;
                renderer.StartSelection(new Point(e.X, e.Y));
            }
            else
            {
                BlobImage img = selectedTile();

                if (img == null)
                {
                    return;
                }

                CellData.FloorData floor = new CellData.FloorData();
                floor.Image = img;

                renderer.SetFloorAt(floor, e.X, e.Y);
            }

            if (MouseDown != null)
            {
                MouseDown(e);
            }
        }
        internal void LoadLevel(FileFormats.Infantry.LevelFile level)
        {
            var images = blobImages();

            for (int x = 0; x < level.Width; x++)
            {
                for (int y = 0; y < level.Height; y++)
                {
                    var cell    = level.Tiles[(y * level.Width) + x];
                    var terrain = level.Floors[cell.TerrainLookup];

                    var fd = new CellData.FloorData();
                    fd.Image = (from blob in images
                                where blob.BlobReference.FileName == terrain.FileName &&
                                blob.BlobReference.Id == terrain.Id
                                select blob).First();

                    renderer.SetFloorAtGrid(fd, x, y);
                }
            }

            MapLoaded = true;
        }
        public void SetFloorAt(CellData.FloorData floor, int pixelX, int pixelY)
        {
            int[] coords = grid.PixelsToGridCoordinates(pixelX + viewport.X, pixelY + viewport.Y);

            if (selection.IsInsideSelection(new Point(pixelX, pixelY)))
            {
                int[] startCoords = grid.PixelsToGridCoordinates(selection.IPoint.X, selection.IPoint.Y);
                int[] endCoords   = grid.PixelsToGridCoordinates(selection.FPoint.X, selection.FPoint.Y);

                Grid.GridRange range = grid.GetRange(startCoords, endCoords);

                foreach (Grid.GridCell cell in range)
                {
                    if (cell.Data == null)
                    {
                        cell.Data = new CellData();
                    }

                    cell.Data.Floor = floor;
                    grid.Insert(cell.Data, cell.X, cell.Y);
                }

                selection.ClearSelection();
            }
            else
            {
                CellData data = grid.Get(coords[0], coords[1]);

                if (data == null)
                {
                    data = new CellData();
                }
                data.Floor = floor;
                grid.Insert(data, coords[0], coords[1]);
            }
        }
        public void SetFloorAtGrid(CellData.FloorData floor, int gridX, int gridY)
        {
            int[] coords = grid.GridCoordinatesToPixels(gridX, gridY);

            SetFloorAt(floor, coords[0], coords[1]);
        }