Exemplo n.º 1
0
 /**
  * Render this offscreen canvas to the specified graphics.
  *
  * @param graphics graphics to render this offscreen canvas to, must not be null
  */
 public void render(final Graphics2D graphics) {
   if (graphics == null) {
     throw new IllegalArgumentException("graphics must not be null");
   }
   final PPaintContext paintContext = new PPaintContext(graphics);
   paintContext.setRenderQuality(renderQuality);
   camera.fullPaint(paintContext);
 }
Exemplo n.º 2
0
  /**
   * Paints the region specified of the canvas onto the given Graphics Context.
   *
   * @param gc graphics onto within painting should occur
   * @param x left of the dirty region
   * @param y top of the dirty region
   * @param w width of the dirty region
   * @param h height of the dirty region
   */
  public void paintComponent(final GC gc, final int x, final int y, final int w, final int h) {
    PDebug.startProcessingOutput();

    GC imageGC = null;
    Graphics2D g2 = null;
    if (doubleBuffered) {
      imageGC = new GC(backBuffer);
      g2 = new SWTGraphics2D(imageGC, getDisplay());
    } else {
      g2 = new SWTGraphics2D(gc, getDisplay());
    }

    g2.setColor(Color.white);
    g2.setBackground(Color.white);

    final Rectangle rect = getBounds();
    g2.fillRect(0, 0, rect.width, rect.height);

    // This fixes a problem with standard debugging of region management in
    // SWT
    if (PDebug.debugRegionManagement) {
      final Rectangle r = gc.getClipping();
      final Rectangle2D r2 = new Rectangle2D.Double(r.x, r.y, r.width, r.height);
      g2.setBackground(PDebug.getDebugPaintColor());
      g2.fill(r2);
    }

    // create new paint context and set render quality
    final PPaintContext paintContext = new PPaintContext(g2);
    if (getInteracting() || getAnimating()) {
      if (interactingRenderQuality > animatingRenderQuality) {
        paintContext.setRenderQuality(interactingRenderQuality);
      } else {
        paintContext.setRenderQuality(animatingRenderQuality);
      }
    } else {
      paintContext.setRenderQuality(defaultRenderQuality);
    }

    // paint Piccolo2D
    camera.fullPaint(paintContext);

    // if switched state from animating to not animating invalidate
    // the entire screen so that it will be drawn with the default instead
    // of animating render quality.
    if (animatingOnLastPaint && !getAnimating()) {
      repaint();
    }
    animatingOnLastPaint = getAnimating();

    final boolean region = PDebug.debugRegionManagement;
    PDebug.debugRegionManagement = false;
    PDebug.endProcessingOutput(g2);
    PDebug.debugRegionManagement = region;

    if (doubleBuffered) {
      gc.drawImage(backBuffer, 0, 0);

      // Dispose of the allocated image gc
      imageGC.dispose();
    }
  }