aboutsummaryrefslogtreecommitdiffstats
path: root/ardor3d-jogl
diff options
context:
space:
mode:
authorJulien Gouesse <[email protected]>2013-08-01 20:02:50 +0200
committerJulien Gouesse <[email protected]>2013-08-01 20:02:50 +0200
commit661d4cb8289bebea60670fd32f98b929ef0b5960 (patch)
tree9ce84d28fafc79c948725b15071c1438e4da1109 /ardor3d-jogl
parentdc2fbacfa01bcd6ae8747652a50ff1556a8e9fd7 (diff)
Allows to skip auto-repeat events
Diffstat (limited to 'ardor3d-jogl')
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/input/jogl/JoglNewtKeyboardWrapper.java43
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/input/jogl/JoglNewtMouseWrapper.java73
2 files changed, 73 insertions, 43 deletions
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/input/jogl/JoglNewtKeyboardWrapper.java b/ardor3d-jogl/src/main/java/com/ardor3d/input/jogl/JoglNewtKeyboardWrapper.java
index 610736b..3f37c3e 100644
--- a/ardor3d-jogl/src/main/java/com/ardor3d/input/jogl/JoglNewtKeyboardWrapper.java
+++ b/ardor3d-jogl/src/main/java/com/ardor3d/input/jogl/JoglNewtKeyboardWrapper.java
@@ -40,9 +40,12 @@ public class JoglNewtKeyboardWrapper extends KeyAdapter implements KeyboardWrapp
protected boolean _consumeEvents = false;
+ protected boolean _skipAutoRepeatEvents = false;
+
protected final EnumSet<Key> _pressedList = EnumSet.noneOf(Key.class);
public JoglNewtKeyboardWrapper(final NewtWindowContainer newtWindowContainer) {
+ super();
_newtWindow = Preconditions.checkNotNull(newtWindowContainer.getNewtWindow(), "newtWindow");
}
@@ -69,25 +72,29 @@ public class JoglNewtKeyboardWrapper extends KeyAdapter implements KeyboardWrapp
@Override
public synchronized void keyPressed(final com.jogamp.newt.event.KeyEvent e) {
- final Key pressed = fromKeyEventToKey(e);
- if (!_pressedList.contains(pressed)) {
- _upcomingEvents.add(new KeyEvent(pressed, KeyState.DOWN, e.getKeyChar()));
- _pressedList.add(pressed);
- }
- if (_consumeEvents) {
- e.setAttachment(NEWTEvent.consumedTag);
- // ignore this event
+ if (!_skipAutoRepeatEvents || !e.isAutoRepeat()) {
+ final Key pressed = fromKeyEventToKey(e);
+ if (!_pressedList.contains(pressed)) {
+ _upcomingEvents.add(new KeyEvent(pressed, KeyState.DOWN, e.getKeyChar()));
+ _pressedList.add(pressed);
+ }
+ if (_consumeEvents) {
+ e.setAttachment(NEWTEvent.consumedTag);
+ // ignore this event
+ }
}
}
@Override
public synchronized void keyReleased(final com.jogamp.newt.event.KeyEvent e) {
- final Key released = fromKeyEventToKey(e);
- _upcomingEvents.add(new KeyEvent(released, KeyState.UP, e.getKeyChar()));
- _pressedList.remove(released);
- if (_consumeEvents) {
- e.setAttachment(NEWTEvent.consumedTag);
- // ignore this event
+ if (!_skipAutoRepeatEvents || !e.isAutoRepeat()) {
+ final Key released = fromKeyEventToKey(e);
+ _upcomingEvents.add(new KeyEvent(released, KeyState.UP, e.getKeyChar()));
+ _pressedList.remove(released);
+ if (_consumeEvents) {
+ e.setAttachment(NEWTEvent.consumedTag);
+ // ignore this event
+ }
}
}
@@ -122,4 +129,12 @@ public class JoglNewtKeyboardWrapper extends KeyAdapter implements KeyboardWrapp
public void setConsumeEvents(final boolean consumeEvents) {
_consumeEvents = consumeEvents;
}
+
+ public boolean isSkipAutoRepeatEvents() {
+ return _skipAutoRepeatEvents;
+ }
+
+ public void setSkipAutoRepeatEvents(final boolean skipAutoRepeatEvents) {
+ _skipAutoRepeatEvents = skipAutoRepeatEvents;
+ }
}
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/input/jogl/JoglNewtMouseWrapper.java b/ardor3d-jogl/src/main/java/com/ardor3d/input/jogl/JoglNewtMouseWrapper.java
index 3abe5f5..a82bb1a 100644
--- a/ardor3d-jogl/src/main/java/com/ardor3d/input/jogl/JoglNewtMouseWrapper.java
+++ b/ardor3d-jogl/src/main/java/com/ardor3d/input/jogl/JoglNewtMouseWrapper.java
@@ -52,6 +52,8 @@ public class JoglNewtMouseWrapper implements MouseWrapper, MouseListener {
protected boolean _consumeEvents = false;
+ protected boolean _skipAutoRepeatEvents = false;
+
protected final Multiset<MouseButton> _clicks = EnumMultiset.create(MouseButton.class);
protected final EnumMap<MouseButton, Long> _lastClickTime = Maps.newEnumMap(MouseButton.class);
protected final EnumSet<MouseButton> _clickArmed = EnumSet.noneOf(MouseButton.class);
@@ -95,47 +97,52 @@ public class JoglNewtMouseWrapper implements MouseWrapper, MouseListener {
@Override
public synchronized void mousePressed(final MouseEvent me) {
- final MouseButton b = getButtonForEvent(me);
- if (_clickArmed.contains(b)) {
- _clicks.setCount(b, 0);
- }
- _clickArmed.add(b);
- _lastClickTime.put(b, System.currentTimeMillis());
+ if (!_skipAutoRepeatEvents || !me.isAutoRepeat()) {
+ final MouseButton b = getButtonForEvent(me);
+ if (_clickArmed.contains(b)) {
+ _clicks.setCount(b, 0);
+ }
+ _clickArmed.add(b);
+ _lastClickTime.put(b, System.currentTimeMillis());
- initState(me);
- if (_consumeEvents) {
- me.setAttachment(NEWTEvent.consumedTag);
- }
+ initState(me);
+ if (_consumeEvents) {
+ me.setAttachment(NEWTEvent.consumedTag);
+ }
- final EnumMap<MouseButton, ButtonState> buttons = _lastState.getButtonStates();
+ final EnumMap<MouseButton, ButtonState> buttons = _lastState.getButtonStates();
- setStateForButton(me, buttons, ButtonState.DOWN);
+ setStateForButton(me, buttons, ButtonState.DOWN);
- addNewState(me, buttons, null);
+ addNewState(me, buttons, null);
+ }
}
@Override
public synchronized void mouseReleased(final MouseEvent me) {
- initState(me);
- if (_consumeEvents) {
- me.setAttachment(NEWTEvent.consumedTag);
- }
+ if (!_skipAutoRepeatEvents || !me.isAutoRepeat()) {
+ initState(me);
+ if (_consumeEvents) {
+ me.setAttachment(NEWTEvent.consumedTag);
+ }
- final EnumMap<MouseButton, ButtonState> buttons = _lastState.getButtonStates();
+ final EnumMap<MouseButton, ButtonState> buttons = _lastState.getButtonStates();
- setStateForButton(me, buttons, ButtonState.UP);
+ setStateForButton(me, buttons, ButtonState.UP);
- final MouseButton b = getButtonForEvent(me);
- if (_clickArmed.contains(b) && (System.currentTimeMillis() - _lastClickTime.get(b) <= MouseState.CLICK_TIME_MS)) {
- _clicks.add(b); // increment count of clicks for button b.
- // XXX: Note the double event add... this prevents sticky click counts, but is it the best way?
- addNewState(me, buttons, EnumMultiset.create(_clicks));
- } else {
- _clicks.setCount(b, 0); // clear click count for button b.
- }
- _clickArmed.remove(b);
+ final MouseButton b = getButtonForEvent(me);
+ if (_clickArmed.contains(b)
+ && (System.currentTimeMillis() - _lastClickTime.get(b) <= MouseState.CLICK_TIME_MS)) {
+ _clicks.add(b); // increment count of clicks for button b.
+ // XXX: Note the double event add... this prevents sticky click counts, but is it the best way?
+ addNewState(me, buttons, EnumMultiset.create(_clicks));
+ } else {
+ _clicks.setCount(b, 0); // clear click count for button b.
+ }
+ _clickArmed.remove(b);
- addNewState(me, buttons, null);
+ addNewState(me, buttons, null);
+ }
}
@Override
@@ -326,4 +333,12 @@ public class JoglNewtMouseWrapper implements MouseWrapper, MouseListener {
public void setConsumeEvents(final boolean consumeEvents) {
_consumeEvents = consumeEvents;
}
+
+ public boolean isSkipAutoRepeatEvents() {
+ return _skipAutoRepeatEvents;
+ }
+
+ public void setSkipAutoRepeatEvents(final boolean skipAutoRepeatEvents) {
+ _skipAutoRepeatEvents = skipAutoRepeatEvents;
+ }
}