Windows: Moved icon handles to java
This commit is contained in:
parent
4dde43f5fe
commit
0a3bf6e075
|
@ -45,7 +45,7 @@ import org.lwjgl.opengl.Display;
|
|||
* $Id$
|
||||
*/
|
||||
final class WindowsSysImplementation extends DefaultSysImplementation {
|
||||
private final static int JNI_VERSION = 17;
|
||||
private final static int JNI_VERSION = 18;
|
||||
|
||||
static {
|
||||
Sys.initialize();
|
||||
|
|
|
@ -68,6 +68,7 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
private final static int WM_SYSKEYDOWN = 260;
|
||||
private final static int WM_SYSCHAR = 262;
|
||||
private final static int WM_CHAR = 258;
|
||||
private final static int WM_SETICON = 0x0080;
|
||||
|
||||
private final static int WM_QUIT = 0x0012;
|
||||
private final static int WM_SYSCOMMAND = 0x0112;
|
||||
|
@ -113,6 +114,9 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
private final static int SW_SHOWDEFAULT = 10;
|
||||
private final static int SW_RESTORE = 9;
|
||||
|
||||
private final static int ICON_SMALL = 0;
|
||||
private final static int ICON_BIG = 1;
|
||||
|
||||
private final static IntBuffer rect_buffer = BufferUtils.createIntBuffer(4);
|
||||
private final static Rect rect = new Rect();
|
||||
private final static Rect rect2 = new Rect();
|
||||
|
@ -143,6 +147,9 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
private long hwnd;
|
||||
private long hdc;
|
||||
|
||||
private long small_icon;
|
||||
private long large_icon;
|
||||
|
||||
public WindowsDisplay() {
|
||||
current_display = this;
|
||||
}
|
||||
|
@ -192,6 +199,8 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
|
||||
public void destroyWindow() {
|
||||
nDestroyWindow(hwnd, hdc);
|
||||
freeLargeIcon();
|
||||
freeSmallIcon();
|
||||
resetCursorClipping();
|
||||
}
|
||||
private static native void nDestroyWindow(long hwnd, long hdc);
|
||||
|
@ -580,6 +589,19 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
((WindowsPbufferPeerInfo)handle).releaseTexImageFromPbuffer(buffer);
|
||||
}
|
||||
|
||||
private void freeSmallIcon() {
|
||||
if (small_icon != 0) {
|
||||
destroyIcon(small_icon);
|
||||
small_icon = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void freeLargeIcon() {
|
||||
if (large_icon != 0) {
|
||||
destroyIcon(large_icon);
|
||||
large_icon = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets one or more icons for the Display.
|
||||
|
@ -604,12 +626,16 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
int size = icons[i].limit() / 4;
|
||||
|
||||
if ((((int) Math.sqrt(size)) == small_icon_size) && (!done_small)) {
|
||||
nSetWindowIconSmall(hwnd, small_icon_size, small_icon_size, icons[i].asIntBuffer());
|
||||
freeSmallIcon();
|
||||
small_icon = createIcon(small_icon_size, small_icon_size, icons[i].asIntBuffer());
|
||||
sendMessage(hwnd, WM_SETICON, ICON_SMALL, small_icon);
|
||||
used++;
|
||||
done_small = true;
|
||||
}
|
||||
if ((((int) Math.sqrt(size)) == large_icon_size) && (!done_large)) {
|
||||
nSetWindowIconLarge(hwnd, large_icon_size, large_icon_size, icons[i].asIntBuffer());
|
||||
freeLargeIcon();
|
||||
large_icon = createIcon(large_icon_size, large_icon_size, icons[i].asIntBuffer());
|
||||
sendMessage(hwnd, WM_SETICON, ICON_BIG, large_icon);
|
||||
used++;
|
||||
done_large = true;
|
||||
}
|
||||
|
@ -617,10 +643,9 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
|
||||
return used;
|
||||
}
|
||||
|
||||
private static native int nSetWindowIconSmall(long hwnd, int width, int height, IntBuffer icon);
|
||||
|
||||
private static native int nSetWindowIconLarge(long hwnd, int width, int height, IntBuffer icon);
|
||||
private static native long createIcon(int width, int height, IntBuffer icon);
|
||||
private static native void destroyIcon(long handle);
|
||||
private static native long sendMessage(long hwnd, long msg, long wparam, long lparam);
|
||||
|
||||
private void handleMouseButton(int button, int state, long millis) {
|
||||
if (mouse != null)
|
||||
|
|
|
@ -50,25 +50,8 @@
|
|||
#include "org_lwjgl_WindowsSysImplementation.h"
|
||||
#include "context.h"
|
||||
|
||||
static HICON small_icon = NULL;
|
||||
static HICON large_icon = NULL;
|
||||
|
||||
#define WINDOWCLASSNAME "LWJGL"
|
||||
|
||||
static void freeLargeIcon() {
|
||||
if (large_icon != NULL) {
|
||||
DestroyIcon(large_icon);
|
||||
large_icon = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void freeSmallIcon() {
|
||||
if (small_icon != NULL) {
|
||||
DestroyIcon(small_icon);
|
||||
small_icon = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* WindowProc for the GL window.
|
||||
*/
|
||||
|
@ -173,8 +156,6 @@ static void destroyWindow(JNIEnv *env, HWND *hwnd, HDC *hdc) {
|
|||
closeWindow(hwnd, hdc);
|
||||
if (display_class_global != NULL)
|
||||
(*env)->DeleteGlobalRef(env, display_class_global);
|
||||
freeLargeIcon();
|
||||
freeSmallIcon();
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_org_lwjgl_opengl_WindowsDisplay_nCreateWindow(JNIEnv *env, jobject self, jobject mode, jboolean fullscreen, jint x, jint y, jboolean undecorated, jboolean child_window, jlong parent_hwnd) {
|
||||
|
@ -453,42 +434,22 @@ static HICON createWindowIcon(JNIEnv *env, jint *pixels, jint width, jint height
|
|||
return icon;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_WindowsDisplay_nSetWindowIconSmall
|
||||
(JNIEnv *env, jclass clazz, jlong hwnd_ptr, jint width, jint height, jobject iconBuffer)
|
||||
{
|
||||
HWND hwnd = (HWND)(INT_PTR)hwnd_ptr;
|
||||
jint *imgData = (jint *)(*env)->GetDirectBufferAddress(env, iconBuffer);
|
||||
|
||||
freeSmallIcon();
|
||||
small_icon = createWindowIcon(env, imgData, width, height);
|
||||
if (small_icon != NULL) {
|
||||
if (hwnd != NULL) {
|
||||
SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM) (small_icon));
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_WindowsDisplay_destroyIcon
|
||||
(JNIEnv *env, jclass clazz, jlong handle) {
|
||||
HICON icon = (HICON)(INT_PTR)handle;
|
||||
DestroyIcon(icon);
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_WindowsDisplay_nSetWindowIconLarge
|
||||
(JNIEnv *env, jclass clazz, jlong hwnd_ptr, jint width, jint height, jobject iconBuffer)
|
||||
{
|
||||
HWND hwnd = (HWND)(INT_PTR)hwnd_ptr;
|
||||
JNIEXPORT jlong JNICALL Java_org_lwjgl_opengl_WindowsDisplay_createIcon
|
||||
(JNIEnv *env, jclass clazz, jint width, jint height, jobject iconBuffer) {
|
||||
jint *imgData = (jint *)(*env)->GetDirectBufferAddress(env, iconBuffer);
|
||||
|
||||
freeLargeIcon();
|
||||
large_icon = createWindowIcon(env, imgData, width, height);
|
||||
if (large_icon != NULL) {
|
||||
if (hwnd != NULL) {
|
||||
SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM) (large_icon));
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
return (INT_PTR)createWindowIcon(env, imgData, width, height);
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_org_lwjgl_opengl_WindowsDisplay_sendMessage
|
||||
(JNIEnv *env, jclass clazz, jlong hwnd_ptr, jlong msg, jlong wparam, jlong lparam) {
|
||||
HWND hwnd = (HWND)(INT_PTR)hwnd_ptr;
|
||||
return SendMessage(hwnd, (UINT)msg, (WPARAM)wparam, (LPARAM)lparam);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_WindowsDisplay_nSetCursorPosition
|
||||
|
|
Loading…
Reference in New Issue