mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
Merge pull request #2927 from JakubValtar/bugfix-contours
Fix contours (#2665)
This commit is contained in:
@@ -67,6 +67,11 @@ public class PGraphicsJava2D extends PGraphics {
|
||||
|
||||
GeneralPath gpath;
|
||||
|
||||
// path for contours so gpath can be closed
|
||||
GeneralPath auxPath;
|
||||
|
||||
boolean openContour;
|
||||
|
||||
/// break the shape at the next vertex (next vertex() call is a moveto())
|
||||
boolean breakShape;
|
||||
|
||||
@@ -597,6 +602,7 @@ public class PGraphicsJava2D extends PGraphics {
|
||||
// this way, just check to see if gpath is null, and if it isn't
|
||||
// then just use it to continue the shape.
|
||||
gpath = null;
|
||||
auxPath = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -752,31 +758,63 @@ public class PGraphicsJava2D extends PGraphics {
|
||||
|
||||
@Override
|
||||
public void beginContour() {
|
||||
breakShape = true;
|
||||
if (openContour) {
|
||||
PGraphics.showWarning("Already called beginContour()");
|
||||
return;
|
||||
}
|
||||
|
||||
// draw contours to auxiliary path so main path can be closed later
|
||||
GeneralPath contourPath = auxPath;
|
||||
auxPath = gpath;
|
||||
gpath = contourPath;
|
||||
|
||||
if (contourPath != null) { // first contour does not break
|
||||
breakShape = true;
|
||||
}
|
||||
|
||||
openContour = true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void endContour() {
|
||||
// does nothing, just need the break in beginContour()
|
||||
if (!openContour) {
|
||||
PGraphics.showWarning("Need to call beginContour() first");
|
||||
return;
|
||||
}
|
||||
|
||||
// close this contour
|
||||
if (gpath != null) gpath.closePath();
|
||||
|
||||
// switch back to main path
|
||||
GeneralPath contourPath = gpath;
|
||||
gpath = auxPath;
|
||||
auxPath = contourPath;
|
||||
|
||||
openContour = false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void endShape(int mode) {
|
||||
if (openContour) { // correct automagically, notify user
|
||||
endContour();
|
||||
PGraphics.showWarning("Missing endContour() before endShape()");
|
||||
}
|
||||
if (gpath != null) { // make sure something has been drawn
|
||||
if (shape == POLYGON) {
|
||||
if (mode == CLOSE) {
|
||||
gpath.closePath();
|
||||
}
|
||||
if (auxPath != null) {
|
||||
gpath.append(auxPath, false);
|
||||
}
|
||||
drawShape(gpath);
|
||||
}
|
||||
}
|
||||
shape = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
// CLIPPING
|
||||
|
||||
@@ -618,7 +618,9 @@ public class PShape implements PConstants {
|
||||
|
||||
|
||||
protected void beginContourImpl() {
|
||||
if (vertexCodes.length == vertexCodeCount) {
|
||||
if (vertexCodes == null) {
|
||||
vertexCodes = new int[10];
|
||||
} else if (vertexCodes.length == vertexCodeCount) {
|
||||
vertexCodes = PApplet.expand(vertexCodes);
|
||||
}
|
||||
vertexCodes[vertexCodeCount++] = BREAK;
|
||||
|
||||
@@ -2363,7 +2363,7 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
if (normalMode == NORMAL_MODE_AUTO) inGeo.calcQuadStripNormals();
|
||||
tessellator.tessellateQuadStrip();
|
||||
} else if (shape == POLYGON) {
|
||||
tessellator.tessellatePolygon(false, mode == CLOSE,
|
||||
tessellator.tessellatePolygon(true, mode == CLOSE,
|
||||
normalMode == NORMAL_MODE_AUTO);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ public class PShapeOpenGL extends PShape {
|
||||
protected boolean needBufferInit = false;
|
||||
|
||||
// Flag to indicate if the shape can have holes or not.
|
||||
protected boolean solid;
|
||||
protected boolean solid = true;
|
||||
|
||||
protected boolean breakShape = false;
|
||||
protected boolean shapeCreated = false;
|
||||
@@ -2995,7 +2995,7 @@ public class PShapeOpenGL extends PShape {
|
||||
if (rounded) {
|
||||
saveBezierVertexSettings();
|
||||
inGeo.addRect(a, b, c, d, tl, tr, br, bl, stroke);
|
||||
tessellator.tessellatePolygon(false, true, true);
|
||||
tessellator.tessellatePolygon(true, true, true);
|
||||
restoreBezierVertexSettings();
|
||||
} else {
|
||||
inGeo.addRect(a, b, c, d, stroke);
|
||||
@@ -3289,7 +3289,7 @@ public class PShapeOpenGL extends PShape {
|
||||
saveCurveVertexSettings();
|
||||
tessellator.resetCurveVertexCount();
|
||||
}
|
||||
tessellator.tessellatePolygon(false, close, true);
|
||||
tessellator.tessellatePolygon(true, close, true);
|
||||
if (bez || quad) restoreBezierVertexSettings();
|
||||
if (curv) restoreCurveVertexSettings();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user