How to Undo/Redo drawing operation in a dialog based application.?
-
Hi, I have a dialog based application. I have a picture control on a dialog. I am drawing a line in OnMouseMove handler. I want to hande Undo /Redo events on that control. If a user has drawn a line then clicking on Undo button will erase the line and Redo will again draw the same line deleted. I have seen that events handled in a SDI application. But I want to do the same in a dialog based application. Any help will be appreciated. Regards,
-
Hi, I have a dialog based application. I have a picture control on a dialog. I am drawing a line in OnMouseMove handler. I want to hande Undo /Redo events on that control. If a user has drawn a line then clicking on Undo button will erase the line and Redo will again draw the same line deleted. I have seen that events handled in a SDI application. But I want to do the same in a dialog based application. Any help will be appreciated. Regards,
-
Hi, I have a dialog based application. I have a picture control on a dialog. I am drawing a line in OnMouseMove handler. I want to hande Undo /Redo events on that control. If a user has drawn a line then clicking on Undo button will erase the line and Redo will again draw the same line deleted. I have seen that events handled in a SDI application. But I want to do the same in a dialog based application. Any help will be appreciated. Regards,
a very basic single-step undo/redo scheme is : get two off-screen images: call them undo and redo. before every action that can be undone, copy the current image to the 'undo' image, clear the 'redo' image. to undo: copy the current image to 'redo', copy 'undo' to the current image to redo: copy the current image to 'undo', copy 'redo' to the current image to do more steps, you'll need an array or queue of images.
-
a very basic single-step undo/redo scheme is : get two off-screen images: call them undo and redo. before every action that can be undone, copy the current image to the 'undo' image, clear the 'redo' image. to undo: copy the current image to 'redo', copy 'undo' to the current image to redo: copy the current image to 'undo', copy 'redo' to the current image to do more steps, you'll need an array or queue of images.
Hi, Thanx for the reply. But for this we need to save the image at every instance we modify the image. I was actually looking at Command Design pattern. But I have no idea, how to handle the MouseMove event in case I am using Command design pattern. if you have any sample code using command design patern with dialog based apps, help will be appreciated. Can u give me a sample code for the idea you had given. I was doing the same way but still it was difficult with MouseMove handler event to save the images. I was saving two images, when you do any modification on again, I'll copy the third image to second and second to first, but it was hadnling the MouseMove event properly. Also the reason I want to use command pattern is that I want to Undo/Redo to some specified level, say 10 or 20 level. Regards,
-
You may have a look at Command Design Pattern[^].
Veni, vidi, vici.
Hi, Thanx for the reply. I was actually looking at Command Design pattern. But I have no idea, how to handle the MouseMove event in case I am using Command design pattern. if you have any sample code using command design patern with dialog based apps, help will be appreciated. Regards,
-
Hi, Thanx for the reply. But for this we need to save the image at every instance we modify the image. I was actually looking at Command Design pattern. But I have no idea, how to handle the MouseMove event in case I am using Command design pattern. if you have any sample code using command design patern with dialog based apps, help will be appreciated. Can u give me a sample code for the idea you had given. I was doing the same way but still it was difficult with MouseMove handler event to save the images. I was saving two images, when you do any modification on again, I'll copy the third image to second and second to first, but it was hadnling the MouseMove event properly. Also the reason I want to use command pattern is that I want to Undo/Redo to some specified level, say 10 or 20 level. Regards,
mbatra31 wrote:
But for this we need to save the image at every instance we modify the image.
or, you can store just the part which was modified. that will reduce memory usage. this Colorizing edit control[^] has unlimited undo/redo, using something like the command pattern. but text handling is much different from images.
-
Hi, Thanx for the reply. But for this we need to save the image at every instance we modify the image. I was actually looking at Command Design pattern. But I have no idea, how to handle the MouseMove event in case I am using Command design pattern. if you have any sample code using command design patern with dialog based apps, help will be appreciated. Can u give me a sample code for the idea you had given. I was doing the same way but still it was difficult with MouseMove handler event to save the images. I was saving two images, when you do any modification on again, I'll copy the third image to second and second to first, but it was hadnling the MouseMove event properly. Also the reason I want to use command pattern is that I want to Undo/Redo to some specified level, say 10 or 20 level. Regards,
You have to think things over. The undo is usually the harder thing to do because you need to restore the previous drawing stage. For example, if you have a "spray-can" tool, the undo of that might be quite difficult without storing the previous bitmap; unless you redraw all the steps from the start (could be fast, could be slow depending on the drawing, but that solution (redrawing every thing) is quite easy to implement. Saving the bitmap is not incompatible with having a command pattern,
Watched code never compiles.
-
Hi, I have a dialog based application. I have a picture control on a dialog. I am drawing a line in OnMouseMove handler. I want to hande Undo /Redo events on that control. If a user has drawn a line then clicking on Undo button will erase the line and Redo will again draw the same line deleted. I have seen that events handled in a SDI application. But I want to do the same in a dialog based application. Any help will be appreciated. Regards,
Well Undo/Redo can be handled in an easier and simpler way. There are complex ways of achieving it like double buffering etc but they seem to work exceptionally well in OpenGL. For simple MFC applications you can follow a simple approach. Create a (master)list class that stores the objects to be drawn. As and when you create a new object add it to this list. Maintain another Undo and Redo list. When the user hits on Undo option pop(remove) the last object added from the master list class add this object to your Undo list class. After this re-draw your dialog. When the user hits on Redo option pop(remove) the last object added from the Undo list class add this object to your Master list class. After this re-draw your dialog.
Sunil