Ejemplo n.º 1
0
  @Override
  public void getRgb(
      int startX, int startY, int width, int height, int[] rgbArray, int offset, int scanSize) {
    Asserts.checkState(isReady(), "Cannot getRgb() a non-ready image");

    if (canvas == null) {
      canvas = img.getOwnerDocument().createCanvasElement();
      canvas.setHeight(img.getHeight());
      canvas.setWidth(img.getWidth());
      canvas.getContext2d().drawImage(img, 0, 0);
      // img.getOwnerDocument().getBody().appendChild(canvas);
    }

    Context2d ctx = canvas.getContext2d();
    ImageData imageData = ctx.getImageData(startX, startY, width, height);
    CanvasPixelArray pixelData = imageData.getData();
    int i = 0;
    int dst = offset;
    for (int y = 0; y < height; y++) {
      for (int x = 0; x < width; x++) {
        int r = pixelData.get(i++);
        int g = pixelData.get(i++);
        int b = pixelData.get(i++);
        int a = pixelData.get(i++);
        rgbArray[dst + x] = a << 24 | r << 16 | g << 8 | b;
      }
      dst += scanSize;
    }
  }
Ejemplo n.º 2
0
 @Override
 public Surface setFillPattern(Pattern pattern) {
   // TODO: Add it to the state stack.
   Asserts.checkArgument(pattern instanceof GLPattern);
   this.fillPattern = ((GLPattern) pattern).image();
   return this;
 }
Ejemplo n.º 3
0
 /**
  * Set the current sprite via the index.
  *
  * <p>The index is an integer between 0 and the number of sprites (@see {@link #numSprites()})
  */
 public void setSprite(int index) {
   Asserts.checkElementIndex(index, spriteImages.size(), "Invalid sprite index");
   if (index != currentId) {
     current = spriteImages.get(index);
     currentId = index;
     updateLayer();
   }
 }
Ejemplo n.º 4
0
  protected static Animation.Value onScaleY(final Layer layer) {
    Asserts.checkNotNull(layer);
    return new Animation.Value() {
      public float initial() {
        return layer.scaleY();
      }

      public void set(float value) {
        layer.setScaleY(value);
      }
    };
  }
Ejemplo n.º 5
0
  /** Starts a tween on the supplied layer's transparency. */
  public Animation.One tweenAlpha(final Layer layer) {
    Asserts.checkNotNull(layer);
    return tween(
        new Animation.Value() {
          public float initial() {
            return layer.alpha();
          }

          public void set(float value) {
            layer.setAlpha(value);
          }
        });
  }
Ejemplo n.º 6
0
  /**
   * Tweens the volume of the supplied sound. Useful for fade-ins and fade-outs. Note, this does not
   * play or stop the sound, those must be enacted separately.
   */
  public Animation.One tweenVolume(final Sound sound) {
    Asserts.checkNotNull(sound);
    return tween(
        new Animation.Value() {
          public float initial() {
            return sound.volume();
          }

          public void set(float value) {
            sound.setVolume(value);
          }
        });
  }
Ejemplo n.º 7
0
  /**
   * Notes the specified piecement placement, assigns it a claim group and propagates its claim
   * information to connected tiles. The tile placement associated with this piecen must have
   * already been added via {@link #addPlacement}.
   */
  public void addPiecen(Piecen piecen) {
    _piecens.put(piecen.loc, piecen);

    // make sure a play exists at the appropriate location
    Placement play =
        Asserts.checkNotNull(
            _plays.get(piecen.loc), "Piecen played at location where no tile exists? %s", piecen);

    List<TileFeature> flist = Lists.newArrayList();
    enumerateGroup(play, play.getFeature(piecen.featureIdx), flist);
    int claimGroup = ++_claimGroupCounter;
    for (TileFeature feat : flist) {
      // one of these calls will result in this piecen's claim group being mapped
      getClaim(feat.play).setClaimGroup(feat.feature, claimGroup);
    }
  }
Ejemplo n.º 8
0
 @Override
 public Region subImage(float sx, float sy, float swidth, float sheight) {
   Asserts.checkArgument(
       sx >= 0
           && sy >= 0
           && swidth > 0
           && sheight > 0
           && (sx + swidth) <= width()
           && (sy + sheight) <= height(),
       "Invalid bounds for subimage [image="
           + width()
           + "x"
           + height()
           + ", subImage="
           + swidth
           + "x"
           + sheight
           + "+"
           + sx
           + "+"
           + sy
           + "]");
   return new JavaImageRegion(this, sx, sy, swidth, sheight);
 }
Ejemplo n.º 9
0
 @Override
 public Pattern toPattern() {
   Asserts.checkState(isReady(), "Cannot generate a pattern from unready image.");
   Rectangle2D rect = new Rectangle2D.Float(0, 0, width(), height());
   return new JavaPattern(this, new TexturePaint(img, rect));
 }
Ejemplo n.º 10
0
 @Override
 protected void updateTexture(int tex) {
   Asserts.checkState(img != null);
   ((JavaGLContext) ctx).updateTexture(tex, img);
 }
Ejemplo n.º 11
0
 @Override
 public void setVolume(float volume) {
   Asserts.checkArgument(0f <= volume && volume <= 1f, "Must ensure 0f <= volume <= 1f");
   sound.setVolume((int) (volume * 100));
 }
Ejemplo n.º 12
0
 @Override
 public Surface restore() {
   Asserts.checkState(transformStack.size() > 1, "Unbalanced save/restore");
   transformStack.remove(transformStack.size() - 1);
   return this;
 }
Ejemplo n.º 13
0
 /** Set the current sprite via the sprite's id. */
 public void setSprite(String id) {
   setSprite(Asserts.checkNotNull(spriteIdMap.get(id), "Invalid sprite id"));
 }
Ejemplo n.º 14
0
 @Override
 public Pattern toPattern() {
   Asserts.checkState(isReady(), "Cannot toPattern() a non-ready image");
   return new HtmlPattern(this, repeatX, repeatY);
 }