Ejemplo n.º 1
0
 public void overlay(Graphics g) {
   if (!firstOverlayInvocation) {
     if (cachedBounds != null) {
       g.setColor(Color.black);
       Rectangle2D tmp = graph.toScreen((Rectangle2D) cachedBounds.clone());
       g.drawRect(
           (int) tmp.getX(),
           (int) tmp.getY(),
           (int) tmp.getWidth() - 2,
           (int) tmp.getHeight() - 2);
     } else if (!initialBounds.equals(vertex.getBounds())) {
       Graphics2D g2 = (Graphics2D) g;
       AffineTransform oldTransform = g2.getTransform();
       g2.scale(graph.getScale(), graph.getScale());
       graph.getUI().paintCell(g, vertex, vertex.getBounds(), true);
       if (contextViews != null) {
         for (int i = 0; i < contextViews.length; i++) {
           graph.getUI().paintCell(g, contextViews[i], contextViews[i].getBounds(), true);
         }
       }
       if (!graph.isPortsScaled()) g2.setTransform(oldTransform);
       if (portViews != null && graph.isPortsVisible()) graph.getUI().paintPorts(g, portViews);
       g2.setTransform(oldTransform);
     }
   }
   firstOverlayInvocation = false;
 }
Ejemplo n.º 2
0
  private boolean drawComposite(Rectangle2D bounds, ImageObserver observer) {
    // Clip source to visible areas that need updating
    Rectangle2D clip = this.getClipBounds();
    Rectangle2D.intersect(bounds, clip, bounds);
    clip =
        new Rectangle(
            buffer.getMinX(), buffer.getMinY(),
            buffer.getWidth(), buffer.getHeight());
    Rectangle2D.intersect(bounds, clip, bounds);

    BufferedImage buffer2 = buffer;
    if (!bounds.equals(buffer2.getRaster().getBounds()))
      buffer2 =
          buffer2.getSubimage(
              (int) bounds.getX(),
              (int) bounds.getY(),
              (int) bounds.getWidth(),
              (int) bounds.getHeight());

    // Get destination clip to bounds
    double[] points =
        new double[] {
          bounds.getX(), bounds.getY(),
          bounds.getMaxX(), bounds.getMaxY()
        };
    transform.transform(points, 0, points, 0, 2);

    Rectangle2D deviceBounds =
        new Rectangle2D.Double(points[0], points[1], points[2] - points[0], points[3] - points[1]);

    Rectangle2D.intersect(deviceBounds, this.getClipInDevSpace(), deviceBounds);

    // Get current image on the component
    GtkImage img = grab(component);
    Graphics gr = componentBuffer.createGraphics();
    gr.drawImage(img, 0, 0, null);
    gr.dispose();

    BufferedImage cBuffer = componentBuffer;
    if (!deviceBounds.equals(cBuffer.getRaster().getBounds()))
      cBuffer =
          cBuffer.getSubimage(
              (int) deviceBounds.getX(),
              (int) deviceBounds.getY(),
              (int) deviceBounds.getWidth(),
              (int) deviceBounds.getHeight());

    // Perform actual composite operation
    compCtx.compose(buffer2.getRaster(), cBuffer.getRaster(), cBuffer.getRaster());

    // This MUST call directly into the "action" method in CairoGraphics2D,
    // not one of the wrappers, to ensure that the composite isn't processed
    // more than once!
    boolean rv =
        super.drawImage(
            cBuffer,
            AffineTransform.getTranslateInstance(bounds.getX(), bounds.getY()),
            null,
            null);
    return rv;
  }