예제 #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
파일: SceneUtils.java 프로젝트: Ezea85/ypyi
  public static void addUniqueEditBar(final MTApplication mtApplication, MTComponent component) {

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

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

    String path = StartYPYIShell.getPathToIconsYPYI();

    //		final MTRoundRectangle frame = new MTRoundRectangle(-50,-50, 0,
    // mtApplication.width+100,mtApplication.height+100, 25,25, mtApplication);
    final MTRectangle frame =
        new MTRectangle(
            -50, -50, 0, mtApplication.width + 100, mtApplication.height + 100, mtApplication);
    frame.setSizeXYGlobal(mtApplication.width, mtApplication.height);
    frame.setNoFill(true);
    frame.sendToFront();
    frame.setPickable(false);
    component.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 w = new Float(frame.getWidthXY(TransformSpace.GLOBAL)).intValue();
    int h = new Float(frame.getHeightXY(TransformSpace.GLOBAL)).intValue();

    final MTSceneTexture sceneTexture = new MTSceneTexture(mtApplication, 0, 0, w, h, 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);
    float yButton = mtApplication.height - (eraser.height / 3);
    eraserButton.translate(new Vector3D(480, yButton, 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);

    eraserButton.scale(2f, 2f, 1, eraserButton.getCenterPointLocal(), TransformSpace.LOCAL);

    // 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(580f, yButton, 0));
    penButton.setNoStroke(true);
    penButton.setStrokeColor(new MTColor(0, 0, 0));
    penButton.scale(2f, 2f, 1, penButton.getCenterPointLocal(), TransformSpace.LOCAL);

    // 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(660f, yButton, 0));
    brushButton.setStrokeColor(new MTColor(0, 0, 0));
    brushButton.setNoStroke(true);
    brushButton.scale(1.5f, 1.5f, 1, brushButton.getCenterPointLocal(), TransformSpace.LOCAL);
    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(
            705f,
            mtApplication.height
                - (eraser.height / 1.5f)
                - colorWidget.getHeightXY(TransformSpace.GLOBAL),
            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(780f, yButton, 0));
    colPickButton.setNoStroke(true);
    colPickButton.scale(2f, 2f, 1, colPickButton.getCenterPointLocal(), TransformSpace.LOCAL);
    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, 400, 76, 0.05f, 2.0f, mtApplication);

    slider.setValue(0);
    frame.addChild(slider);
    //        slider.rotateZ(new Vector3D(), 90, TransformSpace.LOCAL);
    slider.translate(new Vector3D(880, mtApplication.height - (eraser.height / 1.5f)));
    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.png");
    final MTImageButton editButton = new MTImageButton(editIcon, mtApplication);
    frame.addChild(editButton);
    editButton.translate(new Vector3D(360f, yButton, 0));
    editButton.setNoStroke(true);
    editButton.setStrokeColor(new MTColor(0, 0, 0));
    editButton.scale(2f, 2f, 1, editButton.getCenterPointLocal(), TransformSpace.LOCAL);

    PImage handIcon = mtApplication.loadImage(path + "hand2.png");
    final MTImageButton handButton = new MTImageButton(handIcon, mtApplication);
    frame.addChild(handButton);
    handButton.translate(new Vector3D(250f, yButton, 0));
    handButton.setNoStroke(true);
    handButton.setStrokeColor(new MTColor(0, 0, 0));
    handButton.scale(2f, 2f, 1, handButton.getCenterPointLocal(), TransformSpace.LOCAL);

    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;
            }
          }
        });
  }