diff options
Diffstat (limited to 'src/classes/com/sun/javafx/newt')
11 files changed, 269 insertions, 145 deletions
diff --git a/src/classes/com/sun/javafx/newt/Display.java b/src/classes/com/sun/javafx/newt/Display.java index 220a612a4..2aa55246f 100755 --- a/src/classes/com/sun/javafx/newt/Display.java +++ b/src/classes/com/sun/javafx/newt/Display.java @@ -35,31 +35,50 @@ package com.sun.javafx.newt; public abstract class Display { + private static Class getDisplayClass(String type) + throws ClassNotFoundException + { + Class displayClass = null; + if (NewtFactory.KD.equals(type)) { + displayClass = Class.forName("com.sun.javafx.newt.kd.KDDisplay"); + } else if (NewtFactory.WINDOWS.equals(type)) { + displayClass = Class.forName("com.sun.javafx.newt.windows.WindowsDisplay"); + } else if (NewtFactory.X11.equals(type)) { + displayClass = Class.forName("com.sun.javafx.newt.x11.X11Display"); + } else if (NewtFactory.MACOSX.equals(type)) { + displayClass = Class.forName("com.sun.javafx.newt.macosx.MacOSXDisplay"); + } else { + throw new RuntimeException("Unknown display type \"" + type + "\""); + } + return displayClass; + } + protected static Display create(String type, String name) { try { - Class displayClass = null; - if (NewtFactory.KD.equals(type)) { - displayClass = Class.forName("com.sun.javafx.newt.kd.KDDisplay"); - } else if (NewtFactory.WINDOWS.equals(type)) { - displayClass = Class.forName("com.sun.javafx.newt.windows.WindowsDisplay"); - } else if (NewtFactory.X11.equals(type)) { - displayClass = Class.forName("com.sun.javafx.newt.x11.X11Display"); - } else if (NewtFactory.MACOSX.equals(type)) { - displayClass = Class.forName("com.sun.javafx.newt.macosx.MacOSXDisplay"); - } else { - throw new RuntimeException("Unknown display type \"" + type + "\""); - } + Class displayClass = getDisplayClass(type); Display display = (Display) displayClass.newInstance(); display.name=name; display.handle=0; - display.initNative(); + display.createNative(); + return display; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + protected static Display wrapHandle(String type, String name, long handle) { + try { + Class displayClass = getDisplayClass(type); + Display display = (Display) displayClass.newInstance(); + display.name=name; + display.handle=handle; return display; } catch (Exception e) { throw new RuntimeException(e); } } - protected abstract void initNative(); + protected abstract void createNative(); public String getName() { return name; diff --git a/src/classes/com/sun/javafx/newt/EventListener.java b/src/classes/com/sun/javafx/newt/EventListener.java index 881d66b87..2af63bd7c 100644 --- a/src/classes/com/sun/javafx/newt/EventListener.java +++ b/src/classes/com/sun/javafx/newt/EventListener.java @@ -35,5 +35,9 @@ package com.sun.javafx.newt; public interface EventListener { + public static final int WINDOW = 1 << 0; + public static final int MOUSE = 1 << 1; + public static final int KEY = 1 << 2; + } diff --git a/src/classes/com/sun/javafx/newt/NewtFactory.java b/src/classes/com/sun/javafx/newt/NewtFactory.java index addc867d0..9f19be289 100755 --- a/src/classes/com/sun/javafx/newt/NewtFactory.java +++ b/src/classes/com/sun/javafx/newt/NewtFactory.java @@ -64,17 +64,49 @@ public abstract class NewtFactory { return windowType; } + /** + * Create a Display entity, incl native creation + */ public static Display createDisplay(String name) { return Display.create(getWindowType(), name); } + /** + * Create a Screen entity, incl native creation + */ public static Screen createScreen(Display display, int index) { return Screen.create(getWindowType(), display, index); } - public static Window createWindow(Screen screen, int visualID) { + /** + * Create a Window entity, incl native creation + */ + public static Window createWindow(Screen screen, long visualID) { return Window.create(getWindowType(), screen, visualID); } + /** + * Instantiate a Display entity using the native handle. + */ + public static Display wrapDisplay(String name, long handle) { + return Display.wrapHandle(getWindowType(), name, handle); + } + + /** + * Instantiate a Screen entity using the native handle. + */ + public static Screen wrapScreen(Display display, int index, long handle) { + return Screen.wrapHandle(getWindowType(), display, index, handle); + } + + /** + * Instantiate a Window entity using the native handle. + */ + public static Window wrapWindow(Screen screen, long visualID, + long windowHandle, boolean fullscreen, boolean visible, + int x, int y, int width, int height) { + return Window.wrapHandle(getWindowType(), screen, visualID, + windowHandle, fullscreen, visible, x, y, width, height); + } } diff --git a/src/classes/com/sun/javafx/newt/Screen.java b/src/classes/com/sun/javafx/newt/Screen.java index 77414d00e..38669b9e0 100755 --- a/src/classes/com/sun/javafx/newt/Screen.java +++ b/src/classes/com/sun/javafx/newt/Screen.java @@ -35,32 +35,52 @@ package com.sun.javafx.newt; public abstract class Screen { + private static Class getScreenClass(String type) + throws ClassNotFoundException + { + Class screenClass = null; + if (NewtFactory.KD.equals(type)) { + screenClass = Class.forName("com.sun.javafx.newt.kd.KDScreen"); + } else if (NewtFactory.WINDOWS.equals(type)) { + screenClass = Class.forName("com.sun.javafx.newt.windows.WindowsScreen"); + } else if (NewtFactory.X11.equals(type)) { + screenClass = Class.forName("com.sun.javafx.newt.x11.X11Screen"); + } else if (NewtFactory.MACOSX.equals(type)) { + screenClass = Class.forName("com.sun.javafx.newt.macosx.MacOSXScreen"); + } else { + throw new RuntimeException("Unknown window type \"" + type + "\""); + } + return screenClass; + } + protected static Screen create(String type, Display display, int idx) { try { - Class screenClass = null; - if (NewtFactory.KD.equals(type)) { - screenClass = Class.forName("com.sun.javafx.newt.kd.KDScreen"); - } else if (NewtFactory.WINDOWS.equals(type)) { - screenClass = Class.forName("com.sun.javafx.newt.windows.WindowsScreen"); - } else if (NewtFactory.X11.equals(type)) { - screenClass = Class.forName("com.sun.javafx.newt.x11.X11Screen"); - } else if (NewtFactory.MACOSX.equals(type)) { - screenClass = Class.forName("com.sun.javafx.newt.macosx.MacOSXScreen"); - } else { - throw new RuntimeException("Unknown window type \"" + type + "\""); - } + Class screenClass = getScreenClass(type); Screen screen = (Screen) screenClass.newInstance(); screen.display = display; screen.index = idx; screen.handle = 0; - screen.initNative(); + screen.createNative(); + return screen; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + protected static Screen wrapHandle(String type, Display display, int idx, long handle) { + try { + Class screenClass = getScreenClass(type); + Screen screen = (Screen) screenClass.newInstance(); + screen.display = display; + screen.index = idx; + screen.handle = handle; return screen; } catch (Exception e) { throw new RuntimeException(e); } } - protected abstract void initNative(); + protected abstract void createNative(); public Display getDisplay() { return display; diff --git a/src/classes/com/sun/javafx/newt/Window.java b/src/classes/com/sun/javafx/newt/Window.java index 8c1cecd3f..c485a93b1 100755 --- a/src/classes/com/sun/javafx/newt/Window.java +++ b/src/classes/com/sun/javafx/newt/Window.java @@ -45,26 +45,32 @@ public abstract class Window implements NativeWindow public static final boolean DEBUG_KEY_EVENT = false; public static final boolean DEBUG_IMPLEMENTATION = false; - protected static Window create(String type, Screen screen, int visualID) { + private static Class getWindowClass(String type) + throws ClassNotFoundException + { + Class windowClass = null; + if (NewtFactory.KD.equals(type)) { + windowClass = Class.forName("com.sun.javafx.newt.kd.KDWindow"); + } else if (NewtFactory.WINDOWS.equals(type)) { + windowClass = Class.forName("com.sun.javafx.newt.windows.WindowsWindow"); + } else if (NewtFactory.X11.equals(type)) { + windowClass = Class.forName("com.sun.javafx.newt.x11.X11Window"); + } else if (NewtFactory.MACOSX.equals(type)) { + windowClass = Class.forName("com.sun.javafx.newt.macosx.MacOSXWindow"); + } else { + throw new RuntimeException("Unknown window type \"" + type + "\""); + } + return windowClass; + } + + protected static Window create(String type, Screen screen, long visualID) { try { - Class windowClass = null; - if (NewtFactory.KD.equals(type)) { - windowClass = Class.forName("com.sun.javafx.newt.kd.KDWindow"); - } else if (NewtFactory.WINDOWS.equals(type)) { - windowClass = Class.forName("com.sun.javafx.newt.windows.WindowsWindow"); - } else if (NewtFactory.X11.equals(type)) { - windowClass = Class.forName("com.sun.javafx.newt.x11.X11Window"); - } else if (NewtFactory.MACOSX.equals(type)) { - windowClass = Class.forName("com.sun.javafx.newt.macosx.MacOSXWindow"); - } else { - throw new RuntimeException("Unknown window type \"" + type + "\""); - } + Class windowClass = getWindowClass(type); Window window = (Window) windowClass.newInstance(); + window.invalidate(); window.screen = screen; window.visualID = visualID; - window.windowHandle = 0; - window.locked = false; - window.initNative(); + window.createNative(); return window; } catch (Throwable t) { t.printStackTrace(); @@ -72,16 +78,64 @@ public abstract class Window implements NativeWindow } } - protected abstract void initNative(); + protected static Window wrapHandle(String type, Screen screen, long visualID, + long windowHandle, boolean fullscreen, boolean visible, + int x, int y, int width, int height) + { + try { + Class windowClass = getWindowClass(type); + Window window = (Window) windowClass.newInstance(); + window.invalidate(); + window.screen = screen; + window.visualID = visualID; + window.windowHandle = windowHandle; + window.fullscreen=fullscreen; + window.visible=visible; + window.x=x; + window.y=y; + window.width=width; + window.height=height; + return window; + } catch (Throwable t) { + t.printStackTrace(); + throw new RuntimeException(t); + } + } + + /** + * create native windowHandle, ie creates a new native invisible window + */ + protected abstract void createNative(); + + protected abstract void closeNative(); public Screen getScreen() { return screen; } - public abstract int getDisplayWidth(); - public abstract int getDisplayHeight(); + public abstract int getDisplayWidth(); + public abstract int getDisplayHeight(); - public abstract void pumpMessages(); + /** + * eventMask is a bitfield of EventListener event flags + */ + public void pumpMessages(int eventMask) { + if(this.eventMask!=eventMask && eventMask>0) { + this.eventMask=eventMask; + eventMask*=-1; + } + dispatchMessages(eventMask); + } + + public void pumpMessages() { + int em = 0; + //if(windowistener.size()>0) em |= EventListener.WINDOW; + if(mouseListener.size()>0) em |= EventListener.MOUSE; + if(keyListener.size()>0) em |= EventListener.KEY; + pumpMessages(em); + } + + public abstract void dispatchMessages(int eventMask); public String toString() { return "Window[handle "+windowHandle+ @@ -90,33 +144,62 @@ public abstract class Window implements NativeWindow } protected Screen screen; - protected int visualID; + protected long visualID; protected long windowHandle; - protected boolean locked; + protected boolean locked=false; + protected boolean fullscreen, visible; + protected int width, height, x, y; + protected int eventMask; // // NativeWindow impl // - public boolean lockSurface() throws NativeWindowException { + public int lockSurface() throws NativeWindowException { if (locked) { throw new NativeWindowException("Surface already locked"); } - locked = true; - return true; + // locked = true; + // return LOCK_SUCCESS; + return LOCK_NOT_SUPPORTED; } public void unlockSurface() { - if (!locked) { - throw new NativeWindowException("Surface already locked"); + if (locked) { + locked = false; } - locked = false; } public boolean isSurfaceLocked() { return locked; } + public void close() { + closeNative(); + invalidate(); + } + + public void invalidate() { + unlockSurface(); + screen = null; + visualID = 0; + windowHandle = 0; + locked = false; + fullscreen=false; + visible=false; + eventMask = 0; + + // Default position and dimension will be re-set immediately by user + width = 100; + height = 100; + x=0; + y=0; + } + + protected void clearEventMask() { + eventMask=0; + } + public long getDisplayHandle() { return screen.getDisplay().getHandle(); } @@ -133,20 +216,39 @@ public abstract class Window implements NativeWindow return windowHandle; } - public int getVisualID() { + public long getVisualID() { return visualID; } - public abstract int getWidth(); - public abstract int getHeight(); - public abstract int getX(); - public abstract int getY(); + public boolean isVisible() { + return visible; + } + + public int getX() { + return x; + } + + public int getY() { + return y; + } + + public int getWidth() { + return width; + } + + public int getHeight() { + return height; + } + + public boolean isFullscreen() { + return fullscreen; + } + public abstract void setVisible(boolean visible); + public abstract void setSize(int width, int height); public abstract void setPosition(int x, int y); - public abstract boolean isVisible(); public abstract boolean setFullscreen(boolean fullscreen); - public abstract boolean isFullscreen(); // // MouseListener Support diff --git a/src/classes/com/sun/javafx/newt/windows/WindowsDisplay.java b/src/classes/com/sun/javafx/newt/windows/WindowsDisplay.java index ce2ac8c4a..e66a9ac08 100755 --- a/src/classes/com/sun/javafx/newt/windows/WindowsDisplay.java +++ b/src/classes/com/sun/javafx/newt/windows/WindowsDisplay.java @@ -40,7 +40,7 @@ public class WindowsDisplay extends Display { public WindowsDisplay() { } - public void initNative() { + protected void createNative() { handle = 0; } } diff --git a/src/classes/com/sun/javafx/newt/windows/WindowsScreen.java b/src/classes/com/sun/javafx/newt/windows/WindowsScreen.java index cf163ce48..5b38d22d2 100755 --- a/src/classes/com/sun/javafx/newt/windows/WindowsScreen.java +++ b/src/classes/com/sun/javafx/newt/windows/WindowsScreen.java @@ -40,7 +40,7 @@ public class WindowsScreen extends Screen { public WindowsScreen() { } - public void initNative() { + protected void createNative() { handle = 0; } } diff --git a/src/classes/com/sun/javafx/newt/windows/WindowsWindow.java b/src/classes/com/sun/javafx/newt/windows/WindowsWindow.java index 01f763f0f..eda64cc20 100755 --- a/src/classes/com/sun/javafx/newt/windows/WindowsWindow.java +++ b/src/classes/com/sun/javafx/newt/windows/WindowsWindow.java @@ -37,12 +37,6 @@ import com.sun.javafx.newt.*; import com.sun.opengl.impl.*; public class WindowsWindow extends Window { - private boolean fullscreen, visible; - // Default width and height -- will likely be re-set immediately by user - private int width = 100; - private int height = 100; - private int x=0; - private int y=0; private static final String WINDOW_CLASS_NAME = "NewtWindow"; static { @@ -56,16 +50,18 @@ public class WindowsWindow extends Window { public WindowsWindow() { } - public void initNative() { + protected void createNative() { long wndClass = getWindowClass(); - fullscreen=false; - visible=false; windowHandle = CreateWindow(WINDOW_CLASS_NAME, getHInstance(), visualID, x, y, width, height); if (windowHandle == 0) { throw new RuntimeException("Error creating window"); } } + protected void closeNative() { + CloseWindow(windowHandle); + } + public void setVisible(boolean visible) { if(this.visible!=visible) { this.visible=visible; @@ -80,26 +76,6 @@ public class WindowsWindow extends Window { public void setPosition(int x, int y) { } - public boolean isVisible() { - return visible; - } - - public int getX() { - return x; - } - - public int getY() { - return y; - } - - public int getWidth() { - return width; - } - - public int getHeight() { - return height; - } - public boolean setFullscreen(boolean fullscreen) { if(this.fullscreen!=fullscreen) { this.fullscreen=fullscreen; @@ -108,10 +84,6 @@ public class WindowsWindow extends Window { return true; } - public boolean isFullscreen() { - return fullscreen; - } - public int getDisplayWidth() { return 640; // FIXME } @@ -120,8 +92,8 @@ public class WindowsWindow extends Window { return 480; // FIXME } - public void pumpMessages() { - DispatchMessages(windowHandle); + public void dispatchMessages(int eventMask) { + DispatchMessages(windowHandle, eventMask); } //---------------------------------------------------------------------- @@ -153,10 +125,11 @@ public class WindowsWindow extends Window { private static native boolean initIDs(); private static native long LoadLibraryW(String libraryName); private static native long RegisterWindowClass(String windowClassName, long hInstance); - private native long CreateWindow(String windowClassName, long hInstance, int visualID, + private native long CreateWindow(String windowClassName, long hInstance, long visualID, int x, int y, int width, int height); + private native void CloseWindow(long windowHandle); private native void setVisible0(long windowHandle, boolean visible); - private static native void DispatchMessages(long windowHandle); + private static native void DispatchMessages(long windowHandle, int eventMask); private native void setSize0(long windowHandle, int width, int height); private native boolean setFullScreen0(long windowHandle, boolean fullscreen); diff --git a/src/classes/com/sun/javafx/newt/x11/X11Display.java b/src/classes/com/sun/javafx/newt/x11/X11Display.java index 5a4ed8eed..00df325c6 100755 --- a/src/classes/com/sun/javafx/newt/x11/X11Display.java +++ b/src/classes/com/sun/javafx/newt/x11/X11Display.java @@ -44,7 +44,7 @@ public class X11Display extends Display { public X11Display() { } - public void initNative() { + protected void createNative() { handle = CreateDisplay(name); if (handle == 0 ) { throw new RuntimeException("Error creating display: "+name); diff --git a/src/classes/com/sun/javafx/newt/x11/X11Screen.java b/src/classes/com/sun/javafx/newt/x11/X11Screen.java index 279507fab..4094c557c 100755 --- a/src/classes/com/sun/javafx/newt/x11/X11Screen.java +++ b/src/classes/com/sun/javafx/newt/x11/X11Screen.java @@ -44,7 +44,7 @@ public class X11Screen extends Screen { public X11Screen() { } - public void initNative() { + protected void createNative() { handle = GetScreen(display.getHandle(), index); if (handle == 0 ) { throw new RuntimeException("Error creating screen: "+index); diff --git a/src/classes/com/sun/javafx/newt/x11/X11Window.java b/src/classes/com/sun/javafx/newt/x11/X11Window.java index d9a6e07ba..63e558bbc 100755 --- a/src/classes/com/sun/javafx/newt/x11/X11Window.java +++ b/src/classes/com/sun/javafx/newt/x11/X11Window.java @@ -38,13 +38,7 @@ import com.sun.opengl.impl.*; public class X11Window extends Window { private static final String WINDOW_CLASS_NAME = "NewtWindow"; - // Default width and height -- will likely be re-set immediately by user - private int width = 100; - private int height = 100; - private int x=0; - private int y=0; // non fullscreen dimensions .. - private boolean fullscreen, visible; private int nfs_width, nfs_height, nfs_x, nfs_y; static { @@ -58,19 +52,22 @@ public class X11Window extends Window { public X11Window() { } - public void initNative() { - fullscreen=false; - visible=false; + protected void createNative() { long w = CreateWindow(getDisplayHandle(), getScreenHandle(), getScreenIndex(), visualID, x, y, width, height); if (w == 0 || w!=windowHandle) { throw new RuntimeException("Error creating window: "+w); } } + protected void closeNative() { + CloseWindow(getDisplayHandle(), windowHandle); + } + public void setVisible(boolean visible) { if(this.visible!=visible) { this.visible=visible; setVisible0(getDisplayHandle(), windowHandle, visible); + clearEventMask(); } } @@ -82,26 +79,6 @@ public class X11Window extends Window { setPosition0(getDisplayHandle(), windowHandle, x, y); } - public boolean isVisible() { - return visible; - } - - public int getX() { - return x; - } - - public int getY() { - return y; - } - - public int getWidth() { - return width; - } - - public int getHeight() { - return height; - } - public boolean setFullscreen(boolean fullscreen) { if(this.fullscreen!=fullscreen) { int x,y,w,h; @@ -122,14 +99,6 @@ public class X11Window extends Window { return true; } - public boolean isFullscreen() { - return fullscreen; - } - - public void pumpMessages() { - DispatchMessages(getDisplayHandle(), windowHandle); - } - public int getDisplayWidth() { return getDisplayWidth0(getDisplayHandle(), getScreenIndex()); } @@ -138,15 +107,20 @@ public class X11Window extends Window { return getDisplayHeight0(getDisplayHandle(), getScreenIndex()); } + public void dispatchMessages(int eventMask) { + DispatchMessages(getDisplayHandle(), windowHandle, eventMask); + } + //---------------------------------------------------------------------- // Internals only // private static native boolean initIDs(); private native long CreateWindow(long display, long screen, int screen_index, - int visualID, int x, int y, int width, int height); + long visualID, int x, int y, int width, int height); + private native void CloseWindow(long display, long windowHandle); private native void setVisible0(long display, long windowHandle, boolean visible); - private native void DispatchMessages(long display, long windowHandle); + private native void DispatchMessages(long display, long windowHandle, int eventMask); private native void setSize0(long display, long windowHandle, int width, int height); private native void setPosition0(long display, long windowHandle, int x, int y); private native int getDisplayWidth0(long display, int scrn_idx); @@ -170,7 +144,7 @@ public class X11Window extends Window { } } - private void windowCreated(int visualID, long windowHandle) { + private void windowCreated(long visualID, long windowHandle) { this.visualID = visualID; this.windowHandle = windowHandle; } |