Package org.mt4j.components.visibleComponents.widgets

Examples of org.mt4j.components.visibleComponents.widgets.MTTextArea


    this.setClearColor(new MTColor(150, 188, 146, 255));
   
    this.registerGlobalInputProcessor(new CursorTracer(mtApp, this));
   
    //Create a textfield
    MTTextArea textField = new MTTextArea(mtApplication, FontManager.getInstance().createFont(mtApplication, "arial.ttf",
        50, new MTColor(255, 255, 255, 255), new MTColor(255, 255, 255, 255)));
    textField.setNoFill(true);
    textField.setNoStroke(true);
    textField.setText("Scene 3");
    this.getCanvas().addChild(textField);
    textField.setPositionGlobal(new Vector3D(mtApplication.width/2f, mtApplication.height/2f));
   
    //Button to return to the previous scene
    PImage arrow = mtApplication.loadImage(imagePath + "arrowRight.png");
    MTImageButton previousSceneButton = new MTImageButton(arrow, mtApplication);
    previousSceneButton.setNoStroke(true);
View Full Code Here


                // we have to check font/color etc at every character, not only at new positon because
                //pos doesent change at tspans without new posinfo
                //check if equal to last used font and if equal original text font
                if ( fontChanged || textPositionChanged         
                ){ //Make a new textarea if the text position changed or if the font changed at the current character
                  MTTextArea previousTextArea = null;
                  if (!textAreas.isEmpty()){
                    previousTextArea = textAreas.get(textAreas.size()-1);
                  }

                  float newXPos = 0;
                  float newYPos = 0 ;

                  //If there is a previous text, get its ending coordinates
                  //for the DX and DY shift info for the next text area
                  if (previousTextArea != null){
                    PositionAnchor oldAnchor = previousTextArea.getAnchor();
//                    previousTextArea.setAnchor(PositionAnchor.LOWER_RIGHT);
                    previousTextArea.setAnchor(PositionAnchor.UPPER_LEFT);
                    //Calculate last/current textposition for DX and DY use
                    //add up the last textareas start position end position(width)
                    Vector3D lastPos = previousTextArea.getPosition(TransformSpace.LOCAL);
//                    lastPos.addLocal(new Vector3D(previousTextArea.getWidthXY(TransformSpace.LOCAL) - 1 * previousTextArea.getInnerPaddingLeft(),0));
                    lastPos.addLocal(new Vector3D(previousTextArea.getWidthXY(TransformSpace.LOCAL) - 2 * previousTextArea.getInnerPaddingLeft(),0));
//                    newXPos = lastPos.x - previousTextArea.getInnerPaddingLeft();
                    newXPos = lastPos.x;
                    newXPos += (Float)previousTextArea.getUserData("XPos");

                    newYPos = lastPos.y;
//                    newYPos -= previousTextArea.getInnerPaddingTop();
//                    newYPos += fontToUse.getFontMaxDescent(); //FIXME WHY NEVESSARY?
                    newYPos += (Float)previousTextArea.getUserData("YPos");
                    previousTextArea.setAnchor(oldAnchor);
                  }

                  //IF absolute x or y is present overwrite the position values from the last textarea
                  if (charX != null)
                    newXPos = (Float)charX;
                  if (charY != null)
                    newYPos = (Float)charY;
                  if (charDX != null)
                    newXPos += (Float)charDX;
                  if (charDY != null)
                    newYPos += (Float)charDY;
                 
                  // Create the text area \\
                  MTTextArea t = new MTTextArea(pa, fontToUse);
                  t.setNoFill(true);
                  t.setNoStroke(true);
                  textAreas.add(t);
                  try{
                    t.setLocalMatrix(new Matrix(currentLocalTransformMatrix));
                  }catch(Exception e){
                    logger.error(e.getMessage());
                  }

                  //FIXME TEST
//                  if (previousTextArea != null && !textPositionChange){
//                  t.setAnchor(PositionAnchor.LOWER_LEFT);
//                  t.setUserData("posRelParent", new Vector3D(newXPos , newYPos - fontToUse.getFontMaxDescent() , 0));
//                  logger.debug("Character '" + currentChar + "' -> Anchor: LOWER_LEFT");
//                  }else{
                  Value v = CSSUtilities.getComputedStyle(textElement, SVGCSSEngine.TEXT_ANCHOR_INDEX);
                  //INFO: we have to move the BASELINE of the text to the svg position
                  //The textarea is usually fontmaxascent+fontmaxdescent+2*innerPadding big!
                  switch (v.getStringValue().charAt(0)) {
                  case 'e':
                    t.setAnchor(PositionAnchor.LOWER_RIGHT);
                    t.setUserData("posRelParent", new Vector3D((newXPos + t.getInnerPaddingLeft()) , newYPos - fontToUse.getFontMaxDescent()  +  t.getInnerPaddingTop() , 0));
//                    t.setPositionRelativeToParent(new Vector3D(newXPos, newYPos - font.getFontMaxDescent() , 0));
                    logger.debug("Character '" + currentChar + "' -> Anchor: LOWER_RIGHT");
                    break;
                  case 'm': //text-anchor="middle"
                    t.setAnchor(PositionAnchor.CENTER);
//                    t.setUserData("posRelParent", new Vector3D(newXPos, newYPos - fontToUse.getFontMaxAscent()*0.5f - fontToUse.getFontMaxDescent()*0.5f , 0));
//                    t.setUserData("posRelParent", new Vector3D(newXPos, newYPos - fontToUse.getFontAbsoluteHeight()*0.5f + t.getInnerPaddingTop() , 0));
//                    t.setPositionRelativeToParent(new Vector3D(newXPos, newYPos - font.getFontMaxAscent()*0.5f - font.getFontMaxDescent()*0.5f, 0)); //- font.getFontMaxAscent()*0.5f
                    logger.debug("Character '" + currentChar + "' -> Anchor: CENTER");
                    t.setUserData("posRelParent", new Vector3D((newXPos), (newYPos - fontToUse.getFontMaxDescent() + t.getInnerPaddingTop()) - t.getHeightXY(TransformSpace.LOCAL)/2f , 0));
                    break;
                  default: //text-anchor="start" //default!
                    t.setAnchor(PositionAnchor.LOWER_LEFT);
//                    t.setUserData("posRelParent", new Vector3D(newXPos -t.getInnerPaddingLeft(), newYPos - fontToUse.getFontMaxDescent() + t.getInnerPaddingTop() , 0));
                    t.setUserData("posRelParent", new Vector3D(newXPos -t.getInnerPaddingLeft(), newYPos - fontToUse.getFontMaxDescent() + t.getInnerPaddingTop() , 0));
                   
//                    t.setAnchor(PositionAnchor.UPPER_LEFT);
//                    t.setUserData("posRelParent", new Vector3D(newXPos -t.getInnerPaddingLeft(), newYPos, 0));
//                  t.setPositionRelativeToParent(new Vector3D(newXPos, newYPos - font.getFontMaxDescent() , 0));
                  logger.debug("Character '" + currentChar + "' -> Anchor: LOWER_LEFT");
                  }
                  t.setUserData("XPos", newXPos);
                  t.setUserData("YPos", newYPos);
//                  }
                }
                //Add character to the current textarea in the list
                if (!textAreas.isEmpty()){
                  textAreas.get(textAreas.size()-1).appendCharByUnicode(new Character(currentChar).toString());             
                }
              }
              //Set the positions of the textareas
              for (Iterator<MTTextArea> iterator = textAreas.iterator(); iterator.hasNext();) {
                MTTextArea textArea = (MTTextArea) iterator.next();
                logger.debug("Adding text area at: " + (Vector3D) textArea.getUserData("posRelParent"));
                textArea.setPositionRelativeToParent((Vector3D) textArea.getUserData("posRelParent"));
              }
              comps.addAll(textAreas);
            }

            /*
 
View Full Code Here

    MTComponent uiLayer = new MTComponent(mtApplication, new MTCamera(mtApplication));
    uiLayer.setDepthBufferDisabled(true);
    getCanvas().addChild(uiLayer);
    IFont font = FontManager.getInstance().createFont(mtApplication, "arial", 50, new MTColor(255,255,255), new MTColor(0,0,0));
   
    t1 = new MTTextArea(mtApplication, font);
    t1.setPickable(false);
    t1.setNoFill(true);
    t1.setNoStroke(true);
    t1.setPositionGlobal(new Vector3D(5,30,0));
    uiLayer.addChild(t1);
   
    t2 = new MTTextArea(mtApplication, font);
    t2.setPickable(false);
    t2.setNoFill(true);
    t2.setNoStroke(true);
    t2.setPositionGlobal(new Vector3D(mtApplication.width - 65 , 30,0));
    uiLayer.addChild(t2);
View Full Code Here

      @Override
      public void runMTTestCode() {
        IFont font1 = FontManager.getInstance().createFont(getMTApplication(), "arial.ttf", 16, MTColor.GREY, MTColor.GREY, true);
        IFont font2 = FontManager.getInstance().createFont(getMTApplication(), "arial", 16, MTColor.BLACK, MTColor.BLACK, false);
       
        MTTextArea ta = new MTTextArea(getMTApplication(), font1);
        ta.setText("this is a\ntest text written for testing\npurposes");
        scene.getCanvas().addChild(ta);
        ta.setFont(font2);
       
        MTTextArea ta2 = new MTTextArea(200,200, 100,200, font2, getMTApplication());
        ta2.setText("this is another test text written for testing purposes");
        scene.getCanvas().addChild(ta2);
        ta2.setFont(font1);
      }
    });
  }
View Full Code Here

                //Remove old Textfield from keyboard if there is any
                if (textInputListener != null){
                 
                  if (textInputListener instanceof MTTextArea){
                    MTTextArea ta = (MTTextArea)textInputListener;
                    ta.setGestureAllowance(DragProcessor.class, true);
                    ta.setGestureAllowance(RotateProcessor.class, true);
                    ta.setGestureAllowance(ScaleProcessor.class, true);
                   
                    ta.setEnableCaret(false);
                   
                    //Add to clusteranylyzer for clustering the tarea
                    if (getLassoProcessor() != null){
                      getLassoProcessor().addClusterable(ta);
                    }

//                    keyboard.setTextInputAcceptor(null);
                    removeTextInputListener(textInputListener);
                    textInputListener = null;
                   
                    ta.removeAllGestureEventListeners(DragProcessor.class);
                    ta.addGestureListener(DragProcessor.class, defaultDragAction);
//                    ta.unassignGestureClassAndAction(DragGestureAnalyzer.class);
//                    ta.assignGestureClassAndAction(DragGestureAnalyzer.class, defaultDragAction);

                    //The direction, in which the textarea will float off
                    Vector3D v = new Vector3D(0,-100, 0);

                    //Add the textarea to the set parent
                    if (getParentToAddNewTextAreaTo() != null){
                      //Transform the textarea so it appears at the same world coords after its added to another parent
                      Matrix m = MTComponent.getTransformToDestinationParentSpace(ta, getParentToAddNewTextAreaTo());
                      ta.transform(m);
                      //Transform the direction vector for the translation animation
                      //to preserve the direction from the old reference frame to the new parents one
//                      v.transformNormal(m);
                      v.transformDirectionVector(m);

                      ta.tweenTranslate(v, 500, 0.3f, 0.7f);

                      getParentToAddNewTextAreaTo().addChild(ta);
                    }else{
                      //If that isnt set, try to add it to the keyboards parent
                      if (getParent() != null){
                        /////////////////////////
                        // Transform the textarea so it appears at the same place after its added to another parent
                        Matrix m = MTComponent.getTransformToDestinationParentSpace(ta, getParent());
                        ta.transform(m);
                        //Transform the direction vector to preserve the global direction
                        //from the old reference frame to the new parents one
                        //The translation part has to be removed from the matrix because we're transforming
                        //a translation vector not a point vector
                        v.transformDirectionVector(m);

                        ta.tweenTranslate(v, 500, 0.3f, 0.7f);
                        /////////////////////
                        getParent().addChild(ta);
                      }else{
                        //do nothing..?
                        throw new RuntimeException("Dont know where to add text area to!");
View Full Code Here

* Creates a new textarea at the keyboard.
* Fails if there is still one attached to it.
*/
  public void createNewTextArea(){
    if (this.textInputListener == null){
      final MTTextArea t = new MTTextArea(pa, fontForTextField);
      this.textInputListener = t;
     
      t.setExpandDirection(ExpandDirection.UP);
      t.setStrokeColor(new MTColor(0,0 , 0, 255));
      t.setFillColor(new MTColor(205,200,177, 255));
     
      t.setGestureAllowance(DragProcessor.class, true);
      t.setGestureAllowance(RotateProcessor.class, false);
      t.setGestureAllowance(ScaleProcessor.class, false);
     
      t.removeAllGestureEventListeners(DragProcessor.class);
      t.addGestureListener(DragProcessor.class, dragFromKeybAction);
     
      t.setEnableCaret(true);
      t.snapToKeyboard(this);
     
      this.addTextInputListener(this.textInputListener);
      //Remove textarea from listening if destroyed
      t.addStateChangeListener(StateChange.COMPONENT_DESTROYED, new StateChangeListener() {
        public void stateChanged(StateChangeEvent evt) {
          removeTextInputListener(t);
        }
      });
    }else{
View Full Code Here

      if (g.getId() == MTGestureEvent.GESTURE_ENDED){
        if (g instanceof DragEvent){
          DragEvent dragEvent = (DragEvent)g;
         
          if (dragEvent.getTargetComponent() instanceof MTTextArea){
            MTTextArea text = (MTTextArea)dragEvent.getTargetComponent();

            //Add default gesture actions to textfield
//            text.assignGestureClassAndAction(DragGestureAnalyzer.class, defaultDragAction);
//            text.assignGestureClassAndAction(ScaleGestureAnalyzer.class, defaultScaleAction);
//            text.assignGestureClassAndAction(RotateGestureAnalyzer.class, defaultRotateAction);
           
            text.setGestureAllowance(DragProcessor.class, true);
            text.setGestureAllowance(RotateProcessor.class, true);
            text.setGestureAllowance(ScaleProcessor.class, true);
           
            //Disable caret showing
            text.setEnableCaret(false);
           
            //Add to clusteranylyzer for clustering the tarea
            if (getLassoProcessor() != null){
              getLassoProcessor().addClusterable(text);
            }
           
            removeTextInputListener(textInputListener);
            textInputListener = null;
           
            text.removeAllGestureEventListeners(DragProcessor.class);
            text.addGestureListener(DragProcessor.class, defaultDragAction);
           
//            text.unassignGestureClassAndAction(DragGestureAnalyzer.class);
//            text.assignGestureClassAndAction(DragGestureAnalyzer.class, defaultDragAction);
           
//            /*
            //Add the textare to the set parent
            if (getParentToAddNewTextAreaTo() != null){
              text.transform(MTComponent.getTransformToDestinationParentSpace(text, getParentToAddNewTextAreaTo()));
              getParentToAddNewTextAreaTo().addChild(text);
            }else{
              //If that isnt set, try to add it to the keyboards parent
              if (getParent() != null){
                text.transform(MTComponent.getTransformToDestinationParentSpace(text, getParent()));
                getParent().addChild(text);
              }else{
                //do nothing..
//                throw new RuntimeException("Dont know where to add text area to!");
                System.err.println("Dont know where to add text area to!");
View Full Code Here

TOP

Related Classes of org.mt4j.components.visibleComponents.widgets.MTTextArea

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.