Пример #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();
        }
Пример #2
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();
        }