Package org.mt4j.input.inputProcessors.componentProcessors.dragProcessor

Examples of org.mt4j.input.inputProcessors.componentProcessors.dragProcessor.DragEvent


  }
 
 
  private class DragListener implements IGestureEventListener{
    public boolean processGestureEvent(MTGestureEvent ge) {
      DragEvent de = (DragEvent)ge;
      Vector3D to = de.getTo();
      switch (de.getId()) {
      case DragEvent.GESTURE_DETECTED:{
        currentGestureID = (currentGestureID+1) % nGestures;
        //System.out.println("New current gesture ID => " + currentGestureID);
        TailGesture G = gestureArray[currentGestureID];
        idToGesture.put(de.getDragCursor().getId(), G);
        G.clear();
        G.clearPolys();
        G.addPoint(to.x, to.y);
      }break;
      case DragEvent.GESTURE_UPDATED:{
        TailGesture G = idToGesture.get(de.getDragCursor().getId());
        if (G.distToLast(to.x, to.y) > minMove) {
          G.addPoint(to.x, to.y);
          G.smooth();
          G.compile();
        }
      }break;
      case DragEvent.GESTURE_ENDED:{
        idToGesture.remove(de.getDragCursor().getId());
      }break;
      default:
        break;
      }
      return true;
View Full Code Here


   * @author C.Ruff
   */
  private class MapDrag implements IGestureEventListener{
    public boolean processGestureEvent(MTGestureEvent g) {
      if (g instanceof DragEvent){
        DragEvent dragEvent = (DragEvent)g;
        Vector3D tVect = dragEvent.getTranslationVect();
        map.move(tVect.x, tVect.y);
        /*
        transVect.setXYZ(tVect.x, tVect.y, 0);
        fotoTagContainer.translate(transVect);
        */
 
View Full Code Here

      this.theListCellContainer = cont;
      this.canDrag = false;
    }
   
    public boolean processGestureEvent(MTGestureEvent ge) {
      DragEvent de = (DragEvent)ge;
     
      //If all cells fit into the list without scrolling dont do it.
      if (theListCellContainer.getHeightXY(TransformSpace.RELATIVE_TO_PARENT) <= getHeightXY(TransformSpace.LOCAL)){
        if (canDrag && theListCellContainer.isDragging()){
          theListCellContainer.setDragging(false);
          canDrag = false;
        }
        return false;
      }
     
      // Restrict dragging to only 1 listcell at a time
      if (!theListCellContainer.isDragging()){
//        System.out.println("Dragging list with cursor: " + de.getDragCursor().getId());
        theListCellContainer.setDragging(true);
        canDrag = true;
      }
     
      Vector3D dir = de.getTranslationVect();
      //Transform the global direction vector into listCellContainer local coordiante space
      dir.transformDirectionVector(theListCellContainer.getGlobalInverseMatrix());
     
      switch (de.getId()) {
      case MTGestureEvent.GESTURE_DETECTED:
      case MTGestureEvent.GESTURE_UPDATED:
        //Constrain the movement of the listcellcontainer to the boundaries of the List
        if (canDrag){
//          if (dir.y > 0){
            theListCellContainer.translate(new Vector3D(0, dir.y), TransformSpace.LOCAL)
           
            Vector3D listUpperLeftLocal = getListUpperLeftLocal();
            if (getContainerUpperLeftRelParent().y > listUpperLeftLocal.y){
              theListCellContainer.setAnchor(PositionAnchor.UPPER_LEFT);
              theListCellContainer.setPositionRelativeToParent(listUpperLeftLocal);
            }
//          }else if(dir.y < 0){
//            theListCellContainer.translate(new Vector3D(0, dir.y), TransformSpace.LOCAL);
           
            Vector3D listLowLeftLocal = getListLowerLeftLocal();
            if (getContainerLowerLeftRelParent().y < listLowLeftLocal.y){
              theListCellContainer.setAnchor(PositionAnchor.LOWER_LEFT);
              theListCellContainer.setPositionRelativeToParent(listLowLeftLocal);
            }
//          }
        }
        break;
      case MTGestureEvent.GESTURE_ENDED:
        if (canDrag){
          theListCellContainer.setDragging(false);
         
          Vector3D vel = de.getDragCursor().getVelocityVector(140);
          vel.scaleLocal(0.8f);
          vel = vel.getLimited(15);
          IMTController oldController = theListCellContainer.getController();
          theListCellContainer.setController(new InertiaListController(theListCellContainer, vel, oldController));
        }
View Full Code Here

//    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
        dir.transformDirectionVector(knob.getGlobalInverseMatrix());
       
        float oldValue = getValue();
       
View Full Code Here

  /* (non-Javadoc)
   * @see com.jMT.input.gestureAction.IGestureAction#processGesture(com.jMT.input.inputAnalyzers.GestureEvent)
   */
  public boolean processGestureEvent(MTGestureEvent g) {
    if (g instanceof DragEvent){
      DragEvent dragEvent = (DragEvent)g;
     
      if (!useCustomTarget)
        dragTarget = dragEvent.getTargetComponent();
     
      switch (dragEvent.getId()) {
      case MTGestureEvent.GESTURE_DETECTED:
        //Put target on top -> draw on top of others
        if (dragTarget instanceof MTComponent){
          MTComponent baseComp = (MTComponent)dragTarget;
         
          baseComp.sendToFront();
         
          /*
          //End all animations of the target
          Animation[] animations = AnimationManager.getInstance().getAnimationsForTarget(dragTarget);
          for (int i = 0; i < animations.length; i++) {
            Animation animation = animations[i];
            animation.stop();
          }
          */
        }
        dragTarget.translateGlobal(dragEvent.getTranslationVect());
        break;
      case MTGestureEvent.GESTURE_UPDATED:
        dragTarget.translateGlobal(dragEvent.getTranslationVect());
        break;
      case MTGestureEvent.GESTURE_ENDED:
        break;
      default:
        break;
View Full Code Here

  public boolean processGestureEvent(MTGestureEvent ge) {
    IMTComponent3D t = ge.getTargetComponent();
    if (t instanceof MTComponent) {
      MTComponent comp = (MTComponent) t;
      DragEvent de = (DragEvent)ge;
      IMTController oldController;
      switch (de.getId()) {
      case DragEvent.GESTURE_DETECTED:
        break;
      case DragEvent.GESTURE_UPDATED:
        break;
      case DragEvent.GESTURE_ENDED:
        Vector3D vel = de.getDragCursor().getVelocityVector(integrationTime);
        vel.scaleLocal(0.9f); //Test - integrate over longer time but scale down velocity vec
        vel = vel.getLimited(limit);
        oldController = comp.getController();
        comp.setController(new InertiaController(comp, vel, oldController));
        break;
View Full Code Here

        throw new RuntimeException("GameFieldHalfDragListener has to be given a physics object!");
      }
    }
   
    public boolean processGestureEvent(MTGestureEvent ge) {
      DragEvent de = (DragEvent)ge;
      try{
        Body body = (Body)comp.getUserData("box2d");
        MouseJoint mouseJoint;
        Vector3D to = new Vector3D(de.getTo());
        //Un-scale position from mt4j to box2d
        PhysicsHelper.scaleDown(to, scale);
        switch (de.getId()) {
        case DragEvent.GESTURE_DETECTED:
          comp.sendToFront();
          body.wakeUp();
          body.setXForm(new Vec2(to.x,  to.y), body.getAngle());
          mouseJoint = PhysicsHelper.createDragJoint(world, body, to.x, to.y);
          comp.setUserData(comp.getID(), mouseJoint);
          break;
        case DragEvent.GESTURE_UPDATED:
          mouseJoint = (MouseJoint) comp.getUserData(comp.getID());
          if (mouseJoint != null){
            boolean onCorrectGameSide = ((MTComponent)de.getTargetComponent()).containsPointGlobal(de.getTo());
            //System.out.println(((MTComponent)de.getTargetComponent()).getName()  + " Contains  " + to + " -> " + contains);
            if (onCorrectGameSide){
              mouseJoint.setTarget(new Vec2(to.x, to.y))
            }
          }
View Full Code Here

      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{
            MTComponent comp = (MTComponent)de.getTargetComponent();
            Body body = (Body)comp.getUserData("box2d");
            body.setXForm(
                new Vec2(body.getPosition().x + dir.x, body.getPosition().y + dir.y),
                body.getAngle());
            switch (de.getId()) {
            case DragEvent.GESTURE_DETECTED:
              comp.sendToFront();
              body.wakeUp();
              break;
            case DragEvent.GESTURE_UPDATED:
View Full Code Here

      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);
              unhighlightButton(closeButton, buttonOpacity);
              break;
            case MTGestureEvent.GESTURE_UPDATED:
              //Mouse over effect
              if (closeButton.containsPointGlobal(de.getTo())){
                highlightButton(closeButton);
              }else{
                unhighlightButton(closeButton, buttonOpacity);
              }
              break;
            case MTGestureEvent.GESTURE_ENDED:
              unhighlightButton(closeButton, buttonOpacity);
             
              InputCursor cursor = de.getDragCursor();
              Vector3D closeButtonIntersection = closeButton.getIntersectionGlobal(Tools3D.getCameraPickRay(getRenderer(), closeButton, cursor.getCurrentEvtPosX(), cursor.getCurrentEvtPosY()));
              if (closeButtonIntersection != null){
                if (app.popScene()){
                  destroy(); //Destroy this
                  scene.destroy(); //Destroy the scene
View Full Code Here

     
      super.processGestureEvent(g);
     
      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);
View Full Code Here

TOP

Related Classes of org.mt4j.input.inputProcessors.componentProcessors.dragProcessor.DragEvent

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.