public void Redo(object sender, EventArgs e) { if (RActions.Count == 0) { return; } TilemapUndoEntry item = RActions.Pop(); item.Redo(t.tiles); item.reRender(t); UActions.Push(item); redobutton.Enabled = RActions.Count > 0; undobutton.Enabled = true; pictureBox1.Invalidate(true); }
private void pictureBox1_MouseUp(object sender, MouseEventArgs e) { if (down) { if (selTileWidth == 1 && selTileHeight == 1) { getDefaultSize(); selTileWidth = defaultWidth; selTileHeight = defaultHeight; } //Prep for the undo buffer if it isn't a copy action TilemapUndoEntry undoitem = null; if (mode != EditionMode.COPY) { undobutton.Enabled = true; redobutton.Enabled = false; RActions.Clear(); undoitem = new TilemapUndoEntry(t.tiles, selTileX, selTileY, selTileWidth, selTileHeight); UActions.Push(undoitem); } switch (mode) { case EditionMode.DRAW: for (int x = 0; x < selTileWidth; x++) for (int y = 0; y < selTileHeight; y++) { int tnum = picker.selTileNum; tnum += x % picker.selTileWidth; tnum += (y % picker.selTileHeight) * picker.bufferWidth; if (x + selTileX >= t.width) continue; if (y + selTileY >= t.height) continue; t.tiles[x + selTileX, y + selTileY].tileNum = tnum; t.tiles[x + selTileX, y + selTileY].palNum = picker.selTilePal; t.tiles[x + selTileX, y + selTileY].hflip = false; t.tiles[x + selTileX, y + selTileY].vflip = false; } break; case EditionMode.XFLIP: for (int x = 0; x < selTileWidth / 2; x++) for (int y = 0; y < selTileHeight; y++) { int x1 = x + selTileX; int x2 = selTileX + selTileWidth - x - 1; int yy = y + selTileY; Tilemap.Tile tmp = t.tiles[x1, yy]; t.tiles[x1, yy] = t.tiles[x2, yy]; t.tiles[x2, yy] = tmp; } for (int x = 0; x < selTileWidth; x++) for (int y = 0; y < selTileHeight; y++) t.tiles[x + selTileX, y + selTileY].hflip = !t.tiles[x + selTileX, y + selTileY].hflip; break; case EditionMode.YFLIP: for (int x = 0; x < selTileWidth; x++) for (int y = 0; y < selTileHeight / 2; y++) { int y1 = y + selTileY; int y2 = selTileY + selTileHeight - y - 1; int xx = x + selTileX; Tilemap.Tile tmp = t.tiles[xx, y1]; t.tiles[xx, y1] = t.tiles[xx, y2]; t.tiles[xx, y2] = tmp; } for (int x = 0; x < selTileWidth; x++) for (int y = 0; y < selTileHeight; y++) t.tiles[x + selTileX, y + selTileY].vflip = !t.tiles[x + selTileX, y + selTileY].vflip; break; case EditionMode.COPY: clipboard = new Tilemap.Tile[selTileWidth, selTileHeight]; clipboardWidth = selTileWidth; clipboardHeight = selTileHeight; for (int x = 0; x < selTileWidth; x++) for (int y = 0; y < selTileHeight; y++) clipboard[x, y] = t.tiles[x + selTileX, y + selTileY]; break; case EditionMode.PASTE: if(clipboard == null) break; for (int x = 0; x < selTileWidth; x++) for (int y = 0; y < selTileHeight; y++) t.tiles[x + selTileX, y + selTileY] = clipboard[x % clipboardWidth, y % clipboardHeight]; break; case EditionMode.CHANGEPAL: for (int x = 0; x < selTileWidth; x++) for (int y = 0; y < selTileHeight; y++) { t.tiles[x + selTileX, y + selTileY].palNum++; t.tiles[x + selTileX, y + selTileY].palNum %= t.palettes.Length; } break; } t.reRender(selTileX, selTileY, selTileWidth, selTileHeight); pictureBox1.Invalidate(true); if (mode != EditionMode.COPY) undoitem.LoadNewTiles(t.tiles); //Save the new tiles into the undo history } down = false; }
private void pictureBox1_MouseUp(object sender, MouseEventArgs e) { if (down) { if (selTileWidth == 1 && selTileHeight == 1) { getDefaultSize(); selTileWidth = defaultWidth; selTileHeight = defaultHeight; } //Prep for the undo buffer if it isn't a copy action TilemapUndoEntry undoitem = null; if (mode != EditionMode.COPY) { undobutton.Enabled = true; redobutton.Enabled = false; RActions.Clear(); undoitem = new TilemapUndoEntry(t.tiles, selTileX, selTileY, selTileWidth, selTileHeight); UActions.Push(undoitem); } switch (mode) { case EditionMode.DRAW: for (int x = 0; x < selTileWidth; x++) { for (int y = 0; y < selTileHeight; y++) { int tnum = picker.selTileNum; tnum += x % picker.selTileWidth; tnum += (y % picker.selTileHeight) * picker.bufferWidth; if (x + selTileX >= t.width) { continue; } if (y + selTileY >= t.height) { continue; } t.tiles[x + selTileX, y + selTileY].tileNum = tnum; t.tiles[x + selTileX, y + selTileY].palNum = picker.selTilePal; t.tiles[x + selTileX, y + selTileY].hflip = false; t.tiles[x + selTileX, y + selTileY].vflip = false; } } break; case EditionMode.XFLIP: for (int x = 0; x < selTileWidth / 2; x++) { for (int y = 0; y < selTileHeight; y++) { int x1 = x + selTileX; int x2 = selTileX + selTileWidth - x - 1; int yy = y + selTileY; Tilemap.Tile tmp = t.tiles[x1, yy]; t.tiles[x1, yy] = t.tiles[x2, yy]; t.tiles[x2, yy] = tmp; } } for (int x = 0; x < selTileWidth; x++) { for (int y = 0; y < selTileHeight; y++) { t.tiles[x + selTileX, y + selTileY].hflip = !t.tiles[x + selTileX, y + selTileY].hflip; } } break; case EditionMode.YFLIP: for (int x = 0; x < selTileWidth; x++) { for (int y = 0; y < selTileHeight / 2; y++) { int y1 = y + selTileY; int y2 = selTileY + selTileHeight - y - 1; int xx = x + selTileX; Tilemap.Tile tmp = t.tiles[xx, y1]; t.tiles[xx, y1] = t.tiles[xx, y2]; t.tiles[xx, y2] = tmp; } } for (int x = 0; x < selTileWidth; x++) { for (int y = 0; y < selTileHeight; y++) { t.tiles[x + selTileX, y + selTileY].vflip = !t.tiles[x + selTileX, y + selTileY].vflip; } } break; case EditionMode.COPY: clipboard = new Tilemap.Tile[selTileWidth, selTileHeight]; clipboardWidth = selTileWidth; clipboardHeight = selTileHeight; for (int x = 0; x < selTileWidth; x++) { for (int y = 0; y < selTileHeight; y++) { clipboard[x, y] = t.tiles[x + selTileX, y + selTileY]; } } break; case EditionMode.PASTE: if (clipboard == null) { break; } for (int x = 0; x < selTileWidth; x++) { for (int y = 0; y < selTileHeight; y++) { t.tiles[x + selTileX, y + selTileY] = clipboard[x % clipboardWidth, y % clipboardHeight]; } } break; case EditionMode.CHANGEPAL: for (int x = 0; x < selTileWidth; x++) { for (int y = 0; y < selTileHeight; y++) { t.tiles[x + selTileX, y + selTileY].palNum++; t.tiles[x + selTileX, y + selTileY].palNum %= t.palettes.Length; } } break; } t.reRender(selTileX, selTileY, selTileWidth, selTileHeight); pictureBox1.Invalidate(true); if (mode != EditionMode.COPY) { undoitem.LoadNewTiles(t.tiles); //Save the new tiles into the undo history } } down = false; }