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
|
2012-11-22 17:43:43 -05:00
|
|
|
* for each supported platform.
|
2004-11-11 11:03:19 -05:00
|
|
|
* @author elias_naur
|
|
|
|
*/
|
|
|
|
|
2008-04-06 16:56:52 -04:00
|
|
|
import java.awt.Canvas;
|
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
|
|
|
|
2013-02-01 20:15:41 -05:00
|
|
|
import org.lwjgl.input.Cursor;
|
2005-09-09 06:27:13 -04:00
|
|
|
import org.lwjgl.BufferUtils;
|
2012-11-01 16:54:17 -04:00
|
|
|
import org.lwjgl.MemoryUtil;
|
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
|
|
|
|
2010-09-28 17:11:35 -04:00
|
|
|
import static org.lwjgl.opengl.GL11.*;
|
|
|
|
|
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
|
|
|
|
2013-01-16 14:02:09 -05:00
|
|
|
//private MacOSXCanvasListener canvas_listener;
|
2008-04-07 13:10:14 -04:00
|
|
|
private Canvas canvas;
|
2006-10-27 02:04:55 -04:00
|
|
|
private Robot robot;
|
2013-01-14 18:35:46 -05:00
|
|
|
private MacOSXMouseEventQueue mouse_queue;
|
2004-11-11 11:03:19 -05:00
|
|
|
private KeyboardEventQueue keyboard_queue;
|
2013-02-08 18:29:15 -05:00
|
|
|
private DisplayMode requested_mode;
|
2012-12-25 09:14:05 -05:00
|
|
|
|
|
|
|
/* Members for native window use */
|
|
|
|
private MacOSXNativeMouse mouse;
|
|
|
|
private MacOSXNativeKeyboard keyboard;
|
|
|
|
private ByteBuffer window;
|
|
|
|
private ByteBuffer context;
|
|
|
|
|
|
|
|
private boolean skipViewportValue = false;
|
|
|
|
private static final IntBuffer current_viewport = BufferUtils.createIntBuffer(16);
|
|
|
|
|
2013-01-27 18:01:21 -05:00
|
|
|
private boolean mouseInsideWindow;
|
|
|
|
|
2012-12-25 09:14:05 -05:00
|
|
|
private boolean close_requested;
|
2013-01-13 10:34:24 -05:00
|
|
|
|
|
|
|
private boolean native_mode = true;
|
2013-01-27 18:45:08 -05:00
|
|
|
|
|
|
|
private boolean updateNativeCursor = false;
|
|
|
|
|
|
|
|
private long currentNativeCursor = 0;
|
2004-11-25 17:31:38 -05:00
|
|
|
|
|
|
|
MacOSXDisplay() {
|
2012-11-13 16:13:11 -05:00
|
|
|
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2012-12-03 18:04:30 -05:00
|
|
|
private native ByteBuffer nCreateWindow(int x, int y, int width, int height, boolean fullscreen, boolean undecorated, boolean resizable, boolean parented, ByteBuffer peer_info_handle, ByteBuffer window_handle) throws LWJGLException;
|
2012-11-01 16:54:17 -04:00
|
|
|
|
2013-02-08 18:29:15 -05:00
|
|
|
private native Object nGetCurrentDisplayMode();
|
|
|
|
|
|
|
|
private native void nGetDisplayModes(Object modesList);
|
|
|
|
|
2012-11-01 16:54:17 -04:00
|
|
|
private native boolean nIsMiniaturized(ByteBuffer window_handle);
|
|
|
|
|
|
|
|
private native boolean nIsFocused(ByteBuffer window_handle);
|
|
|
|
|
|
|
|
private native void nSetResizable(ByteBuffer window_handle, boolean resizable);
|
|
|
|
|
|
|
|
private native void nResizeWindow(ByteBuffer window_handle, int x, int y, int width, int height);
|
|
|
|
|
|
|
|
private native boolean nWasResized(ByteBuffer window_handle);
|
2012-11-11 13:43:14 -05:00
|
|
|
|
2012-12-16 11:02:40 -05:00
|
|
|
private native int nGetX(ByteBuffer window_handle);
|
|
|
|
|
|
|
|
private native int nGetY(ByteBuffer window_handle);
|
|
|
|
|
2012-11-11 13:43:14 -05:00
|
|
|
private native int nGetWidth(ByteBuffer window_handle);
|
|
|
|
|
|
|
|
private native int nGetHeight(ByteBuffer window_handle);
|
2013-01-15 18:09:03 -05:00
|
|
|
|
|
|
|
private native boolean nIsNativeMode(ByteBuffer peer_info_handle);
|
2012-11-01 16:54:17 -04:00
|
|
|
|
|
|
|
private static boolean isUndecorated() {
|
|
|
|
return Display.getPrivilegedBoolean("org.lwjgl.opengl.Window.undecorated");
|
|
|
|
}
|
|
|
|
|
2012-12-09 11:27:19 -05:00
|
|
|
public void createWindow(final DrawableLWJGL drawable, DisplayMode mode, Canvas parent, int x, int y) throws LWJGLException {
|
2008-10-28 06:05:37 -04:00
|
|
|
boolean fullscreen = Display.isFullscreen();
|
2012-11-25 10:07:20 -05:00
|
|
|
boolean resizable = Display.isResizable();
|
2012-12-18 17:10:44 -05:00
|
|
|
boolean parented = (parent != null) && !fullscreen;
|
2012-11-25 10:07:20 -05:00
|
|
|
|
2012-12-22 15:20:48 -05:00
|
|
|
if (parented) this.canvas = parent;
|
|
|
|
else this.canvas = null;
|
|
|
|
|
2004-11-11 11:03:19 -05:00
|
|
|
close_requested = false;
|
2012-12-25 09:14:05 -05:00
|
|
|
|
|
|
|
DrawableGL gl_drawable = (DrawableGL)Display.getDrawable();
|
|
|
|
PeerInfo peer_info = gl_drawable.peer_info;
|
2012-11-01 16:54:17 -04:00
|
|
|
ByteBuffer peer_handle = peer_info.lockAndGetHandle();
|
2004-11-12 08:23:20 -05:00
|
|
|
try {
|
2012-12-25 09:14:05 -05:00
|
|
|
window = nCreateWindow(x, y, mode.getWidth(), mode.getHeight(),
|
|
|
|
fullscreen, isUndecorated(), resizable,
|
|
|
|
parented, peer_handle, window);
|
2012-12-22 15:20:48 -05:00
|
|
|
|
2012-12-09 11:27:19 -05:00
|
|
|
|
2012-12-25 09:14:05 -05:00
|
|
|
if (fullscreen) {
|
|
|
|
// when going to fullscreen viewport is set to screen size by Cocoa, ignore this value
|
|
|
|
skipViewportValue = true;
|
|
|
|
// if starting in fullscreen then set initial viewport to displaymode size
|
|
|
|
if (current_viewport.get(2) == 0 && current_viewport.get(3) == 0) {
|
|
|
|
current_viewport.put(2, mode.getWidth());
|
|
|
|
current_viewport.put(3, mode.getHeight());
|
|
|
|
}
|
|
|
|
}
|
2013-01-15 18:09:03 -05:00
|
|
|
|
|
|
|
native_mode = nIsNativeMode(peer_handle);
|
|
|
|
|
2013-01-16 14:02:09 -05:00
|
|
|
if (!native_mode) {
|
|
|
|
robot = AWTUtil.createRobot(canvas);
|
|
|
|
}
|
|
|
|
|
2004-11-12 08:23:20 -05:00
|
|
|
} catch (LWJGLException e) {
|
|
|
|
destroyWindow();
|
|
|
|
throw e;
|
2012-12-25 09:14:05 -05:00
|
|
|
} finally {
|
|
|
|
peer_info.unlock();
|
|
|
|
}
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|
|
|
|
|
2012-11-01 16:54:17 -04:00
|
|
|
public void doHandleQuit() {
|
2004-11-11 11:03:19 -05:00
|
|
|
synchronized (this) {
|
|
|
|
close_requested = true;
|
|
|
|
}
|
|
|
|
}
|
2013-01-27 18:01:21 -05:00
|
|
|
|
|
|
|
public void mouseInsideWindow() {
|
|
|
|
synchronized (this) {
|
|
|
|
mouseInsideWindow = true;
|
|
|
|
}
|
2013-01-27 18:45:08 -05:00
|
|
|
updateNativeCursor = true;
|
2013-01-27 18:01:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public void mouseOutsideWindow() {
|
|
|
|
synchronized (this) {
|
|
|
|
mouseInsideWindow = false;
|
|
|
|
}
|
2013-01-27 18:45:08 -05:00
|
|
|
|
|
|
|
updateNativeCursor = true;
|
2013-01-27 18:01:21 -05:00
|
|
|
}
|
2004-11-11 11:03:19 -05:00
|
|
|
|
2013-01-14 18:35:46 -05:00
|
|
|
public native void nDestroyCALayer(ByteBuffer peer_info_handle);
|
|
|
|
|
2012-11-01 16:54:17 -04:00
|
|
|
public native void nDestroyWindow(ByteBuffer window_handle);
|
|
|
|
|
2004-11-11 11:03:19 -05:00
|
|
|
public void destroyWindow() {
|
2013-01-14 18:35:46 -05:00
|
|
|
|
|
|
|
if (!native_mode) {
|
|
|
|
DrawableGL gl_drawable = (DrawableGL)Display.getDrawable();
|
|
|
|
PeerInfo peer_info = gl_drawable.peer_info;
|
|
|
|
if (peer_info != null) {
|
|
|
|
ByteBuffer peer_handle = peer_info.getHandle();
|
|
|
|
nDestroyCALayer(peer_handle);
|
|
|
|
}
|
2013-01-16 14:02:09 -05:00
|
|
|
robot = null;
|
2013-01-14 18:35:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
nDestroyWindow(window);
|
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;
|
|
|
|
}
|
2013-02-08 18:29:15 -05:00
|
|
|
|
|
|
|
private static boolean equals(DisplayMode mode1, DisplayMode mode2) {
|
|
|
|
return mode1.getWidth() == mode2.getWidth() && mode1.getHeight() == mode2.getHeight()
|
|
|
|
&& mode1.getBitsPerPixel() == mode2.getBitsPerPixel() && mode1.getFrequency() == mode2.getFrequency();
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public void switchDisplayMode(DisplayMode mode) throws LWJGLException {
|
2013-02-08 18:29:15 -05:00
|
|
|
DisplayMode[] modes = getAvailableDisplayModes();
|
|
|
|
|
|
|
|
for (DisplayMode available_mode : modes) {
|
|
|
|
if (equals(available_mode, mode)) {
|
|
|
|
requested_mode = available_mode;
|
2004-11-11 11:03:19 -05:00
|
|
|
return;
|
|
|
|
}
|
2010-09-28 17:11:35 -04:00
|
|
|
}
|
2013-02-08 18:29:15 -05:00
|
|
|
|
2004-11-11 11:03:19 -05:00
|
|
|
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() {
|
2012-11-13 16:13:11 -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
|
|
|
|
2013-02-08 18:29:15 -05:00
|
|
|
public Object createDisplayMode(int width, int height, int bitsPerPixel, int refreshRate) {
|
|
|
|
return new DisplayMode(width, height, bitsPerPixel, refreshRate);
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|
2013-02-08 18:29:15 -05:00
|
|
|
|
2005-02-20 06:24:22 -05:00
|
|
|
public DisplayMode init() throws LWJGLException {
|
2013-02-08 18:29:15 -05:00
|
|
|
java.awt.Toolkit.getDefaultToolkit(); // force start AWT Application loop
|
|
|
|
return (DisplayMode) nGetCurrentDisplayMode();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addDisplayMode(Object modesList, int width, int height, int bitsPerPixel, int refreshRate) {
|
|
|
|
List<DisplayMode> modes = (List<DisplayMode>) modesList;
|
|
|
|
DisplayMode displayMode = new DisplayMode(width, height, bitsPerPixel, refreshRate);
|
|
|
|
modes.add(displayMode);
|
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 {
|
2010-09-28 17:11:35 -04:00
|
|
|
List<DisplayMode> modes = new ArrayList<DisplayMode>();
|
2013-02-08 18:29:15 -05:00
|
|
|
nGetDisplayModes(modes); // will populate the above list
|
2010-09-28 17:11:35 -04:00
|
|
|
return modes.toArray(new DisplayMode[modes.size()]);
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2012-11-01 16:54:17 -04:00
|
|
|
private native void nSetTitle(ByteBuffer window_handle, ByteBuffer title_buffer);
|
|
|
|
|
2004-11-11 11:03:19 -05:00
|
|
|
public void setTitle(String title) {
|
2012-11-01 16:54:17 -04:00
|
|
|
ByteBuffer buffer = MemoryUtil.encodeUTF8(title);
|
|
|
|
nSetTitle(window, buffer);
|
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) {
|
2012-11-01 16:54:17 -04:00
|
|
|
result = close_requested;
|
2004-11-11 11:03:19 -05:00
|
|
|
close_requested = false;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isVisible() {
|
2012-11-01 16:54:17 -04:00
|
|
|
return true;
|
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() {
|
2013-01-14 18:35:46 -05:00
|
|
|
if (native_mode) {
|
|
|
|
return nIsFocused(window);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return Display.getParent().hasFocus();
|
|
|
|
}
|
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() {
|
2012-11-01 16:54:17 -04:00
|
|
|
return false;
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|
|
|
|
|
2011-09-03 14:52:45 -04:00
|
|
|
public PeerInfo createPeerInfo(PixelFormat pixel_format, ContextAttribs attribs) throws LWJGLException {
|
2005-11-04 07:38:59 -05:00
|
|
|
try {
|
2011-09-03 14:52:45 -04:00
|
|
|
return new MacOSXDisplayPeerInfo(pixel_format, attribs, true);
|
2005-11-04 07:38:59 -05:00
|
|
|
} catch (LWJGLException e) {
|
2011-09-03 14:52:45 -04:00
|
|
|
return new MacOSXDisplayPeerInfo(pixel_format, attribs, false);
|
2005-11-04 07:38:59 -05:00
|
|
|
}
|
2005-02-20 06:24:22 -05:00
|
|
|
}
|
2004-11-11 11:03:19 -05:00
|
|
|
|
|
|
|
public void update() {
|
2012-11-01 16:54:17 -04:00
|
|
|
boolean should_update = true;
|
2012-12-25 09:14:05 -05:00
|
|
|
|
2011-05-17 12:53:57 -04:00
|
|
|
DrawableGL drawable = (DrawableGL)Display.getDrawable();
|
2005-04-28 08:55:23 -04:00
|
|
|
if (should_update) {
|
2010-04-22 19:21:48 -04:00
|
|
|
drawable.context.update();
|
2004-11-11 11:03:19 -05:00
|
|
|
/* This is necessary to make sure the context won't "forget" about the view size */
|
2012-12-09 11:27:19 -05:00
|
|
|
if (skipViewportValue) skipViewportValue = false;
|
|
|
|
else glGetInteger(GL_VIEWPORT, current_viewport);
|
2010-09-28 17:11:35 -04:00
|
|
|
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
|
|
|
}
|
2013-01-27 18:45:08 -05:00
|
|
|
|
|
|
|
if (native_mode && updateNativeCursor) {
|
|
|
|
updateNativeCursor = false;
|
|
|
|
try {
|
|
|
|
if (mouseInsideWindow) {
|
|
|
|
setNativeCursor(currentNativeCursor);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// restore default cursor if outside Display
|
|
|
|
MacOSXNativeMouse.setCursor(0);
|
|
|
|
}
|
|
|
|
} catch (LWJGLException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public void reshape(int x, int y, int width, int height) {
|
2012-11-01 16:54:17 -04:00
|
|
|
//if (native_mode) {
|
|
|
|
// nResizeWindow(window, 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 {
|
2013-01-14 18:35:46 -05:00
|
|
|
if (native_mode) {
|
|
|
|
mouse = new MacOSXNativeMouse(this, window);
|
|
|
|
mouse.register();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.mouse_queue = new MacOSXMouseEventQueue(canvas);
|
|
|
|
mouse_queue.register();
|
|
|
|
}
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public void destroyMouse() {
|
2013-01-14 18:35:46 -05:00
|
|
|
if (native_mode) {
|
2013-02-03 11:52:45 -05:00
|
|
|
// restore default native cursor
|
|
|
|
try {
|
|
|
|
MacOSXNativeMouse.setCursor(0);
|
|
|
|
} catch (LWJGLException e) {};
|
|
|
|
|
2013-01-14 18:35:46 -05:00
|
|
|
if (mouse != null) {
|
|
|
|
mouse.unregister();
|
|
|
|
}
|
|
|
|
mouse = null;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (mouse_queue != null) {
|
|
|
|
MacOSXMouseEventQueue.nGrabMouse(false);
|
|
|
|
mouse_queue.unregister();
|
|
|
|
}
|
|
|
|
this.mouse_queue = null;
|
|
|
|
}
|
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 pollMouse(IntBuffer coord_buffer, ByteBuffer buttons_buffer) {
|
2013-01-14 18:35:46 -05:00
|
|
|
if (native_mode) {
|
|
|
|
mouse.poll(coord_buffer, buttons_buffer);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mouse_queue.poll(coord_buffer, buttons_buffer);
|
|
|
|
}
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2006-07-03 19:16:26 -04:00
|
|
|
public void readMouse(ByteBuffer buffer) {
|
2013-01-14 18:35:46 -05:00
|
|
|
if (native_mode) {
|
|
|
|
mouse.copyEvents(buffer);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mouse_queue.copyEvents(buffer);
|
|
|
|
}
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public void grabMouse(boolean grab) {
|
2013-01-14 18:35:46 -05:00
|
|
|
if (native_mode) {
|
|
|
|
mouse.setGrabbed(grab);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mouse_queue.setGrabbed(grab);
|
|
|
|
}
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|
|
|
|
|
2005-01-18 07:34:36 -05:00
|
|
|
public int getNativeCursorCapabilities() {
|
2013-02-01 20:15:41 -05:00
|
|
|
if (native_mode) {
|
2013-02-02 14:58:18 -05:00
|
|
|
return Cursor.CURSOR_ONE_BIT_TRANSPARENCY | Cursor.CURSOR_8_BIT_ALPHA | Cursor.CURSOR_ANIMATION;
|
2013-02-01 20:15:41 -05:00
|
|
|
}
|
|
|
|
|
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) {
|
2013-01-14 18:35:46 -05:00
|
|
|
if (native_mode) {
|
|
|
|
if (mouse != null) {
|
|
|
|
mouse.setCursorPosition(x, y);
|
|
|
|
}
|
|
|
|
}
|
2013-02-03 12:47:09 -05:00
|
|
|
//else {
|
2013-01-14 18:35:46 -05:00
|
|
|
//MacOSXMouseEventQueue.nWarpCursor(x, y);
|
2013-02-03 12:47:09 -05:00
|
|
|
//}
|
2005-04-12 07:45:06 -04:00
|
|
|
}
|
|
|
|
|
2004-11-11 11:03:19 -05:00
|
|
|
public void setNativeCursor(Object handle) throws LWJGLException {
|
2013-01-24 19:28:26 -05:00
|
|
|
if (native_mode) {
|
2013-01-27 18:45:08 -05:00
|
|
|
currentNativeCursor = getCursorHandle(handle);
|
2013-02-01 20:15:41 -05:00
|
|
|
if (Display.isCreated()) {
|
|
|
|
MacOSXNativeMouse.setCursor(currentNativeCursor);
|
|
|
|
}
|
2013-01-24 19:28:26 -05:00
|
|
|
}
|
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 {
|
2013-01-14 18:35:46 -05:00
|
|
|
if (native_mode) {
|
|
|
|
this.keyboard = new MacOSXNativeKeyboard(window);
|
|
|
|
keyboard.register();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
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() {
|
2013-01-14 18:35:46 -05:00
|
|
|
if (native_mode) {
|
|
|
|
if (keyboard != null) {
|
|
|
|
keyboard.unregister();
|
|
|
|
}
|
|
|
|
keyboard = null;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (keyboard_queue != null) {
|
|
|
|
keyboard_queue.unregister();
|
|
|
|
}
|
|
|
|
this.keyboard_queue = null;
|
2012-11-13 16:13:11 -05:00
|
|
|
}
|
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 pollKeyboard(ByteBuffer keyDownBuffer) {
|
2013-01-14 18:35:46 -05:00
|
|
|
if (native_mode) {
|
|
|
|
keyboard.poll(keyDownBuffer);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
keyboard_queue.poll(keyDownBuffer);
|
|
|
|
}
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|
2004-11-25 17:31:38 -05:00
|
|
|
|
2006-07-03 19:16:26 -04:00
|
|
|
public void readKeyboard(ByteBuffer buffer) {
|
2013-01-14 18:35:46 -05:00
|
|
|
if (native_mode) {
|
|
|
|
keyboard.copyEvents(buffer);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
keyboard_queue.copyEvents(buffer);
|
|
|
|
}
|
2004-11-12 05:48:51 -05:00
|
|
|
}
|
2013-01-26 17:47:36 -05: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 {
|
2013-01-24 19:28:26 -05:00
|
|
|
if (native_mode) {
|
2013-01-26 17:47:36 -05:00
|
|
|
long cursor = MacOSXNativeMouse.createCursor(width, height, xHotspot, yHotspot, numImages, images, delays);
|
|
|
|
return cursor;
|
2013-01-24 19:28:26 -05:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return AWTUtil.createCursor(width, height, xHotspot, yHotspot, numImages, images, delays);
|
|
|
|
}
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public void destroyCursor(Object cursor_handle) {
|
2013-02-03 12:47:09 -05:00
|
|
|
long handle = getCursorHandle(cursor_handle);
|
|
|
|
|
|
|
|
// reset current cursor if same
|
|
|
|
if (currentNativeCursor == handle) {
|
|
|
|
currentNativeCursor = 0;
|
|
|
|
}
|
2012-12-25 09:14:05 -05:00
|
|
|
|
2013-02-03 12:47:09 -05:00
|
|
|
MacOSXNativeMouse.destroyCursor(handle);
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|
2013-01-26 17:47:36 -05:00
|
|
|
|
|
|
|
private static long getCursorHandle(Object cursor_handle) {
|
|
|
|
return cursor_handle != null ? (Long)cursor_handle : 0;
|
|
|
|
}
|
2004-11-12 05:39:06 -05:00
|
|
|
|
2005-01-18 07:34:36 -05:00
|
|
|
public int getPbufferCapabilities() {
|
2012-12-25 09:14:05 -05:00
|
|
|
return Pbuffer.PBUFFER_SUPPORTED;
|
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;
|
|
|
|
}
|
2010-09-28 17:11:35 -04:00
|
|
|
|
2011-09-03 14:52:45 -04:00
|
|
|
public PeerInfo createPbuffer(int width, int height, PixelFormat pixel_format, ContextAttribs attribs,
|
2005-02-20 06:24:22 -05:00
|
|
|
IntBuffer pixelFormatCaps,
|
|
|
|
IntBuffer pBufferAttribs) throws LWJGLException {
|
2011-09-03 14:52:45 -04:00
|
|
|
return new MacOSXPbufferPeerInfo(width, height, pixel_format, attribs);
|
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) {
|
2012-12-25 09:14:05 -05:00
|
|
|
/*int size = 0;
|
2005-07-05 17:54:12 -04:00
|
|
|
int biggest = -1;
|
2010-09-28 17:11:35 -04:00
|
|
|
|
2005-07-05 17:54:12 -04:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2010-09-28 17:11:35 -04:00
|
|
|
|
2005-07-05 17:54:12 -04:00
|
|
|
if (biggest == -1) {
|
|
|
|
return 0;
|
|
|
|
}
|
2010-09-28 17:11:35 -04:00
|
|
|
|
2005-07-05 17:54:12 -04:00
|
|
|
int width;
|
|
|
|
int height;
|
2010-09-28 17:11:35 -04:00
|
|
|
|
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);
|
2010-09-28 17:11:35 -04:00
|
|
|
|
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);
|
2010-09-28 17:11:35 -04:00
|
|
|
|
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
|
|
|
}
|
2012-02-18 11:30:38 -05:00
|
|
|
|
|
|
|
public int getX() {
|
2012-12-25 09:14:05 -05:00
|
|
|
return nGetX(window);
|
2012-02-18 11:30:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getY() {
|
2012-12-25 09:14:05 -05:00
|
|
|
return nGetY(window);
|
2012-02-18 11:30:38 -05:00
|
|
|
}
|
2006-10-26 16:19:40 -04:00
|
|
|
|
|
|
|
public int getWidth() {
|
2012-12-25 09:14:05 -05:00
|
|
|
return nGetWidth(window);
|
2006-10-26 16:19:40 -04:00
|
|
|
}
|
2012-11-11 13:43:14 -05:00
|
|
|
|
2006-10-26 16:19:40 -04:00
|
|
|
public int getHeight() {
|
2012-12-25 09:14:05 -05:00
|
|
|
return nGetHeight(window);
|
2006-10-26 16:19:40 -04:00
|
|
|
}
|
2009-09-12 18:15:21 -04:00
|
|
|
|
2012-12-25 09:14:05 -05:00
|
|
|
public boolean isInsideWindow() {
|
2013-01-27 18:01:21 -05:00
|
|
|
return mouseInsideWindow;
|
2012-12-25 09:14:05 -05:00
|
|
|
}
|
2011-09-03 14:52:45 -04:00
|
|
|
|
2012-12-25 09:14:05 -05:00
|
|
|
public void setResizable(boolean resizable) {
|
|
|
|
nSetResizable(window, resizable);
|
2011-07-12 18:07:32 -04:00
|
|
|
}
|
2011-09-03 14:52:45 -04:00
|
|
|
|
2011-07-12 18:07:32 -04:00
|
|
|
public boolean wasResized() {
|
2012-12-25 09:14:05 -05:00
|
|
|
return nWasResized(window);
|
2011-07-12 18:07:32 -04:00
|
|
|
}
|
2011-09-03 14:52:45 -04:00
|
|
|
|
2004-11-11 11:03:19 -05:00
|
|
|
}
|