0

I am trying to develop an app similar to paint app.

I want allow user to perform redo or undo operations over canvas. I searched a lot, but dint find any example that explains about redo and undo operations for Circle, Rectangle etc. most of the tutorials explain redo and undo for Line.

Any help will be appreciated.

Mohit
  • 505
  • 8
  • 31
  • Try to think as follows centralizes all of your operations (line, circle, square, etc.) through a stack, every time call undo put the action into another stack (redo) – rkmax Feb 23 '14 at 15:49
  • [HTML5 Canvas tutorial](http://www.codicode.com/art/undo_and_redo_to_the_html5_canvas.aspx) this is a example with a HTML5 canvas try to understand and apply to Android canvas. I have not worked with canvas in android – rkmax Feb 23 '14 at 15:55

1 Answers1

1

Store every operation in a list, then if you want to undo something just remove the last thing you put into the list. A linkedlist or a stack would work.

Pseudocode

Stack<Action> operations=new Stack<Action>();
Stack<Action> redos=new Stack<Action>();

Every time user have done something do

operations.push(new Action(actiontype,ccoordinates));

for undo

redoes.push(operations.pop());

to redo

operations.push(redos.pop());

and in your onDraw() method you draw everything thath is in operations...

Tomas
  • 156
  • 7