diff --git a/src/Calibrator.java b/src/Calibrator.java index c3d4d39..3b5dd63 100644 --- a/src/Calibrator.java +++ b/src/Calibrator.java @@ -38,12 +38,27 @@ class Calibrator { void activate() { this.active = true; - this.drawnScreen = projector.get(0, 0, projector.width, projector.height); + + // Tell the projector that we want to save the state of the screen + // next time it draws + ProjectorCommand saveCommand = (ProjectorApplet p) -> { + this.drawnScreen = p.get(0, 0, p.width, p.height); + return true; + }; + projector.commandQueue.add(saveCommand); } void deactivate() { - projector.clear(); - projector.set(projector.width, 0, this.drawnScreen); + // Create a command which will restore the screen to what it + // looked like before we started calibrating + ProjectorCommand restore_command = (ProjectorApplet p) -> { + p.clear(); + p.set(0, 0, this.drawnScreen); + return true; + }; + + // Insert the restore command at the front of the queue + projector.commandQueue.add(0, restore_command); this.active = false; }