Exemple #1
0
  /**
   * Applies Camera transformations and draws all the Layers in this World.
   *
   * @param canvas The Canvas onto which the World will be drawn.
   */
  public void draw(Canvas canvas) {

    canvas.save();
    canvas.translate(-camera.getPosition().getX(), -camera.getPosition().getY());

    for (Layer l : layers) {
      l.draw(canvas, camera.getBoundingBox());
    }

    canvas.restore();
  }
 public void mouseWheelMoved(
     ViewPanel v, short wheelDirection, int jpx, int jpy, MouseWheelEvent e) {
   Camera c = application.vsm.getActiveCamera();
   double a = (c.focal + Math.abs(c.altitude)) / c.focal;
   if (wheelDirection == WHEEL_UP) {
     c.altitudeOffset(-a * 5);
     application.vsm.repaint();
   } else {
     // wheelDirection == WHEEL_DOWN
     c.altitudeOffset(a * 5);
     application.vsm.repaint();
   }
 }
  public void step() {
    Camera cam = cameras.get(0);
    cam.activate();

    cam.setColor(Color.black);
    tree.display(50, 90, cam, spread, levelHeight);
    // -------------------------------------------------

    cam = cameras.get(1);
    cam.activate();

    if (state.equals("add")) {
      cam.setColor(Color.black);
      cam.drawText(">>> " + stringToAdd, 5, 2);
    }
  }
  public void keyPressed(KeyEvent e) {
    int code = e.getKeyCode();

    Camera cam = cameras.get(0);

    if (state.equals("regular")) {
      if (code == KeyEvent.VK_L) {
        cam.shiftRegion(0.25, 0);
      } else if (code == KeyEvent.VK_R) {
        cam.shiftRegion(-0.25, 0);
      } else if (code == KeyEvent.VK_U) {
        cam.shiftRegion(0, -0.25);
      } else if (code == KeyEvent.VK_D) {
        cam.shiftRegion(0, 0.25);
      } else if (code == KeyEvent.VK_S) {
        cam.scaleRegion(1.1, 1.1);
      } else if (code == KeyEvent.VK_B) {
        cam.scaleRegion(1 / 1.1, 1 / 1.1);
      } else if (code == KeyEvent.VK_W) {
        spread *= 1.1;
      } else if (code == KeyEvent.VK_N) {
        spread /= 1.1;
      } else if (code == KeyEvent.VK_H) {
        cam.setRegion(0, 100, 0, 100);
      }

    } // regular state
    else if (state.equals("add")) {
      if (code == KeyEvent.VK_ENTER) {
        state = "regular";
        if (!stringToAdd.equals("")) tree.add(stringToAdd);
      } else if (code == KeyEvent.VK_DELETE || code == KeyEvent.VK_BACK_SPACE) {
        if (stringToAdd.length() > 0)
          stringToAdd = stringToAdd.substring(0, stringToAdd.length() - 1);
      }
    } // add state
  }
  public void initTest(String vt) {
    eh = new TestDefaultHandler.EventHandlerTestDTH(this);
    vs = vsm.addVirtualSpace("src");
    cam = vs.addCamera();
    List<Camera> cameras = new ArrayList<Camera>();
    cameras.add(cam);
    cam.setZoomFloor(-90);
    testView = vsm.addFrameView(cameras, "Test", vt, 800, 600, true);
    testView.setBackgroundColor(Color.LIGHT_GRAY);
    testView.setListener(eh);
    final Glyph circle = new VCircle(100, 0, 0, 40, Color.WHITE);
    cam.setAltitude(50);
    vs.addGlyph(circle);
    vsm.repaint();

    AnimationManager am = vsm.getAnimationManager();

    for (int i = 0; i < 4; ++i) {
      Animation anim =
          am.getAnimationFactory()
              .createAnimation(
                  3000,
                  1.0,
                  Animation.RepeatBehavior.LOOP,
                  circle,
                  Animation.Dimension.POSITION,
                  new DefaultTimingHandler() {
                    public void timingEvent(
                        float fraction, Object subject, Animation.Dimension dim) {
                      Glyph g = (Glyph) subject;
                      g.moveTo(100 - (double) 600 * fraction, 0);
                    }
                  },
                  new SplineInterpolator(0.7f, 0.1f, 0.3f, 0.9f));
      am.startAnimation(anim, false);
    }

    Animation anim =
        am.getAnimationFactory()
            .createAnimation(
                8000,
                1.0,
                Animation.RepeatBehavior.LOOP,
                circle,
                Animation.Dimension.FILLCOLOR,
                new DefaultTimingHandler() {
                  public void timingEvent(float fraction, Object subject, Animation.Dimension dim) {
                    Glyph g = (Glyph) subject;
                    g.setColor(new Color(0, 0, Float.valueOf(255 * fraction).intValue()));
                  }
                });
    am.startAnimation(anim, false);

    Animation animSize =
        am.getAnimationFactory()
            .createAnimation(
                4000,
                1.0,
                Animation.RepeatBehavior.LOOP,
                circle,
                Animation.Dimension.SIZE,
                new DefaultTimingHandler() {
                  public void timingEvent(float fraction, Object subject, Animation.Dimension dim) {
                    Glyph g = (Glyph) subject;
                    g.sizeTo(40 + 60 * fraction);
                  }
                });
    am.startAnimation(animSize, false);
  }