You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
4.3 KiB
Java

/* Session when program is initially started, screen changes when
doodle button is pressed */
import processing.core.*;
import static processing.core.PApplet.*;
class Calibrator {
boolean active;
PImage drawnScreen;
ProjectorApplet projector;
/////////////////////// proj img screen alignment
float offsetx, offsety, magx, magy, rot;
void reset() {
magx = 7.4f; // reduction factor in X
magy = 6.0f ; // reduction factor in Y
offsetx = 0.423f; // starts projectorApplet screen at distance from right most edge
offsety = 0.44f; // distance from topmost edge
rot = 0; // rotation of projection starts at 0 degrees
}
Calibrator(ProjectorApplet projector){
this.projector = projector;
this.reset();
this.active = false;
}
void toggle() {
if (this.active) {
this.deactivate();
} else {
this.activate();
}
}
void activate() {
this.active = true;
// 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() {
// 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;
}
void buttonPressed(int keyCode){
if (!this.active) {
return;
}
// Calibration of projectorApplet field of view
switch(keyCode) {
case UP:
offsety = offsety - .001f; //Moves projections up in app view
break;
case DOWN:
offsety = offsety + .001f; //Moves projections down
break;
case LEFT:
offsetx = offsetx - .001f; // Moves projections left
break;
case RIGHT:
offsetx = offsetx + .001f; // Moves projections right
break;
case 36:
magx = magx + .05f; // HOME button reduces width of projections
break;
case 35:
magx = magx - .05f; // END button increases width of projections
break;
case 33:
magy = magy + .05f; // PAGE UP button reduces height of projections
break;
case 34:
magy = magy - .05f; // PAGE DOWN button increases height of projections
break;
case SHIFT:
println("x-offset: " + offsetx + " | y-offset: " + offsety);
println("x-magnification: " + magx + " | y-magnification: " + magy);
default:
break;
}
}
void draw(EuglenaApplet a) {
if (!this.active) {
return;
}
projector.clear();
float x0 = a.width * offsetx;
float y0 = a.height * offsety;
float dx = (a.width - a.menu.width)/magx;
float dy = a.height/magy;
// Hello World on 2nd Monitor
projector.noStroke();
projector.textSize(50);
projector.fill(projector.color(0, 90, 0));
projector.text("hello,", x0+20, y0+60);
projector.fill(projector.color(0, 0, 90));
projector.text("world!", x0+20, y0+110);
// Four dots used for calibration (may need to change code so that it better matches the math used to convert other points)
projector.ellipseMode(CORNER);
projector.fill(projector.color(0, 0, 190));
projector.ellipse(x0, y0, 5, 5);
projector.fill(projector.color(190,0,0));
projector.ellipse(x0, y0+dy-10, 5, 5);
projector.fill(255);
projector.ellipse(x0+dx-5, y0+dy-10, 5, 5);
projector.fill(projector.color(0, 190, 0));
projector.ellipse(x0+dx-5, y0, 5, 5);
}
}