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

            PaletteColorData            data   = GetUndoData();
            UndoAction_Subpalette16Edit action = new UndoAction_Subpalette16Edit(undo, this, m_snapshot, data, strDesc);
            bool fHandled = false;

            if (action.IsSelectionChange())
            {
                // Ignore selection changes
                fHandled = true;
            }
            else
            {
                // If the last undo action is also a PaletteEdit, try to merge them together
                UndoAction_Subpalette16Edit last_action = undo.GetCurrent() as UndoAction_Subpalette16Edit;
                if (last_action != null)
                {
                    // Merge 2 color changes (as long as they edit the same color)
                    int last_color, last_color_val1, last_color_val2;
                    int this_color, this_color_val1, this_color_val2;
                    if (last_action.IsColorChange(out last_color, out last_color_val1, out last_color_val2) &&
                        action.IsColorChange(out this_color, out this_color_val1, out this_color_val2)
                        )
                    {
                        if (last_color == this_color)
                        {
                            // If this color change takes it back to the original value, then
                            // delete the UndoAction.
                            if (last_color_val1 == this_color_val2)
                            {
                                undo.DeleteCurrent();
                            }
                            else
                            {
                                last_action.UpdateRedoData(data);
                            }
                            fHandled = true;
                        }
                    }
                }
            }
            if (!fHandled)
            {
                undo.Push(action);
            }

            // Update the snapshot for the next UndoAction
            RecordSnapshot();
        }
Esempio n. 2
0
        public void Test_AddSprite_draw()
        {
            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]);
        }
Esempio n. 3
0
        public void RecordUndoAction(string strDesc, UndoMgr undo)
        {
            if (undo == null)
                return;

            PaletteColorData data = GetUndoData();
            UndoAction_Subpalette16Edit action = new UndoAction_Subpalette16Edit(undo, this, m_snapshot, data, strDesc);
            bool fHandled = false;

            if (action.IsSelectionChange())
            {
                // Ignore selection changes
                fHandled = true;
            }
            else
            {
                // If the last undo action is also a PaletteEdit, try to merge them together
                UndoAction_Subpalette16Edit last_action = undo.GetCurrent() as UndoAction_Subpalette16Edit;
                if (last_action != null)
                {
                    // Merge 2 color changes (as long as they edit the same color)
                    int last_color, last_color_val1, last_color_val2;
                    int this_color, this_color_val1, this_color_val2;
                    if (last_action.IsColorChange(out last_color, out last_color_val1, out last_color_val2)
                        && action.IsColorChange(out this_color, out this_color_val1, out this_color_val2)
                        )
                    {
                        if (last_color == this_color)
                        {
                            // If this color change takes it back to the original value, then
                            // delete the UndoAction.
                            if (last_color_val1 == this_color_val2)
                                undo.DeleteCurrent();
                            else
                                last_action.UpdateRedoData(data);
                            fHandled = true;
                        }
                    }
                }
            }
            if (!fHandled)
                undo.Push(action);

            // Update the snapshot for the next UndoAction
            RecordSnapshot();
        }