예제 #1
0
  private void renderTreeHelper(XML xml, int[] widths, int depth, int[] ltor) {
    float x = (g.width / widths[depth]) * (0.5f + ltor[depth]++);
    float y = (g.height / widths.length) * (0.5f + depth);
    xml.setFloat("x", x);
    xml.setFloat("y", y);
    if (xml.getParent() != null)
      g.line(
          xml.getParent().getFloat("x"),
          xml.getParent().getFloat("y") + RECT_HEIGHT / 2,
          x,
          y - RECT_HEIGHT / 2);
    if (xml.hasAttribute("altColor")) {
      String hexColor = xml.getString("altColor");
      g.fill(
          getColorComponent(hexColor, 0),
          getColorComponent(hexColor, 1),
          getColorComponent(hexColor, 2));
    }
    g.rect(x, y, RECT_WIDTH, RECT_HEIGHT, 4);
    g.fill(0);
    if (xml.hasAttribute("altName"))
      g.text(xml.getString("altName"), x, y, RECT_WIDTH, RECT_HEIGHT);
    else g.text(xml.getName(), x, y, RECT_WIDTH, RECT_HEIGHT);
    g.fill(255);

    XML[] children = xml.getChildren();
    for (int i = 0; i < children.length; i++)
      renderTreeHelper(children[i], widths, depth + 1, ltor);
  }
예제 #2
0
 private int getWidthsHelper(XML xml, int[] widths, int depth, int maxWidth) {
   widths[depth]++;
   if (widths[depth] > maxWidth) maxWidth = widths[depth];
   XML[] children = xml.getChildren();
   for (int i = 0; i < children.length; i++) {
     maxWidth = getWidthsHelper(children[i], widths, depth + 1, maxWidth);
   }
   return maxWidth;
 }
예제 #3
0
 private int getDepth(XML xml) {
   int maxDepth = 0;
   XML[] children = xml.getChildren();
   for (int i = 0; i < children.length; i++) {
     int depth = getDepth(children[i]);
     if (depth > maxDepth) maxDepth = depth;
   }
   return maxDepth + 1;
 }