private VolatileImage loadFromFile(String filename) throws ImageLoadException {
    try {

      BufferedImage bimage = ImageIO.read(new File(filename));
      VolatileImage vimage =
          createVolatileImage(bimage.getWidth(), bimage.getHeight(), Transparency.TRANSLUCENT);
      Graphics2D g = null;

      try {
        g = vimage.createGraphics();
        g.setComposite(AlphaComposite.Src);

        g.setColor(new Color(0, 0, 0, 0));
        g.fillRect(0, 0, vimage.getWidth(), vimage.getHeight());

        g.drawImage(bimage, null, 0, 0);
      } finally {
        g.dispose();
      }

      return vimage;
    } catch (Exception e) {
      throw new ImageLoadException("Impossible de charger une image � " + filename, e);
    }
  }
Esempio n. 2
0
 /**
  * Performs the native flip operation for the given target Component.
  *
  * <p>REMIND: we should really not get here because that would mean that a FLIP BufferStrategy has
  * been created, and one could only be created if accelerated pipeline is present but in some rare
  * (and transitional) cases it may happen that the accelerated graphics device may have a default
  * graphics configuraiton, so this is just a precaution.
  */
 public void flip(
     WComponentPeer peer,
     Component target,
     VolatileImage backBuffer,
     int x1,
     int y1,
     int x2,
     int y2,
     BufferCapabilities.FlipContents flipAction) {
   if (flipAction == BufferCapabilities.FlipContents.COPIED
       || flipAction == BufferCapabilities.FlipContents.UNDEFINED) {
     Graphics g = peer.getGraphics();
     try {
       g.drawImage(backBuffer, x1, y1, x2, y2, x1, y1, x2, y2, null);
     } finally {
       g.dispose();
     }
   } else if (flipAction == BufferCapabilities.FlipContents.BACKGROUND) {
     Graphics g = backBuffer.getGraphics();
     try {
       g.setColor(target.getBackground());
       g.fillRect(0, 0, backBuffer.getWidth(), backBuffer.getHeight());
     } finally {
       g.dispose();
     }
   }
   // the rest of the flip actions are not supported
 }
Esempio n. 3
0
  public void render(Graphics2D g) {
    do {
      do {
        g = (Graphics2D) strategy.getDrawGraphics();
        g.setRenderingHints(renderingHints);
        vi = createVolatileImage(getWidth(), getHeight());
        bi =
            GraphicsEnvironment.getLocalGraphicsEnvironment()
                .getDefaultScreenDevice()
                .getDefaultConfiguration()
                .createCompatibleImage(getWidth(), getHeight());
        vi.getGraphics().fillRect(0, 0, vi.getWidth(), vi.getHeight());

        for (Renderable renderable : Window.objects) {
          if (renderable.getShouldDestroy()) Window.objects.remove(renderable);
          if (renderable.isVisible()) renderable.render((Graphics2D) vi.getGraphics());
        }

        bi.getGraphics().drawImage(vi.getSnapshot(), 0, 0, getWidth(), getHeight(), null);
        bi = vi.getSnapshot();
        // gaussian.filter(bi, bi);
        // glow.filter(bi, bi);
        // motionBlur.filter(bi, bi);
        g.drawImage(bi, 0, 0, getWidth(), getHeight(), null);
        g.dispose();
        Toolkit.getDefaultToolkit().sync();
      } while (strategy.contentsRestored());
      strategy.show();
    } while (strategy.contentsLost());
  }
 /**
  * Paints the image at the specified location. This method assumes scaling has already been done,
  * and simply paints the background image "as-is."
  *
  * @param g The graphics context.
  * @param x The x-coordinate at which to paint.
  * @param y The y-coordinate at which to paint.
  */
 protected void paintImage(Graphics g, int x, int y) {
   if (bgImage != null) {
     do {
       int rc = bgImage.validate(null); // getGraphicsConfiguration());
       if (rc == VolatileImage.IMAGE_RESTORED) {
         // FIXME:  If the image needs to be restored are its width
         // and height still valid??  If not, we'll need to cache
         // these values...
         renderImage(bgImage.getWidth(), bgImage.getHeight(), getScalingHint());
       }
       g.drawImage(bgImage, x, y, null);
     } while (bgImage.contentsLost());
   }
 }
Esempio n. 5
0
  /** Performs the native GLX flip operation for the given target Component. */
  @Override
  public void flip(
      X11ComponentPeer peer,
      Component target,
      VolatileImage xBackBuffer,
      int x1,
      int y1,
      int x2,
      int y2,
      BufferCapabilities.FlipContents flipAction) {
    if (flipAction == BufferCapabilities.FlipContents.COPIED) {
      SurfaceManager vsm = SurfaceManager.getManager(xBackBuffer);
      SurfaceData sd = vsm.getPrimarySurfaceData();

      if (sd instanceof GLXVSyncOffScreenSurfaceData) {
        GLXVSyncOffScreenSurfaceData vsd = (GLXVSyncOffScreenSurfaceData) sd;
        SurfaceData bbsd = vsd.getFlipSurface();
        Graphics2D bbg = new SunGraphics2D(bbsd, Color.black, Color.white, null);
        try {
          bbg.drawImage(xBackBuffer, 0, 0, null);
        } finally {
          bbg.dispose();
        }
      } else {
        Graphics g = peer.getGraphics();
        try {
          g.drawImage(xBackBuffer, x1, y1, x2, y2, x1, y1, x2, y2, null);
        } finally {
          g.dispose();
        }
        return;
      }
    } else if (flipAction == BufferCapabilities.FlipContents.PRIOR) {
      // not supported by GLX...
      return;
    }

    OGLSurfaceData.swapBuffers(peer.getContentWindow());

    if (flipAction == BufferCapabilities.FlipContents.BACKGROUND) {
      Graphics g = xBackBuffer.getGraphics();
      try {
        g.setColor(target.getBackground());
        g.fillRect(0, 0, xBackBuffer.getWidth(), xBackBuffer.getHeight());
      } finally {
        g.dispose();
      }
    }
  }
