Package net.sf.fysix.leveleditor.tool.level.subtool.draw

Examples of net.sf.fysix.leveleditor.tool.level.subtool.draw.ShapeMapObject


            }
          }
        }

        if (smo == null) {
          smo = new ShapeMapObject(ds);
          smo.setPosition(pos);
          refEditor.addMapObject(smo);
        }
        if(e.getClickCount() > 1){ // READY! DOUBLE CLICK
          smo = null;
        } else {
          smo.addVertex(pos);
          if(ds.isEnableAutocomplete() && smo.getNumberOfVertices()>=ds.getNrOfAutocompleteVertices()){
            smo = null;
          }
        }
      } else if(e.getButton() == MouseEvent.BUTTON3){ // CANCEL - UNDO/DEL LATEST VERTEX
        if(smo != null && smo.getNumberOfVertices()>0){
          smo.delVertex();
          if(smo.getNumberOfVertices()==0){
            refEditor.delMapObject(smo);
            smo = null;
          }
        }
      }
      break;

    case MODE_DRAW_COPY:
    case MODE_DRAW_MOVE:
      if(cs.isAttachToGrid()){
        List<IMapObject> mapobjs = refEditor.getIMapObjects();
        for (IMapObject mo : Collections.unmodifiableCollection(mapobjs)){
          if(mo instanceof GridMapObject){
            PresentationSettings ps = ((GridMapObject)mo).getPresentationSettings();
            int x = (pos.getX()/ps.getGridWidth())*ps.getGridWidth();
            if(pos.getX()%ps.getGridWidth()>(ps.getGridWidth()/2)){
              x += ps.getGridWidth();
            }
            int y = (pos.getY()/ps.getGridHeight())*ps.getGridHeight();
            if(pos.getY()%ps.getGridHeight()>(ps.getGridHeight()/2)){
              y += ps.getGridHeight();
            }
            WorldPos gridAttachPos = new WorldPos(x,y);
            pos = gridAttachPos; // Replace with adjusted pos!
          }
        }
      }

      List<IMapObject> mapobjs = refEditor.getIMapObjects();
      //WorldPos UL = new WorldPos(1000,1000); // TODO: Use MAX SCREEN COORDS
      //WorldPos LR = new WorldPos(0,0); // MIN SCREEN COORDS
      int refX = 10000;// TODO: Use MAX SCREEN COORDS
      int refY = 10000;// TODO: Use MAX SCREEN COORDS

      // Get outer bounding for ALL SELECTED shapes
      for (IMapObject mo : Collections.unmodifiableCollection(mapobjs)){
        if(mo instanceof ShapeMapObject){
          ShapeMapObject refSMO = (ShapeMapObject)mo;
          if(refSMO.isSelected()){
            if(refSMO.getUpperLeft().getX()<refX){
              refX = refSMO.getUpperLeft().getX();
            }
            if(refSMO.getUpperLeft().getY()<refY){
              refY = refSMO.getUpperLeft().getY();
            }
          }
        }
      }
      WorldPos diff = new WorldPos(refX, refY);

      if(currentMode == MODE_DRAW_COPY){
        List<ShapeMapObject> copyLst = new ArrayList<ShapeMapObject>();
        if(dragInitiated==true){
          diff.setPosition(0, 0);
          pos.setPosition(0, 0);
        }
        for (IMapObject mo : Collections.unmodifiableCollection(mapobjs)){
          if(mo instanceof ShapeMapObject){
            ShapeMapObject refSMO = (ShapeMapObject)mo;
            if(refSMO.isSelected()){
              ShapeMapObject copySMO = refSMO.copy();
              copySMO.moveShape(diff, pos);
              //refSMO.setPosition();   
              copyLst.add(copySMO);
              if(dragInitiated==true){
                copySMO.setSelected(true);
                refSMO.setSelected(false);
              }
            }
          }
        }
        dragInitiated=false;

        for(ShapeMapObject smoCopy : Collections.unmodifiableCollection(copyLst)){
          refEditor.addMapObject(smoCopy);
        }
      } else {
        for (IMapObject mo : Collections.unmodifiableCollection(mapobjs)){
          if(mo instanceof ShapeMapObject){
            ShapeMapObject refSMO = (ShapeMapObject)mo;
            if(refSMO.isSelected()){
              refSMO.moveShape(diff, pos);
              //refSMO.setPosition();
            }
          }
          if(mo instanceof SelectMapObject){
            SelectMapObject refSMO = (SelectMapObject)mo;
            if(refSMO.getAnchorPos() != null){
              refSMO.getAnchorPos().setX(refSMO.getAnchorPos().getX()-diff.getX()+pos.getX());
              refSMO.getAnchorPos().setY(refSMO.getAnchorPos().getY()-diff.getY()+pos.getY());
            }
          }
        }
      }
      dragButton = MouseEvent.NOBUTTON;

      // Reset state
      if(oldMode != MODE_DRAW_NO && oldMode != currentMode && e != null){
        currentMode = oldMode;
      }
      break;
     
    case MODE_SEL_AREA:
    case MODE_SEL_SINGLE:
      //List<IMapObject> mapobjs;
      WorldPos anchorPos = null;

      mapobjs = refEditor.getIMapObjects();

      // RIGHT CLICK => REMOVE ALL SELECTION!
      if(e.getButton() == MouseEvent.BUTTON3){
        for (IMapObject mo : Collections.unmodifiableCollection(mapobjs)){
          if(mo instanceof ShapeMapObject){
            ShapeMapObject refSMO = (ShapeMapObject)mo;
            refSMO.setSelected(false);
          }
        }
        if(selMO != null){
          refEditor.delMapObject(selMO);
          selMO = null;
        }
      }

      if(currentMode == MODE_SEL_SINGLE){
        mapobjs = refEditor.getIMapObjects();

        for (IMapObject mo : Collections.unmodifiableCollection(mapobjs)){
          if(mo instanceof ShapeMapObject){
            ShapeMapObject refSMO = (ShapeMapObject)mo;
            if(refSMO.isPointInShape(pos)){
              refSMO.setSelected(!refSMO.isSelected());
            }
            if(refSMO.isSelected()){
              if(anchorPos == null){
                anchorPos = new WorldPos(10000,10000);
              }
              if(anchorPos.getX()>refSMO.getUpperLeft().getX()){
                anchorPos.setX(refSMO.getUpperLeft().getX());
              }
              if(anchorPos.getY()>refSMO.getUpperLeft().getY()){
                anchorPos.setY(refSMO.getUpperLeft().getY());
              }
            }
          }
        }
        if(anchorPos == null){
          if(selMO != null){
            refEditor.delMapObject(selMO);
            selMO = null;
          }
        } else {
          if(selMO == null){
            selMO = new SelectMapObject();
            refEditor.addMapObject(selMO);
          }
          selMO.setStartPos(pos);
          selMO.setEndPos(pos);
          selMO.setAnchorPos(anchorPos);
        }
      } else {
        if(dragButton == MouseEvent.BUTTON1){
          mapobjs = refEditor.getIMapObjects();
          for (IMapObject mo : Collections.unmodifiableCollection(mapobjs)){
            if(mo instanceof ShapeMapObject){
              ShapeMapObject refSMO = (ShapeMapObject)mo;
              if( (refSMO.getUpperLeft().getX()>=selMO.getUpperLeft().getX() &&
                  refSMO.getUpperLeft().getX()<=pos.getX() &&
                  refSMO.getUpperLeft().getY()>=selMO.getUpperLeft().getY() &&
                  refSMO.getUpperLeft().getY()<=pos.getY() )
                  ||
                  (refSMO.getLowerRight().getX()>=selMO.getUpperLeft().getX() &&
                      refSMO.getLowerRight().getX()<=pos.getX() &&
                      refSMO.getLowerRight().getY()>=selMO.getUpperLeft().getY() &&
                      refSMO.getLowerRight().getY()<=pos.getY() ) )
              {
                refSMO.setSelected(!refSMO.isSelected());
              }
              if(refSMO.isSelected()){
                if(anchorPos == null){
                  anchorPos = new WorldPos(10000,10000);
                }
                if(anchorPos.getX()>refSMO.getUpperLeft().getX()){
                  anchorPos.setX(refSMO.getUpperLeft().getX());
                }
                if(anchorPos.getY()>refSMO.getUpperLeft().getY()){
                  anchorPos.setY(refSMO.getUpperLeft().getY());
                }
              }
            }
          }
          if(anchorPos == null){
View Full Code Here


    for (IMapObject mo : Collections.unmodifiableCollection(mapobjs)){
      if(mo instanceof ShapeMapObject){
//        if(((ShapeMapObject)mo).isSelected()){
//          int choose = JOptionPane.showConfirmDialog(null, "Do u want to save selected shapes?", "Confirm", JOptionPane.INFORMATION_MESSAGE);
//          if(choose == JOptionPane.OK_OPTION){
            ShapeMapObject ptrSMO = (ShapeMapObject)mo;
            int x[] = new int[ptrSMO.getNumberOfVertices()];
            int y[] = new int[ptrSMO.getNumberOfVertices()];
            WorldPos[] wps = ptrSMO.getVertices();
            for(int i=0;wps != null && i<wps.length;i++){
              x[i] = wps[i].getX(); // TODO: Remove world coordinates?!?
              y[i] = wps[i].getY(); // TODO: Remove world coordinates?!?
            }
            sh.setShapeByName(ptrSMO.getShapeId(), x, y);
//          }
//        }
      }
      //FileDialog fd = new FileDialog(new Frame(), "Save selected shapes");
      //sh.saveShapes(new File(fd.getFile()));
View Full Code Here

  {
    ShapeHandler sh = new ShapeHandler();
    sh.loadShapes(new File("config\\level.xml"));
    List<ShapeData> shapes = sh.getShapes();
    for (ShapeData sd : Collections.unmodifiableCollection(shapes)){
      ShapeMapObject smo = new ShapeMapObject(new DrawSettings()); // TODO: Attach draw settings to GENEREAL (DrawTool)
      for(int i=0;i<sd.x.length;i++){
        WorldPos vertex = new WorldPos(sd.x[i], sd.y[i]);
        smo.addVertex(vertex);
        smo.setShapeId(sd.name);
      }
      refEditor.addMapObject(smo);
   
  }
View Full Code Here

        }
      }
      for (IMapObject mo : Collections.unmodifiableCollection(mapobjs)){
        if(mo instanceof ShapeMapObject){
          if(((ShapeMapObject)mo).isSelected()){
            ShapeMapObject ptrSMO = (ShapeMapObject)mo;
            WorldPos[] wps = ptrSMO.getVertices();
            for(int i=0;wps != null && i<wps.length;i++){;
            int xdiff = wps[i].getX()-anchorPos.getX();
            int ydiff = wps[i].getY()-anchorPos.getY();
            wps[i].setX((int)(anchorPos.getX()+xdiff*Math.cos(Math.PI/4.0)+ydiff*Math.sin(Math.PI/4.0)));
            wps[i].setY((int)(anchorPos.getY()-xdiff*Math.sin(Math.PI/4.0)+ydiff*Math.cos(Math.PI/4.0)));
            }
            ptrSMO.recalcBoundingBox();
          }
        }
      }
    }

View Full Code Here

    for (IMapObject mo : Collections.unmodifiableCollection(mapobjs)){
      if(mo instanceof ShapeMapObject){
        //        if(((ShapeMapObject)mo).isSelected()){
        //          int choose = JOptionPane.showConfirmDialog(null, "Do u want to save selected shapes?", "Confirm", JOptionPane.INFORMATION_MESSAGE);
        //          if(choose == JOptionPane.OK_OPTION){
        ShapeMapObject ptrSMO = (ShapeMapObject)mo;
        int x[] = new int[ptrSMO.getNumberOfVertices()];
        int y[] = new int[ptrSMO.getNumberOfVertices()];
        WorldPos[] wps = ptrSMO.getVertices();
        for(int i=0;wps != null && i<wps.length;i++){
          x[i] = wps[i].getX(); // TODO: Remove world coordinates?!?
          y[i] = wps[i].getY(); // TODO: Remove world coordinates?!?
        }
        sh.setShapeByName(ptrSMO.getShapeId(), x, y);
        //          }
        //        }
      }
      //FileDialog fd = new FileDialog(new Frame(), "Save selected shapes");
      //sh.saveShapes(new File(fd.getFile()));
View Full Code Here

  {
    ShapeHandler sh = new ShapeHandler();
    sh.loadShapes(new File("config\\level.xml"));
    List<ShapeData> shapes = sh.getShapes();
    for (ShapeData sd : Collections.unmodifiableCollection(shapes)){
      ShapeMapObject smo = new ShapeMapObject(new DrawSettings()); // TODO: Attach draw settings to GENEREAL (DrawTool)
      for(int i=0;i<sd.x.length;i++){
        WorldPos vertex = new WorldPos(sd.x[i], sd.y[i]);
        smo.addVertex(vertex);
        smo.setShapeId(sd.name);
      }
      refEditor.addMapObject(smo);
   
  }
View Full Code Here

      int refY = 10000;// TODO: Use MAX SCREEN COORDS

      // Get outer bounding for ALL SELECTED shapes
      for (IMapObject mo : Collections.unmodifiableCollection(mapobjs)){
        if(mo instanceof ShapeMapObject){
          ShapeMapObject refSMO = (ShapeMapObject)mo;
          if(refSMO.isSelected()){
            if(refSMO.getUpperLeft().getX()<refX){
              refX = refSMO.getUpperLeft().getX();
            }
            if(refSMO.getUpperLeft().getY()<refY){
              refY = refSMO.getUpperLeft().getY();
            }
          }
        }
      }
      WorldPos diff = new WorldPos(refX, refY);
   
        switch (currentMode) {
          case MODE_COPY:
            List<ShapeMapObject> copyLst = new ArrayList<ShapeMapObject>();
          if(dragInitiated==true){
            diff.setPosition(0, 0);
            pos.setPosition(0, 0);
          }
            for (IMapObject mo : Collections.unmodifiableCollection(mapobjs)){
              if(mo instanceof ShapeMapObject){
                ShapeMapObject refSMO = (ShapeMapObject)mo;
                if(refSMO.isSelected()){
                  ShapeMapObject copySMO = refSMO.copy();
                  copySMO.moveShape(diff, pos);
                  //refSMO.setPosition();   
                  copyLst.add(copySMO);
                  if(dragInitiated==true){
                    copySMO.setSelected(true);
                    refSMO.setSelected(false);
                  }
                }
              }
            }
            dragInitiated=false;

            for(ShapeMapObject smoCopy : Collections.unmodifiableCollection(copyLst)){
              refEditor.addMapObject(smoCopy);
            }
              break;
          case MODE_MOVE:
        for (IMapObject mo : Collections.unmodifiableCollection(mapobjs)){
          if(mo instanceof ShapeMapObject){
            ShapeMapObject refSMO = (ShapeMapObject)mo;
            if(refSMO.isSelected()){
              refSMO.moveShape(diff, pos);
              //refSMO.setPosition();
            }
          }
          if(mo instanceof SelectMapObject){
            SelectMapObject refSMO = (SelectMapObject)mo;
            if(refSMO.getAnchorPos() != null){
              refSMO.getAnchorPos().setX(refSMO.getAnchorPos().getX()-diff.getX()+pos.getX());
              refSMO.getAnchorPos().setY(refSMO.getAnchorPos().getY()-diff.getY()+pos.getY());
            }
          }
        }
            break;
        }
View Full Code Here

            }
          }
          for (IMapObject mo : Collections.unmodifiableCollection(mapobjs)){
            if(mo instanceof ShapeMapObject){
              if(((ShapeMapObject)mo).isSelected()){
                ShapeMapObject ptrSMO = (ShapeMapObject)mo;
                WorldPos[] wps = ptrSMO.getVertices();
                for(int i=0;wps != null && i<wps.length;i++){;
                  int xdiff = wps[i].getX()-anchorPos.getX();
                  int ydiff = wps[i].getY()-anchorPos.getY();
                  wps[i].setX((int)(anchorPos.getX()+xdiff*Math.cos(Math.PI/4.0)+ydiff*Math.sin(Math.PI/4.0)));
                  wps[i].setY((int)(anchorPos.getY()-xdiff*Math.sin(Math.PI/4.0)+ydiff*Math.cos(Math.PI/4.0)));
                }
                ptrSMO.recalcBoundingBox();
              }
            }
          }
        } else if (source instanceof CustomToggleButton){
            //currentType = (PhysicalEntity)((CustomToggleButton)source).getUserObject();
View Full Code Here

      // RIGHT CLICK => REMOVE ALL SELECTION!
      if(e.getButton() == MouseEvent.BUTTON3){
        for (IMapObject mo : Collections.unmodifiableCollection(mapobjs)){
          if(mo instanceof ShapeMapObject){
            ShapeMapObject refSMO = (ShapeMapObject)mo;
            refSMO.setSelected(false);
          }
        }
        if(selMO != null){
          refEditor.delMapObject(selMO);
          selMO = null;
        }
      }
     
        switch (currentMode) {
        case MODE_SINGLE:
          mapobjs = refEditor.getIMapObjects();
         
      for (IMapObject mo : Collections.unmodifiableCollection(mapobjs)){
        if(mo instanceof ShapeMapObject){
          ShapeMapObject refSMO = (ShapeMapObject)mo;
          if(refSMO.isPointInShape(pos)){
            refSMO.setSelected(!refSMO.isSelected());
          }
          if(refSMO.isSelected()){
            if(anchorPos == null){
              anchorPos = new WorldPos(10000,10000);
            }
            if(anchorPos.getX()>refSMO.getUpperLeft().getX()){
              anchorPos.setX(refSMO.getUpperLeft().getX());
            }
            if(anchorPos.getY()>refSMO.getUpperLeft().getY()){
              anchorPos.setY(refSMO.getUpperLeft().getY());
            }
          }
        }
      }
      if(anchorPos == null){
        if(selMO != null){
          refEditor.delMapObject(selMO);
          selMO = null;
        }
      } else {
        if(selMO == null){
              selMO = new SelectMapObject();
              refEditor.addMapObject(selMO);
            }
            selMO.setStartPos(pos);
            selMO.setEndPos(pos);
        selMO.setAnchorPos(anchorPos);
      }
          break;
        case MODE_AREA:
          if(dragButton == MouseEvent.BUTTON1){           
            mapobjs = refEditor.getIMapObjects();
          for (IMapObject mo : Collections.unmodifiableCollection(mapobjs)){
            if(mo instanceof ShapeMapObject){
              ShapeMapObject refSMO = (ShapeMapObject)mo;
              if( (refSMO.getUpperLeft().getX()>=selMO.getUpperLeft().getX() &&
                   refSMO.getUpperLeft().getX()<=pos.getX() &&
                 refSMO.getUpperLeft().getY()>=selMO.getUpperLeft().getY() &&
                 refSMO.getUpperLeft().getY()<=pos.getY() )
                ||
                (refSMO.getLowerRight().getX()>=selMO.getUpperLeft().getX() &&
                   refSMO.getLowerRight().getX()<=pos.getX() &&
                   refSMO.getLowerRight().getY()>=selMO.getUpperLeft().getY() &&
                   refSMO.getLowerRight().getY()<=pos.getY() ) )
              {
                refSMO.setSelected(!refSMO.isSelected());
              }
              if(refSMO.isSelected()){
              if(anchorPos == null){
                anchorPos = new WorldPos(10000,10000);
              }
              if(anchorPos.getX()>refSMO.getUpperLeft().getX()){
                anchorPos.setX(refSMO.getUpperLeft().getX());
              }
              if(anchorPos.getY()>refSMO.getUpperLeft().getY()){
                anchorPos.setY(refSMO.getUpperLeft().getY());
              }
            }
            }
          }
          if(anchorPos == null){
View Full Code Here

TOP

Related Classes of net.sf.fysix.leveleditor.tool.level.subtool.draw.ShapeMapObject

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.