Ejemplo n.º 1
0
  /* (non-Javadoc)
   * @see org.mt4j.sceneManagement.transition.ITransition#setup(org.mt4j.sceneManagement.Iscene, org.mt4j.sceneManagement.Iscene)
   */
  public void setup(Iscene lastScenee, Iscene nextScenee) {
    this.lastScene = lastScenee;
    this.nextScene = nextScenee;
    finished = false;

    // Disable the scene's global input processors. We will be redirecting the input
    // from the current scene to the window scene
    app.getInputManager().disableGlobalInputProcessors(lastScene);
    app.getInputManager().disableGlobalInputProcessors(nextScene);

    app.invokeLater(
        new Runnable() {
          public void run() {
            lastSceneWindow =
                new MTSceneTexture(
                    app, 0, 0, Math.round(app.width / 2f), Math.round(app.height / 2f), lastScene);
            lastSceneRectangle = new MTRectangle(0, 0, app.width, app.height, app);

            lastSceneRectangle.setGeometryInfo(lastSceneWindow.getGeometryInfo());
            lastSceneRectangle.setTexture(lastSceneWindow.getTexture());
            lastSceneRectangle.setStrokeColor(new MTColor(0, 0, 0, 255));
            lastSceneRectangle.setVisible(false);
            lastSceneRectangle.setNoStroke(true);
            lastSceneRectangle.setDepthBufferDisabled(true);
            getCanvas().addChild(lastSceneRectangle);

            setClear(false);

            // Draw scene into texture once!
            lastSceneWindow.drawComponent(app.g);

            anim.start();
          }
        });
  }
Ejemplo n.º 2
0
  // Global input processor listener implementation (IMTInputEventListener)
  public boolean processInputEvent(MTInputEvent inEvt) {
    if (inEvt instanceof MTFiducialInputEvt) {
      MTFiducialInputEvt fEvt = (MTFiducialInputEvt) inEvt;
      int fID = fEvt.getFiducialId();
      Vector3D position = fEvt.getPosition();

      AbstractShape comp;
      switch (fEvt.getId()) {
        case MTFiducialInputEvt.INPUT_STARTED:
          // Create a new component for the fiducial
          AbstractShape newComp = createComponent(fID, position);
          fiducialIDToComp.put(fID, newComp); // Map id to component
          // Move component to fiducial position
          newComp.setPositionGlobal(position);
          // Save the absolute rotation angle in the component for late
          newComp.setUserData("angle", fEvt.getAngle());
          // Rotate the component
          newComp.rotateZ(
              newComp.getCenterPointRelativeToParent(), MTApplication.degrees(fEvt.getAngle()));
          // Add the component to the canvas to draw it
          getCanvas().addChild(newComp);
          break;
        case MTFiducialInputEvt.INPUT_UPDATED:
          // Retrieve the corresponding component for the fiducial ID from the map
          comp = fiducialIDToComp.get(fID);
          if (comp != null) {
            // Set the new position
            comp.setPositionGlobal(position);
            // Set the rotation (we have to do a little more here because
            // mt4j does incremental rotations instead of specifying an absolute angle)
            float oldAngle = (Float) comp.getUserData("angle"); // retrieve the "old" angle
            float newAngle = fEvt.getAngle();
            if (oldAngle != newAngle) {
              float diff = newAngle - oldAngle;
              comp.setUserData("angle", newAngle);
              diff = MTApplication.degrees(diff); // our rotation expects degrees (not radians)
              comp.rotateZ(comp.getCenterPointRelativeToParent(), diff);
            }
          }
          break;
        case MTFiducialInputEvt.INPUT_ENDED:
          comp = fiducialIDToComp.get(fID);
          if (comp != null) {
            comp.destroy();
            fiducialIDToComp.remove(fID);
          }
          break;
        default:
          break;
      }
    }
    return false;
  }
  @Override
  public void inStartUp(MTApplication app) {
    this.app = app;
    // Add a scene to the mt application
    this.scene = new DummyScene(app, "Dummy Scene");
    app.addScene(scene);

    // Set up components
    parent = new MTComponent(app);
    getCanvas().addChild(parent);

    app.getCssStyleManager().loadStyles("junit/integrationtest.css");
    app.getCssStyleManager().setGloballyEnabled(true);
  }
Ejemplo n.º 4
0
 /** @param e */
 public void keyEvent(KeyEvent e) {
   int evtID = e.getID();
   if (evtID != KeyEvent.KEY_PRESSED) return;
   switch (e.getKeyCode()) {
     case KeyEvent.VK_BACK_SPACE:
       app.popScene();
       break;
     case KeyEvent.VK_F1:
       this.setClearColor(new MTColor(100, 99, 99, 255));
       break;
     case KeyEvent.VK_F2:
       this.setClearColor(new MTColor(120, 119, 119, 255));
       break;
     case KeyEvent.VK_F3:
       this.setClearColor(new MTColor(130, 129, 129, 255));
       break;
     case KeyEvent.VK_F4:
       this.setClearColor(new MTColor(160, 159, 159, 255));
       break;
     case KeyEvent.VK_F5:
       this.setClearColor(new MTColor(180, 179, 179, 255));
       break;
     case KeyEvent.VK_F6:
       this.setClearColor(new MTColor(100, 100, 102, 255));
       break;
     case KeyEvent.VK_F7:
       this.setClearColor(new MTColor(70, 70, 72, 255));
       break;
     case KeyEvent.VK_F:
       System.out.println("FPS: " + app.frameRate);
       break;
     default:
       break;
   }
 }
  /**
   * Instantiates a new abstract input source.
   *
   * @param applet the applet
   */
  public AbstractInputSource(MTApplication mtApp) {
    this.inputListeners = new ArrayList<IinputSourceListener>();
    this.eventQueue = new ArrayDeque<MTInputEvent>(20);

    this.app = mtApp;

    app.registerPre(this);

    inputProcessorsToFireTo = new ArrayList<IinputSourceListener>(10);
  }
  /** Private method, fiducial has been updated */
  private void updated() {
    AbstractShape component = FiducialRegistry.getInstance().getFiducialComponent(EventID);

    if (component != null) {
      component.setPositionGlobal(event.getPosition());
      float oldAngle = (Float) component.getUserData("angle"); // retrieve the "old" angle
      float newAngle = event.getAngle();
      if (oldAngle != newAngle) {
        float diff = newAngle + oldAngle;
        component.setUserData("angle", newAngle);
        diff = MTApplication.degrees(diff); // our rotation expects degrees (not radians)
        component.rotateZ(component.getCenterPointRelativeToParent(), diff);
      }
    }
  }
