Skip to content

Commit f7b8c29

Browse files
committed
make offscreen FX2D work, based on processing/processing#4698 from @GKFX
1 parent a098c13 commit f7b8c29

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

src/processing/javafx/PGraphicsFX2D.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.util.Map;
3434

3535
import javafx.scene.SnapshotParameters;
36+
import javafx.scene.canvas.Canvas;
3637
import javafx.scene.canvas.GraphicsContext;
3738
import javafx.scene.effect.BlendMode;
3839
import javafx.scene.image.PixelFormat;
@@ -112,7 +113,12 @@ public PGraphicsFX2D() { }
112113
//public void setPath(String path)
113114

114115

115-
//public void setSize(int width, int height)
116+
public void setSize(int width, int height) {
117+
if (!primaryGraphics && context == null) {
118+
context = new Canvas(width, height).getGraphicsContext2D();
119+
}
120+
super.setSize(width, height);
121+
}
116122

117123

118124
//public void dispose()
@@ -157,6 +163,8 @@ public void endDraw() {
157163
if (!primaryGraphics) {
158164
// TODO this is probably overkill for most tasks...
159165
loadPixels();
166+
// Make the image cache reload this.
167+
modified = true;
160168
}
161169
}
162170

@@ -2156,12 +2164,15 @@ public void loadPixels() {
21562164
snapshotImage = new WritableImage(pixelWidth, pixelHeight);
21572165
}
21582166

2159-
SnapshotParameters sp = null;
2167+
SnapshotParameters sp = new SnapshotParameters();
2168+
if (!primaryGraphics) {
2169+
// Alpha channel should not be made white (but only if offscreen)
2170+
sp.setFill(Color.TRANSPARENT);
2171+
}
21602172
if (pixelDensity != 1) {
2161-
sp = new SnapshotParameters();
21622173
sp.setTransform(Transform.scale(pixelDensity, pixelDensity));
21632174
}
2164-
snapshotImage = ((PSurfaceFX) surface).canvas.snapshot(sp, snapshotImage);
2175+
snapshotImage = context.getCanvas().snapshot(sp, snapshotImage);
21652176
PixelReader pr = snapshotImage.getPixelReader();
21662177
pr.getPixels(0, 0, pixelWidth, pixelHeight, argbFormat, pixels, 0, pixelWidth);
21672178

todo.txt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
1279 (4.0b4)
2+
o "Tint on FX2D now works properly, and improved JavaFX/Scenebuilder integration"
3+
o https://github.com/processing/processing/pull/6051
4+
X contains too many arbitrary changes (deleted lines, fields made public)
5+
X uses new image cache object, not clear why
6+
X cache mechanism would make memory run out
27

8+
contribs
9+
X make offscreen PGraphicsFX2D work (from @GKFX)
10+
X https://github.com/processing/processing/issues/4638
11+
X https://github.com/processing/processing/pull/4698
312

4-
possible additions for 4.x?
5-
_ Tint on FX2D now works properly, and improved JavaFX/Scenebuilder integration
6-
_ https://github.com/processing/processing/pull/6051
7-
_ make offscreen PGraphicsFX2D work
8-
_ https://github.com/processing/processing/issues/4638
9-
_ https://github.com/processing/processing/pull/4698
1013

11-
12-
api
14+
getting away from reliance on AWT
1315
_ better JavaFX-specific ways to handle loadImage()?
1416
_ https://github.com/processing/processing4/issues/56
1517
_ implement selectInput/Output/Folder methods in PSurfaceFX

0 commit comments

Comments
 (0)