Results 1 to 27 of 27

Thread: Unlimited Undo/Redo

  1. #1

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

    Talking Unlimited Undo/Redo

    I need an unlimited undo/redo code for my app...
    i've found a code for RichTextBoxes but it didnt support
    pictureboxes so i relly need som help with this!
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  2. #2
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    It's a painting program, right? You could just save the picture to an array of invisible Image controls, but it would consume a lot of memory if you have a large number of undos
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  3. #3

    Thread Starter
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    yeah...i know that i can do that but i just need a code example
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  4. #4
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Well, right now I don't have time to code that to you

    But I can tell you how...

    VB Code:
    1. 'Use this to load a control
    2. Load imgUndo(index)
    3.  
    4. 'Use this to unload a control
    5. UnLoad imgUndo(index)

    All you need is imgUndo(0) already in the form (invisible and without any picture).
    * Before the user draws something, load another Image control into the array and copy the image that is on the screen to it.
    * To undo, just copy the image of the last control to the image that is on screen, and unload that control.

    Hope that helped
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  5. #5

    Thread Starter
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    thanks....ill try that later
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  6. #6
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    You could create a RECT and a smaller picturebox, and just put in it what changed. Eg. If a 30x30 area at 0,0 was changed...

    RECT.Right = 29
    RECT.Bottom = 29
    RECT.Top = 0
    RECT.Left = 0
    Picturebox.Picture = 0,0 -> 29,29 region
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  7. #7
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Yeah that's a good idea if you're not a begginer
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  8. #8

    Thread Starter
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    ok... i'll try that when i've got some free time...
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  9. #9
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    GDI

    GDI provides many graphical tools, including unlimited undo/redo stack functionality, you can use SaveDC to push the current state of the DC, that is after you perform a change and RestoreDC when you want to Redo, that is Pop state from the stack, and you can choose how many steps you want to backtrack as well
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  10. #10

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

    cool!

    that sounds realy cool!
    im a bit new on vb so can you tell me just a little bit how to do it?
    that would be great!
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  11. #11
    Zaei
    Guest
    Hey kedaman, Will 18 billion people even be alive during my lifetime? =P

    Z.

  12. #12
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Zaei, Maybe not at the same time

    cyborg, I was wrong, SaveDC and RestoreDC saves the state information of all graphical objects attached to DC's, which i mistoken for saving the whole objects, so I guess you wont have use for them. You could though save a lot of handles if you use GDI only to develope your graphics.

    But, that doesn't stop you from doing it, you could use a imagelist and add upp the images as you do changes to it, then retrieve them when you undo.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  13. #13
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    You don't need an image list, an array of DCs will do just fine
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  14. #14
    Fanatic Member MoMad's Avatar
    Join Date
    Oct 2000
    Location
    Seattle, WA
    Posts
    625
    What about saving them into a temp file?? instead of an array?? and load from the temp file.
    :MoMad:
    Nice Sig!

    http://go.to/momad/ Status: Not Ready

  15. #15
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Originally posted by Jotaf98
    You don't need an image list, an array of DCs will do just fine
    Waste of resources
    What about saving them into a temp file?? instead of an array?? and load from the temp file.
    That would take some time to save and load
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  16. #16
    Fanatic Member MoMad's Avatar
    Join Date
    Oct 2000
    Location
    Seattle, WA
    Posts
    625
    Well, how does photoshop do it without using up alot of memory space???? I always wonder... maybe it saves into temp file????
    :MoMad:
    Nice Sig!

    http://go.to/momad/ Status: Not Ready

  17. #17
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Originally posted by MoMad
    Well, how does photoshop do it without using up alot of memory space???? I always wonder... maybe it saves into temp file????
    Dunno, I don't have photoshop, I use PSP, which I noticed stores stuff on the harddrive, but not everything, just what it is enough down the stack.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  18. #18
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Yeah, like, when the stack is using about 10mb or something, it saves older images to the hard drive so they can be accessed later
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  19. #19
    Fanatic Member MoMad's Avatar
    Join Date
    Oct 2000
    Location
    Seattle, WA
    Posts
    625
    I use phoshop often and it amazes me how i can open 10 images of 100+MB each and edit them, do filters, selections, etc... without even taking up any more memory than it had at start-up.

    So i figured the only way this happens is that photoshop saves it on the HD, how else could it handle such tremendous amount of graphics????

    And performance/speed is not affected at all.
    :MoMad:
    Nice Sig!

    http://go.to/momad/ Status: Not Ready

  20. #20
    Fanatic Member MoMad's Avatar
    Join Date
    Oct 2000
    Location
    Seattle, WA
    Posts
    625
    maybe you can load the data into a struct, and save an array of that struct into a file and load one struct at a time instead of the whole array.

    Something like random access files?

    Code:
    'global
    ' a whole bunch of api calls go here
    ' you also need a class for handling the undo file stuff
    dim undoFile as new clsUndoHandler
    
    sub editImg_onChange()
    Dim temp as udtImage
    static theid as integer
    temp.id = theid
    temp.fid = currentImg
    temp.imagedata = getImgData(editImg(currentImg).hdc)
    temp.hdc = editImg(currentImg).hdc
    '...
    ' basically append adds to the file.
    undoFile.Append(temp)
    
    theid = theid + 1 ' increment the id
    end sub
    But that is slow, so you'll need to make a dll that uses the C-style of file processing.
    PHP Code:
    // append
    __declspec(dllexportvoid _stdcall append(const udtUndo temp)
    {
        
    FILENULL;
        
    udtUndo s;
        
    char fnom[128];
        
    sprintf(fnom"~undo%d.dat"udtUndo->fid);
        
    fopen(fnom"a+");
        
    fwrite(temp1sizeof(s), f); // only append one
        
    fclose(f);
    }

    // load
    __declspec(dllexportudtUndo _stdcall load(int fidint id)
    {
        
    FILENULL;
        
    udtUndo s;
        
    char fnom[128];
        
    sprintf(fnom"~undo%d.dat"fid);
        
    fopen(fnom"r");
        
    fread(sid*sizeof(s), sizeof(s), f); // only append one
        
    fclose(f);

        return 
    utdUndo;

    -that is just off my head, ud have to use it as an idea.
    Last edited by MoMad; Sep 21st, 2001 at 03:15 PM.
    :MoMad:
    Nice Sig!

    http://go.to/momad/ Status: Not Ready

  21. #21
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Yeah, that should work

    Maybe those programs save just something like "did a blur filter in the whole image" (in variables, not text ) and they "invert" the algorythm to get the image back

    Of course, in some cases, like opaque lines, it would still have to save some pixels (eg.: the pixels below the line)... but it would use just a few bytes in memory instead of saving a big image
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  22. #22
    Fanatic Member MoMad's Avatar
    Join Date
    Oct 2000
    Location
    Seattle, WA
    Posts
    625
    Yes EXACTLY, each effect has its own (undo) algorythm. So basically, u just save the effects that u used in the order that u used them... and if you used something like paint or select or whatevere... you just say so and save the dimensions and sthe location of that thingie. Its not really that hard unless you want to complicate urself Photoshop now has unlimited undo/redo, and infact, i found out that it creates a file for undo/redo history. That is a fact.
    :MoMad:
    Nice Sig!

    http://go.to/momad/ Status: Not Ready

  23. #23

    Thread Starter
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    i've tried this.....but then i call StoreUndo it gives me the
    "Object variable or With block variable not set" error!
    Why?
    Can it be fixed somehow?

    Here's the code:

    Dim UndoCount As Integer

    Private Type UndoStack
    UndoPicture As PictureBox
    End Type

    Dim Undoer(1000) As UndoStack


    Private Sub Undo()
    UndoCount = UndoCount - 1
    Picture1.Picture = Undoer(UndoCount).UndoPicture.Picture
    End Sub

    Private Sub StoreUndo()
    UndoCount = UndoCount + 1
    Undoer(UndoCount).UndoPicture.Picture = Picture1.Image
    End Sub
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  24. #24
    Fanatic Member MoMad's Avatar
    Join Date
    Oct 2000
    Location
    Seattle, WA
    Posts
    625
    Whoa!! Its not that simple, you have to put all of the changes in an array, for example, if your program is a line drawing program, you simply put every line on the stack and when someone does an undo, you just decrement the array count and redraw. simple? Well in something more complex like a drawing program, you have to do something much more complex.

    What ur doing is not very good, you cant just save the entire picture into memory, instead, just the parts that changed.

    To make a long story short, well this is a long story and i cant really make it short, but i can tell you it will take a lot more than just a few lines to accomplish such a task.
    :MoMad:
    Nice Sig!

    http://go.to/momad/ Status: Not Ready

  25. #25
    Fanatic Member Mushroom Realm's Avatar
    Join Date
    Mar 2002
    Location
    Murrieta, California
    Posts
    650
    I think the best choice would be the invert algorithm technique and then for say the pencil tool u could just write to the file something like: Pset (X,Y)Color where x is x, y is y, and color is the original color. Ofcourse vb wont just read it and do it. You would have to have some kind of engine setup to use the invert algorithms for whatever the value is. You run into the problem when they do a gradient....

  26. #26

    Thread Starter
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    hmmm....maybe i could store each pixel thats been changed and the color value of it and then the undo code could just put those pixels back...but that would use pretty much memory too...

    its just that im pretty new in programming vb and i just want to do a simple paint program...

    if the whole picture is stored in the memory every time the user changes something and i limit the undos to say 10 times..that wouldn't use so much memory...

    is there any simple way to do that?
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  27. #27

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

    wohooo!

    I've made a code that erases the drawn lines, but theres some problems....
    it just erases the last line! i have no idea why!

    i've attached the code here, so please have a look!

    i've named the variables pretty strange but i think you'll know how they work :P
    Attached Files Attached Files
    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