diff options
author | Carsten Weisse <[email protected]> | 2005-02-20 14:39:23 +0000 |
---|---|---|
committer | Carsten Weisse <[email protected]> | 2005-02-20 14:39:23 +0000 |
commit | a4d8750bd468ef6988aae2c700a09d2434ebabd9 (patch) | |
tree | 7530c74faca1cd682747acea089f98c180923706 | |
parent | 8008377e14de938b383028b3b3f896ba0ac898f3 (diff) |
correct mouse button numbering for jogl (left->K_MOUSE1, center->K_MOUSE3, right->K_MOUSE2)
-rw-r--r-- | src/jake2/sys/JOGLKBD.java | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/src/jake2/sys/JOGLKBD.java b/src/jake2/sys/JOGLKBD.java index 409d290..194500f 100644 --- a/src/jake2/sys/JOGLKBD.java +++ b/src/jake2/sys/JOGLKBD.java @@ -38,7 +38,7 @@ final public class JOGLKBD extends KBD private void HandleEvents() { - int b; + int key; Jake2InputEvent event; while ( (event=InputListener.nextEvent()) != null ) { @@ -61,15 +61,15 @@ final public class JOGLKBD extends KBD my = 0; } break; - + // see java.awt.MouseEvent case Jake2InputEvent.ButtonPress: - b=((MouseEvent)event.ev).getButton()-1; - Do_Key_Event(Key.K_MOUSE1 + b, true); + key = mouseEventToKey((MouseEvent)event.ev); + Do_Key_Event(key, true); break; case Jake2InputEvent.ButtonRelease: - b=((MouseEvent)event.ev).getButton()-1; - Do_Key_Event(Key.K_MOUSE1 + b, false); + key = mouseEventToKey((MouseEvent)event.ev); + Do_Key_Event(key, false); break; case Jake2InputEvent.WheelMoved: @@ -110,6 +110,20 @@ final public class JOGLKBD extends KBD } } + // strange button numbering in java.awt.MouseEvent + // BUTTON1(left) BUTTON2(center) BUTTON3(right) + // K_MOUSE1 K_MOUSE3 K_MOUSE2 + private final int mouseEventToKey(MouseEvent ev) { + switch (ev.getButton()) { + case MouseEvent.BUTTON3: + return Key.K_MOUSE2; + case MouseEvent.BUTTON2: + return Key.K_MOUSE3; + default: + return Key.K_MOUSE1; + } + } + private static int XLateKey(KeyEvent ev) { int key = 0; |