diff options
author | Sven Gothel <[email protected]> | 2011-09-04 20:32:46 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-09-04 20:32:46 +0200 |
commit | d4670328991c02a6f11f8873ea7a2331f17d0ef0 (patch) | |
tree | 6111ef98a9142b44aa22f86e1920decc30fa52b1 /src/newt/classes/jogamp | |
parent | 70b495519094de5fcca37da68fbbf8762eecbe28 (diff) |
NativeWindow/NEWT: Refine Insets definition for size and position, read and write access
Diffstat (limited to 'src/newt/classes/jogamp')
10 files changed, 106 insertions, 75 deletions
diff --git a/src/newt/classes/jogamp/newt/OffscreenWindow.java b/src/newt/classes/jogamp/newt/OffscreenWindow.java index e797a15cd..2f893fb2c 100644 --- a/src/newt/classes/jogamp/newt/OffscreenWindow.java +++ b/src/newt/classes/jogamp/newt/OffscreenWindow.java @@ -35,6 +35,7 @@ package jogamp.newt; import javax.media.nativewindow.*; +import javax.media.nativewindow.util.Insets; import javax.media.nativewindow.util.Point; public class OffscreenWindow extends WindowImpl implements SurfaceChangeable { @@ -121,9 +122,13 @@ public class OffscreenWindow extends WindowImpl implements SurfaceChangeable { } return new Point(0,0); } - + protected Point getLocationOnScreenImpl(int x, int y) { return new Point(x,y); } + + protected void updateInsetsImpl(Insets insets) { + // nop .. + } } diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java index 55b735b4f..faf4c1a50 100644 --- a/src/newt/classes/jogamp/newt/WindowImpl.java +++ b/src/newt/classes/jogamp/newt/WindowImpl.java @@ -66,6 +66,7 @@ import javax.media.nativewindow.NativeWindowFactory; import javax.media.nativewindow.SurfaceUpdatedListener; import javax.media.nativewindow.util.DimensionImmutable; import javax.media.nativewindow.util.Insets; +import javax.media.nativewindow.util.InsetsImmutable; import javax.media.nativewindow.util.Point; import javax.media.nativewindow.util.Rectangle; @@ -84,9 +85,10 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer protected CapabilitiesImmutable capsRequested = null; protected CapabilitiesChooser capabilitiesChooser = null; // default null -> default protected boolean fullscreen = false, visible = false, hasFocus = false; - protected int width = 128, height = 128, x = 0, y = 0; // default values + protected int width = 128, height = 128, x = 0, y = 0; // client-area size/pos w/o insets + protected Insets insets = new Insets(); // insets of decoration (if top-level && decorated) - protected int nfs_width, nfs_height, nfs_x, nfs_y; // non fullscreen dimensions .. + protected int nfs_width, nfs_height, nfs_x, nfs_y; // non fullscreen client-area size/pos w/o insets protected String title = "Newt Window"; protected boolean undecorated = false; private LifecycleHook lifecycleHook = null; @@ -404,8 +406,8 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer * * @param x -1 if no position change requested, otherwise greater than zero * @param y -1 if no position change requested, otherwise greater than zero - * @param width -1 if no size change requested, otherwise greater than zero - * @param height -1 if no size change requested, otherwise greater than zero + * @param width 0 if no size change requested, otherwise greater than zero + * @param height 0 if no size change requested, otherwise greater than zero * @param parentChange true if reparenting requested, otherwise false * @param fullScreenChange 0 if unchanged, -1 fullscreen off, 1 fullscreen on * @param decorationChange 0 if unchanged, -1 undecorated, 1 decorated @@ -426,6 +428,15 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer * @return if not null, the screen location of the given coordinates */ protected abstract Point getLocationOnScreenImpl(int x, int y); + + /** Triggered by user via {@link #getInsets()}.<br> + * Implementations may implement this hook to update the insets.<br> + * However, they may prefer the event driven path via {@link #insetsChanged(int, int, int, int)}. + * + * @see #getInsets() + * @see #insetsChanged(int, int, int, int) + */ + protected abstract void updateInsetsImpl(Insets insets); //---------------------------------------------------------------------- // NativeSurface @@ -719,6 +730,10 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer runOnEDTIfAvail(true, new SetSizeActionImpl(width, height)); } } + + public void setTopLevelSize(int width, int height) { + setSize(width - getInsets().getTotalWidth(), height - getInsets().getTotalHeight()); + } private class DestroyAction implements Runnable { public final void run() { @@ -1222,7 +1237,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer } } - public boolean isUndecorated() { + public final boolean isUndecorated() { return 0 != parentWindowHandle || undecorated || fullscreen ; } @@ -1230,14 +1245,18 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer enqueueRequestFocus(true); } - public boolean hasFocus() { + public final boolean hasFocus() { return hasFocus; } - public Insets getInsets() { - return new Insets(0,0,0,0); + public final InsetsImmutable getInsets() { + if(isUndecorated()) { + return Insets.getZero(); + } + updateInsetsImpl(insets); + return insets; } - + public final int getWidth() { return width; } @@ -1430,6 +1449,10 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer runOnEDTIfAvail(true, new SetPositionActionImpl(x, y)); } } + + public void setTopLevelPosition(int x, int y) { + setPosition(x + getInsets().getLeftWidth(), y + getInsets().getTopHeight()); + } private class FullScreenActionImpl implements Runnable { boolean fullscreen; @@ -2010,9 +2033,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer } } - /** - * @param focusGained - */ + /** Triggered by implementation's WM events to update the focus state. */ protected void focusChanged(boolean focusGained) { if(DEBUG_IMPLEMENTATION) { System.err.println("Window.focusChanged: ("+getThreadName()+"): "+this.hasFocus+" -> "+focusGained+" - windowHandle "+toHexString(windowHandle)+" parentWindowHandle "+toHexString(parentWindowHandle)); @@ -2025,6 +2046,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer } } + /** Triggered by implementation's WM events to update the visibility state. */ protected void visibleChanged(boolean visible) { if(DEBUG_IMPLEMENTATION) { System.err.println("Window.visibleChanged ("+getThreadName()+"): "+this.visible+" -> "+visible+" - windowHandle "+toHexString(windowHandle)+" parentWindowHandle "+toHexString(parentWindowHandle)); @@ -2055,6 +2077,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer return this.visible == visible; } + /** Triggered by implementation's WM events to update the client-area size w/o insets/decorations. */ protected void sizeChanged(int newWidth, int newHeight, boolean force) { if(force || width != newWidth || height != newHeight) { if(DEBUG_IMPLEMENTATION) { @@ -2071,6 +2094,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer } } + /** Triggered by implementation's WM events to update the position. */ protected void positionChanged(int newX, int newY) { if( 0==parentWindowHandle && ( x != newX || y != newY ) ) { if(DEBUG_IMPLEMENTATION) { @@ -2082,6 +2106,27 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer } } + /** + * Triggered by implementation's WM events to update the insets. + * + * @see #getInsets() + * @see #updateInsetsImpl(Insets) + */ + protected void insetsChanged(int left, int right, int top, int bottom) { + if ( left >= 0 && right >= 0 && top >= 0 && bottom >= 0 && + (left != insets.getLeftWidth() || right != insets.getRightWidth() || + top != insets.getTopHeight() || bottom != insets.getBottomHeight() ) + ) { + insets.setLeftWidth(left); + insets.setRightWidth(right); + insets.setTopHeight(top); + insets.setBottomHeight(bottom); + if(DEBUG_IMPLEMENTATION) { + System.err.println("Window.insetsChanged: "+insets); + } + } + } + protected void windowDestroyNotify() { if(DEBUG_IMPLEMENTATION) { System.err.println("Window.windowDestroyNotify START "+getThreadName()); @@ -2100,15 +2145,17 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer } public void windowRepaint(int x, int y, int width, int height) { - final int _width = ( 0 > width ) ? this.width : width; - final int _height = ( 0 > height ) ? this.height : height; + x = ( 0 > x ) ? this.x : x; + y = ( 0 > y ) ? this.y : y; + width = ( 0 >= width ) ? this.width : width; + height = ( 0 >= height ) ? this.height : height; if(DEBUG_IMPLEMENTATION) { - System.err.println("Window.windowRepaint "+getThreadName()+" - "+x+"/"+y+" "+_width+"x"+_height); + System.err.println("Window.windowRepaint "+getThreadName()+" - "+x+"/"+y+" "+width+"x"+height); } if(isValid()) { NEWTEvent e = new WindowUpdateEvent(WindowEvent.EVENT_WINDOW_REPAINT, this, System.currentTimeMillis(), - new Rectangle(x, y, _width, _height)); + new Rectangle(x, y, width, height)); doEvent(false, false, e); } } diff --git a/src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java b/src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java index aaefae037..cbe343f2c 100644 --- a/src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java +++ b/src/newt/classes/jogamp/newt/driver/android/AndroidWindow.java @@ -35,6 +35,7 @@ import jogamp.newt.driver.android.event.AndroidNewtEventFactory; import javax.media.nativewindow.GraphicsConfigurationFactory; import javax.media.nativewindow.NativeWindowException; import javax.media.nativewindow.egl.EGLGraphicsDevice; +import javax.media.nativewindow.util.Insets; import javax.media.nativewindow.util.Point; import javax.media.opengl.GLException; @@ -212,6 +213,10 @@ public class AndroidWindow extends jogamp.newt.WindowImpl implements Callback2 { return new Point(x,y); } + protected void updateInsetsImpl(Insets insets) { + // nop .. + } + //---------------------------------------------------------------------- // Surface Callbacks // @@ -262,5 +267,5 @@ public class AndroidWindow extends jogamp.newt.WindowImpl implements Callback2 { protected static native boolean initIDs(); protected static native long getSurfaceHandle(Surface surface); protected static native void setSurfaceVisualID(long surfaceHandle, int nativeVisualID); - + } diff --git a/src/newt/classes/jogamp/newt/driver/awt/AWTWindow.java b/src/newt/classes/jogamp/newt/driver/awt/AWTWindow.java index e05c6d63a..3ed0c758d 100644 --- a/src/newt/classes/jogamp/newt/driver/awt/AWTWindow.java +++ b/src/newt/classes/jogamp/newt/driver/awt/AWTWindow.java @@ -181,15 +181,12 @@ public class AWTWindow extends WindowImpl { } - @Override - public javax.media.nativewindow.util.Insets getInsets() { - final int insets[] = new int[] { 0, 0, 0, 0 }; + protected void updateInsetsImpl(javax.media.nativewindow.util.Insets insets) { Insets contInsets = container.getInsets(); - insets[0] = contInsets.top; - insets[1] = contInsets.left; - insets[2] = contInsets.bottom; - insets[3] = contInsets.right; - return new javax.media.nativewindow.util.Insets(insets[0],insets[1],insets[2],insets[3]); + insets.setLeftWidth(contInsets.left); + insets.setRightWidth(contInsets.right); + insets.setTopHeight(contInsets.top); + insets.setBottomHeight(contInsets.bottom); } protected boolean reconfigureWindowImpl(final int x, final int y, final int width, final int height, final boolean parentChange, final int fullScreenChange, final int decorationChange) { diff --git a/src/newt/classes/jogamp/newt/driver/broadcom/egl/Window.java b/src/newt/classes/jogamp/newt/driver/broadcom/egl/Window.java index 5bb567067..0a7f63a82 100644 --- a/src/newt/classes/jogamp/newt/driver/broadcom/egl/Window.java +++ b/src/newt/classes/jogamp/newt/driver/broadcom/egl/Window.java @@ -35,7 +35,7 @@ package jogamp.newt.driver.broadcom.egl; import jogamp.opengl.egl.*; import javax.media.nativewindow.*; -import javax.media.nativewindow.NativeWindowException; +import javax.media.nativewindow.util.Insets; import javax.media.nativewindow.util.Point; import javax.media.opengl.GLCapabilitiesImmutable; @@ -119,6 +119,9 @@ public class Window extends jogamp.newt.WindowImpl { return new Point(x,y); } + protected void updateInsetsImpl(Insets insets) { + // nop .. + } @Override public boolean surfaceSwap() { diff --git a/src/newt/classes/jogamp/newt/driver/intel/gdl/Window.java b/src/newt/classes/jogamp/newt/driver/intel/gdl/Window.java index 0e9a17b09..5e312f24d 100644 --- a/src/newt/classes/jogamp/newt/driver/intel/gdl/Window.java +++ b/src/newt/classes/jogamp/newt/driver/intel/gdl/Window.java @@ -34,6 +34,7 @@ package jogamp.newt.driver.intel.gdl; import javax.media.nativewindow.*; +import javax.media.nativewindow.util.Insets; import javax.media.nativewindow.util.Point; public class Window extends jogamp.newt.WindowImpl { @@ -128,6 +129,10 @@ public class Window extends jogamp.newt.WindowImpl { return new Point(x,y); } + protected void updateInsetsImpl(Insets insets) { + // nop .. + } + //---------------------------------------------------------------------- // Internals only // diff --git a/src/newt/classes/jogamp/newt/driver/kd/KDWindow.java b/src/newt/classes/jogamp/newt/driver/kd/KDWindow.java index 2befaa9aa..f63233b37 100644 --- a/src/newt/classes/jogamp/newt/driver/kd/KDWindow.java +++ b/src/newt/classes/jogamp/newt/driver/kd/KDWindow.java @@ -36,7 +36,7 @@ package jogamp.newt.driver.kd; import jogamp.newt.*; import jogamp.opengl.egl.*; import javax.media.nativewindow.*; -import javax.media.nativewindow.NativeWindowException; +import javax.media.nativewindow.util.Insets; import javax.media.nativewindow.util.Point; import javax.media.opengl.GLCapabilitiesImmutable; @@ -118,6 +118,10 @@ public class KDWindow extends WindowImpl { return new Point(x,y); } + protected void updateInsetsImpl(Insets insets) { + // nop .. + } + //---------------------------------------------------------------------- // Internals only // diff --git a/src/newt/classes/jogamp/newt/driver/macosx/MacWindow.java b/src/newt/classes/jogamp/newt/driver/macosx/MacWindow.java index 19a374511..c38c83972 100644 --- a/src/newt/classes/jogamp/newt/driver/macosx/MacWindow.java +++ b/src/newt/classes/jogamp/newt/driver/macosx/MacWindow.java @@ -132,9 +132,6 @@ public class MacWindow extends WindowImpl { private volatile long surfaceHandle; - // non fullscreen dimensions .. - private final Insets insets = new Insets(0,0,0,0); - static { MacDisplay.initSingleton(); } @@ -173,19 +170,6 @@ public class MacWindow extends WindowImpl { return surfaceHandle; } - @Override - public Insets getInsets() { - // in order to properly calculate insets we need the window to be - // created - nsViewLock.lock(); - try { - createWindow(false, getX(), getY(), getWidth(), getHeight(), isFullscreen()); - return (Insets) insets.clone(); - } finally { - nsViewLock.unlock(); - } - } - private RecursiveLock nsViewLock = new RecursiveLock(); @Override @@ -273,19 +257,10 @@ public class MacWindow extends WindowImpl { return null; } - private void insetsChanged(int left, int top, int right, int bottom) { - if (DEBUG_IMPLEMENTATION) { - System.err.println(Thread.currentThread().getName()+ - " Insets changed to " + left + ", " + top + ", " + right + ", " + bottom); - } - if (left != -1 && top != -1 && right != -1 && bottom != -1) { - insets.left = left; - insets.top = top; - insets.right = right; - insets.bottom = bottom; - } + protected void updateInsetsImpl(Insets insets) { + // nop - using event driven insetsChange(..) } - + private char convertKeyChar(char keyChar) { if (keyChar == '\r') { // Turn these into \n diff --git a/src/newt/classes/jogamp/newt/driver/windows/WindowsWindow.java b/src/newt/classes/jogamp/newt/driver/windows/WindowsWindow.java index 029819913..d6ca64d24 100644 --- a/src/newt/classes/jogamp/newt/driver/windows/WindowsWindow.java +++ b/src/newt/classes/jogamp/newt/driver/windows/WindowsWindow.java @@ -46,7 +46,6 @@ public class WindowsWindow extends WindowImpl { private long hmon; private long hdc; private long windowHandleClose; - private final Insets insets = new Insets(0, 0, 0, 0); static { WindowsDisplay.initSingleton(); @@ -167,15 +166,14 @@ public class WindowsWindow extends WindowImpl { setTitle0(getWindowHandle(), title); } - @Override - public Insets getInsets() { - return (Insets)insets.clone(); - } - protected Point getLocationOnScreenImpl(int x, int y) { return GDI.GetRelativeLocation( getWindowHandle(), 0 /*root win*/, x, y); } + protected void updateInsetsImpl(Insets insets) { + // nop - using event driven insetsChange(..) + } + //---------------------------------------------------------------------- // Internals only // @@ -193,17 +191,4 @@ public class WindowsWindow extends WindowImpl { private static native void setTitle0(long windowHandle, String title); private native void requestFocus0(long windowHandle, boolean force); - private void insetsChanged(int left, int top, int right, int bottom) { - if (left != -1 && top != -1 && right != -1 && bottom != -1) { - if (left != insets.left || top != insets.top || right != insets.right || bottom != insets.bottom) { - insets.left = left; - insets.top = top; - insets.right = right; - insets.bottom = bottom; - if(DEBUG_IMPLEMENTATION) { - System.err.println("Window.insetsChanged: "+insets); - } - } - } - } } diff --git a/src/newt/classes/jogamp/newt/driver/x11/X11Window.java b/src/newt/classes/jogamp/newt/driver/x11/X11Window.java index 0efb32cc3..265bec898 100644 --- a/src/newt/classes/jogamp/newt/driver/x11/X11Window.java +++ b/src/newt/classes/jogamp/newt/driver/x11/X11Window.java @@ -37,6 +37,7 @@ import jogamp.nativewindow.x11.X11Util; import jogamp.newt.WindowImpl; import javax.media.nativewindow.*; import javax.media.nativewindow.x11.*; +import javax.media.nativewindow.util.Insets; import javax.media.nativewindow.util.Point; public class X11Window extends WindowImpl { @@ -119,6 +120,10 @@ public class X11Window extends WindowImpl { return X11Util.GetRelativeLocation( getDisplayEDTHandle(), getScreenIndex(), getWindowHandle(), 0 /*root win*/, x, y); } + protected void updateInsetsImpl(Insets insets) { + // TODO !! + } + //---------------------------------------------------------------------- // Internals only // |