[cairo] How can I implement "undo" and "redo" in Cairo application?

Dimiter 'malkia' Stanev malkia at gmail.com
Tue Sep 4 21:26:35 PDT 2012


	In a text editor, every time you do an operation you can store an
opposite one that does the undo, and then call it to make the undo
operation. This is especially easy if your language supports closures,
otherwise you have to implement the so called command "pattern" from GoF.

	But in something like cairo, where there are no reversible operations
it would make sense to keep stack of all operations that were executed,
and then replay all of up to the one before the last to create the undo
effect. (Wasn't there a recorder or something in cairo? I'm not an
advanced cairo user).

	Storing / restoring images would be memory inefficient, and  it would
work only if you decide to do pixel-based imaging, you can probably do
something to detect what changed between one image and another and store
only the diffs back for undo restore, or some combination of replay
packets with full image in there (much like movie codecs have a full
frame, and then diff frames in between for every dozen or so frames).

On 9/4/2012 5:59 PM, SeongWon Cho wrote:
> Hi, all
> 
> Does Anybody have a good idea how to implement "undo" and "redo" in Cairo application?
> I can use pair of APIs, cairo_image_surface_get_data() and cairo_image_surface_create_for_data() to store and to restore of buffer but I have no idea this is a correct approach or not.
> 
> Please feel free to give me any advises and ideas.
> 
> Thanks.
> Cho
> 
> 
>   조 성 원 선임/ Cho, Seong Won
>      SLP R&D Group
> 
>     Mobile Device Division.
>     Telecommunication Network
>     Samsung Electronics Co. Ltd.
>     Phone : +82-31-301-5373       Mobile : +82-10-7260-5373
>     Mail : seongwon1.cho at samsung.com
> 


More information about the cairo mailing list