private void menuSprite_Resize_Click(object sender, EventArgs e) { Spriteset ss = ActiveSpriteset(); Sprite s = ActiveSprite(); if (s == null) { return; } ToolStripMenuItem mi = (sender as ToolStripMenuItem); string strTag = mi.Tag as string; if (strTag == null || strTag == "") { return; } string[] aSize = strTag.Split('x'); int tileWidth = Int32.Parse(aSize[0]); int tileHeight = Int32.Parse(aSize[1]); if (ss.ResizeSelectedSprite(tileWidth, tileHeight)) { s.RecordUndoAction("resize", ActiveUndo()); HandleSpriteDataChanged(ss); } }
private void pbPaletteSelect_MouseUp(object sender, MouseEventArgs e) { if (!m_fSubpaletteSelect_Selecting) { return; } m_fSubpaletteSelect_Selecting = false; // Record an undo action if the current palette selection has changed if (m_fSubpaletteSelect_OriginalSubpalette != m_palette.CurrentSubpaletteId) { Sprite s = m_parent.ActiveSprite(); s.RecordUndoAction("palette select", m_parent.ActiveUndo()); } }
private void menuSprite_Flip_Both_Click(object sender, EventArgs e) { Spriteset ss = ActiveSpriteset(); Sprite s = ActiveSprite(); if (s == null) { return; } if (!s.IsEmpty()) { s.Flip(true, true); s.RecordUndoAction("flipboth", ActiveUndo()); HandleSpriteDataChanged(ss); } }
private void menuSprite_Rotate_180_Click(object sender, EventArgs e) { Spriteset ss = ActiveSpriteset(); Sprite s = ActiveSprite(); if (s == null) { return; } if (!s.IsEmpty()) { if (ss.RotateSelectedSprite(Sprite.RotateDirection.Clockwise180)) { s.RecordUndoAction("rotate180", ActiveUndo()); HandleSpriteDataChanged(ss); } } }
private void pbSprite_MouseUp(object sender, MouseEventArgs e) { if (m_fEditSprite_Selecting) { Toolbox.ToolType tool = m_toolbox.CurrentToolType; // Close out the edit action. FinishEdit(tool); // Record the undo action. string strTool = ""; bool fRecordUndo = false; switch (tool) { //case Toolbox.ToolType.Select - no undo case Toolbox.ToolType.Pencil: strTool = "pencil"; fRecordUndo = true; break; //case Toolbox.ToolType.Eyedropper - no undo case Toolbox.ToolType.FloodFill: strTool = "bucket"; fRecordUndo = true; break; case Toolbox.ToolType.Eraser: strTool = "eraser"; break; } if (fRecordUndo) { Sprite s = m_ss.CurrentSprite; if (s != null) { s.RecordUndoAction(strTool, m_parent.ActiveUndo()); } } } m_fEditSprite_Selecting = false; }
public void Test_AddSprite_draw_redo() { Sprite s = m_ss.AddSprite(1, 1, "sample", 0, "", 0, m_mgr); Assert.IsNotNull(s); Assert.AreEqual(1, m_mgr.Count); Assert.AreEqual(0, m_mgr.Current); Assert.IsTrue(m_mgr.CanUndo()); Assert.IsFalse(m_mgr.CanRedo()); // Draw a pixel. int x1 = 3, y1 = 4; int color1 = 1; s.SetPixel(x1, y1, color1); Assert.AreEqual(color1, s.GetPixel(x1, y1)); s.RecordUndoAction("pencil1", m_mgr); Assert.AreEqual(2, m_mgr.Count); Assert.AreEqual(1, m_mgr.Current); UndoAction_SpriteEdit u1 = m_mgr.GetCurrent() as UndoAction_SpriteEdit; Assert.AreEqual(0, u1.Before.tiles[0].pixels[x1, y1]); Assert.AreEqual(color1, u1.After.tiles[0].pixels[x1, y1]); Assert.IsTrue(m_mgr.CanUndo()); Assert.IsFalse(m_mgr.CanRedo()); // Undo the pixel draw. m_mgr.ApplyUndo(); Assert.AreEqual(2, m_mgr.Count); Assert.AreEqual(0, m_mgr.Current); // Pencil mark reverted. Assert.AreEqual(0, s.GetPixel(x1, y1)); Assert.IsTrue(m_mgr.CanUndo()); Assert.IsTrue(m_mgr.CanRedo()); // Redo the pixel draw. m_mgr.ApplyRedo(); Assert.AreEqual(2, m_mgr.Count); Assert.AreEqual(1, m_mgr.Current); Assert.AreEqual(color1, s.GetPixel(x1, y1)); Assert.IsTrue(m_mgr.CanUndo()); Assert.IsFalse(m_mgr.CanRedo()); }
private void pbArrowbox_MouseDown(object sender, MouseEventArgs e) { if (m_arrowbox.HilightedShiftArrow() != Arrowbox.ShiftArrow.None) { m_arrowbox.SetMouseDownShiftArrow(true); pbArrowbox.Invalidate(); m_sprite.ShiftPixels(m_arrowbox.HilightedShiftArrow()); m_sprite.RecordUndoAction("shift", m_parent.ActiveUndo()); m_parent.HandleSpriteDataChanged(m_ss); return; } if (m_arrowbox.HandleMouseDown(e.X, e.Y)) { pbArrowbox.Invalidate(); } m_fArrowbox_Selecting = true; }
private void menuSprite_Clear_Click(object sender, EventArgs e) { Spriteset ss = ActiveSpriteset(); Sprite s = ActiveSprite(); if (s == null) { return; } if (!s.IsEmpty()) { //if (!AskYesNo("Are you sure you want to erase the data in the currently selected sprite?")) if (!AskYesNo(ResourceMgr.GetString("EraseCurrentSprite"))) { return; } s.Clear(); s.RecordUndoAction("clear", ActiveUndo()); HandleSpriteDataChanged(ss); } }
public void Test_AddSprite_draw_undo() { Sprite s = m_ss.AddSprite(1, 1, "sample", 0, "", 0, m_mgr); Assert.IsNotNull(s); Assert.AreEqual(1, m_mgr.Count); Assert.AreEqual(0, m_mgr.Current); Assert.IsTrue(m_mgr.CanUndo()); Assert.IsFalse(m_mgr.CanRedo()); // Draw a pixel. int x1 = 3, y1 = 4; int color1 = 1; s.SetPixel(x1, y1, color1); Assert.AreEqual(color1, s.GetPixel(x1, y1)); s.RecordUndoAction("pencil1", m_mgr); Assert.AreEqual(2, m_mgr.Count); Assert.AreEqual(1, m_mgr.Current); UndoAction_SpriteEdit u1 = m_mgr.GetCurrent() as UndoAction_SpriteEdit; Assert.AreEqual(0, u1.Before.tiles[0].pixels[x1, y1]); Assert.AreEqual(color1, u1.After.tiles[0].pixels[x1, y1]); Assert.IsTrue(m_mgr.CanUndo()); Assert.IsFalse(m_mgr.CanRedo()); // Draw another pixel. int x2 = 4, y2 = 5; int color2 = 2; s.SetPixel(x2, y2, color2); Assert.AreEqual(color2, s.GetPixel(x2, y2)); s.RecordUndoAction("pencil2", m_mgr); Assert.AreEqual(3, m_mgr.Count); Assert.AreEqual(2, m_mgr.Current); UndoAction_SpriteEdit u2 = m_mgr.GetCurrent() as UndoAction_SpriteEdit; Assert.AreEqual(0, u2.Before.tiles[0].pixels[x2, y2]); Assert.AreEqual(color2, u2.After.tiles[0].pixels[x2, y2]); Assert.IsTrue(m_mgr.CanUndo()); Assert.IsFalse(m_mgr.CanRedo()); // Undo the last pixel draw. m_mgr.ApplyUndo(); Assert.AreEqual(3, m_mgr.Count); Assert.AreEqual(1, m_mgr.Current); // Last pencil reverted. Assert.AreEqual(0, s.GetPixel(x2, y2)); // First pencil still present. Assert.AreEqual(color1, s.GetPixel(x1, y1)); Assert.IsTrue(m_mgr.CanUndo()); Assert.IsTrue(m_mgr.CanRedo()); // Undo the first pixel draw. m_mgr.ApplyUndo(); Assert.AreEqual(3, m_mgr.Count); Assert.AreEqual(0, m_mgr.Current); // Both pencil marks reverted. Assert.AreEqual(0, s.GetPixel(x1, y1)); Assert.AreEqual(0, s.GetPixel(x2, y2)); Assert.IsTrue(m_mgr.CanUndo()); Assert.IsTrue(m_mgr.CanRedo()); // Undo the sprite add. m_mgr.ApplyUndo(); Assert.AreEqual(3, m_mgr.Count); Assert.AreEqual(-1, m_mgr.Current); Assert.IsFalse(m_mgr.CanUndo()); Assert.IsTrue(m_mgr.CanRedo()); }