Exemple #1
0
  /**
   * Starts accessing the native graphics in the underlying OS, when accessing the native graphics
   * Codename One shouldn't be used! The native graphics is unclipped and untranslated by default
   * and its the responsibility of the caller to clip/translate appropriately.
   *
   * <p>When finished with the native graphics it is essential to <b>invoke
   * endNativeGraphicsAccess</b>
   *
   * @return an instance of the underlying native graphics object
   */
  public Object beginNativeGraphicsAccess() {
    if (nativeGraphicsState != null) {
      throw new IllegalStateException("beginNativeGraphicsAccess invoked twice in a row");
    }
    Boolean a = Boolean.FALSE, b = Boolean.FALSE;
    if (isAntiAliasedText()) {
      b = Boolean.TRUE;
    }
    if (isAntiAliased()) {
      a = Boolean.TRUE;
    }

    nativeGraphicsState =
        new Object[] {
          new Integer(getTranslateX()),
          new Integer(getTranslateY()),
          new Integer(getColor()),
          new Integer(getAlpha()),
          new Integer(getClipX()),
          new Integer(getClipY()),
          new Integer(getClipWidth()),
          new Integer(getClipHeight()),
          a,
          b
        };
    translate(-getTranslateX(), -getTranslateY());
    setAlpha(255);
    setClip(
        0, 0, Display.getInstance().getDisplayWidth(), Display.getInstance().getDisplayHeight());
    return nativeGraphics;
  }
Exemple #2
0
 /** Invoke this to restore Codename One's graphics settings into the native graphics */
 public void endNativeGraphicsAccess() {
   translate(
       ((Integer) nativeGraphicsState[0]).intValue(),
       ((Integer) nativeGraphicsState[1]).intValue());
   setColor(((Integer) nativeGraphicsState[2]).intValue());
   setAlpha(((Integer) nativeGraphicsState[3]).intValue());
   setClip(
       ((Integer) nativeGraphicsState[4]).intValue(),
       ((Integer) nativeGraphicsState[5]).intValue(),
       ((Integer) nativeGraphicsState[6]).intValue(),
       ((Integer) nativeGraphicsState[7]).intValue());
   setAntiAliased(((Boolean) nativeGraphicsState[8]).booleanValue());
   setAntiAliasedText(((Boolean) nativeGraphicsState[9]).booleanValue());
   nativeGraphicsState = null;
 }