Nick Retallack
Nick Retallack

Reputation: 19571

How would you implement Undo in a raster drawing program?

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.

Upvotes: 3

Views: 626

Answers (2)

Ira Baxter
Ira Baxter

Reputation: 95392

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.

Upvotes: 2

Nick Retallack
Nick Retallack

Reputation: 19571

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.

Upvotes: 0

Related Questions