/// <summary>
        /// Deletes the last stroke added to the overlay
        /// </summary>
        /// <param name="undoable">whether to add the deleted stroke
        /// to the undo stack. True = add, false = do not add.</param>
        internal void deleteLastStroke(bool undoable)
        {
            int count = basicOverlay.Ink.Strokes.Count;

            if (count == 1) // that one count IS the leftdown stroke
            {
                setFeedback("No stroke to be deleted");
            }
            else
            {
                setFeedback("Last stroke deleted");
                Ink inkClone = basicOverlay.Ink.Clone();                            // use for undo stroke
                basicOverlay.Ink.DeleteStroke(basicOverlay.Ink.Strokes[count - 2]); // delete the stroke before leftdown
                Panel.Invalidate();                                                 // invalidate the window to repaint it

                // if we want this stroke to be undone, add its information to the undo stack
                if (undoable)
                {
                    Strokes last      = inkClone.Strokes;
                    int     numStroke = last.Count;
                    for (int i = 0; i < numStroke - 2; i++)
                    {
                        last.RemoveAt(0); // remove everything except the last stroke, which is what we want
                    }

                    last.RemoveAt(1); // remove the gesture that triggered this
                    undoStack.Push("");
                    undoStack.Push("");
                    undoStack.Push(last); // should only contain the last stroke now
                    undoStack.Push("DeleteLastStroke");
                }
            }
        }//deleteLastStroke
        /// <summary>
        /// Redo image edits that were undone
        /// </summary>
        internal void Redo()
        {
            int index = redoActions.Count - 1;

            if (index < 0)
            {
                return;
            }
            if (redoActions[index] == InkCanvasEditingMode.Ink)
            {
                Strokes.Add(redoStrokes[index]);
            }
            else if (redoActions[index] == InkCanvasEditingMode.EraseByStroke)
            {
                Strokes.RemoveAt(Strokes.Count - 1);
            }
            else if (redoActions[index] == InkCanvasEditingMode.None)
            {
                Strokes.Clear();
            }
            undoActions.Add(redoActions[index]);
            undoStrokes.Add(redoStrokes[index]);
            redoActions.RemoveAt(index);
            redoStrokes.RemoveAt(index);
        }
Example #3
0
        private void UndoButton_Click(object sender, RoutedEventArgs e)
        {
            if (Strokes == null || Strokes.Count == 0)
            {
                return;
            }

            UndoneStrokes.Add(Strokes.ElementAt(Strokes.Count - 1));
            Strokes.RemoveAt(Strokes.Count - 1);
        }
Example #4
0
        private void buttonUndo_Click(object sender, RoutedEventArgs e)
        {
            ptinfos.Clear();             // REM 清除一笔中所有点
            CreateNewBitmap();

            if ((geos.Count > 0))
            {
                strokes.RemoveAt(strokes.Count - 1);           // REM 清除上一笔

                geos.RemoveAt(geos.Count - 1);                 // REM 清除上一笔
                DrawingContext dc = dv.RenderOpen();
                foreach (var g in geos)
                {
                    GeometryDrawing drawing = new GeometryDrawing(Brushes.Black, new Pen(Brushes.Black, 1), g);
                    dc.DrawDrawing(drawing);
                }
                dc.Close();
                bmp.Render(dv);
            }
        }
        /// <summary>
        /// Undo edit actions performed
        /// </summary>
        internal void Undo()
        {
            int index = undoActions.Count - 1;

            if (index < 0)
            {
                return;
            }
            if (undoActions[index] == InkCanvasEditingMode.Ink)
            {
                Strokes.RemoveAt(Strokes.Count - 1);
            }
            else if (undoActions[index] == InkCanvasEditingMode.EraseByStroke)
            {
                Strokes.Add(undoStrokes[index]);
            }
            else if (undoActions[index] == InkCanvasEditingMode.None)
            {
                for (int i = 0; i < index; i++)
                {
                    if (undoActions[i] == InkCanvasEditingMode.Ink)
                    {
                        Strokes.Add(undoStrokes[i]);
                    }
                    else if (undoActions[i] == InkCanvasEditingMode.EraseByStroke)
                    {
                        Strokes.Remove(undoStrokes[i]);
                    }
                    else if (undoActions[i] == InkCanvasEditingMode.None)
                    {
                        Strokes.Clear();
                    }
                }
            }
            redoActions.Add(undoActions[index]);
            redoStrokes.Add(undoStrokes[index]);
            undoActions.RemoveAt(index);
            undoStrokes.RemoveAt(index);
        }