From 99388a2786ec1e3eb80b01aa9641a9d0e0fd17e8 Mon Sep 17 00:00:00 2001 From: jan Date: Sun, 8 Jan 2017 16:57:27 -0800 Subject: [PATCH] Fix calibrator attempting to draw when it's activated (outside of draw() function) --- src/Calibrator.java | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) 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; }