Ejemplo n.º 7
0
  public static void addPictureToScene(
      MTApplication mtApplication,
      AbstractScene slideScene,
      ImagenVO imagenVO,
      int xOffset,
      int yOffset) {

    if (imagenVO == null || imagenVO.getDireccionFisicaImagen() == null) return;

    PImage pImage = mtApplication.loadImage(imagenVO.getDireccionFisicaImagen());

    //		Rectangle2D ubicacionTexto = imagenVO.getImagen().getAnchor2D();
    //
    //		float x = Double.valueOf(ubicacionTexto.getX()).floatValue();
    //		float y = Double.valueOf(ubicacionTexto.getY()).floatValue();
    //
    //		MTRectangle rect = new MTRectangle(pImage, mtApplication);
    ////		rect.setHeightXYGlobal(Double.valueOf(ubicacionTexto.getHeight()).floatValue());
    //
    ////		rect.setHeightXYRelativeToParent(Double.valueOf(ubicacionTexto.getHeight()).floatValue());
    //		rect.setHeightLocal(Double.valueOf(ubicacionTexto.getHeight()*1.2).floatValue());
    ////		rect.setSizeLocal(x, y);
    ////		rect.setWidthXYGlobal(Double.valueOf(ubicacionTexto.getWidth()).floatValue());
    ////		rect.setWidthXYRelativeToParent(Double.valueOf(ubicacionTexto.getWidth()).floatValue());
    //		rect.setWidthLocal(Double.valueOf(ubicacionTexto.getWidth()*1.2).floatValue());
    //
    //		slideScene.getCanvas().addChild(rect);
    //		rect.setPositionGlobal(new Vector3D(200+x, 100+y));
    //		rect.setAnchor(rect.getAnchor());
    //		rect.setNoStroke(true);

    float x = new Float(imagenVO.getImagen().getAnchor().getCenterX()).floatValue();
    float y = new Float(imagenVO.getImagen().getAnchor().getCenterY()).floatValue();
    float w = new Float(imagenVO.getImagen().getAnchor().getWidth()).floatValue();
    float h = new Float(imagenVO.getImagen().getAnchor().getHeight()).floatValue();

    MTRectangle rect = new MTRectangle(x + xOffset, y + yOffset, 0, w, h, mtApplication);
    rect.setTexture(pImage);
    rect.setPickable(imagenVO.isPickable());
    rect.setNoStroke(true);
    slideScene.getCanvas().addChild(rect);
    rect.setPositionGlobal(new Vector3D(x + xOffset, y + yOffset));
  }
