Beispiel #1
0
 public Vector2f getOrigin(String text) {
   Vector2f result = fontSizes.get(text);
   if (result == null) {
     result = new Vector2f(stringWidth(text) / 2f, getHeight() / 2f);
     fontSizes.put(text, result);
   }
   return result;
 }
Beispiel #2
0
  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);
    }
  }
Beispiel #3
0
 @SuppressWarnings("unchecked")
 public <T> T get(String key) {
   return (T) properties.get(key);
 }