Example #1
0
  public void doStitch() {
    Stitcher.Holder[] aholder =
        (Stitcher.Holder[])
            this.setStitchHolders.toArray(new Stitcher.Holder[this.setStitchHolders.size()]);
    Arrays.sort(aholder);
    Stitcher.Holder[] aholder1 = aholder;
    int i = aholder.length;

    for (int j = 0; j < i; ++j) {
      Stitcher.Holder holder = aholder1[j];

      if (!this.allocateSlot(holder)) {
        String s =
            String.format(
                "Unable to fit: %s - size: %dx%d - Maybe try a lowerresolution texturepack?",
                new Object[] {
                  holder.getAtlasSprite().getIconName(),
                  Integer.valueOf(holder.getAtlasSprite().getIconWidth()),
                  Integer.valueOf(holder.getAtlasSprite().getIconHeight())
                });
        throw new StitcherException(holder, s);
      }
    }

    if (this.forcePowerOf2) {
      this.currentWidth = MathHelper.roundUpToPowerOfTwo(this.currentWidth);
      this.currentHeight = MathHelper.roundUpToPowerOfTwo(this.currentHeight);
    }
  }
Example #2
0
  /** Expand stitched texture in order to make space for specified tile */
  private boolean expandAndAllocateSlot(Stitcher.Holder par1StitchHolder) {
    int i = Math.min(par1StitchHolder.getWidth(), par1StitchHolder.getHeight());
    boolean flag = this.currentWidth == 0 && this.currentHeight == 0;
    boolean flag1;
    int j;

    if (this.forcePowerOf2) {
      j = MathHelper.roundUpToPowerOfTwo(this.currentWidth);
      int k = MathHelper.roundUpToPowerOfTwo(this.currentHeight);
      int l = MathHelper.roundUpToPowerOfTwo(this.currentWidth + i);
      int i1 = MathHelper.roundUpToPowerOfTwo(this.currentHeight + i);
      boolean flag2 = l <= this.maxWidth;
      boolean flag3 = i1 <= this.maxHeight;

      if (!flag2 && !flag3) {
        return false;
      }

      boolean flag4 = j != l;
      boolean flag5 = k != i1;

      if (flag4 ^ flag5) {
        flag1 =
            flag5
                && flag3; // Forge: Bug fix: Attempt to fill all downward space before expanding
                          // width
      } else {
        flag1 = flag2 && j <= k;
      }
    } else {
      boolean flag6 = this.currentWidth + i <= this.maxWidth;
      boolean flag7 = this.currentHeight + i <= this.maxHeight;

      if (!flag6 && !flag7) {
        return false;
      }

      flag1 = flag6 && (flag || this.currentWidth <= this.currentHeight);
    }

    j = Math.max(par1StitchHolder.getWidth(), par1StitchHolder.getHeight());

    if (MathHelper.roundUpToPowerOfTwo((flag1 ? this.currentHeight : this.currentWidth) + j)
        > (flag1 ? this.maxHeight : this.maxWidth)) {
      return false;
    } else {
      Stitcher.Slot slot;

      if (flag1) {
        if (par1StitchHolder.getWidth() > par1StitchHolder.getHeight()) {
          par1StitchHolder.rotate();
        }

        if (this.currentHeight == 0) {
          this.currentHeight = par1StitchHolder.getHeight();
        }

        slot =
            new Stitcher.Slot(
                this.currentWidth, 0, par1StitchHolder.getWidth(), this.currentHeight);
        this.currentWidth += par1StitchHolder.getWidth();
      } else {
        slot =
            new Stitcher.Slot(
                0, this.currentHeight, this.currentWidth, par1StitchHolder.getHeight());
        this.currentHeight += par1StitchHolder.getHeight();
      }

      slot.addSlot(par1StitchHolder);
      this.stitchSlots.add(slot);
      return true;
    }
  }