Package ru.snake.spritepacker.core.packer

Examples of ru.snake.spritepacker.core.packer.PackerOutput


  public ListModel getAnimationsModel() {
    return animations;
  }

  public PackerOutput createTextureAtlas() {
    PackerOutput output = new PackerOutput();

    if (atlasPerAnim) {
      List<Animation> allAnimations = animations.getList();
      int animationIndex = START_ANIMATION_INDEX;

      for (Animation eachAnimation : allAnimations) {
        Set<Texture> allTextures = new HashSet<Texture>();

        for (Sprite eachSprite : eachAnimation.getSprites()) {
          allTextures.add(eachSprite.texture);
        }

        ImagePacker packer = new ImagePacker(margin, padding);

        for (Texture eachTexture : allTextures) {
          ImageData data = new ImageData(animationIndex, eachTexture);

          packer.addItem(data);
        }

        output.setNameFormat(eachAnimation.name + "-", null);

        packer.setOutput(output);
        packer.process(maxWidth, maxHeight, true);

        animationIndex++;
      }
    } else {
      Set<Texture> allTextures = new HashSet<Texture>();

      for (Animation eachAnimation : animations.getList()) {
        for (Sprite eachSprite : eachAnimation.getSprites()) {
          allTextures.add(eachSprite.texture);
        }
      }

      ImagePacker packer = new ImagePacker(margin, padding);

      for (Texture eachTexture : allTextures) {
        ImageData data = new ImageData(eachTexture);

        packer.addItem(data);
      }

      output.setNameFormat("atlas-", null);

      packer.setOutput(output);
      packer.process(maxWidth, maxHeight, true);
    }
View Full Code Here


    setIcon(ICON_NAME, false);
  }

  @Override
  public void actionPerformed(ActionEvent e) {
    PackerOutput output = factory.createTextureAtlas();

    if (output.atlasSizes.isEmpty()) {
      Dialogs.warning(parent,
          Messages.getString("ViewAtlasAction.ZERO_ATLASES")); //$NON-NLS-1$

      return;
    }

    if (output.packedImages.isEmpty()) {
      Dialogs.warning(parent,
          Messages.getString("ViewAtlasAction.ZERO_IMAGES")); //$NON-NLS-1$

      return;
    }

    JTabbedPane atlasTabs = new JTabbedPane(JTabbedPane.TOP);

    for (Entry<Integer, Dimension> atlasEntry : output.atlasSizes
        .entrySet()) {
      Collection<ImageData> textures = new LinkedList<ImageData>();
      int index = atlasEntry.getKey();

      for (ImageData eachData : output.packedImages) {
        if (eachData.atlas == index) {
          textures.add(eachData);
        }
      }

      Dimension size = atlasEntry.getValue();
      String sizeStr = String.format(
          Messages.getString("ViewAtlasAction.ATLAS_SIZE_FORMAT"), //$NON-NLS-1$
          size.width, size.height);

      LayoutManager atlasLayout = new BorderLayout(4, 4);
      JPanel atlasPane = new JPanel(atlasLayout);
      TextureAtlas atlas = new TextureAtlas(size.width, size.height,
          textures);
      JLabel sizeLabel = new JLabel(sizeStr);

      atlasPane.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));

      atlasPane.add(atlas, BorderLayout.CENTER);
      atlasPane.add(sizeLabel, BorderLayout.PAGE_END);

      atlasTabs
          .add(String.valueOf(output.getAtlasName(index)), atlasPane);
    }

    JOptionPane.showMessageDialog(parent, atlasTabs,
        Messages.getString("ViewAtlasAction.TITLE"), //$NON-NLS-1$
        JOptionPane.PLAIN_MESSAGE);
View Full Code Here

      factory.setPreference(DESCRIPTION_FOOTER, descriptionFooter);

      factory.setPreference(DESCRIPTION_JOIN,
          String.valueOf(descriptionJoin));

      PackerOutput output = factory.createTextureAtlas();

      if (!isOutputValud(output)) {
        return;
      }
View Full Code Here

TOP

Related Classes of ru.snake.spritepacker.core.packer.PackerOutput

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.