コード例 #1
0
ファイル: UndoMgr.cs プロジェクト: nnn1590/spritely
        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());
        }
コード例 #2
0
 private void DrawSampleSprite(Sprite s, int width, int height, int[,] data)
 {
     for (int y = 0; y < height; y++)
     {
         for (int x = 0; x < width; x++)
         {
             s.SetPixel(x, y, data[y, x]);
         }
     }
 }
コード例 #3
0
ファイル: UndoMgr.cs プロジェクト: nnn1590/spritely
        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());
        }