Ejemplo n.º 8
0
  public static void addEditableImage(
      final MTApplication mtApplication,
      AbstractScene slideScene,
      ImagenVO imagenVO,
      int xOffset,
      int yOffset) {

    System.out.println("******************** Entré al addEditableImage ********************");

    final MTRectangle textureBrush;
    final MTEllipse pencilBrush;
    final DrawSurfaceScene drawingScene;

    String path = StartYPYIShell.getPathToIconsYPYI();

    PImage pImage = mtApplication.loadImage(imagenVO.getDireccionFisicaImagen());
    float x = new Float(imagenVO.getImagen().getAnchor().getCenterX()).floatValue();
    float y = new Float(imagenVO.getImagen().getAnchor().getCenterY()).floatValue();
    float w = new Float(imagenVO.getImagen().getAnchor().getWidth()).floatValue();
    float h = new Float(imagenVO.getImagen().getAnchor().getHeight()).floatValue();

    final MTRectangle frame =
        new MTRectangle(
            -50, -50, 0, mtApplication.width + 100, mtApplication.height + 100, mtApplication);
    frame.setSizeXYGlobal(w, h);
    frame.setPositionGlobal(new Vector3D(x + xOffset, y + yOffset));
    frame.setTexture(pImage);
    //		frame.setPickable(imagenVO.isPickable());
    frame.setNoStroke(true);
    slideScene.getCanvas().addChild(frame);

    // Create the scene in which we actually draw
    drawingScene = new DrawSurfaceScene(mtApplication, "DrawSurface Scene");
    drawingScene.setClear(false);

    // Create texture brush
    PImage brushImage = mtApplication.loadImage(path + "brush1.png");
    textureBrush = new MTRectangle(brushImage, mtApplication);
    textureBrush.setPickable(false);
    textureBrush.setNoFill(false);
    textureBrush.setNoStroke(true);
    textureBrush.setDrawSmooth(true);
    textureBrush.setFillColor(new MTColor(0, 0, 0));
    // Set texture brush as default
    drawingScene.setBrush(textureBrush);

    // Create pencil brush
    pencilBrush =
        new MTEllipse(
            mtApplication,
            new Vector3D(brushImage.width / 2f, brushImage.height / 2f, 0),
            brushImage.width / 2f,
            brushImage.width / 2f,
            60);
    pencilBrush.setPickable(false);
    pencilBrush.setNoFill(false);
    pencilBrush.setNoStroke(false);
    pencilBrush.setDrawSmooth(true);
    pencilBrush.setStrokeColor(new MTColor(0, 0, 0, 255));
    pencilBrush.setFillColor(new MTColor(0, 0, 0, 255));

    // Create the frame/window that displays the drawing scene through a FBO
    //      final MTSceneTexture sceneWindow = new MTSceneTexture(0,0, pa, drawingScene);
    // We have to create a fullscreen fbo in order to save the image uncompressed
    int wi = new Float(frame.getWidthXY(TransformSpace.GLOBAL)).intValue();
    int hi = new Float(frame.getHeightXY(TransformSpace.GLOBAL)).intValue();

    final MTSceneTexture sceneTexture =
        new MTSceneTexture(mtApplication, 0, 0, wi, hi, drawingScene);
    sceneTexture.getFbo().clear(true, 255, 255, 255, 0, true);
    sceneTexture.setStrokeColor(new MTColor(155, 155, 155));
    frame.addChild(sceneTexture);

    // Eraser button
    PImage eraser = mtApplication.loadImage(path + "Kde_crystalsvg_eraser.png");
    final MTImageButton eraserButton = new MTImageButton(eraser, mtApplication);
    eraserButton.setNoStroke(true);
    eraserButton.translate(new Vector3D(-50, 70, 0));
    eraserButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            switch (ae.getID()) {
              case TapEvent.BUTTON_CLICKED:
              case TapEvent.BUTTON_UP:
                {
                  //					//As we are messing with opengl here, we make sure it happens in the
                  // rendering thread
                  mtApplication.invokeLater(
                      new Runnable() {
                        public void run() {
                          sceneTexture.getFbo().clear(true, 255, 255, 255, 0, true);
                        }
                      });
                }
                break;
              default:
                break;
            }
          }
        });
    frame.addChild(eraserButton);

    // Pen brush selector button
    PImage penIcon = mtApplication.loadImage(path + "pen.png");
    final MTImageButton penButton = new MTImageButton(penIcon, mtApplication);
    frame.addChild(penButton);
    penButton.translate(new Vector3D(-50f, 120, 0));
    penButton.setNoStroke(true);
    penButton.setStrokeColor(new MTColor(0, 0, 0));

    // Texture brush selector button
    PImage brushIcon = mtApplication.loadImage(path + "paintbrush.png");
    final MTImageButton brushButton = new MTImageButton(brushIcon, mtApplication);
    frame.addChild(brushButton);
    brushButton.translate(new Vector3D(-50f, 170, 0));
    brushButton.setStrokeColor(new MTColor(0, 0, 0));
    brushButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            switch (ae.getID()) {
              case TapEvent.BUTTON_CLICKED:
              case TapEvent.BUTTON_UP:
                {
                  drawingScene.setBrush(textureBrush);
                  brushButton.setNoStroke(false);
                  penButton.setNoStroke(true);
                }
                break;
              default:
                break;
            }
          }
        });

    penButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            switch (ae.getID()) {
              case TapEvent.BUTTON_CLICKED:
              case TapEvent.BUTTON_UP:
                {
                  drawingScene.setBrush(pencilBrush);
                  penButton.setNoStroke(false);
                  brushButton.setNoStroke(true);
                }
                break;
              default:
                break;
            }
          }
        });

    /////////////////////////
    // ColorPicker and colorpicker button
    PImage colPick = mtApplication.loadImage(path + "colorcircle.png");
    //      final MTColorPicker colorWidget = new MTColorPicker(0, pa.height-colPick.height,
    // colPick, pa);
    final MTColorPicker colorWidget = new MTColorPicker(0, 0, colPick, mtApplication);
    colorWidget.translate(new Vector3D(0f, 175, 0));
    colorWidget.setStrokeColor(new MTColor(0, 0, 0));
    colorWidget.addGestureListener(
        DragProcessor.class,
        new IGestureEventListener() {
          public boolean processGestureEvent(MTGestureEvent ge) {
            if (ge.getId() == MTGestureEvent.GESTURE_ENDED) {
              if (colorWidget.isVisible()) {
                colorWidget.setVisible(false);
              }
            } else {
              drawingScene.setBrushColor(colorWidget.getSelectedColor());
            }
            return false;
          }
        });
    frame.addChild(colorWidget);
    colorWidget.setVisible(false);

    PImage colPickIcon = mtApplication.loadImage(path + "ColorPickerIcon.png");
    final MTImageButton colPickButton = new MTImageButton(colPickIcon, mtApplication);
    frame.addChild(colPickButton);
    colPickButton.translate(new Vector3D(-50f, 235, 0));
    colPickButton.setNoStroke(true);
    colPickButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            switch (ae.getID()) {
              case TapEvent.BUTTON_CLICKED:
              case TapEvent.BUTTON_UP:
                {
                  if (colorWidget.isVisible()) {
                    colorWidget.setVisible(false);
                  } else {
                    colorWidget.setVisible(true);
                    colorWidget.sendToFront();
                  }
                }
                break;
              default:
                break;
            }
          }
        });

    // Add a slider to set the brush width
    final MTSlider slider = new MTSlider(0, 0, 200, 38, 0.05f, 2.0f, mtApplication);
    slider.setValue(1.0f);
    frame.addChild(slider);
    slider.rotateZ(new Vector3D(), 90, TransformSpace.LOCAL);
    slider.translate(new Vector3D(-7, 325));
    slider.setStrokeColor(new MTColor(0, 0, 0));
    slider.setFillColor(new MTColor(220, 220, 220));
    slider.getKnob().setFillColor(new MTColor(70, 70, 70));
    slider.getKnob().setStrokeColor(new MTColor(70, 70, 70));
    slider.addPropertyChangeListener(
        "value",
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent p) {
            drawingScene.setBrushScale((Float) p.getNewValue());
          }
        });
    // Add triangle in slider to indicate brush width
    MTPolygon p =
        new MTPolygon(
            new Vertex[] {
              new Vertex(
                  2 + slider.getKnob().getWidthXY(TransformSpace.LOCAL),
                  slider.getHeightXY(TransformSpace.LOCAL) / 2f,
                  0),
              new Vertex(
                  slider.getWidthXY(TransformSpace.LOCAL) - 3,
                  slider.getHeightXY(TransformSpace.LOCAL) / 4f + 2,
                  0),
              new Vertex(
                  slider.getWidthXY(TransformSpace.LOCAL) - 1,
                  slider.getHeightXY(TransformSpace.LOCAL) / 2f,
                  0),
              new Vertex(
                  slider.getWidthXY(TransformSpace.LOCAL) - 3,
                  -slider.getHeightXY(TransformSpace.LOCAL) / 4f
                      - 2
                      + slider.getHeightXY(TransformSpace.LOCAL),
                  0),
              new Vertex(2, slider.getHeightXY(TransformSpace.LOCAL) / 2f, 0),
            },
            mtApplication);
    p.setFillColor(new MTColor(150, 150, 150, 150));
    p.setStrokeColor(new MTColor(160, 160, 160, 190));
    p.unregisterAllInputProcessors();
    p.setPickable(false);
    slider.getOuterShape().addChild(p);
    slider.getKnob().sendToFront();

    PImage editIcon = mtApplication.loadImage(path + "edit_icon.jpg");
    final MTImageButton editButton = new MTImageButton(editIcon, mtApplication);
    frame.addChild(editButton);
    editButton.translate(new Vector3D(-50f, 20, 0));
    editButton.setNoStroke(true);
    editButton.setStrokeColor(new MTColor(0, 0, 0));

    PImage handIcon = mtApplication.loadImage(path + "hand2.png");
    final MTImageButton handButton = new MTImageButton(handIcon, mtApplication);
    frame.addChild(handButton);
    handButton.translate(new Vector3D(-50f, -40, 0));
    handButton.setNoStroke(true);
    handButton.setStrokeColor(new MTColor(0, 0, 0));

    penButton.setVisible(false);
    brushButton.setVisible(false);
    slider.setVisible(false);
    colPickButton.setVisible(false);
    eraserButton.setVisible(false);
    sceneTexture.setVisible(false);

    handButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            switch (ae.getID()) {
              case TapEvent.BUTTON_CLICKED:
              case TapEvent.BUTTON_UP:
                {
                  handButton.setNoStroke(false);
                  penButton.setVisible(false);
                  brushButton.setVisible(false);
                  slider.setVisible(false);
                  colPickButton.setVisible(false);
                  eraserButton.setVisible(false);

                  sceneTexture.setVisible(false);
                }
                break;
              default:
                break;
            }
          }
        });

    editButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            switch (ae.getID()) {
              case TapEvent.BUTTON_CLICKED:
              case TapEvent.BUTTON_UP:
                {
                  editButton.setNoStroke(false);
                  penButton.setVisible(true);
                  brushButton.setVisible(true);
                  slider.setVisible(true);
                  colPickButton.setVisible(true);
                  eraserButton.setVisible(true);

                  sceneTexture.setVisible(true);
                  //					sceneTexture.sendToFront();
                  //						frame.sendToFront();
                }
                break;
              default:
                break;
            }
          }
        });
  }
