|
From: Kevin G. <kev...@us...> - 2005-07-05 21:54:21
|
Update of /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/opengl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20948/src/java/org/lwjgl/opengl Modified Files: MacOSXDisplay.java LinuxDisplay.java DisplayImplementation.java Display.java Win32Display.java Log Message: Added methods to set the window icon. MacOS implementation added using AWT images. Index: Win32Display.java =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/opengl/Win32Display.java,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- Win32Display.java 4 May 2005 20:59:36 -0000 1.18 +++ Win32Display.java 5 Jul 2005 21:54:12 -0000 1.19 @@ -156,4 +156,44 @@ public void releaseTexImageFromPbuffer(PeerInfo handle, int buffer) { ((Win32PbufferPeerInfo)handle).releaseTexImageFromPbuffer(buffer); } + + + /** + * Sets one or more icons for the Display. + * <ul> + * <li>On Windows you should supply at least one 16x16 icon and one 32x32.</li> + * <li>Linux (and similar platforms) expect one 32x32 icon.</li> + * <li>Mac OS X should be supplied one 128x128 icon</li> + * </ul> + * The implementation will use the supplied ByteBuffers with image data in RGBA and perform any conversions nescesarry for the specific platform. + * + * @param icons Array of icons in RGBA mode + * @return number of icons used. + */ + public int setIcon(ByteBuffer[] icons) { + boolean done16 = false; + boolean done32 = false; + int used = 0; + + for (int i=0;i<icons.length;i++) { + int size = icons[i].limit(); + + if ((((int) Math.sqrt(size)) == 16) && (!done16)) { + nSetWindowIcon16(icons[i]); + used++; + done16 = true; + } + if ((((int) Math.sqrt(size)) == 32) && (!done32)) { + nSetWindowIcon32(icons[i]); + used++; + done32 = true; + } + } + + return used; + } + + private static native int nSetWindowIcon16(ByteBuffer icon); + + private static native int nSetWindowIcon32(ByteBuffer icon); } Index: DisplayImplementation.java =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/opengl/DisplayImplementation.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- DisplayImplementation.java 4 May 2005 20:59:36 -0000 1.13 +++ DisplayImplementation.java 5 Jul 2005 21:54:12 -0000 1.14 @@ -230,4 +230,18 @@ public void bindTexImageToPbuffer(PeerInfo handle, int buffer); public void releaseTexImageFromPbuffer(PeerInfo handle, int buffer); + + /** + * Sets one or more icons for the Display. + * <ul> + * <li>On Windows you should supply at least one 16x16 icon and one 32x32.</li> + * <li>Linux (and similar platforms) expect one 32x32 icon.</li> + * <li>Mac OS X should be supplied one 128x128 icon</li> + * </ul> + * The implementation will use the supplied ByteBuffers with image data in RGBA and perform any conversions nescesarry for the specific platform. + * + * @param icons Array of icons in RGBA mode + * @return number of icons used. + */ + public int setIcon(ByteBuffer[] icons); } Index: MacOSXDisplay.java =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java,v retrieving revision 1.33 retrieving revision 1.34 diff -u -d -r1.33 -r1.34 --- MacOSXDisplay.java 1 Jun 2005 07:18:09 -0000 1.33 +++ MacOSXDisplay.java 5 Jul 2005 21:54:12 -0000 1.34 @@ -513,4 +513,44 @@ public void releaseTexImageFromPbuffer(PeerInfo handle, int buffer) { throw new UnsupportedOperationException(); } + + /** + * Sets one or more icons for the Display. + * <ul> + * <li>On Windows you should supply at least one 16x16 icon and one 32x32.</li> + * <li>Linux (and similar platforms) expect one 32x32 icon.</li> + * <li>Mac OS X should be supplied one 128x128 icon</li> + * </ul> + * The implementation will use the supplied ByteBuffers with image data in RGBA and perform any conversions nescesarry for the specific platform. + * + * @param icons Array of icons in RGBA mode + * @return number of icons used. + */ + public int setIcon(ByteBuffer[] icons) { + int size = 0; + int biggest = -1; + + for (int i=0;i<icons.length;i++) { + if (icons[i].limit() > size) { + biggest = i; + size = icons[i].limit(); + } + } + + if (biggest == -1) { + return 0; + } + + int width; + int height; + + width = height = (int) Math.sqrt(size); + int[] imageData = icons[biggest].asIntBuffer().array(); + + BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); + img.setRGB(0, 0, width, height, imageData, 0, width); + frame.setIconImage(img); + + return 1; + } } Index: Display.java =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/opengl/Display.java,v retrieving revision 1.53 retrieving revision 1.54 diff -u -d -r1.53 -r1.54 --- Display.java 29 Jun 2005 20:48:58 -0000 1.53 +++ Display.java 5 Jul 2005 21:54:12 -0000 1.54 @@ -43,6 +43,7 @@ * @author foo */ +import java.nio.ByteBuffer; import java.nio.FloatBuffer; import java.util.Arrays; import java.util.HashSet; @@ -813,4 +814,21 @@ public static String getVersion() { return display_impl.getVersion(); } + + + /** + * Sets one or more icons for the Display. + * <ul> + * <li>On Windows you should supply at least one 16x16 icon and one 32x32.</li> + * <li>Linux (and similar platforms) expect one 32x32 icon.</li> + * <li>Mac OS X should be supplied one 128x128 icon</li> + * </ul> + * The implementation will use the supplied ByteBuffers with image data in RGBA and perform any conversions nescesarry for the specific platform. + * + * @param icons Array of icons in RGBA mode + * @return number of icons used. + */ + public static int setIcon(ByteBuffer[] icons) { + return display_impl.setIcon(icons); + } } Index: LinuxDisplay.java =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java,v retrieving revision 1.26 retrieving revision 1.27 diff -u -d -r1.26 -r1.27 --- LinuxDisplay.java 4 May 2005 20:59:36 -0000 1.26 +++ LinuxDisplay.java 5 Jul 2005 21:54:12 -0000 1.27 @@ -436,4 +436,32 @@ public void releaseTexImageFromPbuffer(PeerInfo handle, int buffer) { throw new UnsupportedOperationException(); } + + + /** + * Sets one or more icons for the Display. + * <ul> + * <li>On Windows you should supply at least one 16x16 icon and one 32x32.</li> + * <li>Linux (and similar platforms) expect one 32x32 icon.</li> + * <li>Mac OS X should be supplied one 128x128 icon</li> + * </ul> + * The implementation will use the supplied ByteBuffers with image data in RGBA and perform any conversions nescesarry for the specific platform. + * + * @param icons Array of icons in RGBA mode + * @return number of icons used. + */ + public int setIcon(ByteBuffer[] icons) { + for (int i=0;i<icons.length;i++) { + int size = icons[i].limit(); + + if (((int) Math.sqrt(size)) == 32) { + nSetWindowIcon(icons[i]); + return 1; + } + } + + return 0; + } + + private static native int nSetWindowIcon(ByteBuffer icon); } |