2016-07-10 09:03:16 -07:00
|
|
|
import processing.core.*;
|
|
|
|
import static processing.core.PApplet.*;
|
|
|
|
|
|
|
|
|
|
|
|
class Rectangle {
|
|
|
|
|
|
|
|
float corner1x, corner1y, corner2x, corner2y;
|
|
|
|
int color, brushSize;
|
|
|
|
boolean visible;
|
|
|
|
|
|
|
|
private boolean corner1complete;
|
|
|
|
|
|
|
|
Rectangle(int color, int penWidth) {
|
|
|
|
this.color = color;
|
|
|
|
this.brushSize = penWidth;
|
|
|
|
this.visible = false;
|
|
|
|
|
|
|
|
this.corner1complete = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Rectangle(float corner1x, float corner1y, float corner2x, float corner2y, int color, int penWidth) {
|
|
|
|
this.corner1x = corner1x;
|
|
|
|
this.corner1y = corner1y;
|
|
|
|
this.corner2x = corner2x;
|
|
|
|
this.corner2y = corner2y;
|
|
|
|
this.color = color;
|
|
|
|
this.brushSize = penWidth;
|
|
|
|
this.visible = true;
|
|
|
|
|
|
|
|
this.corner1complete = true;
|
|
|
|
}
|
|
|
|
|
2016-07-10 17:51:01 -07:00
|
|
|
ProjectorCommand makeProjectorCommand() {
|
2016-07-10 09:03:16 -07:00
|
|
|
return (ProjectorApplet p) -> {
|
|
|
|
if (!visible) {
|
|
|
|
//done drawing already
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
float old_strokeWeight = p.g.strokeWeight;
|
|
|
|
int old_strokeColor = p.g.strokeColor;
|
|
|
|
|
|
|
|
p.rectMode(CORNERS);
|
|
|
|
p.strokeWeight(brushSize);
|
|
|
|
p.stroke(color);
|
|
|
|
p.noFill();
|
|
|
|
|
|
|
|
p.rect(p.convertXCoord(corner1x), p.convertYCoord(corner1y),
|
|
|
|
p.convertXCoord(corner2x), p.convertYCoord(corner2y));
|
|
|
|
|
|
|
|
p.strokeWeight(old_strokeWeight);
|
|
|
|
p.stroke(old_strokeColor);
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
ClickGetter makeClickGetter(ProjectorApplet p) {
|
|
|
|
return (int x, int y) -> {
|
|
|
|
if (!corner1complete){
|
|
|
|
corner1x = x;
|
|
|
|
corner1y = y;
|
|
|
|
corner1complete = true;
|
|
|
|
return false;
|
2016-07-10 18:20:55 -07:00
|
|
|
|
2016-07-10 09:03:16 -07:00
|
|
|
} else {
|
|
|
|
corner2x = x;
|
|
|
|
corner2y = y;
|
|
|
|
visible = true;
|
|
|
|
|
2016-07-10 17:51:01 -07:00
|
|
|
p.commandQueue.add(makeProjectorCommand());
|
2016-07-10 09:03:16 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|