Ejemplo n.º 9
0
  public static void addBackgroundToScene(
      MTApplication mtApplication,
      AbstractScene slideScene,
      ImagenVO background,
      int xOffset,
      int yOffset) {

    if (background != null) {
      float x = mtApplication.getWidth() / 2;
      float y = mtApplication.getHeight() / 2;
      float w = mtApplication.getWidth() - (xOffset * 2);
      float h = mtApplication.getHeight() - (yOffset * 2);
      ;
      MTRectangle rect = new MTRectangle(x, y, 0, w, h, mtApplication);

      if (background.getDireccionFisicaImagen() != null) {
        rect.setTexture(mtApplication.loadImage(background.getDireccionFisicaImagen()));
      } else if (background.getColor() != null) {
        rect.setFillColor(
            new MTColor(
                background.getColor().getRed(),
                background.getColor().getGreen(),
                background.getColor().getBlue()));
      } else {
        return;
      }

      rect.setPickable(false);
      rect.setNoStroke(true);
      slideScene.getCanvas().addChild(rect);
      rect.setPositionGlobal(new Vector3D(x, y));
    }

    //		background.getFill().getPictureData().getData();
    //		BufferedImage img = new BufferedImage(new
    // Double(imagenVO.getImagen().getAnchor().getWidth()).intValue(),new
    // Double(imagenVO.getImagen().getAnchor().getHeight()).intValue(),imagenVO.getImagen().getPictureData().getType());
    //		imagenVO.getImagen().draw(img.createGraphics());
    //		img.flush();

    //		try {
    //			FileOutputStream out = new FileOutputStream(getPathToIconsYPYI() +  "back-aux.png");
    //			out.write(background.getFill().getPictureData().getData());
    //		} catch (Exception e) {
    //			// TODO Auto-generated catch block
    //			e.printStackTrace();
    //		}

    //		PImage pImage = mtApplication.loadImage(imagenVO.getDireccionFisicaImagen());
    //
    //		Rectangle2D ubicacionTexto = imagenVO.getImagen().getAnchor2D();
    //
    //
    //		background.getSheet().get
    //
    //
    //		float x = Double.valueOf(ubicacionTexto.getX()).floatValue();
    //		float y = Double.valueOf(ubicacionTexto.getY()).floatValue();
    //
    //		MTRectangle rect = new MTRectangle(pImage, mtApplication);
    //
    //		rect.setHeightLocal(Double.valueOf(ubicacionTexto.getHeight()*1.2).floatValue());
    //		rect.setWidthLocal(Double.valueOf(ubicacionTexto.getWidth()*1.2).floatValue());
    //
    //		slideScene.getCanvas().addChild(rect);
    //		rect.setPositionGlobal(new Vector3D(mtApplication.width/2f, mtApplication.height/2f));

  }
