|
From: <eli...@us...> - 2008-05-01 09:21:00
|
Revision: 3060
http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3060&view=rev
Author: elias_naur
Date: 2008-05-01 02:20:57 -0700 (Thu, 01 May 2008)
Log Message:
-----------
Windows: Moved icon handles to java
Modified Paths:
--------------
trunk/LWJGL/src/java/org/lwjgl/WindowsSysImplementation.java
trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java
trunk/LWJGL/src/native/windows/org_lwjgl_opengl_Display.c
Modified: trunk/LWJGL/src/java/org/lwjgl/WindowsSysImplementation.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/WindowsSysImplementation.java 2008-04-30 19:00:08 UTC (rev 3059)
+++ trunk/LWJGL/src/java/org/lwjgl/WindowsSysImplementation.java 2008-05-01 09:20:57 UTC (rev 3060)
@@ -45,7 +45,7 @@
* $Id$
*/
final class WindowsSysImplementation extends DefaultSysImplementation {
- private final static int JNI_VERSION = 17;
+ private final static int JNI_VERSION = 18;
static {
Sys.initialize();
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java 2008-04-30 19:00:08 UTC (rev 3059)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java 2008-05-01 09:20:57 UTC (rev 3060)
@@ -68,6 +68,7 @@
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 @@
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 @@
private long hwnd;
private long hdc;
+ private long small_icon;
+ private long large_icon;
+
public WindowsDisplay() {
current_display = this;
}
@@ -192,6 +199,8 @@
public void destroyWindow() {
nDestroyWindow(hwnd, hdc);
+ freeLargeIcon();
+ freeSmallIcon();
resetCursorClipping();
}
private static native void nDestroyWindow(long hwnd, long hdc);
@@ -580,7 +589,20 @@
((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.
* <ul>
@@ -604,12 +626,16 @@
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,11 +643,10 @@
return used;
}
+ 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 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 void handleMouseButton(int button, int state, long millis) {
if (mouse != null)
mouse.handleMouseButton((byte)button, (byte)state, millis);
Modified: trunk/LWJGL/src/native/windows/org_lwjgl_opengl_Display.c
===================================================================
--- trunk/LWJGL/src/native/windows/org_lwjgl_opengl_Display.c 2008-04-30 19:00:08 UTC (rev 3059)
+++ trunk/LWJGL/src/native/windows/org_lwjgl_opengl_Display.c 2008-05-01 09:20:57 UTC (rev 3060)
@@ -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 @@
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 @@
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;
+JNIEXPORT void JNICALL Java_org_lwjgl_opengl_WindowsDisplay_destroyIcon
+ (JNIEnv *env, jclass clazz, jlong handle) {
+ HICON icon = (HICON)(INT_PTR)handle;
+ DestroyIcon(icon);
+}
+
+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);
-
- 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;
+ return (INT_PTR)createWindowIcon(env, imgData, width, height);
}
-JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_WindowsDisplay_nSetWindowIconLarge
- (JNIEnv *env, jclass clazz, jlong hwnd_ptr, jint width, jint height, jobject iconBuffer)
-{
+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;
- 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 SendMessage(hwnd, (UINT)msg, (WPARAM)wparam, (LPARAM)lparam);
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_WindowsDisplay_nSetCursorPosition
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|