Package ch.sahits.game.graphic.image.model

Examples of ch.sahits.game.graphic.image.model.ImageData


  }

  @Override
  public BufferedImage init(DisplayImageDIResolver resolver) {
    BufferedImage tmpImg = xmlLoader.getImage(SCENE_IMAGE_NAME); // portScene
    ImageData imgData = xmlLoader.getImageData(SCENE_IMAGE_NAME);
    ImageScaleState state = new ImageScaleState(new Dimension(tmpImg.getWidth(), tmpImg.getHeight()), getBounds().getSize(), imgData.getCrop(), imgData.getMaxCrop());
logger.debug("State of the port scene before: "+state);   
    BufferedImage img = imageUtils.cropAndScale(tmpImg, state);
    scaleMap.put(SCENE_IMAGE_NAME, state.getScaleFactor());
    Rectangle bounds = imageUtils.computeBounds(getBounds().getSize(),new Dimension(img.getWidth(),img.getHeight()));
    initPolygons(resolver, imgData, state, new Point(getBounds().x+bounds.x, getBounds().y+bounds.y));
View Full Code Here


   * Setting the positions of the polygons on the screen
   */
  protected void initPolygons(DisplayImageDIResolver resolver,
      ImageData imgData, ImageScaleState state, Point offset) {
    IPolygonScaling scaler = resolver.getPolygonCalculator();
    ImageData recalculated = scaler.recalculatePolygons(imgData, state);
    recalculated = scaler.recalculatePolygonsOffsett(recalculated, offset);
    for (Entry<Integer, NamedPolygon> item : recalculated.getPolygons().entrySet()) {
      NamedPolygon poly = item.getValue();
      int zIndex = item.getKey();
      logger.debug("Add polygon: "+poly);
      this.polygons.put(zIndex, poly); // maybe we should use meanX instead
    }   
View Full Code Here

  }

  @Override
  public BufferedImage init(DisplayImageDIResolver resolver) {
    BufferedImage tmpImg = xmlLoader.getImage(SCENE_IMAGE_NAME); // portScene
    ImageData imgData = xmlLoader.getImageData(SCENE_IMAGE_NAME);
    ImageScaleState state = new ImageScaleState(new Dimension(tmpImg.getWidth(), tmpImg.getHeight()), getBounds().getSize(), imgData.getCrop(), imgData.getMaxCrop());
logger.debug("State of the market place scene before: "+state);   
    BufferedImage img = imageUtils.cropAndScale(tmpImg, state);
    scaleMap.put(SCENE_IMAGE_NAME, state.getScaleFactor());
    Rectangle bounds = imageUtils.computeBounds(getBounds().getSize(),new Dimension(img.getWidth(),img.getHeight()));
    initPolygons(resolver, imgData, state, new Point(getBounds().x+bounds.x, getBounds().y+bounds.y));
View Full Code Here

 
  private final Logger logger = Logger.getLogger(PolygonScaling.class);

  @Override
  public ImageData recalculatePolygons(ImageData imgData,ImageScaleState state) {
    ImageData result=null;
    // order is important: we do not want to scale translocated polygons
    if (state.isScaled()){
      result = recalculatePolygonScale(imgData, state);
    }
    if (state.isBordered() && result==null){
View Full Code Here

  @Override
  public ImageData recalculatePolygonsOffsett(ImageData imgData, Point offset) {
    if (offset.x==0 && offset.y==0){
      return createNewCopy(imgData);
    }
    ImageData result = createNewCopy(imgData);
    for (NamedPolygon poly : result.getPolygons().values()) {
      updateCoordinates(poly, offset.x, offset.y);
    }
    return result;
  }
View Full Code Here

    }
    if (state.getBordered()==0 || state.getBorderDirection()==null){
      throw new IllegalStateException("Border amount and direction must be specified");
    }
    final int amount = state.getBordered();
    ImageData result = createNewCopy(imgData);
    if (state.getBorderDirection()==EScaleDirection.HORIZONTAL){ // change x coordinate
      logger.trace("Borders on the side: update X coordinate by "+amount);
      for (NamedPolygon poly : result.getPolygons().values()) {
        updateXCoordinate(poly, amount);
      }       
    } else { // change y coordinate
      logger.trace("Borders at the top and bottom: update Y coordinate by "+amount);
      for (NamedPolygon poly : result.getPolygons().values()) {
        updateYCoordinate(poly, amount);
      }       
    }
    return result;
  }
View Full Code Here

      return createNewCopy(imgData);
    }
    if (state.getCropped()==0 || state.getCrop()==ECrop.NONE){
      throw new IllegalStateException("Crop amount and crop side must be specified");
    }
    ImageData result = createNewCopy(imgData);
    final int amount = state.getCropped();
    if (state.getCrop()==ECrop.BOTTOM || state.getCrop()==ECrop.RIGHT){
      logger.trace("Image has was cropped at the bottom or the right side: no change");
      return result;
    } else if (state.getCrop()==ECrop.LEFT){ // change x coordinate
      logger.trace("Crop on the left side: update X coordinate by "+amount);
      for (NamedPolygon poly : result.getPolygons().values()) {
        updateXCoordinate(poly, (int)Math.rint(-amount*state.getScaleFactor()));
      }       
    } else { // change y coordinate
      logger.trace("Crop at the top: update Y coordinate by "+amount);
      for (NamedPolygon poly : result.getPolygons().values()) {
        updateYCoordinate(poly, (int)Math.rint(-amount*state.getScaleFactor()));
      }       
    }
    return result;
  }
View Full Code Here

      return createNewCopy(imgData);
    }
    if (state.getScaleFactor()==1 ){
      throw new IllegalStateException("Scale factor must be specified");
    }
    ImageData result = createNewCopy(imgData);
    final double scaleFactor = state.getScaleFactor();
    logger.trace("Scale by factor "+scaleFactor);
    for (NamedPolygon poly : result.getPolygons().values()) {
      updateCoordinate(poly, scaleFactor);
    }       
    return result;
  }
View Full Code Here

          crop = ECrop.NONE;
          maxCrop=0;
        }
        String type = image.getAttributeValue("type");
        Element polygons = image.getChild("polygons");
        ImageData imgData = new ImageData(name, crop, maxCrop);
        if (polygons!=null){ // it might be an image definition without any polygons defined
          List<Element> polygonList = polygons.getChildren("polygon");
          for (Element polygon : polygonList) {
            String name2 = polygon.getAttributeValue("name");
            NamedPolygon poly = new NamedPolygon(name2);
            int zIndex = 1;
            if (polygon.getAttribute("z-index")!=null){
              zIndex = Integer.parseInt(polygon.getAttributeValue("z-index"));
            }
            List<Element> points = polygon.getChildren("point");
            for (Element point : points) {
              int x = Integer.parseInt(point.getAttributeValue("x"));
              int y = Integer.parseInt(point.getAttributeValue("y"));
              poly.addPoint(x, y);
            }
            imgData.addPolygon(poly,zIndex);
          } // end <polygon>
        } // end extracting all <polygons>
        // Load the image
        parseImageDefinitionAndLoad(type, imgData);
      } // end extracting <image>
View Full Code Here

TOP

Related Classes of ch.sahits.game.graphic.image.model.ImageData

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.