Package org.mt4j.input.inputProcessors

Examples of org.mt4j.input.inputProcessors.IGestureEventListener


      }
     
      //Remove the default drag listener from the cell for safety
      IGestureEventListener[] l = item.getGestureListeners();
        for (int j = 0; j < l.length; j++) {
        IGestureEventListener gestureEventListener = l[j];
        if (gestureEventListener.getClass().equals(DefaultDragAction.class)){
          item.removeGestureEventListener(DragProcessor.class, gestureEventListener);
        }
      }
       
      item.addGestureListener(DragProcessor.class, new ListCellDragListener(this));


//    outerShape = new MTRectangle(x,y, width, height, applet);
    outerShape = new MTRoundRectangle(x,y,0, width, height, knobWidth/2f + innerPadding, knobHeight/2f  + innerPadding, applet);
    outerShape.unregisterAllInputProcessors();
    //When we click on the outershape move the knob in that direction a certain step
    outerShape.registerInputProcessor(new TapProcessor(applet, 35));
    outerShape.addGestureListener(TapProcessor.class, new IGestureEventListener() {
      public boolean processGestureEvent(MTGestureEvent ge) {
        TapEvent te = (TapEvent)ge;
        switch (te.getTapID()) {
        case TapEvent.BUTTON_CLICKED:
          Vector3D screenPos = te.getLocationOnScreen();
          Vector3D intersection = outerShape.getIntersectionGlobal(Tools3D.getCameraPickRay(app, outerShape, screenPos.x, screenPos.y));
          if (intersection != null){
            //Get the intersection point into knob local relative space
            Vector3D localClickPos = knob.globalToLocal(intersection);
            Vector3D knobCenterLocal = knob.getCenterPointLocal();
            float range = getValueRange();
            float step = range/5f; //Arbitrary step value
            float oldValue = getValue();
            if (localClickPos.x < knobCenterLocal.x){
              setValue(oldValue - step); //Move knob Left
            }else if (localClickPos.x > knobCenterLocal.x){
              setValue(oldValue + step)//Move knob Right
            }
          }
          break;
        }
        return false;
      }
    });
   
//    knob = new MTRectangle(x+innerOffset, y+innerOffset,   knobWidth, knobHeight, applet);
    knob = new MTEllipse(applet,  new Vector3D(0,0,0), knobWidth*0.5f, knobHeight*0.5f);
    knob.setFillColor(new MTColor(140, 140, 140, 255));
    AbstractComponentProcessor[] inputPs = knob.getInputProcessors();
    for (int i = 0; i < inputPs.length; i++) {
      AbstractComponentProcessor p = inputPs[i];
      if (!(p instanceof DragProcessor)){
        knob.unregisterInputProcessor(p);
      }
    }
    knob.removeAllGestureEventListeners(DragProcessor.class);
   
    outerShape.addChild(knob);
    this.addChild(outerShape);
   
    //TODO these have to be updated if knob or outershape are changed
