예제 #1
0
  protected void handleZero(WritableRaster wr) {
    // Get my source.
    CachableRed src = (CachableRed) getSources().get(0);
    Rectangle srcR = src.getBounds();
    Rectangle wrR = wr.getBounds();

    ZeroRecter zr = ZeroRecter.getZeroRecter(wr);

    // area rect (covers the area left to handle).
    Rectangle ar = new Rectangle(wrR.x, wrR.y, wrR.width, wrR.height);
    // draw rect (used for calls to zeroRect);
    Rectangle dr = new Rectangle(wrR.x, wrR.y, wrR.width, wrR.height);

    // We split the edge drawing up into four parts.
    //
    //  +-----------------------------+
    //  | 1    | 2                    |
    //  |      +---------------+------|
    //  /      /               /4     /
    //  /      /               /      /
    //  /      /               /      /
    //  /      /               /      /
    //  |      +---------------+------|
    //  |      |  3                   |
    //  +-----------------------------+
    //
    //  We update our x,y, width, height as we go along so
    //  we 'forget' about the parts we have already painted...

    // Draw #1
    if (DEBUG) {
      System.out.println("WrR: " + wrR + " srcR: " + srcR);
      // g2d.setColor(new Color(255,0,0,128));
    }
    if (ar.x < srcR.x) {
      int w = srcR.x - ar.x;
      if (w > ar.width) w = ar.width;
      // g2d.fillRect(x, y, w, height);
      dr.width = w;
      zr.zeroRect(dr);

      ar.x += w;
      ar.width -= w;
    }

    // Draw #2
    if (DEBUG) {
      System.out.println(
          "WrR: [" + ar.x + "," + ar.y + "," + ar.width + "," + ar.height + "] s rcR: " + srcR);
      // g2d.setColor(new Color(0,0,255,128));
    }
    if (ar.y < srcR.y) {
      int h = srcR.y - ar.y;
      if (h > ar.height) h = ar.height;
      // g2d.fillRect(x, y, width, h);
      dr.x = ar.x;
      dr.y = ar.y;
      dr.width = ar.width;
      dr.height = h;
      zr.zeroRect(dr);

      ar.y += h;
      ar.height -= h;
    }

    // Draw #3
    if (DEBUG) {
      System.out.println(
          "WrR: [" + ar.x + "," + ar.y + "," + ar.width + "," + ar.height + "] srcR: " + srcR);
      // g2d.setColor(new Color(0,255,0,128));
    }
    if (ar.y + ar.height > srcR.y + srcR.height) {
      int h = (ar.y + ar.height) - (srcR.y + srcR.height);
      if (h > ar.height) h = ar.height;

      int y0 = ar.y + ar.height - h; // the +/-1 cancel (?)

      // g2d.fillRect(x, y0, width, h);
      dr.x = ar.x;
      dr.y = y0;
      dr.width = ar.width;
      dr.height = h;
      zr.zeroRect(dr);

      ar.height -= h;
    }

    // Draw #4
    if (DEBUG) {
      System.out.println(
          "WrR: [" + ar.x + "," + ar.y + "," + ar.width + "," + ar.height + "] srcR: " + srcR);
      // g2d.setColor(new Color(255,255,0,128));
    }
    if (ar.x + ar.width > srcR.x + srcR.width) {
      int w = (ar.x + ar.width) - (srcR.x + srcR.width);
      if (w > ar.width) w = ar.width;
      int x0 = ar.x + ar.width - w; // the +/-1 cancel (?)

      // g2d.fillRect(x0, y, w, height);
      dr.x = x0;
      dr.y = ar.y;
      dr.width = w;
      dr.height = ar.height;
      zr.zeroRect(dr);

      ar.width -= w;
    }
  }
예제 #2
0
 public static void zeroRect(WritableRaster wr) {
   ZeroRecter zr = getZeroRecter(wr);
   zr.zeroRect(wr.getBounds());
 }