Ejemplo n.º 10
0
  public FlickrScene(MTApplication mtAppl, String name) {
    super(mtAppl, name);
    this.app = mtAppl;
    piler = new PileManager(this.app, this.getCanvas());

    // Set a zoom limit
    final MTCamera camManager = new MTCamera(mtAppl);
    this.setSceneCam(camManager);
    this.getSceneCam().setZoomMinDistance(80);

    //		this.setClearColor(new MTColor(135, 206, 250, 255));
    this.setClearColor(new MTColor(70, 70, 72, 255));

    // Show touches
    this.registerGlobalInputProcessor(new CursorTracer(mtAppl, this));

    // Add multitouch gestures to the canvas background
    lassoProcessor = new LassoProcessor(app, this.getCanvas(), this.getSceneCam());
    this.getCanvas().registerInputProcessor(lassoProcessor);
    this.getCanvas()
        .addGestureListener(
            LassoProcessor.class,
            new DefaultLassoAction(app, this.getCanvas().getPileManager(), this.getCanvas()));

    this.getCanvas().registerInputProcessor(new PanProcessorTwoFingers(app));
    this.getCanvas().addGestureListener(PanProcessorTwoFingers.class, new DefaultPanAction());

    this.getCanvas().registerInputProcessor(new ZoomProcessor(app));
    this.getCanvas().addGestureListener(ZoomProcessor.class, new DefaultZoomAction());

    makePileProcessor = new MakePileProcessor(app, this.getCanvas());
    this.getCanvas().registerInputProcessor(makePileProcessor);
    this.getCanvas()
        .addGestureListener(
            MakePileProcessor.class,
            new DefaultMakePileAction(app, this.getCanvas().getPileManager(), this.getCanvas()));

    this.getCanvas().registerInputProcessor(new TapAndHoldProcessor(app, 2000));
    this.getCanvas()
        .addGestureListener(TapAndHoldProcessor.class, new TapAndHoldVisualizer(app, getCanvas()));
    this.getCanvas()
        .addGestureListener(
            TapAndHoldProcessor.class,
            new IGestureEventListener() {
              public boolean processGestureEvent(MTGestureEvent ge) {
                TapAndHoldEvent th = (TapAndHoldEvent) ge;
                switch (th.getId()) {
                  case TapAndHoldEvent.GESTURE_DETECTED:
                    break;
                  case TapAndHoldEvent.GESTURE_UPDATED:
                    break;
                  case TapAndHoldEvent.GESTURE_ENDED:
                    break;
                  default:
                    break;
                }
                return false;
              }
            });

    piler = new PileManager(app, getCanvas());

    pictureLayer = new MTComponent(app);

    MTComponent topLayer = new MTComponent(app, "top layer group", new MTCamera(app));

    PImage keyboardImg =
        app.loadImage(
            System.getProperty("user.dir")
                + File.separator
                + "examples"
                + File.separator
                + "advanced"
                + File.separator
                + File.separator
                + "flickrMT"
                + File.separator
                + File.separator
                + "data"
                + File.separator
                //		+ "keyb2.png");
                + "keyb128.png");

    final MTImageButton keyboardButton = new MTImageButton(keyboardImg, app);
    keyboardButton.setFillColor(new MTColor(255, 255, 255, 200));
    keyboardButton.setName("KeyboardButton");
    keyboardButton.setNoStroke(true);
    //		keyboardButton.translateGlobal(new Vector3D(5,5,0));
    keyboardButton.translateGlobal(
        new Vector3D(-2, app.height - keyboardButton.getWidthXY(TransformSpace.GLOBAL) + 2, 0));
    topLayer.addChild(keyboardButton);

    progressBar =
        new MTProgressBar(
            app, app.loadFont(MT4jSettings.getInstance().getDefaultFontPath() + "Ziggurat.vlw"));
    progressBar.setDepthBufferDisabled(true);
    progressBar.setVisible(false);
    topLayer.addChild(progressBar);

    keyboardButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            switch (ae.getID()) {
              case TapEvent.BUTTON_CLICKED:
                // Flickr Keyboard
                MTKeyboard keyb = new MTKeyboard(app);
                keyb.setFillColor(new MTColor(30, 30, 30, 210));
                keyb.setStrokeColor(new MTColor(0, 0, 0, 255));

                final MTTextArea t =
                    new MTTextArea(
                        app,
                        FontManager.getInstance()
                            .createFont(
                                app,
                                "arial.ttf",
                                50,
                                new MTColor(0, 0, 0, 255), // Fill color
                                new MTColor(0, 0, 0, 255))); // Stroke color
                t.setStrokeColor(new MTColor(0, 0, 0, 255));
                t.setFillColor(new MTColor(205, 200, 177, 255));
                t.unregisterAllInputProcessors();
                t.setEnableCaret(true);
                t.snapToKeyboard(keyb);
                keyb.addTextInputListener(t);

                // Flickr Button for the keyboard
                MTSvgButton flickrButton =
                    new MTSvgButton(
                        System.getProperty("user.dir")
                            + File.separator
                            + "examples"
                            + File.separator
                            + "advanced"
                            + File.separator
                            + File.separator
                            + "flickrMT"
                            + File.separator
                            + "data"
                            + File.separator
                            + "Flickr_Logo.svg",
                        app);
                flickrButton.scale(0.4f, 0.4f, 1, new Vector3D(0, 0, 0), TransformSpace.LOCAL);
                flickrButton.translate(new Vector3D(0, 15, 0));
                flickrButton.setBoundsPickingBehaviour(AbstractShape.BOUNDS_ONLY_CHECK);

                // Add actionlistener to flickr button
                flickrButton.addActionListener(
                    new ActionListener() {
                      public void actionPerformed(ActionEvent arg0) {
                        if (arg0.getSource() instanceof MTComponent) {
                          // MTBaseComponent clickedComp = (MTBaseComponent)arg0.getSource();
                          switch (arg0.getID()) {
                            case TapEvent.BUTTON_CLICKED:
                              // Get current search parameters
                              SearchParameters sp = new SearchParameters();
                              // sp.setSafeSearch("213on");
                              /*
                              DateFormat dateFormat = new SimpleDateFormat ("yyyy/MM/dd HH:mm:ss");
                              java.util.Date date = new java.util.Date ();
                              String dateStr = dateFormat.format (date);
                              System.out.println("Date: " + dateStr);
                              try{
                              	Date date2 = dateFormat.parse (dateStr);
                              	sp.setInterestingnessDate(date2);
                              }catch(ParseException pe){
                              	pe.printStackTrace();
                              }
                              */

                              // sp.setMachineTags(new String[]{"geo:locality=\"san francisco\""});
                              sp.setText(t.getText());
                              // sp.setTags(new String[]{t.getText()});
                              sp.setSort(SearchParameters.RELEVANCE);

                              System.out.println("Flickr search for: \"" + t.getText() + "\"");

                              // Load flickr api key from file
                              String flickrApiKey = "";
                              String flickrSecret = "";
                              Properties properties = new Properties();
                              try {
                                properties.load(
                                    new FileInputStream(
                                        System.getProperty("user.dir")
                                            + File.separator
                                            + "examples"
                                            + File.separator
                                            + "advanced"
                                            + File.separator
                                            + File.separator
                                            + "flickrMT"
                                            + File.separator
                                            + "data"
                                            + File.separator
                                            + "FlickrApiKey.txt"));
                                flickrApiKey = properties.getProperty("FlickrApiKey", " ");
                                flickrSecret = properties.getProperty("FlickrSecret", " ");
                              } catch (Exception e) {
                                System.err.println(
                                    "Error while loading Settings.txt file. Using defaults.");
                              }

                              // Create flickr loader thread
                              final FlickrMTFotoLoader flickrLoader =
                                  new FlickrMTFotoLoader(app, flickrApiKey, flickrSecret, sp, 300);
                              flickrLoader.setFotoLoadCount(15);
                              // Define action when loader thread finished
                              flickrLoader.addProgressFinishedListener(
                                  new IMTEventListener() {
                                    public void processMTEvent(MTEvent mtEvent) {
                                      // Add the loaded fotos in the main drawing thread to
                                      // avoid threading problems
                                      registerPreDrawAction(
                                          new IPreDrawAction() {
                                            public void processAction() {
                                              MTImage[] fotos = flickrLoader.getMtFotos();
                                              for (int i = 0; i < fotos.length; i++) {
                                                MTImage card = fotos[i];
                                                card.setUseDirectGL(true);
                                                card.setDisplayCloseButton(true);
                                                card.setPositionGlobal(
                                                    new Vector3D(
                                                        Tools3D.getRandom(
                                                            10,
                                                            MT4jSettings.getInstance()
                                                                    .getScreenWidth()
                                                                - 100),
                                                        Tools3D.getRandom(
                                                            10,
                                                            MT4jSettings.getInstance()
                                                                    .getScreenHeight()
                                                                - 50),
                                                        0));
                                                card.toSize(200, 200);
                                                card.addGestureListener(
                                                    DragProcessor.class, new InertiaDragAction());
                                                lassoProcessor.addClusterable(
                                                    card); // make fotos lasso-able
                                                makePileProcessor.addClusterable(
                                                    card); // make elements pileable by this
                                                           // processor
                                                piler.addPileable(
                                                    card); // makes the photos pile-able
                                                pictureLayer.addChild(card);
                                              }
                                              progressBar.setVisible(false);
                                            }

                                            public boolean isLoop() {
                                              return false;
                                            }
                                          });
                                    }
                                  });
                              progressBar.setProgressInfoProvider(flickrLoader);
                              progressBar.setVisible(true);
                              // Run the thread
                              flickrLoader.start();
                              // Clear textarea
                              t.clear();
                              break;
                            default:
                              break;
                          }
                        }
                      }
                    });
                keyb.addChild(flickrButton);
                //			        getCanvas().addChild(0, keyb);
                getCanvas().addChild(keyb);
                keyb.setPositionGlobal(new Vector3D(app.width / 2f, app.height / 2f, 0));
                break;
              default:
                break;
            }
          }
        });

    this.getCanvas().addChild(pictureLayer);
    this.getCanvas().addChild(topLayer);
  }
