Package Hexel.rendering

Examples of Hexel.rendering.GLChunk$Rect


        || usedNode.y >= freeNode.y + freeNode.height || usedNode.y + usedNode.height <= freeNode.y) return false;

      if (usedNode.x < freeNode.x + freeNode.width && usedNode.x + usedNode.width > freeNode.x) {
        // New node at the top side of the used node.
        if (usedNode.y > freeNode.y && usedNode.y < freeNode.y + freeNode.height) {
          Rect newNode = new Rect(freeNode);
          newNode.height = usedNode.y - newNode.y;
          freeRectangles.add(newNode);
        }

        // New node at the bottom side of the used node.
        if (usedNode.y + usedNode.height < freeNode.y + freeNode.height) {
          Rect newNode = new Rect(freeNode);
          newNode.y = usedNode.y + usedNode.height;
          newNode.height = freeNode.y + freeNode.height - (usedNode.y + usedNode.height);
          freeRectangles.add(newNode);
        }
      }

      if (usedNode.y < freeNode.y + freeNode.height && usedNode.y + usedNode.height > freeNode.y) {
        // New node at the left side of the used node.
        if (usedNode.x > freeNode.x && usedNode.x < freeNode.x + freeNode.width) {
          Rect newNode = new Rect(freeNode);
          newNode.width = usedNode.x - newNode.x;
          freeRectangles.add(newNode);
        }

        // New node at the right side of the used node.
        if (usedNode.x + usedNode.width < freeNode.x + freeNode.width) {
          Rect newNode = new Rect(freeNode);
          newNode.x = usedNode.x + usedNode.width;
          newNode.width = freeNode.x + freeNode.width - (usedNode.x + usedNode.width);
          freeRectangles.add(newNode);
        }
      }
View Full Code Here


    if (pages == null) {
      Random random = new Random(1243);
      Array<Rect> inputRects = new Array();
      for (int i = 0; i < 240; i++) {
        Rect rect = new Rect();
        rect.name = "rect" + i;
        rect.height = 16 + random.nextInt(120);
        rect.width = 16 + random.nextInt(240);
        inputRects.add(rect);
      }
      for (int i = 0; i < 10; i++) {
        Rect rect = new Rect();
        rect.name = "rect" + (40 + i);
        rect.height = 400 + random.nextInt(340);
        rect.width = 1 + random.nextInt(10);
        inputRects.add(rect);
      }

      long s = System.nanoTime();

      pages = new MaxRectsPacker(settings).pack(inputRects);

      long e = System.nanoTime();
      System.out.println("fast: " + settings.fast);
      System.out.println((e - s) / 1e6f + " ms");
      System.out.println();
    }

    int x = 20, y = 20;
    for (Page page : pages) {
      renderer.setColor(Color.GRAY);
      renderer.begin(ShapeType.Filled);
      for (int i = 0; i < page.outputRects.size; i++) {
        Rect rect = page.outputRects.get(i);
        renderer.rect(x + rect.x + settings.paddingX, y + rect.y + settings.paddingY, rect.width - settings.paddingX,
          rect.height - settings.paddingY);
      }
      renderer.end();
      renderer.setColor(Color.RED);
      renderer.begin(ShapeType.Line);
      for (int i = 0; i < page.outputRects.size; i++) {
        Rect rect = page.outputRects.get(i);
        renderer.rect(x + rect.x + settings.paddingX, y + rect.y + settings.paddingY, rect.width - settings.paddingX,
          rect.height - settings.paddingY);
      }
      renderer.setColor(Color.GREEN);
      renderer.rect(x, y, page.width + settings.paddingX * 2, page.height + settings.paddingY * 2);
 
View Full Code Here

    // Strip extension.
    int dotIndex = name.lastIndexOf('.');
    if (dotIndex != -1) name = name.substring(0, dotIndex);

    Rect rect = addImage(image, name);
    if (rect != null && settings.limitMemory) rect.unloadImage(file);
  }
