Ellipse clickGetter works

This commit is contained in:
jan 2016-07-10 07:14:09 -07:00
commit df880a0e66
6 changed files with 209 additions and 178 deletions

3
src/ClickGetter.java Normal file
View file

@ -0,0 +1,3 @@
public interface ClickGetter {
boolean click(int mouseX, int mouseY);
}

View file

@ -1,82 +1,80 @@
import processing.core.*;
import static processing.core.PApplet.*;
//class EllipseDrawer {
//
// Ellipse ellipseinprogress;
//
// boolean centerpointcomplete;
// boolean widthcomplete;
//
// void reset() {
// ellipseinprogress = new Ellipse(-1, -1, 0, 0);
// ellipseinprogress.visible = false;
// centerpointcomplete = false;
// widthcomplete = false;
//
// }
//
// EllipseDrawer(){
// this.reset();
// }
//
// void mouseClicked(ProjectorApplet p, float x, float y){
// if (!centerpointcomplete){
// ellipseinprogress.centerX = x;
// ellipseinprogress.centerY = y;
// centerpointcomplete = true;
//
// } else if (!widthcomplete) {
// ellipseinprogress.width = PApplet.abs(ellipseinprogress.centerX - x) * 2;
// widthcomplete = true;
//
// } else {
// ellipseinprogress.height = PApplet.abs(ellipseinprogress.centerY - y) * 2;
// ellipseinprogress.visible = true;
// //ellipses.add(ellipseinprogress);
//
// ellipseinprogress.draw(p);
// this.reset();
// }
// }
//}
class Ellipse {
float centerX, centerY, width, height;
int red, green, blue, brushSize;
int color, brushSize;
boolean visible;
Ellipse(float centerX, float centerY, float width, float height, int rVal, int gVal, int bVal, int penWidth) {
private boolean centerPointComplete, widthComplete;
Ellipse(int color, int penWidth) {
this.color = color;
this.brushSize = penWidth;
this.centerPointComplete = false;
this.widthComplete = false;
}
Ellipse(float centerX, float centerY, float width, float height, int color, int penWidth) {
this.centerX = centerX;
this.centerY = centerY;
this.width = width;
this.height = height;
this.red = rVal;
this.green = gVal;
this.blue = bVal;
this.color = color;
this.brushSize = penWidth;
this.visible = true;
this.centerPointComplete = true;
this.widthComplete = true;
}
void draw(ProjectorApplet projector) {
if (visible) {
projector.commandQueue.add(
(ProjectorApplet p) -> {
float old_strokeWeight = p.g.strokeWeight;
int old_strokeColor = p.g.strokeColor;
ProjectorCommand drawCommand() {
return (ProjectorApplet p) -> {
if (!visible) {
//done drawing already
return true;
}
p.ellipseMode(PApplet.CENTER);
p.strokeWeight(brushSize);
p.stroke(p.color(red, green, blue));
p.noFill();
float old_strokeWeight = p.g.strokeWeight;
int old_strokeColor = p.g.strokeColor;
p.ellipse(p.convertXCoord(centerX), p.convertYCoord(centerY),
p.convertXDistance(width), p.convertYDistance(height));
p.strokeWeight(old_strokeWeight);
p.stroke(old_strokeColor);
return true;
});
}
p.ellipseMode(CENTER);
p.strokeWeight(brushSize);
p.stroke(color);
p.noFill();
p.ellipse(p.convertXCoord(centerX), p.convertYCoord(centerY),
p.convertXDistance(width), p.convertYDistance(height));
p.strokeWeight(old_strokeWeight);
p.stroke(old_strokeColor);
return true;
};
}
ClickGetter clickGetter(ProjectorApplet p) {
return (int x, int y) -> {
if (!centerPointComplete){
centerX = x;
centerY = y;
centerPointComplete = true;
return false;
} else if (!widthComplete) {
width = abs(centerX - x) * 2;
widthComplete = true;
return false;
} else {
height = abs(centerY - y) * 2;
visible = true;
p.commandQueue.add(drawCommand());
return true;
}
};
}
}

View file

@ -12,6 +12,7 @@ public class EuglenaApplet extends PApplet {
// Software components
Menu menu;
Calibrator calibrator;
ClickGetter clickGetter;
boolean tester;
@ -52,12 +53,24 @@ public class EuglenaApplet extends PApplet {
image(camera.getImage(), 0, 0, width - menu.width, height);
if (!tester) {
new Ellipse(0f, 0f, 1000f, 1000f, 250, 250, 250, 8).draw(this.projectorApplet);
// this.projectorApplet.commandQueue.add(new Ellipse(0f, 0f, 1000f, 1000f, color(250, 250, 250), 8).drawCommand());
this.clickGetter = new Ellipse(color(255), 10).clickGetter(projectorApplet);
tester = true;
}
}
@Override
public void mouseClicked(){
if (clickGetter != null) {
if (clickGetter.click(mouseX, mouseY)) {
clickGetter = null;
}
}
}
void drawArrow(int cx, int cy, int len, float angle){
pushMatrix();
translate(cx, cy);

4
src/Procedure.java Normal file
View file

@ -0,0 +1,4 @@
public interface Procedure {
void execute();
}

View file

@ -1,7 +1,6 @@
import processing.core.PApplet;
import java.util.ArrayDeque;
import java.util.function.*;
class ProjectorApplet extends PApplet {
final int projectorScreenNumber = 2;
@ -32,10 +31,6 @@ class ProjectorApplet extends PApplet {
@Override
public void draw() {
// background(50);
// fill(255);
// ellipse(mouseX, mouseY, 10, 10);
calibrator.draw(parent);
while (!commandQueue.isEmpty()) {