diff options
author | Sven Gothel <[email protected]> | 2010-10-06 16:04:06 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2010-10-06 16:04:06 +0200 |
commit | 018c7e8660dc0af68bd129be9af5094d04d0b431 (patch) | |
tree | ac17156a48167f4a28e129adfc78b7c746aa6744 /src/nativewindow/classes | |
parent | 03416ffe040d50b96573930104a78933605ae40d (diff) |
NativeWindow/NativeSurface Refactoring ; Added mouseClick NEWT/AWT unit test
NativeWindow/NativeSurface Refactoring
- Using NativeSurface interface
- NativeWindow extends NativeSurface, adds getLocationOnScreen(Point)
- NativeWindow add: getParent()
- NativeWindow/Surface: Removed 'invalidate()', use 'destroy()' if you must.
- NullWindow -> ProxySurface impl NativeSurface
- JOGL: Uses NativeSurface only.
- GLDrawable.getNativeWindow() -> GLDrawable.getNativeSurface()
Added mouseClick NEWT/AWT unit test
JOGL:
- GLAnimatorControl add: resetCounter()
-
NEWT:
- GLWindow counters: return GLWindow counters always
- WindowImpl
- requestFocus() wait until done
- reparent: readded requestFocusImpl(true),
native impl skips java focusAction if reparented
- X11Window: Add XRaiseWindow() in requestFocus()
Diffstat (limited to 'src/nativewindow/classes')
11 files changed, 625 insertions, 198 deletions
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/NullWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/ProxySurface.java index fc6242968..5e6487ae8 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/impl/NullWindow.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/ProxySurface.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 2010 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -36,16 +37,19 @@ package com.jogamp.nativewindow.impl; -import javax.media.nativewindow.*; -import com.jogamp.nativewindow.impl.RecursiveToolkitLock; +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.NativeSurface; +import javax.media.nativewindow.NativeWindow; +import javax.media.nativewindow.NativeWindowException; +import javax.media.nativewindow.SurfaceChangeable; -public class NullWindow implements NativeWindow, SurfaceChangeable { +public class ProxySurface implements NativeSurface, SurfaceChangeable { private RecursiveToolkitLock recurLock = new RecursiveToolkitLock(); protected int width, height, scrnIndex; protected long surfaceHandle, displayHandle; protected AbstractGraphicsConfiguration config; - public NullWindow(AbstractGraphicsConfiguration cfg) { + public ProxySurface(AbstractGraphicsConfiguration cfg) { invalidate(); config = cfg; displayHandle=cfg.getScreen().getDevice().getHandle(); @@ -58,6 +62,10 @@ public class NullWindow implements NativeWindow, SurfaceChangeable { protected void initNative() throws NativeWindowException { } + public NativeWindow getParent() { + return null; + } + public void destroy() { invalidate(); } @@ -97,7 +105,23 @@ public class NullWindow implements NativeWindow, SurfaceChangeable { return false; } - public void surfaceUpdated(Object updater, NativeWindow window, long when) { } + public long getSurfaceHandle() { + return surfaceHandle; + } + + public int getWidth() { + return width; + } + + public int getHeight() { + return height; + } + + public AbstractGraphicsConfiguration getGraphicsConfiguration() { + return config; + } + + public void surfaceUpdated(Object updater, NativeSurface ns, long when) { } public long getDisplayHandle() { return displayHandle; @@ -105,36 +129,16 @@ public class NullWindow implements NativeWindow, SurfaceChangeable { public int getScreenIndex() { return scrnIndex; } - public long getWindowHandle() { - return 0; - } - public long getSurfaceHandle() { - return surfaceHandle; - } + public void setSurfaceHandle(long surfaceHandle) { this.surfaceHandle=surfaceHandle; } - public AbstractGraphicsConfiguration getGraphicsConfiguration() { - return config; - } - - public final boolean isTerminalObject() { - return true; - } public void setSize(int width, int height) { this.width=width; this.height=height; } - public int getWidth() { - return width; - } - - public int getHeight() { - return height; - } - public String toString() { return "NullWindow[config "+config+ ", displayHandle 0x"+Long.toHexString(getDisplayHandle())+ diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTWindow.java index 1cd63235d..0cb861453 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTWindow.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTWindow.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 2010 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -36,14 +37,14 @@ package com.jogamp.nativewindow.impl.jawt; -import com.jogamp.nativewindow.impl.*; -import com.jogamp.nativewindow.util.Rectangle; import java.awt.Component; import java.awt.Window; import java.awt.GraphicsEnvironment; import javax.media.nativewindow.*; import com.jogamp.nativewindow.impl.*; +import javax.media.nativewindow.util.Point; +import javax.media.nativewindow.util.Rectangle; public abstract class JAWTWindow implements NativeWindow { protected static final boolean DEBUG = Debug.debug("JAWT"); @@ -79,21 +80,12 @@ public abstract class JAWTWindow implements NativeWindow { protected abstract void initNative() throws NativeWindowException; - public synchronized void invalidate() { + protected synchronized void invalidate() { component = null; drawable= 0; bounds = new Rectangle(); } - public synchronized void destroy() { - if(null!=component) { - if(component instanceof Window) { - ((Window)component).dispose(); - } - } - invalidate(); - } - protected void updateBounds(JAWT_Rectangle jawtBounds) { bounds.setX(jawtBounds.getX()); bounds.setY(jawtBounds.getY()); @@ -101,6 +93,25 @@ public abstract class JAWTWindow implements NativeWindow { bounds.setHeight(jawtBounds.getHeight()); } + /** @return the JAWT_DrawingSurfaceInfo's (JAWT_Rectangle) bounds, updated with lock */ + public Rectangle getBounds() { return bounds; } + + public Component getAWTComponent() { + return component; + } + + // + // SurfaceUpdateListener + // + + public void surfaceUpdated(Object updater, NativeSurface ns, long when) { + // nop + } + + // + // NativeSurface + // + private RecursiveToolkitLock recurLock = new RecursiveToolkitLock(); protected abstract int lockSurfaceImpl() throws NativeWindowException; @@ -148,15 +159,6 @@ public abstract class JAWTWindow implements NativeWindow { public void surfaceUpdated(Object updater, NativeWindow window, long when) { } - public long getDisplayHandle() { - return config.getScreen().getDevice().getHandle(); - } - public int getScreenIndex() { - return config.getScreen().getIndex(); - } - public long getWindowHandle() { - return drawable; - } public long getSurfaceHandle() { return drawable; } @@ -164,8 +166,12 @@ public abstract class JAWTWindow implements NativeWindow { return config; } - public Object getWrappedWindow() { - return component; + public long getDisplayHandle() { + return config.getScreen().getDevice().getHandle(); + } + + public int getScreenIndex() { + return config.getScreen().getIndex(); } public void setSize(int width, int height) { @@ -180,8 +186,44 @@ public abstract class JAWTWindow implements NativeWindow { return component.getHeight(); } - /** @return the JAWT_DrawingSurfaceInfo's (JAWT_Rectangle) bounds, updated with lock */ - public Rectangle getBounds() { return bounds; } + // + // NativeWindow + // + + public synchronized void destroy() { + if(null!=component) { + if(component instanceof Window) { + ((Window)component).dispose(); + } + } + invalidate(); + } + + public NativeWindow getParent() { + return null; + } + + public long getWindowHandle() { + return drawable; + } + + public int getX() { + return component.getX(); + } + + public int getY() { + return component.getY(); + } + + public Point getLocationOnScreen(Point point) { + java.awt.Point awtLOS = component.getLocationOnScreen(); + int dx = (int) ( awtLOS.getX() + .5 ) ; + int dy = (int) ( awtLOS.getY() + .5 ) ; + if(null!=point) { + return point.translate(dx, dy); + } + return new Point(dx, dy); + } public String toString() { StringBuffer sb = new StringBuffer(); @@ -191,14 +233,14 @@ public abstract class JAWTWindow implements NativeWindow { ", surfaceHandle 0x"+Long.toHexString(getSurfaceHandle())+ ", bounds "+bounds); if(null!=component) { - sb.append(", pos "+component.getX()+"/"+component.getY()+", size "+getWidth()+"x"+getHeight()+ + sb.append(", pos "+getX()+"/"+getY()+", size "+getWidth()+"x"+getHeight()+ ", visible "+component.isVisible()); } else { sb.append(", component NULL"); } sb.append(", lockedExt "+isSurfaceLockedByOtherThread()+ ",\n\tconfig "+config+ - ",\n\twrappedWindow "+getWrappedWindow()+"]"); + ",\n\tawtComponent "+getAWTComponent()+"]"); return sb.toString(); } diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/windows/WindowsJAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/windows/WindowsJAWTWindow.java index c3b3682fd..b6da7166d 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/windows/WindowsJAWTWindow.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/windows/WindowsJAWTWindow.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 2010 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -56,7 +57,7 @@ public class WindowsJAWTWindow extends JAWTWindow { protected void initNative() throws NativeWindowException { } - public synchronized void invalidate() { + protected synchronized void invalidate() { super.invalidate(); windowHandle = 0; } diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeSurface.java b/src/nativewindow/classes/javax/media/nativewindow/NativeSurface.java new file mode 100644 index 000000000..3648a9a32 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/NativeSurface.java @@ -0,0 +1,166 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * Copyright (c) 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package javax.media.nativewindow; + +/** Provides low-level information required for + hardware-accelerated rendering using a surface in a platform-independent manner.<P> + + A NativeSurface created for a particular on- or offscreen component is + expected to have the same lifetime as that component. As long as + the component is alive and realized/visible, NativeSurface must be able + provide information such as the surface handle while it is locked.<P> +*/ +public interface NativeSurface extends SurfaceUpdatedListener { + /** Unlocked state */ + public static final int LOCK_SURFACE_UNLOCKED = 0; + + /** Returned by {@link #lockSurface()} if the surface is not ready to be locked. */ + public static final int LOCK_SURFACE_NOT_READY = 1; + + /** Returned by {@link #lockSurface()} if the surface is locked, but has changed. */ + public static final int LOCK_SURFACE_CHANGED = 2; + + /** Returned by {@link #lockSurface()} if the surface is locked, and is unchanged. */ + public static final int LOCK_SUCCESS = 3; + + /** + * Lock the surface of this native window<P> + * + * The surface handle, see {@link #lockSurface()}, <br> + * shall be valid after a successfull call, + * ie return a value other than {@link #LOCK_SURFACE_NOT_READY}.<P> + * + * This call is blocking until the surface has been locked + * or a timeout is reached. The latter will throw a runtime exception. <P> + * + * This call allows recursion from the same thread.<P> + * + * The implementation may want to aquire the + * application level {@link com.jogamp.nativewindow.impl.RecursiveToolkitLock} + * first before proceeding with a native surface lock. <P> + * + * @return {@link #LOCK_SUCCESS}, {@link #LOCK_SURFACE_CHANGED} or {@link #LOCK_SURFACE_NOT_READY}. + * + * @throws RuntimeException after timeout when waiting for the surface lock + * + * @see com.jogamp.nativewindow.impl.RecursiveToolkitLock + */ + public int lockSurface(); + + /** + * Unlock the surface of this native window + * + * Shall not modify the surface handle, see {@link #lockSurface()} <P> + * + * @throws RuntimeException if surface is not locked + * + * @see #lockSurface + * @see com.jogamp.nativewindow.impl.RecursiveToolkitLock + */ + public void unlockSurface() throws NativeWindowException ; + + /** + * Return if surface is locked by another thread, ie not the current one + */ + public boolean isSurfaceLockedByOtherThread(); + + /** + * Return if surface is locked + */ + public boolean isSurfaceLocked(); + + /** + * Return the locking owner's Thread, or null if not locked. + */ + public Thread getSurfaceLockOwner(); + + /** + * Return the lock-exception, or null if not locked. + * + * The lock-exception is created at {@link #lockSurface()} + * and hence holds the locker's call stack. + */ + public Exception getSurfaceLockStack(); + + /** + * Provide a mechanism to utilize custom (pre-) swap surface + * code. This method is called before the render toolkit (e.g. JOGL) + * swaps the buffer/surface. The implementation may itself apply the swapping, + * in which case true shall be returned. + * + * @return true if this method completed swapping the surface, + * otherwise false, in which case eg the GLDrawable + * implementation has to swap the code. + */ + public boolean surfaceSwap(); + + /** + * Returns the handle to the surface for this NativeSurface. <P> + * + * The surface handle should be set/update by {@link #lockSurface()}, + * where {@link #unlockSurface()} is not allowed to modify it. + * After {@link #unlockSurface()} it is no more guaranteed + * that the surface handle is still valid. + * + * The surface handle shall reflect the platform one + * for all drawable surface operations, e.g. opengl, swap-buffer. <P> + * + * On X11 this returns an entity of type Window, + * since there is no differentiation of surface and window there. <BR> + * On Microsoft Windows this returns an entity of type HDC. + */ + public long getSurfaceHandle(); + + /** Returns the current width of this surface. */ + public int getWidth(); + + /** Returns the current height of this surface. */ + public int getHeight(); + + /** + * Returns the graphics configuration corresponding to this window. + * @see javax.media.nativewindow.GraphicsConfigurationFactory#chooseGraphicsConfiguration(Capabilities, CapabilitiesChooser, AbstractGraphicsScreen) + */ + public AbstractGraphicsConfiguration getGraphicsConfiguration(); + + /** + * Convenience: Get display handle from + * AbstractGraphicsConfiguration . AbstractGraphicsScreen . AbstractGraphicsDevice + */ + public long getDisplayHandle(); + + /** + * Convenience: Get display handle from + * AbstractGraphicsConfiguration . AbstractGraphicsScreen + */ + public int getScreenIndex(); + +} + diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeWindow.java b/src/nativewindow/classes/javax/media/nativewindow/NativeWindow.java index 2187f6054..d65cc8c18 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/NativeWindow.java +++ b/src/nativewindow/classes/javax/media/nativewindow/NativeWindow.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 2010 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -39,111 +40,18 @@ package javax.media.nativewindow; -/** Provides the low-level information required for - hardware-accelerated rendering in a platform-independent manner. A - window toolkit such as the AWT may either implement this interface +import javax.media.nativewindow.util.Point; + +/** Extend the {@link NativeSurface} interface with windowing + information such as window handle and position.<P> + + A window toolkit such as the AWT may either implement this interface directly with one of its components, or provide and register an implementation of {@link NativeWindowFactory NativeWindowFactory} which can create NativeWindow objects for its components. <P> - - A NativeWindow created for a particular on-screen component is - expected to have the same lifetime as that component. As long as - the component is alive, the NativeWindow must be able to control - it, and any time it is visible and locked, provide information - such as the window handle. */ -public interface NativeWindow extends SurfaceUpdatedListener { - /** Unlocked state */ - public static final int LOCK_SURFACE_UNLOCKED = 0; - - /** Returned by {@link #lockSurface()} if the surface is not ready to be locked. */ - public static final int LOCK_SURFACE_NOT_READY = 1; - - /** Returned by {@link #lockSurface()} if the surface is locked, but has changed. */ - public static final int LOCK_SURFACE_CHANGED = 2; - - /** Returned by {@link #lockSurface()} if the surface is locked, and is unchanged. */ - public static final int LOCK_SUCCESS = 3; - - /** - * Lock the surface of this native window<P> - * - * The surface handle, see {@link #lockSurface()}, <br> - * shall be valid after a successfull call, - * ie return a value other than {@link #LOCK_SURFACE_NOT_READY}.<P> - * - * This call is blocking until the surface has been locked - * or a timeout is reached. The latter will throw a runtime exception. <P> - * - * This call allows recursion from the same thread.<P> - * - * The implementation may want to aquire the - * application level {@link com.jogamp.nativewindow.impl.RecursiveToolkitLock} - * first before proceeding with a native surface lock. <P> - * - * @return {@link #LOCK_SUCCESS}, {@link #LOCK_SURFACE_CHANGED} or {@link #LOCK_SURFACE_NOT_READY}. - * - * @throws RuntimeException after timeout when waiting for the surface lock - * - * @see com.jogamp.nativewindow.impl.RecursiveToolkitLock - */ - public int lockSurface(); - - /** - * Unlock the surface of this native window - * - * Shall not modify the surface handle, see {@link #lockSurface()} <P> - * - * @throws RuntimeException if surface is not locked - * - * @see #lockSurface - * @see com.jogamp.nativewindow.impl.RecursiveToolkitLock - */ - public void unlockSurface() throws NativeWindowException ; - - /** - * Return if surface is locked by another thread, ie not the current one - */ - public boolean isSurfaceLockedByOtherThread(); - - /** - * Return if surface is locked - */ - public boolean isSurfaceLocked(); - - /** - * Return the locking owner's Thread, or null if not locked. - */ - public Thread getSurfaceLockOwner(); - - /** - * Return the lock-exception, or null if not locked. - * - * The lock-exception is created at {@link #lockSurface()} - * and hence holds the locker's call stack. - */ - public Exception getSurfaceLockStack(); - - /** - * Provide a mechanism to utilize custom (pre-) swap surface - * code. This method is called before the render toolkit (e.g. JOGL) - * swaps the buffer/surface. The implementation may itself apply the swapping, - * in which case true shall be returned. - * - * @return true if this method completed swapping the surface, - * otherwise false, in which case eg the GLDrawable - * implementation has to swap the code. - */ - public boolean surfaceSwap(); - - /** - * render all native window information invalid, - * as if the native window was destroyed - * - * @see #destroy - */ - public void invalidate(); - +public interface NativeWindow extends NativeSurface { + /** * destroys the window and releases * windowing related resources. @@ -151,6 +59,11 @@ public interface NativeWindow extends SurfaceUpdatedListener { public void destroy(); /** + * @return The parent NativeWindow, or null if this NativeWindow is top level. + */ + public NativeWindow getParent(); + + /** * Returns the window handle for this NativeWindow. <P> * * The window handle shall reflect the platform one @@ -161,45 +74,20 @@ public interface NativeWindow extends SurfaceUpdatedListener { */ public long getWindowHandle(); - /** - * Returns the handle to the surface for this NativeWindow. <P> - * - * The surface handle should be set/update by {@link #lockSurface()}, - * where {@link #unlockSurface()} is not allowed to modify it. - * After {@link #unlockSurface()} it is no more guaranteed - * that the surface handle is still valid. - * - * The surface handle shall reflect the platform one - * for all drawable surface operations, e.g. opengl, swap-buffer. <P> - * - * On X11 this returns an entity of type Window, - * since there is no differentiation of surface and window there. <BR> - * On Microsoft Windows this returns an entity of type HDC. - */ - public long getSurfaceHandle(); - - /** Returns the current width of this window. */ - public int getWidth(); + /** Returns the current x position of this window, relative to it's parent. */ + public int getX(); - /** Returns the current height of this window. */ - public int getHeight(); + /** Returns the current y position of this window, relative to it's parent. */ + public int getY(); - /** - * Returns the graphics configuration corresponding to this window. - * @see javax.media.nativewindow.GraphicsConfigurationFactory#chooseGraphicsConfiguration(Capabilities, CapabilitiesChooser, AbstractGraphicsScreen) - */ - public AbstractGraphicsConfiguration getGraphicsConfiguration(); - - /** - * Convenience: Get display handle from - * AbstractGraphicsConfiguration . AbstractGraphicsScreen . AbstractGraphicsDevice - */ - public long getDisplayHandle(); - - /** - * Convenience: Get display handle from - * AbstractGraphicsConfiguration . AbstractGraphicsScreen + /** + * Returns the current absolute location of this window. + * @param point if not null, + * {@link javax.media.nativewindow.util.Point#translate(javax.media.nativewindow.util.Point)} + * the passed {@link javax.media.nativewindow.util.Point} by this location on the screen and return it. + * @return either the passed non null translated point by the screen location of this NativeWindow, + * or a new instance with the screen location of this NativeWindow. */ - public int getScreenIndex(); - + public Point getLocationOnScreen(Point point); + } diff --git a/src/nativewindow/classes/javax/media/nativewindow/SurfaceUpdatedListener.java b/src/nativewindow/classes/javax/media/nativewindow/SurfaceUpdatedListener.java index 7be15408c..88e805d14 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/SurfaceUpdatedListener.java +++ b/src/nativewindow/classes/javax/media/nativewindow/SurfaceUpdatedListener.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 2010 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -38,9 +39,9 @@ public interface SurfaceUpdatedListener { * * @param updater is the caller object who updated the surface, * e.g. a JOGL GLDrawable. - * @param window the NativeWindow, which surface is updated + * @param ns the updated NativeSurface * @param when the time in ms, when the surface was updated */ - public void surfaceUpdated(Object updater, NativeWindow window, long when) ; + public void surfaceUpdated(Object updater, NativeSurface ns, long when) ; } diff --git a/src/nativewindow/classes/javax/media/nativewindow/package.html b/src/nativewindow/classes/javax/media/nativewindow/package.html index fa422b2ab..1eb1cef08 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/package.html +++ b/src/nativewindow/classes/javax/media/nativewindow/package.html @@ -39,8 +39,9 @@ <br> shall be registered with {@link javax.media.nativewindow.GraphicsConfigurationFactory#registerFactory GraphicsConfigurationFactory.registerFactory(..)}.</li><br> </ul><br> - This protocol <i>does not</i> describe how to <i>create</i> native windows, but how to <i>bind</i> a native window to an implementation of - {@link javax.media.nativewindow.NativeWindow NativeWindow}.<br> + This protocol <i>does not</i> describe how to <i>create</i> native windows, but how to <i>bind</i> a native surface to an implementation of + and window to an implementation of {@link javax.media.nativewindow.NativeSurface NativeSurface}.<br> + {@link javax.media.nativewindow.NativeWindow NativeWindow} specializes the NativeSurface.<br> However, an implementation of this protocol (e.g. {@link com.jogamp.newt}) may support the creation.<br> <h3>Dependencies</h3> diff --git a/src/nativewindow/classes/javax/media/nativewindow/util/Dimension.java b/src/nativewindow/classes/javax/media/nativewindow/util/Dimension.java new file mode 100644 index 000000000..19ec1e259 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/util/Dimension.java @@ -0,0 +1,94 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * Copyright (c) 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + + +package javax.media.nativewindow.util; + +public class Dimension { + int width; + int height; + + public Dimension() { + this(0, 0); + } + + public Dimension(int width, int height) { + this.width=width; + this.height=height; + } + public int getWidth() { return width; } + public int getHeight() { return height; } + public void setWidth(int width) { this.width = width; } + public void setHeight(int height) { this.height = height; } + + public Dimension scale(int s) { + width *= s; + height *= s; + return this; + } + + public Dimension add(Dimension pd) { + width += pd.width ; + height += pd.height ; + return this; + } + + public String toString() { + return new String("Dimension["+width+"x"+height+"]"); + } + + /** + * Checks whether two dimensions objects are equal. Two instances + * of <code>Dimension</code> are equal if the four integer values + * of the fields <code>height</code> and <code>width</code> + * are equal. + * @return <code>true</code> if the two dimensions are equal; + * otherwise <code>false</code>. + */ + public boolean equals(Object obj) { + if (obj instanceof Dimension) { + Dimension p = (Dimension)obj; + return (height == p.height) && (width == p.width) && + (height == p.height) && (width == p.width); + } + return false; + } + + /** + * Returns the hash code for this Dimension. + * + * @return a hash code for this Dimension. + */ + public int hashCode() { + int sum1 = width + height; + return sum1 * (sum1 + 1)/2 + width; + } + +} + diff --git a/src/nativewindow/classes/javax/media/nativewindow/util/Insets.java b/src/nativewindow/classes/javax/media/nativewindow/util/Insets.java new file mode 100644 index 000000000..4162e1099 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/util/Insets.java @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ +package javax.media.nativewindow.util; + +/** + * Simple class representing insets. + * + * @author tdv + */ +public class Insets implements Cloneable { + public int top; + public int left; + public int bottom; + public int right; + + /** + * Creates and initializes a new <code>Insets</code> object with the + * specified top, left, bottom, and right insets. + * @param top the inset from the top. + * @param left the inset from the left. + * @param bottom the inset from the bottom. + * @param right the inset from the right. + */ + public Insets(int top, int left, int bottom, int right) { + this.top = top; + this.left = left; + this.bottom = bottom; + this.right = right; + } + + /** + * Checks whether two insets objects are equal. Two instances + * of <code>Insets</code> are equal if the four integer values + * of the fields <code>top</code>, <code>left</code>, + * <code>bottom</code>, and <code>right</code> are all equal. + * @return <code>true</code> if the two insets are equal; + * otherwise <code>false</code>. + */ + public boolean equals(Object obj) { + if (obj instanceof Insets) { + Insets insets = (Insets)obj; + return ((top == insets.top) && (left == insets.left) && + (bottom == insets.bottom) && (right == insets.right)); + } + return false; + } + + /** + * Returns the hash code for this Insets. + * + * @return a hash code for this Insets. + */ + public int hashCode() { + int sum1 = left + bottom; + int sum2 = right + top; + int val1 = sum1 * (sum1 + 1)/2 + left; + int val2 = sum2 * (sum2 + 1)/2 + top; + int sum3 = val1 + val2; + return sum3 * (sum3 + 1)/2 + val2; + } + + public String toString() { + return getClass().getName() + "[top=" + top + ",left=" + left + + ",bottom=" + bottom + ",right=" + right + "]"; + } + + public Object clone() { + try { + return super.clone(); + } catch (CloneNotSupportedException ex) { + throw new InternalError(); + } + } + +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/util/Point.java b/src/nativewindow/classes/javax/media/nativewindow/util/Point.java new file mode 100644 index 000000000..a541b3cfd --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/util/Point.java @@ -0,0 +1,93 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * Copyright (c) 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + + +package javax.media.nativewindow.util; + +public class Point { + int x; + int y; + + public Point() { + this(0, 0); + } + + public Point(int x, int y) { + this.x=x; + this.y=y; + } + public int getX() { return x; } + public int getY() { return y; } + public void setX(int x) { this.x = x; } + public void setY(int y) { this.y = y; } + + public Point translate(Point pd) { + x += pd.x ; + y += pd.y ; + return this; + } + + public Point translate(int dx, int dy) { + x += dx ; + y += dy ; + return this; + } + + public String toString() { + return new String("Point["+x+"/"+y+"]"); + } + + /** + * Checks whether two points objects are equal. Two instances + * of <code>Point</code> are equal if the four integer values + * of the fields <code>y</code> and <code>x</code> + * are equal. + * @return <code>true</code> if the two points are equal; + * otherwise <code>false</code>. + */ + public boolean equals(Object obj) { + if (obj instanceof Point) { + Point p = (Point)obj; + return (y == p.y) && (x == p.x); + } + return false; + } + + /** + * Returns the hash code for this Point. + * + * @return a hash code for this Point. + */ + public int hashCode() { + int sum1 = x + y; + return sum1 * (sum1 + 1)/2 + x; + } + +} + diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/util/Rectangle.java b/src/nativewindow/classes/javax/media/nativewindow/util/Rectangle.java index 9f7711443..84e970b9f 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/util/Rectangle.java +++ b/src/nativewindow/classes/javax/media/nativewindow/util/Rectangle.java @@ -27,7 +27,7 @@ */ -package com.jogamp.nativewindow.util; +package javax.media.nativewindow.util; public class Rectangle { int x; @@ -54,6 +54,37 @@ public class Rectangle { public void setWidth(int width) { this.width = width; } public void setHeight(int height) { this.height = height; } + /** + * Checks whether two rect objects are equal. Two instances + * of <code>Rectangle</code> are equal if the four integer values + * of the fields <code>y</code>, <code>x</code>, + * <code>height</code>, and <code>width</code> are all equal. + * @return <code>true</code> if the two rectangles are equal; + * otherwise <code>false</code>. + */ + public boolean equals(Object obj) { + if (obj instanceof Rectangle) { + Rectangle rect = (Rectangle)obj; + return (y == rect.y) && (x == rect.x) && + (height == rect.height) && (width == rect.width); + } + return false; + } + + /** + * Returns the hash code for this Rectangle. + * + * @return a hash code for this Rectangle. + */ + public int hashCode() { + int sum1 = x + height; + int sum2 = width + y; + int val1 = sum1 * (sum1 + 1)/2 + x; + int val2 = sum2 * (sum2 + 1)/2 + y; + int sum3 = val1 + val2; + return sum3 * (sum3 + 1)/2 + val2; + } + public String toString() { return new String("Rect["+x+"/"+y+" "+width+"x"+height+"]"); } |