Results 1 to 6 of 6

Thread: Unlimited Undo/Redo PictureBox

  1. #1

    Thread Starter
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755

    Question Unlimited Undo/Redo PictureBox

    Hi!

    I have a problem...

    I love to make painting programs and other graphic programs, and now i want to make an unlimited undo/redo function, but i dont know how!

    I've tried to remake a function for richtext but it didnt turn out good

    please help me! i really need to know how to do this!
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  2. #2
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    One way would be to store the previous and new value of each pixel as the user changes it. Then wien the user clickes undo, have it revert (but you would have to work out how to undo, i.e. don't have to undo each pixel individualy).


    I havn't tried doing an undo feature but i woudl suggest something like this.

    Create an array of a custom type like this

    VB Code:
    1. Private Type typUndoRedo
    2.     PixelX as Double
    3.     PixelY as Double
    4.     OldColour as Long '???
    5.     NewColour as Long '???
    6.     IsUndoRedoPoint as Boolean
    7. End Type
    8. Dim UndoRedo(Really Big Number, Or variable length) as typUndoRedo

    I presume you have various functions for manipulating pixels, such as square, circle, line etc....

    Do this sort of thing for each of these.

    Code:
    sub Box(param1,param2...)
        'The first pixel change
        currentnumber = currentnumber+1
        UndoRedo(Currentnumber).isundoredopoint = True
        UndoRedo(Currentnumber).pixelx = 5
        UndoRedo(Currentnumber).pixely = 7
        UndoRedo(Currentnumber).OldColour = ColourOfPixel(5,7)
        UndoRedo(Currentnumber).NewColour = vbBlack
        pset (5,7),vbBlack
        
        'The rest of the code for changing all the pixels in the square
        currentnumber = currentnumber+1
        UndoRedo(Currentnumber).isundoredopoint = False
        UndoRedo(Currentnumber).pixelx = X
        UndoRedo(Currentnumber).pixely = Y
        UndoRedo(Currentnumber).OldColour = ColourOfPixel(X,Y)
        UndoRedo(Currentnumber).NewColour = vbBlack
        pset (X,Y),vbBlack
    
    
        'The Last Pixel Change
    
        currentnumber = currentnumber+1
        UndoRedo(Currentnumber).isundoredopoint = True
        UndoRedo(Currentnumber).pixelx = 56
        UndoRedo(Currentnumber).pixely = 32
        UndoRedo(Currentnumber).OldColour = ColourOfPixel(56,32)
        UndoRedo(Currentnumber).NewColour = vbBlack
        pset (56,32),vbBlack
    end sub

    Now, for your undo function, you will start at currentnumber, and go back through the array, changing the pixels to oldcolour. UNTILL you get to the isundoredopoint = True

    For the redo function you would do the same, but go forward.



    NB: This is purely, me thinking about how it may work, as i havn't tried it before, or tested the above method it may not work. Its just an idea of how i would go about it. Hope it helpes.

    If you want me to explain a certain aspect better, just ask.
    Last edited by SLH; Apr 21st, 2002 at 04:54 AM.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  3. #3

    Thread Starter
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    i think i get the idea but im not a good programmer so i would need some help to finish it...

    one think that would be cool is to make a listbox with thumbnails of the changes so the user could click on any item in the list to restore a previous picture...
    i think phososhop has that feature but im not sure....
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  4. #4
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    You start it, and i'll be happy to help.

    Unless you did some clever coding, to manipulate those pictures, that would take up A LOT of memory, with a lot of undo levels.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Download the project attached in this thread to the last post by Nucleus.

    http://www.vbforums.com/showthread.p...highlight=undo

  6. #6

    Thread Starter
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    oh! thanks!
    that code reminds me alot about that richtext undo/redo code that i couldt remake to picturebox code, but i can try...
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width