aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--make/build.xml5
-rwxr-xr-xmake/gl-es1.cfg4
-rw-r--r--src/classes/com/sun/javafx/newt/EventListener.java39
-rw-r--r--src/classes/com/sun/javafx/newt/InputEvent.java95
-rw-r--r--src/classes/com/sun/javafx/newt/KeyEvent.java275
-rw-r--r--src/classes/com/sun/javafx/newt/KeyListener.java42
-rw-r--r--src/classes/com/sun/javafx/newt/MouseEvent.java86
-rw-r--r--src/classes/com/sun/javafx/newt/MouseListener.java46
-rwxr-xr-xsrc/classes/com/sun/javafx/newt/Window.java149
-rwxr-xr-xsrc/classes/com/sun/javafx/newt/windows/WindowsWindow.java64
-rwxr-xr-xsrc/classes/com/sun/javafx/newt/x11/X11Window.java190
-rwxr-xr-xsrc/classes/com/sun/opengl/util/BufferUtil.java28
-rw-r--r--src/native/jogl/KeyEvent.h10
-rw-r--r--src/native/jogl/MouseEvent.h13
-rwxr-xr-xsrc/native/jogl/WindowsWindow.c47
-rwxr-xr-xsrc/native/jogl/X11Window.c333
16 files changed, 1401 insertions, 25 deletions
diff --git a/make/build.xml b/make/build.xml
index 608e02e30..c758b69c4 100644
--- a/make/build.xml
+++ b/make/build.xml
@@ -892,6 +892,8 @@
<include name="${rootrel.src.c.jogl}/Mixer.cpp" if="isWindows"/>
<!-- FIXME: the WindowsWindow should be moved to another library -->
<include name="${rootrel.src.c.jogl}/WindowsWindow.c" if="isWindows"/>
+ <!-- FIXME: the X11Window should be moved to another library -->
+ <include name="${rootrel.src.c.jogl}/X11Window.c" if="isX11"/>
<include name="${rootrel.generated.c.jogl}/*GL*.c" unless="jogl.noglnatives"/>
<include name="${rootrel.src.c.jogl}/XineramaHelper.c" if="isX11"/>
<!-- Xinerama supporting functions for Linux only (for now) -->
@@ -1013,6 +1015,9 @@
<!-- FIXME: this is temporary until we move this to another workspace -->
<javah destdir="../build/gensrc/native/jogl" classpath="${jogl.jar}" class="com.sun.javafx.newt.windows.WindowsWindow" />
+ <!-- FIXME: this is temporary until we move this to another workspace -->
+ <javah destdir="../build/gensrc/native/jogl" classpath="${jogl.jar}" class="com.sun.javafx.newt.x11.X11Window" />
+
<!-- Compile stuff -->
<antcall target="c.build" inheritRefs="true">
<param name="c.compiler.src.files" value="c.src.files.jogl"/>
diff --git a/make/gl-es1.cfg b/make/gl-es1.cfg
index 629d59330..19f33f3c4 100755
--- a/make/gl-es1.cfg
+++ b/make/gl-es1.cfg
@@ -179,8 +179,8 @@ CustomCCode #define GL_APICALL __declspec(dllimport)
CustomCCode #include <GLES/gl.h>
CustomCCode #include <GLES/glext.h>
CustomCCode #include <stdlib.h>
-CustomCCode /* Include missing function pointer typedef */
-CustomCCode typedef void (GL_APIENTRYP PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) (GLenum target, GLeglImageOES image);
+# CustomCCode /* Include missing function pointer typedef */
+# CustomCCode typedef void (GL_APIENTRYP PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) (GLenum target, GLeglImageOES image);
CustomCCode typedef int intptr_t;
diff --git a/src/classes/com/sun/javafx/newt/EventListener.java b/src/classes/com/sun/javafx/newt/EventListener.java
new file mode 100644
index 000000000..881d66b87
--- /dev/null
+++ b/src/classes/com/sun/javafx/newt/EventListener.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution 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 Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+
+package com.sun.javafx.newt;
+
+public interface EventListener
+{
+}
+
diff --git a/src/classes/com/sun/javafx/newt/InputEvent.java b/src/classes/com/sun/javafx/newt/InputEvent.java
new file mode 100644
index 000000000..e8644f953
--- /dev/null
+++ b/src/classes/com/sun/javafx/newt/InputEvent.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution 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 Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+
+package com.sun.javafx.newt;
+
+public abstract class InputEvent
+{
+ public static int SHIFT_MASK = 1 << 0;
+ public static int CTRL_MASK = 1 << 1;
+ public static int META_MASK = 1 << 2;
+ public static int ALT_MASK = 1 << 3;
+ public static int ALT_GRAPH_MASK = 1 << 5;
+
+ protected InputEvent(boolean sysEvent, Window source, long when, int modifiers) {
+ this.consumed=false;
+ this.sysEvent=sysEvent;
+ this.source=source;
+ this.when=when;
+ this.modifiers=modifiers;
+ }
+
+ protected boolean isSysEvent() {
+ return sysEvent;
+ }
+
+ public void consume() {
+ consumed=true;
+ }
+
+ public boolean isConsumed() {
+ return consumed;
+ }
+ public int getModifiers() {
+ return modifiers;
+ }
+ public long getWhen() {
+ return when;
+ }
+ public boolean isAltDown() {
+ return (modifiers&ALT_MASK)!=0;
+ }
+ public boolean isAltGraphDown() {
+ return (modifiers&ALT_GRAPH_MASK)!=0;
+ }
+ public boolean isControlDown() {
+ return (modifiers&CTRL_MASK)!=0;
+ }
+ public boolean isMetaDown() {
+ return (modifiers&META_MASK)!=0;
+ }
+ public boolean isShiftDown() {
+ return (modifiers&SHIFT_MASK)!=0;
+ }
+
+ public String toString() {
+ return "InputEvent[sys:"+sysEvent+", source:"+source+", when:"+when+", modifiers:"+modifiers+"]";
+ }
+
+ private boolean sysEvent, consumed;
+ private Window source;
+ private int modifiers;
+ private long when;
+
+}
+
diff --git a/src/classes/com/sun/javafx/newt/KeyEvent.java b/src/classes/com/sun/javafx/newt/KeyEvent.java
new file mode 100644
index 000000000..96df883df
--- /dev/null
+++ b/src/classes/com/sun/javafx/newt/KeyEvent.java
@@ -0,0 +1,275 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution 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 Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+
+package com.sun.javafx.newt;
+
+public class KeyEvent extends InputEvent
+{
+ protected KeyEvent(boolean sysEvent, int eventType, Window source, long when, int modifiers, int keyCode, char keyChar) {
+ super(sysEvent, source, when, modifiers);
+ this.eventType=eventType;
+ this.keyCode=keyCode;
+ this.keyChar=keyChar;
+ }
+ public KeyEvent(int eventType, Window source, long when, int modifiers, int keyCode, char keyChar) {
+ this(false, eventType, source, when, modifiers, keyCode, keyChar);
+ }
+
+ public int getEventType() {
+ return eventType;
+ }
+ public char getKeyChar() {
+ return keyChar;
+ }
+ public int getKeyCode() {
+ return keyCode;
+ }
+
+ public String toString() {
+ return "KeyEvent[code "+keyCode+", char "+keyChar+", "+super.toString();
+ }
+
+ public boolean isActionKey() {
+ switch (keyCode) {
+ case VK_HOME:
+ case VK_END:
+ case VK_PAGE_UP:
+ case VK_PAGE_DOWN:
+ case VK_UP:
+ case VK_DOWN:
+ case VK_LEFT:
+ case VK_RIGHT:
+
+ case VK_F1:
+ case VK_F2:
+ case VK_F3:
+ case VK_F4:
+ case VK_F5:
+ case VK_F6:
+ case VK_F7:
+ case VK_F8:
+ case VK_F9:
+ case VK_F10:
+ case VK_F11:
+ case VK_F12:
+ case VK_F13:
+ case VK_F14:
+ case VK_F15:
+ case VK_F16:
+ case VK_F17:
+ case VK_F18:
+ case VK_F19:
+ case VK_F20:
+ case VK_F21:
+ case VK_F22:
+ case VK_F23:
+ case VK_F24:
+ case VK_PRINTSCREEN:
+ case VK_CAPS_LOCK:
+ case VK_PAUSE:
+ case VK_INSERT:
+
+ case VK_HELP:
+ case VK_WINDOWS:
+ return true;
+ }
+ return false;
+ }
+
+ private int eventType;
+ private int keyCode;
+ private char keyChar;
+
+ public static final int EVENT_KEY_PRESSED = 1 << 0;
+ public static final int EVENT_KEY_RELEASED= 1 << 1;
+ public static final int EVENT_KEY_TYPED = 1 << 2;
+
+ /* Virtual key codes. */
+
+ public static final int VK_ENTER = '\n';
+ public static final int VK_BACK_SPACE = '\b';
+ public static final int VK_TAB = '\t';
+ public static final int VK_CANCEL = 0x03;
+ public static final int VK_CLEAR = 0x0C;
+ public static final int VK_SHIFT = 0x10;
+ public static final int VK_CONTROL = 0x11;
+ public static final int VK_ALT = 0x12;
+ public static final int VK_PAUSE = 0x13;
+ public static final int VK_CAPS_LOCK = 0x14;
+ public static final int VK_ESCAPE = 0x1B;
+ public static final int VK_SPACE = 0x20;
+ public static final int VK_PAGE_UP = 0x21;
+ public static final int VK_PAGE_DOWN = 0x22;
+ public static final int VK_END = 0x23;
+ public static final int VK_HOME = 0x24;
+
+ /**
+ * Constant for the non-numpad <b>left</b> arrow key.
+ */
+ public static final int VK_LEFT = 0x25;
+
+ /**
+ * Constant for the non-numpad <b>up</b> arrow key.
+ */
+ public static final int VK_UP = 0x26;
+
+ /**
+ * Constant for the non-numpad <b>right</b> arrow key.
+ */
+ public static final int VK_RIGHT = 0x27;
+
+ /**
+ * Constant for the non-numpad <b>down</b> arrow key.
+ */
+ public static final int VK_DOWN = 0x28;
+
+ /** Constant for the F1 function key. */
+ public static final int VK_F1 = 0x70;
+
+ /** Constant for the F2 function key. */
+ public static final int VK_F2 = 0x71;
+
+ /** Constant for the F3 function key. */
+ public static final int VK_F3 = 0x72;
+
+ /** Constant for the F4 function key. */
+ public static final int VK_F4 = 0x73;
+
+ /** Constant for the F5 function key. */
+ public static final int VK_F5 = 0x74;
+
+ /** Constant for the F6 function key. */
+ public static final int VK_F6 = 0x75;
+
+ /** Constant for the F7 function key. */
+ public static final int VK_F7 = 0x76;
+
+ /** Constant for the F8 function key. */
+ public static final int VK_F8 = 0x77;
+
+ /** Constant for the F9 function key. */
+ public static final int VK_F9 = 0x78;
+
+ /** Constant for the F10 function key. */
+ public static final int VK_F10 = 0x79;
+
+ /** Constant for the F11 function key. */
+ public static final int VK_F11 = 0x7A;
+
+ /** Constant for the F12 function key. */
+ public static final int VK_F12 = 0x7B;
+
+ /**
+ * Constant for the F13 function key.
+ * @since 1.2
+ */
+ /* F13 - F24 are used on IBM 3270 keyboard; use random range for constants. */
+ public static final int VK_F13 = 0xF000;
+
+ /**
+ * Constant for the F14 function key.
+ * @since 1.2
+ */
+ public static final int VK_F14 = 0xF001;
+
+ /**
+ * Constant for the F15 function key.
+ * @since 1.2
+ */
+ public static final int VK_F15 = 0xF002;
+
+ /**
+ * Constant for the F16 function key.
+ * @since 1.2
+ */
+ public static final int VK_F16 = 0xF003;
+
+ /**
+ * Constant for the F17 function key.
+ * @since 1.2
+ */
+ public static final int VK_F17 = 0xF004;
+
+ /**
+ * Constant for the F18 function key.
+ * @since 1.2
+ */
+ public static final int VK_F18 = 0xF005;
+
+ /**
+ * Constant for the F19 function key.
+ * @since 1.2
+ */
+ public static final int VK_F19 = 0xF006;
+
+ /**
+ * Constant for the F20 function key.
+ * @since 1.2
+ */
+ public static final int VK_F20 = 0xF007;
+
+ /**
+ * Constant for the F21 function key.
+ * @since 1.2
+ */
+ public static final int VK_F21 = 0xF008;
+
+ /**
+ * Constant for the F22 function key.
+ * @since 1.2
+ */
+ public static final int VK_F22 = 0xF009;
+
+ /**
+ * Constant for the F23 function key.
+ * @since 1.2
+ */
+ public static final int VK_F23 = 0xF00A;
+
+ /**
+ * Constant for the F24 function key.
+ * @since 1.2
+ */
+ public static final int VK_F24 = 0xF00B;
+
+ public static final int VK_PRINTSCREEN = 0x9A;
+ public static final int VK_INSERT = 0x9B;
+ public static final int VK_HELP = 0x9C;
+ public static final int VK_META = 0x9D;
+
+ public static final int VK_BACK_QUOTE = 0xC0;
+ public static final int VK_QUOTE = 0xDE;
+
+ public static final int VK_WINDOWS = 0x020C;
+}
+
diff --git a/src/classes/com/sun/javafx/newt/KeyListener.java b/src/classes/com/sun/javafx/newt/KeyListener.java
new file mode 100644
index 000000000..6f022c45a
--- /dev/null
+++ b/src/classes/com/sun/javafx/newt/KeyListener.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution 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 Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+
+package com.sun.javafx.newt;
+
+public interface KeyListener extends EventListener
+{
+ public void keyPressed(KeyEvent e);
+ public void keyReleased(KeyEvent e);
+ public void keyTyped(KeyEvent e) ;
+}
+
diff --git a/src/classes/com/sun/javafx/newt/MouseEvent.java b/src/classes/com/sun/javafx/newt/MouseEvent.java
new file mode 100644
index 000000000..99026bd7b
--- /dev/null
+++ b/src/classes/com/sun/javafx/newt/MouseEvent.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution 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 Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+
+package com.sun.javafx.newt;
+
+public class MouseEvent extends InputEvent
+{
+ public static final int BUTTON1 = 1;
+ public static final int BUTTON2 = 2;
+ public static final int BUTTON3 = 3;
+
+ protected MouseEvent(boolean sysEvent, int eventType, Window source, long when, int modifiers, int x, int y, int clickCount, int button)
+ {
+ super(sysEvent, source, when, modifiers);
+ this.eventType=eventType;
+ this.x=x;
+ this.y=y;
+ this.clickCount=clickCount;
+ this.button=button;
+ }
+ public MouseEvent(int eventType, Window source, long when, int modifiers, int x, int y, int clickCount, int button) {
+ this(false, eventType, source, when, modifiers, x, y, clickCount, button);
+ }
+
+ public int getEventType() {
+ return eventType;
+ }
+ public int getButton() {
+ return button;
+ }
+ public int getClickCount() {
+ return clickCount;
+ }
+ public int getX() {
+ return x;
+ }
+ public int getY() {
+ return y;
+ }
+
+ public String toString() {
+ return "MouseEvent["+x+"/"+y+", button "+button+", count "+clickCount+", "+super.toString();
+ }
+
+ private int eventType, x, y, clickCount, button;
+
+ public static final int EVENT_MOUSE_CLICKED = 1 << 0;
+ public static final int EVENT_MOUSE_ENTERED = 1 << 1;
+ public static final int EVENT_MOUSE_EXITED = 1 << 2;
+ public static final int EVENT_MOUSE_PRESSED = 1 << 3;
+ public static final int EVENT_MOUSE_RELEASED = 1 << 4;
+ public static final int EVENT_MOUSE_MOVED = 1 << 5;
+ public static final int EVENT_MOUSE_DRAGGED = 1 << 6;
+
+}
+
diff --git a/src/classes/com/sun/javafx/newt/MouseListener.java b/src/classes/com/sun/javafx/newt/MouseListener.java
new file mode 100644
index 000000000..f707979ba
--- /dev/null
+++ b/src/classes/com/sun/javafx/newt/MouseListener.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution 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 Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+
+package com.sun.javafx.newt;
+
+public interface MouseListener extends EventListener
+{
+ public void mouseClicked(MouseEvent e);
+ public void mouseEntered(MouseEvent e);
+ public void mouseExited(MouseEvent e);
+ public void mousePressed(MouseEvent e);
+ public void mouseReleased(MouseEvent e);
+ public void mouseMoved(MouseEvent e);
+ public void mouseDragged(MouseEvent e);
+}
+
diff --git a/src/classes/com/sun/javafx/newt/Window.java b/src/classes/com/sun/javafx/newt/Window.java
index c9437a196..2bfcf1265 100755
--- a/src/classes/com/sun/javafx/newt/Window.java
+++ b/src/classes/com/sun/javafx/newt/Window.java
@@ -33,6 +33,9 @@
package com.sun.javafx.newt;
+import java.util.ArrayList;
+import java.util.Iterator;
+
public abstract class Window {
/** OpenKODE window type */
public static final String KD = "KD";
@@ -47,7 +50,7 @@ public abstract class Window {
public static final String MACOSX = "MacOSX";
/** Creates a Window of the default type for the current operating system. */
- public static Window create() {
+ public static Window create(long visualID) {
String osName = System.getProperty("os.name");
String osNameLowerCase = osName.toLowerCase();
String windowType;
@@ -58,7 +61,9 @@ public abstract class Window {
} else {
windowType = X11;
}
- return create(windowType);
+ Window window = create(windowType);
+ window.initNative(visualID);
+ return window;
}
@@ -82,13 +87,149 @@ public abstract class Window {
}
}
- protected Window() {
- }
+ protected abstract void initNative(long visualID);
+ 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 int getWidth();
public abstract int getHeight();
+ public abstract int getX();
+ public abstract int getY();
public abstract boolean setFullscreen(boolean fullscreen);
+ public abstract boolean isFullscreen();
+ public abstract int getDisplayWidth();
+ public abstract int getDisplayHeight();
public abstract long getWindowHandle();
public abstract void pumpMessages();
+
+ //
+ // MouseListener Support
+ //
+
+ public synchronized void addMouseListener(MouseListener l) {
+ if(l == null) {
+ return;
+ }
+ mouseListener.add(l);
+ }
+
+ public synchronized void removeMouseListener(MouseListener l) {
+ if (l == null) {
+ return;
+ }
+ mouseListener.remove(l);
+ }
+
+ public synchronized MouseListener[] getMouseListeners() {
+ return (MouseListener[]) mouseListener.toArray();
+ }
+
+ private ArrayList mouseListener = new ArrayList();
+ private long lastMousePressed = 0;
+ private int lastMouseClickCount = 0;
+ public static final int ClickTimeout = 200;
+
+ private void sendMouseEvent(int eventType, int modifiers, int x, int y, int button) {
+ long when = System.currentTimeMillis();
+ MouseEvent eClicked = null;
+ MouseEvent e = null;
+
+ if(MouseEvent.EVENT_MOUSE_PRESSED==eventType) {
+ if(when-lastMousePressed<ClickTimeout) {
+ lastMouseClickCount++;
+ } else {
+ lastMouseClickCount=1;
+ }
+ lastMousePressed=when;
+ e = new MouseEvent(true, eventType, this, when,
+ modifiers, x, y, lastMouseClickCount, button);
+ } else if(MouseEvent.EVENT_MOUSE_RELEASED==eventType) {
+ e = new MouseEvent(true, eventType, this, when,
+ modifiers, x, y, lastMouseClickCount, button);
+ if(when-lastMousePressed<ClickTimeout) {
+ eClicked = new MouseEvent(true, MouseEvent.EVENT_MOUSE_CLICKED, this, when,
+ modifiers, x, y, lastMouseClickCount, button);
+ }
+ lastMouseClickCount=0;
+ lastMousePressed=0;
+ } else if(MouseEvent.EVENT_MOUSE_MOVED==eventType &&
+ 1==lastMouseClickCount) {
+ e = new MouseEvent(true, eventType, this, when,
+ modifiers, x, y, 1, button);
+ } else {
+ e = new MouseEvent(true, eventType, this, when,
+ modifiers, x, y, 0, button);
+ }
+
+ for(Iterator i = mouseListener.iterator(); i.hasNext(); ) {
+ switch(eventType) {
+ case MouseEvent.EVENT_MOUSE_ENTERED:
+ ((MouseListener)i.next()).mouseEntered(e);
+ break;
+ case MouseEvent.EVENT_MOUSE_EXITED:
+ ((MouseListener)i.next()).mouseExited(e);
+ break;
+ case MouseEvent.EVENT_MOUSE_PRESSED:
+ ((MouseListener)i.next()).mousePressed(e);
+ break;
+ case MouseEvent.EVENT_MOUSE_RELEASED:
+ ((MouseListener)i.next()).mouseReleased(e);
+ if(null!=eClicked) {
+ ((MouseListener)i.next()).mouseClicked(eClicked);
+ }
+ break;
+ case MouseEvent.EVENT_MOUSE_MOVED:
+ ((MouseListener)i.next()).mouseMoved(e);
+ break;
+ case MouseEvent.EVENT_MOUSE_DRAGGED:
+ ((MouseListener)i.next()).mouseDragged(e);
+ break;
+ }
+ }
+ }
+
+ //
+ // KeyListener Support
+ //
+
+ public synchronized void addKeyListener(KeyListener l) {
+ if(l == null) {
+ return;
+ }
+ keyListener.add(l);
+ }
+
+ public synchronized void removeKeyListener(KeyListener l) {
+ if (l == null) {
+ return;
+ }
+ keyListener.remove(l);
+ }
+
+ public synchronized KeyListener[] getKeyListeners() {
+ return (KeyListener[]) keyListener.toArray();
+ }
+
+ private ArrayList keyListener = new ArrayList();
+
+ private void sendKeyEvent(int eventType, int modifiers, int keyCode, char keyChar) {
+ KeyEvent e = new KeyEvent(true, eventType, this, System.currentTimeMillis(),
+ modifiers, keyCode, keyChar);
+ for(Iterator i = keyListener.iterator(); i.hasNext(); ) {
+ switch(eventType) {
+ case KeyEvent.EVENT_KEY_PRESSED:
+ ((KeyListener)i.next()).keyPressed(e);
+ break;
+ case KeyEvent.EVENT_KEY_RELEASED:
+ ((KeyListener)i.next()).keyReleased(e);
+ break;
+ case KeyEvent.EVENT_KEY_TYPED:
+ ((KeyListener)i.next()).keyTyped(e);
+ break;
+ }
+ }
+ }
}
+
diff --git a/src/classes/com/sun/javafx/newt/windows/WindowsWindow.java b/src/classes/com/sun/javafx/newt/windows/WindowsWindow.java
index dfe423096..faa26dcb7 100755
--- a/src/classes/com/sun/javafx/newt/windows/WindowsWindow.java
+++ b/src/classes/com/sun/javafx/newt/windows/WindowsWindow.java
@@ -37,12 +37,16 @@ import com.sun.javafx.newt.*;
import com.sun.opengl.impl.*;
public class WindowsWindow extends Window {
+ private boolean fullscreen, visible;
+ private long visualID;
private long 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;
+ private static final String WINDOW_CLASS_NAME = "NewtWindow";
static {
NativeLibLoader.loadCore();
@@ -51,18 +55,45 @@ public class WindowsWindow extends Window {
}
}
- public WindowsWindow() {
+ protected WindowsWindow() {
+ }
+
+ protected void initNative(long visualID) {
long wndClass = getWindowClass();
- window = CreateWindow(WINDOW_CLASS_NAME, getHInstance(), width, height);
+ fullscreen=false;
+ visible=false;
+ window = CreateWindow(WINDOW_CLASS_NAME, getHInstance(), visualID, x, y, width, height);
if (window == 0) {
throw new RuntimeException("Error creating window");
}
}
+ public void setVisible(boolean visible) {
+ if(this.visible!=visible) {
+ this.visible=visible;
+ setVisible0(window, visible);
+ }
+ }
+
public void setSize(int width, int height) {
setSize0(window, width, height);
}
+ 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;
}
@@ -72,7 +103,23 @@ public class WindowsWindow extends Window {
}
public boolean setFullscreen(boolean fullscreen) {
- return setFullScreen0(window, fullscreen);
+ if(this.fullscreen!=fullscreen) {
+ this.fullscreen=fullscreen;
+ return setFullScreen0(window, fullscreen);
+ }
+ return true;
+ }
+
+ public boolean isFullscreen() {
+ return fullscreen;
+ }
+
+ public int getDisplayWidth() {
+ return 640; // FIXME
+ }
+
+ public int getDisplayHeight() {
+ return 480; // FIXME
}
public long getWindowHandle() {
@@ -112,7 +159,9 @@ 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 width, int height);
+ private native long CreateWindow(String windowClassName, long hInstance, long visualID,
+ int x, int y, int width, int height);
+ private native void setVisible0(long window, boolean visible);
private static native void DispatchMessages(long window);
private native void setSize0(long window, int width, int height);
private native boolean setFullScreen0(long window, boolean fullscreen);
@@ -128,6 +177,11 @@ public class WindowsWindow extends Window {
height = newHeight;
}
+ private void positionChanged(int newX, int newY) {
+ x = newX;
+ y = newY;
+ }
+
private void windowClosed() {
}
diff --git a/src/classes/com/sun/javafx/newt/x11/X11Window.java b/src/classes/com/sun/javafx/newt/x11/X11Window.java
new file mode 100755
index 000000000..828f08eff
--- /dev/null
+++ b/src/classes/com/sun/javafx/newt/x11/X11Window.java
@@ -0,0 +1,190 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution 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 Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+
+package com.sun.javafx.newt.x11;
+
+import com.sun.javafx.newt.*;
+import com.sun.opengl.impl.*;
+
+public class X11Window extends Window {
+ private long visualID;
+ private long dpy, screen, 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 {
+ NativeLibLoader.loadCore();
+
+ if (!initIDs()) {
+ throw new RuntimeException("Failed to initialize jmethodIDs");
+ }
+ }
+
+ protected X11Window() {
+ }
+
+ protected void initNative(long visualID) {
+ fullscreen=false;
+ visible=false;
+ long w = CreateWindow(visualID, x, y, width, height);
+ if (w == 0 || w!=window) {
+ throw new RuntimeException("Error creating window: "+w);
+ }
+ }
+
+ public void setVisible(boolean visible) {
+ if(this.visible!=visible) {
+ this.visible=visible;
+ setVisible0(dpy, window, visible);
+ }
+ }
+
+ public void setSize(int width, int height) {
+ setSize0(dpy, window, width, height);
+ }
+
+ public void setPosition(int x, int y) {
+ setPosition0(dpy, window, 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;
+ this.fullscreen=fullscreen;
+ if(this.fullscreen) {
+ x = 0; y = 0;
+ w = getDisplayWidth0(dpy, screen);
+ h = getDisplayHeight0(dpy, screen);
+ } else {
+ x = nfs_x;
+ y = nfs_y;
+ w = nfs_width;
+ h = nfs_height;
+ }
+ setPosition0(dpy, window, x, y);
+ setSize0(dpy, window, w, h);
+ }
+ return true;
+ }
+
+ public boolean isFullscreen() {
+ return fullscreen;
+ }
+
+ public long getWindowHandle() {
+ return window;
+ }
+
+ public void pumpMessages() {
+ DispatchMessages(dpy, window);
+ }
+
+ public int getDisplayWidth() {
+ return getDisplayWidth0(dpy, screen);
+ }
+
+ public int getDisplayHeight() {
+ return getDisplayHeight0(dpy, screen);
+ }
+
+ //----------------------------------------------------------------------
+ // Internals only
+ //
+
+ private static native boolean initIDs();
+ private native long CreateWindow(long visualID, int x, int y, int width, int height);
+ private native void setVisible0(long display, long window, boolean visible);
+ private native void DispatchMessages(long display, long window);
+ private native void setSize0(long display, long window, int width, int height);
+ private native void setPosition0(long display, long window, int x, int y);
+ private native int getDisplayWidth0(long display, long screen);
+ private native int getDisplayHeight0(long display, long screen);
+
+ private void sizeChanged(int newWidth, int newHeight) {
+ width = newWidth;
+ height = newHeight;
+ if(!fullscreen) {
+ nfs_width=width;
+ nfs_height=height;
+ }
+ }
+
+ private void positionChanged(int newX, int newY) {
+ x = newX;
+ y = newY;
+ if(!fullscreen) {
+ nfs_x=x;
+ nfs_y=y;
+ }
+ }
+
+ private void windowCreated(long dpy, long scrn, long window) {
+ this.dpy = dpy;
+ this.screen = scrn;
+ this.window = window;
+ }
+
+ private void windowClosed() {
+ }
+
+ private void windowDestroyed() {
+ }
+
+}
diff --git a/src/classes/com/sun/opengl/util/BufferUtil.java b/src/classes/com/sun/opengl/util/BufferUtil.java
index 392a03974..f439df046 100755
--- a/src/classes/com/sun/opengl/util/BufferUtil.java
+++ b/src/classes/com/sun/opengl/util/BufferUtil.java
@@ -88,6 +88,13 @@ public class BufferUtil {
return bb;
}
+ public static ByteBuffer newByteBuffer(byte[] values) {
+ ByteBuffer bb = newByteBuffer(values.length);
+ bb.put(values);
+ bb.rewind();
+ return bb;
+ }
+
// FIXME: refactor dependencies on Java SE buffer classes
// /** Allocates a new direct DoubleBuffer with the specified number of
// elements. The returned buffer will have its byte order set to
@@ -105,6 +112,13 @@ public class BufferUtil {
return bb.asFloatBuffer();
}
+ public static FloatBuffer newFloatBuffer(float[] values) {
+ FloatBuffer bb = newFloatBuffer(values.length);
+ bb.put(values);
+ bb.rewind();
+ return bb;
+ }
+
/** Allocates a new direct IntBuffer with the specified number of
elements. The returned buffer will have its byte order set to
the host platform's native byte order. */
@@ -113,6 +127,13 @@ public class BufferUtil {
return bb.asIntBuffer();
}
+ public static IntBuffer newIntBuffer(int[] values) {
+ IntBuffer bb = newIntBuffer(values.length);
+ bb.put(values);
+ bb.rewind();
+ return bb;
+ }
+
// FIXME: refactor dependencies on Java SE buffer classes
// /** Allocates a new direct LongBuffer with the specified number of
// elements. The returned buffer will have its byte order set to
@@ -130,6 +151,13 @@ public class BufferUtil {
return bb.asShortBuffer();
}
+ public static ShortBuffer newShortBuffer(short[] values) {
+ ShortBuffer bb = newShortBuffer(values.length);
+ bb.put(values);
+ bb.rewind();
+ return bb;
+ }
+
// FIXME: refactor dependencies on Java SE buffer classes
// These are only used by the GLU implementation anyway, which
// mostly disappears in the embedded OpenGL case
diff --git a/src/native/jogl/KeyEvent.h b/src/native/jogl/KeyEvent.h
new file mode 100644
index 000000000..fed4636b1
--- /dev/null
+++ b/src/native/jogl/KeyEvent.h
@@ -0,0 +1,10 @@
+
+#ifndef _KEY_EVENT_H_
+#define _KEY_EVENT_H_
+
+#define EVENT_KEY_PRESSED (1 << 0)
+#define EVENT_KEY_RELEASED (1 << 1)
+// Send by Java: EVENT_KEY_TYPED (1 << 2)
+
+#endif
+
diff --git a/src/native/jogl/MouseEvent.h b/src/native/jogl/MouseEvent.h
new file mode 100644
index 000000000..13e805028
--- /dev/null
+++ b/src/native/jogl/MouseEvent.h
@@ -0,0 +1,13 @@
+
+#ifndef _MOUSE_EVENT_H_
+#define _MOUSE_EVENT_H_
+
+// Generated by Java: EVENT_MOUSE_CLICKED
+#define EVENT_MOUSE_ENTERED (1 << 1)
+#define EVENT_MOUSE_EXITED (1 << 2)
+#define EVENT_MOUSE_PRESSED (1 << 3)
+#define EVENT_MOUSE_RELEASED (1 << 4)
+#define EVENT_MOUSE_MOVED (1 << 5)
+// Generated by Java: EVENT_MOUSE_DRAGGED (1 << 6)
+
+#endif
diff --git a/src/native/jogl/WindowsWindow.c b/src/native/jogl/WindowsWindow.c
index 151666ab3..c33c68d3c 100755
--- a/src/native/jogl/WindowsWindow.c
+++ b/src/native/jogl/WindowsWindow.c
@@ -49,11 +49,15 @@ typedef int intptr_t;
#include "com_sun_javafx_newt_windows_WindowsWindow.h"
-static jmethodID keyDownID = NULL;
-static jmethodID keyUpID = NULL;
+#include "MouseEvent.h"
+#include "KeyEvent.h"
+
static jmethodID sizeChangedID = NULL;
+static jmethodID positionChangedID = NULL;
static jmethodID windowClosedID = NULL;
static jmethodID windowDestroyedID = NULL;
+static jmethodID sendMouseEventID = NULL;
+static jmethodID sendKeyEventID = NULL;
// This is set by DispatchMessages, below, and cleared when it exits
static JNIEnv* env = NULL;
@@ -97,12 +101,14 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
break;
case WM_KEYDOWN:
- (*env)->CallVoidMethod(env, window, keyDownID, (jlong) wParam);
+ (*env)->CallVoidMethod(env, obj, sendKeyEventID, (jint) EVENT_KEY_PRESSED,
+ (jint) 0, (jint) 0x28, (jchar) 0);
useDefWindowProc = 1;
break;
case WM_KEYUP:
- (*env)->CallVoidMethod(env, window, keyUpID, (jlong) wParam);
+ (*env)->CallVoidMethod(env, obj, sendKeyEventID, (jint) EVENT_KEY_PRESSED,
+ (jint) 0, (jint) 0x26, (jchar) 0);
useDefWindowProc = 1;
break;
@@ -111,6 +117,11 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
(*env)->CallVoidMethod(env, window, sizeChangedID, (jint) rc.right, (jint) rc.bottom);
break;
+ /* FIXME:
+ case WM_MOUSE_LALA:
+ (*env)->CallVoidMethod(env, obj, sendMouseEventID, (jint) eventType, (jint) mod,
+ (jint) x, (jint) y, (jint) button);
+ */
default:
useDefWindowProc = 1;
}
@@ -128,16 +139,18 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_initIDs
(JNIEnv *env, jclass clazz)
{
- keyDownID = (*env)->GetMethodID(env, clazz, "keyDown", "(J)V");
- keyUpID = (*env)->GetMethodID(env, clazz, "keyUp", "(J)V");
sizeChangedID = (*env)->GetMethodID(env, clazz, "sizeChanged", "(II)V");
+ positionChangedID = (*env)->GetMethodID(env, clazz, "positionChanged", "(II)V");
windowClosedID = (*env)->GetMethodID(env, clazz, "windowClosed", "()V");
windowDestroyedID = (*env)->GetMethodID(env, clazz, "windowDestroyed", "()V");
- if (keyDownID == NULL ||
- keyUpID == NULL ||
- sizeChangedID == NULL ||
+ sendMouseEventID = (*env)->GetMethodID(env, clazz, "sendMouseEvent", "(IIIII)V");
+ sendKeyEventID = (*env)->GetMethodID(env, clazz, "sendKeyEvent", "(IIIC)V");
+ if (sizeChangedID == NULL ||
+ positionChangedID == NULL ||
windowClosedID == NULL ||
- windowDestroyedID == NULL) {
+ windowDestroyedID == NULL ||
+ sendMouseEventID == NULL ||
+ sendKeyEventID == NULL) {
return JNI_FALSE;
}
return JNI_TRUE;
@@ -192,17 +205,20 @@ JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_RegisterW
/*
* Class: com_sun_javafx_newt_windows_WindowsWindow
* Method: CreateWindow
- * Signature: (Ljava/lang/String;II)J
+ * Signature: (Ljava/lang/String;JJIIII)J
*/
JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_CreateWindow
- (JNIEnv *env, jobject obj, jstring windowClassName, jlong hInstance, jint defaultWidth, jint defaultHeight)
+ (JNIEnv *env, jobject obj, jstring windowClassName, jlong hInstance, jlong visualID,
+ jint jx, jint jy, jint defaultWidth, jint defaultHeight)
{
jchar* wndClassName = GetNullTerminatedStringChars(env, windowClassName);
DWORD windowStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
- int x, y;
- int width, height;
+ int x=(int)x, y=(int)y;
+ int width=(int)defaultWidth, height=(int)defaultHeight;
HWND window = NULL;
+/** FIXME: why ? use setFullscreen() ..
+ *
#ifdef UNDER_CE
width = GetSystemMetrics(SM_CXSCREEN);
height = GetSystemMetrics(SM_CYSCREEN);
@@ -214,6 +230,9 @@ JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_CreateWin
width = defaultWidth;
height = defaultHeight;
#endif
+ */
+ (void) visualID; // FIXME: use the visualID ..
+
window = CreateWindowW(wndClassName, wndClassName, windowStyle,
x, y, width, height,
NULL, NULL,
diff --git a/src/native/jogl/X11Window.c b/src/native/jogl/X11Window.c
new file mode 100755
index 000000000..1c4200347
--- /dev/null
+++ b/src/native/jogl/X11Window.c
@@ -0,0 +1,333 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution 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 Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/keysym.h>
+
+#include "com_sun_javafx_newt_x11_X11Window.h"
+
+#include "MouseEvent.h"
+#include "KeyEvent.h"
+
+static jmethodID sizeChangedID = NULL;
+static jmethodID positionChangedID = NULL;
+static jmethodID windowClosedID = NULL;
+static jmethodID windowDestroyedID = NULL;
+static jmethodID windowCreatedID = NULL;
+static jmethodID sendMouseEventID = NULL;
+static jmethodID sendKeyEventID = NULL;
+
+// This is set by DispatchMessages, below, and cleared when it exits
+static JNIEnv* env = NULL;
+
+#if 0
+static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
+ WPARAM wParam, LPARAM lParam)
+{
+ RECT rc;
+ int useDefWindowProc = 0;
+ jobject window = NULL;
+
+ window = (jobject) GetWindowLongPtr(wnd, GWLP_USERDATA);
+ if (window == NULL || env == NULL) {
+ // Shouldn't happen
+ return DefWindowProc(wnd, message, wParam, lParam);
+ }
+
+ switch (message) {
+ case WM_CLOSE:
+ (*env)->CallVoidMethod(env, window, windowClosedID);
+ DestroyWindow(wnd);
+ break;
+
+ case WM_DESTROY:
+ (*env)->CallVoidMethod(env, window, windowDestroyedID);
+ break;
+
+ case WM_KEYDOWN:
+ (*env)->CallVoidMethod(env, window, keyDownID, (jlong) wParam);
+ useDefWindowProc = 1;
+ break;
+
+ case WM_KEYUP:
+ (*env)->CallVoidMethod(env, window, keyUpID, (jlong) wParam);
+ useDefWindowProc = 1;
+ break;
+
+ case WM_SIZE:
+ GetClientRect(wnd, &rc);
+ (*env)->CallVoidMethod(env, window, sizeChangedID, (jint) rc.right, (jint) rc.bottom);
+ break;
+
+ default:
+ useDefWindowProc = 1;
+ }
+
+ if (useDefWindowProc)
+ return DefWindowProc(wnd, message, wParam, lParam);
+ return 0;
+}
+#endif
+
+/*
+ * Class: com_sun_javafx_newt_x11_X11Window
+ * Method: initIDs
+ * Signature: ()Z
+ */
+JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_x11_X11Window_initIDs
+ (JNIEnv *env, jclass clazz)
+{
+ sizeChangedID = (*env)->GetMethodID(env, clazz, "sizeChanged", "(II)V");
+ positionChangedID = (*env)->GetMethodID(env, clazz, "positionChanged", "(II)V");
+ windowClosedID = (*env)->GetMethodID(env, clazz, "windowClosed", "()V");
+ windowDestroyedID = (*env)->GetMethodID(env, clazz, "windowDestroyed", "()V");
+ windowCreatedID = (*env)->GetMethodID(env, clazz, "windowCreated", "(JJJ)V");
+ sendMouseEventID = (*env)->GetMethodID(env, clazz, "sendMouseEvent", "(IIIII)V");
+ sendKeyEventID = (*env)->GetMethodID(env, clazz, "sendKeyEvent", "(IIIC)V");
+ if (sizeChangedID == NULL ||
+ positionChangedID == NULL ||
+ windowClosedID == NULL ||
+ windowDestroyedID == NULL ||
+ windowCreatedID == NULL ||
+ sendMouseEventID == NULL ||
+ sendKeyEventID == NULL) {
+ return JNI_FALSE;
+ }
+ return JNI_TRUE;
+}
+
+/*
+ * Class: com_sun_javafx_newt_x11_X11Window
+ * Method: CreateWindow
+ * Signature: (JIIII)J
+ */
+JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_x11_X11Window_CreateWindow
+ (JNIEnv *env, jobject obj, jlong visualID,
+ jint x, jint y, jint width, jint height)
+{
+ Display * dpy;
+ Screen * scrn;
+ Window windowParent = 0;
+ Window window = 0;
+
+ XVisualInfo visualTemplate;
+ XVisualInfo *pVisualQuery = NULL;
+ XSetWindowAttributes xswa;
+ unsigned long attrMask;
+
+ int n;
+
+ dpy = XOpenDisplay(NULL);
+ if(dpy==NULL) {
+ fprintf(stderr, "could not open X display ..\n");
+ return 0;
+ }
+
+ memset(&visualTemplate, 0, sizeof(XVisualInfo));
+ visualTemplate.visualid = (VisualID)visualID;
+
+ pVisualQuery = XGetVisualInfo(dpy, VisualIDMask, &visualTemplate,&n);
+ if (pVisualQuery==NULL)
+ {
+ fprintf(stderr, "could not query XVisualInfo ..\n");
+ return 0;
+ }
+
+ scrn = ScreenOfDisplay(dpy, pVisualQuery->screen);
+
+ windowParent = XRootWindowOfScreen(scrn);
+
+ attrMask = (CWBackPixel | CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect);
+ memset(&xswa, 0, sizeof(xswa));
+ xswa.override_redirect = True;
+ xswa.border_pixel = 0;
+ xswa.background_pixel = 0;
+ xswa.event_mask = ExposureMask | StructureNotifyMask | KeyPressMask | KeyReleaseMask;
+ xswa.colormap = XCreateColormap(dpy,
+ RootWindow(dpy, pVisualQuery->screen),
+ pVisualQuery->visual,
+ AllocNone);
+
+ window = XCreateWindow(dpy,
+ windowParent,
+ x, y,
+ width, height,
+ 0, // border width
+ pVisualQuery->depth,
+ InputOutput,
+ pVisualQuery->visual,
+ attrMask,
+ &xswa);
+ XFree(pVisualQuery);
+
+ (*env)->CallVoidMethod(env, obj, windowCreatedID, (jlong) (intptr_t) dpy, (jlong) (intptr_t) scrn, (jlong) window);
+
+ return (jlong) window;
+}
+
+/*
+ * Class: com_sun_javafx_newt_x11_X11Window
+ * Method: setVisible0
+ * Signature: (JJZ)V
+ */
+JNIEXPORT void JNICALL Java_com_sun_javafx_newt_x11_X11Window_setVisible0
+ (JNIEnv *env, jobject obj, jlong display, jlong window, jboolean visible)
+{
+ Display * dpy = (Display *) (intptr_t) display;
+ Window w = (Window)window;
+ if(visible==JNI_TRUE) {
+ XMapWindow(dpy, window);
+
+ XSelectInput(dpy, window, ButtonPressMask|ButtonRelease|PointerMotionMask|
+ KeyPressMask|KeyReleaseMask);
+ } else {
+ XSelectInput(dpy, window, 0);
+ XUnmapWindow(dpy, window);
+ }
+}
+
+/*
+ * Class: com_sun_javafx_newt_x11_X11Window
+ * Method: DispatchMessages
+ * Signature: (JJ)V
+ */
+JNIEXPORT void JNICALL Java_com_sun_javafx_newt_x11_X11Window_DispatchMessages
+ (JNIEnv *env, jobject obj, jlong display, jlong window)
+{
+ Display * dpy = (Display *) (intptr_t) display;
+ Window w = (Window)window;
+
+ // Periodically take a break
+ while( XPending(dpy)>0 ) {
+ int eventType;
+ XEvent evt;
+ int i;
+
+ XNextEvent(dpy, &evt);
+
+ switch(evt.type) {
+ case ButtonPress:
+ (*env)->CallVoidMethod(env, obj, sendMouseEventID, (jint) EVENT_MOUSE_PRESSED,
+ (jint) evt.xbutton.state,
+ (jint) evt.xbutton.x, (jint) evt.xbutton.y, (jint) evt.xbutton.button);
+ break;
+ case ButtonRelease:
+ (*env)->CallVoidMethod(env, obj, sendMouseEventID, (jint) EVENT_MOUSE_RELEASED,
+ (jint) evt.xbutton.state,
+ (jint) evt.xbutton.x, (jint) evt.xbutton.y, (jint) evt.xbutton.button);
+ break;
+ case MotionNotify:
+ (*env)->CallVoidMethod(env, obj, sendMouseEventID, (jint) EVENT_MOUSE_MOVED,
+ (jint) evt.xmotion.state,
+ (jint) evt.xmotion.x, (jint) evt.xmotion.y, (jint) 0);
+ break;
+ case KeyPress:
+ i = evt.xkey.keycode;
+ (*env)->CallVoidMethod(env, obj, sendKeyEventID, (jint) EVENT_KEY_PRESSED,
+ (jint) evt.xkey.state,
+ (jint) i, (jchar) ( isascii(i)?i:0 ) );
+ // evt.xkey
+ break;
+ case KeyRelease:
+ // evt.xkey
+ break;
+ case FocusIn:
+ // evt.xfocus
+ break;
+ case FocusOut:
+ // evt.xfocus
+ break;
+ }
+ }
+}
+
+/*
+ * Class: com_sun_javafx_newt_x11_X11Window
+ * Method: setSize0
+ * Signature: (JJII)V
+ */
+JNIEXPORT void JNICALL Java_com_sun_javafx_newt_x11_X11Window_setSize0
+ (JNIEnv *env, jobject obj, jlong display, jlong window, jint width, jint height)
+{
+ Display * dpy = (Display *) (intptr_t) display;
+ Window w = (Window)window;
+ XResizeWindow(dpy, w, (unsigned)width, (unsigned)height);
+ (*env)->CallVoidMethod(env, obj, sizeChangedID, (jint) width, (jint) height);
+}
+
+/*
+ * Class: com_sun_javafx_newt_x11_X11Window
+ * Method: setPosition0
+ * Signature: (JJII)V
+ */
+JNIEXPORT void JNICALL Java_com_sun_javafx_newt_x11_X11Window_setPosition0
+ (JNIEnv *env, jobject obj, jlong display, jlong window, jint x, jint y)
+{
+ Display * dpy = (Display *) (intptr_t) display;
+ Window w = (Window)window;
+ XMoveWindow(dpy, w, (unsigned)x, (unsigned)y);
+ // (*env)->CallVoidMethod(env, obj, positionChangedID, (jint) width, (jint) height);
+}
+
+/*
+ * Class: com_sun_javafx_newt_x11_X11Window
+ * Method: getDisplayWidth0
+ * Signature: (JJ)I
+ */
+JNIEXPORT jint JNICALL Java_com_sun_javafx_newt_x11_X11Window_getDisplayWidth0
+ (JNIEnv *env, jobject obj, jlong display, jlong screen)
+{
+ Display * dpy = (Display *) (intptr_t) display;
+ Screen * scrn = (Screen *) (intptr_t) screen;
+ return (jint) XDisplayWidth( dpy, scrn);
+}
+
+/*
+ * Class: com_sun_javafx_newt_x11_X11Window
+ * Method: getDisplayHeight0
+ * Signature: (JJ)I
+ */
+JNIEXPORT jint JNICALL Java_com_sun_javafx_newt_x11_X11Window_getDisplayHeight0
+ (JNIEnv *env, jobject obj, jlong display, jlong screen)
+{
+ Display * dpy = (Display *) (intptr_t) display;
+ Screen * scrn = (Screen *) (intptr_t) screen;
+ return (jint) XDisplayHeight( dpy, scrn);
+}
+
+