문제

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.

도움이 되었습니까?

해결책

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...

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top