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$
|
* $Id$
|
||||||
*/
|
*/
|
||||||
final class WindowsSysImplementation extends DefaultSysImplementation {
|
final class WindowsSysImplementation extends DefaultSysImplementation {
|
||||||
private final static int JNI_VERSION = 17;
|
private final static int JNI_VERSION = 18;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Sys.initialize();
|
Sys.initialize();
|
||||||
|
|
|
@ -68,6 +68,7 @@ final class WindowsDisplay implements DisplayImplementation {
|
||||||
private final static int WM_SYSKEYDOWN = 260;
|
private final static int WM_SYSKEYDOWN = 260;
|
||||||
private final static int WM_SYSCHAR = 262;
|
private final static int WM_SYSCHAR = 262;
|
||||||
private final static int WM_CHAR = 258;
|
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_QUIT = 0x0012;
|
||||||
private final static int WM_SYSCOMMAND = 0x0112;
|
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_SHOWDEFAULT = 10;
|
||||||
private final static int SW_RESTORE = 9;
|
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 IntBuffer rect_buffer = BufferUtils.createIntBuffer(4);
|
||||||
private final static Rect rect = new Rect();
|
private final static Rect rect = new Rect();
|
||||||
private final static Rect rect2 = new Rect();
|
private final static Rect rect2 = new Rect();
|
||||||
|
@ -143,6 +147,9 @@ final class WindowsDisplay implements DisplayImplementation {
|
||||||
private long hwnd;
|
private long hwnd;
|
||||||
private long hdc;
|
private long hdc;
|
||||||
|
|
||||||
|
private long small_icon;
|
||||||
|
private long large_icon;
|
||||||
|
|
||||||
public WindowsDisplay() {
|
public WindowsDisplay() {
|
||||||
current_display = this;
|
current_display = this;
|
||||||
}
|
}
|
||||||
|
@ -192,6 +199,8 @@ final class WindowsDisplay implements DisplayImplementation {
|
||||||
|
|
||||||
public void destroyWindow() {
|
public void destroyWindow() {
|
||||||
nDestroyWindow(hwnd, hdc);
|
nDestroyWindow(hwnd, hdc);
|
||||||
|
freeLargeIcon();
|
||||||
|
freeSmallIcon();
|
||||||
resetCursorClipping();
|
resetCursorClipping();
|
||||||
}
|
}
|
||||||
private static native void nDestroyWindow(long hwnd, long hdc);
|
private static native void nDestroyWindow(long hwnd, long hdc);
|
||||||
|
@ -580,6 +589,19 @@ final class WindowsDisplay implements DisplayImplementation {
|
||||||
((WindowsPbufferPeerInfo)handle).releaseTexImageFromPbuffer(buffer);
|
((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.
|
* Sets one or more icons for the Display.
|
||||||
|
@ -604,12 +626,16 @@ final class WindowsDisplay implements DisplayImplementation {
|
||||||
int size = icons[i].limit() / 4;
|
int size = icons[i].limit() / 4;
|
||||||
|
|
||||||
if ((((int) Math.sqrt(size)) == small_icon_size) && (!done_small)) {
|
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++;
|
used++;
|
||||||
done_small = true;
|
done_small = true;
|
||||||
}
|
}
|
||||||
if ((((int) Math.sqrt(size)) == large_icon_size) && (!done_large)) {
|
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++;
|
used++;
|
||||||
done_large = true;
|
done_large = true;
|
||||||
}
|
}
|
||||||
|
@ -617,10 +643,9 @@ final class WindowsDisplay implements DisplayImplementation {
|
||||||
|
|
||||||
return used;
|
return used;
|
||||||
}
|
}
|
||||||
|
private static native long createIcon(int width, int height, IntBuffer icon);
|
||||||
private static native int nSetWindowIconSmall(long hwnd, 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 static native int nSetWindowIconLarge(long hwnd, int width, int height, IntBuffer icon);
|
|
||||||
|
|
||||||
private void handleMouseButton(int button, int state, long millis) {
|
private void handleMouseButton(int button, int state, long millis) {
|
||||||
if (mouse != null)
|
if (mouse != null)
|
||||||
|
|
|
@ -50,25 +50,8 @@
|
||||||
#include "org_lwjgl_WindowsSysImplementation.h"
|
#include "org_lwjgl_WindowsSysImplementation.h"
|
||||||
#include "context.h"
|
#include "context.h"
|
||||||
|
|
||||||
static HICON small_icon = NULL;
|
|
||||||
static HICON large_icon = NULL;
|
|
||||||
|
|
||||||
#define WINDOWCLASSNAME "LWJGL"
|
#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.
|
* WindowProc for the GL window.
|
||||||
*/
|
*/
|
||||||
|
@ -173,8 +156,6 @@ static void destroyWindow(JNIEnv *env, HWND *hwnd, HDC *hdc) {
|
||||||
closeWindow(hwnd, hdc);
|
closeWindow(hwnd, hdc);
|
||||||
if (display_class_global != NULL)
|
if (display_class_global != NULL)
|
||||||
(*env)->DeleteGlobalRef(env, display_class_global);
|
(*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) {
|
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;
|
return icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_WindowsDisplay_nSetWindowIconSmall
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_WindowsDisplay_destroyIcon
|
||||||
(JNIEnv *env, jclass clazz, jlong hwnd_ptr, jint width, jint height, jobject iconBuffer)
|
(JNIEnv *env, jclass clazz, jlong handle) {
|
||||||
{
|
HICON icon = (HICON)(INT_PTR)handle;
|
||||||
HWND hwnd = (HWND)(INT_PTR)hwnd_ptr;
|
DestroyIcon(icon);
|
||||||
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 jint JNICALL Java_org_lwjgl_opengl_WindowsDisplay_nSetWindowIconLarge
|
JNIEXPORT jlong JNICALL Java_org_lwjgl_opengl_WindowsDisplay_createIcon
|
||||||
(JNIEnv *env, jclass clazz, jlong hwnd_ptr, jint width, jint height, jobject iconBuffer)
|
(JNIEnv *env, jclass clazz, jint width, jint height, jobject iconBuffer) {
|
||||||
{
|
|
||||||
HWND hwnd = (HWND)(INT_PTR)hwnd_ptr;
|
|
||||||
jint *imgData = (jint *)(*env)->GetDirectBufferAddress(env, iconBuffer);
|
jint *imgData = (jint *)(*env)->GetDirectBufferAddress(env, iconBuffer);
|
||||||
|
return (INT_PTR)createWindowIcon(env, imgData, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
freeLargeIcon();
|
JNIEXPORT jlong JNICALL Java_org_lwjgl_opengl_WindowsDisplay_sendMessage
|
||||||
large_icon = createWindowIcon(env, imgData, width, height);
|
(JNIEnv *env, jclass clazz, jlong hwnd_ptr, jlong msg, jlong wparam, jlong lparam) {
|
||||||
if (large_icon != NULL) {
|
HWND hwnd = (HWND)(INT_PTR)hwnd_ptr;
|
||||||
if (hwnd != NULL) {
|
return SendMessage(hwnd, (UINT)msg, (WPARAM)wparam, (LPARAM)lparam);
|
||||||
SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM) (large_icon));
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_WindowsDisplay_nSetCursorPosition
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_WindowsDisplay_nSetCursorPosition
|
||||||
|
|
Loading…
Reference in New Issue