Skip to content

Commit 8915c48

Browse files
authored
Merge pull request #636 from hx2A/macos-javafx
Macos javafx
2 parents 62d935d + 1e2fa84 commit 8915c48

File tree

5 files changed

+24
-8
lines changed

5 files changed

+24
-8
lines changed

py5_jar/src/main/java/py5/core/Sketch.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,12 @@ public void setup() {
190190
if (success) {
191191
PSurface surface = getSurface();
192192

193-
// request focus for Java2D renderer on Windows and MacOS
194-
if (platform == WINDOWS && sketchRenderer().equals(JAVA2D)) {
193+
// request focus for Java2D and FX2D renderers on Windows and MacOS
194+
if (platform == WINDOWS && (sketchRenderer().equals(JAVA2D) || sketchRenderer().equals(FX2D))) {
195195
Canvas canvas = (Canvas) surface.getNative();
196196
canvas.setFocusable(true);
197197
canvas.requestFocus();
198-
} else if (platform == MACOS && (sketchRenderer().equals(JAVA2D) || g.isGL())) {
198+
} else if (platform == MACOS && (sketchRenderer().equals(JAVA2D) || sketchRenderer().equals(FX2D) || g.isGL())) {
199199
ThinkDifferent.activateSketchWindow();
200200
}
201201

@@ -261,7 +261,8 @@ public void draw() {
261261
}
262262

263263
if (frameCount == 1 && platform == LINUX && g.isGL()) {
264-
// Linux with KDE Plasma window manager and OpenGL need to capture pixels after the last draw() call
264+
// Linux with KDE Plasma window manager and OpenGL need to capture pixels after
265+
// the last draw() call
265266
capturePixels();
266267
}
267268
}

py5_resources/py5_module/py5/render_helper.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,16 @@ def draw(self):
129129
def _check_allowed_renderer(renderer):
130130
renderer_name = {
131131
Sketch.SVG: "SVG",
132+
Sketch.FX2D: "FX2D",
132133
Sketch.PDF: "PDF",
133134
Sketch.DXF: "DXF",
134135
Sketch.P2D: "P2D",
135136
Sketch.P3D: "P3D",
136137
}.get(renderer, renderer)
137138
renderers = (
138-
[Sketch.HIDDEN, Sketch.JAVA2D]
139+
[Sketch.HIDDEN, Sketch.JAVA2D, Sketch.FX2D]
139140
if sys.platform == "darwin"
140-
else [Sketch.HIDDEN, Sketch.JAVA2D, Sketch.P2D, Sketch.P3D]
141+
else [Sketch.HIDDEN, Sketch.JAVA2D, Sketch.FX2D, Sketch.P2D, Sketch.P3D]
141142
)
142143
if renderer not in renderers:
143144
return (

py5_resources/py5_module/py5/test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ def test_java2d():
5656
test.run_sketch()
5757

5858

59+
def test_fx2d():
60+
test = RendererTest(Sketch.FX2D, "FX2D")
61+
test.run_sketch()
62+
63+
5964
def test_p2d():
6065
test = RendererTest(Sketch.P2D, "P2D")
6166
test.run_sketch()
@@ -91,6 +96,11 @@ def test_interactivity_java2d():
9196
test.run_sketch()
9297

9398

99+
def test_interactivity_fx2d():
100+
test = TestInteractivity(Sketch.FX2D, "FX2D")
101+
test.run_sketch()
102+
103+
94104
def test_interactivity_p2d():
95105
test = TestInteractivity(Sketch.P2D, "P2D")
96106
test.run_sketch()

py5_resources/py5_module/py5_tools/imported.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ def _run_sketch(sketch_path, classpath, exit_if_error):
223223
jvm.add_jars(sketch_path.parent / "jars")
224224

225225
set_imported_mode(True)
226+
try:
227+
import py5javafx
228+
except ImportError:
229+
pass
226230
import py5
227231

228232
if py5.is_running() if callable(py5.is_running) else py5.is_running:

py5_resources/py5_module/py5_tools/magics/drawing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ def py5draw(self, line, cell):
295295
args = parse_argstring(self.py5draw, line)
296296

297297
if sys.platform == "darwin":
298-
if args.renderer in ["P2D", "P3D", "DXF"]:
298+
if args.renderer in ["P2D", "P3D", "FX2D", "DXF"]:
299299
print(
300300
f"Sorry, py5 magics do not support the {args.renderer} renderer on macOS.",
301301
file=sys.stderr,
@@ -312,7 +312,7 @@ def py5draw(self, line, cell):
312312
if args.renderer == "PDF":
313313
print("please use %%py5drawpdf for PDFs.", file=sys.stderr)
314314
return
315-
if args.renderer not in ["HIDDEN", "JAVA2D", "P2D", "P3D"]:
315+
if args.renderer not in ["HIDDEN", "JAVA2D", "P2D", "P3D", "FX2D"]:
316316
print(f"unknown renderer {args.renderer}", file=sys.stderr)
317317
return
318318

0 commit comments

Comments
 (0)