Add mouseDragged handler and add code for freehand drawing and erasing
Ursprung
99388a2786
Commit
9658e99e39
@ -0,0 +1,47 @@
|
||||
/*
|
||||
Interface for handling mouse drags
|
||||
*/
|
||||
|
||||
public interface DragGetter {
|
||||
boolean drag(int x1, int y1, int x2, int y2);
|
||||
}
|
||||
|
||||
|
||||
//public interface Shape {
|
||||
// public int numVertices();
|
||||
//}
|
||||
//
|
||||
//
|
||||
//class Circle2 implements Shape {
|
||||
// Circle2() {
|
||||
// blah;
|
||||
// }
|
||||
//
|
||||
// int numVertices() {
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// void expand() {
|
||||
// blah2;
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//class Square implements Shape {
|
||||
// int numVertices() {
|
||||
// return 4;
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//Shape g = new Circle2();
|
||||
////g.expand(); // bad
|
||||
//println(g.numVertices()); //good
|
||||
//g = new Square();
|
||||
//println(g.numVertices());
|
||||
//
|
||||
//void printNumberOfVertices(Shape s) {
|
||||
// println(s.numVertices());
|
||||
//}
|
||||
//
|
||||
//printNumberOfVertices(new Circle2());
|
||||
//printNumberOfVertices(new Square());
|
@ -0,0 +1,27 @@
|
||||
class Freehand {
|
||||
/*
|
||||
Class for freehand drawing
|
||||
*/
|
||||
|
||||
int color, brushSize;
|
||||
|
||||
Freehand(int color, int penWidth) {
|
||||
this.color = color;
|
||||
this.brushSize = penWidth;
|
||||
}
|
||||
|
||||
DragGetter makeDragGetter(ProjectorApplet p) {
|
||||
/*
|
||||
Create a DragGetter which can accept incoming mouse drags
|
||||
and use them to draw lines
|
||||
*/
|
||||
|
||||
return (int x1, int y1, int x2, int y2) -> {
|
||||
Line line = new Line(x1, y1, x2, y2, this.color, this.brushSize);
|
||||
p.commandQueue.add(line.makeProjectorCommand());
|
||||
|
||||
// Keep using this DragGetter, don't stop
|
||||
return false;
|
||||
};
|
||||
}
|
||||
}
|
Laden…
In neuem Issue referenzieren