mirror of
https://github.com/shadowfacts/lwjgl2-arm64.git
synced 2026-02-23 08:04:38 +01:00
Mac OS X port, second try :)
This commit is contained in:
parent
4e35eea9ca
commit
1ec70842d0
|
|
@ -332,6 +332,9 @@
|
|||
<javah classpath="${lwjgl.bin}" destdir="${lwjgl.src.native}/win32" force="yes">
|
||||
<class name="org.lwjgl.opengl.Win32Display" />
|
||||
</javah>
|
||||
<javah classpath="${lwjgl.bin}" destdir="${lwjgl.src.native}/macosx" force="yes">
|
||||
<class name="org.lwjgl.opengl.MacOSXDisplay" />
|
||||
</javah>
|
||||
<!-- lwjgl -->
|
||||
<javah classpath="${lwjgl.bin}" destdir="${lwjgl.src.headers}" force="yes">
|
||||
<class name="org.lwjgl.Sys" />
|
||||
|
|
|
|||
|
|
@ -197,6 +197,8 @@ public class Keyboard {
|
|||
public static final int STATE_OFF = 1;
|
||||
public static final int STATE_UNKNOWN = 2;
|
||||
|
||||
public final static int KEYBOARD_SIZE = 256;
|
||||
|
||||
/** Buffer size in events */
|
||||
private final static int BUFFER_SIZE = 50;
|
||||
/** Event size in elements */
|
||||
|
|
@ -237,7 +239,7 @@ public class Keyboard {
|
|||
private static boolean created;
|
||||
|
||||
/** The keys status from the last poll */
|
||||
private static final ByteBuffer keyDownBuffer = BufferUtils.createByteBuffer(256);
|
||||
private static final ByteBuffer keyDownBuffer = BufferUtils.createByteBuffer(KEYBOARD_SIZE);
|
||||
|
||||
/**
|
||||
* The key events from the last read: a sequence of pairs of key number,
|
||||
|
|
|
|||
279
src/java/org/lwjgl/opengl/KeyboardEventQueue.java
Normal file
279
src/java/org/lwjgl/opengl/KeyboardEventQueue.java
Normal file
|
|
@ -0,0 +1,279 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2004 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.lwjgl.opengl;
|
||||
|
||||
/**
|
||||
* A java implementation of a LWJGL compatible Keyboard event queue.
|
||||
* Currently only used by the Mac OS X implementation.
|
||||
* @author elias_naur
|
||||
*/
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
import java.awt.event.KeyListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
final class KeyboardEventQueue extends EventQueue implements KeyListener {
|
||||
private final static int[] KEY_MAP = new int[0xffff];
|
||||
private final static int EVENT_SIZE = 3;
|
||||
|
||||
private final byte[] key_states = new byte[Keyboard.KEYBOARD_SIZE];
|
||||
|
||||
/** Event scratch array */
|
||||
private final int[] event = new int[EVENT_SIZE];
|
||||
|
||||
static {
|
||||
KEY_MAP[KeyEvent.VK_0] = Keyboard.KEY_0;
|
||||
KEY_MAP[KeyEvent.VK_1] = Keyboard.KEY_1;
|
||||
KEY_MAP[KeyEvent.VK_2] = Keyboard.KEY_2;
|
||||
KEY_MAP[KeyEvent.VK_3] = Keyboard.KEY_3;
|
||||
KEY_MAP[KeyEvent.VK_4] = Keyboard.KEY_4;
|
||||
KEY_MAP[KeyEvent.VK_5] = Keyboard.KEY_5;
|
||||
KEY_MAP[KeyEvent.VK_6] = Keyboard.KEY_6;
|
||||
KEY_MAP[KeyEvent.VK_7] = Keyboard.KEY_7;
|
||||
KEY_MAP[KeyEvent.VK_8] = Keyboard.KEY_8;
|
||||
KEY_MAP[KeyEvent.VK_9] = Keyboard.KEY_9;
|
||||
KEY_MAP[KeyEvent.VK_A] = Keyboard.KEY_A;
|
||||
// KEY_MAP[KeyEvent.VK_ACCEPT] = Keyboard.KEY_ACCEPT;
|
||||
KEY_MAP[KeyEvent.VK_ADD] = Keyboard.KEY_ADD;
|
||||
// KEY_MAP[KeyEvent.VK_AGAIN] = Keyboard.KEY_AGAIN;
|
||||
// KEY_MAP[KeyEvent.VK_ALL_CANDIDATES] = Keyboard.KEY_ALL_CANDIDATES;
|
||||
// KEY_MAP[KeyEvent.VK_ALPHANUMERIC] = Keyboard.KEY_ALPHANUMERIC;
|
||||
KEY_MAP[KeyEvent.VK_ALT] = Keyboard.KEY_LMENU;
|
||||
KEY_MAP[KeyEvent.VK_ALT_GRAPH] = Keyboard.KEY_RMENU;
|
||||
// KEY_MAP[KeyEvent.VK_AMPERSAND] = Keyboard.KEY_AMPERSAND;
|
||||
// KEY_MAP[KeyEvent.VK_ASTERISK] = Keyboard.KEY_ASTERISK;
|
||||
KEY_MAP[KeyEvent.VK_AT] = Keyboard.KEY_AT;
|
||||
KEY_MAP[KeyEvent.VK_B] = Keyboard.KEY_B;
|
||||
// KEY_MAP[KeyEvent.VK_BACK_QUOTE] = Keyboard.KEY_BACK_QUOTE;
|
||||
KEY_MAP[KeyEvent.VK_BACK_SLASH] = Keyboard.KEY_BACKSLASH;
|
||||
KEY_MAP[KeyEvent.VK_BACK_SPACE] = Keyboard.KEY_BACK;
|
||||
// KEY_MAP[KeyEvent.VK_BRACELEFT] = Keyboard.KEY_BRACELEFT;
|
||||
// KEY_MAP[KeyEvent.VK_BRACERIGHT] = Keyboard.KEY_BRACERIGHT;
|
||||
KEY_MAP[KeyEvent.VK_C] = Keyboard.KEY_C;
|
||||
// KEY_MAP[KeyEvent.VK_CANCEL] = Keyboard.KEY_CANCEL;
|
||||
KEY_MAP[KeyEvent.VK_CAPS_LOCK] = Keyboard.KEY_CAPITAL;
|
||||
KEY_MAP[KeyEvent.VK_CIRCUMFLEX] = Keyboard.KEY_CIRCUMFLEX;
|
||||
// KEY_MAP[KeyEvent.VK_CLEAR] = Keyboard.KEY_CLEAR;
|
||||
KEY_MAP[KeyEvent.VK_CLOSE_BRACKET] = Keyboard.KEY_RBRACKET;
|
||||
// KEY_MAP[KeyEvent.VK_CODE_INPUT] = Keyboard.KEY_CODE_INPUT;
|
||||
KEY_MAP[KeyEvent.VK_COLON] = Keyboard.KEY_COLON;
|
||||
KEY_MAP[KeyEvent.VK_COMMA] = Keyboard.KEY_COMMA;
|
||||
// KEY_MAP[KeyEvent.VK_COMPOSE] = Keyboard.KEY_COMPOSE;
|
||||
KEY_MAP[KeyEvent.VK_CONTROL] = Keyboard.KEY_LCONTROL;
|
||||
KEY_MAP[KeyEvent.VK_CONVERT] = Keyboard.KEY_CONVERT;
|
||||
// KEY_MAP[KeyEvent.VK_COPY] = Keyboard.KEY_COPY;
|
||||
// KEY_MAP[KeyEvent.VK_CUT] = Keyboard.KEY_CUT;
|
||||
KEY_MAP[KeyEvent.VK_D] = Keyboard.KEY_D;
|
||||
// KEY_MAP[KeyEvent.VK_DEAD_ABOVEDOT] = Keyboard.KEY_DEAD_ABOVEDOT;
|
||||
// KEY_MAP[KeyEvent.VK_DEAD_ABOVERING] = Keyboard.KEY_DEAD_ABOVERING;
|
||||
// KEY_MAP[KeyEvent.VK_DEAD_ACUTE] = Keyboard.KEY_DEAD_ACUTE;
|
||||
// KEY_MAP[KeyEvent.VK_DEAD_BREVE] = Keyboard.KEY_DEAD_BREVE;
|
||||
// KEY_MAP[KeyEvent.VK_DEAD_CARON] = Keyboard.KEY_DEAD_CARON;
|
||||
// KEY_MAP[KeyEvent.VK_DEAD_CEDILLA] = Keyboard.KEY_DEAD_CEDILLA;
|
||||
// KEY_MAP[KeyEvent.VK_DEAD_CIRCUMFLEX] = Keyboard.KEY_DEAD_CIRCUMFLEX;
|
||||
// KEY_MAP[KeyEvent.VK_DEAD_DIAERESIS] = Keyboard.KEY_DEAD_DIAERESIS;
|
||||
// KEY_MAP[KeyEvent.VK_DEAD_DOUBLEACUTE] = Keyboard.KEY_DEAD_DOUBLEACUTE;
|
||||
// KEY_MAP[KeyEvent.VK_DEAD_GRAVE] = Keyboard.KEY_DEAD_GRAVE;
|
||||
// KEY_MAP[KeyEvent.VK_DEAD_IOTA] = Keyboard.KEY_DEAD_IOTA;
|
||||
// KEY_MAP[KeyEvent.VK_DEAD_MACRON] = Keyboard.KEY_DEAD_MACRON;
|
||||
// KEY_MAP[KeyEvent.VK_DEAD_OGONEK] = Keyboard.KEY_DEAD_OGONEK;
|
||||
// KEY_MAP[KeyEvent.VK_DEAD_SEMIVOICED_SOUND] = Keyboard.KEY_DEAD_SEMIVOICED_SOUND;
|
||||
// KEY_MAP[KeyEvent.VK_DEAD_TILDE] = Keyboard.KEY_DEAD_TILDE;
|
||||
// KEY_MAP[KeyEvent.VK_DEAD_VOICED_SOUND] = Keyboard.KEY_DEAD_VOICED_SOUND;
|
||||
KEY_MAP[KeyEvent.VK_DECIMAL] = Keyboard.KEY_DECIMAL;
|
||||
KEY_MAP[KeyEvent.VK_DELETE] = Keyboard.KEY_DELETE;
|
||||
KEY_MAP[KeyEvent.VK_DIVIDE] = Keyboard.KEY_DIVIDE;
|
||||
// KEY_MAP[KeyEvent.VK_DOLLAR] = Keyboard.KEY_DOLLAR;
|
||||
KEY_MAP[KeyEvent.VK_DOWN] = Keyboard.KEY_DOWN;
|
||||
KEY_MAP[KeyEvent.VK_E] = Keyboard.KEY_E;
|
||||
KEY_MAP[KeyEvent.VK_END] = Keyboard.KEY_END;
|
||||
KEY_MAP[KeyEvent.VK_ENTER] = Keyboard.KEY_RETURN;
|
||||
KEY_MAP[KeyEvent.VK_EQUALS] = Keyboard.KEY_EQUALS;
|
||||
KEY_MAP[KeyEvent.VK_ESCAPE] = Keyboard.KEY_ESCAPE;
|
||||
// KEY_MAP[KeyEvent.VK_EURO_SIGN] = Keyboard.KEY_EURO_SIGN;
|
||||
// KEY_MAP[KeyEvent.VK_EXCLAMATION_MARK] = Keyboard.KEY_EXCLAMATION_MARK;
|
||||
KEY_MAP[KeyEvent.VK_F] = Keyboard.KEY_F;
|
||||
KEY_MAP[KeyEvent.VK_F1] = Keyboard.KEY_F1;
|
||||
KEY_MAP[KeyEvent.VK_F10] = Keyboard.KEY_F10;
|
||||
KEY_MAP[KeyEvent.VK_F11] = Keyboard.KEY_F11;
|
||||
KEY_MAP[KeyEvent.VK_F12] = Keyboard.KEY_F12;
|
||||
KEY_MAP[KeyEvent.VK_F13] = Keyboard.KEY_F13;
|
||||
KEY_MAP[KeyEvent.VK_F14] = Keyboard.KEY_F14;
|
||||
KEY_MAP[KeyEvent.VK_F15] = Keyboard.KEY_F15;
|
||||
// KEY_MAP[KeyEvent.VK_F16] = Keyboard.KEY_F16;
|
||||
// KEY_MAP[KeyEvent.VK_F17] = Keyboard.KEY_F17;
|
||||
// KEY_MAP[KeyEvent.VK_F18] = Keyboard.KEY_F18;
|
||||
// KEY_MAP[KeyEvent.VK_F19] = Keyboard.KEY_F19;
|
||||
KEY_MAP[KeyEvent.VK_F2] = Keyboard.KEY_F2;
|
||||
// KEY_MAP[KeyEvent.VK_F20] = Keyboard.KEY_F20;
|
||||
// KEY_MAP[KeyEvent.VK_F21] = Keyboard.KEY_F21;
|
||||
// KEY_MAP[KeyEvent.VK_F22] = Keyboard.KEY_F22;
|
||||
// KEY_MAP[KeyEvent.VK_F23] = Keyboard.KEY_F23;
|
||||
// KEY_MAP[KeyEvent.VK_F24] = Keyboard.KEY_F24;
|
||||
KEY_MAP[KeyEvent.VK_F3] = Keyboard.KEY_F3;
|
||||
KEY_MAP[KeyEvent.VK_F4] = Keyboard.KEY_F4;
|
||||
KEY_MAP[KeyEvent.VK_F5] = Keyboard.KEY_F5;
|
||||
KEY_MAP[KeyEvent.VK_F6] = Keyboard.KEY_F6;
|
||||
KEY_MAP[KeyEvent.VK_F7] = Keyboard.KEY_F7;
|
||||
KEY_MAP[KeyEvent.VK_F8] = Keyboard.KEY_F8;
|
||||
KEY_MAP[KeyEvent.VK_F9] = Keyboard.KEY_F9;
|
||||
// KEY_MAP[KeyEvent.VK_FINAL] = Keyboard.KEY_FINAL;
|
||||
// KEY_MAP[KeyEvent.VK_FIND] = Keyboard.KEY_FIND;
|
||||
// KEY_MAP[KeyEvent.VK_FULL_WIDTH] = Keyboard.KEY_FULL_WIDTH;
|
||||
KEY_MAP[KeyEvent.VK_G] = Keyboard.KEY_G;
|
||||
// KEY_MAP[KeyEvent.VK_GREATER] = Keyboard.KEY_GREATER;
|
||||
KEY_MAP[KeyEvent.VK_H] = Keyboard.KEY_H;
|
||||
// KEY_MAP[KeyEvent.VK_HALF_WIDTH] = Keyboard.KEY_HALF_WIDTH;
|
||||
// KEY_MAP[KeyEvent.VK_HELP] = Keyboard.KEY_HELP;
|
||||
// KEY_MAP[KeyEvent.VK_HIRAGANA] = Keyboard.KEY_HIRAGANA;
|
||||
KEY_MAP[KeyEvent.VK_HOME] = Keyboard.KEY_HOME;
|
||||
KEY_MAP[KeyEvent.VK_I] = Keyboard.KEY_I;
|
||||
// KEY_MAP[KeyEvent.VK_INPUT_METHOD_ON_OFF] = Keyboard.KEY_INPUT_METHOD_ON_OFF;
|
||||
KEY_MAP[KeyEvent.VK_INSERT] = Keyboard.KEY_INSERT;
|
||||
// KEY_MAP[KeyEvent.VK_INVERTED_EXCLAMATION_MARK] = Keyboard.KEY_INVERTED_EXCLAMATION_MARK;
|
||||
KEY_MAP[KeyEvent.VK_J] = Keyboard.KEY_J;
|
||||
// KEY_MAP[KeyEvent.VK_JAPANESE_HIRAGANA] = Keyboard.KEY_JAPANESE_HIRAGANA;
|
||||
// KEY_MAP[KeyEvent.VK_JAPANESE_KATAKANA] = Keyboard.KEY_JAPANESE_KATAKANA;
|
||||
// KEY_MAP[KeyEvent.VK_JAPANESE_ROMAN] = Keyboard.KEY_JAPANESE_ROMAN;
|
||||
KEY_MAP[KeyEvent.VK_K] = Keyboard.KEY_K;
|
||||
KEY_MAP[KeyEvent.VK_KANA] = Keyboard.KEY_KANA;
|
||||
// KEY_MAP[KeyEvent.VK_KANA_LOCK] = Keyboard.KEY_KANA_LOCK;
|
||||
KEY_MAP[KeyEvent.VK_KANJI] = Keyboard.KEY_KANJI;
|
||||
// KEY_MAP[KeyEvent.VK_KATAKANA] = Keyboard.KEY_KATAKANA;
|
||||
// KEY_MAP[KeyEvent.VK_KP_DOWN] = Keyboard.KEY_KP_DOWN;
|
||||
// KEY_MAP[KeyEvent.VK_KP_LEFT] = Keyboard.KEY_KP_LEFT;
|
||||
// KEY_MAP[KeyEvent.VK_KP_RIGHT] = Keyboard.KEY_KP_RIGHT;
|
||||
// KEY_MAP[KeyEvent.VK_KP_UP] = Keyboard.KEY_KP_UP;
|
||||
KEY_MAP[KeyEvent.VK_L] = Keyboard.KEY_L;
|
||||
KEY_MAP[KeyEvent.VK_LEFT] = Keyboard.KEY_LEFT;
|
||||
// KEY_MAP[KeyEvent.VK_LEFT_PARENTHESIS] = Keyboard.KEY_LEFT_PARENTHESIS;
|
||||
// KEY_MAP[KeyEvent.VK_LESS] = Keyboard.KEY_LESS;
|
||||
KEY_MAP[KeyEvent.VK_M] = Keyboard.KEY_M;
|
||||
// KEY_MAP[KeyEvent.VK_META] = Keyboard.KEY_META;
|
||||
KEY_MAP[KeyEvent.VK_MINUS] = Keyboard.KEY_MINUS;
|
||||
// KEY_MAP[KeyEvent.VK_MODECHANGE] = Keyboard.KEY_MODECHANGE;
|
||||
KEY_MAP[KeyEvent.VK_MULTIPLY] = Keyboard.KEY_MULTIPLY;
|
||||
KEY_MAP[KeyEvent.VK_N] = Keyboard.KEY_N;
|
||||
// KEY_MAP[KeyEvent.VK_NONCONVERT] = Keyboard.KEY_NONCONVERT;
|
||||
KEY_MAP[KeyEvent.VK_NUM_LOCK] = Keyboard.KEY_NUMLOCK;
|
||||
// KEY_MAP[KeyEvent.VK_NUMBER_SIGN] = Keyboard.KEY_NUMBER_SIGN;
|
||||
KEY_MAP[KeyEvent.VK_NUMPAD0] = Keyboard.KEY_NUMPAD0;
|
||||
KEY_MAP[KeyEvent.VK_NUMPAD1] = Keyboard.KEY_NUMPAD1;
|
||||
KEY_MAP[KeyEvent.VK_NUMPAD2] = Keyboard.KEY_NUMPAD2;
|
||||
KEY_MAP[KeyEvent.VK_NUMPAD3] = Keyboard.KEY_NUMPAD3;
|
||||
KEY_MAP[KeyEvent.VK_NUMPAD4] = Keyboard.KEY_NUMPAD4;
|
||||
KEY_MAP[KeyEvent.VK_NUMPAD5] = Keyboard.KEY_NUMPAD5;
|
||||
KEY_MAP[KeyEvent.VK_NUMPAD6] = Keyboard.KEY_NUMPAD6;
|
||||
KEY_MAP[KeyEvent.VK_NUMPAD7] = Keyboard.KEY_NUMPAD7;
|
||||
KEY_MAP[KeyEvent.VK_NUMPAD8] = Keyboard.KEY_NUMPAD8;
|
||||
KEY_MAP[KeyEvent.VK_NUMPAD9] = Keyboard.KEY_NUMPAD9;
|
||||
KEY_MAP[KeyEvent.VK_O] = Keyboard.KEY_O;
|
||||
KEY_MAP[KeyEvent.VK_OPEN_BRACKET] = Keyboard.KEY_LBRACKET;
|
||||
KEY_MAP[KeyEvent.VK_P] = Keyboard.KEY_P;
|
||||
KEY_MAP[KeyEvent.VK_PAGE_DOWN] = Keyboard.KEY_NEXT;
|
||||
KEY_MAP[KeyEvent.VK_PAGE_UP] = Keyboard.KEY_PRIOR;
|
||||
// KEY_MAP[KeyEvent.VK_PASTE] = Keyboard.KEY_PASTE;
|
||||
KEY_MAP[KeyEvent.VK_PAUSE] = Keyboard.KEY_PAUSE;
|
||||
KEY_MAP[KeyEvent.VK_PERIOD] = Keyboard.KEY_PERIOD;
|
||||
// KEY_MAP[KeyEvent.VK_PLUS] = Keyboard.KEY_PLUS;
|
||||
// KEY_MAP[KeyEvent.VK_PREVIOUS_CANDIDATE] = Keyboard.KEY_PREVIOUS_CANDIDATE;
|
||||
// KEY_MAP[KeyEvent.VK_PRINTSCREEN] = Keyboard.KEY_PRINTSCREEN;
|
||||
// KEY_MAP[KeyEvent.VK_PROPS] = Keyboard.KEY_PROPS;
|
||||
KEY_MAP[KeyEvent.VK_Q] = Keyboard.KEY_Q;
|
||||
// KEY_MAP[KeyEvent.VK_QUOTE] = Keyboard.KEY_QUOTE;
|
||||
// KEY_MAP[KeyEvent.VK_QUOTEDBL] = Keyboard.KEY_QUOTEDBL;
|
||||
KEY_MAP[KeyEvent.VK_R] = Keyboard.KEY_R;
|
||||
KEY_MAP[KeyEvent.VK_RIGHT] = Keyboard.KEY_RIGHT;
|
||||
// KEY_MAP[KeyEvent.VK_RIGHT_PARENTHESIS] = Keyboard.KEY_RIGHT_PARENTHESIS;
|
||||
// KEY_MAP[KeyEvent.VK_ROMAN_CHARACTERS] = Keyboard.KEY_ROMAN_CHARACTERS;
|
||||
KEY_MAP[KeyEvent.VK_S] = Keyboard.KEY_S;
|
||||
KEY_MAP[KeyEvent.VK_SCROLL_LOCK] = Keyboard.KEY_SCROLL;
|
||||
KEY_MAP[KeyEvent.VK_SEMICOLON] = Keyboard.KEY_SEMICOLON;
|
||||
KEY_MAP[KeyEvent.VK_SEPARATOR] = Keyboard.KEY_DECIMAL;
|
||||
KEY_MAP[KeyEvent.VK_SHIFT] = Keyboard.KEY_LSHIFT;
|
||||
KEY_MAP[KeyEvent.VK_SLASH] = Keyboard.KEY_SLASH;
|
||||
KEY_MAP[KeyEvent.VK_SPACE] = Keyboard.KEY_SPACE;
|
||||
KEY_MAP[KeyEvent.VK_STOP] = Keyboard.KEY_STOP;
|
||||
KEY_MAP[KeyEvent.VK_SUBTRACT] = Keyboard.KEY_SUBTRACT;
|
||||
KEY_MAP[KeyEvent.VK_T] = Keyboard.KEY_T;
|
||||
KEY_MAP[KeyEvent.VK_TAB] = Keyboard.KEY_TAB;
|
||||
KEY_MAP[KeyEvent.VK_U] = Keyboard.KEY_U;
|
||||
// KEY_MAP[KeyEvent.VK_UNDERSCORE] = Keyboard.KEY_UNDERSCORE;
|
||||
// KEY_MAP[KeyEvent.VK_UNDO] = Keyboard.KEY_UNDO;
|
||||
KEY_MAP[KeyEvent.VK_UP] = Keyboard.KEY_UP;
|
||||
KEY_MAP[KeyEvent.VK_V] = Keyboard.KEY_V;
|
||||
KEY_MAP[KeyEvent.VK_W] = Keyboard.KEY_W;
|
||||
KEY_MAP[KeyEvent.VK_X] = Keyboard.KEY_X;
|
||||
KEY_MAP[KeyEvent.VK_Y] = Keyboard.KEY_Y;
|
||||
KEY_MAP[KeyEvent.VK_Z] = Keyboard.KEY_Z;
|
||||
}
|
||||
|
||||
public KeyboardEventQueue() {
|
||||
super(EVENT_SIZE);
|
||||
}
|
||||
|
||||
private void putKeyboardEvent(int key_code, int state, int character) {
|
||||
event[0] = key_code;
|
||||
event[1] = state;
|
||||
event[2] = character;
|
||||
putEvent(event);
|
||||
}
|
||||
|
||||
public synchronized void poll(ByteBuffer key_down_buffer) {
|
||||
int old_position = key_down_buffer.position();
|
||||
key_down_buffer.put(key_states);
|
||||
key_down_buffer.position(old_position);
|
||||
}
|
||||
|
||||
private synchronized void handleKey(int key_code, int state, char character) {
|
||||
int key_code_mapped = KEY_MAP[key_code];
|
||||
if (character == KeyEvent.CHAR_UNDEFINED)
|
||||
character = Keyboard.CHAR_NONE;
|
||||
int key_int_char = ((int)character) & 0xffff;
|
||||
putKeyboardEvent(key_code_mapped, state, key_int_char);
|
||||
}
|
||||
|
||||
public void keyPressed(KeyEvent e) {
|
||||
handleKey(e.getKeyCode(), 1, e.getKeyChar());
|
||||
}
|
||||
|
||||
public void keyReleased(KeyEvent e) {
|
||||
handleKey(e.getKeyCode(), 0, Keyboard.CHAR_NONE);
|
||||
}
|
||||
|
||||
public void keyTyped(KeyEvent e) {
|
||||
}
|
||||
}
|
||||
399
src/java/org/lwjgl/opengl/MacOSXDisplay.java
Normal file
399
src/java/org/lwjgl/opengl/MacOSXDisplay.java
Normal file
|
|
@ -0,0 +1,399 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2004 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.lwjgl.opengl;
|
||||
|
||||
/**
|
||||
* This is the Display implementation interface. Display delegates
|
||||
* to implementors of this interface. There is one DisplayImplementation
|
||||
* for each supported platform.
|
||||
* @author elias_naur
|
||||
*/
|
||||
|
||||
import java.nio.FloatBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.lwjgl.LWJGLException;
|
||||
import org.lwjgl.Sys;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Frame;
|
||||
import javax.swing.JFrame;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Point;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import com.apple.eawt.Application;
|
||||
import com.apple.eawt.ApplicationListener;
|
||||
import com.apple.eawt.ApplicationEvent;
|
||||
|
||||
final class MacOSXDisplay extends WindowAdapter implements DisplayImplementation, ApplicationListener {
|
||||
private JFrame frame;
|
||||
private MacOSXGLCanvas canvas;
|
||||
private boolean close_requested;
|
||||
private MouseEventQueue mouse_queue;
|
||||
private KeyboardEventQueue keyboard_queue;
|
||||
private java.awt.DisplayMode requested_mode;
|
||||
|
||||
public MacOSXDisplay() {
|
||||
Application.getApplication().addApplicationListener(this);
|
||||
System.out.println("getMaxCursorSize = " + getMaxCursorSize());
|
||||
}
|
||||
|
||||
public void createWindow(DisplayMode mode, boolean fullscreen, int x, int y) throws LWJGLException {
|
||||
close_requested = false;
|
||||
frame = new JFrame();
|
||||
frame.setResizable(false);
|
||||
frame.addWindowListener(this);
|
||||
canvas = new MacOSXGLCanvas();
|
||||
frame.getContentPane().add(canvas, BorderLayout.CENTER);
|
||||
frame.setUndecorated(fullscreen);
|
||||
if (fullscreen) {
|
||||
getDevice().setFullScreenWindow(frame);
|
||||
getDevice().setDisplayMode(requested_mode);
|
||||
/** For some strange reason, the display mode is sometimes silently capped even though the mode is reported as supported */
|
||||
if (requested_mode.getWidth() != getDevice().getDisplayMode().getWidth() || requested_mode.getHeight() != getDevice().getDisplayMode().getHeight()) {
|
||||
destroyWindow();
|
||||
throw new LWJGLException("AWT capped mode");
|
||||
}
|
||||
}
|
||||
frame.pack();
|
||||
reshape(x, y, mode.getWidth(), mode.getHeight());
|
||||
frame.setVisible(true);
|
||||
frame.requestFocus();
|
||||
canvas.requestFocus();
|
||||
canvas.waitForCanvasCreated();
|
||||
}
|
||||
|
||||
private GraphicsDevice getDevice() {
|
||||
GraphicsEnvironment g_env = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
GraphicsDevice device = g_env.getDefaultScreenDevice();
|
||||
return device;
|
||||
}
|
||||
|
||||
public void handleAbout(ApplicationEvent event) {
|
||||
}
|
||||
|
||||
public void handleOpenApplication(ApplicationEvent event) {
|
||||
}
|
||||
|
||||
public void handleOpenFile(ApplicationEvent event) {
|
||||
}
|
||||
|
||||
public void handlePreferences(ApplicationEvent event) {
|
||||
}
|
||||
|
||||
public void handlePrintFile(ApplicationEvent event) {
|
||||
}
|
||||
|
||||
public void handleQuit(ApplicationEvent event) {
|
||||
handleQuit();
|
||||
}
|
||||
|
||||
public void handleReOpenApplication(ApplicationEvent event) {
|
||||
}
|
||||
|
||||
private void handleQuit() {
|
||||
synchronized (this) {
|
||||
close_requested = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void windowClosing(WindowEvent e) {
|
||||
handleQuit();
|
||||
}
|
||||
|
||||
public void windowActivated(WindowEvent e) {
|
||||
warpCursor();
|
||||
}
|
||||
|
||||
public void destroyWindow() {
|
||||
if (getDevice().getFullScreenWindow() != null)
|
||||
getDevice().setFullScreenWindow(null);
|
||||
setView(null);
|
||||
frame.dispose();
|
||||
frame = null;
|
||||
canvas = null;
|
||||
}
|
||||
|
||||
public native int getGammaRampLength();
|
||||
public native void setGammaRamp(FloatBuffer gammaRamp) throws LWJGLException;
|
||||
|
||||
public String getAdapter() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean equals(java.awt.DisplayMode awt_mode, DisplayMode mode) {
|
||||
return awt_mode.getWidth() == mode.getWidth() && awt_mode.getHeight() == mode.getHeight()
|
||||
&& awt_mode.getBitDepth() == mode.getBitsPerPixel() && awt_mode.getRefreshRate() == mode.getFrequency();
|
||||
}
|
||||
|
||||
public void switchDisplayMode(DisplayMode mode) throws LWJGLException {
|
||||
java.awt.DisplayMode[] awt_modes = getDevice().getDisplayModes();
|
||||
for (int i = 0; i < awt_modes.length; i++)
|
||||
if (equals(awt_modes[i], mode)) {
|
||||
requested_mode = awt_modes[i];
|
||||
return;
|
||||
}
|
||||
throw new LWJGLException(mode + " is not supported");
|
||||
}
|
||||
|
||||
public void resetDisplayMode() {
|
||||
if (getDevice().getFullScreenWindow() != null)
|
||||
getDevice().setFullScreenWindow(null);
|
||||
requested_mode = null;
|
||||
}
|
||||
|
||||
private DisplayMode createLWJGLDisplayMode(java.awt.DisplayMode awt_mode) {
|
||||
int bit_depth;
|
||||
int refresh_rate;
|
||||
int awt_bit_depth = awt_mode.getBitDepth();
|
||||
int awt_refresh_rate = awt_mode.getRefreshRate();
|
||||
if (awt_bit_depth != java.awt.DisplayMode.BIT_DEPTH_MULTI)
|
||||
bit_depth = awt_bit_depth;
|
||||
else
|
||||
bit_depth = 32; // Assume the best bit depth
|
||||
if (awt_refresh_rate != java.awt.DisplayMode.REFRESH_RATE_UNKNOWN)
|
||||
refresh_rate = awt_refresh_rate;
|
||||
else
|
||||
refresh_rate = 0;
|
||||
return new DisplayMode(awt_mode.getWidth(), awt_mode.getHeight(), bit_depth, refresh_rate);
|
||||
}
|
||||
|
||||
public DisplayMode init() {
|
||||
return createLWJGLDisplayMode(getDevice().getDisplayMode());
|
||||
}
|
||||
|
||||
public DisplayMode[] getAvailableDisplayModes() {
|
||||
java.awt.DisplayMode[] awt_modes = getDevice().getDisplayModes();
|
||||
List modes = new ArrayList();
|
||||
for (int i = 0; i < awt_modes.length; i++)
|
||||
if (awt_modes[i].getBitDepth() >= 16)
|
||||
modes.add(createLWJGLDisplayMode(awt_modes[i]));
|
||||
DisplayMode[] mode_list = new DisplayMode[modes.size()];
|
||||
modes.toArray(mode_list);
|
||||
return mode_list;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
frame.setTitle(title);
|
||||
}
|
||||
|
||||
public boolean isCloseRequested() {
|
||||
boolean result;
|
||||
synchronized (this) {
|
||||
result = close_requested;
|
||||
close_requested = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean isVisible() {
|
||||
return frame.isShowing();
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return frame.isFocused();
|
||||
}
|
||||
|
||||
public boolean isDirty() {
|
||||
return canvas.isDirty();
|
||||
}
|
||||
|
||||
public native void setView(MacOSXGLCanvas canvas);
|
||||
|
||||
public native void swapBuffers();
|
||||
|
||||
public native void makeCurrent() throws LWJGLException;
|
||||
|
||||
public native void createContext(PixelFormat pixel_format) throws LWJGLException;
|
||||
|
||||
public native void destroyContext();
|
||||
|
||||
public void update() {
|
||||
if (canvas.shouldUpdateContext()) {
|
||||
updateContext();
|
||||
/* This is necessary to make sure the context won't "forget" about the view size */
|
||||
GL11.glViewport(0, 0, canvas.getWidth(), canvas.getHeight());
|
||||
warpCursor();
|
||||
}
|
||||
mouse_queue.updateDeltas();
|
||||
}
|
||||
|
||||
private void warpCursor() {
|
||||
if (mouse_queue != null && mouse_queue.isGrabbed()) {
|
||||
Rectangle bounds = frame.getBounds();
|
||||
int x = bounds.x + bounds.width/2;
|
||||
int y = bounds.y + bounds.height/2;
|
||||
nWarpCursor(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
native void getMouseDeltas(IntBuffer delta_buffer);
|
||||
|
||||
private native void updateContext();
|
||||
|
||||
public native void setVSyncEnabled(boolean sync);
|
||||
|
||||
public void reshape(int x, int y, int width, int height) {
|
||||
Insets insets = frame.getInsets();
|
||||
frame.setBounds(x, y, width + insets.left + insets.right, height + insets.top + insets.bottom);
|
||||
}
|
||||
|
||||
/* Mouse */
|
||||
public boolean hasWheel() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public int getButtonCount() {
|
||||
return MouseEventQueue.NUM_BUTTONS;
|
||||
}
|
||||
|
||||
public void createMouse() {
|
||||
this.mouse_queue = new MouseEventQueue(canvas.getWidth(), canvas.getHeight());
|
||||
canvas.addMouseListener(mouse_queue);
|
||||
canvas.addMouseMotionListener(mouse_queue);
|
||||
canvas.addMouseWheelListener(mouse_queue);
|
||||
}
|
||||
|
||||
public void destroyMouse() {
|
||||
canvas.removeMouseListener(mouse_queue);
|
||||
canvas.removeMouseWheelListener(mouse_queue);
|
||||
canvas.removeMouseMotionListener(mouse_queue);
|
||||
this.mouse_queue = null;
|
||||
}
|
||||
|
||||
public void pollMouse(IntBuffer coord_buffer, ByteBuffer buttons_buffer) {
|
||||
mouse_queue.poll(coord_buffer, buttons_buffer);
|
||||
}
|
||||
|
||||
public void enableMouseBuffer() throws LWJGLException {
|
||||
}
|
||||
|
||||
public int readMouse(IntBuffer buffer, int buffer_position) {
|
||||
assert buffer_position == buffer.position();
|
||||
return mouse_queue.copyEvents(buffer);
|
||||
}
|
||||
|
||||
public void grabMouse(boolean grab) {
|
||||
nGrabMouse(grab);
|
||||
mouse_queue.setGrabbed(grab);
|
||||
warpCursor();
|
||||
}
|
||||
|
||||
private native void nWarpCursor(int x, int y);
|
||||
|
||||
private native void nGrabMouse(boolean grab);
|
||||
|
||||
public int getNativeCursorCaps() {
|
||||
int cursor_colors = Toolkit.getDefaultToolkit().getMaximumCursorColors();
|
||||
boolean supported = cursor_colors >= Short.MAX_VALUE && getMaxCursorSize() > 0;
|
||||
int caps = supported ? Mouse.CURSOR_8_BIT_ALPHA | Mouse.CURSOR_ONE_BIT_TRANSPARENCY: 0;
|
||||
return caps;
|
||||
}
|
||||
|
||||
public void setNativeCursor(Object handle) throws LWJGLException {
|
||||
Cursor awt_cursor = (Cursor)handle;
|
||||
canvas.setCursor(awt_cursor);
|
||||
}
|
||||
|
||||
public int getMinCursorSize() {
|
||||
Dimension min_size = Toolkit.getDefaultToolkit().getBestCursorSize(0, 0);
|
||||
return Math.max(min_size.width, min_size.height);
|
||||
}
|
||||
|
||||
public int getMaxCursorSize() {
|
||||
Dimension max_size = Toolkit.getDefaultToolkit().getBestCursorSize(10000, 10000);
|
||||
return Math.min(max_size.width, max_size.height);
|
||||
}
|
||||
|
||||
/* Keyboard */
|
||||
public void createKeyboard() throws LWJGLException {
|
||||
this.keyboard_queue = new KeyboardEventQueue();
|
||||
canvas.addKeyListener(keyboard_queue);
|
||||
}
|
||||
|
||||
public void destroyKeyboard() {
|
||||
/*
|
||||
* This line is commented out to work around AWT bug 4867453:
|
||||
* http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4867453
|
||||
*/
|
||||
// canvas.removeKeyListener(keyboard_queue);
|
||||
|
||||
this.keyboard_queue = null;
|
||||
}
|
||||
|
||||
public void pollKeyboard(ByteBuffer keyDownBuffer) {
|
||||
keyboard_queue.poll(keyDownBuffer);
|
||||
}
|
||||
|
||||
public int readKeyboard(IntBuffer buffer, int buffer_position) {
|
||||
assert buffer_position == buffer.position();
|
||||
return keyboard_queue.copyEvents(buffer);
|
||||
}
|
||||
|
||||
public void enableTranslation() throws LWJGLException {
|
||||
}
|
||||
|
||||
public void enableKeyboardBuffer() throws LWJGLException {
|
||||
}
|
||||
|
||||
public native int isStateKeySet(int key);
|
||||
|
||||
/** Native cursor handles */
|
||||
public Object createCursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, IntBuffer delays) throws LWJGLException {
|
||||
BufferedImage cursor_image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
||||
int[] pixels = new int[images.remaining()];
|
||||
int old_position = images.position();
|
||||
images.get(pixels);
|
||||
images.position(old_position);
|
||||
cursor_image.setRGB(0, 0, width, height, pixels, 0, width);
|
||||
return Toolkit.getDefaultToolkit().createCustomCursor(cursor_image, new Point(xHotspot, yHotspot), "LWJGL Custom cursor");
|
||||
}
|
||||
|
||||
public void destroyCursor(Object cursor_handle) {
|
||||
}
|
||||
}
|
||||
140
src/java/org/lwjgl/opengl/MacOSXGLCanvas.java
Normal file
140
src/java/org/lwjgl/opengl/MacOSXGLCanvas.java
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2004 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.lwjgl.opengl;
|
||||
|
||||
/**
|
||||
* The AWT compatible Canvas for Mac OS X.
|
||||
* @author elias_naur
|
||||
*/
|
||||
|
||||
import java.awt.Canvas;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Point;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.event.HierarchyBoundsListener;
|
||||
import java.awt.event.HierarchyEvent;
|
||||
|
||||
final class MacOSXGLCanvas extends Canvas implements HierarchyBoundsListener {
|
||||
private boolean context_update;
|
||||
private boolean canvas_created;
|
||||
private boolean dirty;
|
||||
|
||||
public MacOSXGLCanvas() {
|
||||
setFocusTraversalKeysEnabled(false);
|
||||
/* Input methods are not enabled in fullscreen anyway, so disable always */
|
||||
enableInputMethods(false);
|
||||
addHierarchyBoundsListener(this);
|
||||
}
|
||||
|
||||
public void update(Graphics g) {
|
||||
paint(g);
|
||||
}
|
||||
|
||||
public void paint(Graphics g) {
|
||||
synchronized (this) {
|
||||
dirty = true;
|
||||
if (!canvas_created) {
|
||||
((MacOSXDisplay)Display.getImplementation()).setView(this);
|
||||
canvas_created = true;
|
||||
setUpdate();
|
||||
notify();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isDirty() {
|
||||
boolean result;
|
||||
synchronized (this) {
|
||||
result = dirty;
|
||||
dirty = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void waitForCanvasCreated() {
|
||||
synchronized (this) {
|
||||
while (!canvas_created) {
|
||||
try {
|
||||
wait();
|
||||
} catch (InterruptedException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean shouldUpdateContext() {
|
||||
boolean should_update;
|
||||
synchronized (this) {
|
||||
should_update = context_update;
|
||||
context_update = false;
|
||||
}
|
||||
return should_update;
|
||||
}
|
||||
|
||||
private synchronized void setUpdate() {
|
||||
context_update = true;
|
||||
}
|
||||
|
||||
public void ancestorResized(HierarchyEvent e) {
|
||||
setUpdate();
|
||||
}
|
||||
|
||||
public void ancestorMoved(HierarchyEvent e) {
|
||||
setUpdate();
|
||||
}
|
||||
|
||||
public void setLocation(int x, int y) {
|
||||
super.setLocation(x, y);
|
||||
setUpdate();
|
||||
}
|
||||
|
||||
public void setLocation(Point p) {
|
||||
super.setLocation(p);
|
||||
setUpdate();
|
||||
}
|
||||
|
||||
public void setSize(Dimension d) {
|
||||
super.setSize(d);
|
||||
setUpdate();
|
||||
}
|
||||
|
||||
public void setSize(int width, int height) {
|
||||
super.setSize(width, height);
|
||||
setUpdate();
|
||||
}
|
||||
|
||||
public void setBounds(int x, int y, int width, int height) {
|
||||
super.setBounds(x, y, width, height);
|
||||
setUpdate();
|
||||
}
|
||||
}
|
||||
|
|
@ -74,9 +74,22 @@ public class WindowCreationTest {
|
|||
System.out.println("Window created");
|
||||
System.out.println(Display.getDisplayMode().getHeight() + ", " + Display.getDisplayMode().getWidth() + ", " + Display.getTitle());
|
||||
|
||||
Display.setVSyncEnabled(true);
|
||||
Display.setTitle("WindowCreationTest");
|
||||
float color = 0f;
|
||||
int direction = 1;
|
||||
// wait for user to close window
|
||||
while(!Display.isCloseRequested()) {
|
||||
GL11.glClearColor(color, color, color, 1f);
|
||||
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
|
||||
color += direction*.05f;
|
||||
if (color > 1f) {
|
||||
color = 1f;
|
||||
direction = -1*direction;
|
||||
} else if (color < 0f) {
|
||||
direction = -1*direction;
|
||||
color = 0f;
|
||||
}
|
||||
Display.update();
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
|
|
|
|||
36
src/native/macosx/Makefile
Normal file
36
src/native/macosx/Makefile
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
AL=/Users/oddlabs/cvs/openal
|
||||
|
||||
|
||||
|
||||
CC=gcc
|
||||
LINKER=gcc
|
||||
STRIP=strip
|
||||
CFLAGS_LINK=-dynamiclib -Wall
|
||||
#FRAMEWORKS=-framework OpenGL -framework AppKit -framework JavaVM
|
||||
FRAMEWORKS=-framework Foundation -framework AppKit -framework JavaVM
|
||||
CFLAGS_O=-O2 -D_MACOSX -Wall -c -I${AL}/include -I../common -I/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers
|
||||
#SRC:=$(shell find . -name \*.c -print) $(shell find ../common -name \*.c)
|
||||
SRC=$(wildcard *.m) $(wildcard *.c) $(wildcard ../common/*.c) $(wildcard ../common/arb/*.c) $(wildcard ../common/ati/*.c) $(wildcard ../common/ext/*.c) $(wildcard ../common/nv/*.c)
|
||||
OBJECTS=$(subst .m,.o, $(subst .c,.o,$(SRC)))
|
||||
#OBJECTS=org_lwjgl_opengl_Display.o \
|
||||
# org_lwjgl_Sys.o \
|
||||
# ../common/extgl.o \
|
||||
# ../common/extal.o \
|
||||
# ../common/org_lwjgl_openal_AL.o \
|
||||
# ../common/org_lwjgl_openal_ALC.o \
|
||||
# ../common/org_lwjgl_openal_AL10.o \
|
||||
# ../common/common_tools.o
|
||||
LIBRARY=liblwjgl.jnilib
|
||||
|
||||
$(LIBRARY): $(OBJECTS)
|
||||
$(LINKER) $(CFLAGS_LINK) -o $@ $(OBJECTS) $(FRAMEWORKS)
|
||||
# $(STRIP) -S -X $@
|
||||
|
||||
.m.o:
|
||||
$(CC) $(CFLAGS_O) $< -o $@
|
||||
|
||||
.c.o:
|
||||
$(CC) $(CFLAGS_O) $< -o $@
|
||||
|
||||
clean:
|
||||
rm -f ${OBJECTS} ${LIBRARY}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
noinst_LTLIBRARIES = libnative.la
|
||||
|
||||
libnative_la_SOURCES = $(NATIVE)
|
||||
INCLUDES = -I../common
|
||||
|
||||
NATIVE = \
|
||||
org_lwjgl_Display.cpp \
|
||||
org_lwjgl_Sys.cpp \
|
||||
org_lwjgl_input_Controller.cpp \
|
||||
org_lwjgl_input_Keyboard.cpp \
|
||||
tools.cpp \
|
||||
hid.cpp \
|
||||
org_lwjgl_input_Mouse.cpp \
|
||||
org_lwjgl_input_Cursor.cpp \
|
||||
org_lwjgl_opengl_Window.cpp \
|
||||
org_lwjgl_opengl_Pbuffer.cpp
|
||||
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2004 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
* Include file to access public window features
|
||||
*
|
||||
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
#ifndef _LWJGL_WINDOW_H_INCLUDED_
|
||||
#define _LWJGL_WINDOW_H_INCLUDED_
|
||||
|
||||
#include <jni.h>
|
||||
#include <Carbon/Carbon.h>
|
||||
extern void resetMode(JNIEnv *env);
|
||||
extern bool switchMode(JNIEnv *env, long width, long height, long bpp, long freq);
|
||||
extern bool switchToNearestMode(JNIEnv *env, long width, long height, long bpp, long freq);
|
||||
extern void handleKeyboardEvent(EventRef event);
|
||||
extern void handleMouseEvent(EventRef event);
|
||||
|
||||
#endif /* _LWJGL_WINDOW_H_INCLUDED_ */
|
||||
|
|
@ -1,162 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002 Light Weight Java Game Library Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'Light Weight Java Game Library' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/* remember to turn on the -faltivec flag for gcc compilation */
|
||||
|
||||
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
* math library.
|
||||
*
|
||||
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include "org_lwjgl_Math_MatrixOpCopy_MatrixOpSafe.h"
|
||||
#include "MatrixOpCommon.h"
|
||||
|
||||
|
||||
void altivec_CopyPackedSafe (char * src, char * dst, int length);
|
||||
|
||||
/*
|
||||
* Class: org_lwjgl_Math_MatrixOpCopy_MatrixOpSafe
|
||||
* Method: execute
|
||||
* Signature: (IIIIIZIIZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Math_00024MatrixOpCopy_00024MatrixOpSafe_execute
|
||||
(
|
||||
JNIEnv * env,
|
||||
jobject obj,
|
||||
jint sourceAddress,
|
||||
jint sourceStride,
|
||||
jint numElements,
|
||||
jint sourceWidth,
|
||||
jint sourceHeight,
|
||||
jboolean transposeSource,
|
||||
jint destAddress,
|
||||
jint destStride,
|
||||
jboolean transposeDest
|
||||
)
|
||||
{
|
||||
// remove any unnecessary copying
|
||||
if (transposeSource == transposeDest)
|
||||
{
|
||||
transposeSource = false;
|
||||
transposeDest = false;
|
||||
}
|
||||
|
||||
/* handle all cases where the data is packed and transposition is not necessary */
|
||||
if ((transposeSource == transposeDest)
|
||||
&& ((sourceWidth * sourceHeight * 4) == sourceStride))
|
||||
{
|
||||
altivec_CopyPackedSafe((char *)sourceAddress, (char *)destAddress, numElements*sourceWidth*sourceHeight*4);
|
||||
return;
|
||||
}
|
||||
|
||||
MatrixSrc source (sourceAddress, sourceStride, sourceWidth, sourceHeight, numElements, transposeSource);
|
||||
MatrixDst dest (destAddress, destStride, source.width, source.height, source.elements, transposeDest);
|
||||
|
||||
float * srcMatrix, * destMatrix;
|
||||
int matrixByteCount = source.width*source.height*sizeof(jfloat);
|
||||
|
||||
for (int i = 0; i < source.elements; i++)
|
||||
{
|
||||
srcMatrix = source.nextMatrix();
|
||||
destMatrix = dest.nextMatrix();
|
||||
|
||||
// just do a straight memory copy
|
||||
memcpy(destMatrix, srcMatrix, matrixByteCount);
|
||||
dest.writeComplete();
|
||||
}
|
||||
}
|
||||
|
||||
void altivec_CopyPackedSafe (char * src, char * dst, int length)
|
||||
{
|
||||
int src_a = (int)src;
|
||||
int dst_a = (int)dst;
|
||||
|
||||
//std::cout << "src: " << src_a << " dst: " << dst_a <<"\n";
|
||||
|
||||
if ((src_a & 0x0F) == (dst_a & 0x0F))
|
||||
{
|
||||
|
||||
//std::cout << "same alignment\n" << "\n";
|
||||
int first_bytes = 16 - ((int)(src) & 0x0000000F);
|
||||
|
||||
//std::cout << "first bytes" << first_bytes << "\n";
|
||||
int i = first_bytes;
|
||||
if (first_bytes > length)
|
||||
first_bytes = length;
|
||||
if (first_bytes == 16)
|
||||
first_bytes = 0;
|
||||
|
||||
while (i--)
|
||||
dst[i] = src[i];
|
||||
|
||||
src = &src[first_bytes];
|
||||
dst = &dst[first_bytes];
|
||||
|
||||
length -= first_bytes;
|
||||
//std::cout << "new length" << length << "\n";
|
||||
|
||||
// figure out how many 16 byte chunks there are
|
||||
int middle_cycles = (length >> 4); // ignore any other bytes
|
||||
length -= (middle_cycles << 4);
|
||||
|
||||
while (middle_cycles --)
|
||||
{
|
||||
// load a vector, set the cache line to be LRU
|
||||
vector float a = (vector float) vec_ldl(0, (float *) src);
|
||||
src += 16;
|
||||
|
||||
// write it back, set cache line LRU, gets flushed back to RAM (not L2 or L3)
|
||||
vec_stl(a, 0, (float *) dst);
|
||||
dst += 16;
|
||||
}
|
||||
|
||||
// write back any remaining bytes
|
||||
while(length--)
|
||||
dst[length] = src[length];
|
||||
|
||||
}
|
||||
else
|
||||
{ //std::cout << "different alignment\n";
|
||||
// differing offsets (byte by byte copy)
|
||||
while (length--)
|
||||
dst[length] = src[length];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,239 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2004 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
* Mac OS X mouse handling.
|
||||
*
|
||||
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
#include "hid.h"
|
||||
#include "tools.h"
|
||||
#include "common_tools.h"
|
||||
|
||||
static void searchDictionary(CFDictionaryRef dict, hid_device_t *hid_dev, int num_cookies, hid_cookie_t *hid_cookies);
|
||||
static void searchObject(CFTypeRef object, hid_device_t *hid_dev, int num_cookies, hid_cookie_t *hid_cookies);
|
||||
|
||||
static void printCFString(CFStringRef str) {
|
||||
CFIndex buffer_size = CFStringGetLength(str) + 1;
|
||||
char * buffer = (char *)malloc(buffer_size);
|
||||
if (buffer != NULL) {
|
||||
if (CFStringGetCString(str, buffer, buffer_size, CFStringGetSystemEncoding()))
|
||||
printf("%s", buffer);
|
||||
free(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
static void printCFNumber(CFNumberRef num) {
|
||||
long number;
|
||||
|
||||
if (CFNumberGetValue(num, kCFNumberLongType, &number))
|
||||
printf("0x%lx (%ld)", number, number);
|
||||
}
|
||||
|
||||
|
||||
static void printProperty(CFDictionaryRef dict, CFStringRef key) {
|
||||
CFTypeRef val = CFDictionaryGetValue(dict, key);
|
||||
if (val != NULL) {
|
||||
CFTypeID type = CFGetTypeID(val);
|
||||
/* if (type == CFArrayGetTypeID()) printf("array\n");
|
||||
else if (type == CFBooleanGetTypeID()) printf("boolean\n");
|
||||
else if (type == CFDictionaryGetTypeID()) printf("dictionary\n");
|
||||
else*/ if (type == CFNumberGetTypeID()) printCFNumber((CFNumberRef)val);
|
||||
else if (type == CFStringGetTypeID()) printCFString((CFStringRef)val);
|
||||
else printf("<unknown object type>\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void closeDeviceAndQueue(hid_device_t *hid_dev) {
|
||||
(*hid_dev->device_queue)->dispose(hid_dev->device_queue);
|
||||
(*hid_dev->device_queue)->Release(hid_dev->device_queue);
|
||||
(*hid_dev->device_interface)->close(hid_dev->device_interface);
|
||||
}
|
||||
|
||||
static void closeDeviceAll(hid_device_t *hid_dev) {
|
||||
closeDeviceAndQueue(hid_dev);
|
||||
CFRelease(hid_dev->cookie_map);
|
||||
}
|
||||
|
||||
static IOHIDQueueInterface **allocDeviceQueue(IOHIDDeviceInterface **device_interface, int buffer_size) {
|
||||
IOHIDQueueInterface **device_queue = (*device_interface)->allocQueue(device_interface);
|
||||
if (device_queue == NULL)
|
||||
return false;
|
||||
HRESULT err = (*device_queue)->create(device_queue, 0, buffer_size);
|
||||
if (err != S_OK) {
|
||||
(*device_queue)->Release(device_queue);
|
||||
return NULL;
|
||||
}
|
||||
return device_queue;
|
||||
}
|
||||
|
||||
static void searchArray(CFArrayRef array, hid_device_t *hid_dev, int num_cookies, hid_cookie_t *hid_cookies) {
|
||||
int size = CFArrayGetCount(array);
|
||||
for (int i = 0; i < size; i++) {
|
||||
CFTypeRef value = (CFTypeRef)CFArrayGetValueAtIndex(array, i);
|
||||
searchObject(value, hid_dev, num_cookies, hid_cookies);
|
||||
}
|
||||
}
|
||||
|
||||
static void searchObject(CFTypeRef object, hid_device_t *hid_dev, int num_cookies, hid_cookie_t *hid_cookies) {
|
||||
CFTypeID type = CFGetTypeID(object);
|
||||
if (type == CFArrayGetTypeID()) searchArray((CFArrayRef)object, hid_dev, num_cookies, hid_cookies);
|
||||
else if (type == CFDictionaryGetTypeID()) searchDictionary((CFDictionaryRef)object, hid_dev, num_cookies, hid_cookies);
|
||||
else printf("<unknown object>\n");
|
||||
}
|
||||
|
||||
static void searchDictionaryElement(CFDictionaryRef dict, CFStringRef key, hid_device_t *hid_dev, int num_cookies, hid_cookie_t *hid_cookies) {
|
||||
CFTypeRef object = CFDictionaryGetValue(dict, key);
|
||||
if (object != NULL)
|
||||
searchObject(object, hid_dev, num_cookies, hid_cookies);
|
||||
}
|
||||
|
||||
static void addToDeviceQueue(hid_device_t *hid_dev, IOHIDElementCookie cookie, int index) {
|
||||
HRESULT result = (*hid_dev->device_queue)->addElement(hid_dev->device_queue, cookie, 0);
|
||||
if (result != S_OK) {
|
||||
printfDebug("Could not add cookie to queue\n");
|
||||
return;
|
||||
}
|
||||
CFDictionaryAddValue(hid_dev->cookie_map, cookie, (void *)index);
|
||||
}
|
||||
|
||||
static void searchDictionary(CFDictionaryRef dict, hid_device_t *hid_dev, int num_cookies, hid_cookie_t *hid_cookies) {
|
||||
searchDictionaryElement(dict, CFSTR(kIOHIDElementKey), hid_dev, num_cookies, hid_cookies);
|
||||
long cookie_num;
|
||||
long usage;
|
||||
long usage_page;
|
||||
if (!getDictLong(dict, CFSTR(kIOHIDElementCookieKey), &cookie_num) ||
|
||||
!getDictLong(dict, CFSTR(kIOHIDElementUsageKey), &usage) ||
|
||||
!getDictLong(dict, CFSTR(kIOHIDElementUsagePageKey), &usage_page))
|
||||
return;
|
||||
for (int i = 0; i < num_cookies; i++) {
|
||||
if (hid_cookies[i].usage_page != kHIDPage_Undefined && hid_cookies[i].usage != kHIDUsage_Undefined &&
|
||||
usage_page == hid_cookies[i].usage_page && usage == hid_cookies[i].usage) {
|
||||
addToDeviceQueue(hid_dev, (IOHIDElementCookie)cookie_num, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool initDevice(hid_device_t *hid_dev, io_object_t hid_device, CFDictionaryRef dict, int num_cookies, hid_cookie_t *hid_cookies, int buffer_size) {
|
||||
io_name_t class_name;
|
||||
IOCFPlugInInterface **plugin_interface;
|
||||
SInt32 score;
|
||||
IOReturn io_err = IOObjectGetClass(hid_device, class_name);
|
||||
if (io_err != kIOReturnSuccess)
|
||||
return false;
|
||||
io_err = IOCreatePlugInInterfaceForService(hid_device, kIOHIDDeviceUserClientTypeID, kIOCFPlugInInterfaceID, &plugin_interface, &score);
|
||||
if (io_err != kIOReturnSuccess)
|
||||
return false;
|
||||
HRESULT plugin_err = (*plugin_interface)->QueryInterface(plugin_interface, CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID), (LPVOID *)(&(hid_dev->device_interface)));
|
||||
(*plugin_interface)->Release(plugin_interface);
|
||||
if (plugin_err != S_OK)
|
||||
return false;
|
||||
io_err = (*hid_dev->device_interface)->open(hid_dev->device_interface, 0);
|
||||
if (io_err != kIOReturnSuccess)
|
||||
return false;
|
||||
hid_dev->device_queue = allocDeviceQueue(hid_dev->device_interface, buffer_size);
|
||||
if (hid_dev->device_queue == NULL) {
|
||||
(*hid_dev->device_interface)->close(hid_dev->device_interface);
|
||||
return false;
|
||||
}
|
||||
hid_dev->cookie_map = CFDictionaryCreateMutable(NULL, 0, NULL, NULL);
|
||||
if (hid_dev->cookie_map == NULL) {
|
||||
closeDeviceAndQueue(hid_dev);
|
||||
return false;
|
||||
}
|
||||
searchDictionary(dict, hid_dev, num_cookies, hid_cookies);
|
||||
HRESULT err = (*hid_dev->device_queue)->start(hid_dev->device_queue);
|
||||
if (err != S_OK) {
|
||||
closeDeviceAll(hid_dev);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool findDevice(hid_device_t *hid_dev, long device_usage_page, long device_usage, int num_cookies, hid_cookie_t *hid_cookies, int buffer_size) {
|
||||
io_iterator_t device_iterator;
|
||||
io_object_t hid_device;
|
||||
kern_return_t kern_err;
|
||||
bool success = false;
|
||||
CFMutableDictionaryRef dev_props;
|
||||
CFDictionaryRef matching_dic = IOServiceMatching(kIOHIDDeviceKey);
|
||||
IOReturn err = IOServiceGetMatchingServices(kIOMasterPortDefault, matching_dic, &device_iterator);
|
||||
if (err != kIOReturnSuccess) {
|
||||
printfDebug("Could not find matching devices\n");
|
||||
return false;
|
||||
}
|
||||
while (!success && (hid_device = IOIteratorNext(device_iterator)) != NULL) {
|
||||
kern_err = IORegistryEntryCreateCFProperties(hid_device, &dev_props, kCFAllocatorDefault, kNilOptions);
|
||||
if (kern_err == KERN_SUCCESS && dev_props != NULL) {
|
||||
long usage;
|
||||
long usage_page;
|
||||
if (getDictLong(dev_props, CFSTR(kIOHIDPrimaryUsageKey), &usage) &&
|
||||
getDictLong(dev_props, CFSTR(kIOHIDPrimaryUsagePageKey), &usage_page)) {
|
||||
if (isDebugEnabled()) {
|
||||
printf("Considering device '");
|
||||
printProperty(dev_props, CFSTR(kIOHIDProductKey));
|
||||
printf("', usage page %ld usage %ld\n", usage_page, usage);
|
||||
}
|
||||
if (usage_page == device_usage_page && usage == device_usage) {
|
||||
success = initDevice(hid_dev, hid_device, dev_props, num_cookies, hid_cookies, buffer_size);
|
||||
}
|
||||
}
|
||||
CFRelease(dev_props);
|
||||
}
|
||||
IOObjectRelease(hid_device);
|
||||
if (success)
|
||||
break;
|
||||
}
|
||||
IOObjectRelease(device_iterator);
|
||||
return success;
|
||||
}
|
||||
|
||||
void shutdownDevice(hid_device_t *hid_dev) {
|
||||
(*hid_dev->device_queue)->stop(hid_dev->device_queue);
|
||||
closeDeviceAll(hid_dev);
|
||||
}
|
||||
|
||||
bool nextDeviceEvent(hid_device_t *hid_dev, hid_event_t *hid_event) {
|
||||
IOHIDEventStruct event;
|
||||
AbsoluteTime zero_time = {0, 0};
|
||||
HRESULT err = (*hid_dev->device_queue)->getNextEvent(hid_dev->device_queue, &event, zero_time, 0);
|
||||
if (err != S_OK)
|
||||
return false;
|
||||
const void *mapped_index = CFDictionaryGetValue(hid_dev->cookie_map, event.elementCookie);
|
||||
hid_event->cookie_index = mapped_index;
|
||||
hid_event->value = (int)event.value;
|
||||
return true;
|
||||
}
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2004 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
* Mac OS X HID tools.
|
||||
*
|
||||
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
#ifndef _HID_H
|
||||
#define _HID_H
|
||||
|
||||
#include <IOKit/IOKitLib.h>
|
||||
#include <IOKit/hid/IOHIDKeys.h>
|
||||
#include <IOKit/hid/IOHIDLib.h>
|
||||
#include <IOKit/hid/IOHIDUsageTables.h>
|
||||
#include <IOKit/IOCFPlugIn.h>
|
||||
#include <CoreServices/CoreServices.h>
|
||||
|
||||
typedef struct {
|
||||
IOHIDDeviceInterface **device_interface;
|
||||
IOHIDQueueInterface **device_queue;
|
||||
CFMutableDictionaryRef cookie_map;
|
||||
} hid_device_t;
|
||||
|
||||
typedef struct {
|
||||
long usage_page;
|
||||
long usage;
|
||||
} hid_cookie_t;
|
||||
|
||||
typedef struct {
|
||||
int cookie_index;
|
||||
long value;
|
||||
} hid_event_t;
|
||||
|
||||
extern void shutdownDevice(hid_device_t *hid_dev);
|
||||
extern bool findDevice(hid_device_t *hid_dev, long usage_page_match, long usage_match, int num_cookies, hid_cookie_t *device_cookies, int buffer_size);
|
||||
extern bool nextDeviceEvent(hid_device_t *hid_dev, hid_event_t *hid_event);
|
||||
|
||||
#endif
|
||||
|
|
@ -1,215 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2004 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
* Mac OS X specific library for display handling.
|
||||
*
|
||||
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
#include <ApplicationServices/ApplicationServices.h>
|
||||
#include "org_lwjgl_Display.h"
|
||||
#include "common_tools.h"
|
||||
#include "tools.h"
|
||||
|
||||
#define GAMMARAMP_LENGTH 256
|
||||
|
||||
static CFDictionaryRef original_mode;
|
||||
static bool initialized = false;
|
||||
static bool display_captured = false;
|
||||
|
||||
static void saveMode(JNIEnv *env, long width, long height, long bpp, long freq) {
|
||||
jclass display_class = env->FindClass("org/lwjgl/Display");
|
||||
jclass jclass_DisplayMode = env->FindClass("org/lwjgl/DisplayMode");
|
||||
jmethodID ctor = env->GetMethodID(jclass_DisplayMode, "<init>", "(IIII)V");
|
||||
jobject newMode = env->NewObject(jclass_DisplayMode, ctor, width, height, bpp, freq);
|
||||
jfieldID fid_initialMode = env->GetStaticFieldID(display_class, "mode", "Lorg/lwjgl/DisplayMode;");
|
||||
env->SetStaticObjectField(display_class, fid_initialMode, newMode);
|
||||
}
|
||||
|
||||
static void saveOriginalMode(JNIEnv *env) {
|
||||
long width;
|
||||
long height;
|
||||
long bpp;
|
||||
long freq;
|
||||
getDictLong(original_mode, kCGDisplayWidth, &width);
|
||||
getDictLong(original_mode, kCGDisplayHeight, &height);
|
||||
getDictLong(original_mode, kCGDisplayBitsPerPixel, &bpp);
|
||||
getDictLong(original_mode, kCGDisplayRefreshRate, &freq);
|
||||
saveMode(env, width, height, bpp, freq);
|
||||
}
|
||||
|
||||
static void init(JNIEnv *env) {
|
||||
if (!initialized) {
|
||||
initialized = true;
|
||||
original_mode = CGDisplayCurrentMode(kCGDirectMainDisplay);
|
||||
saveOriginalMode(env);
|
||||
}
|
||||
}
|
||||
|
||||
bool switchMode(JNIEnv *env, long width, long height, long bpp, long freq) {
|
||||
init(env);
|
||||
if (display_captured)
|
||||
return false;
|
||||
display_captured = true;
|
||||
CGDisplayCapture(kCGDirectMainDisplay);
|
||||
CFArrayRef modes = CGDisplayAvailableModes(kCGDirectMainDisplay);
|
||||
int size = CFArrayGetCount(modes);
|
||||
for (int i = 0; i < size; i++) {
|
||||
CFDictionaryRef mode = (CFDictionaryRef)CFArrayGetValueAtIndex(modes, i);
|
||||
long mode_width;
|
||||
long mode_height;
|
||||
long mode_bpp;
|
||||
long mode_freq;
|
||||
getDictLong(mode, kCGDisplayWidth, &mode_width);
|
||||
getDictLong(mode, kCGDisplayHeight, &mode_height);
|
||||
getDictLong(mode, kCGDisplayRefreshRate, &mode_freq);
|
||||
getDictLong(mode, kCGDisplayBitsPerPixel, &mode_bpp);
|
||||
if (width == mode_width && height == mode_height && bpp == mode_bpp && mode_freq == freq) {
|
||||
CGDisplayErr err = CGDisplaySwitchToMode(kCGDirectMainDisplay, mode);
|
||||
if (!err) {
|
||||
saveMode(env, width, height, bpp, freq);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
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)
|
||||
return;
|
||||
display_captured = false;
|
||||
CGDisplayRestoreColorSyncSettings();
|
||||
CGDisplaySwitchToMode(kCGDirectMainDisplay, original_mode);
|
||||
CGDisplayRelease(kCGDirectMainDisplay);
|
||||
saveOriginalMode(env);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Display_init(JNIEnv * env, jclass clazz) {
|
||||
init(env);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Display_setDisplayMode(JNIEnv * env, jclass clazz, jobject mode) {
|
||||
jclass cls_displayMode = env->FindClass("org/lwjgl/DisplayMode");
|
||||
jfieldID fid_width = env->GetFieldID(cls_displayMode, "width", "I");
|
||||
jfieldID fid_height = env->GetFieldID(cls_displayMode, "height", "I");
|
||||
jfieldID fid_bpp = env->GetFieldID(cls_displayMode, "bpp", "I");
|
||||
jfieldID fid_freq = env->GetFieldID(cls_displayMode, "freq", "I");
|
||||
int width = env->GetIntField(mode, fid_width);
|
||||
int height = env->GetIntField(mode, fid_height);
|
||||
int bpp = env->GetIntField(mode, fid_bpp);
|
||||
int freq = env->GetIntField(mode, fid_freq);
|
||||
if (!switchMode(env, width, height, bpp, freq)) {
|
||||
throwException(env, "Could not switch mode.");
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_Display_nGetAvailableDisplayModes(JNIEnv * env, jclass clazz) {
|
||||
CFArrayRef modes = CGDisplayAvailableModes(kCGDirectMainDisplay);
|
||||
int size = CFArrayGetCount(modes);
|
||||
int avail_modes = 0;
|
||||
for (int i = 0; i < size; i++) {
|
||||
CFDictionaryRef mode = (CFDictionaryRef)CFArrayGetValueAtIndex(modes, i);
|
||||
long bpp;
|
||||
getDictLong(mode, kCGDisplayBitsPerPixel, &bpp);
|
||||
if (bpp > 8)
|
||||
avail_modes++;
|
||||
}
|
||||
jclass displayModeClass = env->FindClass("org/lwjgl/DisplayMode");
|
||||
jobjectArray ret = env->NewObjectArray(avail_modes, displayModeClass, NULL);
|
||||
jmethodID displayModeConstructor = env->GetMethodID(displayModeClass, "<init>", "(IIII)V");
|
||||
int array_index = 0;
|
||||
for (int i = 0; i < size; i++) {
|
||||
CFDictionaryRef mode = (CFDictionaryRef)CFArrayGetValueAtIndex(modes, i);
|
||||
long width;
|
||||
long height;
|
||||
long bpp;
|
||||
long freq;
|
||||
getDictLong(mode, kCGDisplayWidth, &width);
|
||||
getDictLong(mode, kCGDisplayHeight, &height);
|
||||
getDictLong(mode, kCGDisplayBitsPerPixel, &bpp);
|
||||
getDictLong(mode, kCGDisplayRefreshRate, &freq);
|
||||
if (bpp > 8) {
|
||||
jobject displayMode = env->NewObject(displayModeClass, displayModeConstructor, width, height, bpp, freq);
|
||||
env->SetObjectArrayElement(ret, array_index++, displayMode);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jint JNICALL Java_org_lwjgl_Display_getGammaRampLength(JNIEnv *env, jclass clazz) {
|
||||
return GAMMARAMP_LENGTH;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Display_setGammaRamp(JNIEnv *env, jclass clazz, jobject gamma_ramp_buffer) {
|
||||
const float *gamma_ramp = (const float *)env->GetDirectBufferAddress(gamma_ramp_buffer);
|
||||
CGDisplayErr err = CGSetDisplayTransferByTable(kCGDirectMainDisplay, GAMMARAMP_LENGTH, gamma_ramp, gamma_ramp, gamma_ramp);
|
||||
if (err) {
|
||||
throwException(env, "Could not set gamma.");
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Display_resetDisplayMode(JNIEnv *env, jclass clazz) {
|
||||
resetMode(env);
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL Java_org_lwjgl_Display_getAdapter(JNIEnv * , jclass) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL Java_org_lwjgl_Display_getVersion(JNIEnv * , jclass) {
|
||||
return NULL;
|
||||
}
|
||||
123
src/native/macosx/org_lwjgl_Sys.c
Normal file
123
src/native/macosx/org_lwjgl_Sys.c
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2004 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
* Linux system library.
|
||||
*
|
||||
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
#include <sched.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#include <Carbon/Carbon.h>
|
||||
#include "org_lwjgl_Sys.h"
|
||||
#include "common_tools.h"
|
||||
|
||||
static long int hires_timer; // Hires timer current time
|
||||
|
||||
/*
|
||||
* Class: org_lwjgl_Sys
|
||||
* Method: getTimerResolution
|
||||
* Signature: ()J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL Java_org_lwjgl_Sys_getTimerResolution
|
||||
(JNIEnv * env, jclass clazz)
|
||||
{
|
||||
// Constant on MacOS
|
||||
return 1000000;
|
||||
}
|
||||
|
||||
static long queryTime(void) {
|
||||
struct timeval tv;
|
||||
if (gettimeofday(&tv, NULL) == -1) {
|
||||
printfDebug("Could not read current time\n");
|
||||
}
|
||||
long result = tv.tv_sec * 1000000l + tv.tv_usec;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Sys_setDebug(JNIEnv *env, jclass clazz, jboolean enabled) {
|
||||
setDebugEnabled(enabled == JNI_TRUE ? true : false);
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_org_lwjgl_Sys_ngetTime
|
||||
(JNIEnv * env, jclass clazz)
|
||||
{
|
||||
hires_timer = queryTime();
|
||||
return (jlong) hires_timer;
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL Java_org_lwjgl_Sys_getNativeLibraryVersion(JNIEnv *env, jclass clazz) {
|
||||
return getVersionString(env);
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Sys_setProcessPriority(JNIEnv * env, jclass clazz, jint priority) {
|
||||
printfDebug("WARNING: setProcessPriority unsupported\n");
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Sys_nAlert(JNIEnv * env, jclass clazz, jstring title, jstring message)
|
||||
{
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Sys_nOpenURL
|
||||
(JNIEnv * env, jclass clazz, jstring url)
|
||||
{
|
||||
/* const char * urlString = env->GetStringUTFChars(url, NULL);
|
||||
|
||||
OSStatus err;
|
||||
ICInstance inst;
|
||||
long startSel;
|
||||
long endSel;
|
||||
Str255 urlStr;
|
||||
|
||||
CopyCStringToPascal(urlString, urlStr);
|
||||
env->ReleaseStringUTFChars(url, urlString);
|
||||
err = ICStart(&inst, '????'); // Use your creator code if you have one!
|
||||
if (err == noErr) {
|
||||
startSel = 0;
|
||||
endSel = urlStr[0];
|
||||
err = ICLaunchURL(inst, "\p", (char *) &urlStr[1], urlStr[0], &startSel, &endSel);
|
||||
(void) ICStop(inst);
|
||||
}*/
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL Java_org_lwjgl_Sys_nGetClipboard
|
||||
(JNIEnv * env, jclass clazz)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2004 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
* Mac OS X controller handling.
|
||||
*
|
||||
* @author Elias Naur <brian@matzon.com>
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
#include "org_lwjgl_input_Controller.h"
|
||||
#include "common_tools.h"
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_input_Controller_initIDs(JNIEnv * env, jclass clazz) {
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_input_Controller_nCreate(JNIEnv *env, jclass clazz) {
|
||||
throwException(env, "Controller not implemented");
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_input_Controller_nDestroy(JNIEnv *env, jclass clazz) {
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_input_Controller_nPoll(JNIEnv * env, jclass clazz) {
|
||||
}
|
||||
|
||||
|
|
@ -1,386 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2004 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
* Mac OS X keyboard handling.
|
||||
*
|
||||
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
#include "Window.h"
|
||||
#include "tools.h"
|
||||
#include "org_lwjgl_input_Keyboard.h"
|
||||
#include "common_tools.h"
|
||||
#include <CoreServices/CoreServices.h>
|
||||
|
||||
#define KEYBOARD_SIZE 256
|
||||
#define TRANSLATION_BUFFER_SIZE 10
|
||||
|
||||
static unsigned char key_buf[KEYBOARD_SIZE];
|
||||
static unsigned char key_map[KEYBOARD_SIZE];
|
||||
static bool buffer_enabled = false;
|
||||
static bool translation_enabled = false;
|
||||
static event_queue_t event_queue;
|
||||
static UInt32 deadKeyState;
|
||||
|
||||
static bool handleMappedKey(unsigned char mapped_code, unsigned char state) {
|
||||
unsigned char old_state = key_buf[mapped_code];
|
||||
if (old_state != state) {
|
||||
key_buf[mapped_code] = state;
|
||||
if (buffer_enabled) {
|
||||
putEventElement(&event_queue, mapped_code);
|
||||
putEventElement(&event_queue, state);
|
||||
return translation_enabled;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool handleKey(UInt32 key_code, unsigned char state) {
|
||||
if (key_code >= KEYBOARD_SIZE) {
|
||||
printfDebug("Key code >= %d %x\n", KEYBOARD_SIZE, (unsigned int)key_code);
|
||||
return false;
|
||||
}
|
||||
unsigned char mapped_code = key_map[key_code];
|
||||
if (mapped_code == 0) {
|
||||
printfDebug("unknown key code: %x\n", (unsigned int)key_code);
|
||||
return false;
|
||||
}
|
||||
return handleMappedKey(mapped_code, state);
|
||||
}
|
||||
|
||||
static unsigned char getSecondByte(UniChar ch) {
|
||||
return (unsigned char)(ch & 0xff);
|
||||
}
|
||||
|
||||
static unsigned char getFirstByte(UniChar ch) {
|
||||
return (unsigned char)((ch & 0xff00) >> 16);
|
||||
}
|
||||
|
||||
static bool writeUniChars(int num_chars, const UniChar *buffer) {
|
||||
if (num_chars == 0)
|
||||
return false;
|
||||
unsigned char b0 = getFirstByte(buffer[0]);
|
||||
unsigned char b1 = getSecondByte(buffer[0]);
|
||||
putEventElement(&event_queue, b0);
|
||||
putEventElement(&event_queue, b1);
|
||||
for (int i = 1; i < num_chars; i++) {
|
||||
putEventElement(&event_queue, 0);
|
||||
putEventElement(&event_queue, 0);
|
||||
b0 = getFirstByte(buffer[i]);
|
||||
b1 = getSecondByte(buffer[i]);
|
||||
putEventElement(&event_queue, b0);
|
||||
putEventElement(&event_queue, b1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool writeAsciiChars(int num_chars, const unsigned 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 handleTranslation(EventRef event, bool state) {
|
||||
UniChar unicodeInputString[TRANSLATION_BUFFER_SIZE];
|
||||
|
||||
KeyboardLayoutRef layout;
|
||||
OSStatus err = KLGetCurrentKeyboardLayout(&layout);
|
||||
if (err != noErr) {
|
||||
printfDebug("Could not get current keyboard layout\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
UInt32 keyboardType;
|
||||
UInt32 modifierKeyState;
|
||||
UInt32 virtualKeyCode;
|
||||
UniCharCount actualStringLength;
|
||||
OSStatus status;
|
||||
UCKeyboardLayout *uchrHandle;
|
||||
bool success = GetEventParameter(event, kEventParamKeyCode, typeUInt32, NULL, sizeof(virtualKeyCode), NULL, &virtualKeyCode) == noErr;
|
||||
success = success && GetEventParameter(event, kEventParamKeyboardType, typeUInt32, NULL, sizeof(keyboardType), NULL, &keyboardType) == noErr;
|
||||
success = success && GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(modifierKeyState), NULL, &modifierKeyState) == noErr;
|
||||
if (!success) {
|
||||
printfDebug("Could not get event parameters for character translation\n");
|
||||
return false;
|
||||
}
|
||||
err = KLGetKeyboardLayoutProperty(layout, kKLuchrData, (const void **)&uchrHandle);
|
||||
if (err == noErr && uchrHandle != NULL) {
|
||||
UInt16 action = state ? kUCKeyActionDown : kUCKeyActionUp;
|
||||
status = UCKeyTranslate(uchrHandle, virtualKeyCode, action,
|
||||
modifierKeyState, keyboardType, 0,
|
||||
&deadKeyState, TRANSLATION_BUFFER_SIZE,
|
||||
&actualStringLength, unicodeInputString);
|
||||
if (state)
|
||||
return writeUniChars(actualStringLength, unicodeInputString);
|
||||
} else {
|
||||
void * kchrHandle;
|
||||
err = KLGetKeyboardLayoutProperty(layout, kKLKCHRData, (const void **)&kchrHandle);
|
||||
if (err == noErr && kchrHandle != NULL) {
|
||||
UInt16 action = state ? 0x80 : 0x00;
|
||||
UInt16 key_code = (virtualKeyCode & 0x7f);
|
||||
UInt16 modifier_code = (modifierKeyState & 0xff00);
|
||||
UInt16 code = modifier_code | action | key_code;
|
||||
UInt32 character = KeyTranslate(kchrHandle, code, &deadKeyState);
|
||||
int count = 0;
|
||||
unsigned char ascii_buffer[2];
|
||||
unsigned char c1 = (unsigned char)(character & 0xff);
|
||||
if (c1 != 0)
|
||||
ascii_buffer[count++] = c1;
|
||||
unsigned char c2 = (unsigned char)((character & 0xff0000) >> 16);
|
||||
if (c2 != 0)
|
||||
ascii_buffer[count++] = c2;
|
||||
if (state)
|
||||
return writeAsciiChars(count, ascii_buffer);
|
||||
} else {
|
||||
printfDebug("Could not translate key\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void doKeyDown(EventRef event) {
|
||||
UInt32 key_code;
|
||||
OSStatus err = GetEventParameter(event, kEventParamKeyCode, typeUInt32, NULL, sizeof(key_code), NULL, &key_code);
|
||||
if (err != noErr) {
|
||||
printfDebug("Could not get event key code\n");
|
||||
return;
|
||||
}
|
||||
if (handleKey(key_code, 1) && !handleTranslation(event, true)) {
|
||||
putEventElement(&event_queue, 0);
|
||||
putEventElement(&event_queue, 0);
|
||||
}
|
||||
}
|
||||
|
||||
static void doKeyUp(EventRef event) {
|
||||
UInt32 key_code;
|
||||
OSStatus err = GetEventParameter(event, kEventParamKeyCode, typeUInt32, NULL, sizeof(key_code), NULL, &key_code);
|
||||
if (err != noErr) {
|
||||
printfDebug("Could not get event key code\n");
|
||||
return;
|
||||
}
|
||||
if (handleKey(key_code, 0) && !handleTranslation(event, false)) {
|
||||
putEventElement(&event_queue, 0);
|
||||
putEventElement(&event_queue, 0);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
static void handleModifier(UInt32 modifier_bit_mask, UInt32 modifier_bit, unsigned char key_code) {
|
||||
bool key_down = (modifier_bit_mask & modifier_bit) == modifier_bit;
|
||||
unsigned char key_state = key_down ? 1 : 0;
|
||||
if (handleMappedKey(key_code, key_state)) {
|
||||
putEventElement(&event_queue, 0);
|
||||
putEventElement(&event_queue, 0);
|
||||
}
|
||||
}
|
||||
|
||||
static void doKeyModifier(EventRef event) {
|
||||
UInt32 modifier_bits;
|
||||
OSStatus err = GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(modifier_bits), NULL, &modifier_bits);
|
||||
if (err != noErr) {
|
||||
printfDebug("Could not get event key code\n");
|
||||
return;
|
||||
}
|
||||
handleModifier(modifier_bits, controlKey, 0x1d);
|
||||
handleModifier(modifier_bits, rightControlKey, 0x9d);
|
||||
handleModifier(modifier_bits, shiftKey, 0x2a);
|
||||
handleModifier(modifier_bits, rightShiftKey, 0x36);
|
||||
handleModifier(modifier_bits, optionKey, 0x38);
|
||||
handleModifier(modifier_bits, rightOptionKey, 0xb8);
|
||||
handleModifier(modifier_bits, cmdKey, 0xdb);
|
||||
handleModifier(modifier_bits, alphaLock, 0x3a);
|
||||
handleModifier(modifier_bits, kEventKeyModifierNumLockMask, 0x45);
|
||||
//handleModifier(modifier_bits, rightCmdKey, 0xdc);
|
||||
return;
|
||||
}
|
||||
|
||||
void handleKeyboardEvent(EventRef event) {
|
||||
UInt32 event_kind = GetEventKind(event);
|
||||
switch (event_kind) {
|
||||
case kEventRawKeyDown:
|
||||
doKeyDown(event);
|
||||
break;
|
||||
case kEventRawKeyUp:
|
||||
doKeyUp(event);
|
||||
break;
|
||||
case kEventRawKeyModifiersChanged:
|
||||
doKeyModifier(event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void setupMappings(void) {
|
||||
memset(key_map, 0, KEYBOARD_SIZE*sizeof(unsigned char));
|
||||
key_map[0x35] = org_lwjgl_input_Keyboard_KEY_ESCAPE;
|
||||
key_map[0x12] = org_lwjgl_input_Keyboard_KEY_1;
|
||||
key_map[0x13] = org_lwjgl_input_Keyboard_KEY_2;
|
||||
key_map[0x14] = org_lwjgl_input_Keyboard_KEY_3;
|
||||
key_map[0x15] = org_lwjgl_input_Keyboard_KEY_4;
|
||||
key_map[0x17] = org_lwjgl_input_Keyboard_KEY_5;
|
||||
key_map[0x16] = org_lwjgl_input_Keyboard_KEY_6;
|
||||
key_map[0x1a] = org_lwjgl_input_Keyboard_KEY_7;
|
||||
key_map[0x1c] = org_lwjgl_input_Keyboard_KEY_8;
|
||||
key_map[0x19] = org_lwjgl_input_Keyboard_KEY_9;
|
||||
key_map[0x1d] = org_lwjgl_input_Keyboard_KEY_0;
|
||||
key_map[0x1b] = org_lwjgl_input_Keyboard_KEY_MINUS;
|
||||
key_map[0x18] = org_lwjgl_input_Keyboard_KEY_EQUALS;
|
||||
key_map[0x33] = org_lwjgl_input_Keyboard_KEY_BACK;
|
||||
key_map[0x30] = org_lwjgl_input_Keyboard_KEY_TAB;
|
||||
key_map[0x0c] = org_lwjgl_input_Keyboard_KEY_Q;
|
||||
key_map[0x0d] = org_lwjgl_input_Keyboard_KEY_W;
|
||||
key_map[0x0e] = org_lwjgl_input_Keyboard_KEY_E;
|
||||
key_map[0x0f] = org_lwjgl_input_Keyboard_KEY_R;
|
||||
key_map[0x11] = org_lwjgl_input_Keyboard_KEY_T;
|
||||
key_map[0x10] = org_lwjgl_input_Keyboard_KEY_Y;
|
||||
key_map[0x20] = org_lwjgl_input_Keyboard_KEY_U;
|
||||
key_map[0x22] = org_lwjgl_input_Keyboard_KEY_I;
|
||||
key_map[0x1f] = org_lwjgl_input_Keyboard_KEY_O;
|
||||
key_map[0x23] = org_lwjgl_input_Keyboard_KEY_P;
|
||||
key_map[0x21] = org_lwjgl_input_Keyboard_KEY_LBRACKET;
|
||||
key_map[0x1e] = org_lwjgl_input_Keyboard_KEY_RBRACKET;
|
||||
key_map[0x24] = org_lwjgl_input_Keyboard_KEY_RETURN;
|
||||
key_map[0x00] = org_lwjgl_input_Keyboard_KEY_A;
|
||||
key_map[0x01] = org_lwjgl_input_Keyboard_KEY_S;
|
||||
key_map[0x02] = org_lwjgl_input_Keyboard_KEY_D;
|
||||
key_map[0x03] = org_lwjgl_input_Keyboard_KEY_F;
|
||||
key_map[0x05] = org_lwjgl_input_Keyboard_KEY_G;
|
||||
key_map[0x04] = org_lwjgl_input_Keyboard_KEY_H;
|
||||
key_map[0x26] = org_lwjgl_input_Keyboard_KEY_J;
|
||||
key_map[0x28] = org_lwjgl_input_Keyboard_KEY_K;
|
||||
key_map[0x25] = org_lwjgl_input_Keyboard_KEY_L;
|
||||
key_map[0x29] = org_lwjgl_input_Keyboard_KEY_SEMICOLON;
|
||||
key_map[0x27] = org_lwjgl_input_Keyboard_KEY_APOSTROPHE;
|
||||
key_map[0x2a] = org_lwjgl_input_Keyboard_KEY_GRAVE;
|
||||
key_map[0x32] = org_lwjgl_input_Keyboard_KEY_BACKSLASH;
|
||||
key_map[0x06] = org_lwjgl_input_Keyboard_KEY_Z;
|
||||
key_map[0x07] = org_lwjgl_input_Keyboard_KEY_X;
|
||||
key_map[0x08] = org_lwjgl_input_Keyboard_KEY_C;
|
||||
key_map[0x09] = org_lwjgl_input_Keyboard_KEY_V;
|
||||
key_map[0x0b] = org_lwjgl_input_Keyboard_KEY_B;
|
||||
key_map[0x2d] = org_lwjgl_input_Keyboard_KEY_N;
|
||||
key_map[0x2e] = org_lwjgl_input_Keyboard_KEY_M;
|
||||
key_map[0x2b] = org_lwjgl_input_Keyboard_KEY_COMMA;
|
||||
key_map[0x2f] = org_lwjgl_input_Keyboard_KEY_PERIOD;
|
||||
key_map[0x2c] = org_lwjgl_input_Keyboard_KEY_SLASH;
|
||||
key_map[0x43] = org_lwjgl_input_Keyboard_KEY_MULTIPLY;
|
||||
key_map[0x31] = org_lwjgl_input_Keyboard_KEY_SPACE;
|
||||
key_map[0x7a] = org_lwjgl_input_Keyboard_KEY_F1;
|
||||
key_map[0x78] = org_lwjgl_input_Keyboard_KEY_F2;
|
||||
key_map[0x63] = org_lwjgl_input_Keyboard_KEY_F3;
|
||||
key_map[0x76] = org_lwjgl_input_Keyboard_KEY_F4;
|
||||
key_map[0x60] = org_lwjgl_input_Keyboard_KEY_F5;
|
||||
key_map[0x61] = org_lwjgl_input_Keyboard_KEY_F6;
|
||||
key_map[0x62] = org_lwjgl_input_Keyboard_KEY_F7;
|
||||
key_map[0x64] = org_lwjgl_input_Keyboard_KEY_F8;
|
||||
key_map[0x65] = org_lwjgl_input_Keyboard_KEY_F9;
|
||||
key_map[0x6d] = org_lwjgl_input_Keyboard_KEY_F10;
|
||||
key_map[0x59] = org_lwjgl_input_Keyboard_KEY_NUMPAD7;
|
||||
key_map[0x5b] = org_lwjgl_input_Keyboard_KEY_NUMPAD8;
|
||||
key_map[0x5c] = org_lwjgl_input_Keyboard_KEY_NUMPAD9;
|
||||
key_map[0x4e] = org_lwjgl_input_Keyboard_KEY_SUBTRACT;
|
||||
key_map[0x56] = org_lwjgl_input_Keyboard_KEY_NUMPAD4;
|
||||
key_map[0x57] = org_lwjgl_input_Keyboard_KEY_NUMPAD5;
|
||||
key_map[0x58] = org_lwjgl_input_Keyboard_KEY_NUMPAD6;
|
||||
key_map[0x45] = org_lwjgl_input_Keyboard_KEY_ADD;
|
||||
key_map[0x53] = org_lwjgl_input_Keyboard_KEY_NUMPAD1;
|
||||
key_map[0x54] = org_lwjgl_input_Keyboard_KEY_NUMPAD2;
|
||||
key_map[0x55] = org_lwjgl_input_Keyboard_KEY_NUMPAD3;
|
||||
key_map[0x52] = org_lwjgl_input_Keyboard_KEY_NUMPAD0;
|
||||
key_map[0x41] = org_lwjgl_input_Keyboard_KEY_DECIMAL;
|
||||
key_map[0x67] = org_lwjgl_input_Keyboard_KEY_F11;
|
||||
key_map[0x6f] = org_lwjgl_input_Keyboard_KEY_F12;
|
||||
key_map[0x51] = org_lwjgl_input_Keyboard_KEY_NUMPADEQUALS;
|
||||
key_map[0x4c] = org_lwjgl_input_Keyboard_KEY_NUMPADENTER;
|
||||
key_map[0x4b] = org_lwjgl_input_Keyboard_KEY_DIVIDE;
|
||||
key_map[0x73] = org_lwjgl_input_Keyboard_KEY_HOME;
|
||||
key_map[0x7e] = org_lwjgl_input_Keyboard_KEY_UP;
|
||||
key_map[0x74] = org_lwjgl_input_Keyboard_KEY_PRIOR;
|
||||
key_map[0x7b] = org_lwjgl_input_Keyboard_KEY_LEFT;
|
||||
key_map[0x7c] = org_lwjgl_input_Keyboard_KEY_RIGHT;
|
||||
key_map[0x7d] = org_lwjgl_input_Keyboard_KEY_DOWN;
|
||||
key_map[0x79] = org_lwjgl_input_Keyboard_KEY_NEXT;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nCreate(JNIEnv * env, jclass clazz) {
|
||||
buffer_enabled = false;
|
||||
translation_enabled = false;
|
||||
deadKeyState = 0;
|
||||
initEventQueue(&event_queue);
|
||||
memset(key_buf, 0, KEYBOARD_SIZE*sizeof(unsigned char));
|
||||
setupMappings();
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nDestroy(JNIEnv * env, jclass clazz) {
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nPoll(JNIEnv * env, jclass clazz, jobject buffer) {
|
||||
unsigned char *new_keyboard_buffer = (unsigned char *)env->GetDirectBufferAddress(buffer);
|
||||
memcpy(new_keyboard_buffer, key_buf, KEYBOARD_SIZE*sizeof(unsigned char));
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_org_lwjgl_input_Keyboard_nRead(JNIEnv * env, jclass clazz, jobject buffer, jint buffer_position) {
|
||||
int event_size;
|
||||
if (translation_enabled)
|
||||
event_size = 4;
|
||||
else
|
||||
event_size = 2;
|
||||
unsigned char* buffer_ptr = (unsigned char *)env->GetDirectBufferAddress(buffer);
|
||||
int buffer_size = env->GetDirectBufferCapacity(buffer) - buffer_position;
|
||||
return copyEvents(&event_queue, buffer_ptr + buffer_position, buffer_size, event_size);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nEnableTranslation(JNIEnv *env, jclass clazz) {
|
||||
translation_enabled = true;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nEnableBuffer(JNIEnv * env, jclass clazz) {
|
||||
buffer_enabled = true;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_org_lwjgl_input_Keyboard_nisStateKeySet(JNIEnv *env, jclass clazz, jint key) {
|
||||
return org_lwjgl_input_Keyboard_STATE_UNKNOWN;
|
||||
}
|
||||
|
|
@ -33,16 +33,40 @@
|
|||
/**
|
||||
* $Id$
|
||||
*
|
||||
* Mac OS X cursor handling.
|
||||
* Mac OS X mouse handling.
|
||||
*
|
||||
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
#include "org_lwjgl_input_Cursor.h"
|
||||
#include <jni.h>
|
||||
#include <ApplicationServices/ApplicationServices.h>
|
||||
#include "common_tools.h"
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_org_lwjgl_input_Cursor_nCreateCursor(JNIEnv *env, jclass clazz, jint width, jint height, jint x_hotspot, jint y_hotspot, jint num_images, jobject image_buffer, jint images_offset, jobject delay_buffer, jint delays_offset) {
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_nGrabMouse(JNIEnv *env, jobject this, jboolean grab) {
|
||||
CGAssociateMouseAndMouseCursorPosition(grab == JNI_TRUE ? FALSE : TRUE);
|
||||
if (grab == JNI_TRUE)
|
||||
CGDisplayHideCursor(kCGDirectMainDisplay);
|
||||
else
|
||||
CGDisplayShowCursor(kCGDirectMainDisplay);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_input_Cursor_nDestroyCursor(JNIEnv *env, jclass clazz, jlong cursor_handle) {
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_nWarpCursor(JNIEnv *env, jobject this, jint x, jint y) {
|
||||
CGPoint p;
|
||||
p.x = x;
|
||||
p.y = y;
|
||||
CGWarpMouseCursorPosition(p);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_getMouseDeltas(JNIEnv *env, jobject this, jobject delta_buffer) {
|
||||
CGMouseDelta dx, dy;
|
||||
CGGetLastMouseDelta(&dx, &dy);
|
||||
int buffer_length = (*env)->GetDirectBufferCapacity(env, delta_buffer);
|
||||
if (buffer_length != 2) {
|
||||
printfDebug("Delta buffer not large enough!\n");
|
||||
return;
|
||||
}
|
||||
jint *buffer = (*env)->GetDirectBufferAddress(env, delta_buffer);
|
||||
buffer[0] = dx;
|
||||
buffer[1] = dy;
|
||||
}
|
||||
|
|
@ -1,269 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2004 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
* Mac OS X mouse handling.
|
||||
*
|
||||
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
#include <ApplicationServices/ApplicationServices.h>
|
||||
#include "org_lwjgl_input_Mouse.h"
|
||||
#include "Window.h"
|
||||
#include "tools.h"
|
||||
#include "common_tools.h"
|
||||
#include "hid.h"
|
||||
|
||||
static const int NUM_BUTTONS = 7;
|
||||
static const int NUM_COOKIES = NUM_BUTTONS + 3;
|
||||
static const int WHEEL_SCALE = 120;
|
||||
|
||||
static jbyte button_states[NUM_BUTTONS];
|
||||
static bool buffer_enabled;
|
||||
/*static int x_axis_index = NUM_BUTTONS;
|
||||
static int y_axis_index = NUM_BUTTONS + 1;
|
||||
static int z_axis_index = NUM_BUTTONS + 2;
|
||||
static hid_device_t hid_dev;*/
|
||||
static event_queue_t event_queue;
|
||||
|
||||
static int last_dx;
|
||||
static int last_dy;
|
||||
static int last_dz;
|
||||
static bool created;
|
||||
|
||||
static void handleButton(unsigned char button_index, jbyte state) {
|
||||
if (button_index >= NUM_BUTTONS) {
|
||||
printfDebug("Button index %d out of range [0..%d]\n", button_index, NUM_BUTTONS);
|
||||
return;
|
||||
}
|
||||
button_states[button_index] = state;
|
||||
if (buffer_enabled) {
|
||||
putEventElement(&event_queue, button_index);
|
||||
putEventElement(&event_queue, state);
|
||||
}
|
||||
}
|
||||
|
||||
/*static void pollMouseDevice() {
|
||||
hid_event_t event;
|
||||
cont:
|
||||
while (nextDeviceEvent(&hid_dev, &event)) {
|
||||
if (event.cookie_index == x_axis_index) {
|
||||
last_dx += event.value;
|
||||
continue;
|
||||
}
|
||||
else if (event.cookie_index == y_axis_index) {
|
||||
last_dy += event.value;
|
||||
continue;
|
||||
}
|
||||
else if (event.cookie_index == z_axis_index) {
|
||||
last_dz += event.value;
|
||||
continue;
|
||||
} else {
|
||||
for (int i = 0; i < NUM_BUTTONS; i++) {
|
||||
if (event.cookie_index == i) {
|
||||
if (event.value != 0)
|
||||
handleButton(i, 1);
|
||||
else
|
||||
handleButton(i, 0);
|
||||
goto cont;
|
||||
}
|
||||
}
|
||||
}
|
||||
printfDebug("Recieved an unknown HID device event\n");
|
||||
}
|
||||
}
|
||||
*/
|
||||
static void resetDeltas(void) {
|
||||
last_dx = 0;
|
||||
last_dy = 0;
|
||||
last_dz = 0;
|
||||
}
|
||||
|
||||
static void handleButtonEvent(EventRef event, unsigned char state) {
|
||||
EventMouseButton button;
|
||||
OSStatus err = GetEventParameter(event, kEventParamMouseButton, typeMouseButton, NULL, sizeof(button), NULL, &button);
|
||||
if (err != noErr) {
|
||||
printfDebug("Could not get button parameter from event\n");
|
||||
return;
|
||||
}
|
||||
handleButton(button - 1, state);
|
||||
}
|
||||
|
||||
static void handleMovedEvent(EventRef event) {
|
||||
HIPoint delta;
|
||||
OSStatus err = GetEventParameter(event, kEventParamMouseDelta, typeHIPoint, NULL, sizeof(delta), NULL, &delta);
|
||||
if (err != noErr) {
|
||||
printfDebug("Could not delta parameter from event\n");
|
||||
return;
|
||||
}
|
||||
last_dx += (int)delta.x;
|
||||
last_dy += (int)delta.y;
|
||||
}
|
||||
|
||||
static void handleWheelEvent(EventRef event) {
|
||||
long delta;
|
||||
OSStatus err = GetEventParameter(event, kEventParamMouseWheelDelta, typeLongInteger, NULL, sizeof(delta), NULL, &delta);
|
||||
if (err != noErr) {
|
||||
printfDebug("Could not delta parameter from event\n");
|
||||
return;
|
||||
}
|
||||
last_dz += (int)delta;
|
||||
}
|
||||
|
||||
void handleMouseEvent(EventRef event) {
|
||||
UInt32 event_kind = GetEventKind(event);
|
||||
switch (event_kind) {
|
||||
case kEventMouseDown:
|
||||
handleButtonEvent(event, 1);
|
||||
break;
|
||||
case kEventMouseUp:
|
||||
handleButtonEvent(event, 0);
|
||||
break;
|
||||
case kEventMouseDragged:
|
||||
case kEventMouseMoved:
|
||||
handleMovedEvent(event);
|
||||
break;
|
||||
case kEventMouseWheelMoved:
|
||||
handleWheelEvent(event);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_input_Mouse_nHasWheel(JNIEnv *, jclass) {
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_org_lwjgl_input_Mouse_nGetButtonCount(JNIEnv *, jclass) {
|
||||
return NUM_BUTTONS;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_org_lwjgl_input_Mouse_nGetNativeCursorCaps(JNIEnv *env, jclass clazz) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nSetNativeCursor(JNIEnv *env, jclass clazz, jlong cursor_handle) {
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_org_lwjgl_input_Mouse_nGetMinCursorSize(JNIEnv *env, jclass clazz) {
|
||||
return 16;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_org_lwjgl_input_Mouse_nGetMaxCursorSize(JNIEnv *env, jclass clazz) {
|
||||
return 16;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nCreate(JNIEnv * env, jclass clazz) {
|
||||
// native_cursor = false;
|
||||
buffer_enabled = false;
|
||||
resetDeltas();
|
||||
for (int i = 0; i < NUM_BUTTONS; i++) {
|
||||
button_states[i] = 0;
|
||||
}
|
||||
initEventQueue(&event_queue);
|
||||
/* hid_cookie_t hid_cookies[NUM_COOKIES];
|
||||
for (int i = 0; i < NUM_BUTTONS; i++) {
|
||||
hid_cookies[i].usage_page = kHIDPage_Button;
|
||||
hid_cookies[i].usage = i + 1;
|
||||
}
|
||||
hid_cookies[x_axis_index].usage_page = kHIDPage_GenericDesktop;
|
||||
hid_cookies[x_axis_index].usage = kHIDUsage_GD_X;
|
||||
hid_cookies[y_axis_index].usage_page = kHIDPage_GenericDesktop;
|
||||
hid_cookies[y_axis_index].usage = kHIDUsage_GD_Y;
|
||||
hid_cookies[z_axis_index].usage_page = kHIDPage_GenericDesktop;
|
||||
hid_cookies[z_axis_index].usage = kHIDUsage_GD_Wheel;
|
||||
if (!findDevice(&hid_dev, kHIDPage_GenericDesktop, kHIDUsage_GD_Mouse, NUM_COOKIES, hid_cookies, EVENT_BUFFER_SIZE)) {
|
||||
throwException(env, "Could not find HID mouse device");
|
||||
return;
|
||||
}*/
|
||||
CGAssociateMouseAndMouseCursorPosition(FALSE);
|
||||
CGDisplayHideCursor(CGMainDisplayID());
|
||||
created = true;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nDestroy(JNIEnv * env, jclass clazz) {
|
||||
//shutdownDevice(&hid_dev);
|
||||
if (created) {
|
||||
created = false;
|
||||
CGDisplayShowCursor(CGMainDisplayID());
|
||||
CGAssociateMouseAndMouseCursorPosition(TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nPoll(JNIEnv * env, jclass clazz, jobject coord_buffer_obj, jobject button_buffer_obj) {
|
||||
int dx, dy, dz;
|
||||
//pollMouseDevice();
|
||||
dz = last_dz*WHEEL_SCALE;
|
||||
dx = last_dx;
|
||||
dy = -last_dy;
|
||||
int *coords = (int *)env->GetDirectBufferAddress(coord_buffer_obj);
|
||||
int coords_length = env->GetDirectBufferCapacity(coord_buffer_obj);
|
||||
unsigned char *buttons_buffer = (unsigned char *)env->GetDirectBufferAddress(button_buffer_obj);
|
||||
int buttons_length = env->GetDirectBufferCapacity(button_buffer_obj);
|
||||
if (coords_length < 3) {
|
||||
printfDebug("ERROR: Not enough space in coords array: %d < 3\n", coords_length);
|
||||
return;
|
||||
}
|
||||
coords[0] = dx;
|
||||
coords[1] = dy;
|
||||
coords[2] = dz;
|
||||
int num_buttons = NUM_BUTTONS;
|
||||
if (num_buttons > buttons_length)
|
||||
num_buttons = buttons_length;
|
||||
for (int i = 0; i < num_buttons; i++)
|
||||
buttons_buffer[i] = button_states[i];
|
||||
resetDeltas();
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nEnableBuffer(JNIEnv *env, jclass clazz) {
|
||||
buffer_enabled = true;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_org_lwjgl_input_Mouse_nRead(JNIEnv *env, jclass clazz, jobject buffer, jint buffer_position) {
|
||||
unsigned char* buffer_ptr = (unsigned char *)env->GetDirectBufferAddress(buffer);
|
||||
int buffer_size = env->GetDirectBufferCapacity(buffer) - buffer_position;
|
||||
return copyEvents(&event_queue, buffer_ptr + buffer_position, buffer_size, 2);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_lwjgl_input_Mouse
|
||||
* Method: nGrabMouse
|
||||
* Signature: (Z)Z
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nGrabMouse
|
||||
(JNIEnv * env, jclass clazz, jboolean grab) {
|
||||
// do it?
|
||||
}
|
||||
|
|
@ -29,12 +29,18 @@
|
|||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef TOOLS_H
|
||||
#define TOOLS_H
|
||||
|
||||
#include <JavaVM/jni.h>
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
* Mac OS X Pbuffer.
|
||||
*
|
||||
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
extern bool getDictLong(CFDictionaryRef dict, CFStringRef key, long *key_value);
|
||||
#include <jni.h>
|
||||
|
||||
#endif
|
||||
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Pbuffer_getPbufferCaps(JNIEnv *env, jclass clazz) {
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,134 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2004 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
* Mac OS X Pbuffer.
|
||||
*
|
||||
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
#include "org_lwjgl_opengl_Pbuffer.h"
|
||||
#include "extgl.h"
|
||||
#include <OpenGL/OpenGL.h>
|
||||
#include "common_tools.h"
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Pbuffer_nIsBufferLost(JNIEnv *env, jclass clazz, jint handle) {
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Pbuffer_getPbufferCaps(JNIEnv *env, jclass clazz) {
|
||||
/* CGLRendererInfoObj renderers;
|
||||
long num_renderers;
|
||||
CGLError err = CGLQueryRendererInfo(~0L, &renderers, &num_renderers);
|
||||
if (err)
|
||||
return 0;
|
||||
int result = 0;
|
||||
for (long i = 0; i < num_renderers; i++) {
|
||||
long pbuffer_supported;
|
||||
err = CGLDescribeRenderer(renderers, i, kCGLRPOffScreen, &pbuffer_supported);
|
||||
if (!err && pbuffer_supported == true)
|
||||
result = org_lwjgl_opengl_Pbuffer_PBUFFER_SUPPORTED;
|
||||
}
|
||||
CGLDestroyRendererInfo(renderers);
|
||||
return result;*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_lwjgl_opengl_Pbuffer
|
||||
* Method: nCreate
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Pbuffer_nCreate
|
||||
(JNIEnv *env, jclass clazz,
|
||||
jint width, jint height,
|
||||
jint bpp, jint alpha, jint depth, jint stencil,
|
||||
jint samples,
|
||||
jobject pixelFormatCaps, jint pixelFormatCapsSize, jobject pBufferAttribs, jint pBufferAttribsSize)
|
||||
{
|
||||
/* CGLPixelFormatObj pixel_format;
|
||||
CGLContextObj context;
|
||||
int dummy;
|
||||
CGLPixelFormatAttribute attribs[] = {kCGLPFAOffScreen,
|
||||
kCGLPFAMinimumPolicy,
|
||||
kCGLPFAColorSize,
|
||||
(CGLPixelFormatAttribute)bpp,
|
||||
kCGLPFAAlphaSize,
|
||||
(CGLPixelFormatAttribute)alpha,
|
||||
kCGLPFADepthSize,
|
||||
(CGLPixelFormatAttribute)depth,
|
||||
kCGLPFAStencilSize,
|
||||
(CGLPixelFormatAttribute)stencil,
|
||||
(CGLPixelFormatAttribute)NULL};
|
||||
CGLChoosePixelFormat(attribs, &pixel_format, &dummy);
|
||||
if (pixel_format == NULL) {
|
||||
throwException(env, "Could not find matching pixel format");
|
||||
return -1;
|
||||
}
|
||||
CGLCreateContext(pixel_format, NULL, &context);
|
||||
CGLDestroyPixelFormat(pixel_format);
|
||||
if (context == NULL) {
|
||||
throwException(env, "Could not create offscreen context");
|
||||
return -1;
|
||||
}
|
||||
CGLSetOffscreen(*/
|
||||
return -1;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Pbuffer_nReleaseContext(JNIEnv *env, jclass clazz) {
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Pbuffer_nMakeCurrent(JNIEnv *env, jclass clazz, jint handle) {
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Pbuffer_nDestroy(JNIEnv *env, jclass clazz, jint handle) {
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Pbuffer_nSetAttrib
|
||||
(JNIEnv *env, jclass clazz, jint handle, jint attrib, jint value)
|
||||
{
|
||||
throwException(env, "The render-to-texture extension is not supported.");
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Pbuffer_nBindTexImage
|
||||
(JNIEnv *env, jclass clazz, jint handle, jint buffer)
|
||||
{
|
||||
throwException(env, "The render-to-texture extension is not supported.");
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Pbuffer_nReleaseTexImage
|
||||
(JNIEnv *env, jclass clazz, jint handle, jint buffer)
|
||||
{
|
||||
throwException(env, "The render-to-texture extension is not supported.");
|
||||
}
|
||||
|
|
@ -1,192 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2004 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
* Base OSX functionality for GL.
|
||||
*
|
||||
* @author Elias Naur <elias_naur@sourceforge.net>
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
#include <OpenGL/OpenGL.h>
|
||||
#include "org_lwjgl_opengl_Window.h"
|
||||
#include "Window.h"
|
||||
#include "extgl.h"
|
||||
#include "tools.h"
|
||||
#include "common_tools.h"
|
||||
|
||||
static CGLContextObj context;
|
||||
static bool vsync_enabled;
|
||||
static bool current_fullscreen;
|
||||
|
||||
static void destroyMode(JNIEnv *env, jclass clazz) {
|
||||
if (!current_fullscreen)
|
||||
resetMode(env);
|
||||
}
|
||||
|
||||
static void destroy(JNIEnv *env, jclass clazz) {
|
||||
CGLSetCurrentContext(NULL);
|
||||
CGLDestroyContext(context);
|
||||
destroyMode(env, clazz);
|
||||
}
|
||||
|
||||
static bool createFullscreenContext(JNIEnv *env, jint bpp, jint alpha, jint depth, jint stencil) {
|
||||
CGOpenGLDisplayMask display_mask = CGDisplayIDToOpenGLDisplayMask(kCGDirectMainDisplay);
|
||||
CGLPixelFormatObj pixel_format;
|
||||
long num_formats;
|
||||
CGLPixelFormatAttribute attribs[] = {kCGLPFAFullScreen,
|
||||
kCGLPFADoubleBuffer,
|
||||
kCGLPFAMinimumPolicy,
|
||||
kCGLPFAAccelerated,
|
||||
kCGLPFADisplayMask,
|
||||
(CGLPixelFormatAttribute)display_mask,
|
||||
kCGLPFAColorSize,
|
||||
(CGLPixelFormatAttribute)bpp,
|
||||
kCGLPFAAlphaSize,
|
||||
(CGLPixelFormatAttribute)alpha,
|
||||
kCGLPFADepthSize,
|
||||
(CGLPixelFormatAttribute)depth,
|
||||
kCGLPFAStencilSize,
|
||||
(CGLPixelFormatAttribute)stencil,
|
||||
(CGLPixelFormatAttribute)NULL};
|
||||
CGLChoosePixelFormat(attribs, &pixel_format, &num_formats);
|
||||
if (pixel_format == NULL) {
|
||||
throwException(env, "Could not find matching pixel format");
|
||||
return false;
|
||||
}
|
||||
CGLCreateContext(pixel_format, NULL, &context);
|
||||
CGLDestroyPixelFormat(pixel_format);
|
||||
if (context == NULL) {
|
||||
throwException(env, "Could not create fullscreen context");
|
||||
return false;
|
||||
}
|
||||
CGLSetFullScreen(context);
|
||||
CGLSetCurrentContext(context);
|
||||
return true;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Window_nIsCloseRequested(JNIEnv *, jclass) {
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_lwjgl_Window
|
||||
* Method: nMakeCurrent
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nMakeCurrent
|
||||
(JNIEnv *env, jclass clazz) {
|
||||
CGLSetCurrentContext(context);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nCreate(JNIEnv *env, jclass clazz, jstring title, jint x, jint y, jint width, jint height, jboolean fullscreen, jint bpp, jint alpha, jint depth, jint stencil, jint samples) {
|
||||
vsync_enabled = false;
|
||||
current_fullscreen = fullscreen == JNI_TRUE;
|
||||
if (!extgl_InitAGL(env)) {
|
||||
throwException(env, "Could not load agl symbols");
|
||||
return;
|
||||
}
|
||||
if (!current_fullscreen) {
|
||||
if (!switchToNearestMode(env, width, height, bpp, 60)) {
|
||||
destroyMode(env, clazz);
|
||||
throwException(env, "Could not switch mode.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!createFullscreenContext(env, bpp, alpha, depth, stencil)) {
|
||||
destroyMode(env, clazz);
|
||||
return;
|
||||
}
|
||||
FlushEventQueue(GetMainEventQueue());
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nSetTitle(JNIEnv * env, jclass clazz, jstring title_obj) {
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nUpdate(JNIEnv *env, jclass clazz) {
|
||||
EventRef event;
|
||||
OSStatus err = ReceiveNextEvent(0, NULL, 0, true, &event);
|
||||
if (err == noErr) {
|
||||
UInt32 event_class = GetEventClass(event);
|
||||
switch (event_class) {
|
||||
case kEventClassKeyboard:
|
||||
handleKeyboardEvent(event);
|
||||
break;
|
||||
case kEventClassMouse:
|
||||
handleMouseEvent(event);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_swapBuffers(JNIEnv * env, jclass clazz) {
|
||||
CGLFlushDrawable(context);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_minimize(JNIEnv *env, jclass clazz) {
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_restore(JNIEnv *env, jclass clazz) {
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nDestroy(JNIEnv *env, jclass clazz) {
|
||||
destroy(env, clazz);
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Window_nIsFocused(JNIEnv *env, jclass clazz) {
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Window_nIsDirty(JNIEnv *env, jclass clazz) {
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Window_nIsMinimized(JNIEnv *env, jclass clazz) {
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Window_nIsVisible(JNIEnv *env, jclass clazz) {
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nSetVSyncEnabled(JNIEnv *env, jclass clazz, jboolean enable) {
|
||||
bool should_enable = enable == JNI_TRUE;
|
||||
if (vsync_enabled != should_enable) {
|
||||
vsync_enabled = should_enable;
|
||||
long swap_interval = vsync_enabled ? 1 : 0;
|
||||
CGLSetParameter(context, kCGLCPSwapInterval, &swap_interval);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2004 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <CoreServices/CoreServices.h>
|
||||
#include "tools.h"
|
||||
#include "common_tools.h"
|
||||
|
||||
MPCriticalRegionID critical_region;
|
||||
|
||||
bool getDictLong(CFDictionaryRef dict, CFStringRef key, long *key_value) {
|
||||
CFTypeRef val = CFDictionaryGetValue(dict, key);
|
||||
if (val != NULL) {
|
||||
CFTypeID type = CFGetTypeID(val);
|
||||
if (type == CFNumberGetTypeID())
|
||||
if (CFNumberGetValue((CFNumberRef)val, kCFNumberLongType, key_value))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Loading…
Reference in a new issue