aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/jake2/client/VID.java24
-rw-r--r--src/jake2/client/refexport_t.java5
-rw-r--r--src/jake2/render/FastJoglRenderer.java10
-rw-r--r--src/jake2/render/JoglBase.java13
-rw-r--r--src/jake2/render/JoglRenderer.java14
-rw-r--r--src/jake2/sys/IN.java51
-rw-r--r--src/jake2/sys/InputListener.java4
-rw-r--r--src/jake2/sys/JOGLKBD.java219
-rw-r--r--src/jake2/sys/KBD.java204
-rw-r--r--src/jake2/sys/LWJGLKBD.java186
-rw-r--r--src/jake2/sys/Sys.java4
11 files changed, 489 insertions, 245 deletions
diff --git a/src/jake2/client/VID.java b/src/jake2/client/VID.java
index b77128b..5dc39d5 100644
--- a/src/jake2/client/VID.java
+++ b/src/jake2/client/VID.java
@@ -2,7 +2,7 @@
* VID.java
* Copyright (C) 2003
*
- * $Id: VID.java,v 1.9 2004-08-23 20:49:12 hzi Exp $
+ * $Id: VID.java,v 1.10 2004-12-14 00:11:10 hzi Exp $
*/
/*
Copyright (C) 1997-2001 Id Software, Inc.
@@ -33,7 +33,6 @@ import jake2.qcommon.*;
import jake2.render.Renderer;
import jake2.sound.S;
import jake2.sys.IN;
-import jake2.sys.KBD;
import jake2.util.Vargs;
import java.awt.Dimension;
@@ -155,7 +154,7 @@ public class VID extends Globals {
static void FreeReflib()
{
if (Globals.re != null) {
- KBD.Close();
+ Globals.re.getKeyboardHandler().Close();
IN.Shutdown();
}
@@ -173,7 +172,7 @@ public class VID extends Globals {
if ( reflib_active )
{
- KBD.Close();
+ Globals.re.getKeyboardHandler().Close();
IN.Shutdown();
Globals.re.Shutdown();
@@ -221,7 +220,7 @@ public class VID extends Globals {
}
/* Init KBD */
- KBD.Init();
+ Globals.re.getKeyboardHandler().Init();
Com.Printf( "------------------------------------\n");
reflib_active = true;
@@ -329,7 +328,7 @@ public class VID extends Globals {
{
if ( reflib_active )
{
- KBD.Close();
+ Globals.re.getKeyboardHandler().Close();
IN.Shutdown();
Globals.re.Shutdown();
@@ -345,6 +344,7 @@ public class VID extends Globals {
static final int REF_OPENGL_JOGL = 0;
static final int REF_OPENGL_FASTJOGL =1;
+ static final int REF_OPENGL_LWJGL =2;
static cvar_t gl_mode;
static cvar_t gl_driver;
@@ -531,6 +531,12 @@ public class VID extends Globals {
if (gl_driver.modified)
vid_ref.modified = true;
break;
+ case REF_OPENGL_LWJGL :
+ Cvar.Set( "vid_ref", "lwjgl" );
+ Cvar.Set( "gl_driver", "lwjgl" );
+ if (gl_driver.modified)
+ vid_ref.modified = true;
+ break;
}
Menu.ForceMenuOff();
@@ -565,6 +571,7 @@ public class VID extends Globals {
// "[Mesa 3-D glX ]",
"[OpenGL jogl ]",
"[OpenGL fastjogl]",
+ "[OpenGL lwjgl]",
null
};
static final String[] yesno_names =
@@ -658,6 +665,11 @@ public class VID extends Globals {
s_current_menu_index = OPENGL_MENU;
s_ref_list[0].curvalue = s_ref_list[1].curvalue = REF_OPENGL_FASTJOGL;
}
+ else if ( vid_ref.string.equalsIgnoreCase("lwjgl"))
+ {
+ s_current_menu_index = OPENGL_MENU;
+ s_ref_list[0].curvalue = s_ref_list[1].curvalue = REF_OPENGL_LWJGL;
+ }
// else if (strcmp( vid_ref->string, "softx" ) == 0 )
// {
// s_current_menu_index = SOFTWARE_MENU;
diff --git a/src/jake2/client/refexport_t.java b/src/jake2/client/refexport_t.java
index 340a8c0..a5c3b25 100644
--- a/src/jake2/client/refexport_t.java
+++ b/src/jake2/client/refexport_t.java
@@ -2,7 +2,7 @@
* refexport_t.java
* Copyright (C) 2003
*
- * $Id: refexport_t.java,v 1.2 2004-07-15 14:37:35 hzi Exp $
+ * $Id: refexport_t.java,v 1.3 2004-12-14 00:11:10 hzi Exp $
*/
/*
Copyright (C) 1997-2001 Id Software, Inc.
@@ -29,6 +29,7 @@ package jake2.client;
import jake2.qcommon.xcommand_t;
import jake2.render.image_t;
import jake2.render.model_t;
+import jake2.sys.KBD;
import java.awt.Dimension;
import java.awt.DisplayMode;
@@ -107,4 +108,6 @@ public interface refexport_t {
int apiVersion();
DisplayMode[] getModeList();
+
+ KBD getKeyboardHandler();
}
diff --git a/src/jake2/render/FastJoglRenderer.java b/src/jake2/render/FastJoglRenderer.java
index e333c10..7ec8d7e 100644
--- a/src/jake2/render/FastJoglRenderer.java
+++ b/src/jake2/render/FastJoglRenderer.java
@@ -2,7 +2,7 @@
* FastJoglRenderer.java
* Copyright (C) 2003
*
- * $Id: FastJoglRenderer.java,v 1.3 2004-07-16 10:11:34 cawe Exp $
+ * $Id: FastJoglRenderer.java,v 1.4 2004-12-14 00:11:09 hzi Exp $
*/
/*
Copyright (C) 1997-2001 Id Software, Inc.
@@ -29,6 +29,8 @@ import jake2.Defines;
import jake2.client.*;
import jake2.qcommon.xcommand_t;
import jake2.render.fastjogl.Misc;
+import jake2.sys.JOGLKBD;
+import jake2.sys.KBD;
import java.awt.Dimension;
@@ -39,6 +41,8 @@ import java.awt.Dimension;
*/
final class FastJoglRenderer extends Misc implements refexport_t, Ref {
+ private JOGLKBD kbd=new JOGLKBD();
+
public static final String DRIVER_NAME = "fastjogl";
static {
@@ -304,4 +308,8 @@ final class FastJoglRenderer extends Misc implements refexport_t, Ref {
return this;
}
+ public KBD getKeyboardHandler()
+ {
+ return kbd;
+ }
} \ No newline at end of file
diff --git a/src/jake2/render/JoglBase.java b/src/jake2/render/JoglBase.java
index 4388209..075e306 100644
--- a/src/jake2/render/JoglBase.java
+++ b/src/jake2/render/JoglBase.java
@@ -2,7 +2,7 @@
* JoglCommon.java
* Copyright (C) 2004
*
- * $Id: JoglBase.java,v 1.12 2004-11-03 08:53:27 hzi Exp $
+ * $Id: JoglBase.java,v 1.13 2004-12-14 00:11:09 hzi Exp $
*/
/*
Copyright (C) 1997-2001 Id Software, Inc.
@@ -31,6 +31,7 @@ import jake2.client.*;
import jake2.game.cvar_t;
import jake2.qcommon.Cbuf;
import jake2.qcommon.xcommand_t;
+import jake2.sys.JOGLKBD;
import jake2.sys.KBD;
import java.awt.*;
@@ -227,11 +228,11 @@ public abstract class JoglBase implements GLEventListener {
});
// D I F F E R E N T J A K E 2 E V E N T P R O C E S S I N G
- window.addComponentListener(KBD.listener);
- canvas.addKeyListener(KBD.listener);
- canvas.addMouseListener(KBD.listener);
- canvas.addMouseMotionListener(KBD.listener);
- canvas.addMouseWheelListener(KBD.listener);
+ window.addComponentListener(JOGLKBD.listener);
+ canvas.addKeyListener(JOGLKBD.listener);
+ canvas.addMouseListener(JOGLKBD.listener);
+ canvas.addMouseMotionListener(JOGLKBD.listener);
+ canvas.addMouseWheelListener(JOGLKBD.listener);
if (fullscreen) {
diff --git a/src/jake2/render/JoglRenderer.java b/src/jake2/render/JoglRenderer.java
index 4aa619d..f381879 100644
--- a/src/jake2/render/JoglRenderer.java
+++ b/src/jake2/render/JoglRenderer.java
@@ -2,7 +2,7 @@
* JoglRenderer.java
* Copyright (C) 2003
*
- * $Id: JoglRenderer.java,v 1.5 2004-07-16 10:11:34 cawe Exp $
+ * $Id: JoglRenderer.java,v 1.6 2004-12-14 00:11:03 hzi Exp $
*/
/*
Copyright (C) 1997-2001 Id Software, Inc.
@@ -26,9 +26,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
package jake2.render;
import jake2.Defines;
-import jake2.client.*;
+import jake2.client.refdef_t;
+import jake2.client.refexport_t;
import jake2.qcommon.xcommand_t;
import jake2.render.jogl.Misc;
+import jake2.sys.JOGLKBD;
+import jake2.sys.KBD;
import java.awt.Dimension;
@@ -39,6 +42,8 @@ import java.awt.Dimension;
*/
final class JoglRenderer extends Misc implements refexport_t, Ref {
+ private JOGLKBD kbd=new JOGLKBD();
+
public static final String DRIVER_NAME = "jogl";
static {
@@ -301,4 +306,9 @@ final class JoglRenderer extends Misc implements refexport_t, Ref {
public refexport_t GetRefAPI() {
return this;
}
+
+ public KBD getKeyboardHandler()
+ {
+ return kbd;
+ }
} \ No newline at end of file
diff --git a/src/jake2/sys/IN.java b/src/jake2/sys/IN.java
index 2c70d53..4723d3e 100644
--- a/src/jake2/sys/IN.java
+++ b/src/jake2/sys/IN.java
@@ -2,7 +2,7 @@
* IN.java
* Copyright (C) 2003
*
- * $Id: IN.java,v 1.5 2004-09-22 19:22:14 salomo Exp $
+ * $Id: IN.java,v 1.6 2004-12-14 00:11:01 hzi Exp $
*/
/*
Copyright (C) 1997-2001 Id Software, Inc.
@@ -45,10 +45,6 @@ import javax.swing.ImageIcon;
*/
public final class IN extends Globals {
- static Component c = null;
-
- static Cursor emptyCursor = null;
-
static boolean mouse_avail = true;
static boolean mouse_active = false;
@@ -66,7 +62,7 @@ public final class IN extends Globals {
static boolean mlooking;
public static void ActivateMouse() {
- if (!mouse_avail || c == null)
+ if (!mouse_avail)
return;
if (!mouse_active) {
KBD.mx = KBD.my = 0; // don't spazz
@@ -84,19 +80,15 @@ public final class IN extends Globals {
}
private static void install_grabs() {
- if (emptyCursor == null) {
- ImageIcon emptyIcon = new ImageIcon(new byte[0]);
- emptyCursor = c.getToolkit().createCustomCursor(
- emptyIcon.getImage(), new Point(0, 0), "emptyCursor");
- }
- c.setCursor(emptyCursor);
- KBD.centerMouse();
- ignorefirst = true;
+ Globals.re.getKeyboardHandler().installGrabs();
+ Globals.re.getKeyboardHandler().centerMouse();
+
+ ignorefirst = true;
}
private static void uninstall_grabs() {
- c.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+ Globals.re.getKeyboardHandler().uninstallGrabs();
}
public static void toggleMouse() {
@@ -157,21 +149,20 @@ public final class IN extends Globals {
}
public static void Commands() {
- int i;
-
- if (!IN.mouse_avail)
- return;
-
- for (i = 0; i < 3; i++) {
- if ((IN.mouse_buttonstate & (1 << i)) != 0
- && (IN.mouse_oldbuttonstate & (1 << i)) == 0)
- KBD.Do_Key_Event(Key.K_MOUSE1 + i, true);
-
- if ((IN.mouse_buttonstate & (1 << i)) == 0
- && (IN.mouse_oldbuttonstate & (1 << i)) != 0)
- KBD.Do_Key_Event(Key.K_MOUSE1 + i, false);
- }
- IN.mouse_oldbuttonstate = IN.mouse_buttonstate;
+ int i;
+
+ if (!IN.mouse_avail)
+ return;
+
+ KBD kbd=Globals.re.getKeyboardHandler();
+ for (i=0 ; i<3 ; i++) {
+ if ( (IN.mouse_buttonstate & (1<<i)) != 0 && (IN.mouse_oldbuttonstate & (1<<i)) == 0 )
+ kbd.Do_Key_Event(Key.K_MOUSE1 + i, true);
+
+ if ( (IN.mouse_buttonstate & (1<<i)) == 0 && (IN.mouse_oldbuttonstate & (1<<i)) != 0 )
+ kbd.Do_Key_Event(Key.K_MOUSE1 + i, false);
+ }
+ IN.mouse_oldbuttonstate = IN.mouse_buttonstate;
}
public static void Frame() {
diff --git a/src/jake2/sys/InputListener.java b/src/jake2/sys/InputListener.java
index 2c60b38..2e2b57d 100644
--- a/src/jake2/sys/InputListener.java
+++ b/src/jake2/sys/InputListener.java
@@ -2,7 +2,7 @@
* InputListener.java
* Copyright (C) 2004
*
- * $Id: InputListener.java,v 1.3 2004-11-03 08:53:27 hzi Exp $
+ * $Id: InputListener.java,v 1.4 2004-12-14 00:11:01 hzi Exp $
*/
/*
Copyright (C) 1997-2001 Id Software, Inc.
@@ -99,7 +99,7 @@ public final class InputListener implements KeyListener, MouseListener,
}
public void componentShown(ComponentEvent e) {
- IN.c = e.getComponent();
+ JOGLKBD.c = e.getComponent();
addEvent(new Jake2InputEvent(Jake2InputEvent.CreateNotify, e));
}
diff --git a/src/jake2/sys/JOGLKBD.java b/src/jake2/sys/JOGLKBD.java
new file mode 100644
index 0000000..18fccad
--- /dev/null
+++ b/src/jake2/sys/JOGLKBD.java
@@ -0,0 +1,219 @@
+package jake2.sys;
+
+import jake2.client.Key;
+
+import java.awt.AWTException;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Cursor;
+import java.awt.Insets;
+import java.awt.Point;
+import java.awt.Robot;
+import java.awt.event.ComponentEvent;
+import java.awt.event.InputEvent;
+import java.awt.event.KeyEvent;
+import java.awt.event.MouseEvent;
+
+import javax.swing.ImageIcon;
+
+final public class JOGLKBD extends KBD
+{
+ static Robot robot;
+ public static InputListener listener = new InputListener();
+ static Cursor emptyCursor = null;
+ static Component c = null;
+
+ static int win_w2 = 0;
+ static int win_h2 = 0;
+
+ static {
+ try {
+ robot = new Robot();
+ } catch (AWTException e) {
+ System.exit(1);
+ }
+ }
+
+ public void Init() {
+ }
+
+ public void Update() {
+ // get events
+ HandleEvents();
+ }
+
+ public void Close() {
+ }
+
+ private void HandleEvents()
+ {
+ int b;
+
+ Jake2InputEvent event;
+ while ( (event=InputListener.nextEvent()) != null ) {
+ switch(event.type) {
+ case Jake2InputEvent.KeyPress:
+ case Jake2InputEvent.KeyRelease:
+ Do_Key_Event(XLateKey((KeyEvent)event.ev), event.type == Jake2InputEvent.KeyPress);
+ break;
+
+ case Jake2InputEvent.MotionNotify:
+// if (IN.ignorefirst) {
+// IN.ignorefirst = false;
+// break;
+// }
+ if (IN.mouse_active) {
+ mx = (((MouseEvent)event.ev).getX() - win_w2) * 2;
+ my = (((MouseEvent)event.ev).getY() - win_h2) * 2;
+ } else {
+ mx = 0;
+ my = 0;
+ }
+ break;
+
+ case Jake2InputEvent.ButtonPress:
+ b=((MouseEvent)event.ev).getButton()-1;
+ Do_Key_Event(Key.K_MOUSE1 + b, true);
+ break;
+
+ case Jake2InputEvent.ButtonRelease:
+ b=((MouseEvent)event.ev).getButton()-1;
+ Do_Key_Event(Key.K_MOUSE1 + b, false);
+ break;
+
+ case Jake2InputEvent.CreateNotify :
+ case Jake2InputEvent.ConfigureNotify :
+ Component c = ((ComponentEvent)event.ev).getComponent();
+ win_x = 0;
+ win_y = 0;
+ win_w2 = c.getWidth() / 2;
+ win_h2 = c.getHeight() / 2;
+ while (c != null) {
+ if (c instanceof Container) {
+ Insets insets = ((Container)c).getInsets();
+ win_x += insets.left;
+ win_y += insets.top;
+ }
+ win_x += c.getX();
+ win_y += c.getY();
+ c = c.getParent();
+ }
+ break;
+ }
+ }
+
+ if (mx != 0 || my != 0) {
+ // move the mouse to the window center again
+ robot.mouseMove(win_x + win_w2, win_y + win_h2);
+ }
+ }
+
+ private static int XLateKey(KeyEvent ev) {
+
+ int key = 0;
+ int code = ev.getKeyCode();
+
+ switch(code) {
+// 00626 case XK_KP_Page_Up: key = K_KP_PGUP; break;
+ case KeyEvent.VK_PAGE_UP: key = Key.K_PGUP; break;
+
+// 00629 case XK_KP_Page_Down: key = K_KP_PGDN; break;
+ case KeyEvent.VK_PAGE_DOWN: key = Key.K_PGDN; break;
+
+// 00632 case XK_KP_Home: key = K_KP_HOME; break;
+ case KeyEvent.VK_HOME: key = Key.K_HOME; break;
+
+// 00635 case XK_KP_End: key = K_KP_END; break;
+ case KeyEvent.VK_END: key = Key.K_END; break;
+
+ case KeyEvent.VK_KP_LEFT: key = Key.K_KP_LEFTARROW; break;
+ case KeyEvent.VK_LEFT: key = Key.K_LEFTARROW; break;
+
+ case KeyEvent.VK_KP_RIGHT: key = Key.K_KP_RIGHTARROW; break;
+ case KeyEvent.VK_RIGHT: key = Key.K_RIGHTARROW; break;
+
+ case KeyEvent.VK_KP_DOWN: key = Key.K_KP_DOWNARROW; break;
+ case KeyEvent.VK_DOWN: key = Key.K_DOWNARROW; break;
+
+ case KeyEvent.VK_KP_UP: key = Key.K_KP_UPARROW; break;
+ case KeyEvent.VK_UP: key = Key.K_UPARROW; break;
+
+ case KeyEvent.VK_ESCAPE: key = Key.K_ESCAPE; break;
+
+
+ case KeyEvent.VK_ENTER: key = Key.K_ENTER; break;
+// 00652 case XK_KP_Enter: key = K_KP_ENTER; break;
+
+ case KeyEvent.VK_TAB: key = Key.K_TAB; break;
+
+ case KeyEvent.VK_F1: key = Key.K_F1; break;
+ case KeyEvent.VK_F2: key = Key.K_F2; break;
+ case KeyEvent.VK_F3: key = Key.K_F3; break;
+ case KeyEvent.VK_F4: key = Key.K_F4; break;
+ case KeyEvent.VK_F5: key = Key.K_F5; break;
+ case KeyEvent.VK_F6: key = Key.K_F6; break;
+ case KeyEvent.VK_F7: key = Key.K_F7; break;
+ case KeyEvent.VK_F8: key = Key.K_F8; break;
+ case KeyEvent.VK_F9: key = Key.K_F9; break;
+ case KeyEvent.VK_F10: key = Key.K_F10; break;
+ case KeyEvent.VK_F11: key = Key.K_F11; break;
+ case KeyEvent.VK_F12: key = Key.K_F12; break;
+
+ case KeyEvent.VK_BACK_SPACE: key = Key.K_BACKSPACE; break;
+
+ case KeyEvent.VK_DELETE: key = Key.K_DEL; break;
+// 00683 case XK_KP_Delete: key = K_KP_DEL; break;
+
+ case KeyEvent.VK_PAUSE: key = Key.K_PAUSE; break;
+
+ case KeyEvent.VK_SHIFT: key = Key.K_SHIFT; break;
+ case KeyEvent.VK_CONTROL: key = Key.K_CTRL; break;
+
+ case KeyEvent.VK_ALT:
+ case KeyEvent.VK_ALT_GRAPH: key = Key.K_ALT; break;
+
+// 00700 case XK_KP_Begin: key = K_KP_5; break;
+// 00701
+ case KeyEvent.VK_INSERT: key = Key.K_INS; break;
+ // toggle console for DE and US keyboards
+ case KeyEvent.VK_DEAD_ACUTE:
+ case KeyEvent.VK_CIRCUMFLEX:
+ case KeyEvent.VK_DEAD_CIRCUMFLEX: key = '`'; break;
+
+ default:
+ if ((ev.getModifiers() & (InputEvent.ALT_MASK | InputEvent.CTRL_MASK)) != 0) {
+ key = ev.getKeyCode();
+ } else {
+ key = ev.getKeyChar();
+ }
+ if (key >= 'A' && key <= 'Z')
+ key = key - 'A' + 'a';
+ break;
+ }
+ if (key > 255) key = 0;
+
+ return key;
+ }
+
+ public void Do_Key_Event(int key, boolean down) {
+ Key.Event(key, down, Sys.Milliseconds());
+ }
+
+ public void centerMouse() {
+ robot.mouseMove(win_x + win_w2, win_y + win_h2);
+ }
+
+ 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);
+ }
+
+ public void uninstallGrabs()
+ {
+ c.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+ }
+}
diff --git a/src/jake2/sys/KBD.java b/src/jake2/sys/KBD.java
index 3272090..426778d 100644
--- a/src/jake2/sys/KBD.java
+++ b/src/jake2/sys/KBD.java
@@ -2,7 +2,7 @@
* KBD.java
* Copyright (C) 2004
*
- * $Id: KBD.java,v 1.5 2004-11-03 10:16:42 hzi Exp $
+ * $Id: KBD.java,v 1.6 2004-12-14 00:11:01 hzi Exp $
*/
/*
Copyright (C) 1997-2001 Id Software, Inc.
@@ -25,214 +25,28 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package jake2.sys;
-import jake2.client.Key;
-
-import java.awt.*;
-import java.awt.event.*;
/**
* KBD
*/
-public final class KBD {
+abstract public class KBD {
static int win_x = 0;
static int win_y = 0;
- static int win_w2 = 0;
- static int win_h2 = 0;
// motion values
public static int mx = 0;
public static int my = 0;
- static Robot robot;
- public static InputListener listener = new InputListener();
-
- static {
- try {
- robot = new Robot();
- } catch (AWTException e) {
- System.exit(1);
- }
- }
-
- public static void Init() {
- }
-
- public static void Update() {
- // get events
- HandleEvents();
- }
-
- public static void Close() {
- }
-
- static void HandleEvents() {
- int b;
-
- Jake2InputEvent event;
- while ( (event=InputListener.nextEvent()) != null ) {
- switch(event.type) {
- case Jake2InputEvent.KeyPress:
- case Jake2InputEvent.KeyRelease:
- Do_Key_Event(XLateKey((KeyEvent)event.ev), event.type == Jake2InputEvent.KeyPress);
- break;
-
- case Jake2InputEvent.MotionNotify:
-// if (IN.ignorefirst) {
-// IN.ignorefirst = false;
-// break;
-// }
- if (IN.mouse_active) {
- mx = (((MouseEvent)event.ev).getX() - win_w2) * 2;
- my = (((MouseEvent)event.ev).getY() - win_h2) * 2;
- } else {
- mx = 0;
- my = 0;
- }
- break;
-
- case Jake2InputEvent.ButtonPress:
- b=((MouseEvent)event.ev).getButton()-1;
- Do_Key_Event(Key.K_MOUSE1 + b, true);
- break;
-
- case Jake2InputEvent.ButtonRelease:
- b=((MouseEvent)event.ev).getButton()-1;
- Do_Key_Event(Key.K_MOUSE1 + b, false);
- break;
-
- case Jake2InputEvent.WheelMoved:
- int dir = ((MouseWheelEvent)event.ev).getWheelRotation();
- if (dir > 0) {
- Do_Key_Event(Key.K_MWHEELDOWN, true);
- Do_Key_Event(Key.K_MWHEELDOWN, false);
- } else {
- Do_Key_Event(Key.K_MWHEELUP, true);
- Do_Key_Event(Key.K_MWHEELUP, false);
- }
- break;
-
- case Jake2InputEvent.CreateNotify :
- case Jake2InputEvent.ConfigureNotify :
- Component c = ((ComponentEvent)event.ev).getComponent();
- win_x = 0;
- win_y = 0;
- win_w2 = c.getWidth() / 2;
- win_h2 = c.getHeight() / 2;
- while (c != null) {
- if (c instanceof Container) {
- Insets insets = ((Container)c).getInsets();
- win_x += insets.left;
- win_y += insets.top;
- }
- win_x += c.getX();
- win_y += c.getY();
- c = c.getParent();
- }
- break;
- }
- }
-
- if (mx != 0 || my != 0) {
- // move the mouse to the window center again
- robot.mouseMove(win_x + win_w2, win_y + win_h2);
- }
- }
-
- private static int XLateKey(KeyEvent ev) {
-
- int key = 0;
- int code = ev.getKeyCode();
-
- switch(code) {
-// 00626 case XK_KP_Page_Up: key = K_KP_PGUP; break;
- case KeyEvent.VK_PAGE_UP: key = Key.K_PGUP; break;
-
-// 00629 case XK_KP_Page_Down: key = K_KP_PGDN; break;
- case KeyEvent.VK_PAGE_DOWN: key = Key.K_PGDN; break;
-
-// 00632 case XK_KP_Home: key = K_KP_HOME; break;
- case KeyEvent.VK_HOME: key = Key.K_HOME; break;
+ abstract public void Init();
-// 00635 case XK_KP_End: key = K_KP_END; break;
- case KeyEvent.VK_END: key = Key.K_END; break;
-
- case KeyEvent.VK_KP_LEFT: key = Key.K_KP_LEFTARROW; break;
- case KeyEvent.VK_LEFT: key = Key.K_LEFTARROW; break;
-
- case KeyEvent.VK_KP_RIGHT: key = Key.K_KP_RIGHTARROW; break;
- case KeyEvent.VK_RIGHT: key = Key.K_RIGHTARROW; break;
+ abstract public void Update();
- case KeyEvent.VK_KP_DOWN: key = Key.K_KP_DOWNARROW; break;
- case KeyEvent.VK_DOWN: key = Key.K_DOWNARROW; break;
+ abstract public void Close();
+ abstract public void Do_Key_Event(int key, boolean down);
- case KeyEvent.VK_KP_UP: key = Key.K_KP_UPARROW; break;
- case KeyEvent.VK_UP: key = Key.K_UPARROW; break;
-
- case KeyEvent.VK_ESCAPE: key = Key.K_ESCAPE; break;
-
-
- case KeyEvent.VK_ENTER: key = Key.K_ENTER; break;
-// 00652 case XK_KP_Enter: key = K_KP_ENTER; break;
-
- case KeyEvent.VK_TAB: key = Key.K_TAB; break;
-
- case KeyEvent.VK_F1: key = Key.K_F1; break;
- case KeyEvent.VK_F2: key = Key.K_F2; break;
- case KeyEvent.VK_F3: key = Key.K_F3; break;
- case KeyEvent.VK_F4: key = Key.K_F4; break;
- case KeyEvent.VK_F5: key = Key.K_F5; break;
- case KeyEvent.VK_F6: key = Key.K_F6; break;
- case KeyEvent.VK_F7: key = Key.K_F7; break;
- case KeyEvent.VK_F8: key = Key.K_F8; break;
- case KeyEvent.VK_F9: key = Key.K_F9; break;
- case KeyEvent.VK_F10: key = Key.K_F10; break;
- case KeyEvent.VK_F11: key = Key.K_F11; break;
- case KeyEvent.VK_F12: key = Key.K_F12; break;
-
- case KeyEvent.VK_BACK_SPACE: key = Key.K_BACKSPACE; break;
-
- case KeyEvent.VK_DELETE: key = Key.K_DEL; break;
-// 00683 case XK_KP_Delete: key = K_KP_DEL; break;
-
- case KeyEvent.VK_PAUSE: key = Key.K_PAUSE; break;
-
- case KeyEvent.VK_SHIFT: key = Key.K_SHIFT; break;
- case KeyEvent.VK_CONTROL: key = Key.K_CTRL; break;
-
- case KeyEvent.VK_ALT:
- case KeyEvent.VK_ALT_GRAPH: key = Key.K_ALT; break;
-
-// 00700 case XK_KP_Begin: key = K_KP_5; break;
-// 00701
- case KeyEvent.VK_INSERT: key = Key.K_INS; break;
- // toggle console for DE and US keyboards
- case KeyEvent.VK_DEAD_ACUTE:
- case KeyEvent.VK_CIRCUMFLEX:
- case KeyEvent.VK_DEAD_CIRCUMFLEX: key = '`'; break;
-
- default:
- if ((ev.getModifiers() & (InputEvent.ALT_MASK | InputEvent.CTRL_MASK)) != 0) {
- key = ev.getKeyCode();
- } else {
- key = ev.getKeyChar();
- }
- if (key >= 'A' && key <= 'Z')
- key = key - 'A' + 'a';
- break;
- }
- if (key > 255) key = 0;
-
- return key;
- }
-
- static void Do_Key_Event(int key, boolean down) {
- Key.Event(key, down, Sys.Milliseconds());
- }
-
- static void centerMouse() {
- robot.mouseMove(win_x + win_w2, win_y + win_h2);
- }
-
+ abstract public void installGrabs();
+ abstract public void uninstallGrabs();
+ abstract public void centerMouse();
}
diff --git a/src/jake2/sys/LWJGLKBD.java b/src/jake2/sys/LWJGLKBD.java
new file mode 100644
index 0000000..1ef5935
--- /dev/null
+++ b/src/jake2/sys/LWJGLKBD.java
@@ -0,0 +1,186 @@
+package jake2.sys;
+
+import jake2.Defines;
+import jake2.client.Key;
+import jake2.qcommon.Cbuf;
+
+import org.lwjgl.input.Keyboard;
+import org.lwjgl.input.Mouse;
+import org.lwjgl.opengl.Display;
+
+/**
+ * @author dsanders
+ */
+public class LWJGLKBD extends KBD {
+
+ static private int win_w2;
+ static private int win_h2;
+
+ public void Init()
+ {
+ try
+ {
+ if (!Keyboard.isCreated()) Keyboard.create();
+ if (!Mouse.isCreated()) Mouse.create();
+
+ if (!Keyboard.isBuffered()) Keyboard.enableBuffer();
+ if (!Mouse.isBuffered()) Mouse.enableBuffer();
+
+ win_w2=Display.getDisplayMode().getWidth()/2;
+ win_h2=Display.getDisplayMode().getHeight()/2;
+
+ } catch (Exception e) {;}
+ }
+
+ public void Update() {
+ // get events
+ HandleEvents();
+ }
+
+ public void Close() {
+ Keyboard.destroy();
+ Mouse.destroy();
+ }
+
+ private void HandleEvents()
+ {
+ if (Display.isCloseRequested())
+ {
+ Cbuf.ExecuteText(Defines.EXEC_APPEND, "quit");
+ }
+
+ for (int i=0; i<Keyboard.getNumKeyboardEvents(); i++)
+ {
+ Keyboard.next();
+
+ int key=Keyboard.getEventKey();
+ char ch=Keyboard.getEventCharacter();
+ Do_Key_Event(XLateKey(key,ch),Keyboard.getEventKeyState());
+ }
+
+ if (IN.mouse_active)
+ {
+ mx=(Mouse.getX()-win_w2)*2;
+ my=(Mouse.getY()-win_h2)*2;
+ }
+ else
+ {
+ mx=0;
+ my=0;
+ }
+
+ while (Mouse.next())
+ {
+ int button=Mouse.getEventButton();
+ if (button>=0)
+ {
+ Do_Key_Event(Key.K_MOUSE1 + button, Mouse.getEventButtonState());
+ }
+ }
+ }
+
+ private static int XLateKey(int code, int ch)
+ {
+ int key = 0;
+
+ switch(code)
+ {
+// 00626 case XK_KP_Page_Up: key = K_KP_PGUP; break;
+ case Keyboard.KEY_PRIOR: key = Key.K_PGUP; break;
+
+// 00629 case XK_KP_Page_Down: key = K_KP_PGDN; break;
+ case Keyboard.KEY_NEXT: key = Key.K_PGDN; break;
+
+// 00632 case XK_KP_Home: key = K_KP_HOME; break;
+ case Keyboard.KEY_HOME: key = Key.K_HOME; break;
+
+// 00635 case XK_KP_End: key = K_KP_END; break;
+ case Keyboard.KEY_END: key = Key.K_END; break;
+
+ // case Keyboard.KEY_LEFT: key = Key.K_KP_LEFTARROW; break;
+ case Keyboard.KEY_LEFT: key = Key.K_LEFTARROW; break;
+
+ // case Keyboard.KEY_RIGHT: key = Key.K_KP_RIGHTARROW; break;
+ case Keyboard.KEY_RIGHT: key = Key.K_RIGHTARROW; break;
+
+ // case Keyboard.KEY_DOWN: key = Key.K_KP_DOWNARROW; break;
+ case Keyboard.KEY_DOWN: key = Key.K_DOWNARROW; break;
+
+ // case Keyboard.KEY_UP: key = Key.K_KP_UPARROW; break;
+ case Keyboard.KEY_UP: key = Key.K_UPARROW; break;
+
+ case Keyboard.KEY_ESCAPE: key = Key.K_ESCAPE; break;
+
+
+ case Keyboard.KEY_RETURN: key = Key.K_ENTER; break;
+// 00652 case XK_KP_Enter: key = K_KP_ENTER; break;
+
+ case Keyboard.KEY_TAB: key = Key.K_TAB; break;
+
+ case Keyboard.KEY_F1: key = Key.K_F1; break;
+ case Keyboard.KEY_F2: key = Key.K_F2; break;
+ case Keyboard.KEY_F3: key = Key.K_F3; break;
+ case Keyboard.KEY_F4: key = Key.K_F4; break;
+ case Keyboard.KEY_F5: key = Key.K_F5; break;
+ case Keyboard.KEY_F6: key = Key.K_F6; break;
+ case Keyboard.KEY_F7: key = Key.K_F7; break;
+ case Keyboard.KEY_F8: key = Key.K_F8; break;
+ case Keyboard.KEY_F9: key = Key.K_F9; break;
+ case Keyboard.KEY_F10: key = Key.K_F10; break;
+ case Keyboard.KEY_F11: key = Key.K_F11; break;
+ case Keyboard.KEY_F12: key = Key.K_F12; break;
+
+ case Keyboard.KEY_BACK: key = Key.K_BACKSPACE; break;
+
+ case Keyboard.KEY_DELETE: key = Key.K_DEL; break;
+// 00683 case XK_KP_Delete: key = K_KP_DEL; break;
+
+ case Keyboard.KEY_PAUSE: key = Key.K_PAUSE; break;
+
+ case Keyboard.KEY_RSHIFT:
+ case Keyboard.KEY_LSHIFT: key = Key.K_SHIFT; break;
+
+ case Keyboard.KEY_RCONTROL:
+ case Keyboard.KEY_LCONTROL: key = Key.K_CTRL; break;
+
+ case Keyboard.KEY_LMENU:
+ case Keyboard.KEY_RMENU: key = Key.K_ALT; break;
+
+// 00700 case XK_KP_Begin: key = K_KP_5; break;
+// 00701
+ case Keyboard.KEY_INSERT: key = Key.K_INS; break;
+ // toggle console for DE and US keyboards
+ case Keyboard.KEY_CIRCUMFLEX: key = '`'; break;
+
+ default:
+ key = ch;
+ if (key >= 'A' && key <= 'Z')
+ key = key - 'A' + 'a';
+ break;
+ }
+ if (key > 255) key = 0;
+
+ return key;
+ }
+
+ public void Do_Key_Event(int key, boolean down) {
+ Key.Event(key, down, Sys.Milliseconds());
+ }
+
+ public void centerMouse()
+ {
+ Mouse.setPosition(win_x + win_w2,win_y + win_h2);
+ //Mouse.setGrabbed(true);
+ //Mouse.setTrackingEnabled(true);
+ }
+
+ public void installGrabs()
+ {
+ Mouse.setGrabbed(true);
+ }
+
+ public void uninstallGrabs()
+ {
+ Mouse.setGrabbed(false);
+ }
+}
diff --git a/src/jake2/sys/Sys.java b/src/jake2/sys/Sys.java
index ba2a6c7..aeb30fc 100644
--- a/src/jake2/sys/Sys.java
+++ b/src/jake2/sys/Sys.java
@@ -2,7 +2,7 @@
* Sys.java
* Copyright (C) 2003
*
- * $Id: Sys.java,v 1.9 2004-09-22 19:22:14 salomo Exp $
+ * $Id: Sys.java,v 1.10 2004-12-14 00:11:01 hzi Exp $
*/
/*
Copyright (C) 1997-2001 Id Software, Inc.
@@ -227,7 +227,7 @@ public final class Sys extends Defines {
}
public static void SendKeyEvents() {
- KBD.Update();
+ Globals.re.getKeyboardHandler().Update();
// grab frame time
Globals.sys_frame_time = Sys.Milliseconds();