diff options
Diffstat (limited to 'src')
4 files changed, 75 insertions, 59 deletions
diff --git a/src/newt/classes/com/jogamp/newt/opengl/util/NEWTDemoListener.java b/src/newt/classes/com/jogamp/newt/opengl/util/NEWTDemoListener.java index ca4b51192..2444067d2 100644 --- a/src/newt/classes/com/jogamp/newt/opengl/util/NEWTDemoListener.java +++ b/src/newt/classes/com/jogamp/newt/opengl/util/NEWTDemoListener.java @@ -28,7 +28,10 @@ package com.jogamp.newt.opengl.util; import java.net.URLConnection; +import java.util.ArrayList; +import java.util.List; +import com.jogamp.common.ExceptionUtils; import com.jogamp.common.util.IOUtil; import com.jogamp.nativewindow.CapabilitiesImmutable; import com.jogamp.nativewindow.ScalableSurface; @@ -65,7 +68,7 @@ public class NEWTDemoListener extends WindowAdapter implements KeyListener, Mous if( null != pointerIcons ) { this.pointerIcons = pointerIcons; } else { - this.pointerIcons = createPointerIcons(glWindow); + this.pointerIcons = createPointerIcons(glWindow.getScreen().getDisplay()); } } public NEWTDemoListener(final GLWindow glWin) { @@ -424,76 +427,69 @@ public class NEWTDemoListener extends WindowAdapter implements KeyListener, Mous win.setTitle("GLWindow["+capsA+"], win: "+win.getBounds()+", pix: "+win.getSurfaceWidth()+"x"+win.getSurfaceHeight()+", sDPI "+sDPI[0]+" x "+sDPI[1]); } - public static PointerIcon[] createPointerIcons(final GLWindow glWindow) { - final PointerIcon[] pointerIcons = { null, null, null, null, null }; + public static PointerIcon[] createPointerIcons(final Display disp) { + final List<PointerIcon> pointerIcons = new ArrayList<PointerIcon>(); { - final Display disp = glWindow.getScreen().getDisplay(); disp.createNative(); - int idx = 0; { PointerIcon _pointerIcon = null; - final IOUtil.ClassResources res = new IOUtil.ClassResources(glWindow.getClass(), new String[] { "newt/data/cross-grey-alpha-16x16.png" } ); + final IOUtil.ClassResources res = new IOUtil.ClassResources(disp.getClass(), new String[] { "newt/data/cross-grey-alpha-16x16.png" } ); try { _pointerIcon = disp.createPointerIcon(res, 8, 8); - System.err.printf("Create PointerIcon #%02d: %s%n", idx, _pointerIcon.toString()); + pointerIcons.add(_pointerIcon); + System.err.printf("Create PointerIcon #%02d: %s%n", pointerIcons.size(), _pointerIcon.toString()); } catch (final Exception e) { - e.printStackTrace(); + ExceptionUtils.dumpThrowable("", e); } - pointerIcons[idx] = _pointerIcon; } - idx++; { PointerIcon _pointerIcon = null; - final IOUtil.ClassResources res = new IOUtil.ClassResources(glWindow.getClass(), new String[] { "newt/data/pointer-grey-alpha-16x24.png" } ); + final IOUtil.ClassResources res = new IOUtil.ClassResources(disp.getClass(), new String[] { "newt/data/pointer-grey-alpha-16x24.png" } ); try { _pointerIcon = disp.createPointerIcon(res, 0, 0); - System.err.printf("Create PointerIcon #%02d: %s%n", idx, _pointerIcon.toString()); + pointerIcons.add(_pointerIcon); + System.err.printf("Create PointerIcon #%02d: %s%n", pointerIcons.size(), _pointerIcon.toString()); } catch (final Exception e) { - e.printStackTrace(); + ExceptionUtils.dumpThrowable("", e); } - pointerIcons[idx] = _pointerIcon; } - idx++; { PointerIcon _pointerIcon = null; - final IOUtil.ClassResources res = new IOUtil.ClassResources(glWindow.getClass(), new String[] { "arrow-red-alpha-64x64.png" } ); + final IOUtil.ClassResources res = new IOUtil.ClassResources(disp.getClass(), new String[] { "arrow-red-alpha-64x64.png" } ); try { _pointerIcon = disp.createPointerIcon(res, 0, 0); - System.err.printf("Create PointerIcon #%02d: %s%n", idx, _pointerIcon.toString()); + pointerIcons.add(_pointerIcon); + System.err.printf("Create PointerIcon #%02d: %s%n", pointerIcons.size(), _pointerIcon.toString()); } catch (final Exception e) { - e.printStackTrace(); + ExceptionUtils.dumpThrowable("", e); } - pointerIcons[idx] = _pointerIcon; } - idx++; { PointerIcon _pointerIcon = null; - final IOUtil.ClassResources res = new IOUtil.ClassResources(glWindow.getClass(), new String[] { "arrow-blue-alpha-64x64.png" } ); + final IOUtil.ClassResources res = new IOUtil.ClassResources(disp.getClass(), new String[] { "arrow-blue-alpha-64x64.png" } ); try { _pointerIcon = disp.createPointerIcon(res, 0, 0); - System.err.printf("Create PointerIcon #%02d: %s%n", idx, _pointerIcon.toString()); + pointerIcons.add(_pointerIcon); + System.err.printf("Create PointerIcon #%02d: %s%n", pointerIcons.size(), _pointerIcon.toString()); } catch (final Exception e) { - e.printStackTrace(); + ExceptionUtils.dumpThrowable("", e); } - pointerIcons[idx] = _pointerIcon; } - idx++; if( PNGIcon.isAvailable() ) { PointerIcon _pointerIcon = null; - final IOUtil.ClassResources res = new IOUtil.ClassResources(glWindow.getClass(), new String[] { "jogamp-pointer-64x64.png" } ); + final IOUtil.ClassResources res = new IOUtil.ClassResources(disp.getClass(), new String[] { "jogamp-pointer-64x64.png" } ); try { final URLConnection urlConn = res.resolve(0); final PNGPixelRect image = PNGPixelRect.read(urlConn.getInputStream(), null, false /* directBuffer */, 0 /* destMinStrideInBytes */, false /* destIsGLOriented */); - System.err.printf("Create PointerIcon #%02d: %s%n", idx, image.toString()); + System.err.printf("Create PointerIcon #%02d: %s%n", pointerIcons.size()+1, image.toString()); _pointerIcon = disp.createPointerIcon(image, 32, 0); - System.err.printf("Create PointerIcon #%02d: %s%n", idx, _pointerIcon.toString()); + pointerIcons.add(_pointerIcon); + System.err.printf("Create PointerIcon #%02d: %s%n", pointerIcons.size(), _pointerIcon.toString()); } catch (final Exception e) { - e.printStackTrace(); + ExceptionUtils.dumpThrowable("", e); } - pointerIcons[idx] = _pointerIcon; } - idx++; } - return pointerIcons; + return pointerIcons.toArray(new PointerIcon[pointerIcons.size()]); } }
\ No newline at end of file diff --git a/src/newt/classes/com/jogamp/newt/util/applet/JOGLNewtAppletBase.java b/src/newt/classes/com/jogamp/newt/util/applet/JOGLNewtAppletBase.java index e02e02013..5194d9416 100644 --- a/src/newt/classes/com/jogamp/newt/util/applet/JOGLNewtAppletBase.java +++ b/src/newt/classes/com/jogamp/newt/util/applet/JOGLNewtAppletBase.java @@ -33,6 +33,7 @@ import java.security.PrivilegedAction; import com.jogamp.nativewindow.NativeWindow; import com.jogamp.nativewindow.WindowClosingProtocol.WindowClosingMode; +import com.jogamp.nativewindow.util.InsetsImmutable; import com.jogamp.opengl.FPSCounter; import com.jogamp.opengl.GL; import com.jogamp.opengl.GLAutoDrawable; @@ -41,11 +42,9 @@ import com.jogamp.opengl.GLPipelineFactory; import jogamp.newt.Debug; -import com.jogamp.common.util.IOUtil; import com.jogamp.common.util.InterruptSource; -import com.jogamp.newt.Display; import com.jogamp.newt.Window; -import com.jogamp.newt.Display.PointerIcon; +import com.jogamp.newt.event.KeyEvent; import com.jogamp.newt.event.KeyListener; import com.jogamp.newt.event.MouseListener; import com.jogamp.newt.event.WindowAdapter; @@ -60,7 +59,7 @@ import com.jogamp.opengl.util.AnimatorBase; /** Shows how to deploy an applet using JOGL. This demo must be referenced from a web page via an <applet> tag. */ -public class JOGLNewtAppletBase implements GLEventListener { +public class JOGLNewtAppletBase implements KeyListener, GLEventListener { public static final boolean DEBUG = Debug.debug("Applet"); String glEventListenerClazzName; @@ -69,7 +68,6 @@ public class JOGLNewtAppletBase implements GLEventListener { boolean glClosable; boolean glDebug; boolean glTrace; - PointerIcon pointerIconTest = null; GLEventListener glEventListener = null; GLWindow glWindow = null; @@ -193,7 +191,10 @@ public class JOGLNewtAppletBase implements GLEventListener { glWindow.addKeyListener((KeyListener)glEventListener); } + glWindow.addWindowListener(reparentHomeListener); + if(!noDefaultKeyListener) { + glWindow.addKeyListener(this); final NEWTDemoListener newtDemoListener = new NEWTDemoListener(glWindow); glWindow.addKeyListener(newtDemoListener); glWindow.addMouseListener(newtDemoListener); @@ -237,24 +238,13 @@ public class JOGLNewtAppletBase implements GLEventListener { if(isValid) { glWindow.setVisible(true); glWindow.sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); - if( null == pointerIconTest ) { - final IOUtil.ClassResources res = new IOUtil.ClassResources(glWindow.getClass(), new String[] { "newt/data/cross-grey-alpha-16x16.png" } ); - final Display disp = glWindow.getScreen().getDisplay(); - try { - pointerIconTest = disp.createPointerIcon(res, 8, 8); - } catch (final Exception e) { - e.printStackTrace(); - } - } glAnimator.start(); parentWin = glWindow.getParent(); - glWindow.addWindowListener(reparentHomeListener); } } public void stop() { if(null!=glAnimator) { - glWindow.removeWindowListener(reparentHomeListener); glAnimator.stop(); glWindow.setVisible(false); } @@ -305,5 +295,43 @@ public class JOGLNewtAppletBase implements GLEventListener { public void dispose(final GLAutoDrawable drawable) { } + // *********************************************************************************** + // *********************************************************************************** + // *********************************************************************************** + + @Override + public void keyPressed(final KeyEvent e) { + if( !e.isPrintableKey() || e.isAutoRepeat() ) { + return; + } + + if(e.getKeyChar()=='r' && 0==e.getModifiers() && null!=parentWin) { + e.setConsumed(true); + glWindow.invokeOnNewThread(null, false, new Runnable() { + public void run() { + if(null == glWindow.getParent()) { + glWindow.reparentWindow(parentWin, -1, -1, 0 /* hints */); + } else { + final InsetsImmutable insets = glWindow.getInsets(); + final int x, y; + if ( 0 >= insets.getTopHeight() ) { + // fail safe .. + x = 32; + y = 32; + } else { + x = insets.getLeftWidth(); + y = insets.getTopHeight(); + } + glWindow.reparentWindow(null, x, y, 0 /* hints */); + glWindow.setDefaultCloseOperation( glClosable ? WindowClosingMode.DISPOSE_ON_CLOSE : WindowClosingMode.DO_NOTHING_ON_CLOSE ); + } + } } ); + } + } + + @Override + public void keyReleased(final KeyEvent e) { + } + } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java index 39e94effc..f08e9a282 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java @@ -33,7 +33,6 @@ import java.lang.reflect.InvocationTargetException; import com.jogamp.junit.util.JunitTracer; import com.jogamp.newt.Display; -import com.jogamp.newt.Display.PointerIcon; import com.jogamp.newt.NewtFactory; import com.jogamp.newt.Screen; import com.jogamp.newt.Window; @@ -182,13 +181,7 @@ public class TestGearsES2NEWT extends UITestCase { } }); - final PointerIcon[] pointerIcons = NEWTDemoListener.createPointerIcons(glWindow); - if( setPointerIcon ) { - glWindow.setPointerIcon(pointerIcons[0]); - System.err.println("Set PointerIcon: "+glWindow.getPointerIcon()); - } - - final NEWTDemoListener newtDemoListener = new NEWTDemoListener(glWindow, pointerIcons); + final NEWTDemoListener newtDemoListener = new NEWTDemoListener(glWindow); newtDemoListener.quitAdapterEnable(true); glWindow.addKeyListener(newtDemoListener); glWindow.addMouseListener(newtDemoListener); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/NewtAWTReparentingKeyAdapter.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/NewtAWTReparentingKeyAdapter.java index 3bf13f063..4fdee82c3 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/NewtAWTReparentingKeyAdapter.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/NewtAWTReparentingKeyAdapter.java @@ -29,7 +29,6 @@ package com.jogamp.opengl.test.junit.newt.parenting; import java.awt.Frame; -import com.jogamp.common.util.InterruptSource; import com.jogamp.nativewindow.CapabilitiesImmutable; import com.jogamp.nativewindow.util.InsetsImmutable; import com.jogamp.newt.Window; @@ -64,7 +63,7 @@ public class NewtAWTReparentingKeyAdapter extends NEWTDemoListener { case KeyEvent.VK_R: e.setConsumed(true); quitAdapterOff(); - new InterruptSource.Thread() { + glWindow.invokeOnNewThread(null, false, new Runnable() { public void run() { final java.lang.Thread t = glWindow.setExclusiveContextThread(null); if(glWindow.getParent()==null) { @@ -95,7 +94,7 @@ public class NewtAWTReparentingKeyAdapter extends NEWTDemoListener { glWindow.requestFocus(); glWindow.setExclusiveContextThread(t); quitAdapterOn(); - } }.start(); + } } ); break; } } |