April 26, 2024, 12:23:48 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Creating an Undo System

Started by kryton9, September 20, 2006, 07:11:34 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

kryton9

September 20, 2006, 07:11:34 PM Last Edit: September 20, 2006, 07:15:19 PM by kryton9
How does one go about implementing an Undo? It must be different depending on what you are doing, so let's just use a difficult one, a paint program.

You can paint and fill and then undo multiple times... does that mean some sort of CList of buffers the size of the picture is being used. So each new thing the user does is a new item in the CList?

Or do you just store the state of all variables and steps the users takes in a script in a similar manner some sort of structure of in CList and then replay all the steps in the CList to recreate to the point of the undo?

Ionic Wind Support Team

A paint program stores each operation (stroke, fill, line, etc.) into an object or structure and maintains them in at least one list.  Programs  like photoshop would have dozens of such lists of objects for managing layers and overlays.

The lists are used as a common mechanism.  When drawing on the screen the list is iterated and each object drawn in turn.  When output to a printer scaling can be applied to each object before it is sent to account for paper sizes.

An undo mechanism would remove the last added object from the list and place it into the redo list.  Many programs limit the number of undo levels to a fixed size so arrays can be used instead of a linked list.  It also saves on memory since the maximum number of objects stored in the undo list is a fixed size.  Using arrays is only slightly more difficult than using a list when creating an undo mechanism. 

Ionic Wind Support Team

Parker

See http://www.catch22.net/tuts/editor17.asp
It's a good approach, but maybe a bit difficult to grasp.

kryton9

Thanks for the replies.

I think what throws me, is now that I've have been using Macs and Windows systems with GUI's well since around 1986 with a mac and early to mid 90's with windows, it just seems like there are real objects and that things work differently, but when you look, it is all just incredible it all comes down to just basic coding and providing a good illusion. It is like the movie The Matrix in a way... a nice illusion but in reality it is something else.

I guess you just have to think how can it be done, there is no shortcut or whatever color pill it would be in the movie to take to make it happen :)

Ionic Wind Support Team

You can use real objects of course, or just linked lists and structures (udt's).

While you may not be real versed in OOP yet search for a Microsoft example called "Scribble" which goes through the steps of creating a paint like program with undo/redo and uses objects to store all editing.

Ionic Wind Support Team

kryton9

Thanks, will look into it. It does make sense.