Exemplo n.º 1
0
 public void setNextScene(Iscene nextScene, PImage arrow) {
   nextSceneInner = nextScene;
   // Button to get to the next scene
   MTImageButton nextSceneButton = new MTImageButton(arrow, mtApp);
   nextSceneButton.setNoStroke(true);
   if (MT4jSettings.getInstance().isOpenGlMode()) nextSceneButton.setUseDirectGL(true);
   nextSceneButton.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent ae) {
           switch (ae.getID()) {
             case TapEvent.BUTTON_CLICKED:
             case TapEvent.BUTTON_UP:
               // Save the current scene on the scene stack before changing
               mtApp.pushScene();
               mtApp.changeScene(nextSceneInner);
               break;
             default:
               break;
           }
         }
       });
   getCanvas().addChild(nextSceneButton);
   nextSceneButton.setPositionGlobal(
       new Vector3D(
           mtApp.width - nextSceneButton.getWidthXY(TransformSpace.GLOBAL) - 5,
           mtApp.height - nextSceneButton.getHeightXY(TransformSpace.GLOBAL) - 5,
           0));
 }
Exemplo n.º 2
0
  public SlideScene2(
      MTApplication mtApplication, String name, PImage pImage, boolean hasPrev, PImage arrow) {
    super(mtApplication, name);
    this.mtApp = mtApplication;

    // Set the background color
    this.setClearColor(new MTColor(0, 0, 0, 0));

    this.registerGlobalInputProcessor(new CursorTracer(mtApp, this));

    MTRectangle rect = new MTRectangle(pImage, mtApplication);
    this.getCanvas().addChild(rect);
    rect.setPositionGlobal(new Vector3D(mtApplication.width / 2f, mtApplication.height / 2f));

    if (hasPrev) {

      MTImageButton previousSceneButton = new MTImageButton(arrow, mtApplication);
      previousSceneButton.setNoStroke(true);
      if (MT4jSettings.getInstance().isOpenGlMode()) previousSceneButton.setUseDirectGL(true);
      previousSceneButton.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
              switch (ae.getID()) {
                case TapEvent.BUTTON_CLICKED:
                case TapEvent.BUTTON_UP:
                  mtApp.popScene();
                  break;
                default:
                  break;
              }
            }
          });
      getCanvas().addChild(previousSceneButton);
      previousSceneButton.scale(
          -1, 1, 1, previousSceneButton.getCenterPointLocal(), TransformSpace.LOCAL);
      previousSceneButton.setPositionGlobal(
          new Vector3D(
              previousSceneButton.getWidthXY(TransformSpace.GLOBAL) + 5,
              mtApp.height - previousSceneButton.getHeightXY(TransformSpace.GLOBAL) - 5,
              0));
    }

    // Set a scene transition - Flip transition only available using opengl supporting the FBO
    // extenstion
    if (MT4jSettings.getInstance().isOpenGlMode() && GLFBO.isSupported(mtApp))
      this.setTransition(new FlipTransition(mtApp, 700));
    else {
      this.setTransition(new FadeTransition(mtApp));
    }
  }
Exemplo n.º 3
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);
  }