//    final float knobWidthRelParent = knob.getWidthXY(TransformSpace.RELATIVE_TO_PARENT);
//    final float knobHeightRelParent = knob.getHeightXY(TransformSpace.RELATIVE_TO_PARENT);
//    final float outerWidthLocal = outerShape.getWidthXY(TransformSpace.LOCAL);
   
    knob.addGestureListener(DragProcessor.class, new IGestureEventListener() {
      //@Override
      public boolean processGestureEvent(MTGestureEvent ge) {
        DragEvent de = (DragEvent)ge;
        Vector3D dir = new Vector3D(de.getTranslationVect());
        //Transform the global direction vector into knob local coordiante space

    tapOnly.setFillColor(textAreaColor);
    tapOnly.setStrokeColor(textAreaColor);
    tapOnly.setText("Tap me! ---");
    this.clearAllGestures(tapOnly);
    tapOnly.registerInputProcessor(new TapProcessor(app));
    tapOnly.addGestureListener(TapProcessor.class, new IGestureEventListener() {
      public boolean processGestureEvent(MTGestureEvent ge) {
        TapEvent te = (TapEvent)ge;
        switch (te.getId()) {
        case MTGestureEvent.GESTURE_DETECTED:
          tapOnly.setFillColor(new MTColor(220,220,220,255));
          break;
        case MTGestureEvent.GESTURE_UPDATED:
          break;
        case MTGestureEvent.GESTURE_ENDED:
          if (te.isTapped()){
            if (tapOnly.getText().endsWith("--"))
              tapOnly.setText("Tap me! -|-");
            else
              tapOnly.setText("Tap me! ---")
          }
          tapOnly.setFillColor(textAreaColor);
          break;
        }
        return false;
      }
    });
    this.getCanvas().addChild(tapOnly);
    tapOnly.setAnchor(PositionAnchor.UPPER_LEFT);
    tapOnly.setPositionGlobal(new Vector3D(1*horizontalPad,0,0));
   
    //Double Tap gesture
    final MTTextArea doubleTap = new MTTextArea(mtApplication, font);
    doubleTap.setFillColor(textAreaColor);
    doubleTap.setStrokeColor(textAreaColor);
    doubleTap.setText("Double Tap me! ---");
    this.clearAllGestures(doubleTap);
    doubleTap.registerInputProcessor(new TapProcessor(app, 25, true, 350));
    doubleTap.addGestureListener(TapProcessor.class, new IGestureEventListener() {
      public boolean processGestureEvent(MTGestureEvent ge) {
        TapEvent te = (TapEvent)ge;
        if (te.isDoubleTap()){
          if (doubleTap.getText().endsWith("--"))
            doubleTap.setText("Double Tap me! -|-");
          else
            doubleTap.setText("Double Tap me! ---")
        }
        return false;
      }
    });
    this.getCanvas().addChild(doubleTap);
    doubleTap.setAnchor(PositionAnchor.UPPER_LEFT);
    doubleTap.setPositionGlobal(new Vector3D(1*horizontalPad,1*verticalPad,0));
   
    //Tap and Hold gesture
    final MTTextArea tapAndHoldOnly = new MTTextArea(mtApplication, font);
    tapAndHoldOnly.setFillColor(textAreaColor);
    tapAndHoldOnly.setStrokeColor(textAreaColor);
    tapAndHoldOnly.setText("Tap&Hold me!  ---");
    this.clearAllGestures(tapAndHoldOnly);
    tapAndHoldOnly.registerInputProcessor(new TapAndHoldProcessor(app, 2000));
    tapAndHoldOnly.addGestureListener(TapAndHoldProcessor.class, new TapAndHoldVisualizer(app, getCanvas()));
    tapAndHoldOnly.addGestureListener(TapAndHoldProcessor.class, new IGestureEventListener() {
      public boolean processGestureEvent(MTGestureEvent ge) {
        TapAndHoldEvent th = (TapAndHoldEvent)ge;
        switch (th.getId()) {
        case TapAndHoldEvent.GESTURE_DETECTED:
          break;

    if (isDynamic){
      //DYNAMIC BODIES MAKE MOUSEJOINTS
      comp.removeAllGestureEventListeners(DragProcessor.class);

      comp.registerInputProcessor(new MultipleDragProcessor(comp.getRenderer()));
      comp.addGestureListener(MultipleDragProcessor.class, new IGestureEventListener() {

//        comp.addGestureListener(DragProcessor.class, new IGestureEventListener() {
        //@Override
        public boolean processGestureEvent(MTGestureEvent ge) {
          DragEvent de = (DragEvent)ge;
          try{
            MTComponent comp = (MTComponent)de.getTargetComponent();
            Body body = (Body)comp.getUserData("box2d");
            MouseJoint mouseJoint;
            Vector3D to = new Vector3D(de.getTo());
            //Un-scale position from mt4j to box2d
            PhysicsHelper.scaleDown(to, worldScale);
            //System.out.println("MouseJoint To: " + to);
            long cursorID =  de.getDragCursor().getId();

            switch (de.getId()) {
            case DragEvent.GESTURE_DETECTED:
              comp.sendToFront();
              body.wakeUp();
              mouseJoint = createDragJoint(theWorld, body, to.x, to.y);
              comp.setUserData("mouseJoint" + cursorID, mouseJoint);
              break;
            case DragEvent.GESTURE_UPDATED:
              mouseJoint = (MouseJoint) comp.getUserData("mouseJoint" + cursorID);
              if (mouseJoint != null){
                mouseJoint.setTarget(new Vec2(to.x, to.y));
              }
              break;
            case DragEvent.GESTURE_ENDED:
              mouseJoint = (MouseJoint) comp.getUserData("mouseJoint" + cursorID);
              if (mouseJoint != null){
                comp.setUserData("mouseJoint" + cursorID, null);
//                theWorld.destroyJoint(mouseJoint); 
                //Only destroy the joint if it isnt already (go through joint list and check)
                for (Joint joint = theWorld.getJointList(); joint != null; joint = joint.getNext()) {
                  JointType type = joint.getType();
                  switch (type) {
                  case MOUSE_JOINT:
                    MouseJoint mj = (MouseJoint)joint;
                    if (body.equals(mj.getBody1()) || body.equals(mj.getBody2())){
//                      theWorld.destroyJoint(mj);
                      if (mj.equals(mouseJoint)) {
                        theWorld.destroyJoint(mj);
                      }
                    }
                    break;
                  default:
                    break;
                  }
                }
              }
              mouseJoint = null;
              break;
            default:
              break;
            }
          }catch (Exception e) {
            System.err.println(e.getMessage());
          }
          return true;
        }
      });
    }else{
      comp.removeAllGestureEventListeners(DragProcessor.class);
     
      boolean hasDragProcessor = false;
      AbstractComponentProcessor[] p = comp.getInputProcessors();
      for (int i = 0; i < p.length; i++) {
        AbstractComponentProcessor abstractComponentProcessor = p[i];
        if (abstractComponentProcessor instanceof DragProcessor) {
          hasDragProcessor = true;
        }
      }
      if (!hasDragProcessor){
        comp.registerInputProcessor(new DragProcessor(comp.getRenderer()));
      }
     
      //For static bodies just alter the transform of the body
      comp.addGestureListener(DragProcessor.class, new IGestureEventListener() {
        //@Override
        public boolean processGestureEvent(MTGestureEvent ge) {
          DragEvent de = (DragEvent)ge;
          Vector3D dir = PhysicsHelper.scaleDown(new Vector3D(de.getTranslationVect()), worldScale);
          try{

   * @param gestureEvtSender the gesture evt sender
   */
  public void removeAllGestureEventListeners(Class<? extends IInputProcessor> gestureEvtSender) {
    IGestureEventListener[] l = this.getGestureListeners();
      for (int j = 0; j < l.length; j++) {
      IGestureEventListener gestureEventListener = l[j];
      this.removeGestureEventListener(gestureEvtSender, gestureEventListener);
    }
  }

        PImage colPick = pa.loadImage(imagesPath + "colorcircle.png");
//        final MTColorPicker colorWidget = new MTColorPicker(0, pa.height-colPick.height, colPick, pa);
        final MTColorPicker colorWidget = new MTColorPicker(0, 0, colPick, pa);
        colorWidget.translate(new Vector3D(0f, 135,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);
          }

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

      this.selectionRect.unregisterAllInputProcessors();
      this.addChild(selectionRect);
     
//      this.registerInputProcessor(new DragProcessor(app));
      this.removeAllGestureEventListeners(DragProcessor.class);
      this.addGestureListener(DragProcessor.class, new IGestureEventListener() {
      public boolean processGestureEvent(MTGestureEvent ge) {
        DragEvent de = (DragEvent)ge;
       
        Vector3D hitPointLocal = getIntersectionLocal(globalToLocal(Tools3D.getCameraPickRay(app, MTColorPicker.this, de.getDragCursor().getCurrentEvtPosX(), de.getDragCursor().getCurrentEvtPosY())));
        if (hitPointLocal != null){

    playSymbol = new PlaySymbol(app, this.movieClip.getCenterPointRelativeToParent(), movieClipWidth/2f, movieClipWidth/2f, 35);
    this.addChild(playSymbol);
   
   
    this.registerInputProcessor(new TapProcessor(app, 30));
    this.addGestureListener(TapProcessor.class, new IGestureEventListener() {
      public boolean processGestureEvent(MTGestureEvent ge) {
        TapEvent te = (TapEvent)ge;
        if (te.isTapped()){
          if (movieClip != null && movieClip.movie != null){
//            if (movieClip.getMovie().isPlaying()){

        slider = new MTSlider(lowerLeft.x + sliderXPadding, lowerLeft.y - sliderHeight - sliderYPadding, MTMovieClip.this.getWidthXY(TransformSpace.LOCAL) - sliderXPadding*2, sliderHeight, 0, 10, app);
        slider.getOuterShape().setFillColor(new MTColor(0, 0, 0, 80));
        slider.getOuterShape().setStrokeColor(new MTColor(0, 0, 0, 80));
        slider.getKnob().setFillColor(new MTColor(100, 100, 100, 80));
        slider.getOuterShape().setStrokeColor(new MTColor(100, 100, 100, 80));
        slider.getKnob().addGestureListener(DragProcessor.class, new IGestureEventListener() {
          public boolean processGestureEvent(MTGestureEvent ge) {
            DragEvent de = (DragEvent)ge;
            switch (de.getId()) {
            case MTGestureEvent.GESTURE_DETECTED:
              stopSliderAdvance = true;
              break;
            case MTGestureEvent.GESTURE_UPDATED:
              break;
            case MTGestureEvent.GESTURE_ENDED:
              if (movieClip != null && movieClip.getMovie() != null /*&& movieClip.getMovie().isPlaying()*/){
                float currValue = slider.getValue();
                movieClip.jump(currValue);
              }
              stopSliderAdvance = false;
              break;
            default:
              break;
            }
            return false;
          }
        });
        //Dont do every frame! Duration is only valid if playing..
        slider.setValueRange(0, m.duration());
       
        slider.getOuterShape().addGestureListener(TapProcessor.class, new IGestureEventListener() {
          public boolean processGestureEvent(MTGestureEvent ge) {
            TapEvent te = (TapEvent)ge;
            switch (te.getTapID()) {
            case TapEvent.BUTTON_DOWN:
              stopSliderAdvance = true;

TOP

Related Classes of org.mt4j.input.inputProcessors.IGestureEventListener

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.