Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to Undo/Redo drawing operation in a dialog based application.?

How to Undo/Redo drawing operation in a dialog based application.?

Scheduled Pinned Locked Moved C / C++ / MFC
graphicshelptutorialquestion
8 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mbatra31
    wrote on last edited by
    #1

    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,

    C C S 3 Replies Last reply
    0
    • M mbatra31

      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,

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      You may have a look at Command Design Pattern[^].

      Veni, vidi, vici.

      M 1 Reply Last reply
      0
      • M mbatra31

        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,

        C Offline
        C Offline
        Chris Losinger
        wrote on last edited by
        #3

        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.

        image processing toolkits | batch image processing

        M 1 Reply Last reply
        0
        • C Chris Losinger

          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.

          image processing toolkits | batch image processing

          M Offline
          M Offline
          mbatra31
          wrote on last edited by
          #4

          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,

          C M 2 Replies Last reply
          0
          • C CPallini

            You may have a look at Command Design Pattern[^].

            Veni, vidi, vici.

            M Offline
            M Offline
            mbatra31
            wrote on last edited by
            #5

            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,

            1 Reply Last reply
            0
            • M mbatra31

              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,

              C Offline
              C Offline
              Chris Losinger
              wrote on last edited by
              #6

              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.

              image processing toolkits | batch image processing

              1 Reply Last reply
              0
              • M mbatra31

                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,

                M Offline
                M Offline
                Maximilien
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0
                • M mbatra31

                  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,

                  S Offline
                  S Offline
                  Sunil P V
                  wrote on last edited by
                  #8

                  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

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups