Skip to content

Commit c0fd308

Browse files
committed
going full factory with this f*ker
1 parent 725b3ba commit c0fd308

File tree

3 files changed

+91
-77
lines changed

3 files changed

+91
-77
lines changed

core/src/processing/awt/PShapeJava2D.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ public PShapeJava2D(XML svg) {
5353
}
5454

5555

56+
public PShapeJava2D(PShapeSVG parent, XML properties, boolean parseKids) {
57+
super(parent, properties, parseKids);
58+
}
59+
60+
5661
@Override
5762
protected void setParent(PShapeSVG parent) {
5863
if (parent instanceof PShapeJava2D) {
@@ -67,6 +72,15 @@ protected void setParent(PShapeSVG parent) {
6772
}
6873

6974

75+
/** Factory method for subclasses. */
76+
@Override
77+
protected PShapeSVG createShape(PShapeSVG parent, XML properties, boolean parseKids) {
78+
return new PShapeJava2D(parent, properties, parseKids);
79+
}
80+
81+
82+
83+
7084
static class LinearGradientPaint implements Paint {
7185
float x1, y1, x2, y2;
7286
float[] offset;
@@ -272,12 +286,14 @@ public Raster getRaster(int x, int y, int w, int h) {
272286

273287
protected Paint calcGradientPaint(Gradient gradient) {
274288
if (gradient instanceof LinearGradient) {
289+
System.out.println("creating linear gradient");
275290
LinearGradient grad = (LinearGradient) gradient;
276291
return new LinearGradientPaint(grad.x1, grad.y1, grad.x2, grad.y2,
277292
grad.offset, grad.color, grad.count,
278293
opacity);
279294

280295
} else if (gradient instanceof RadialGradient) {
296+
System.out.println("creating radial gradient");
281297
RadialGradient grad = (RadialGradient) gradient;
282298
return new RadialGradientPaint(grad.cx, grad.cy, grad.r,
283299
grad.offset, grad.color, grad.count,

core/src/processing/core/PShapeSVG.java

Lines changed: 73 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -137,64 +137,6 @@ public PShapeSVG(XML svg) {
137137
}
138138

139139

140-
// Broken out so that subclasses can copy any additional variables
141-
// (i.e. fillGradientPaint and strokeGradientPaint)
142-
protected void setParent(PShapeSVG parent) {
143-
// Need to set this so that findChild() works.
144-
// Otherwise 'parent' is null until addChild() is called later.
145-
this.parent = parent;
146-
147-
if (parent == null) {
148-
// set values to their defaults according to the SVG spec
149-
stroke = false;
150-
strokeColor = 0xff000000;
151-
strokeWeight = 1;
152-
strokeCap = PConstants.SQUARE; // equivalent to BUTT in svg spec
153-
strokeJoin = PConstants.MITER;
154-
strokeGradient = null;
155-
// strokeGradientPaint = null;
156-
strokeName = null;
157-
158-
fill = true;
159-
fillColor = 0xff000000;
160-
fillGradient = null;
161-
// fillGradientPaint = null;
162-
fillName = null;
163-
164-
//hasTransform = false;
165-
//transformation = null; //new float[] { 1, 0, 0, 1, 0, 0 };
166-
167-
// svgWidth, svgHeight, and svgXYSize done below.
168-
169-
strokeOpacity = 1;
170-
fillOpacity = 1;
171-
opacity = 1;
172-
173-
} else {
174-
stroke = parent.stroke;
175-
strokeColor = parent.strokeColor;
176-
strokeWeight = parent.strokeWeight;
177-
strokeCap = parent.strokeCap;
178-
strokeJoin = parent.strokeJoin;
179-
strokeGradient = parent.strokeGradient;
180-
// strokeGradientPaint = parent.strokeGradientPaint;
181-
strokeName = parent.strokeName;
182-
183-
fill = parent.fill;
184-
fillColor = parent.fillColor;
185-
fillGradient = parent.fillGradient;
186-
// fillGradientPaint = parent.fillGradientPaint;
187-
fillName = parent.fillName;
188-
189-
svgWidth = parent.svgWidth;
190-
svgHeight = parent.svgHeight;
191-
svgXYSize = parent.svgXYSize;
192-
193-
opacity = parent.opacity;
194-
}
195-
}
196-
197-
198140
protected PShapeSVG(PShapeSVG parent, XML properties, boolean parseKids) {
199141
setParent(parent);
200142

@@ -280,6 +222,70 @@ protected PShapeSVG(PShapeSVG parent, XML properties, boolean parseKids) {
280222
}
281223

282224

225+
// Broken out so that subclasses can copy any additional variables
226+
// (i.e. fillGradientPaint and strokeGradientPaint)
227+
protected void setParent(PShapeSVG parent) {
228+
// Need to set this so that findChild() works.
229+
// Otherwise 'parent' is null until addChild() is called later.
230+
this.parent = parent;
231+
232+
if (parent == null) {
233+
// set values to their defaults according to the SVG spec
234+
stroke = false;
235+
strokeColor = 0xff000000;
236+
strokeWeight = 1;
237+
strokeCap = PConstants.SQUARE; // equivalent to BUTT in svg spec
238+
strokeJoin = PConstants.MITER;
239+
strokeGradient = null;
240+
// strokeGradientPaint = null;
241+
strokeName = null;
242+
243+
fill = true;
244+
fillColor = 0xff000000;
245+
fillGradient = null;
246+
// fillGradientPaint = null;
247+
fillName = null;
248+
249+
//hasTransform = false;
250+
//transformation = null; //new float[] { 1, 0, 0, 1, 0, 0 };
251+
252+
// svgWidth, svgHeight, and svgXYSize done below.
253+
254+
strokeOpacity = 1;
255+
fillOpacity = 1;
256+
opacity = 1;
257+
258+
} else {
259+
stroke = parent.stroke;
260+
strokeColor = parent.strokeColor;
261+
strokeWeight = parent.strokeWeight;
262+
strokeCap = parent.strokeCap;
263+
strokeJoin = parent.strokeJoin;
264+
strokeGradient = parent.strokeGradient;
265+
// strokeGradientPaint = parent.strokeGradientPaint;
266+
strokeName = parent.strokeName;
267+
268+
fill = parent.fill;
269+
fillColor = parent.fillColor;
270+
fillGradient = parent.fillGradient;
271+
// fillGradientPaint = parent.fillGradientPaint;
272+
fillName = parent.fillName;
273+
274+
svgWidth = parent.svgWidth;
275+
svgHeight = parent.svgHeight;
276+
svgXYSize = parent.svgXYSize;
277+
278+
opacity = parent.opacity;
279+
}
280+
}
281+
282+
283+
/** Factory method for subclasses. */
284+
protected PShapeSVG createShape(PShapeSVG parent, XML properties, boolean parseKids) {
285+
return new PShapeSVG(parent, properties, parseKids);
286+
}
287+
288+
283289
protected void parseChildren(XML graphics) {
284290
XML[] elements = graphics.getChildren();
285291
children = new PShape[elements.length];
@@ -307,49 +313,39 @@ protected PShape parseChild(XML elem) {
307313
// just some whitespace that can be ignored (hopefully)
308314

309315
} else if (name.equals("g")) {
310-
//return new BaseObject(this, elem);
311-
shape = new PShapeSVG(this, elem, true);
316+
shape = createShape(this, elem, true);
312317

313318
} else if (name.equals("defs")) {
314319
// generally this will contain gradient info, so may
315320
// as well just throw it into a group element for parsing
316-
//return new BaseObject(this, elem);
317-
shape = new PShapeSVG(this, elem, true);
321+
shape = createShape(this, elem, true);
318322

319323
} else if (name.equals("line")) {
320-
//return new Line(this, elem);
321-
//return new BaseObject(this, elem, LINE);
322-
shape = new PShapeSVG(this, elem, true);
324+
shape = createShape(this, elem, true);
323325
shape.parseLine();
324326

325327
} else if (name.equals("circle")) {
326-
//return new BaseObject(this, elem, ELLIPSE);
327-
shape = new PShapeSVG(this, elem, true);
328+
shape = createShape(this, elem, true);
328329
shape.parseEllipse(true);
329330

330331
} else if (name.equals("ellipse")) {
331-
//return new BaseObject(this, elem, ELLIPSE);
332-
shape = new PShapeSVG(this, elem, true);
332+
shape = createShape(this, elem, true);
333333
shape.parseEllipse(false);
334334

335335
} else if (name.equals("rect")) {
336-
//return new BaseObject(this, elem, RECT);
337-
shape = new PShapeSVG(this, elem, true);
336+
shape = createShape(this, elem, true);
338337
shape.parseRect();
339338

340339
} else if (name.equals("polygon")) {
341-
//return new BaseObject(this, elem, POLYGON);
342-
shape = new PShapeSVG(this, elem, true);
340+
shape = createShape(this, elem, true);
343341
shape.parsePoly(true);
344342

345343
} else if (name.equals("polyline")) {
346-
//return new BaseObject(this, elem, POLYGON);
347-
shape = new PShapeSVG(this, elem, true);
344+
shape = createShape(this, elem, true);
348345
shape.parsePoly(false);
349346

350347
} else if (name.equals("path")) {
351-
//return new BaseObject(this, elem, PATH);
352-
shape = new PShapeSVG(this, elem, true);
348+
shape = createShape(this, elem, true);
353349
shape.parsePath();
354350

355351
} else if (name.equals("radialGradient")) {

core/todo.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ _ update wiki/docs to say "don't override sketchXxxx() methods"
115115

116116

117117
beta
118+
_ gradients currently broken for Java2D
119+
_ https://github.com/processing/processing/issues/3417
118120
_ run only the necessary pieces on the EDT
119121
_ in part because FX doesn't even use the EDT
120122
_ re-check the Linux frame visibility stuff

0 commit comments

Comments
 (0)