lwjgl2-arm64/src/java/org/lwjgl/opengl/AbstractAWTInput.java
Elias Naur 3674d843c2 Added org.lwjgl.opengl.AWTInputAdapter which enabled use of Mouse and
Keyboard with AWTGLCanvases. Programs can now avoid implementing AWT input processing and access the mouse grabbing features from both Display and AWTGLCanvas. See org.lwjgl.test.opengl.awt.AWTInputAdapterTest for an example.

Note: This commit is the linux and generic AWT imlementation and can still
change a lot while implementing windows and mac os x.
2006-10-26 20:19:40 +00:00

168 lines
4.7 KiB
Java

/*
* 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;
import java.nio.IntBuffer;
import java.nio.ByteBuffer;
import org.lwjgl.LWJGLException;
import org.lwjgl.LWJGLUtil;
import java.awt.event.FocusListener;
import java.awt.Cursor;
/**
*
* @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision: 2586 $
* $Id: LinuxAWTGLCanvasPeerInfo.java 2586 2006-10-20 11:51:34Z elias_naur $
*/
abstract class AbstractAWTInput implements AWTCanvasInputImplementation {
private AWTGLCanvas canvas;
private volatile int current_height;
private volatile int current_width;
private KeyboardEventQueue keyboard_queue;
private MouseEventQueue mouse_queue;
private volatile boolean grab;
protected AbstractAWTInput(AWTGLCanvas canvas) throws LWJGLException {
this.canvas = canvas;
}
public synchronized void grabMouse(boolean grab) {
this.grab = grab;
if (mouse_queue != null)
mouse_queue.setGrabbed(grab);
}
protected boolean isGrabbed() {
return grab;
}
protected final AWTGLCanvas getCanvas() {
return canvas;
}
public final void init() {
canvas.setInput(this);
}
public synchronized void destroy() {
canvas.setInput(null);
canvas = null;
}
public final int getWidth() {
return current_width;
}
public final int getHeight() {
return current_height;
}
public synchronized void processInput(PeerInfo peer_info) {
current_width = canvas.getWidth();
current_height = canvas.getHeight();
}
public boolean hasWheel() {
return AWTUtil.hasWheel();
}
public int getButtonCount() {
return AWTUtil.getButtonCount();
}
public void createMouse() throws LWJGLException {
mouse_queue = new MouseEventQueue(canvas);
mouse_queue.register();
}
public void destroyMouse() {
mouse_queue.unregister();
}
public int getNativeCursorCapabilities() {
return AWTUtil.getNativeCursorCapabilities();
}
public void setCursorPosition(int x, int y) {
AWTUtil.setCursorPosition(canvas, x, y);
}
public void setNativeCursor(Object handle) throws LWJGLException {
canvas.setCursor((Cursor)handle);
}
public int getMinCursorSize() {
return AWTUtil.getMinCursorSize();
}
public int getMaxCursorSize() {
return AWTUtil.getMaxCursorSize();
}
public synchronized void createKeyboard() throws LWJGLException {
keyboard_queue = new KeyboardEventQueue(canvas);
keyboard_queue.register();
}
public synchronized void destroyKeyboard() {
if (keyboard_queue != null)
keyboard_queue.unregister();
}
public Object createCursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, IntBuffer delays) throws LWJGLException {
return AWTUtil.createCursor(width, height, xHotspot, yHotspot, numImages, images, delays);
}
public void destroyCursor(Object cursor_handle) {
}
public synchronized void readMouse(ByteBuffer buffer) {
mouse_queue.copyEvents(buffer);
}
public synchronized void pollMouse(IntBuffer coord_buffer, ByteBuffer buttons) {
mouse_queue.poll(coord_buffer, buttons);
}
public synchronized void readKeyboard(ByteBuffer buffer) {
keyboard_queue.copyEvents(buffer);
}
public synchronized void pollKeyboard(ByteBuffer keyDownBuffer) {
keyboard_queue.poll(keyDownBuffer);
}
}