-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed rendering, added draggable point, added line that reacts to point
- Loading branch information
Kristopher Guzman
committed
Dec 3, 2016
1 parent
bbc8777
commit ebd302b
Showing
7 changed files
with
679 additions
and
29 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package main; | ||
|
||
import javafx.scene.canvas.Canvas; | ||
import javafx.scene.canvas.GraphicsContext; | ||
import javafx.scene.paint.Color; | ||
import javafx.scene.paint.Paint; | ||
|
||
/** | ||
* Created by kristopherguzman on 12/2/16. | ||
*/ | ||
public class DragPoint implements Drawable { | ||
|
||
public boolean isDragging = false; | ||
|
||
private GraphicsContext gc; | ||
|
||
private int screenWidth; | ||
private double x; | ||
private double y; | ||
private int size = 20; | ||
|
||
public double getX() { return x + (size / 2); } | ||
public double getY() { return y + (size / 2); } | ||
|
||
|
||
public DragPoint(Canvas canvas, double x, double y) { | ||
|
||
this.gc = canvas.getGraphicsContext2D(); | ||
screenWidth = canvas.widthProperty().intValue(); | ||
this.x = x; | ||
this.y = y; | ||
|
||
Controller.drawableObjects.add(this); | ||
|
||
} | ||
|
||
public void setPosition(double x, double y) { | ||
|
||
if(x > screenWidth - 25 || x < 25 || y > screenWidth - 25 || y < 25) { | ||
return; | ||
} | ||
|
||
this.x = x - (size / 2); | ||
this.y = y - (size / 2); | ||
|
||
} | ||
|
||
public boolean inBoundsOf(double mx, double my) { | ||
|
||
//checks if point of mouse click is in bounds of drag point | ||
System.out.println("px: " + x + " py: " + y + " mx: " + mx + " my: " + my); | ||
return (mx > x && mx < x + size && my > y && my < y + size); | ||
|
||
} | ||
|
||
public void update() { | ||
|
||
gc.setFill(Color.BLACK); | ||
gc.fillOval(x, y, size, size); | ||
|
||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package main; | ||
|
||
/** | ||
* Created by kristopherguzman on 12/2/16. | ||
*/ | ||
public interface Drawable { | ||
void update(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,47 @@ | ||
package main; | ||
|
||
import javafx.scene.canvas.Canvas; | ||
import javafx.scene.canvas.GraphicsContext; | ||
import javafx.scene.paint.Color; | ||
|
||
/** | ||
* Created by kristopherguzman on 12/2/16. | ||
*/ | ||
public class Line { | ||
public class Line implements Drawable { | ||
|
||
private int start; | ||
private int end; | ||
private GraphicsContext gc; | ||
private DragPoint p; | ||
private int thickness; | ||
private int screenWidth; | ||
|
||
public void setStart(); | ||
public Line(Canvas canvas, int thickness, DragPoint p) { | ||
|
||
public Line(Canvas canvas, int thickness, int from, int to) { | ||
this.gc = canvas.getGraphicsContext2D(); | ||
this.thickness = thickness; | ||
this.screenWidth = canvas.widthProperty().intValue(); | ||
this.p = p; | ||
|
||
this.start = canvas.widthProperty().intValue() - start; | ||
this.end = canvas.heightProperty().intValue() - end; | ||
Controller.drawableObjects.add(this); | ||
Controller.update(gc); | ||
|
||
} | ||
|
||
public void update() { | ||
|
||
double py = screenWidth - p.getY(); | ||
double m = (py - screenWidth) / (p.getX() - screenWidth); // y2 - y1 / x2 - x2 | ||
double b = m * (0 - screenWidth) + screenWidth; // m(x - x1) = y intercept | ||
double y = b; // y = mx + b | ||
double x = 0; | ||
y = screenWidth - y; //invert y coordinate | ||
|
||
gc.beginPath(); | ||
gc.moveTo(screenWidth, 0); | ||
gc.lineTo(x, y); | ||
gc.setLineWidth(thickness); | ||
gc.stroke(); | ||
gc.closePath(); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters