示例#1
0
文件: FloodRed.java 项目: srnsw/xena
  /**
   * Construct a fully transparent image <tt>bounds</tt> size, will paint one tile with paint. Thus
   * paint should not be a pattered paint or gradient but should be a solid color.
   *
   * @param bounds the bounds of the image (in fact will respond with any request).
   */
  public FloodRed(Rectangle bounds, Paint paint) {
    super(); // We _must_ call init...

    ColorModel cm = GraphicsUtil.sRGB_Unpre;

    int defSz = AbstractTiledRed.getDefaultTileSize();

    int tw = bounds.width;
    if (tw > defSz) tw = defSz;
    int th = bounds.height;
    if (th > defSz) th = defSz;

    // fix my sample model so it makes sense given my size.
    SampleModel sm = cm.createCompatibleSampleModel(tw, th);

    // Finish initializing our base class...
    init((CachableRed) null, bounds, cm, sm, 0, 0, null);

    raster = Raster.createWritableRaster(sm, new Point(0, 0));
    BufferedImage offScreen = new BufferedImage(cm, raster, cm.isAlphaPremultiplied(), null);

    Graphics2D g = GraphicsUtil.createGraphics(offScreen);
    g.setPaint(paint);
    g.fillRect(0, 0, bounds.width, bounds.height);
    g.dispose();
  }
示例#2
0
  // long lastFrame = -1;
  public void repaint(RectListManager devRLM) {
    if (devRLM == null) return;

    updateWorkingBuffers();
    if ((rootGN == null) || (workImg == null)) return;

    try {
      // Ensure only one thread works on WorkImg at a time...
      synchronized (workImg) {
        Graphics2D g2d = GraphicsUtil.createGraphics(workImg, renderingHints);

        Rectangle dr;
        dr = new Rectangle(0, 0, offScreenWidth, offScreenHeight);

        if ((isDoubleBuffered) && (currImg != null) && (damagedAreas != null)) {

          damagedAreas.subtract(devRLM, COPY_OVERHEAD, COPY_LINE_OVERHEAD);

          damagedAreas.mergeRects(COPY_OVERHEAD, COPY_LINE_OVERHEAD);

          Iterator iter = damagedAreas.iterator();
          g2d.setComposite(AlphaComposite.Src);
          while (iter.hasNext()) {
            Rectangle r = (Rectangle) iter.next();
            if (!dr.intersects(r)) continue;
            r = dr.intersection(r);
            g2d.setClip(r.x, r.y, r.width, r.height);
            g2d.setComposite(AlphaComposite.Clear);
            g2d.fillRect(r.x, r.y, r.width, r.height);
            g2d.setComposite(AlphaComposite.SrcOver);
            g2d.drawImage(currImg, 0, 0, null);
          }
        }

        Iterator iter = devRLM.iterator();
        while (iter.hasNext()) {
          Rectangle r = (Rectangle) iter.next();
          if (!dr.intersects(r)) continue;
          r = dr.intersection(r);
          g2d.setTransform(IDENTITY);
          g2d.setClip(r.x, r.y, r.width, r.height);
          g2d.setComposite(AlphaComposite.Clear);
          g2d.fillRect(r.x, r.y, r.width, r.height);
          g2d.setComposite(AlphaComposite.SrcOver);
          g2d.transform(usr2dev);
          rootGN.paint(g2d);
        }
        g2d.dispose();
      }
    } catch (Throwable t) {
      t.printStackTrace();
    }
    if (HaltingThread.hasBeenHalted()) return;

    // System.out.println("Dmg: "   + damagedAreas);
    // System.out.println("Areas: " + devRects);

    // Swap the buffers if the rendering completed cleanly.
    if (isDoubleBuffered) {
      BufferedImage tmpImg = workImg;
      workImg = currImg;
      currImg = tmpImg;
      damagedAreas = devRLM;
    }
  }