From 83709d2c3e20ed032255932c517315b11c2e457f Mon Sep 17 00:00:00 2001 From: codeanticode Date: Wed, 13 May 2015 20:36:35 -0400 Subject: [PATCH] added present mode to jogl library --- .../src/processing/jogl/PSurfaceJOGL.java | 75 ++++++++++++------- 1 file changed, 49 insertions(+), 26 deletions(-) diff --git a/java/libraries/jogl/src/processing/jogl/PSurfaceJOGL.java b/java/libraries/jogl/src/processing/jogl/PSurfaceJOGL.java index e3d4383b9..04869a85b 100644 --- a/java/libraries/jogl/src/processing/jogl/PSurfaceJOGL.java +++ b/java/libraries/jogl/src/processing/jogl/PSurfaceJOGL.java @@ -65,30 +65,24 @@ public class PSurfaceJOGL implements PSurface { this.pgl = (PJOGL) ((PGraphicsOpenGL)graphics).pgl; } + public void initOffscreen(PApplet sketch) { - // TODO Auto-generated method stub - } - - - /* - public Canvas initComponent(PApplet sketch) { - this.sketch = sketch; - - sketchWidth = sketch.sketchWidth(); - sketchHeight = sketch.sketchHeight(); - - if (window != null) { - canvas = new NewtCanvasAWT(window); - canvas.setBounds(0, 0, window.getWidth(), window.getHeight()); +// this.sketch = sketch; +// +// sketchWidth = sketch.sketchWidth(); +// sketchHeight = sketch.sketchHeight(); +// +// if (window != null) { +// canvas = new NewtCanvasAWT(window); +// canvas.setBounds(0, 0, window.getWidth(), window.getHeight()); // canvas.setBackground(new Color(pg.backgroundColor, true)); - canvas.setFocusable(true); - - return canvas; - } - - return null; +// canvas.setFocusable(true); +// +// return canvas; +// } +// +// return null; } - */ public void initFrame(PApplet sketch, int backgroundColor, @@ -194,7 +188,8 @@ public class PSurfaceJOGL implements PSurface { fullScreen = true; } - if (fullScreen || spanDisplays) { +// if (fullScreen || spanDisplays) { + if (spanDisplays) { sketchWidth = screenRect.width; sketchHeight = screenRect.height; } @@ -210,6 +205,7 @@ public class PSurfaceJOGL implements PSurface { // This example could be useful: // com.jogamp.opengl.test.junit.newt.mm.TestScreenMode01cNEWT if (fullScreen) { + PApplet.hideMenuBar(); if (spanDisplays) { window.setFullscreen(monitors); } else { @@ -379,9 +375,18 @@ public class PSurfaceJOGL implements PSurface { } - public void placePresent(int stopColor) { - // TODO Auto-generated method stub - + boolean presentMode = false; + float offsetX; + float offsetY; + public void placePresent(int stopColor) { + if (sketchWidth < screenRect.width || sketchHeight < screenRect.height) { + System.err.println("Present mode"); +// System.err.println("WILL USE FBO"); + presentMode = pgl.presentMode = true; + offsetX = pgl.offsetX = 0.5f * (screenRect.width - sketchWidth); + offsetY = pgl.offsetY = 0.5f * (screenRect.height - sketchHeight); + pgl.requestFBOLayer(); + } } public void setupExternalMessages() { @@ -627,9 +632,27 @@ public class PSurfaceJOGL implements PSurface { peCount = nativeEvent.getClickCount(); } + + if (presentMode) { + if (20 < nativeEvent.getX() && nativeEvent.getX() < 20 + 100 && + screenRect.height - 70 < nativeEvent.getY() && nativeEvent.getY() < screenRect.height - 20) { + System.err.println("clicked on exit button"); +// if (externalMessages) { +// System.err.println(PApplet.EXTERNAL_QUIT); +// System.err.flush(); // important +// } + animator.stop(); + PSurfaceJOGL.this.sketch.exit(); + window.destroy(); + } + } + + int x = nativeEvent.getX() - (int)offsetX; + int y = nativeEvent.getY() - (int)offsetY; + MouseEvent me = new MouseEvent(nativeEvent, nativeEvent.getWhen(), peAction, peModifiers, - nativeEvent.getX(), nativeEvent.getY(), + x, y, peButton, peCount);