Code cleanup
This commit is contained in:
parent
3041c0494d
commit
83dd8b6bbc
|
@ -57,10 +57,10 @@ import org.lwjgl.input.Mouse;
|
|||
public final class Display {
|
||||
|
||||
/** The display implementor */
|
||||
private final static DisplayImplementation display_impl;
|
||||
private static final DisplayImplementation display_impl;
|
||||
|
||||
/** The initial display mode */
|
||||
private final static DisplayMode initial_mode;
|
||||
private static final DisplayMode initial_mode;
|
||||
|
||||
/** The current display mode, if created */
|
||||
private static DisplayMode current_mode;
|
||||
|
@ -100,7 +100,7 @@ public final class Display {
|
|||
});
|
||||
}
|
||||
|
||||
private final static DisplayImplementation createDisplayImplementation() {
|
||||
private static DisplayImplementation createDisplayImplementation() {
|
||||
String class_name;
|
||||
String os_name = System.getProperty("os.name");
|
||||
if (os_name.startsWith("Linux")) {
|
||||
|
@ -285,11 +285,13 @@ public final class Display {
|
|||
timeThen = timeNow;
|
||||
}
|
||||
|
||||
private static long timeLate;
|
||||
|
||||
/**
|
||||
* Alternative sync method which works better on triple-buffered GL displays.
|
||||
*
|
||||
* @param fps The desired frame rate, in frames per second
|
||||
*/
|
||||
private static long timeLate;
|
||||
public static void sync2(int fps) {
|
||||
long gapTo = Sys.getTimerResolution() / fps + timeThen;
|
||||
timeNow = Sys.getTime();
|
||||
|
|
|
@ -44,16 +44,18 @@ import java.nio.ByteBuffer;
|
|||
import org.lwjgl.LWJGLException;
|
||||
|
||||
public interface DisplayImplementation {
|
||||
public void createWindow(DisplayMode mode, boolean fullscreen, int x, int y) throws LWJGLException;
|
||||
public void destroyWindow();
|
||||
|
||||
public void switchDisplayMode(DisplayMode mode) throws LWJGLException;
|
||||
void createWindow(DisplayMode mode, boolean fullscreen, int x, int y) throws LWJGLException;
|
||||
|
||||
void destroyWindow();
|
||||
|
||||
void switchDisplayMode(DisplayMode mode) throws LWJGLException;
|
||||
|
||||
/**
|
||||
* Reset the display mode to whatever it was when LWJGL was initialized.
|
||||
* Fails silently.
|
||||
*/
|
||||
public void resetDisplayMode();
|
||||
void resetDisplayMode();
|
||||
|
||||
/**
|
||||
* Return the length of the gamma ramp arrays. Returns 0 if gamma settings are
|
||||
|
@ -61,132 +63,130 @@ public interface DisplayImplementation {
|
|||
*
|
||||
* @return the length of each gamma ramp array, or 0 if gamma settings are unsupported.
|
||||
*/
|
||||
public int getGammaRampLength();
|
||||
int getGammaRampLength();
|
||||
|
||||
/**
|
||||
* Native method to set the gamma ramp.
|
||||
*/
|
||||
public void setGammaRamp(FloatBuffer gammaRamp) throws LWJGLException;
|
||||
void setGammaRamp(FloatBuffer gammaRamp) throws LWJGLException;
|
||||
|
||||
/**
|
||||
* Get the driver adapter string. This is a unique string describing the actual card's hardware, eg. "Geforce2", "PS2",
|
||||
* "Radeon9700". If the adapter cannot be determined, this function returns null.
|
||||
* @return a String
|
||||
*/
|
||||
public String getAdapter();
|
||||
String getAdapter();
|
||||
|
||||
/**
|
||||
* Get the driver version. This is a vendor/adapter specific version string. If the version cannot be determined,
|
||||
* this function returns null.
|
||||
* @return a String
|
||||
*/
|
||||
public String getVersion();
|
||||
String getVersion();
|
||||
|
||||
/**
|
||||
* Initialize and return the current display mode.
|
||||
*/
|
||||
public DisplayMode init();
|
||||
DisplayMode init();
|
||||
|
||||
/**
|
||||
* Native implementation of setTitle(). This will read the window's title member
|
||||
* and stash it in the native title of the window.
|
||||
*/
|
||||
public void setTitle(String title);
|
||||
void setTitle(String title);
|
||||
|
||||
public boolean isCloseRequested();
|
||||
boolean isCloseRequested();
|
||||
|
||||
public boolean isVisible();
|
||||
public boolean isActive();
|
||||
boolean isVisible();
|
||||
boolean isActive();
|
||||
|
||||
public boolean isDirty();
|
||||
boolean isDirty();
|
||||
|
||||
/**
|
||||
* Swap double buffers.
|
||||
*/
|
||||
public void swapBuffers();
|
||||
void swapBuffers();
|
||||
|
||||
/**
|
||||
* Make the window the current rendering context for GL calls.
|
||||
*/
|
||||
public void makeCurrent() throws LWJGLException;
|
||||
void makeCurrent() throws LWJGLException;
|
||||
|
||||
/**
|
||||
* Create the native OpenGL context.
|
||||
* @throws LWJGLException
|
||||
*/
|
||||
public void createContext(PixelFormat pixel_format) throws LWJGLException;
|
||||
void createContext(PixelFormat pixel_format) throws LWJGLException;
|
||||
|
||||
public void destroyContext();
|
||||
void destroyContext();
|
||||
|
||||
/**
|
||||
* Updates the windows internal state. This must be called at least once per video frame
|
||||
* to handle window close requests, moves, paints, etc.
|
||||
*/
|
||||
public void update();
|
||||
void update();
|
||||
|
||||
public void setVSyncEnabled(boolean sync);
|
||||
void setVSyncEnabled(boolean sync);
|
||||
|
||||
public void reshape(int x, int y, int width, int height);
|
||||
void reshape(int x, int y, int width, int height);
|
||||
|
||||
/**
|
||||
* Native method for getting displaymodes
|
||||
*/
|
||||
public DisplayMode[] getAvailableDisplayModes();
|
||||
DisplayMode[] getAvailableDisplayModes();
|
||||
|
||||
/*
|
||||
* Mouse methods
|
||||
*/
|
||||
/** Native query of wheel support */
|
||||
public boolean hasWheel();
|
||||
boolean hasWheel();
|
||||
|
||||
/** Native query of button count */
|
||||
public int getButtonCount();
|
||||
int getButtonCount();
|
||||
|
||||
/**
|
||||
* Native method to create the mouse.
|
||||
*
|
||||
* @return true if the mouse was created
|
||||
*/
|
||||
public void createMouse();
|
||||
void createMouse();
|
||||
|
||||
/**
|
||||
* Native method the destroy the mouse
|
||||
*/
|
||||
public void destroyMouse();
|
||||
void destroyMouse();
|
||||
|
||||
/**
|
||||
* Native method to poll the mouse
|
||||
*/
|
||||
public void pollMouse(IntBuffer coord_buffer, ByteBuffer buttons);
|
||||
void pollMouse(IntBuffer coord_buffer, ByteBuffer buttons);
|
||||
|
||||
/**
|
||||
* Native method to enable the buffer
|
||||
* @return the event buffer,
|
||||
* or null if no buffer can be allocated
|
||||
*/
|
||||
public void enableMouseBuffer() throws LWJGLException;
|
||||
void enableMouseBuffer() throws LWJGLException;
|
||||
|
||||
/**
|
||||
* Native method to read the keyboard buffer
|
||||
*
|
||||
* @return the total number of events read.
|
||||
*/
|
||||
public int readMouse(IntBuffer buffer, int buffer_position);
|
||||
int readMouse(IntBuffer buffer, int buffer_position);
|
||||
|
||||
public void grabMouse(boolean grab);
|
||||
|
||||
void grabMouse(boolean grab);
|
||||
|
||||
/**
|
||||
* Native function to determine native cursor support
|
||||
*/
|
||||
public int getNativeCursorCaps();
|
||||
int getNativeCursorCaps();
|
||||
|
||||
/** Native method to set the native cursor */
|
||||
public void setNativeCursor(Object handle) throws LWJGLException;
|
||||
void setNativeCursor(Object handle) throws LWJGLException;
|
||||
|
||||
/** Native method returning the minimum cursor size */
|
||||
public int getMinCursorSize();
|
||||
int getMinCursorSize();
|
||||
|
||||
/** Native method returning the maximum cursor size */
|
||||
public int getMaxCursorSize();
|
||||
int getMaxCursorSize();
|
||||
|
||||
/*
|
||||
* Keyboard methods
|
||||
|
@ -195,48 +195,46 @@ public interface DisplayImplementation {
|
|||
/**
|
||||
* Native method to create the keyboard
|
||||
*/
|
||||
public void createKeyboard() throws LWJGLException;
|
||||
void createKeyboard() throws LWJGLException;
|
||||
|
||||
/**
|
||||
* Native method to destroy the keyboard
|
||||
*/
|
||||
public void destroyKeyboard();
|
||||
void destroyKeyboard();
|
||||
|
||||
/**
|
||||
* Native method to poll the keyboard.
|
||||
*
|
||||
* @param keyDownBufferAddress the address of a 256-byte buffer to place
|
||||
* @param keyDownBuffer the address of a 256-byte buffer to place
|
||||
* key states in.
|
||||
*/
|
||||
public void pollKeyboard(ByteBuffer keyDownBuffer);
|
||||
void pollKeyboard(ByteBuffer keyDownBuffer);
|
||||
|
||||
/**
|
||||
* Native method to read the keyboard buffer
|
||||
* @return the total number of events read.
|
||||
*/
|
||||
public int readKeyboard(IntBuffer buffer, int buffer_position);
|
||||
int readKeyboard(IntBuffer buffer, int buffer_position);
|
||||
|
||||
/**
|
||||
* Native method to enable the translation buffer
|
||||
*/
|
||||
public void enableTranslation() throws LWJGLException;
|
||||
void enableTranslation() throws LWJGLException;
|
||||
|
||||
/**
|
||||
* Native method to enable the buffer
|
||||
* @return the event buffer,
|
||||
* or null if no buffer can be allocated
|
||||
*/
|
||||
public void enableKeyboardBuffer() throws LWJGLException;
|
||||
void enableKeyboardBuffer() throws LWJGLException;
|
||||
|
||||
public int isStateKeySet(int key);
|
||||
int isStateKeySet(int key);
|
||||
|
||||
/** Native cursor handles */
|
||||
public Object createCursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, IntBuffer delays) throws LWJGLException;
|
||||
Object createCursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, IntBuffer delays) throws LWJGLException;
|
||||
|
||||
public void destroyCursor(Object cursor_handle);
|
||||
void destroyCursor(Object cursor_handle);
|
||||
|
||||
/* Pbuffer caps */
|
||||
public int getPbufferCaps();
|
||||
int getPbufferCaps();
|
||||
|
||||
public boolean openURL(String url);
|
||||
boolean openURL(String url);
|
||||
}
|
||||
|
|
|
@ -128,7 +128,7 @@ public final class DisplayMode {
|
|||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
StringBuffer sb = new StringBuffer(32);
|
||||
sb.append(width);
|
||||
sb.append(" x ");
|
||||
sb.append(height);
|
||||
|
|
|
@ -41,11 +41,14 @@ import java.nio.ByteBuffer;
|
|||
import java.nio.IntBuffer;
|
||||
|
||||
abstract class EventQueue {
|
||||
private final static int QUEUE_SIZE = 200;
|
||||
|
||||
private static final int QUEUE_SIZE = 200;
|
||||
|
||||
private final int event_size;
|
||||
|
||||
private final IntBuffer queue;
|
||||
|
||||
public EventQueue(int event_size) {
|
||||
protected EventQueue(int event_size) {
|
||||
this.event_size = event_size;
|
||||
this.queue = ByteBuffer.allocateDirect(QUEUE_SIZE*event_size).asIntBuffer();
|
||||
}
|
||||
|
|
|
@ -44,8 +44,9 @@ import java.nio.ByteBuffer;
|
|||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
final class KeyboardEventQueue extends EventQueue implements KeyListener {
|
||||
private final static int[] KEY_MAP = new int[0xffff];
|
||||
private final static int EVENT_SIZE = 3;
|
||||
|
||||
private static final int[] KEY_MAP = new int[0xffff];
|
||||
private static final int EVENT_SIZE = 3;
|
||||
|
||||
private final byte[] key_states = new byte[Keyboard.KEYBOARD_SIZE];
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ import org.lwjgl.BufferUtils;
|
|||
import org.lwjgl.LWJGLException;
|
||||
|
||||
final class LinuxDisplay implements DisplayImplementation {
|
||||
private final static int CURSOR_HANDLE_SIZE = 8;
|
||||
private static final int CURSOR_HANDLE_SIZE = 8;
|
||||
|
||||
public native void createWindow(DisplayMode mode, boolean fullscreen, int x, int y) throws LWJGLException;
|
||||
public native void destroyWindow();
|
||||
|
|
|
@ -51,7 +51,6 @@ import java.lang.reflect.Proxy;
|
|||
import java.nio.ByteBuffer;
|
||||
import java.nio.FloatBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -59,7 +58,7 @@ import org.lwjgl.LWJGLException;
|
|||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
final class MacOSXDisplay implements DisplayImplementation {
|
||||
private final static int GAMMA_LENGTH = 256;
|
||||
private static final int GAMMA_LENGTH = 256;
|
||||
|
||||
private MacOSXFrame frame;
|
||||
private MouseEventQueue mouse_queue;
|
||||
|
@ -69,7 +68,7 @@ final class MacOSXDisplay implements DisplayImplementation {
|
|||
/* States */
|
||||
private boolean close_requested;
|
||||
|
||||
public MacOSXDisplay() {
|
||||
MacOSXDisplay() {
|
||||
new MacOSXApplicationListener();
|
||||
}
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@ import java.lang.reflect.InvocationTargetException;
|
|||
import org.lwjgl.LWJGLException;
|
||||
|
||||
final class MacOSXFrame extends Frame implements WindowListener, ComponentListener {
|
||||
|
||||
private final MacOSXGLCanvas canvas;
|
||||
private boolean close_requested;
|
||||
|
||||
|
@ -62,7 +63,7 @@ final class MacOSXFrame extends Frame implements WindowListener, ComponentListen
|
|||
private boolean visible;
|
||||
private boolean minimized;
|
||||
|
||||
public MacOSXFrame(DisplayMode mode, java.awt.DisplayMode requested_mode, boolean fullscreen, int x, int y) throws LWJGLException {
|
||||
MacOSXFrame(DisplayMode mode, java.awt.DisplayMode requested_mode, boolean fullscreen, int x, int y) throws LWJGLException {
|
||||
setResizable(false);
|
||||
addWindowListener(this);
|
||||
addComponentListener(this);
|
||||
|
@ -119,7 +120,7 @@ final class MacOSXFrame extends Frame implements WindowListener, ComponentListen
|
|||
updateBounds();
|
||||
}
|
||||
|
||||
public final static GraphicsDevice getDevice() {
|
||||
public static GraphicsDevice getDevice() {
|
||||
GraphicsEnvironment g_env = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
GraphicsDevice device = g_env.getDefaultScreenDevice();
|
||||
return device;
|
||||
|
@ -172,9 +173,10 @@ final class MacOSXFrame extends Frame implements WindowListener, ComponentListen
|
|||
}
|
||||
|
||||
private class TitleSetter implements Runnable {
|
||||
|
||||
private final String title;
|
||||
|
||||
public TitleSetter(String title) {
|
||||
TitleSetter(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
|
@ -222,12 +224,13 @@ final class MacOSXFrame extends Frame implements WindowListener, ComponentListen
|
|||
}
|
||||
|
||||
private class Reshaper implements Runnable {
|
||||
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int width;
|
||||
private final int height;
|
||||
|
||||
public Reshaper(int x, int y, int width, int height) {
|
||||
Reshaper(int x, int y, int width, int height) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
|
@ -255,9 +258,10 @@ final class MacOSXFrame extends Frame implements WindowListener, ComponentListen
|
|||
}
|
||||
|
||||
private class CursorSetter implements Runnable {
|
||||
|
||||
private final java.awt.Cursor awt_cursor;
|
||||
|
||||
public CursorSetter(java.awt.Cursor awt_cursor) {
|
||||
CursorSetter(java.awt.Cursor awt_cursor) {
|
||||
this.awt_cursor = awt_cursor;
|
||||
}
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@ import java.awt.event.ComponentEvent;
|
|||
import java.awt.event.ComponentListener;
|
||||
|
||||
final class MacOSXGLCanvas extends Canvas implements ComponentListener {
|
||||
|
||||
private int width;
|
||||
private int height;
|
||||
private boolean context_update;
|
||||
|
|
|
@ -49,9 +49,10 @@ import java.nio.ByteBuffer;
|
|||
import org.lwjgl.BufferUtils;
|
||||
|
||||
final class MouseEventQueue extends EventQueue implements MouseListener, MouseMotionListener, MouseWheelListener {
|
||||
private final static int WHEEL_SCALE = 120;
|
||||
public final static int NUM_BUTTONS = 3;
|
||||
private final static int EVENT_SIZE = 5;
|
||||
|
||||
private static final int WHEEL_SCALE = 120;
|
||||
public static final int NUM_BUTTONS = 3;
|
||||
private static final int EVENT_SIZE = 5;
|
||||
|
||||
private final int width;
|
||||
private final int height;
|
||||
|
@ -75,7 +76,7 @@ final class MouseEventQueue extends EventQueue implements MouseListener, MouseMo
|
|||
/** Buttons array */
|
||||
private final byte[] buttons = new byte[NUM_BUTTONS];
|
||||
|
||||
public MouseEventQueue(int width, int height) {
|
||||
MouseEventQueue(int width, int height) {
|
||||
super(EVENT_SIZE);
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
|
|
|
@ -46,7 +46,7 @@ import org.lwjgl.BufferUtils;
|
|||
import org.lwjgl.LWJGLException;
|
||||
|
||||
final class Win32Display implements DisplayImplementation {
|
||||
private final static int CURSOR_HANDLE_SIZE = 8;
|
||||
private static final int CURSOR_HANDLE_SIZE = 8;
|
||||
|
||||
public native void createWindow(DisplayMode mode, boolean fullscreen, int x, int y) throws LWJGLException;
|
||||
public native void destroyWindow();
|
||||
|
@ -70,6 +70,7 @@ final class Win32Display implements DisplayImplementation {
|
|||
public native void setVSyncEnabled(boolean sync);
|
||||
public native void reshape(int x, int y, int width, int height);
|
||||
public native DisplayMode[] getAvailableDisplayModes();
|
||||
|
||||
/* Mouse */
|
||||
public native boolean hasWheel();
|
||||
public native int getButtonCount();
|
||||
|
@ -83,6 +84,7 @@ final class Win32Display implements DisplayImplementation {
|
|||
public native void setNativeCursor(Object handle) throws LWJGLException;
|
||||
public native int getMinCursorSize();
|
||||
public native int getMaxCursorSize();
|
||||
|
||||
/* Keyboard */
|
||||
public native void createKeyboard() throws LWJGLException;
|
||||
public native void destroyKeyboard();
|
||||
|
|
Loading…
Reference in New Issue