Ejemplo n.º 11
0
 @Override
 public void shutDown() {
   app.unregisterKeyEvent(this);
 }
Ejemplo n.º 12
0
 @Override
 public void init() {
   app.registerKeyEvent(this);
 }
Ejemplo n.º 13
0
  /**
   * Instantiates a new mouse input source.
   *
   * @param pa the pa
   */
  public MouseInputSource(MTApplication pa) {
    super(pa);

    pa.registerMouseEvent(this);
    mouseBusy = false;
  }
Ejemplo n.º 14
0
  /**
   * Instantiates a new model display scene.
   *
   * @param mtApplication the mt application
   * @param name the name
   */
  public Space3DScene(MTApplication mtApplication, String name) {
    super(mtApplication, name);
    this.pa = mtApplication;

    if (!MT4jSettings.getInstance().isOpenGlMode()) {
      System.err.println("Scene only usable when using the OpenGL renderer! - See settings.txt");
      return;
    }

    this.setClearColor(new MTColor(200, 200, 200, 255));
    this.registerGlobalInputProcessor(new CursorTracer(pa, this));

    // Add a background image for the scene
    this.getCanvas()
        .addChild(new MTBackgroundImage(pa, pa.loadImage(imagesPath + "3040.jpg"), true));

    // Init light settings
    MTLight.enableLightningAndAmbient(pa, 150, 150, 150, 255);
    // Create a light source //I think GL_LIGHT0 is used by processing!
    //		MTLight light = new MTLight(pa, GL.GL_LIGHT3, new Vector3D(0,0,0));
    MTLight light = new MTLight(pa, GL.GL_LIGHT3, new Vector3D(pa.width / 5f, -pa.height / 10f, 0));

    // Set up a material to react to the light
    GLMaterial material = new GLMaterial(Tools3D.getGL(pa));
    material.setAmbient(new float[] {.1f, .1f, .1f, 1f});
    material.setDiffuse(new float[] {1.0f, 1.0f, 1.0f, 1f});
    material.setEmission(new float[] {.0f, .0f, .0f, 1f});
    material.setSpecular(new float[] {1.0f, 1.0f, 1.0f, 1f}); // almost white: very reflective
    material.setShininess(127); // 0=no shine,  127=max shine

    // Create the earth
    earth = new MTSphere(pa, "earth", 40, 40, 80, TextureMode.Projected); // TextureMode.Polar);
    earth.setLight(light);
    earth.setMaterial(material);
    earth.rotateX(earth.getCenterPointRelativeToParent(), -90);
    earth.setTexture(
        new GLTexture(
            pa,
            imagesPath + "worldMap.jpg",
            new GLTextureSettings(
                TEXTURE_TARGET.TEXTURE_2D,
                SHRINKAGE_FILTER.Trilinear,
                EXPANSION_FILTER.Bilinear,
                WRAP_MODE.CLAMP_TO_EDGE,
                WRAP_MODE.CLAMP_TO_EDGE)));
    earth.generateAndUseDisplayLists();
    earth.setPositionGlobal(
        new Vector3D(
            pa.width / 2f,
            pa.height / 2f,
            250)); // earth.setPositionGlobal(new Vector3D(200, 200, 250));
    // Animate earth rotation
    new Animation(
            "rotation animation", new MultiPurposeInterpolator(0, 360, 17000, 0, 1, -1), earth)
        .addAnimationListener(
            new IAnimationListener() {
              public void processAnimationEvent(AnimationEvent ae) {
                earth.rotateY(earth.getCenterPointLocal(), ae.getDelta(), TransformSpace.LOCAL);
              }
            })
        .start();

    // Put planets in a group that can be manipulated by gestures
    // so the rotation of the planets doesent get changed by the gestures
    MTComponent group = new MTComponent(mtApplication);
    group.setComposite(
        true); // This makes the group "consume" all picking and gestures of the children
    group.registerInputProcessor(new DragProcessor(mtApplication));
    group.addGestureListener(DragProcessor.class, new DefaultDragAction());
    group.addGestureListener(DragProcessor.class, new InertiaDragAction(80, 0.8f, 10));
    group.registerInputProcessor(new RotateProcessor(mtApplication));
    group.addGestureListener(RotateProcessor.class, new DefaultRotateAction());
    // Scale the earth from the center. Else it might get distorted
    group.registerInputProcessor(new ScaleProcessor(mtApplication));
    group.addGestureListener(
        ScaleProcessor.class,
        new IGestureEventListener() {
          public boolean processGestureEvent(MTGestureEvent ge) {
            ScaleEvent se = (ScaleEvent) ge;
            earth.scaleGlobal(
                se.getScaleFactorX(),
                se.getScaleFactorY(),
                se.getScaleFactorX(),
                earth.getCenterPointGlobal());
            return false;
          }
        });
    this.getCanvas().addChild(group);
    group.addChild(earth);

    // Create the moon
    final MTSphere moonSphere = new MTSphere(pa, "moon", 35, 35, 25, TextureMode.Polar);
    moonSphere.setMaterial(material);
    moonSphere.translate(new Vector3D(earth.getRadius() + moonSphere.getRadius() + 50, 0, 0));
    moonSphere.setTexture(
        new GLTexture(
            pa,
            imagesPath + "moonmap1k.jpg",
            new GLTextureSettings(
                TEXTURE_TARGET.RECTANGULAR,
                SHRINKAGE_FILTER.Trilinear,
                EXPANSION_FILTER.Bilinear,
                WRAP_MODE.CLAMP_TO_EDGE,
                WRAP_MODE.CLAMP_TO_EDGE)));
    moonSphere.generateAndUseDisplayLists();
    moonSphere.unregisterAllInputProcessors();
    // Rotate the moon around the earth
    new Animation(
            "moon animation", new MultiPurposeInterpolator(0, 360, 12000, 0, 1, -1), moonSphere)
        .addAnimationListener(
            new IAnimationListener() {
              public void processAnimationEvent(AnimationEvent ae) {
                moonSphere.rotateZ(
                    earth.getCenterPointLocal(), ae.getDelta(), TransformSpace.RELATIVE_TO_PARENT);
              }
            })
        .start();
    // Rotate the moon around ints own center
    new Animation(
            "moon animation around own axis",
            new MultiPurposeInterpolator(0, 360, 9000, 0, 1, -1),
            moonSphere)
        .addAnimationListener(
            new IAnimationListener() {
              public void processAnimationEvent(AnimationEvent ae) {
                moonSphere.rotateZ(
                    moonSphere.getCenterPointLocal(), -3 * ae.getDelta(), TransformSpace.LOCAL);
                moonSphere.rotateY(
                    moonSphere.getCenterPointLocal(), 0.5f * ae.getDelta(), TransformSpace.LOCAL);
              }
            })
        .start();
    earth.addChild(moonSphere);
  }
