Added methods to set the window icon. MacOS implementation added using AWT images.

This commit is contained in:
Kevin Glass 2005-07-05 21:54:12 +00:00
parent 0208d5b6d5
commit 94e0bb30c0
5 changed files with 140 additions and 0 deletions

View File

@ -43,6 +43,7 @@ package org.lwjgl.opengl;
* @author foo
*/
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.util.Arrays;
import java.util.HashSet;
@ -813,4 +814,21 @@ public final class Display {
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);
}
}

View File

@ -230,4 +230,18 @@ public interface DisplayImplementation {
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);
}

View File

@ -436,4 +436,32 @@ final class LinuxDisplay implements DisplayImplementation {
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);
}

View File

@ -513,4 +513,44 @@ final class MacOSXDisplay implements DisplayImplementation {
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;
}
}

View File

@ -156,4 +156,44 @@ final class Win32Display implements DisplayImplementation {
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);
}