Permalink
Browse files

Add setActive()

  • Loading branch information...
1 parent 31bcd09 commit 22741d19cd6aa3068b62e285c3c6b4c2456a3bd7 @jdf committed Sep 16, 2010
Showing with 26 additions and 4 deletions.
  1. +21 −4 src/peasy/PeasyCam.java
  2. +5 −0 test/peasy/test/TestPeasy.java
View
25 src/peasy/PeasyCam.java
@@ -96,6 +96,10 @@ public void handleWheel(final int delta) {
private PeasyWheelHandler wheelHandler = zoomWheelHandler;
private double wheelScale = 1.0;
+ private final PeasyMouseListener mouseListener = new PeasyMouseListener();
+ private final PeasyMousewheelListener mouseWheelListener = new PeasyMousewheelListener();
+ private boolean isActive = false;
+
private final PMatrix3D originalMatrix; // for HUD restore
public final String VERSION = "0.9";
@@ -156,13 +160,26 @@ protected void behave(final double velocity) {
}
};
- final PeasyMouseListener mouseListener = new PeasyMouseListener();
- p.registerMouseEvent(mouseListener);
- p.registerKeyEvent(mouseListener);
- p.addMouseWheelListener(new PeasyMousewheelListener());
+ setActive(true);
System.err.println("PeasyCam v" + VERSION);
}
+ public void setActive(final boolean active) {
+ if (active == isActive) {
+ return;
+ }
+ isActive = active;
+ if (isActive) {
+ p.registerMouseEvent(mouseListener);
+ p.registerKeyEvent(mouseListener);
+ p.addMouseWheelListener(mouseWheelListener);
+ } else {
+ p.unregisterMouseEvent(mouseListener);
+ p.unregisterKeyEvent(mouseListener);
+ p.removeMouseWheelListener(mouseWheelListener);
+ }
+ }
+
/**
* <p>
* Turn on or off default mouse-handling behavior:
View
5 test/peasy/test/TestPeasy.java
@@ -28,4 +28,9 @@ public void draw() {
box(5);
popMatrix();
}
+
+ @Override
+ public void keyPressed() {
+ cam.setActive(key == 'a');
+ }
}

0 comments on commit 22741d1

Please sign in to comment.