Пример #1
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));
    }
  }
Пример #2
0
  public Scene6(MTApplication mtApplication, String name) {
    super(mtApplication, name, 6);
    this.mtApp = mtApplication;

    // Create a textfield
    MTTextArea textField =
        new MTTextArea(
            mtApplication,
            FontManager.getInstance()
                .createFont(mtApp, "arial.ttf", 50, new MTColor(251, 151, 29, 255)));
    textField.setNoFill(true);
    textField.setNoStroke(true);
    textField.setText("Ready?");
    this.getCanvas().addChild(textField);
    textField.setPositionGlobal(new Vector3D(mtApp.width / 2f, mtApp.height / 4f));
    textField.removeAllGestureEventListeners(DragProcessor.class); // To enable drag & drop
    textField.removeAllGestureEventListeners(RotateProcessor.class);

    startButton = new MTRoundRectangle(mtApp, 0, 0, 0, 200, 150, radius, radius);
    startButton.setPositionRelativeToParent(new Vector3D(mtApp.width / 2f, mtApp.height / 2f));
    startButton.setStrokeWeight(5);
    startButton.setFillColor(new MTColor(254, 201, 71, 255));
    startButton.setStrokeColor(new MTColor(251, 151, 29, 255));
    startButton.removeAllGestureEventListeners(DragProcessor.class); // To enable drag & drop
    startButton.removeAllGestureEventListeners(RotateProcessor.class);

    MTTextArea startButtonTextField =
        new MTTextArea(
            mtApplication,
            FontManager.getInstance()
                .createFont(mtApp, "arial.ttf", 50, new MTColor(251, 151, 29, 255)));
    startButtonTextField.setNoFill(true);
    startButtonTextField.setNoStroke(true);
    startButtonTextField.setText("Start");
    startButton.addChild(startButtonTextField);
    startButtonTextField.setPositionGlobal(new Vector3D(mtApp.width / 2f, mtApp.height / 2f));
    startButtonTextField.removeAllGestureEventListeners(
        DragProcessor.class); // To enable drag & drop
    startButtonTextField.removeAllGestureEventListeners(RotateProcessor.class);

    this.getCanvas().addChild(startButton);

    startButtonTextField.registerInputProcessor(new TapProcessor(mtApplication));
    startButtonTextField.addGestureListener(
        TapProcessor.class,
        new IGestureEventListener() {
          @Override
          public boolean processGestureEvent(MTGestureEvent ge) {
            TapEvent te = (TapEvent) ge;
            switch (te.getTapID()) {
              case TapEvent.TAPPED:
                setTransition(slideLeftTransition);
                if (workPlaceScene == null) {
                  workPlaceScene = new WorkPlaceScene(mtApp, "WorkPlaceScene");
                  mtApp.addScene(workPlaceScene);
                }
                // Do the scene change
                mtApp.changeScene(workPlaceScene);
                break;
              default:
                break;
            }

            return false;
          }
        });

    super.addButtons(6);

    // Set a scene transition - Flip transition only available using opengl supporting the FBO
    // extenstion
    if (MT4jSettings.getInstance().isOpenGlMode() && GLFBO.isSupported(mtApp)) {
      slideLeftTransition = new SlideTransition(mtApp, 700, true);
      slideRightTransition = new SlideTransition(mtApp, 700, false);
    } else {
      this.setTransition(new FadeTransition(mtApp));
    }

    // Register flick gesture with the canvas to change the scene
    getCanvas().registerInputProcessor(new FlickProcessor());
    getCanvas()
        .addGestureListener(
            FlickProcessor.class,
            new IGestureEventListener() {
              public boolean processGestureEvent(MTGestureEvent ge) {
                FlickEvent e = (FlickEvent) ge;
                if (e.getId() == MTGestureEvent.GESTURE_ENDED && e.isFlick()) {
                  switch (e.getDirection()) {
                    case WEST:
                    case NORTH_WEST:
                    case SOUTH_WEST:
                      setTransition(slideLeftTransition);
                      if (workPlaceScene == null) {
                        workPlaceScene = new WorkPlaceScene(mtApp, "WorkPlaceScene");
                        mtApp.addScene(workPlaceScene);
                      }
                      // Do the scene change
                      mtApp.changeScene(workPlaceScene);
                      break;
                    case EAST:
                    case NORTH_EAST:
                    case SOUTH_EAST:
                      setTransition(slideRightTransition);
                      if (mtApp.getScene("Scene 5") == null) {
                        scenePrevious = new Scene5(mtApp, "Scene 5");
                        mtApp.addScene(scenePrevious);
                        mtApp.changeScene(scenePrevious);
                      } else {
                        mtApp.changeScene(mtApp.getScene("Scene 5"));
                      }
                      break;
                    default:
                      break;
                  }
                }
                return false;
              }
            });
  }