Package org.mt4j.components.visibleComponents.shapes

Examples of org.mt4j.components.visibleComponents.shapes.AbstractShape$TranslationAnimationListener


    if (inputEvent instanceof AbstractCursorInputEvt) {
      AbstractCursorInputEvt cursorEvt = (AbstractCursorInputEvt)inputEvent;
      InputCursor c = ((AbstractCursorInputEvt)inputEvent).getCursor();
      Vector3D position = new Vector3D(cursorEvt.getPosX(), cursorEvt.getPosY());

      AbstractShape displayShape = null;
      switch (cursorEvt.getId()) {
      case AbstractCursorInputEvt.INPUT_DETECTED:
        displayShape = createDisplayComponent(app, position);
        cursorIDToDisplayShape.put(c, displayShape);
        overlayGroup.addChild(displayShape);
       
//        compToCreationTime.put(displayShape, System.currentTimeMillis()); //FIXME REMOVE
//        displayShape.setUserData("Cursor", c);//FIXME REMOVE
        break;
      case AbstractCursorInputEvt.INPUT_UPDATED:
        displayShape = cursorIDToDisplayShape.get(c);
        if (displayShape != null){
          displayShape.setPositionGlobal(position);
        }
        break;
      case AbstractCursorInputEvt.INPUT_ENDED:
        displayShape = cursorIDToDisplayShape.remove(c);
        if (displayShape != null){
          displayShape.destroy();
        }
        break;
      default:
        break;
      }
View Full Code Here


                  /*
                      //Use random brush from brushes
                      int brushIndex = Math.round(Tools3D.getRandom(0, brushes.length-1));
                      AbstractShape brushToDraw = brushes[brushIndex];
                   */
                  AbstractShape brushToDraw = drawShape;

                  //Draw brush
                  brushToDraw.drawComponent(mtApp.g);

                  mtApp.popMatrix();
                }
                mtApp.popMatrix();

