Пример #1
0
        public void Redo(int numberOfRedo = 1)
        {
            for (int i = 0; i < numberOfRedo; i++)
            {
                if (RedoBuffer.Count == 0)
                {
                    return;
                }

                var last = RedoBuffer.OrderByDescending(kvp => kvp.Key).Last();
                RedoBuffer.Remove(last.Key);

                var level        = last.Value.Level;
                var undoRecorder = new UndoRecorder(level, false);
                var editSession  = new EditHelper(level, undoRecorder: undoRecorder);

                // Redo
                var restore = last.Value.Postsnapshot;
                foreach (Block block in restore)
                {
                    editSession.SetBlock(block);
                }

                var history = undoRecorder.CreateHistory();
                AddHistory(history, true);
            }
        }
Пример #2
0
 public void AddCommand(RipCommand command, IList <Rectangle> updates = null, bool direct = false)
 {
     if (this.Client != null && !direct)
     {
         if (sendCommands == null)
         {
             sendCommands = new Messages.SendCommands(this);
         }
         //Console.WriteLine ("Prepping command {0}", command);
         sendCommands.Commands.Add(command);
     }
     else
     {
         if (command is RipOptionalCommand && !RipDocument.OptionalApplied.Contains(command.OpCode))
         {
             RipDocument.OptionalApplied.Add(command.OpCode);
         }
         //Console.WriteLine ("Adding command {0}", command);
         command.Apply(updates);
         RipDocument.Commands.Add(command);
         RipDocument.IsModified = true;
         if (!direct)
         {
             RedoBuffer.Clear();
         }
     }
 }
Пример #3
0
 public void MakeHistory(string id = "")
 {
     if (!TrackChanges)
     {
         return;
     }
     if (id == null)
     {
         id = "";
     }
     if (id == "" || id != lastid)
     {
         UndoBuffer.AddLast(Model.Clone());
         RedoBuffer.Clear();
         if (UndoBuffer.Count > 100)
         {
             UndoBuffer.RemoveFirst();
         }
         UnsavedChanges++;
         Device.BeginInvokeOnMainThread(() =>
         {
             Save.ChangeCanExecute();
             Undo.ChangeCanExecute();
             Redo.ChangeCanExecute();
         });
     }
     lastid = id;
 }
Пример #4
0
        /// <summary>
        /// Switches to the previous <see cref="SimisTreeNode"/>/<see cref="SimisAce"/> root.
        /// </summary>
        public void Undo()
        {
            RedoBuffer.Push(new SimisFileState(base.Tree, base.Ace));
            var state = UndoBuffer.Pop();

            base.Tree = state.Tree;
            base.Ace  = state.Ace;
        }
Пример #5
0
        public void AddHistory(HistoryEntry history, bool keepRedoBuffer = false)
        {
            long time = DateTime.UtcNow.Ticks;

            History.Add(time, history);
            if (!keepRedoBuffer)
            {
                RedoBuffer.Clear();
            }
        }
Пример #6
0
        private void pictureBox_MouseMove(object sender, MouseEventArgs e)
        {
            PictureBox picture = sender as PictureBox;

            if (!(picture).ClientRectangle.Contains(e.Location))
            {
                return;
            }

            bool isImage         = picture == pictureBox1;
            int  imageDimensions = isImage ? 8 : 5;
            int  x     = (e.X - picture.AutoScrollOffset.X) / imageDimensions;
            int  y     = (e.Y - picture.AutoScrollOffset.Y) / imageDimensions;
            int  xy    = y * (isImage ? 32 : 16) + x;
            byte color = isImage ? Image[xy] : (byte)xy;

            if (e.Button != MouseButtons.None)
            {
                if (!ReplaceColorButton.Checked || ModifierKeys == Keys.Control || !isImage)
                {
                    if ((ModifierKeys == Keys.Control && EditingImage) || !isImage) //eyedropper
                    {
                        if (e.Button == MouseButtons.Left)
                        {
                            PrimaryColor = color;
                        }
                        else
                        {
                            SecondaryColor = color;
                        }
                    }
                    else
                    {
                        byte colorToDraw = (e.Button == MouseButtons.Left) ? PrimaryColor : SecondaryColor;
                        if (color != colorToDraw) //otherwise there's no point in doing anything
                        {
                            RedoBuffer.Clear();
                            var PixelsBeingChanged = new List <ChangedPixel>();
                            if (FillButton.Checked)
                            {
                                Fill(new Point(x, y), colorToDraw, color, PixelsBeingChanged);
                            }
                            else
                            {
                                PixelsBeingChanged.Add(new ChangedPixel(Image[xy], xy));
                                Image[xy] = colorToDraw;
                                DrawColor(x, y);
                            }
                            UndoBuffer.Push(PixelsBeingChanged);
                        }
                    }
                }
            }
            Text = FormTitle + " \u2013 " + color;
        }
Пример #7
0
        void MakeEntireImageUndoable()
        {
            RedoBuffer.Clear();
            var PixelsBeingChanged = new List <ChangedPixel>();

            for (int i = 0; i < 32 * 32; ++i)
            {
                PixelsBeingChanged.Add(new ChangedPixel(Image[i], i));
            }
            UndoBuffer.Push(PixelsBeingChanged);
        }
Пример #8
0
        private void ReplaceColor(byte dst, byte src)
        {
            RedoBuffer.Clear();
            var PixelsBeingChanged = new List <ChangedPixel>();

            for (int i = 0; i < 32 * 32; ++i)
            {
                if (Image[i] == src)
                {
                    PixelsBeingChanged.Add(new ChangedPixel(Image[i], i));
                    Image[i] = dst;
                    DrawColor(i & 31, i >> 5);
                }
            }
            UndoBuffer.Push(PixelsBeingChanged);
        }
Пример #9
0
        public void Undo(int numberOfUndo = 1)
        {
            for (int i = 0; i < numberOfUndo; i++)
            {
                if (History.Count == 0)
                {
                    return;
                }

                var last = History.OrderBy(kvp => kvp.Key).Last();
                History.Remove(last.Key);
                RedoBuffer.Add(last.Key, last.Value);

                // Undo
                HistoryEntry historyEntry = last.Value;
                var          restore      = historyEntry.Presnapshot;
                foreach (Block block in restore)
                {
                    historyEntry.Level.SetBlock(block);
                }
            }
        }
Пример #10
0
 public void ClearHistory()
 {
     History.Clear();
     RedoBuffer.Clear();
 }
Пример #11
0
 void ResetUndo()
 {
     UndoBuffer.Clear();
     RedoBuffer.Clear();
 }