here is a starting example I did a while back, it is mainly for undo redo and open and save as for image editing you can easily add that yourself there is a great tutorial on
processing.org
you would need the G4P lib as I used the file IO from there
did not get it quit right I have been meaning to fix it but it is just been sitting there
never undos the first action
- import g4p_controls.*;
- GButton btnInput, btnOutput;
- GButton btnUndo, btnRedo;
- int lineToolX, lineToolY;
- PImage save;
- PImage screen;
- ArrayList<PImage> screens;
- int counter=1;
- int redocounter=0;
- int buty=26;
- void setup() {
- size(400,400);
- background(255);
- frameRate(200);
- loadPixels();
- screens=new ArrayList();
- PApplet.useNativeSelect=true;
- btnInput = new GButton(this, 0, 0, 57, 20, "Open");
- btnOutput = new GButton(this, 0, buty, 57, 20, "Save");
- btnUndo = new GButton(this, 0, buty*2, 57, 20, "undo");
- btnRedo = new GButton(this, 0, buty*3, 57, 20, "redo");
- }
- void draw()
- {
- /*if(save!=null)
- image(save,57,57);
- updatePixels();
- rect(0,57*2,57,57*2);
- fill(200);
- rect(0,57*2,57,57);
- fill(100);
- rect(0,57*3,57,57);*/
- fill(255);
- noStroke();
- rect(0,0,width,57);
- rect(0,0,57,height);
- stroke(0);
- line(57,57,width,57);
- line(57,57,57,height);
- if(mousePressed&&mouseX>57&&mouseY>57){
- stroke(0);
- strokeWeight(3);
- line(pmouseX,pmouseY, mouseX, mouseY);
- }
- }
- void mousePressed()
- {
- lineToolX = mouseX;
- lineToolY = mouseY;
- }
- void mouseReleased() {
- if(mouseX>57&&mouseY>57){
- redocounter++;
- screen=get(57,57,width,height);
- screens.add(screen);
- println(screens.size()+" "+counter);}
- loadPixels();
- }
- // G4P code for folder and file dialogs
- public void handleButtonEvents(GButton button, GEvent event) {
- String fname;
- // File input selection
- if (button == btnInput) {
- // Use file filter if possible
- fname = G4P.selectInput("Open", "png,gif,jpg,jpeg", "Image files");
- save = loadImage(fname);
- set(0, 0, save);
- loadPixels();
- }
- // File output selection
- else if (button == btnOutput) {
- fname = G4P.selectOutput("Save as");
- save = get();
- save.save(fname);
- //lblFile.setText(fname);
- }
- else if (button == btnRedo) {
- if(counter>1){
- counter--;
- if((screens.size())!=counter){
-
- set(57,57,screens.get(screens.size()-counter));
- println(screens.size()+" "+counter+" "+(screens.size()-counter));} }
- }else if (button == btnUndo) {
- counter++;
- if((screens.size()-counter)>=0){
-
- set(57,57,screens.get(screens.size()-counter));
- println(screens.size()+" "+counter+" "+(screens.size()-counter));}
-
-
- }
- }