View Full Code Here

   *
   * @return the largest svg comp
   */
  public static AbstractShape getLargestSvgComp(MTComponent comp, AbstractShape compWithBiggestBoundingRect){
    if (comp instanceof AbstractShape) {
      AbstractShape shape = (AbstractShape) comp;
      float rectWidthGlobal = shape.getWidthXY(TransformSpace.GLOBAL);
      float rectHeightGlobal = shape.getHeightXY(TransformSpace.GLOBAL);

      if (
          compWithBiggestBoundingRect != null
      ){
//        System.out.println("Fromer biggest != null, checking if " + comp.getName() + " is bigger.");
View Full Code Here

      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(x + a.x, y + a.y, buttonWidth, buttonHeight, app);
   
    if (closeButtonImage == null){
      closeButtonImage = app.loadImage(MT4jSettings.getInstance().getDefaultImagesPath() +
//          "close_32.png"));
//          "126182-simple-black-square-icon-alphanumeric-circled-x3_cr.png"));
//          "124241-matte-white-square-icon-alphanumeric-circled-x3_cr.png");
          "closeButton64.png");
    }
   
    closeButton.setTexture(closeButtonImage);
    closeButton.setFillColor(new MTColor(255, 255, 255, buttonOpacity));
    closeButton.setNoStroke(true);
    closeButton.setVisible(false);
    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(x + b.x, y + b.y, buttonWidth, buttonHeight, app);
     
      if (restoreButtonImage == null){
        restoreButtonImage = app.loadImage(MT4jSettings.getInstance().getDefaultImagesPath() +
//            "window_app_32.png"));
//            "126630-simple-black-square-icon-business-document10-sc1_cr.png");
    //        restoreButton.setFillColor(new MTColor(150, 150, 250, 200));
            "restoreButton64.png");
      }
     
      restoreButton.setTexture(restoreButtonImage);
      restoreButton.setFillColor(new MTColor(255, 255, 255, buttonOpacity));
      restoreButton.setNoStroke(true);
      restoreButton.setVisible(false);
      this.addChild(restoreButton);
     
      menuShape.addGestureListener(DragProcessor.class, new IGestureEventListener() {
        public boolean processGestureEvent(MTGestureEvent ge) {
          DragEvent de = (DragEvent)ge;
          switch (de.getId()) {
          case MTGestureEvent.GESTURE_DETECTED:
            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_DETECTED:
              closeButton.setVisible(true);
View Full Code Here

          logger.error("Discarding clip-path path element. Not implemented.");
          return null;
        }
       
        //Create the shape
        AbstractShape pathComp = getLivePathComponent(pathElem, noFill, windingRule);
       
        try{
          pathComp.setLocalMatrix(currentLocalTransformMatrix);
        }catch(Exception e){
          logger.error(e.getMessage());
        }
        returnComp = pathComp;
      }else if (gfxElem instanceof SVGOMPolygonElement){
        SVGOMPolygonElement polygonElem = (SVGOMPolygonElement)gfxElem;
       
        //Create the shape
        AbstractShape comp = getLivePolygonComponent(polygonElem, noFill, windingRule);
               
        try{
          comp.setLocalMatrix(currentLocalTransformMatrix);
        }catch(Exception e){
          logger.error(e.getMessage());
        }
        returnComp = comp;
      }else if (gfxElem instanceof SVGOMPolylineElement){
        SVGOMPolylineElement polyLineElem = (SVGOMPolylineElement)gfxElem;
       
        //Create Vertex[] from points
        SVGPointList pointList = polyLineElem.getPoints();
        Vertex[] vertices = new Vertex[pointList.getNumberOfItems()];
        for (int i = 0; i < pointList.getNumberOfItems(); i++) {
        SVGPoint p = pointList.getItem(i);
        vertices[i] = new Vertex(p.getX(), p.getY(),0);
        }
       
        //Create the shape
        AbstractShape comp = createPoly(vertices);
       
        try{
          comp.setLocalMatrix(currentLocalTransformMatrix);
        }catch(Exception e){
          logger.error(e.getMessage());
        }
        returnComp = comp;
      }else if (gfxElem instanceof SVGOMRectElement){
        SVGOMRectElement rectElem = (SVGOMRectElement)gfxElem;
        if (isUnderClipPath(rectElem)){
          logger.error("discarding clip-path Rect");
          return null;
        }
       
        float x     = rectElem.getX().getBaseVal().getValue();
        float y     = rectElem.getY().getBaseVal().getValue();
        float width   = rectElem.getWidth().getBaseVal().getValue();
        float height   = rectElem.getHeight().getBaseVal().getValue();
        float rx     = rectElem.getRx().getBaseVal().getValue();
        float ry     = rectElem.getRy().getBaseVal().getValue();
       
        AbstractShape comp;
        //Create a normal rectangle or a round rectangle
        if (rx != 0.0f || ry != 0.0f){
          if (rx > width/2 )
            rx = width/2;
          if (ry > height/2 )
            ry = height/2;
          comp = new MTRoundRectangle(x,y,0, width,height,rx, ry, pa);
        }else{
          comp = new MTRectangle(x,y, width,height, pa);
        }
       
        try{
          comp.setLocalMatrix(currentLocalTransformMatrix);
        }catch(Exception e){
          logger.error(e.getMessage());
        }
        returnComp = comp;
      }else if (gfxElem instanceof SVGOMEllipseElement){
        SVGOMEllipseElement ellipseElem = (SVGOMEllipseElement)gfxElem;
        float cx = ellipseElem.getCx().getBaseVal().getValue();
        float cy = ellipseElem.getCy().getBaseVal().getValue();
        float r  = ellipseElem.getRx().getBaseVal().getValue();
        float r2 = ellipseElem.getRy().getBaseVal().getValue();
       
        Vertex middlePoint = new Vertex(cx,cy,0);
        //Apply transformation, transform centerpoint and the radii
        try{
          middlePoint.transform(currentLocalTransformMatrix);
        }catch(Exception e){
          logger.error(e.getMessage());
        }
       
        //somehow the circle radii need to be doubled
        //or else theyre too small => processing bug?
//        r*=2;
//        r2*=2;
        MTEllipse comp = new MTEllipse(pa, middlePoint, r, r2);
        returnComp = comp;
      }else if (gfxElem instanceof SVGOMCircleElement){
        SVGOMCircleElement circleElem = (SVGOMCircleElement)gfxElem;
        float cx = circleElem.getCx().getBaseVal().getValue();
        float cy = circleElem.getCy().getBaseVal().getValue();
        float r = circleElem.getR().getBaseVal().getValue();
        float r2 = circleElem.getR().getBaseVal().getValue();
       
        Vertex middlePoint = new Vertex(cx,cy,0);
        //Apply transformation, transform centerpoint and the radii
        try{
          middlePoint.transform(currentLocalTransformMatrix);
        }catch(Exception e){
          logger.error(e.getMessage());
        }
       
        //somehow the circle radii need to be doubled
        //or else theyre too small => processing bug?
//        r*=2;
//        r2*=2;
        MTEllipse comp = new MTEllipse(pa, middlePoint, r, r2);
        returnComp = comp;
      }else if (gfxElem instanceof SVGOMLineElement){
        SVGOMLineElement line = (SVGOMLineElement)gfxElem;
        float x1 = line.getX1().getBaseVal().getValue();
        float y1 = line.getY1().getBaseVal().getValue();
        float x2 = line.getX2().getBaseVal().getValue();
        float y2 = line.getY2().getBaseVal().getValue();
        //logger.debug("Line x1: " + x1 + ",y1:" + y1 + ",x2:" + x2 + ",y2:" + y2);
       
        MTLine comp = new MTLine(pa, x1,y1 ,x2,y2);
      
        try{
          comp.setLocalMatrix(currentLocalTransformMatrix);
        }catch(Exception e){
          logger.error(e.getMessage());
        }
        returnComp = comp;
      }else if (gfxElem instanceof SVGOMClipPathElement){
      }else if (gfxElem instanceof SVGOMDefsElement){
      }else if (gfxElem instanceof SVGOMMaskElement){
      }else if (gfxElem instanceof SVGOMSwitchElement){
      }else if (gfxElem instanceof SVGOMFlowRootElement){
      }else if (gfxElem instanceof SVGURIReferenceGraphicsElement){
      }else if (gfxElem instanceof BindableElement){
      }else if (gfxElem instanceof SVGOMForeignObjectElement){
      }else if (gfxElem instanceof SVGOMToBeImplementedElement){
      }
     
      //Do the finishing touch of the svg graphics element
      if (returnComp != null){
        returnComp.setName(gfxElem.getTagName());
       
        //Set style infos
        if (returnComp instanceof AbstractVisibleComponent){
          AbstractVisibleComponent comp = (AbstractVisibleComponent)returnComp;
          //Set Fill
          comp.setFillColor(new MTColor(fillR, fillG, fillB, fillOpacity));
          comp.setNoFill(noFill);
          //Set Stroke
          comp.setStrokeColor(new MTColor(strokeR, strokeG, strokeB, strokeOpacity));
          //Opengl cant handle big lines well
          //So cap at width 3
          if (strokeWidth > 2.0f)
            strokeWidth = 2.0f;
          comp.setStrokeWeight(strokeWidth);
          comp.setNoStroke(noStroke);
          //Other
          comp.setDrawSmooth(true);
          comp.setPickable(false);
         
          //Hack for smoothing non stroked components with a stroke same as fillcolor
          if (comp.isNoStroke()
           && linearGradient == null
          ){ 
            comp.setStrokeColor(new MTColor(fillR, fillG, fillB, fillOpacity)); //fillOpacity
            comp.setStrokeWeight(0.6f);
            //Ellipse doesent smooth right with 0.1f strokeweight
            if (comp instanceof MTEllipse){
              comp.setStrokeWeight(1.0f);
            }
            comp.setNoStroke(false);
          }

          //Some settings for Geometric shapes (actually should all be)
          if (comp instanceof AbstractShape ){
            AbstractShape shape = (AbstractShape)comp;
            //Set a bounding rectangle to check first at picking
            if (shape.getVerticesLocal().length >= 3){
              shape.setBoundsBehaviour(AbstractShape.BOUNDS_CHECK_THEN_GEOMETRY_CHECK);
              //shape.setBoundingShape(new BoundsZPlaneRectangle(shape)); //already done by override, (ie svgpoly)
             
              //Create amd apply the linear gradient if existant and if we are in opengl rendering mode
              if (MT4jSettings.getInstance().isOpenGlMode()){
                if (linearGradient != null){
                  FillPaint gradient = this.createLinearGradient(linearGradient, gfxElem, originalFillOpacity, shape);
                  if (gradient != null){
                    shape.setFillPaint(gradient);
                  }
                }
                if (radialGradient != null){
                  FillPaint gradient = this.createRadialGradient(radialGradient, gfxElem, opacity, shape);
                  if (gradient != null){
                    shape.setFillPaint(gradient);
                  }
                }
              //Per default use direct gl drawing and displaylists in OGL mode
              if (pa instanceof MTApplication) {
                MTApplication app = (MTApplication) pa;
                app.invokeLater(new InvokeLaterAction(shape));
              }
              }
              //IF shape has no or only 1 vertex return null
            }else if (shape.getVerticesLocal().length < 2){
              return null;
            }else{
              shape.setBoundsBehaviour(AbstractShape.BOUNDS_DONT_USE);
              shape.setBounds(null);
//              shape.setUseDirectGL(false);
            }
           
            //Allow for picking the shape
            shape.setPickable(true);
           
            //Assign default gestures
//            shape.assignGestureClassAndAction(DragGestureAnalyzer.class, defaultDragAction);
//            shape.registerInputAnalyzer(new DragDetector(pa));
//            shape.setGestureAllowance(DragDetector.class, true);
View Full Code Here

   *
   * @return the float[]
   */
  private  float[] calcBounds(MTComponent currentComp, float[] bounds){
    if (currentComp instanceof AbstractShape){
      AbstractShape shape = (AbstractShape)currentComp;
      Vertex[] globalVecs = shape.getVerticesGlobal();
      for (int j = 0; j < globalVecs.length; j++) {
        Vertex v = globalVecs[j];
        if (v.x < bounds[0])
          bounds[0] = v.x;
        if (v.x > bounds[1])
View Full Code Here

   * @return the largest svg comp
   */
  private AbstractShape getLargestSvgComp(MTComponent comp, AbstractShape compWithBiggestBoundingRect, float biggestWidth, float biggestHeight){
////    System.out.println("Checking: " + comp.getName());
    if (comp instanceof AbstractShape) {
      AbstractShape shape = (AbstractShape) comp;
      float rectWidthGlobal = shape.getWidthXY(TransformSpace.GLOBAL);
      float rectHeightGlobal = shape.getHeightXY(TransformSpace.GLOBAL);
      if (
//          compWithBiggestBoundingRect != null
             biggestWidth > 0
          && biggestHeight > 0
      ){
View Full Code Here

    comp.setGestureAllowance(ScaleProcessor.class, false);
    comp.setGestureAllowance(TapProcessor.class, false);
//    comp.unregisterAllInputProcessors();
//    /*
    if (comp instanceof AbstractShape){
      AbstractShape shape = (AbstractShape)comp;
      if (!shape.hasBounds() && !(shape.getBounds() instanceof BoundsZPlaneRectangle)){
        shape.setBounds(new BoundsZPlaneRectangle(shape));
      }
      shape.setBoundsBehaviour(boundsBehaviour);
    }
//    */
    for(MTComponent child : comp.getChildren()){
      setSvgOptionsRecursive(child, boundsBehaviour);
    }
View Full Code Here

TOP

Related Classes of org.mt4j.components.visibleComponents.shapes.AbstractShape$TranslationAnimationListener

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.