Ejemplo n.º 1
0
        public void RecordUndoAction(string strDesc, UndoMgr undo)
        {
            if (undo == null)
            {
                return;
            }

            UndoData data = GetUndoData();

            // Don't record anything if there aren't any changes
            if (!data.Equals(m_snapshot))
            {
                UndoAction_SpriteEdit action = new UndoAction_SpriteEdit(undo, m_ss, this, m_snapshot, data, strDesc);
                undo.Push(action);

                // Update the snapshot for the next UndoAction
                RecordSnapshot();
            }
        }
Ejemplo n.º 2
0
        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());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Scan backwards in the undo stack for the most recently edited sprite.
        /// This is used to select a sprite when the current one is deleted.
        /// </summary>
        /// <returns>The most recent Sprite, or null if a suitable Sprite cannot be found.</returns>
        public Sprite FindMostRecentSprite()
        {
            for (int i = m_nCurrent - 1; i >= 0; i--)
            {
                // Use sprite from most recent edit.
                UndoAction_SpriteEdit action_edit = m_history[i] as UndoAction_SpriteEdit;
                if (action_edit != null)
                {
                    return(action_edit.GetSprite);
                }

                // Use sprite from most recent Add (not Delete, since the sprite doesn't exist anymore).
                UndoAction_AddSprite action_add = m_history[i] as UndoAction_AddSprite;
                if (action_add != null && action_add.Add)
                {
                    return(action_add.GetSprite);
                }
            }
            return(null);
        }
Ejemplo n.º 4
0
        public void RecordUndoAction(string strDesc, UndoMgr undo)
        {
            if (undo == null)
                return;

            UndoData data = GetUndoData();

            // Don't record anything if there aren't any changes
            if (!data.Equals(m_snapshot))
            {
                UndoAction_SpriteEdit action = new UndoAction_SpriteEdit(undo, m_ss, this, m_snapshot, data, strDesc);
                undo.Push(action);

                // Update the snapshot for the next UndoAction
                RecordSnapshot();
            }
        }
Ejemplo n.º 5
0
        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());
        }