diff options
author | Sven Gothel <[email protected]> | 2012-10-08 10:44:05 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-10-08 10:44:05 +0200 |
commit | f5612e7dfc635359f15b402c2ee9022a5e703a9d (patch) | |
tree | 0b54287f72b87a2693f38ed308195e928311a093 /src/jake2/sys | |
parent | 3119458b32c8620f971ba44488389ddf03b2d705 (diff) |
Simple NEWT port: Remove AWT dependencies in Jake2 / JOGL / Fast (default mode) - Prepare for ES2NEWT
- Removed AWT init dialog, replaced w/ UI less auto install if n/a @ default location:
$HOME/Jake2/baseq2
- JOGL GL2 Renderer 'joglgl2'
- JOGL ES2 Renderer 'jogles2' (TBD)
- Replaced JOGLKBD (AWT) w/ NEWTKBD
- JOGL* Renderer using NEWT
Diffstat (limited to 'src/jake2/sys')
-rw-r--r-- | src/jake2/sys/InputListener.java | 71 | ||||
-rw-r--r-- | src/jake2/sys/Jake2InputEvent.java | 6 | ||||
-rw-r--r-- | src/jake2/sys/KBD.java | 3 | ||||
-rw-r--r-- | src/jake2/sys/NEWTKBD.java (renamed from src/jake2/sys/JOGLKBD.java) | 117 |
4 files changed, 94 insertions, 103 deletions
diff --git a/src/jake2/sys/InputListener.java b/src/jake2/sys/InputListener.java index 8cbe2ae..3efece2 100644 --- a/src/jake2/sys/InputListener.java +++ b/src/jake2/sys/InputListener.java @@ -25,17 +25,17 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package jake2.sys; -import java.awt.event.*; +import com.jogamp.newt.event.*; + import java.util.LinkedList; /** * InputListener */ -public final class InputListener implements KeyListener, MouseListener, - MouseMotionListener, ComponentListener, MouseWheelListener { +public final class InputListener implements KeyListener, MouseListener, WindowListener { // modifications of eventQueue must be thread safe! - private static LinkedList eventQueue = new LinkedList(); + private static LinkedList<Jake2InputEvent> eventQueue = new LinkedList<Jake2InputEvent>(); static void addEvent(Jake2InputEvent ev) { synchronized (eventQueue) { @@ -51,67 +51,88 @@ public final class InputListener implements KeyListener, MouseListener, return ev; } + @Override public void keyPressed(KeyEvent e) { - if (!((e.getModifiersEx() & InputEvent.ALT_GRAPH_DOWN_MASK) != 0)) { - addEvent(new Jake2InputEvent(Jake2InputEvent.KeyPress, e)); - } + addEvent(new Jake2InputEvent(Jake2InputEvent.KeyPress, e)); } + @Override public void keyReleased(KeyEvent e) { - addEvent(new Jake2InputEvent(Jake2InputEvent.KeyRelease, e)); + addEvent(new Jake2InputEvent(Jake2InputEvent.KeyRelease, e)); } + @Override public void keyTyped(KeyEvent e) { - if ((e.getModifiersEx() & InputEvent.ALT_GRAPH_DOWN_MASK) != 0) { - addEvent(new Jake2InputEvent(Jake2InputEvent.KeyPress, e)); - addEvent(new Jake2InputEvent(Jake2InputEvent.KeyRelease, e)); - } } + @Override public void mouseClicked(MouseEvent e) { } + @Override public void mouseEntered(MouseEvent e) { } + @Override public void mouseExited(MouseEvent e) { } + @Override + public void mouseWheelMoved(MouseEvent e) { + addEvent(new Jake2InputEvent(Jake2InputEvent.WheelMoved, e)); + } + + @Override public void mousePressed(MouseEvent e) { addEvent(new Jake2InputEvent(Jake2InputEvent.ButtonPress, e)); } + @Override public void mouseReleased(MouseEvent e) { addEvent(new Jake2InputEvent(Jake2InputEvent.ButtonRelease, e)); } + @Override public void mouseDragged(MouseEvent e) { addEvent(new Jake2InputEvent(Jake2InputEvent.MotionNotify, e)); } + @Override public void mouseMoved(MouseEvent e) { addEvent(new Jake2InputEvent(Jake2InputEvent.MotionNotify, e)); } - public void componentHidden(ComponentEvent e) { - } - - public void componentMoved(ComponentEvent e) { + @Override + public void windowMoved(WindowEvent e) { addEvent(new Jake2InputEvent(Jake2InputEvent.ConfigureNotify, e)); } - public void componentResized(ComponentEvent e) { + @Override + public void windowResized(WindowEvent e) { addEvent(new Jake2InputEvent(Jake2InputEvent.ConfigureNotify, e)); } - public void componentShown(ComponentEvent e) { - JOGLKBD.c = e.getComponent(); - addEvent(new Jake2InputEvent(Jake2InputEvent.CreateNotify, e)); - } - - public void mouseWheelMoved(MouseWheelEvent e) { - addEvent(new Jake2InputEvent(Jake2InputEvent.WheelMoved, e)); - } + @Override + public void windowDestroyNotify(WindowEvent e) { + } + + @Override + public void windowDestroyed(WindowEvent e) { + } + + @Override + public void windowGainedFocus(WindowEvent e) { + addEvent(new Jake2InputEvent(Jake2InputEvent.ConfigureNotify, e)); + } + + @Override + public void windowLostFocus(WindowEvent e) { + } + + @Override + public void windowRepaint(WindowUpdateEvent e) { + addEvent(new Jake2InputEvent(Jake2InputEvent.ConfigureNotify, e)); + } } diff --git a/src/jake2/sys/Jake2InputEvent.java b/src/jake2/sys/Jake2InputEvent.java index 32becf9..cce63bc 100644 --- a/src/jake2/sys/Jake2InputEvent.java +++ b/src/jake2/sys/Jake2InputEvent.java @@ -25,7 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package jake2.sys; -import java.awt.AWTEvent; +import com.jogamp.newt.event.NEWTEvent; /** * Jake2InputEvent @@ -40,9 +40,9 @@ class Jake2InputEvent { static final int ConfigureNotify = 6; static final int WheelMoved = 7; int type; - AWTEvent ev; + NEWTEvent ev; - Jake2InputEvent(int type, AWTEvent ev) { + Jake2InputEvent(int type, NEWTEvent ev) { this.type = type; this.ev = ev; } diff --git a/src/jake2/sys/KBD.java b/src/jake2/sys/KBD.java index 2ed7ac0..33df0f4 100644 --- a/src/jake2/sys/KBD.java +++ b/src/jake2/sys/KBD.java @@ -31,9 +31,6 @@ package jake2.sys; */ abstract public class KBD { - static int win_x = 0; - static int win_y = 0; - // motion values public static int mx = 0; public static int my = 0; diff --git a/src/jake2/sys/JOGLKBD.java b/src/jake2/sys/NEWTKBD.java index dbf54fb..6b53254 100644 --- a/src/jake2/sys/JOGLKBD.java +++ b/src/jake2/sys/NEWTKBD.java @@ -1,40 +1,26 @@ package jake2.sys; -import jake2.Globals; import jake2.client.Key; -import java.awt.*; -import java.awt.event.*; +import com.jogamp.newt.Window; +import com.jogamp.newt.event.*; -import javax.swing.ImageIcon; - -final public class JOGLKBD extends KBD +final public class NEWTKBD extends KBD { - static Robot robot; public static InputListener listener = new InputListener(); - static Cursor emptyCursor = null; - static Component c = null; + // static Cursor emptyCursor = null; + static Window c = null; static int win_w2 = 0; static int win_h2 = 0; - static { - try { - robot = new Robot(); - } catch (AWTException e) { - if (!Globals.appletMode) { - System.exit(1); - } - } - } - public void Init() { } // Used only for the applet case - public static void Init(Component component) { - c = component; - handleCreateAndConfigureNotify(component); + public static void Init(Window window) { + c = window; + handleCreateAndConfigureNotify(window); } public void Update() { @@ -51,12 +37,17 @@ final public class JOGLKBD extends KBD Jake2InputEvent event; while ( (event=InputListener.nextEvent()) != null ) { + Window eventWin = null; + Object source = event.ev.getSource(); + if(source instanceof Window) { + eventWin = (Window)source; + } switch(event.type) { case Jake2InputEvent.KeyPress: case Jake2InputEvent.KeyRelease: - Do_Key_Event(XLateKey((KeyEvent)event.ev), event.type == Jake2InputEvent.KeyPress); + Do_Key_Event(XLateKeyCode((KeyEvent)event.ev), event.type == Jake2InputEvent.KeyPress); break; - + case Jake2InputEvent.MotionNotify: // if (IN.ignorefirst) { // IN.ignorefirst = false; @@ -70,7 +61,7 @@ final public class JOGLKBD extends KBD my = 0; } break; - // see java.awt.MouseEvent + case Jake2InputEvent.ButtonPress: key = mouseEventToKey((MouseEvent)event.ev); Do_Key_Event(key, true); @@ -82,7 +73,7 @@ final public class JOGLKBD extends KBD break; case Jake2InputEvent.WheelMoved: - int dir = ((MouseWheelEvent)event.ev).getWheelRotation(); + int dir = ((MouseEvent)event.ev).getWheelRotation(); if (dir > 0) { Do_Key_Event(Key.K_MWHEELDOWN, true); Do_Key_Event(Key.K_MWHEELDOWN, false); @@ -93,51 +84,26 @@ final public class JOGLKBD extends KBD break; case Jake2InputEvent.CreateNotify : - case Jake2InputEvent.ConfigureNotify : - handleCreateAndConfigureNotify(((ComponentEvent)event.ev).getComponent()); + case Jake2InputEvent.ConfigureNotify : + handleCreateAndConfigureNotify(eventWin); break; } } if (mx != 0 || my != 0) { // move the mouse to the window center again - robot.mouseMove(win_x + win_w2, win_y + win_h2); + c.warpPointer(c.getWidth()/2, c.getHeight()/2); } } - private static void handleCreateAndConfigureNotify(Component component) { - // Probably could unify this code better, but for now just - // leave the two code paths separate - if (!Globals.appletMode) { - win_x = 0; - win_y = 0; - win_w2 = component.getWidth() / 2; - win_h2 = component.getHeight() / 2; - int left = 0; int top = 0; - while (component != null) { - if (component instanceof Container) { - Insets insets = ((Container)component).getInsets(); - left += insets.left; - top += insets.top; - } - win_x += component.getX(); - win_y += component.getY(); - component = component.getParent(); - } - win_x += left; win_y += top; - win_w2 -= left / 2; win_h2 -= top / 2; - } else { - win_x = 0; - win_y = 0; + private static void handleCreateAndConfigureNotify(Window component) { + if(null != component) { win_w2 = component.getWidth() / 2; win_h2 = component.getHeight() / 2; - Point p = component.getLocationOnScreen(); - win_x = p.x; - win_y = p.y; } } - // strange button numbering in java.awt.MouseEvent + // Different NEWT button numbering: // BUTTON1(left) BUTTON2(center) BUTTON3(right) // K_MOUSE1 K_MOUSE3 K_MOUSE2 private final int mouseEventToKey(MouseEvent ev) { @@ -151,11 +117,9 @@ final public class JOGLKBD extends KBD } } - private static int XLateKey(KeyEvent ev) { - - int key = 0; + private static int XLateKeyCode(KeyEvent ev) { int code = ev.getKeyCode(); - + int key = 0; switch(code) { // 00626 case XK_KP_Page_Up: key = K_KP_PGUP; break; case KeyEvent.VK_PAGE_UP: key = Key.K_PGUP; break; @@ -221,40 +185,49 @@ final public class JOGLKBD extends KBD // toggle console for DE and US keyboards case KeyEvent.VK_DEAD_ACUTE: case KeyEvent.VK_CIRCUMFLEX: - case KeyEvent.VK_DEAD_CIRCUMFLEX: key = '`'; break; - + case KeyEvent.VK_DEAD_CIRCUMFLEX: + case KeyEvent.VK_BACK_QUOTE: + key='`'; + break; default: - key = ev.getKeyChar(); - - if (key >= 'A' && key <= 'Z') - key = key - 'A' + 'a'; - break; + if( KeyEvent.VK_0 <= code && code <= KeyEvent.VK_9 ) { + key = code - KeyEvent.VK_0 + '0'; + } + if( KeyEvent.VK_A <= code && code <= KeyEvent.VK_Z ) { + key = code - KeyEvent.VK_A + 'a'; + } } if (key > 255) key = 0; return key; - } - + } + public void Do_Key_Event(int key, boolean down) { Key.Event(key, down, Timer.Milliseconds()); } public void centerMouse() { - robot.mouseMove(win_x + win_w2, win_y + win_h2); + c.warpPointer(c.getWidth()/2, c.getHeight()/2); } public void installGrabs() { + /* if (emptyCursor == null) { ImageIcon emptyIcon = new ImageIcon(new byte[0]); emptyCursor = c.getToolkit().createCustomCursor(emptyIcon.getImage(), new Point(0, 0), "emptyCursor"); } c.setCursor(emptyCursor); - centerMouse(); + */ + c.setPointerVisible(false); + centerMouse(); } public void uninstallGrabs() { + /* c.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + */ + c.setPointerVisible(true); } } |