|
From: Elias N. <eli...@us...> - 2003-11-03 13:34:09
|
Update of /cvsroot/java-game-lib/LWJGL/src/native/macosx In directory sc8-pr-cvs1:/tmp/cvs-serv1819/macosx Modified Files: org_lwjgl_Display.cpp org_lwjgl_input_Keyboard.cpp org_lwjgl_opengl_Window.cpp Log Message: Updated to make input work with Mac OS X 10.3 Index: org_lwjgl_Display.cpp CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/macosx/org_lwjgl_Display.cpp =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/macosx/org_lwjgl_Display.cpp,v retrieving revision 1.25 retrieving revision 1.26 diff -u -d -r1.25 -r1.26 --- org_lwjgl_Display.cpp 24 Oct 2003 11:45:55 -0000 1.25 +++ org_lwjgl_Display.cpp 3 Nov 2003 13:34:06 -0000 1.26 @@ -108,6 +108,24 @@ return false; } +bool switchToNearestMode(JNIEnv *env, long width, long height, long bpp, long freq) { + init(env); + if (display_captured) + return false; + display_captured = true; + CGDisplayCapture(kCGDirectMainDisplay); + boolean_t match; + CFDictionaryRef mode = CGDisplayBestModeForParametersAndRefreshRate(kCGDirectMainDisplay, bpp, width, height, freq, &match); + if (mode == NULL) + return false; + CGDisplayErr err = CGDisplaySwitchToMode(kCGDirectMainDisplay, mode); + if (!err) { + saveMode(env, width, height, bpp, freq); + return true; + } else + return false; +} + void resetMode(JNIEnv *env) { init(env); if (!display_captured) Index: org_lwjgl_input_Keyboard.cpp CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/macosx/org_lwjgl_input_Keyboard.cpp =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/macosx/org_lwjgl_input_Keyboard.cpp,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- org_lwjgl_input_Keyboard.cpp 22 Oct 2003 10:57:19 -0000 1.16 +++ org_lwjgl_input_Keyboard.cpp 3 Nov 2003 13:34:06 -0000 1.17 @@ -45,7 +45,7 @@ #include "common_tools.h" #define KEYBOARD_SIZE 256 -#define UNICODE_BUFFER_SIZE 10 +#define TRANSLATION_BUFFER_SIZE 10 static unsigned char key_buf[KEYBOARD_SIZE]; static unsigned char key_map[KEYBOARD_SIZE]; @@ -60,7 +60,7 @@ if (buffer_enabled) { putEventElement(&event_queue, mapped_code); putEventElement(&event_queue, state); - return true; + return translation_enabled; } } return false; @@ -91,7 +91,7 @@ return (unsigned char)((ch & 0xff00) >> 16); } -static bool writeChars(int num_chars, UniChar *buffer) { +static bool writeUniChars(int num_chars, const UniChar *buffer) { if (num_chars == 0) return false; unsigned char b0 = getFirstByte(buffer[0]); @@ -109,8 +109,24 @@ return true; } +static bool writeAsciiChars(int num_chars, const char *buffer) { + if (num_chars == 0) + return false; + unsigned char c = buffer[0]; + putEventElement(&event_queue, 0); + putEventElement(&event_queue, c); + for (int i = 1; i < num_chars; i++) { + putEventElement(&event_queue, 0); + putEventElement(&event_queue, 0); + unsigned char c = buffer[i]; + putEventElement(&event_queue, 0); + putEventElement(&event_queue, c); + } + return true; +} + static bool handleUnicode(EventRef event) { - UniChar unicode_buffer[UNICODE_BUFFER_SIZE]; + UniChar unicode_buffer[TRANSLATION_BUFFER_SIZE]; UInt32 data_size; int num_chars; OSStatus err = GetEventParameter(event, kEventParamKeyUnicodes, typeUnicodeText, NULL, 0, &data_size, NULL); @@ -121,7 +137,7 @@ return false; } num_chars = data_size/sizeof(UniChar); - if (num_chars >= UNICODE_BUFFER_SIZE) { + if (num_chars >= TRANSLATION_BUFFER_SIZE) { #ifdef _DEBUG printf("Unicode chars could not fit in buffer\n"); #endif @@ -134,7 +150,39 @@ #endif return false; } - return writeChars(num_chars, unicode_buffer); + return writeUniChars(num_chars, unicode_buffer); +} + +static bool handleAscii(EventRef event) { + char ascii_buffer[TRANSLATION_BUFFER_SIZE]; + UInt32 data_size; + int num_chars; + OSStatus err = GetEventParameter(event, kEventParamKeyMacCharCodes, typeChar, NULL, 0, &data_size, NULL); + if (err != noErr) { +#ifdef _DEBUG + printf("Could not get ascii char count\n"); +#endif + return false; + } + num_chars = data_size/sizeof(char); + if (num_chars >= TRANSLATION_BUFFER_SIZE) { +#ifdef _DEBUG + printf("Ascii chars could not fit in buffer\n"); +#endif + return false; + } + err = GetEventParameter(event, kEventParamKeyMacCharCodes, typeChar, NULL, data_size, NULL, ascii_buffer); + if (err != noErr) { +#ifdef _DEBUG + printf("Could not get ascii chars\n"); +#endif + return false; + } + return writeAsciiChars(num_chars, ascii_buffer); +} + +static bool handleTranslation(EventRef event) { + return handleUnicode(event) || handleAscii(event); } static void doKeyDown(EventRef event) { @@ -146,16 +194,9 @@ #endif return; } - if (handleKey(key_code, 1)) { - if (translation_enabled) { - if (!handleUnicode(event)) { - putEventElement(&event_queue, 0); - putEventElement(&event_queue, 0); - } - } else { - putEventElement(&event_queue, 0); - putEventElement(&event_queue, 0); - } + if (handleKey(key_code, 1) && !handleTranslation(event)) { + putEventElement(&event_queue, 0); + putEventElement(&event_queue, 0); } } @@ -168,7 +209,7 @@ #endif return; } - if (handleKey(key_code, 0)) { + if (handleKey(key_code, 0) && !handleTranslation(event)) { putEventElement(&event_queue, 0); putEventElement(&event_queue, 0); } Index: org_lwjgl_opengl_Window.cpp CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/macosx/org_lwjgl_opengl_Window.cpp =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/macosx/org_lwjgl_opengl_Window.cpp,v retrieving revision 1.30 retrieving revision 1.31 diff -u -d -r1.30 -r1.31 --- org_lwjgl_opengl_Window.cpp 2 Nov 2003 11:34:27 -0000 1.30 +++ org_lwjgl_opengl_Window.cpp 3 Nov 2003 13:34:06 -0000 1.31 @@ -113,7 +113,7 @@ return; } if (!current_fullscreen) { - if (!switchMode(env, width, height, bpp, 60)) { + if (!switchToNearestMode(env, width, height, bpp, 60)) { destroyMode(env, clazz); extgl_Close(); throwException(env, "Could not switch mode."); |