lwjgl2-arm64/src/java/org/lwjgl/opengl/MacOSXFrame.java

215 lines
6 KiB
Java
Raw Normal View History

2004-11-25 23:31:38 +01:00
/*
2008-04-07 20:36:09 +02:00
* Copyright (c) 2002-2008 LWJGL Project
2004-11-12 14:23:20 +01:00
* All rights reserved.
2004-11-25 23:31:38 +01:00
*
2004-11-12 14:23:20 +01:00
* Redistribution and use in source and binary forms, with or without
2004-11-25 23:31:38 +01:00
* modification, are permitted provided that the following conditions are
2004-11-12 14:23:20 +01:00
* met:
2004-11-25 23:31:38 +01:00
*
* * Redistributions of source code must retain the above copyright
2004-11-12 14:23:20 +01: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 23:31:38 +01:00
* * Neither the name of 'LWJGL' nor the names of
* its contributors may be used to endorse or promote products derived
2004-11-12 14:23:20 +01:00
* from this software without specific prior written permission.
2004-11-25 23:31:38 +01:00
*
2004-11-12 14:23:20 +01: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 23:31:38 +01: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-12 14:23:20 +01:00
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
2004-11-25 23:31:38 +01:00
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
2004-11-12 14:23:20 +01: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 Mac OS X AWT Frame. It contains thread safe
* methods to manipulateit from non-AWT threads
* @author elias_naur
*/
import java.awt.BorderLayout;
import java.awt.Frame;
2004-11-20 17:46:44 +01:00
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
2004-11-12 14:23:20 +01:00
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.event.ComponentEvent;
2004-11-20 17:46:44 +01:00
import java.awt.event.ComponentListener;
2004-11-12 14:23:20 +01:00
import java.awt.event.WindowEvent;
2004-11-20 17:46:44 +01:00
import java.awt.event.WindowListener;
import java.security.AccessController;
import java.security.PrivilegedActionException;
2006-01-16 22:04:49 +01:00
import java.security.PrivilegedExceptionAction;
2004-11-12 14:23:20 +01:00
import org.lwjgl.LWJGLException;
final class MacOSXFrame extends Frame implements WindowListener, ComponentListener {
2004-11-25 23:31:38 +01:00
private static final long serialVersionUID = -5823294716668988777L;
2004-11-12 14:23:20 +01:00
private final MacOSXGLCanvas canvas;
private boolean close_requested;
/* States */
private Rectangle bounds;
private boolean active;
private boolean minimized;
private boolean should_warp_cursor;
2004-11-25 23:31:38 +01:00
MacOSXFrame(DisplayMode mode, final java.awt.DisplayMode requested_mode, boolean fullscreen, int x, int y) throws LWJGLException {
2004-11-12 14:23:20 +01:00
setResizable(false);
addWindowListener(this);
addComponentListener(this);
canvas = new MacOSXGLCanvas();
add(canvas, BorderLayout.CENTER);
boolean undecorated = Display.getPrivilegedBoolean("org.lwjgl.opengl.Window.undecorated");
setUndecorated(fullscreen || undecorated);
2004-11-25 23:31:38 +01:00
if ( fullscreen ) {
try {
AccessController.doPrivileged(new PrivilegedExceptionAction() {
public Object run() throws Exception {
getDevice().setFullScreenWindow(MacOSXFrame.this);
getDevice().setDisplayMode(requested_mode);
java.awt.DisplayMode real_mode = getDevice().getDisplayMode();
/** For some strange reason, the display mode is sometimes silently capped even though the mode is reported as supported */
if ( requested_mode.getWidth() != real_mode.getWidth() || requested_mode.getHeight() != real_mode.getHeight() ) {
getDevice().setFullScreenWindow(null);
if (isDisplayable())
dispose();
throw new LWJGLException("AWT capped mode: requested mode = " + requested_mode.getWidth() + "x" + requested_mode.getHeight() +
" but got " + real_mode.getWidth() + " " + real_mode.getHeight());
}
return null;
}
});
} catch (PrivilegedActionException e) {
throw new LWJGLException(e);
2004-11-12 14:23:20 +01:00
}
}
pack();
resize(x, y, mode.getWidth(), mode.getHeight());
setVisible(true);
requestFocus();
canvas.requestFocus();
2005-04-18 08:47:41 +02:00
updateBounds();
2004-11-12 14:23:20 +01:00
}
public void resize(int x, int y, int width, int height) {
Insets insets = getInsets();
setBounds(x, y, width + insets.left + insets.right, height + insets.top + insets.bottom);
}
2004-11-12 14:23:20 +01:00
public Rectangle syncGetBounds() {
2004-11-25 23:31:38 +01:00
synchronized ( this ) {
2004-11-12 14:23:20 +01:00
return bounds;
}
}
2004-11-25 23:31:38 +01:00
2004-11-12 14:23:20 +01:00
public void componentShown(ComponentEvent e) {
}
public void componentHidden(ComponentEvent e) {
}
private void updateBounds() {
2004-11-25 23:31:38 +01:00
synchronized ( this ) {
2004-11-12 14:23:20 +01:00
bounds = getBounds();
}
}
public void componentResized(ComponentEvent e) {
updateBounds();
}
public void componentMoved(ComponentEvent e) {
updateBounds();
}
2004-11-25 23:31:38 +01:00
public static GraphicsDevice getDevice() {
2004-11-12 14:23:20 +01:00
GraphicsEnvironment g_env = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device = g_env.getDefaultScreenDevice();
return device;
}
public void windowIconified(WindowEvent e) {
2004-11-25 23:31:38 +01:00
synchronized ( this ) {
2004-11-12 14:23:20 +01:00
minimized = true;
}
}
public void windowDeiconified(WindowEvent e) {
2004-11-25 23:31:38 +01:00
synchronized ( this ) {
2004-11-12 14:23:20 +01:00
minimized = false;
}
}
public void windowOpened(WindowEvent e) {
}
public void windowClosed(WindowEvent e) {
}
public void windowClosing(WindowEvent e) {
2004-11-25 23:31:38 +01:00
synchronized ( this ) {
2004-11-12 14:23:20 +01:00
close_requested = true;
}
}
2004-11-25 23:31:38 +01:00
2004-11-12 14:23:20 +01:00
public void windowDeactivated(WindowEvent e) {
2004-11-25 23:31:38 +01:00
synchronized ( this ) {
2004-11-12 14:23:20 +01:00
active = false;
}
}
public void windowActivated(WindowEvent e) {
2004-11-25 23:31:38 +01:00
synchronized ( this ) {
2004-11-12 14:23:20 +01:00
active = true;
should_warp_cursor = true;
2004-11-12 14:23:20 +01:00
}
}
public boolean syncIsCloseRequested() {
boolean result;
2004-11-25 23:31:38 +01:00
synchronized ( this ) {
2004-11-12 14:23:20 +01:00
result = close_requested;
close_requested = false;
}
return result;
}
public boolean syncIsVisible() {
2004-11-25 23:31:38 +01:00
synchronized ( this ) {
2004-11-12 14:23:20 +01:00
return !minimized;
}
}
2004-11-25 23:31:38 +01:00
2004-11-12 14:23:20 +01:00
public boolean syncIsActive() {
2004-11-25 23:31:38 +01:00
synchronized ( this ) {
2004-11-12 14:23:20 +01:00
return active;
}
}
2004-11-25 23:31:38 +01:00
2004-11-12 14:23:20 +01:00
public MacOSXGLCanvas getCanvas() {
return canvas;
}
public boolean syncShouldWarpCursor() {
2004-11-12 14:23:20 +01:00
boolean result;
2004-11-25 23:31:38 +01:00
synchronized ( this ) {
result = should_warp_cursor;
should_warp_cursor = false;
2004-11-12 14:23:20 +01:00
}
return result;
}
}