From 79d0f9a45d36656051a77a7b0837aa0318f81ee5 Mon Sep 17 00:00:00 2001 From: Normand Briere <nbriere@noware.ca> Date: Sun, 09 Jun 2019 11:23:18 -0400 Subject: [PATCH] Undo/redo --- ObjEditor.java | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 103 insertions(+), 0 deletions(-) diff --git a/ObjEditor.java b/ObjEditor.java index 1edfe37..05b548c 100644 --- a/ObjEditor.java +++ b/ObjEditor.java @@ -3207,10 +3207,112 @@ { copy.remove(1); } + ResetModel(); objEditor.refreshContents(); } + Object3D graphs[] = new Object3D[10000]; + int undoindex = 0; + + static public Object clone(Object o) + { + try + { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream out = new ObjectOutputStream(baos); + + out.writeObject(o); + + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + ObjectInputStream in = new ObjectInputStream(bais); + Object obj = in.readObject(); + in.close(); + out.close(); + return obj; + } catch (Exception e) + { + System.err.println(e); + return null; + } + } + + public void Save() + { + if (true) return; + + //EditorFrame.m_MainFrame.requestFocusInWindow(); + graphs[undoindex++] = (Object3D)clone(copy); + + for (int i = undoindex; i < graphs.length; i++) + { + graphs[i] = null; + } + + // test save + if (false) + { + try + { + FileOutputStream ostream = new FileOutputStream("save" + undoindex); + ObjectOutputStream p = new ObjectOutputStream(ostream); + + p.writeObject(copy); + + p.flush(); + + ostream.close(); + } catch (Exception e) + { + e.printStackTrace(); + } + } + } + + public void Undo() + { + if (undoindex == 0) + { + java.awt.Toolkit.getDefaultToolkit().beep(); + return; + } + + if (graphs[undoindex] == null) + { + Save(); + undoindex -= 1; + } + + undoindex -= 1; + + copy = graphs[undoindex]; + + cameraView.object = copy; + copy.Touch(); + + ResetModel(); + refreshContents(); + } + + public void Redo() + { + if (graphs[undoindex + 1] == null) + { + java.awt.Toolkit.getDefaultToolkit().beep(); + return; + } + + undoindex += 1; + + copy = graphs[undoindex]; + + cameraView.object = copy; + copy.Touch(); + + ResetModel(); + refreshContents(); + } + void ImportGFD() { FileDialog browser = new FileDialog(objEditor.frame, "Import GrafreeD", FileDialog.LOAD); @@ -3855,6 +3957,7 @@ void makeSomething(Object3D thing, boolean resetmodel) // deselect) { + Save(); //Tween.set(thing, 0).target(1).start(tweenManager); //Tween.to(thing, 0, 0.5f).target(0).start(tweenManager); // if (thing instanceof GenericJointDemo) -- Gitblit v1.6.2