Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FX - align to pixel grid when drawing 1 px strokes #3712

Merged
merged 1 commit into from
Aug 24, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions core/src/processing/javafx/PGraphicsFX2D.java
Original file line number Diff line number Diff line change
Expand Up @@ -611,13 +611,27 @@ public void point(float x, float y) {

@Override
public void line(float x1, float y1, float x2, float y2) {
if (drawingThinLines()) {
x1 += 0.5f;
x2 += 0.5f;
y1 += 0.5f;
y2 += 0.5f;
}
context.strokeLine(x1, y1, x2, y2);
}


@Override
public void triangle(float x1, float y1, float x2, float y2,
float x3, float y3) {
if (drawingThinLines()) {
x1 += 0.5f;
x2 += 0.5f;
x3 += 0.5f;
y1 += 0.5f;
y2 += 0.5f;
y3 += 0.5f;
}
context.beginPath();
context.moveTo(x1, y1);
context.lineTo(x2, y2);
Expand All @@ -631,6 +645,16 @@ public void triangle(float x1, float y1, float x2, float y2,
@Override
public void quad(float x1, float y1, float x2, float y2,
float x3, float y3, float x4, float y4) {
if (drawingThinLines()) {
x1 += 0.5f;
x2 += 0.5f;
x3 += 0.5f;
x4 += 0.5f;
y1 += 0.5f;
y2 += 0.5f;
y3 += 0.5f;
y4 += 0.5f;
}
context.beginPath();
context.moveTo(x1, y1);
context.lineTo(x2, y2);
Expand Down Expand Up @@ -658,6 +682,12 @@ public void quad(float x1, float y1, float x2, float y2,
protected void rectImpl(float x1, float y1, float x2, float y2) {
// rect.setFrame(x1, y1, x2-x1, y2-y1);
// drawShape(rect);
if (drawingThinLines()) {
x1 += 0.5f;
x2 += 0.5f;
y1 += 0.5f;
y2 += 0.5f;
}
if (fill) context.fillRect(x1, y1, x2 - x1, y2 - y1);
if (stroke) context.strokeRect(x1, y1, x2 - x1, y2 - y1);
}
Expand All @@ -679,6 +709,10 @@ protected void rectImpl(float x1, float y1, float x2, float y2) {
protected void ellipseImpl(float x, float y, float w, float h) {
// ellipse.setFrame(x, y, w, h);
// drawShape(ellipse);
if (drawingThinLines()) {
x += 0.5f;
y += 0.5f;
}
if (fill) context.fillOval(x, y, w, h);
if (stroke) context.strokeOval(x, y, w, h);
}
Expand All @@ -699,6 +733,10 @@ protected void arcImpl(float x, float y, float w, float h,
float start, float stop, int mode) {
// 0 to 90 in java would be 0 to -90 for p5 renderer
// but that won't work, so -90 to 0?
if (drawingThinLines()) {
x += 0.5f;
y += 0.5f;
}

start = -start * RAD_TO_DEG;
stop = -stop * RAD_TO_DEG;
Expand Down Expand Up @@ -1729,6 +1767,12 @@ protected void strokeFromCalc() {
}


protected boolean drawingThinLines() {
// align strokes to pixel centers when drawing thin lines
return stroke && strokeWeight == 1;
}



//////////////////////////////////////////////////////////////

Expand Down