예제 #1
0
파일: BMFont.java 프로젝트: lwxcool/LGame
 public void close() {
   this.isClose = true;
   if (displayList != null) {
     displayList.close();
     displayList = null;
   }
   if (displays != null) {
     for (Display d : displays.values()) {
       if (d != null && d.cache != null) {
         d.cache.close();
         d.cache = null;
       }
     }
     displays.clear();
     displays = null;
   }
 }
예제 #2
0
파일: BMFont.java 프로젝트: lwxcool/LGame
  private void parse(String text) throws Exception {
    if (displays == null) {
      displays = new ObjectMap<String, Display>(DEFAULT_MAX_CHAR);
    } else {
      displays.clear();
    }
    StringTokenizer br = new StringTokenizer(text, LSystem.LS);
    info = br.nextToken();
    common = br.nextToken();
    page = br.nextToken();

    ObjectMap<Short, TArray<Short>> kerning = new ObjectMap<Short, TArray<Short>>(64);
    TArray<CharDef> charDefs = new TArray<CharDef>(DEFAULT_MAX_CHAR);

    int maxChar = 0;
    boolean done = false;
    for (; !done; ) {
      String line = br.nextToken();
      if (line == null) {
        done = true;
      } else {
        if (line.startsWith("chars c")) {
        } else if (line.startsWith("char")) {
          CharDef def = parseChar(line);
          if (def != null) {
            maxChar = MathUtils.max(maxChar, def.id);
            charDefs.add(def);
          }
        }
        if (line.startsWith("kernings c")) {
        } else if (line.startsWith("kerning")) {
          StringTokenizer tokens = new StringTokenizer(line, " =");
          tokens.nextToken();
          tokens.nextToken();
          short first = Short.parseShort(tokens.nextToken());
          tokens.nextToken();
          int second = Integer.parseInt(tokens.nextToken());
          tokens.nextToken();
          int offset = Integer.parseInt(tokens.nextToken());
          TArray<Short> values = kerning.get(new Short(first));
          if (values == null) {
            values = new TArray<Short>();
            kerning.put(new Short(first), values);
          }
          values.add(new Short((short) ((offset << 8) | second)));
        }
      }
    }

    this.chars = new CharDef[maxChar + 1];

    for (Iterator<CharDef> iter = charDefs.iterator(); iter.hasNext(); ) {
      CharDef def = iter.next();
      chars[def.id] = def;
    }

    for (Entries<Short, TArray<Short>> iter = kerning.entries(); iter.hasNext(); ) {
      Entry<Short, TArray<Short>> entry = iter.next();
      short first = entry.key;
      TArray<Short> valueList = entry.value;
      short[] valueArray = new short[valueList.size];
      int i = 0;
      for (Iterator<Short> valueIter = valueList.iterator(); valueIter.hasNext(); i++) {
        valueArray[i] = (valueIter.next()).shortValue();
      }
      chars[first].kerning = valueArray;
    }
  }
예제 #3
0
파일: BMFont.java 프로젝트: lwxcool/LGame
  private void drawBatchString(
      float tx, float ty, String text, LColor c, int startIndex, int endIndex) {

    if (isClose) {
      return;
    }

    if (displays.size > DEFAULT_MAX_CHAR) {
      displays.clear();
    }

    lazyHashCode = 1;

    if (c != null) {
      lazyHashCode = LSystem.unite(lazyHashCode, c.r);
      lazyHashCode = LSystem.unite(lazyHashCode, c.g);
      lazyHashCode = LSystem.unite(lazyHashCode, c.b);
      lazyHashCode = LSystem.unite(lazyHashCode, c.a);
    }

    String key = text + lazyHashCode;

    Display display = displays.get(key);

    if (display == null) {

      int x = 0, y = 0;

      displayList.glBegin();
      displayList.setBatchPos(tx, ty);

      if (c != null) {
        displayList.setImageColor(c);
      }

      CharDef lastCharDef = null;
      char[] data = text.toCharArray();
      for (int i = 0; i < data.length; i++) {
        int id = data[i];
        if (id == '\n') {
          x = 0;
          y += getLineHeight();
          continue;
        }
        if (id >= chars.length) {
          continue;
        }
        CharDef charDef = chars[id];
        if (charDef == null) {
          continue;
        }

        if (lastCharDef != null) {
          x += lastCharDef.getKerning(id);
        }
        lastCharDef = charDef;

        if ((i >= startIndex) && (i <= endIndex)) {
          charDef.draw(x, y);
        }

        x += charDef.advance;
      }

      if (c != null) {
        displayList.setImageColor(LColor.white);
      }

      displayList.glEnd();

      display = new Display();

      display.cache = displayList.newBatchCache();
      display.text = text;
      display.width = 0;
      display.height = 0;

      displays.put(key, display);

    } else if (display.cache != null) {
      display.cache.x = tx;
      display.cache.y = ty;
      displayList.postCache(display.cache);
    }
  }
예제 #4
0
 public TMXProperties clear() {
   properties.clear();
   return this;
 }