Skip to content

Commit 056bbae

Browse files
committed
initial PShape implementation for JAVA2D
1 parent f1afce5 commit 056bbae

File tree

2 files changed

+204
-1
lines changed

2 files changed

+204
-1
lines changed

core/src/processing/core/PGraphicsJava2D.java

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,118 @@ public void hint(int which) {
470470
// SHAPES
471471

472472

473-
//public void beginShape(int kind)
473+
//////////////////////////////////////////////////////////////
474+
475+
// SHAPE CREATION
476+
477+
478+
// @Override
479+
// public PShape createShape(PShape source) {
480+
// return PShapeOpenGL.createShape2D(this, source);
481+
// }
482+
483+
484+
@Override
485+
public PShape createShape() {
486+
return createShape(PShape.GEOMETRY);
487+
}
488+
489+
490+
@Override
491+
public PShape createShape(int type) {
492+
return createShapeImpl(this, type);
493+
}
494+
495+
496+
@Override
497+
public PShape createShape(int kind, float... p) {
498+
return createShapeImpl(this, kind, p);
499+
}
500+
501+
502+
static protected PShape createShapeImpl(PGraphicsJava2D pg, int type) {
503+
PShape shape = null;
504+
if (type == PConstants.GROUP) {
505+
shape = new PShape(pg, PConstants.GROUP);
506+
} else if (type == PShape.PATH) {
507+
shape = new PShape(pg, PShape.PATH);
508+
} else if (type == PShape.GEOMETRY) {
509+
shape = new PShape(pg, PShape.GEOMETRY);
510+
}
511+
shape.is3D(false);
512+
return shape;
513+
}
514+
515+
516+
static protected PShape createShapeImpl(PGraphicsJava2D pg,
517+
int kind, float... p) {
518+
PShape shape = null;
519+
int len = p.length;
520+
521+
if (kind == POINT) {
522+
if (len != 2) {
523+
showWarning("Wrong number of parameters");
524+
return null;
525+
}
526+
shape = new PShape(pg, PShape.PRIMITIVE);
527+
shape.setKind(POINT);
528+
} else if (kind == LINE) {
529+
if (len != 4) {
530+
showWarning("Wrong number of parameters");
531+
return null;
532+
}
533+
shape = new PShape(pg, PShape.PRIMITIVE);
534+
shape.setKind(LINE);
535+
} else if (kind == TRIANGLE) {
536+
if (len != 6) {
537+
showWarning("Wrong number of parameters");
538+
return null;
539+
}
540+
shape = new PShape(pg, PShape.PRIMITIVE);
541+
shape.setKind(TRIANGLE);
542+
} else if (kind == QUAD) {
543+
if (len != 8) {
544+
showWarning("Wrong number of parameters");
545+
return null;
546+
}
547+
shape = new PShape(pg, PShape.PRIMITIVE);
548+
shape.setKind(QUAD);
549+
} else if (kind == RECT) {
550+
if (len != 4 && len != 5 && len != 8 && len != 9) {
551+
showWarning("Wrong number of parameters");
552+
return null;
553+
}
554+
shape = new PShape(pg, PShape.PRIMITIVE);
555+
shape.setKind(RECT);
556+
} else if (kind == ELLIPSE) {
557+
if (len != 4 && len != 5) {
558+
showWarning("Wrong number of parameters");
559+
return null;
560+
}
561+
shape = new PShape(pg, PShape.PRIMITIVE);
562+
shape.setKind(ELLIPSE);
563+
} else if (kind == ARC) {
564+
if (len != 6 && len != 7) {
565+
showWarning("Wrong number of parameters");
566+
return null;
567+
}
568+
shape = new PShape(pg, PShape.PRIMITIVE);
569+
shape.setKind(ARC);
570+
} else if (kind == BOX) {
571+
showWarning("Primitive not supported in 2D");
572+
} else if (kind == SPHERE) {
573+
showWarning("Primitive not supported in 2D");
574+
} else {
575+
showWarning("Unrecognized primitive type");
576+
}
577+
578+
if (shape != null) {
579+
shape.setParams(p);
580+
}
581+
582+
shape.is3D(false);
583+
return shape;
584+
}
474585

475586

476587
@Override

core/src/processing/core/PShape.java

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.HashMap;
2626

2727
import processing.core.PApplet;
28+
import processing.core.PGraphicsJava2D;
2829

2930

3031
/**
@@ -274,6 +275,97 @@ public PShape(int family) {
274275
this.family = family;
275276
}
276277

278+
public PShape(PGraphicsJava2D pg, int family) {
279+
// this.g = pg;
280+
// pgl = pg.pgl;
281+
// context = pgl.createEmptyContext();
282+
283+
// glPolyVertex = 0;
284+
// glPolyColor = 0;
285+
// glPolyNormal = 0;
286+
// glPolyTexcoord = 0;
287+
// glPolyAmbient = 0;
288+
// glPolySpecular = 0;
289+
// glPolyEmissive = 0;
290+
// glPolyShininess = 0;
291+
// glPolyIndex = 0;
292+
//
293+
// glLineVertex = 0;
294+
// glLineColor = 0;
295+
// glLineAttrib = 0;
296+
// glLineIndex = 0;
297+
//
298+
// glPointVertex = 0;
299+
// glPointColor = 0;
300+
// glPointAttrib = 0;
301+
// glPointIndex = 0;
302+
//
303+
// this.tessellator = PGraphicsOpenGL.tessellator;
304+
this.family = family;
305+
// this.root = this;
306+
this.parent = null;
307+
// this.tessellated = false;
308+
309+
// if (family == GEOMETRY || family == PRIMITIVE || family == PATH) {
310+
// inGeo = PGraphicsOpenGL.newInGeometry(pg, PGraphicsOpenGL.RETAINED);
311+
// }
312+
313+
// Style parameters are retrieved from the current values in the renderer.
314+
textureMode = pg.textureMode;
315+
316+
colorMode(pg.colorMode,
317+
pg.colorModeX, pg.colorModeY, pg.colorModeZ, pg.colorModeA);
318+
319+
// Initial values for fill, stroke and tint colors are also imported from
320+
// the renderer. This is particular relevant for primitive shapes, since is
321+
// not possible to set their color separately when creating them, and their
322+
// input vertices are actually generated at rendering time, by which the
323+
// color configuration of the renderer might have changed.
324+
fill = pg.fill;
325+
fillColor = pg.fillColor;
326+
327+
stroke = pg.stroke;
328+
strokeColor = pg.strokeColor;
329+
strokeWeight = pg.strokeWeight;
330+
strokeCap = pg.strokeCap;
331+
strokeJoin = pg.strokeJoin;
332+
333+
tint = pg.tint;
334+
tintColor = pg.tintColor;
335+
336+
setAmbient = pg.setAmbient;
337+
ambientColor = pg.ambientColor;
338+
specularColor = pg.specularColor;
339+
emissiveColor = pg.emissiveColor;
340+
shininess = pg.shininess;
341+
342+
sphereDetailU = pg.sphereDetailU;
343+
sphereDetailV = pg.sphereDetailV;
344+
345+
// bezierDetail = pg.bezierDetail;
346+
// curveDetail = pg.curveDetail;
347+
// curveTightness = pg.curveTightness;
348+
349+
// The rect and ellipse modes are set to CORNER since it is the expected
350+
// mode for svg shapes.
351+
rectMode = CORNER;
352+
ellipseMode = CORNER;
353+
354+
// normalX = normalY = 0;
355+
// normalZ = 1;
356+
//
357+
// normalMode = NORMAL_MODE_AUTO;
358+
359+
// To make sure that the first vertex is marked as a break.
360+
// Same behavior as in the immediate mode.
361+
// breakShape = false;
362+
363+
if (family == GROUP) {
364+
// GROUP shapes are always marked as ended.
365+
// shapeCreated = true;
366+
}
367+
}
368+
277369

278370
public void setKind(int kind) {
279371
this.kind = kind;

0 commit comments

Comments
 (0)