You're making a drawing program like Paint. You want to be able to undo/redo brush strokes. How would you implement this?
Optimize for speed and memory.
You're making a drawing program like Paint. You want to be able to undo/redo brush strokes. How would you implement this?
Optimize for speed and memory.
Create a backup copy of the canvas. Choose a rectangular patch that completely surrounds the brush stroke. Save the bitmap contained in that patch in both the new version and the backup. You can now blit these changes to undo or redo the stroke.
May use a lot of memory.
Use a quadtree to record the previous state of the part of the canvas that changed. On an undo, replace the canvas state from the quadtree.