Example #1
0
 @Override
 public int hashCode() {
   if (hash == 1) {
     hash = LSystem.unite(textFormat.font.name.hashCode(), hash);
     hash = LSystem.unite(textFormat.font.style.ordinal(), hash);
     hash = LSystem.unite((int) textFormat.font.size, hash);
   }
   return hash;
 }
Example #2
0
 public byte[] readBytes() {
   InputStream input = read();
   try {
     return LSystem.copyStreamToByteArray(input, estimateLength());
   } catch (IOException ex) {
     throw new RuntimeException("Error reading file: " + this, ex);
   } finally {
     LSystem.close(input);
   }
 }
Example #3
0
 public void write(InputStream input, boolean append) {
   OutputStream output = null;
   try {
     output = write(append);
     LSystem.copyStream(input, output, 4096);
   } catch (Exception ex) {
     throw new RuntimeException("Error stream writing to file: " + file + " (" + type + ")", ex);
   } finally {
     LSystem.close(input);
     LSystem.close(output);
   }
 }
Example #4
0
 public int stringHeight(String message) {
   if (LSystem.base() == null) {
     return 0;
   }
   initLayout(message);
   return textLayout.bounds.height;
 }
Example #5
0
 public int charHeight(char ch) {
   if (LSystem.base() == null) {
     return 0;
   }
   initLayout(String.valueOf(ch));
   return textLayout.bounds.height;
 }
Example #6
0
 public int stringWidth(String message) {
   if (LSystem.base() == null) {
     return 0;
   }
   initLayout(message);
   return textLayout.stringWidth(message);
 }
Example #7
0
 public int charWidth(char ch) {
   if (LSystem.base() == null) {
     return 0;
   }
   initLayout(String.valueOf(ch));
   return textLayout.bounds.width;
 }
Example #8
0
 public Reader reader(String charset) {
   InputStream stream = read();
   try {
     return new InputStreamReader(stream, charset);
   } catch (UnsupportedEncodingException ex) {
     LSystem.close(stream);
     throw new RuntimeException("Error reading file: " + this, ex);
   }
 }
Example #9
0
 public void writeBytes(byte[] bytes, int offset, int length, boolean append) {
   OutputStream output = write(append);
   try {
     output.write(bytes, offset, length);
   } catch (IOException ex) {
     throw new RuntimeException("Error writing file: " + file + " (" + type + ")", ex);
   } finally {
     LSystem.close(output);
   }
 }
Example #10
0
 public void writeString(String string, boolean append, String charset) {
   Writer writer = null;
   try {
     writer = writer(append, charset);
     writer.write(string);
   } catch (Exception ex) {
     throw new RuntimeException("Error writing file: " + file + " (" + type + ")", ex);
   } finally {
     LSystem.close(writer);
   }
 }
Example #11
0
 public long length() {
   if (type == FileType.Classpath || (type == FileType.Internal && !file.exists())) {
     InputStream input = read();
     try {
       return input.available();
     } catch (Exception ignored) {
     } finally {
       LSystem.close(input);
     }
     return 0;
   }
   return file().length();
 }
Example #12
0
 /**
  * 创建默认的选择器背景图片
  *
  * @param w
  * @param h
  * @return
  */
 private synchronized LTexture createDefaultDialog(int w, int h) {
   if (lazyDialog == null) {
     lazyDialog = new HashMap<String, LTexture>();
   }
   int hash = 1;
   hash = LSystem.unite(hash, w);
   hash = LSystem.unite(hash, h);
   String key = String.valueOf(hash);
   LTexture o = lazyDialog.get(key);
   if (o == null) {
     Image tmp = Image.createImage(w, h);
     Canvas g = tmp.getCanvas();
     LGradation.getInstance(LColor.white, LColor.black, w, h).drawHeight(g, 0, 0);
     g.setColor(LColor.black);
     g.strokeRect(0, 0, w - 1, h - 1);
     o = tmp.texture();
     if (tmp != null) {
       tmp.close();
       tmp = null;
     }
     lazyDialog.put(key, o);
   }
   return o;
 }
Example #13
0
 public int readBytes(byte[] bytes, int offset, int size) {
   InputStream input = read();
   int position = 0;
   try {
     while (true) {
       int count = input.read(bytes, offset + position, size - position);
       if (count <= 0) break;
       position += count;
     }
   } catch (IOException ex) {
     throw new RuntimeException("Error reading file: " + this, ex);
   } finally {
     LSystem.close(input);
   }
   return position - offset;
 }
Example #14
0
 public static String getResourcePath(String name) throws IOException {
   if (self == null) {
     return name;
   }
   if (LSystem.base().type() == LGame.Type.ANDROID) {
     if (name.toLowerCase().startsWith("assets/")) {
       name = StringUtils.replaceIgnoreCase(name, "assets/", "");
     }
     if (name.startsWith("/") || name.startsWith("\\")) {
       name = name.substring(1, name.length());
     }
   }
   File file = new File(self.getFilesDir(), name);
   if (!file.exists()) {
     retrieveFromAssets(self, name);
   }
   return file.getAbsolutePath();
 }
Example #15
0
 public String readString(String charset) {
   StringBuilder output = new StringBuilder(estimateLength());
   InputStreamReader reader = null;
   try {
     if (charset == null) reader = new InputStreamReader(read());
     else reader = new InputStreamReader(read(), charset);
     char[] buffer = new char[256];
     while (true) {
       int length = reader.read(buffer);
       if (length == -1) break;
       output.append(buffer, 0, length);
     }
   } catch (IOException ex) {
     throw new RuntimeException("Error reading layout file: " + this, ex);
   } finally {
     LSystem.close(reader);
   }
   return output.toString();
 }