Ejemplo n.º 15
0
  /**
   * Inits the.
   *
   * @param x the x
   * @param y the y
   * @param width the width
   * @param height the height
   */
  private void init(float x, float y, float width, float height) {
    this.setNoStroke(true);
    this.setFillColor(new MTColor(255, 255, 255, 150));

    overlayGroup = new MTOverlayContainer(app, "Window Menu Overlay Group");

    if (menuImage == null) {
      menuImage =
          app.loadImage(
              MT4jSettings.getInstance().getDefaultImagesPath() + "blackRoundSolidCorner64sh2.png");
    }

    if (MT4jSettings.getInstance().isOpenGlMode()) {
      GLTextureSettings ts = new GLTextureSettings();
      ts.wrappingHorizontal = WRAP_MODE.CLAMP;
      ts.wrappingVertical = WRAP_MODE.CLAMP;
      GLTexture glTex = new GLTexture(app, menuImage.width, menuImage.height, ts);
      glTex.loadGLTexture(menuImage);
      this.setTexture(glTex);
    } else {
      this.setTexture(menuImage);
    }

    AbstractShape menuShape = this;
    menuShape.unregisterAllInputProcessors();
    menuShape.removeAllGestureEventListeners(DragProcessor.class);
    menuShape.registerInputProcessor(new DragProcessor(app));

    float buttonWidth = 80;
    float buttonHeight = 80;
    final float buttonOpacity = 170;

    // CLOSE BUTTON
    //		Vector3D a = new Vector3D(-width * 1.2f, height/2f);
    Vector3D a = new Vector3D(-width * 1.55f, 0);
    a.rotateZ(PApplet.radians(80));
    final MTRectangle closeButton =
        new MTRectangle(app, x + a.x, y + a.y, buttonWidth, buttonHeight);

    if (closeButtonImage == null) {
      closeButtonImage =
          app.loadImage(MT4jSettings.getInstance().getDefaultImagesPath() + "closeButton64.png");
    }

    closeButton.setTexture(closeButtonImage);
    closeButton.setFillColor(new MTColor(255, 255, 255, buttonOpacity));
    closeButton.setNoStroke(true);
    closeButton.setVisible(false);
    closeButton.removeAllGestureEventListeners(DragProcessor.class);
    closeButton.removeAllGestureEventListeners(RotateProcessor.class);
    closeButton.removeAllGestureEventListeners(ScaleProcessor.class);
    this.addChild(closeButton);

    // Check if this menu belongs to a window Scene (MTSceneWindow)
    // or was added to a normal scene
    // -> if its not a windowed scene we dont display the Restore button
    if (this.windowedScene) {
      // RESTORE BUTTON
      Vector3D b = new Vector3D(-width * 1.55f, 0);
      b.rotateZ(PApplet.radians(10));
      final MTRectangle restoreButton =
          new MTRectangle(app, x + b.x, y + b.y, buttonWidth, buttonHeight);

      if (restoreButtonImage == null) {
        restoreButtonImage =
            app.loadImage(
                MT4jSettings.getInstance().getDefaultImagesPath() + "restoreButton64.png");
      }

      restoreButton.setTexture(restoreButtonImage);
      restoreButton.setFillColor(new MTColor(255, 255, 255, buttonOpacity));
      restoreButton.setNoStroke(true);
      restoreButton.setVisible(false);
      restoreButton.removeAllGestureEventListeners(DragProcessor.class);
      restoreButton.removeAllGestureEventListeners(RotateProcessor.class);
      restoreButton.removeAllGestureEventListeners(ScaleProcessor.class);
      this.addChild(restoreButton);

      menuShape.addGestureListener(
          DragProcessor.class,
          new IGestureEventListener() {
            public boolean processGestureEvent(MTGestureEvent ge) {
              DragEvent de = (DragEvent) ge;
              switch (de.getId()) {
                case MTGestureEvent.GESTURE_STARTED:
                  restoreButton.setVisible(true);
                  closeButton.setVisible(true);
                  unhighlightButton(closeButton, buttonOpacity);
                  unhighlightButton(restoreButton, buttonOpacity);
                  break;
                case MTGestureEvent.GESTURE_UPDATED:
                  // Mouse over effect
                  if (closeButton.containsPointGlobal(de.getTo())) {
                    highlightButton(closeButton);
                  } else {
                    unhighlightButton(closeButton, buttonOpacity);
                  }
                  if (restoreButton.containsPointGlobal(de.getTo())) {
                    highlightButton(restoreButton);
                  } else {
                    unhighlightButton(restoreButton, buttonOpacity);
                  }
                  break;
                case MTGestureEvent.GESTURE_ENDED:
                  unhighlightButton(closeButton, buttonOpacity);
                  unhighlightButton(restoreButton, buttonOpacity);

                  InputCursor cursor = de.getDragCursor();
                  Vector3D restoreButtonIntersection =
                      restoreButton.getIntersectionGlobal(
                          Tools3D.getCameraPickRay(
                              getRenderer(),
                              restoreButton,
                              cursor.getCurrentEvtPosX(),
                              cursor.getCurrentEvtPosY()));
                  if (restoreButtonIntersection != null) {
                    logger.debug("--> RESTORE!");
                    MTSceneMenu.this.sceneTexture.restore();
                  }
                  Vector3D closeButtonIntersection =
                      closeButton.getIntersectionGlobal(
                          Tools3D.getCameraPickRay(
                              getRenderer(),
                              closeButton,
                              cursor.getCurrentEvtPosX(),
                              cursor.getCurrentEvtPosY()));
                  if (closeButtonIntersection != null) {
                    //							if (app.popScene()){
                    //								app.removeScene(scene); //FIXME wont work if the scene has a
                    // transition because we cant remove the still active scene
                    ////								destroy(); //this will be destroyed with the scene
                    //								sceneTexture.destroy(); //destroys also the MTSceneWindow and with it
                    // the scene
                    //								logger.debug("--> CLOSE!");
                    //							}
                    if (sceneTexture.restore()) {
                      //								app.removeScene(scene); //FIXME wont work if the scene has a
                      // transition because we cant remove the still active scene
                      //								destroy(); //this will be destroyed with the scene
                      sceneTexture
                          .destroy(); // destroys also the MTSceneWindow and with it the scene
                      logger.debug("--> CLOSE!");
                    }
                  }

                  restoreButton.setVisible(false);
                  closeButton.setVisible(false);
                  break;
                default:
                  break;
              }
              return false;
            }
          });
    } else {
      if (scene != null) {
        menuShape.addGestureListener(
            DragProcessor.class,
            new IGestureEventListener() {
              public boolean processGestureEvent(MTGestureEvent ge) {
                DragEvent de = (DragEvent) ge;
                switch (de.getId()) {
                  case MTGestureEvent.GESTURE_STARTED:
                    closeButton.setVisible(true);
                    unhighlightButton(closeButton, buttonOpacity);
                    break;
                  case MTGestureEvent.GESTURE_UPDATED:
                    // Mouse over effect
                    if (closeButton.containsPointGlobal(de.getTo())) {
                      highlightButton(closeButton);
                    } else {
                      unhighlightButton(closeButton, buttonOpacity);
                    }
                    break;
                  case MTGestureEvent.GESTURE_ENDED:
                    unhighlightButton(closeButton, buttonOpacity);

                    InputCursor cursor = de.getDragCursor();
                    Vector3D closeButtonIntersection =
                        closeButton.getIntersectionGlobal(
                            Tools3D.getCameraPickRay(
                                getRenderer(),
                                closeButton,
                                cursor.getCurrentEvtPosX(),
                                cursor.getCurrentEvtPosY()));
                    if (closeButtonIntersection != null) {
                      if (app.popScene()) {
                        destroy(); // Destroy this
                        scene.destroy(); // Destroy the scene
                        logger.debug("--> CLOSE!");
                      }
                    }
                    closeButton.setVisible(false);
                    break;
                  default:
                    break;
                }
                return false;
              }
            });
      }
    }
  }