View Full Code Here

    if (rect != null && settings.limitMemory) rect.unloadImage(file);
  }

  /** The image will be kept in-memory during packing. */
  public Rect addImage (BufferedImage image, String name) {
    Rect rect = processImage(image, name);

    if (rect == null) {
      System.out.println("Ignoring blank input image: " + name);
      return null;
    }

    if (settings.alias) {
      String crc = hash(rect.getImage(this));
      Rect existing = crcs.get(crc);
      if (existing != null) {
        System.out.println(rect.name + " (alias of " + existing.name + ")");
        existing.aliases.add(new Alias(rect));
        return null;
      }
View Full Code Here

      BufferedImage newImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_4BYTE_ABGR);
      newImage.getGraphics().drawImage(image, 0, 0, null);
      image = newImage;
    }

    Rect rect = null;
    if (name.endsWith(".9")) {
      // Strip ".9" from file name, read ninepatch split pixels, and strip ninepatch split pixels.
      name = name.substring(0, name.length() - 2);
      int[] splits = getSplits(image, name);
      int[] pads = getPads(image, name, splits);
      // Strip split pixels.
      BufferedImage newImage = new BufferedImage(image.getWidth() - 2, image.getHeight() - 2, BufferedImage.TYPE_4BYTE_ABGR);
      newImage.getGraphics().drawImage(image, 0, 0, newImage.getWidth(), newImage.getHeight(), 1, 1, image.getWidth() - 1,
        image.getHeight() - 1, null);
      image = newImage;
      // Ninepatches aren't rotated or whitespace stripped.
      rect = new Rect(image, 0, 0, image.getWidth(), image.getHeight(), true);
      rect.splits = splits;
      rect.pads = pads;
      rect.canRotate = false;
    } else {
      rect = stripWhitespace(image);
View Full Code Here

  /** Strips whitespace and returns the rect, or null if the image should be ignored. */
  private Rect stripWhitespace (BufferedImage source) {
    WritableRaster alphaRaster = source.getAlphaRaster();
    if (alphaRaster == null || (!settings.stripWhitespaceX && !settings.stripWhitespaceY))
      return new Rect(source, 0, 0, source.getWidth(), source.getHeight(), false);
    final byte[] a = new byte[1];
    int top = 0;
    int bottom = source.getHeight();
    if (settings.stripWhitespaceX) {
      outer:
      for (int y = 0; y < source.getHeight(); y++) {
        for (int x = 0; x < source.getWidth(); x++) {
          alphaRaster.getDataElements(x, y, a);
          int alpha = a[0];
          if (alpha < 0) alpha += 256;
          if (alpha > settings.alphaThreshold) break outer;
        }
        top++;
      }
      outer:
      for (int y = source.getHeight(); --y >= top;) {
        for (int x = 0; x < source.getWidth(); x++) {
          alphaRaster.getDataElements(x, y, a);
          int alpha = a[0];
          if (alpha < 0) alpha += 256;
          if (alpha > settings.alphaThreshold) break outer;
        }
        bottom--;
      }
    }
    int left = 0;
    int right = source.getWidth();
    if (settings.stripWhitespaceY) {
      outer:
      for (int x = 0; x < source.getWidth(); x++) {
        for (int y = top; y < bottom; y++) {
          alphaRaster.getDataElements(x, y, a);
          int alpha = a[0];
          if (alpha < 0) alpha += 256;
          if (alpha > settings.alphaThreshold) break outer;
        }
        left++;
      }
      outer:
      for (int x = source.getWidth(); --x >= left;) {
        for (int y = top; y < bottom; y++) {
          alphaRaster.getDataElements(x, y, a);
          int alpha = a[0];
          if (alpha < 0) alpha += 256;
          if (alpha > settings.alphaThreshold) break outer;
        }
        right--;
      }
    }
    int newWidth = right - left;
    int newHeight = bottom - top;
    if (newWidth <= 0 || newHeight <= 0) {
      if (settings.ignoreBlankImages)
        return null;
      else
        return new Rect(emptyImage, 0, 0, 1, 1, false);
    }
    return new Rect(source, left, top, newWidth, newHeight, false);
  }
View Full Code Here

      throw new RuntimeException("Page min height cannot be higher than max height.");
  }

  public Array<Page> pack (Array<Rect> inputRects) {
    for (int i = 0, nn = inputRects.size; i < nn; i++) {
      Rect rect = inputRects.get(i);
      rect.width += settings.paddingX;
      rect.height += settings.paddingY;
    }

    if (settings.fast) {
View Full Code Here

    }
    // Find min size.
    int minWidth = Integer.MAX_VALUE;
    int minHeight = Integer.MAX_VALUE;
    for (int i = 0, nn = inputRects.size; i < nn; i++) {
      Rect rect = inputRects.get(i);
      minWidth = Math.min(minWidth, rect.width);
      minHeight = Math.min(minHeight, rect.height);
      if (settings.rotation) {
        if ((rect.width > settings.maxWidth || rect.height > settings.maxHeight)
          && (rect.width > settings.maxHeight || rect.height > settings.maxWidth)) {
View Full Code Here

      if (!settings.fast) {
        result = maxRects.pack(inputRects, methods[i]);
      } else {
        Array<Rect> remaining = new Array();
        for (int ii = 0, nn = inputRects.size; ii < nn; ii++) {
          Rect rect = inputRects.get(ii);
          if (maxRects.insert(rect, methods[i]) == null) {
            while (ii < nn)
              remaining.add(inputRects.get(ii++));
          }
        }
View Full Code Here

   * @return the rectangle information of the specified window.
   *
   */
  public static Rectangle getWindowRect(int hwnd)
  {
    RECT rect = new RECT();
    Extension.GetWindowRect(hwnd, rect);
    return new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom
        - rect.top);
  }
View Full Code Here

TOP

Related Classes of Hexel.rendering.GLChunk$Rect

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.