2004-11-25 17:31:38 -05:00
|
|
|
/*
|
2008-04-07 14:36:09 -04:00
|
|
|
* Copyright (c) 2002-2008 LWJGL Project
|
2004-11-11 11:03:19 -05:00
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2008-04-06 16:56:52 -04:00
|
|
|
import java.awt.Canvas;
|
2008-06-05 09:36:57 -04:00
|
|
|
import java.awt.Cursor;
|
2006-02-27 14:55:43 -05:00
|
|
|
import java.awt.Robot;
|
2004-11-20 11:46:44 -05:00
|
|
|
import java.nio.ByteBuffer;
|
|
|
|
import java.nio.FloatBuffer;
|
|
|
|
import java.nio.IntBuffer;
|
2005-05-30 12:21:05 -04:00
|
|
|
import java.security.AccessController;
|
|
|
|
import java.security.PrivilegedAction;
|
2006-02-27 14:55:43 -05:00
|
|
|
import java.security.PrivilegedExceptionAction;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2005-05-30 12:21:05 -04:00
|
|
|
|
2005-09-09 06:27:13 -04:00
|
|
|
import org.lwjgl.BufferUtils;
|
2004-11-20 11:46:44 -05:00
|
|
|
import org.lwjgl.LWJGLException;
|
2005-03-29 13:09:33 -05:00
|
|
|
import org.lwjgl.LWJGLUtil;
|
2004-11-11 11:03:19 -05:00
|
|
|
|
2008-06-05 09:36:57 -04:00
|
|
|
import com.apple.eawt.Application;
|
|
|
|
import com.apple.eawt.ApplicationAdapter;
|
|
|
|
import com.apple.eawt.ApplicationEvent;
|
2008-04-22 12:52:16 -04: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
|
|
|
|
2008-04-07 09:34:20 -04:00
|
|
|
private MacOSXCanvasListener canvas_listener;
|
2004-11-12 08:23:20 -05:00
|
|
|
private MacOSXFrame frame;
|
2008-04-07 13:10:14 -04:00
|
|
|
private Canvas canvas;
|
2006-10-27 02:04:55 -04:00
|
|
|
private Robot robot;
|
2006-10-26 16:49:07 -04:00
|
|
|
private MacOSXMouseEventQueue mouse_queue;
|
2004-11-11 11:03:19 -05:00
|
|
|
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() {
|
2008-04-22 12:52:16 -04:00
|
|
|
try {
|
|
|
|
AccessController.doPrivileged(new PrivilegedExceptionAction() {
|
|
|
|
public Object run() throws Exception {
|
|
|
|
Application.getApplication().addApplicationListener(new ApplicationAdapter() {
|
|
|
|
public final void handleQuit(ApplicationEvent event) {
|
|
|
|
doHandleQuit();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} catch (Throwable e) {
|
|
|
|
/**
|
|
|
|
* In an applet environment, referencing com.apple.eawt.Application can fail with
|
|
|
|
* a native exception. So log any exceptions instead of re-throwing.
|
|
|
|
*/
|
|
|
|
LWJGLUtil.log("Failed to register quit handler: " + e.getMessage());
|
|
|
|
}
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2008-10-28 06:05:37 -04:00
|
|
|
public void createWindow(DisplayMode mode, Canvas parent, int x, int y) throws LWJGLException {
|
|
|
|
boolean fullscreen = Display.isFullscreen();
|
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 {
|
2008-04-07 13:10:14 -04:00
|
|
|
if (parent == null) {
|
|
|
|
frame = new MacOSXFrame(mode, requested_mode, fullscreen, x, y);
|
|
|
|
canvas = frame.getCanvas();
|
|
|
|
} else {
|
|
|
|
frame = null;
|
|
|
|
canvas = parent;
|
|
|
|
}
|
|
|
|
canvas_listener = new MacOSXCanvasListener(canvas);
|
|
|
|
robot = AWTUtil.createRobot(canvas);
|
2004-11-12 08:23:20 -05:00
|
|
|
} catch (LWJGLException e) {
|
|
|
|
destroyWindow();
|
|
|
|
throw e;
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-22 12:52:16 -04:00
|
|
|
private void doHandleQuit() {
|
2004-11-11 11:03:19 -05:00
|
|
|
synchronized (this) {
|
|
|
|
close_requested = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void destroyWindow() {
|
2008-04-07 09:34:20 -04:00
|
|
|
if (canvas_listener != null) {
|
|
|
|
canvas_listener.disableListeners();
|
|
|
|
canvas_listener = null;
|
|
|
|
}
|
2004-11-19 10:18:29 -05:00
|
|
|
if (frame != null) {
|
2005-05-30 12:21:05 -04:00
|
|
|
AccessController.doPrivileged(new PrivilegedAction() {
|
|
|
|
public Object run() {
|
|
|
|
if (MacOSXFrame.getDevice().getFullScreenWindow() == frame)
|
|
|
|
MacOSXFrame.getDevice().setFullScreenWindow(null);
|
|
|
|
return 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) {
|
2008-04-07 13:10:14 -04:00
|
|
|
if (frame != null)
|
|
|
|
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() {
|
2008-04-07 13:10:14 -04:00
|
|
|
return frame == null || 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() {
|
2008-04-07 13:10:14 -04:00
|
|
|
return canvas.isFocusOwner();
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2008-04-07 13:10:14 -04:00
|
|
|
public Canvas getCanvas() {
|
|
|
|
return canvas;
|
2005-02-23 06:11:08 -05:00
|
|
|
}
|
|
|
|
|
2004-11-11 11:03:19 -05:00
|
|
|
public boolean isDirty() {
|
2008-04-07 13:10:14 -04:00
|
|
|
return frame != null && 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-11-04 07:38:59 -05:00
|
|
|
try {
|
|
|
|
return new MacOSXDisplayPeerInfo(pixel_format, true);
|
|
|
|
} catch (LWJGLException e) {
|
|
|
|
return new MacOSXDisplayPeerInfo(pixel_format, false);
|
|
|
|
}
|
2005-02-20 06:24:22 -05:00
|
|
|
}
|
2004-11-11 11:03:19 -05:00
|
|
|
|
2005-09-09 06:27:13 -04:00
|
|
|
private final static IntBuffer current_viewport = BufferUtils.createIntBuffer(16);
|
2004-11-11 11:03:19 -05:00
|
|
|
public void update() {
|
2008-04-07 09:34:20 -04:00
|
|
|
boolean should_update = canvas_listener.syncShouldUpdateContext();
|
2005-04-28 08:55:23 -04:00
|
|
|
/*
|
|
|
|
* Workaround for the "white screen in fullscreen mode" problem
|
|
|
|
*
|
|
|
|
* Sometimes, switching from windowed mode to fullscreen or simply creating the Display
|
|
|
|
* in fullscreen mode will result in the context not being bound to the window correctly.
|
|
|
|
* The program runs fine, but the canvas background (white) is shown instead of the context
|
|
|
|
* front buffer.
|
|
|
|
*
|
|
|
|
* I've discovered that re-binding the context with another setView() won't fix the problem, while a
|
|
|
|
* clearDrawable() followed by a setView() does work. A straightforward workaround would be
|
|
|
|
* to simply run the combination at every update(). This is not sufficient, since the clearDrawable()
|
|
|
|
* call makes the the background appear shortly, causing visual artifacts.
|
|
|
|
* What we really need is a way to detect that a setView() failed, and then do the magic combo. I've not
|
|
|
|
* been able to find such a detection so alternatively I'm triggering the combo if the display is fullscreen
|
|
|
|
* (I've not seen the white screen problem in windowed mode) and if the canvas has gotten a paint message or
|
|
|
|
* if its update flag was set.
|
|
|
|
*
|
|
|
|
* My testing seems to indicate that the workaround works, since I've not seen the problem after the fix.
|
|
|
|
*
|
|
|
|
* - elias
|
|
|
|
*/
|
2008-04-07 13:10:14 -04:00
|
|
|
if (Display.isFullscreen() && (frame != null && frame.getCanvas().syncCanvasPainted() || should_update)) {
|
2005-04-28 08:55:23 -04:00
|
|
|
try {
|
2007-02-12 07:18:26 -05:00
|
|
|
MacOSXContextImplementation.resetView(Display.getDrawable().getContext().getPeerInfo(), Display.getDrawable().getContext());
|
2005-04-28 08:55:23 -04:00
|
|
|
} catch (LWJGLException e) {
|
|
|
|
LWJGLUtil.log("Failed to reset context: " + e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (should_update) {
|
2007-02-12 07:18:26 -05:00
|
|
|
Display.getDrawable().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 */
|
2005-09-09 06:27:13 -04:00
|
|
|
GL11.glGetInteger(GL11.GL_VIEWPORT, current_viewport);
|
|
|
|
GL11.glViewport(current_viewport.get(0), current_viewport.get(1), current_viewport.get(2), current_viewport.get(3));
|
2005-02-23 06:11:08 -05:00
|
|
|
}
|
2008-09-11 05:52:23 -04:00
|
|
|
if (frame != null && mouse_queue != null) {
|
|
|
|
if (frame.syncShouldReleaseCursor())
|
|
|
|
MacOSXMouseEventQueue.nGrabMouse(false);
|
|
|
|
if (frame.syncShouldWarpCursor())
|
|
|
|
mouse_queue.warpCursor();
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
2005-05-03 05:08:12 -04:00
|
|
|
*
|
|
|
|
* The workaround is not necessary on 10.4, and since 10.4 shows
|
|
|
|
* instability problems calling SetSystemUIMode, we'll only call it
|
|
|
|
* when the OS version is 10.3 or lower.
|
2004-11-16 08:21:46 -05:00
|
|
|
*/
|
2005-05-03 05:08:12 -04:00
|
|
|
private void hideUI(boolean hide) {
|
2006-01-16 15:37:28 -05:00
|
|
|
if (!LWJGLUtil.isMacOSXEqualsOrBetterThan(10, 4))
|
2005-05-05 07:04:17 -04:00
|
|
|
nHideUI(hide);
|
|
|
|
}
|
|
|
|
|
2005-05-03 05:08:12 -04:00
|
|
|
private native void nHideUI(boolean hide);
|
2004-11-16 08:21:46 -05:00
|
|
|
|
2004-11-11 11:03:19 -05:00
|
|
|
public void reshape(int x, int y, int width, int height) {
|
2008-04-07 13:10:14 -04:00
|
|
|
if (frame != null)
|
|
|
|
frame.resize(x, y, width, height);
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Mouse */
|
|
|
|
public boolean hasWheel() {
|
2006-10-26 10:47:02 -04:00
|
|
|
return AWTUtil.hasWheel();
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getButtonCount() {
|
2006-10-26 10:47:02 -04:00
|
|
|
return AWTUtil.getButtonCount();
|
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 void createMouse() throws LWJGLException {
|
2006-10-26 16:19:40 -04:00
|
|
|
this.mouse_queue = new MacOSXMouseEventQueue(canvas);
|
2006-10-26 11:03:47 -04:00
|
|
|
mouse_queue.register();
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public void destroyMouse() {
|
2006-11-19 16:41:34 -05:00
|
|
|
if (mouse_queue != null) {
|
2008-04-30 09:16:53 -04:00
|
|
|
MacOSXMouseEventQueue.nGrabMouse(false);
|
2006-10-26 11:03:47 -04:00
|
|
|
mouse_queue.unregister();
|
2006-11-19 16:41:34 -05:00
|
|
|
}
|
2004-11-11 11:03:19 -05:00
|
|
|
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
|
|
|
|
2006-07-03 19:16:26 -04:00
|
|
|
public void readMouse(ByteBuffer buffer) {
|
2006-07-03 15:09:47 -04:00
|
|
|
mouse_queue.copyEvents(buffer);
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public void grabMouse(boolean grab) {
|
|
|
|
mouse_queue.setGrabbed(grab);
|
|
|
|
}
|
|
|
|
|
2005-01-18 07:34:36 -05:00
|
|
|
public int getNativeCursorCapabilities() {
|
2006-10-26 10:47:02 -04:00
|
|
|
return AWTUtil.getNativeCursorCapabilities();
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2005-04-12 07:45:06 -04:00
|
|
|
public void setCursorPosition(int x, int y) {
|
2008-04-07 13:10:14 -04:00
|
|
|
AWTUtil.setCursorPosition(canvas, robot, x, y);
|
2005-04-12 07:45:06 -04:00
|
|
|
}
|
|
|
|
|
2004-11-11 11:03:19 -05:00
|
|
|
public void setNativeCursor(Object handle) throws LWJGLException {
|
|
|
|
Cursor awt_cursor = (Cursor)handle;
|
2008-04-07 13:10:14 -04:00
|
|
|
if (frame != null)
|
|
|
|
frame.setCursor(awt_cursor);
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getMinCursorSize() {
|
2006-10-26 10:47:02 -04:00
|
|
|
return AWTUtil.getMinCursorSize();
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getMaxCursorSize() {
|
2006-10-26 10:47:02 -04:00
|
|
|
return AWTUtil.getMaxCursorSize();
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Keyboard */
|
|
|
|
public void createKeyboard() throws LWJGLException {
|
2006-10-26 11:03:47 -04:00
|
|
|
this.keyboard_queue = new KeyboardEventQueue(canvas);
|
|
|
|
keyboard_queue.register();
|
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 destroyKeyboard() {
|
2006-10-26 11:03:47 -04:00
|
|
|
if (keyboard_queue != null)
|
|
|
|
keyboard_queue.unregister();
|
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
|
|
|
|
2006-07-03 19:16:26 -04:00
|
|
|
public void readKeyboard(ByteBuffer buffer) {
|
2006-07-03 15:09:47 -04:00
|
|
|
keyboard_queue.copyEvents(buffer);
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|
|
|
|
|
2006-06-10 16:42:26 -04:00
|
|
|
/* public int isStateKeySet(int key) {
|
2006-06-10 15:40:54 -04:00
|
|
|
int awt_key;
|
|
|
|
switch (key) {
|
|
|
|
case Keyboard.KEY_CAPITAL:
|
|
|
|
awt_key = KeyEvent.VK_CAPS_LOCK;
|
|
|
|
break;
|
|
|
|
case Keyboard.KEY_NUMLOCK:
|
|
|
|
awt_key = KeyEvent.VK_NUM_LOCK;
|
|
|
|
break;
|
|
|
|
case Keyboard.KEY_SYSRQ:
|
|
|
|
awt_key = KeyEvent.VK_SCROLL_LOCK;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return Keyboard.STATE_UNKNOWN;
|
|
|
|
}
|
2006-06-10 15:46:28 -04:00
|
|
|
try {
|
|
|
|
boolean state = Toolkit.getDefaultToolkit().getLockingKeyState(awt_key);
|
|
|
|
return state ? Keyboard.STATE_ON : Keyboard.STATE_OFF;
|
|
|
|
} catch (Exception e) {
|
|
|
|
LWJGLUtil.log("Failed to query key state: " + e);
|
|
|
|
return Keyboard.STATE_UNKNOWN;
|
|
|
|
}
|
2004-11-12 05:48:51 -05:00
|
|
|
}
|
2006-06-10 16:42:26 -04:00
|
|
|
*/
|
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 {
|
2006-10-26 10:47:02 -04:00
|
|
|
return AWTUtil.createCursor(width, height, xHotspot, yHotspot, numImages, images, delays);
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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() {
|
2006-01-16 15:37:28 -05:00
|
|
|
if (LWJGLUtil.isMacOSXEqualsOrBetterThan(10, 3))
|
2005-05-05 07:04:17 -04:00
|
|
|
return Pbuffer.PBUFFER_SUPPORTED;
|
|
|
|
else
|
|
|
|
return 0;
|
2004-11-18 07:10:28 -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();
|
|
|
|
}
|
2005-07-05 17:54:12 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets one or more icons for the Display.
|
|
|
|
* <ul>
|
|
|
|
* <li>On Windows you should supply at least one 16x16 icon and one 32x32.</li>
|
|
|
|
* <li>Linux (and similar platforms) expect one 32x32 icon.</li>
|
|
|
|
* <li>Mac OS X should be supplied one 128x128 icon</li>
|
|
|
|
* </ul>
|
|
|
|
* The implementation will use the supplied ByteBuffers with image data in RGBA and perform any conversions nescesarry for the specific platform.
|
|
|
|
*
|
|
|
|
* @param icons Array of icons in RGBA mode
|
|
|
|
* @return number of icons used.
|
|
|
|
*/
|
|
|
|
public int setIcon(ByteBuffer[] icons) {
|
2007-07-20 17:24:03 -04:00
|
|
|
/* int size = 0;
|
2005-07-05 17:54:12 -04:00
|
|
|
int biggest = -1;
|
|
|
|
|
|
|
|
for (int i=0;i<icons.length;i++) {
|
2005-10-31 05:51:54 -05:00
|
|
|
if (icons[i].remaining() > size) {
|
2005-07-05 17:54:12 -04:00
|
|
|
biggest = i;
|
2005-10-31 05:51:54 -05:00
|
|
|
size = icons[i].remaining();
|
2005-07-05 17:54:12 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (biggest == -1) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
|
2005-10-31 05:51:54 -05:00
|
|
|
IntBuffer biggest_icon = icons[biggest].asIntBuffer();
|
|
|
|
int[] imageData = new int[biggest_icon.remaining()];
|
|
|
|
width = height = (int) Math.sqrt(imageData.length);
|
|
|
|
biggest_icon.get(imageData);
|
2005-07-05 17:54:12 -04:00
|
|
|
|
|
|
|
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
|
|
|
img.setRGB(0, 0, width, height, imageData, 0, width);
|
|
|
|
frame.setIconImage(img);
|
|
|
|
|
2007-07-20 17:24:03 -04:00
|
|
|
return 1;*/
|
|
|
|
// Don't use any icon, since Mac OS X windows don't have window icons
|
|
|
|
return 0;
|
2005-07-05 17:54:12 -04:00
|
|
|
}
|
2006-10-26 16:19:40 -04:00
|
|
|
|
|
|
|
public int getWidth() {
|
|
|
|
return Display.getDisplayMode().getWidth();
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getHeight() {
|
|
|
|
return Display.getDisplayMode().getHeight();
|
|
|
|
}
|
2009-09-12 18:15:21 -04:00
|
|
|
|
|
|
|
public boolean isInsideWindow() {
|
|
|
|
return true;
|
|
|
|
}
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|