private void Flip(FlipType flipType) { if (DraggedTiles != null) { Defloat(DraggedTiles); } if (overlay.SelectTS.Empty) { return; } int x_ = overlay.SelectTS.Location.X / 16; int y_ = overlay.SelectTS.Location.Y / 16; CopyBuffer buffer = new CopyBuffer(overlay.SelectTS.Width, overlay.SelectTS.Height); Tile[] copiedTiles = new Tile[(overlay.SelectTS.Width / 16) * (overlay.SelectTS.Height / 16)]; for (int y = 0; y < overlay.SelectTS.Height / 16; y++) { for (int x = 0; x < overlay.SelectTS.Width / 16; x++) { copiedTiles[y * (overlay.SelectTS.Width / 16) + x] = Tileset.Tilesets_tiles[Layer][(y + y_) * 16 + x + x_].Copy(); } } if (flipType == FlipType.Horizontal) { Do.FlipHorizontal(copiedTiles, overlay.SelectTS.Width / 16, overlay.SelectTS.Height / 16); } else if (flipType == FlipType.Vertical) { Do.FlipVertical(copiedTiles, overlay.SelectTS.Width / 16, overlay.SelectTS.Height / 16); } buffer.Tiles = copiedTiles; Defloat(buffer); }
private void Copy() { if (overlay.SelectTS.Empty) { return; } if (DraggedTiles != null) { this.copiedTiles = DraggedTiles; return; } // make the copy int x_ = overlay.SelectTS.Location.X / 16; int y_ = overlay.SelectTS.Location.Y / 16; this.copiedTiles = new CopyBuffer(overlay.SelectTS.Width, overlay.SelectTS.Height); Tile[] copiedTiles = new Tile[(overlay.SelectTS.Width / 16) * (overlay.SelectTS.Height / 16)]; for (int y = 0; y < overlay.SelectTS.Height / 16; y++) { for (int x = 0; x < overlay.SelectTS.Width / 16; x++) { copiedTiles[y * (overlay.SelectTS.Width / 16) + x] = Tileset.Tilesets_tiles[Layer][(y + y_) * 16 + x + x_].Copy(); } } this.copiedTiles.Tiles = copiedTiles; }
private void picture_MouseDown(object sender, MouseEventArgs e) { if (e.Clicks > 1) { return; } if (e.Button == MouseButtons.Right) { return; } mouseDownObject = MapObject.None; this.ownerForm.Layer = this.Layer; // set a floor and ceiling for the coordinates int x = Math.Max(0, Math.Min(e.X, Picture.Width)); int y = Math.Max(0, Math.Min(e.Y, Picture.Height)); Picture.Focus(); // if moving an object and outside of it, paste it if (moving && mouseOverObject != MapObject.Selection) { // if copied tiles were pasted and not dragging a non-copied selection if (copiedTiles != null && DraggedTiles == null) { Defloat(copiedTiles); } if (DraggedTiles != null) { Defloat(DraggedTiles); DraggedTiles = null; } selection = null; moving = false; } // if making a new selection if (e.Button == MouseButtons.Left && mouseOverObject == MapObject.None) { overlay.SelectTS.Reload(16, x / 16 * 16, y / 16 * 16, 16, 16, Picture); } // if moving a current selection if (!lockEditing.Checked && e.Button == MouseButtons.Left && mouseOverObject == MapObject.Selection) { mouseDownObject = MapObject.Selection; mouseDownPosition = overlay.SelectTS.MousePosition(x, y); if (!moving) // only do this if the current selection has not been initially moved { moving = true; Drag(); } } mouseDownTile = y / 16 * 16 + (x / 16); LoadTileEditor(); }
private void Paste(Point area, CopyBuffer buffer) { if (buffer == null) { return; } moving = true; // now dragging a new selection DraggedTiles = buffer; selection = buffer.GetImage(); overlay.SelectTS.Set(16, area, buffer.Size, Picture); this.Picture.Invalidate(); }
/// <summary> /// "Cements" either a dragged selection or a newly pasted selection. /// </summary> /// <param name="buffer">The dragged selection or the newly pasted selection.</param> public void Defloat(CopyBuffer buffer) { if (buffer == null) { return; } if (overlay.SelectTS.Empty) { return; } selection = null; int x_ = overlay.SelectTS.X / 16; int y_ = overlay.SelectTS.Y / 16; for (int y = 0; y < buffer.Height / 16; y++) { for (int x = 0; x < buffer.Width / 16; x++) { if (y + y_ < 0 || y + y_ >= Tileset.Height || x + x_ < 0 || x + x_ >= 16) { continue; } int index = (y + y_) * 16 + x + x_; Tile tile = buffer.Tiles[y * (buffer.Width / 16) + x]; Tileset.Tilesets_tiles[Layer][index] = tile.Copy(); Tileset.Tilesets_tiles[Layer][index].Index = index; } } Tileset.ParseTileset(Tileset.Tilesets_tiles[Layer], Tileset.Tilesets_bytes[Layer]); Tileset.WriteToModel(16, Layer); SetTilesetImage(); if (autoUpdate.Checked) { updater.UpdateTileset(); } }
/// <summary> /// Start dragging a selection. /// </summary> private void Drag() { if (overlay.SelectTS.Empty) { return; } // make the copy int x_ = overlay.SelectTS.Location.X / 16; int y_ = overlay.SelectTS.Location.Y / 16; this.DraggedTiles = new CopyBuffer(overlay.SelectTS.Width, overlay.SelectTS.Height); Tile[] draggedTiles = new Tile[(overlay.SelectTS.Width / 16) * (overlay.SelectTS.Height / 16)]; for (int y = 0; y < overlay.SelectTS.Height / 16; y++) { for (int x = 0; x < overlay.SelectTS.Width / 16; x++) { draggedTiles[y * (overlay.SelectTS.Width / 16) + x] = Tileset.Tilesets_tiles[Layer][(y + y_) * 16 + x + x_].Copy(); } } this.DraggedTiles.Tiles = draggedTiles; selection = new Bitmap(this.DraggedTiles.GetImage()); Delete(); }