Example #16
0
  @Override
  public void init(Stage o, Stage n) {
    super.init(o, n);
    n.players.setDepth(_close ? 1 : -1);
    _toflip = _close ? n : o;
    _batch = new RotationYBatch(LSystem.base().graphics().gl, 0f, 0.5f, 1.5f);
    _toflip.players.setBatch(_batch);
    final float fwidth = _toflip.width(), fheight = _toflip.height();
    _shadow =
        new Player() {
          @Override
          protected void paintImpl(GLEx g) {
            g.setAlpha(_alpha).setFillColor(0xFF000000).fillRect(0, 0, fwidth / 4, fheight);
          }

          @Override
          public void update(long elapsedTime) {}
        };
    _toflip.players.addAt(_shadow, fwidth, 0);
    updateAngle(0);
  }
Example #17
0
  protected void updateViewSize(final boolean landscape, int width, int height, LMode mode) {

    RectBox d = getScreenDimension();

    this.maxWidth = (int) d.getWidth();
    this.maxHeight = (int) d.getHeight();

    if (landscape && (d.getWidth() > d.getHeight())) {
      maxWidth = (int) d.getWidth();
      maxHeight = (int) d.getHeight();
    } else if (landscape && (d.getWidth() < d.getHeight())) {
      maxHeight = (int) d.getWidth();
      maxWidth = (int) d.getHeight();
    } else if (!landscape && (d.getWidth() < d.getHeight())) {
      maxWidth = (int) d.getWidth();
      maxHeight = (int) d.getHeight();
    } else if (!landscape && (d.getWidth() > d.getHeight())) {
      maxHeight = (int) d.getWidth();
      maxWidth = (int) d.getHeight();
    }

    if (mode != LMode.Max) {
      if (landscape) {
        this.zoomWidth = width;
        this.zoomHeight = height;
      } else {
        this.zoomWidth = height;
        this.zoomHeight = width;
      }
    } else {
      if (landscape) {
        this.zoomWidth = maxWidth >= width ? width : maxWidth;
        this.zoomHeight = maxHeight >= height ? height : maxHeight;
      } else {
        this.zoomWidth = maxWidth >= height ? height : maxWidth;
        this.zoomHeight = maxHeight >= width ? width : maxHeight;
      }
    }

    if (mode == LMode.Fill) {

      LSystem.setScaleWidth(((float) maxWidth) / zoomWidth);
      LSystem.setScaleHeight(((float) maxHeight) / zoomHeight);

    } else if (mode == LMode.FitFill) {

      RectBox res = AndroidGraphicsUtils.fitLimitSize(zoomWidth, zoomHeight, maxWidth, maxHeight);
      maxWidth = res.width;
      maxHeight = res.height;
      LSystem.setScaleWidth(((float) maxWidth) / zoomWidth);
      LSystem.setScaleHeight(((float) maxHeight) / zoomHeight);

    } else if (mode == LMode.Ratio) {

      maxWidth = View.MeasureSpec.getSize(maxWidth);
      maxHeight = View.MeasureSpec.getSize(maxHeight);

      float userAspect = (float) zoomWidth / (float) zoomHeight;
      float realAspect = (float) maxWidth / (float) maxHeight;

      if (realAspect < userAspect) {
        maxHeight = Math.round(maxWidth / userAspect);
      } else {
        maxWidth = Math.round(maxHeight * userAspect);
      }

      LSystem.setScaleWidth(((float) maxWidth) / zoomWidth);
      LSystem.setScaleHeight(((float) maxHeight) / zoomHeight);

    } else if (mode == LMode.MaxRatio) {

      maxWidth = View.MeasureSpec.getSize(maxWidth);
      maxHeight = View.MeasureSpec.getSize(maxHeight);

      float userAspect = (float) zoomWidth / (float) zoomHeight;
      float realAspect = (float) maxWidth / (float) maxHeight;

      if ((realAspect < 1 && userAspect > 1) || (realAspect > 1 && userAspect < 1)) {
        userAspect = (float) zoomHeight / (float) zoomWidth;
      }

      if (realAspect < userAspect) {
        maxHeight = Math.round(maxWidth / userAspect);
      } else {
        maxWidth = Math.round(maxHeight * userAspect);
      }

      LSystem.setScaleWidth(((float) maxWidth) / zoomWidth);
      LSystem.setScaleHeight(((float) maxHeight) / zoomHeight);

    } else {

      LSystem.setScaleWidth(1f);
      LSystem.setScaleHeight(1f);
    }

    LSystem.setScaleWidth(((float) maxWidth) / zoomWidth);
    LSystem.setScaleHeight(((float) maxHeight) / zoomHeight);
    LSystem.viewSize.setSize(zoomWidth, zoomHeight);

    StringBuffer sbr = new StringBuffer();
    sbr.append("Mode:").append(mode);
    sbr.append("\nWidth:").append(zoomWidth).append(",Height:" + zoomHeight);
    sbr.append("\nMaxWidth:").append(maxWidth).append(",MaxHeight:" + maxHeight);
    Log.d("Android2DSize", sbr.toString());
  }
Example #18
0
 public File file() {
   if (type == FileType.External) {
     return new File(LSystem.files().getExternalStoragePath(), file.getPath());
   }
   return file;
 }
Example #19
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);
    }
  }
Example #20
0
 public TextLayout getLayoutText(String text) {
   return LSystem.base().graphics().layoutText(text, this.textFormat);
 }
Example #21
0
 private void initLayout(String text) {
   if (textLayout == null || !text.equals(lastText)) {
     textLayout = LSystem.base().graphics().layoutText(tmp, this.textFormat);
   }
 }