Esempio n. 6
0
  public void initialize() {

    // openLevelFile images:
    try {
      boxSpriteSheet = ImageIO.read(new File("ItemContainer.png"));
      coinSpriteSheet = ImageIO.read(new File("Coin.png"));
    } catch (Exception e) {
    }

    if (openLevelFile == false) {
      try {
        loadLevel(initLevel);
      } catch (Exception e) {
        System.out.println(e);
      }
    } else {
      loadLevel(FileOpenDialog("Open ..."));
    }

    // create tile layer:
    renderTileLayer();

    // create bg layer:
    backgroundLayer = new VolatileImage[backgroundImage.length];

    // render layer:
    for (int i = 0; i < backgroundImage.length; i++) {
      renderBackgroundLayer(0);
      renderBackgroundLayer(1);
    }

    // create hardware accellerated rendering layer:
    renderImage =
        this.getGraphicsConfiguration()
            .createCompatibleVolatileImage(
                loadedLevel.getWidth() * 16,
                loadedLevel.getHeight() * 16,
                Transparency.TRANSLUCENT);
    Graphics2D g2d = renderImage.createGraphics();
    g2d.setComposite(AlphaComposite.Src);

    // Clear the image.
    g2d.setColor(new Color(0, 0, 0, 0));
    g2d.fillRect(0, 0, renderImage.getWidth(), renderImage.getHeight());
    g2d.setBackground(new Color(0, 0, 0, 0));
  }
Esempio n. 7
0
  /** @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#paintComponent(java.awt.Graphics) */
  public void paintComponent(Graphics g) {
    //		long t1 = System.currentTimeMillis();

    VolatileImage image = createVolatileImage();
    Graphics gh = image.createGraphics();
    gh.setColor(getLayoutControl().getBackground());
    gh.fillRect(0, 0, image.getWidth(), image.getHeight());

    getLayoutControl().getLayoutDraw().drawRectangle((Graphics2D) gh);
    gh.drawImage(getLayoutControl().getImage(), 0, 0, null);
    gh.drawImage(getLayoutControl().getImgRuler(), 0, 0, null);
    //		long t2 = System.currentTimeMillis();

    //		BufferedImage img = getLayoutControl().getImage();
    //		BufferedImage imgRuler=getLayoutControl().getImgRuler();
    //		g.drawImage(img, 0, 0, getLayoutControl());
    //		g.drawImage(imgRuler, 0, 0, getLayoutControl());
    gh.setColor(Color.black);
    gh.setXORMode(Color.white);

    // Borramos el anterior
    Rectangle r = new Rectangle();

    // Dibujamos el actual
    if (dragged
        && (getLayoutControl().getFirstPoint() != null)
        && (getLayoutControl().getLastPoint() != null)) {
      r.setFrameFromDiagonal(getLayoutControl().getFirstPoint(), getLayoutControl().getLastPoint());
      gh.drawRect(r.x, r.y, r.width, r.height);
    }
    IFFrame[] frames = getLayoutControl().getLayoutContext().getFFrameSelected();
    for (int i = 0; i < frames.length; i++) {
      gh.setColor(Color.black);
      frames[i].drawHandlers((Graphics2D) gh);
    }
    gh.setPaintMode();
    //		getLayoutControl().drawCursor(gh);
    g.drawImage(image, 0, 0, null);
    //		long t3 = System.currentTimeMillis();
    //		System.out.println("t1 = " + (t2-t1) + " t2=" + (t3-t2));

  }
Esempio n. 8
0
    public void rebuild() {
      backG.setColor(Color.BLACK);
      backG.fillRect(0, 0, backImg.getWidth(), backImg.getHeight());

      for (int z = 0; z < paths.length; z++) {
        Path path = paths[z];

        double[] d = path.getCoords(animPos);
        if (path instanceof MemoryPath) {
          MemoryPath mp = (MemoryPath) path;
          for (int i = 1 - mp.getMemorySize(); i <= 0; i++) {
            int col = 0xff0000 + (0x110000 * i);
            d = mp.getPreviousCoords(i);
            backG.setColor(new Color(col));
            backG.fillRect((int) (d[0] - 2), (int) (d[1] - 2), 5, 5);
          }
        } else {
          backG.setColor(Color.RED);
          backG.fillRect((int) (d[0] - 2), (int) (d[1] - 2), 5, 5);
        }
      }

      this.repaint();
    }
Esempio n. 9
0
  public VolatileImage renderTileLayer() {
    // create hardware accellerated tile layer (Volatile Image)
    tileLayer =
        this.getGraphicsConfiguration()
            .createCompatibleVolatileImage(
                loadedLevel.getWidth() * 16,
                loadedLevel.getHeight() * 16,
                Transparency.TRANSLUCENT);
    Graphics2D g2d = tileLayer.createGraphics();
    g2d.setComposite(AlphaComposite.Src);

    // Clear the image.
    g2d.setColor(new Color(0, 0, 0, 0));
    g2d.fillRect(0, 0, tileLayer.getWidth(), tileLayer.getHeight());
    g2d.setBackground(new Color(0, 0, 0, 0));

    g2d.setColor(new Color(1f, 1f, 1f, 1f));

    for (int i = 0; i < numberOfTiles; i++) {
      tile[i].draw(g2d, this);
    }

    return tileLayer;
  }