2004-11-25 17:31:38 -05:00
|
|
|
/*
|
2004-11-11 11:03:19 -05:00
|
|
|
* Copyright (c) 2002-2004 LWJGL Project
|
|
|
|
* All rights reserved.
|
2004-11-25 17:31:38 -05:00
|
|
|
*
|
2004-11-11 11:03:19 -05:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
2004-11-25 17:31:38 -05:00
|
|
|
* modification, are permitted provided that the following conditions are
|
2004-11-11 11:03:19 -05:00
|
|
|
* met:
|
2004-11-25 17:31:38 -05:00
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
2004-11-11 11:03:19 -05:00
|
|
|
* 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.
|
|
|
|
*
|
2004-11-25 17:31:38 -05:00
|
|
|
* * Neither the name of 'LWJGL' nor the names of
|
|
|
|
* its contributors may be used to endorse or promote products derived
|
2004-11-11 11:03:19 -05:00
|
|
|
* from this software without specific prior written permission.
|
2004-11-25 17:31:38 -05:00
|
|
|
*
|
2004-11-11 11:03:19 -05:00
|
|
|
* 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
|
2004-11-25 17:31:38 -05:00
|
|
|
* 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
|
2004-11-11 11:03:19 -05:00
|
|
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
2004-11-25 17:31:38 -05:00
|
|
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
2004-11-11 11:03:19 -05:00
|
|
|
* 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.awt.Cursor;
|
|
|
|
import java.awt.Dimension;
|
|
|
|
import java.awt.Point;
|
2004-11-20 11:46:44 -05:00
|
|
|
import java.awt.Rectangle;
|
2004-11-11 11:03:19 -05:00
|
|
|
import java.awt.Toolkit;
|
|
|
|
import java.awt.image.BufferedImage;
|
2004-11-12 05:39:06 -05:00
|
|
|
import java.lang.reflect.InvocationHandler;
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
2004-11-20 11:46:44 -05:00
|
|
|
import java.lang.reflect.Method;
|
|
|
|
import java.lang.reflect.Proxy;
|
|
|
|
import java.nio.ByteBuffer;
|
|
|
|
import java.nio.FloatBuffer;
|
|
|
|
import java.nio.IntBuffer;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import org.lwjgl.LWJGLException;
|
2005-01-11 08:53:12 -05:00
|
|
|
import org.lwjgl.BufferUtils;
|
2004-11-20 11:46:44 -05:00
|
|
|
import org.lwjgl.input.Keyboard;
|
2004-11-11 11:03:19 -05:00
|
|
|
|
2004-11-12 08:23:20 -05:00
|
|
|
final class MacOSXDisplay implements DisplayImplementation {
|
2005-01-11 08:53:12 -05:00
|
|
|
private static final int PBUFFER_HANDLE_SIZE = 24;
|
2004-11-25 17:31:38 -05:00
|
|
|
private static final int GAMMA_LENGTH = 256;
|
2004-11-16 09:08:31 -05:00
|
|
|
|
2004-11-12 08:23:20 -05:00
|
|
|
private MacOSXFrame frame;
|
2004-11-11 11:03:19 -05:00
|
|
|
private MouseEventQueue mouse_queue;
|
|
|
|
private KeyboardEventQueue keyboard_queue;
|
|
|
|
private java.awt.DisplayMode requested_mode;
|
2004-11-12 08:23:20 -05:00
|
|
|
|
|
|
|
/* States */
|
|
|
|
private boolean close_requested;
|
2004-11-25 17:31:38 -05:00
|
|
|
|
|
|
|
MacOSXDisplay() {
|
2004-11-12 05:39:06 -05:00
|
|
|
new MacOSXApplicationListener();
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2004-11-11 11:03:19 -05:00
|
|
|
public void createWindow(DisplayMode mode, boolean fullscreen, int x, int y) throws LWJGLException {
|
2004-11-16 08:21:46 -05:00
|
|
|
hideUI(fullscreen);
|
2004-11-11 11:03:19 -05:00
|
|
|
close_requested = false;
|
2004-11-12 08:23:20 -05:00
|
|
|
try {
|
|
|
|
frame = new MacOSXFrame(mode, requested_mode, fullscreen, x, y);
|
|
|
|
} catch (LWJGLException e) {
|
|
|
|
destroyWindow();
|
|
|
|
throw e;
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleQuit() {
|
|
|
|
synchronized (this) {
|
|
|
|
close_requested = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void destroyWindow() {
|
2004-11-19 10:18:29 -05:00
|
|
|
if (frame != null) {
|
2005-01-21 17:07:20 -05:00
|
|
|
if (MacOSXFrame.getDevice().getFullScreenWindow() == frame)
|
|
|
|
MacOSXFrame.getDevice().setFullScreenWindow(null);
|
2005-02-23 06:11:08 -05:00
|
|
|
// setView(null);
|
2005-01-21 17:07:20 -05:00
|
|
|
if (frame.isDisplayable())
|
|
|
|
frame.dispose();
|
2004-11-19 10:18:29 -05:00
|
|
|
frame = null;
|
|
|
|
}
|
2004-11-16 08:21:46 -05:00
|
|
|
hideUI(false);
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2004-11-12 05:48:51 -05:00
|
|
|
public int getGammaRampLength() {
|
2004-11-16 09:08:31 -05:00
|
|
|
return GAMMA_LENGTH;
|
2004-11-12 05:48:51 -05:00
|
|
|
}
|
|
|
|
|
2004-11-16 09:08:31 -05:00
|
|
|
public native void setGammaRamp(FloatBuffer gammaRamp) throws LWJGLException;
|
2004-11-11 11:03:19 -05:00
|
|
|
|
|
|
|
public String getAdapter() {
|
|
|
|
return null;
|
|
|
|
}
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2004-11-11 11:03:19 -05:00
|
|
|
public String getVersion() {
|
|
|
|
return null;
|
|
|
|
}
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2004-11-11 11:03:19 -05:00
|
|
|
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 {
|
2004-11-12 08:23:20 -05:00
|
|
|
java.awt.DisplayMode[] awt_modes = MacOSXFrame.getDevice().getDisplayModes();
|
2004-11-11 11:03:19 -05:00
|
|
|
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");
|
|
|
|
}
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2004-11-11 11:03:19 -05:00
|
|
|
public void resetDisplayMode() {
|
2004-11-12 08:23:20 -05:00
|
|
|
if (MacOSXFrame.getDevice().getFullScreenWindow() != null)
|
|
|
|
MacOSXFrame.getDevice().setFullScreenWindow(null);
|
2004-11-11 11:03:19 -05:00
|
|
|
requested_mode = null;
|
2004-11-16 09:08:31 -05:00
|
|
|
restoreGamma();
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|
2004-11-16 09:08:31 -05:00
|
|
|
|
|
|
|
private native void restoreGamma();
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2004-11-11 11:03:19 -05:00
|
|
|
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);
|
|
|
|
}
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2005-02-20 06:24:22 -05:00
|
|
|
public DisplayMode init() throws LWJGLException {
|
2004-11-12 08:23:20 -05:00
|
|
|
return createLWJGLDisplayMode(MacOSXFrame.getDevice().getDisplayMode());
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2005-02-20 06:24:22 -05:00
|
|
|
public DisplayMode[] getAvailableDisplayModes() throws LWJGLException {
|
2004-11-12 08:23:20 -05:00
|
|
|
java.awt.DisplayMode[] awt_modes = MacOSXFrame.getDevice().getDisplayModes();
|
2004-11-11 11:03:19 -05:00
|
|
|
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;
|
|
|
|
}
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2004-11-11 11:03:19 -05:00
|
|
|
public void setTitle(String title) {
|
2005-01-21 17:07:20 -05:00
|
|
|
frame.setTitle(title);
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2004-11-11 11:03:19 -05:00
|
|
|
public boolean isCloseRequested() {
|
|
|
|
boolean result;
|
|
|
|
synchronized (this) {
|
2005-01-21 19:34:50 -05:00
|
|
|
result = close_requested || (frame != null && frame.syncIsCloseRequested());
|
2004-11-11 11:03:19 -05:00
|
|
|
close_requested = false;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isVisible() {
|
2004-11-12 08:23:20 -05:00
|
|
|
return frame.syncIsVisible();
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2004-11-11 11:03:19 -05:00
|
|
|
public boolean isActive() {
|
2004-11-12 08:23:20 -05:00
|
|
|
return frame.syncIsActive();
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2005-02-23 06:11:08 -05:00
|
|
|
public MacOSXFrame getFrame() {
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
2004-11-11 11:03:19 -05:00
|
|
|
public boolean isDirty() {
|
2004-11-12 08:23:20 -05:00
|
|
|
return frame.getCanvas().syncIsDirty();
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|
|
|
|
|
2005-02-20 06:24:22 -05:00
|
|
|
public PeerInfo createPeerInfo(PixelFormat pixel_format) throws LWJGLException {
|
2005-02-23 06:11:08 -05:00
|
|
|
return new MacOSXDisplayPeerInfo(pixel_format);
|
2005-02-20 06:24:22 -05:00
|
|
|
}
|
2004-11-11 11:03:19 -05:00
|
|
|
|
|
|
|
public void update() {
|
2005-02-23 06:11:08 -05:00
|
|
|
if (frame.getCanvas().syncShouldUpdateContext()) {
|
|
|
|
Display.getContext().update();
|
2004-11-11 11:03:19 -05:00
|
|
|
/* This is necessary to make sure the context won't "forget" about the view size */
|
2004-11-12 08:23:20 -05:00
|
|
|
GL11.glViewport(0, 0, frame.getCanvas().syncGetWidth(), frame.getCanvas().syncGetHeight());
|
2005-02-23 06:11:08 -05:00
|
|
|
}
|
|
|
|
if (frame.syncShouldWarpCursor()) {
|
2004-11-11 11:03:19 -05:00
|
|
|
warpCursor();
|
|
|
|
}
|
|
|
|
}
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2004-11-11 11:03:19 -05:00
|
|
|
private void warpCursor() {
|
|
|
|
if (mouse_queue != null && mouse_queue.isGrabbed()) {
|
2004-11-12 08:23:20 -05:00
|
|
|
Rectangle bounds = frame.syncGetBounds();
|
2004-11-11 11:03:19 -05:00
|
|
|
int x = bounds.x + bounds.width/2;
|
|
|
|
int y = bounds.y + bounds.height/2;
|
|
|
|
nWarpCursor(x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-16 08:21:46 -05:00
|
|
|
/**
|
|
|
|
* This is an interface to the native Carbon call
|
|
|
|
* SetSystemUIMode. It is used to hide the dock in a way
|
|
|
|
* that will prevent AWT from shifting the fullscreen window
|
|
|
|
*/
|
|
|
|
private native void hideUI(boolean hide);
|
|
|
|
|
2004-11-11 11:03:19 -05:00
|
|
|
native void getMouseDeltas(IntBuffer delta_buffer);
|
|
|
|
|
|
|
|
private native void updateContext();
|
|
|
|
|
|
|
|
public void reshape(int x, int y, int width, int height) {
|
2005-01-21 17:07:20 -05:00
|
|
|
frame.resize(x, y, width, height);
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Mouse */
|
|
|
|
public boolean hasWheel() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getButtonCount() {
|
|
|
|
return MouseEventQueue.NUM_BUTTONS;
|
|
|
|
}
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2005-02-20 06:24:22 -05:00
|
|
|
public void createMouse() throws LWJGLException {
|
2004-11-12 08:23:20 -05:00
|
|
|
MacOSXGLCanvas canvas = frame.getCanvas();
|
2004-11-11 11:03:19 -05:00
|
|
|
this.mouse_queue = new MouseEventQueue(canvas.getWidth(), canvas.getHeight());
|
|
|
|
canvas.addMouseListener(mouse_queue);
|
|
|
|
canvas.addMouseMotionListener(mouse_queue);
|
|
|
|
canvas.addMouseWheelListener(mouse_queue);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void destroyMouse() {
|
2004-11-12 08:23:20 -05:00
|
|
|
MacOSXGLCanvas canvas = frame.getCanvas();
|
2004-11-11 11:03:19 -05:00
|
|
|
canvas.removeMouseListener(mouse_queue);
|
|
|
|
canvas.removeMouseWheelListener(mouse_queue);
|
|
|
|
canvas.removeMouseMotionListener(mouse_queue);
|
|
|
|
this.mouse_queue = null;
|
|
|
|
}
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2004-11-11 11:03:19 -05:00
|
|
|
public void pollMouse(IntBuffer coord_buffer, ByteBuffer buttons_buffer) {
|
|
|
|
mouse_queue.poll(coord_buffer, buttons_buffer);
|
|
|
|
}
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2004-11-11 11:03:19 -05:00
|
|
|
public int readMouse(IntBuffer buffer, int buffer_position) {
|
|
|
|
assert buffer_position == buffer.position();
|
|
|
|
return mouse_queue.copyEvents(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void grabMouse(boolean grab) {
|
|
|
|
mouse_queue.setGrabbed(grab);
|
|
|
|
warpCursor();
|
2004-11-15 10:28:53 -05:00
|
|
|
nGrabMouse(grab);
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
private native void nWarpCursor(int x, int y);
|
|
|
|
|
|
|
|
private native void nGrabMouse(boolean grab);
|
|
|
|
|
2005-01-18 07:34:36 -05:00
|
|
|
public int getNativeCursorCapabilities() {
|
2004-11-15 09:38:00 -05:00
|
|
|
/*
|
2004-11-11 11:03:19 -05:00
|
|
|
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;
|
2004-11-15 09:38:00 -05:00
|
|
|
*/
|
|
|
|
/* Return no capability, as there are two unsolved bugs (both reported to apple along with
|
|
|
|
minimal test case):
|
|
|
|
1. When a custom cursor (or some standard) java.awt.Cursor is assigned to a
|
|
|
|
Componennt, it is reset to the default pointer cursor when the window is de-
|
|
|
|
activated and the re-activated. The Cursor can not be reset to the custom cursor,
|
|
|
|
with another setCursor.
|
2004-11-25 17:31:38 -05:00
|
|
|
2. When the cursor is moving in the top pixel row (y = 0 in AWT coordinates) in fullscreen
|
2004-11-15 09:38:00 -05:00
|
|
|
mode, no mouse moved events are reported, even though mouse pressed/released and dragged
|
2004-11-15 10:28:53 -05:00
|
|
|
events are reported
|
2004-11-15 09:38:00 -05:00
|
|
|
*/
|
|
|
|
return 0;
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2004-11-11 11:03:19 -05:00
|
|
|
public void setNativeCursor(Object handle) throws LWJGLException {
|
|
|
|
Cursor awt_cursor = (Cursor)handle;
|
2005-01-21 17:07:20 -05:00
|
|
|
frame.setCursor(awt_cursor);
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2004-11-12 08:23:20 -05:00
|
|
|
MacOSXGLCanvas canvas = frame.getCanvas();
|
2004-11-11 11:03:19 -05:00
|
|
|
this.keyboard_queue = new KeyboardEventQueue();
|
|
|
|
canvas.addKeyListener(keyboard_queue);
|
|
|
|
}
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2004-11-11 11:03:19 -05:00
|
|
|
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
|
|
|
|
*/
|
2004-11-12 08:23:20 -05:00
|
|
|
// frame.getCanvas().removeKeyListener(keyboard_queue);
|
2004-11-11 11:03:19 -05:00
|
|
|
|
|
|
|
this.keyboard_queue = null;
|
|
|
|
}
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2004-11-11 11:03:19 -05:00
|
|
|
public void pollKeyboard(ByteBuffer keyDownBuffer) {
|
|
|
|
keyboard_queue.poll(keyDownBuffer);
|
|
|
|
}
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2004-11-11 11:03:19 -05:00
|
|
|
public int readKeyboard(IntBuffer buffer, int buffer_position) {
|
|
|
|
assert buffer_position == buffer.position();
|
|
|
|
return keyboard_queue.copyEvents(buffer);
|
|
|
|
}
|
|
|
|
|
2004-11-12 05:48:51 -05:00
|
|
|
public int isStateKeySet(int key) {
|
|
|
|
return Keyboard.STATE_UNKNOWN;
|
|
|
|
}
|
2004-11-11 11:03:19 -05:00
|
|
|
|
|
|
|
/** 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) {
|
|
|
|
}
|
2004-11-12 05:39:06 -05:00
|
|
|
|
2005-01-18 07:34:36 -05:00
|
|
|
public int getPbufferCapabilities() {
|
2004-11-18 07:10:28 -05:00
|
|
|
return GL11.glGetString(GL11.GL_EXTENSIONS).indexOf("GL_APPLE_pixel_buffer") != -1 ? Pbuffer.PBUFFER_SUPPORTED : 0;
|
|
|
|
}
|
|
|
|
|
2004-11-12 05:39:06 -05:00
|
|
|
/**
|
|
|
|
* This class captures com.apple.eawt.ApplicationEvents through reflection
|
|
|
|
* to enable compilation on other platforms than Mac OS X
|
|
|
|
*/
|
|
|
|
private class MacOSXApplicationListener implements InvocationHandler {
|
|
|
|
private final Method handleQuit;
|
|
|
|
|
|
|
|
public MacOSXApplicationListener() {
|
|
|
|
try {
|
|
|
|
/* Get the com.apple.eawt.Application class */
|
|
|
|
Class com_apple_eawt_Application = Class.forName("com.apple.eawt.Application");
|
|
|
|
/* Call the static Application.getApplication() method */
|
|
|
|
Object application = com_apple_eawt_Application.getMethod("getApplication", null).invoke(null, null);
|
|
|
|
/* Create a proxy implementing com.apple.eawt.ApplicationListener */
|
|
|
|
Class com_apple_eawt_ApplicationListener = Class.forName("com.apple.eawt.ApplicationListener");
|
|
|
|
Object listener_proxy = Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] {com_apple_eawt_ApplicationListener}, this);
|
|
|
|
/* Invoke the method application.addApplicationListener(proxy) */
|
|
|
|
Method addApplicationListener = com_apple_eawt_Application.getMethod("addApplicationListener", new Class[]{com_apple_eawt_ApplicationListener});
|
|
|
|
addApplicationListener.invoke(application, new Object[]{listener_proxy});
|
|
|
|
/* Finally, get the handleQuit method we want to react to */
|
|
|
|
Class com_apple_eawt_ApplicationEvent = Class.forName("com.apple.eawt.ApplicationEvent");
|
|
|
|
handleQuit = com_apple_eawt_ApplicationListener.getMethod("handleQuit", new Class[]{com_apple_eawt_ApplicationEvent});
|
|
|
|
} catch (InvocationTargetException e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
} catch (NoSuchMethodException e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
} catch (ClassNotFoundException e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
} catch (IllegalAccessException e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Object invoke(Object proxy, Method method, Object[] args) {
|
|
|
|
if (method.equals(handleQuit))
|
|
|
|
handleQuit();
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2005-01-11 08:53:12 -05:00
|
|
|
|
2005-02-20 06:24:22 -05:00
|
|
|
public boolean isBufferLost(PeerInfo handle) {
|
2005-01-11 08:53:12 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-02-20 06:24:22 -05:00
|
|
|
public PeerInfo createPbuffer(int width, int height, PixelFormat pixel_format,
|
|
|
|
IntBuffer pixelFormatCaps,
|
|
|
|
IntBuffer pBufferAttribs) throws LWJGLException {
|
2005-02-23 06:11:08 -05:00
|
|
|
return new MacOSXPbufferPeerInfo(width, height, pixel_format);
|
2005-02-20 06:24:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setPbufferAttrib(PeerInfo handle, int attrib, int value) {
|
2005-01-11 08:53:12 -05:00
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
|
2005-02-20 06:24:22 -05:00
|
|
|
public void bindTexImageToPbuffer(PeerInfo handle, int buffer) {
|
2005-01-11 08:53:12 -05:00
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
|
2005-02-20 06:24:22 -05:00
|
|
|
public void releaseTexImageFromPbuffer(PeerInfo handle, int buffer) {
|
2005-01-11 08:53:12 -05:00
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|