public void RollbackEdit()
 {
     _actionsRecord = false;
     _currentAction.Undo();
     _currentAction = null;
     _actionsRecord = true;
 }
        public void DrawPixel(int frame, int x, int y, byte color)
        {
            if (x < 0 || x >= _sprite[frame].Width || y < 0 || y >= _sprite[frame].Height)
            {
                return;
            }
            if (_sprite[frame][x, y] == color)
            {
                return;
            }

            if (_actionsRecord)
            {
                if (!(_currentAction is PaintAction))
                {
                    CommitEdit();
                    _currentAction = new PaintAction(this);
                }

                PaintAction action = (PaintAction)_currentAction;
                action.DrawPixel(frame, x, y, _sprite[frame][x, y], color);
            }

            _sprite[frame][x, y] = color;
            if (frame == _currentFrame)
            {
                _bmp.SetPixel(x, y, _palette[color]);
                InvalidatePixel(x, y);
            }
        }
 public void CommitEdit()
 {
     if (_currentAction != null)
     {
         _undoStack.Add(_currentAction);
         while (_undoStack.Count > UndoStackLength)
         {
             _undoStack.RemoveAt(0);
         }
         _redoStack.Clear();
         _currentAction = null;
     }
 }
        public void Redo()
        {
            if (_redoStack.Count > 0)
            {
                EditAction action = _redoStack[_redoStack.Count - 1];

                _actionsRecord = false;
                action.Redo();
                _actionsRecord = true;

                _redoStack.Remove(action);
                _undoStack.Add(action);
            }
        }
        public void Undo()
        {
            if (_currentAction != null)
            {
                _currentAction.Undo();
            }
            else if (_undoStack.Count > 0)
            {
                EditAction action = _undoStack[_undoStack.Count - 1];

                _actionsRecord = false;
                action.Undo();
                _actionsRecord = true;

                _undoStack.Remove(action);
                _redoStack.Add(action);
            }
        }