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!
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
To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systemshere.
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."
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:
'Use this to load a control
Load imgUndo(index)
'Use this to unload a control
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.
To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systemshere.
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."
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 )
To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systemshere.
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."
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.
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.
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
To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systemshere.
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."
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.
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.
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
To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systemshere.
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."
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????
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(dllexport) void _stdcall append(const udtUndo * temp)
{
FILE* f = NULL;
udtUndo s;
char fnom[128];
sprintf(fnom, "~undo%d.dat", udtUndo->fid);
f = fopen(fnom, "a+");
fwrite(temp, 1, sizeof(s), f); // only append one
fclose(f);
}
// load
__declspec(dllexport) udtUndo _stdcall load(int fid, int id)
{
FILE* f = NULL;
udtUndo s;
char fnom[128];
sprintf(fnom, "~undo%d.dat", fid);
f = fopen(fnom, "r");
fread(s, id*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.
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
To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systemshere.
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."
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.
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.
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....
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...