Now the only Window class you need :D
This commit is contained in:
parent
e482a9e815
commit
2049563485
|
@ -7,7 +7,7 @@
|
|||
package org.lwjgl;
|
||||
|
||||
/**
|
||||
* This is the abstract base class for a Window in LWJGL. LWJGL windows have some
|
||||
* This is the abstract class for a Window in LWJGL. LWJGL windows have some
|
||||
* peculiar characteristics:
|
||||
*
|
||||
* - width and height are always fixed and cannot be changed
|
||||
|
@ -20,21 +20,15 @@ package org.lwjgl;
|
|||
*
|
||||
* @author foo
|
||||
*/
|
||||
public abstract class Window {
|
||||
public final class Window {
|
||||
|
||||
static {
|
||||
System.loadLibrary(Sys.getLibraryName());
|
||||
}
|
||||
|
||||
/** The currently created window */
|
||||
private static Window currentWindow;
|
||||
|
||||
/** Whether the window is currently created, ie. has a native peer */
|
||||
private static boolean created;
|
||||
|
||||
/** The window's native data structure. On Win32 this is an HWND. */
|
||||
private static int handle;
|
||||
|
||||
/** Whether the window is currently minimized */
|
||||
private static boolean minimized;
|
||||
|
||||
|
@ -65,6 +59,21 @@ public abstract class Window {
|
|||
/** Title of the window */
|
||||
private static String title;
|
||||
|
||||
/** Color bits */
|
||||
private static int color;
|
||||
|
||||
/** Alpha bits */
|
||||
private static int alpha;
|
||||
|
||||
/** Depth bits */
|
||||
private static int depth;
|
||||
|
||||
/** Stencil bits */
|
||||
private static int stencil;
|
||||
|
||||
/** Fullscreen */
|
||||
private static boolean fullscreen;
|
||||
|
||||
/**
|
||||
* Construct a Window. Some OSs may not support non-fullscreen windows; in
|
||||
* which case the window will be fullscreen regardless.
|
||||
|
@ -88,13 +97,7 @@ public abstract class Window {
|
|||
* @param height Height of window
|
||||
* @throws RuntimeException if you attempt to create more than one window at the same time
|
||||
*/
|
||||
protected Window(String title, int x, int y, int width, int height) {
|
||||
Window.title = title;
|
||||
Window.x = x;
|
||||
Window.y = y;
|
||||
Window.width = width;
|
||||
Window.height = height;
|
||||
|
||||
private Window() {
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -199,51 +202,111 @@ public abstract class Window {
|
|||
public static void paint() {
|
||||
assert isCreated();
|
||||
dirty = false;
|
||||
currentWindow.doPaint();
|
||||
swapBuffers();
|
||||
}
|
||||
|
||||
protected abstract void doPaint();
|
||||
/**
|
||||
* Swap double buffers.
|
||||
*/
|
||||
private static native void swapBuffers();
|
||||
|
||||
/**
|
||||
* Create the window.
|
||||
* Create a fullscreen window. If the underlying OS does not
|
||||
* support fullscreen mode, then a window will be created instead. If this
|
||||
* fails too then an Exception will be thrown.
|
||||
*
|
||||
* @param title The title of the window
|
||||
* @param bpp Minimum bits per pixel
|
||||
* @param alpha Minimum bits per pixel in alpha buffer
|
||||
* @param depth Minimum bits per pixel in depth buffer
|
||||
* @param stencil Minimum bits per pixel in stencil buffer
|
||||
* @throws Exception if the window could not be created for any reason; typically because
|
||||
* the minimum requirements could not be met satisfactorily
|
||||
*/
|
||||
public final void create() throws Exception {
|
||||
if (currentWindow != null)
|
||||
throw new RuntimeException("Only one LWJGL window may be instantiated at any one time.");
|
||||
doCreate();
|
||||
currentWindow = this;
|
||||
public static void create(String title, int bpp, int alpha, int depth, int stencil) throws Exception {
|
||||
if (isCreated())
|
||||
throw new Exception("Only one LWJGL window may be instantiated at any one time.");
|
||||
Window.x = 0;
|
||||
Window.y = 0;
|
||||
Window.color = bpp;
|
||||
Window.alpha = alpha;
|
||||
Window.depth = depth;
|
||||
Window.stencil = stencil;
|
||||
Window.fullscreen = true;
|
||||
Window.title = title;
|
||||
Window.width = Display.getWidth();
|
||||
Window.height = Display.getHeight();
|
||||
nCreate(title, x, y, width, height, fullscreen, color, alpha, depth, stencil);
|
||||
created = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the window (derived classes).
|
||||
* Create a window. If the underlying OS does not have "floating" windows, then a fullscreen
|
||||
* display will be created instead. If this fails too then an Exception will be thrown.
|
||||
* If the window is created fullscreen, then its size may not match the specified size
|
||||
* here.
|
||||
*
|
||||
* @param title The title of the window
|
||||
* @param x The position of the window on the x axis. May be ignored.
|
||||
* @param y The position of the window on the y axis. May be ignored.
|
||||
* @param width The width of the window's client area
|
||||
* @param height The height of the window's client area
|
||||
* @param bpp Minimum bits per pixel
|
||||
* @param alpha Minimum bits per pixel in alpha buffer
|
||||
* @param depth Minimum bits per pixel in depth buffer
|
||||
* @param stencil Minimum bits per pixel in stencil buffer
|
||||
* @throws Exception if the window could not be created for any reason; typically because
|
||||
* the minimum requirements could not be met satisfactorily
|
||||
*/
|
||||
public static void create(String title, int x, int y, int width, int height, int bpp, int alpha, int depth, int stencil)
|
||||
throws Exception {
|
||||
if (isCreated())
|
||||
throw new Exception("Only one LWJGL window may be instantiated at any one time.");
|
||||
Window.x = x;
|
||||
Window.y = y;
|
||||
Window.width = width;
|
||||
Window.height = height;
|
||||
Window.color = bpp;
|
||||
Window.alpha = alpha;
|
||||
Window.depth = depth;
|
||||
Window.stencil = stencil;
|
||||
Window.fullscreen = false;
|
||||
Window.title = title;
|
||||
nCreate(title, x, y, width, height, fullscreen, color, alpha, depth, stencil);
|
||||
created = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the native window peer.
|
||||
* @throws Exception
|
||||
*/
|
||||
protected abstract void doCreate() throws Exception;
|
||||
private static native void nCreate(
|
||||
String title,
|
||||
int x,
|
||||
int y,
|
||||
int width,
|
||||
int height,
|
||||
boolean fullscreen,
|
||||
int bpp,
|
||||
int alpha,
|
||||
int depth,
|
||||
int stencil)
|
||||
throws Exception;
|
||||
|
||||
/**
|
||||
* Destroy the window.
|
||||
*/
|
||||
public final void destroy() {
|
||||
public static void destroy() {
|
||||
if (!created)
|
||||
return;
|
||||
doDestroy();
|
||||
currentWindow = null;
|
||||
nDestroy();
|
||||
created = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy the window (derived classes)
|
||||
* Destroy the native window peer.
|
||||
*/
|
||||
protected abstract void doDestroy();
|
||||
|
||||
|
||||
/**
|
||||
* @return the native window handle
|
||||
*/
|
||||
public static int getHandle() {
|
||||
return handle;
|
||||
}
|
||||
private native static void nDestroy();
|
||||
|
||||
/**
|
||||
* @return true if the window's native peer has been created
|
||||
|
@ -258,17 +321,4 @@ public abstract class Window {
|
|||
*/
|
||||
public static native void tick();
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
return "Window["+title+"]";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the current window, or null, if there is no current window
|
||||
*/
|
||||
public static Window getCurrentWindow() {
|
||||
return currentWindow;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue