Re: How to realize the undo function in a sketchbook application?



On Wed, 2003-05-14 at 02:55, hamb ka wrote:
Hi, all

I am now writing a sketchbook application, and by using multiple GdkPixmaps 
I want to implement the Redo and Undo functions. It is simple to record down 
every stroke a user made, but if the strokes are overlapping each other, the 
later pixmaps would cover the previous one. And since there is no 
transparent color in gtk+, the option of changing color in graphics contexts 
is not viable.
Please give me a suggestion on it...
Thanks :)

Well, very briefly, each time the user makes a stroke, you want to save
what was underneath the strokes.

The undo operation consists of swapping the pixels in the undo stack
with the pixels in the canvas and to redo you just swap back (You keep
track of where you are in the undo stack currently.) 

There's a lot of details here that I haven't covered; you might want
to look at some existing code.

For one example, look at gsumi:

 http://www.gtk.org/~otaylor/gtk/gsumi/

but there's some complexity there because gsumi doesn't use pixmaps to
store the image data. Still, it may be useful in seeing how to manage
an undo stack.

There are certainly plenty of examples around as well.

Regards,
                                        Owen





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]