-2
I’m doing a project where I develop functions to apply effects to photos (such as Contrast, Vignette, Sepia...).
As I apply effects to photos, the various states of the photos are being stored in an image array.
In this same project, I need two functions, Undo and Redo. Undo will be used to obtain the photo with the previously applied effect and Redo will be used to obtain the last applied effect.
Someone can help me in the development of these functions (Undo and Redo)?
Thank you.
Here’s what I got in class:
class Historico {
private ColorImage [] VCI;
private int atual;
boolean undo = false;
private int undos;
private int redos;
public Historico(ColorImage [] VCI) {
this.VCI = VCI;
atual = 0;
undos = 0;
redos = 0;
}
static ColorImage copy (ColorImage CI) {
ColorImage NCI = new ColorImage(CI.getWidth(),CI.getHeight());
for(int x = 0; x < CI.getWidth(); x++){
for(int y = 0; y < CI.getHeight(); y++){
Color c = CI.getColor(x,y);
NCI.setColor(x,y,c);
}
}
return NCI;
}
void saveImage(ColorImage CI) {
VCI [atual] = copy(CI);
atual++;
undo = false;
undos = 0;
redos=0;
}
public void undo() {
ColorImage CI = copy(VCI[atual-2-undos]);
VCI[atual] = CI;
atual = atual + 1;
undo = true;
undos = undos + 2;
}
public void redo() {
if(undo = true) {
ColorImage CI = copy(VCI[atual-2-redos]);
VCI[atual] = CI;
atual = atual + 1;
undos--;
if(undos<0){
undos = 0;
undo = false;
}
redos = redos + 2;
}
}
}
Have you ever heard of the design pattern memento?
– Victor Stafusa
Hello Victor Stafusa. I haven’t heard of it. I’ve already done the Undo function. My Redo function I can apply it twice but the third one stops working (nothing happens at all), can you help me? If necessary I copy the code I already have of the 2 functions. Thank you
– Márcio
Yes, it is recommended that you post your code: https://pt.meta.stackoverflow.com/a/5484/132
– Victor Stafusa
Okay, I’m sorry. I just edited the question and there’s the code I have in the class. What is malfunctioning is the Redo function (I can use it twice but the third time it stops working (nothing happens))
– Márcio