/// <summary> /// Get a region of tiles from a layer /// </summary> /// <param name="region"> Tile region </param> /// <param name="layer"> Layer in context </param> /// <returns> A region based from zero extracted from the layer </returns> public WorldRegion GetLayerRegion(Rectangle region, int layer) { WorldLayer layerIn = GetLayer(layer); WorldRegion regionOut = new WorldRegion(region.Width, region.Height); for (int x = region.X, ox = 0; x < region.Right; x++, ox++) { for (int y = region.Y, oy = 0; y < region.Bottom; y++, oy++) { if (!PointInWorld(x, y)) { regionOut[ox, oy] = null; continue; } WorldTile i = layerIn[x, y]; regionOut[ox, oy] = i == null ? null : i.Clone(); } } return regionOut; }
/// <summary> /// Deletes all tiles in the selection rectangle /// </summary> public void DeleteSelection() { WorldRegion undoRegion = GetLayerRegion(selectionRectangle, SelectedLayer), redoRegion = new WorldRegion(selectionRectangle.Width, selectionRectangle.Height); for (int x = selectionRectangle.X; x < selectionRectangle.Right; x++) { for (int y = selectionRectangle.Y; y < selectionRectangle.Bottom; y++) { if (!PointInWorld(x, y)) continue; SetTile(x, y, null, SelectedLayer); } } History.Add(new HistoryItem(new TileChangesRegion(undoRegion, selectionRectangle.Location, SelectedLayer), new TileChangesRegion(redoRegion, selectionRectangle.Location, SelectedLayer), applyDeletionChanges)); SelectionRectangle = Rectangle.Empty; worldCanvas.Invalidate(); }