public FrontBack(SJGame sjg) {
    super(sjg);
    frontImage = sjg.createImage(sjg.getWidth(), sjg.getHeight());
    backImage = sjg.createImage(sjg.getWidth(), sjg.getHeight());
    setFront(frontImage.getGraphics());
    setBack(backImage.getGraphics());

    getFront().setColor(Color.white);
    getFront().fillRect(0, 0, sjg.getWidth(), sjg.getHeight());
    getFront().setColor(Color.black);

    getBack().setColor(Color.white);
    getBack().fillRect(0, 0, sjg.getWidth(), sjg.getHeight());
    getBack().setColor(Color.black);
  }
Esempio n. 2
0
  private void gameRender() {
    if (dbImage == null) {
      dbImage = createImage(PWIDTH, PHEIGHT);
      if (dbImage == null) {
        System.out.println("dbImage is null");
        return;
      } else dbg = dbImage.getGraphics();
    }

    // draw a white background
    dbg.setColor(Color.white);
    dbg.fillRect(0, 0, PWIDTH, PHEIGHT);

    // draw the game elements: order is important
    ribsMan.display(dbg); // the background ribbons
    bricksMan.display(dbg); // the bricks
    jack.drawSprite(dbg); // the sprites
    fireball.drawSprite(dbg);

    if (showExplosion) // draw the explosion (in front of jack)
    dbg.drawImage(explosionPlayer.getCurrentImage(), xExpl, yExpl, null);

    reportStats(dbg);

    if (gameOver) gameOverMessage(dbg);

    if (showHelp) // draw the help at the very front (if switched on)
    dbg.drawImage(
          helpIm, (PWIDTH - helpIm.getWidth()) / 2, (PHEIGHT - helpIm.getHeight()) / 2, null);
  } // end of gameRender()
Esempio n. 3
0
 /**
  * Prepare a buffer for the image, return if the canvas is ready Only need to call this when the
  * size of the canvas is changed, Since we automatically detect the size change in paint() only
  * call this on start
  */
 public boolean newImgBuf() {
   Dimension sz = getSize();
   if (sz.width == 0 || sz.height == 0) return false;
   // quit if the current image already has the right size
   if (img != null && imgG != null && sz.equals(imgSize)) return true;
   img = createImage(sz.width, sz.height);
   if (imgG != null) imgG.dispose();
   imgG = img.getGraphics();
   imgSize = sz;
   return true;
 }
Esempio n. 4
0
  public void setSize(Dimension d) {

    super.setSize(d);

    if (offg != null) {
      offscreen = createImage(getWidth(), getHeight());
      offg = offscreen.getGraphics();
    }
    /*
    if(IGView.view!=null){
        IGView.view.setScreenSize(w,h);
        IGView.view.update();
    }
    IGCore.setDisplaySize(d);
    */
  }
Esempio n. 5
0
 // Use double buffer to reduce flicker when drawing complex ROIs.
 // Author: Erik Meijering
 void paintDoubleBuffered(Graphics g) {
   final int srcRectWidthMag = (int) (srcRect.width * magnification);
   final int srcRectHeightMag = (int) (srcRect.height * magnification);
   if (offScreenImage == null
       || offScreenWidth != srcRectWidthMag
       || offScreenHeight != srcRectHeightMag) {
     offScreenImage = createImage(srcRectWidthMag, srcRectHeightMag);
     offScreenWidth = srcRectWidthMag;
     offScreenHeight = srcRectHeightMag;
   }
   Roi roi = imp.getRoi();
   try {
     if (imageUpdated) {
       imageUpdated = false;
       imp.updateImage();
     }
     Graphics offScreenGraphics = offScreenImage.getGraphics();
     Java2.setBilinearInterpolation(offScreenGraphics, Prefs.interpolateScaledImages);
     Image img = imp.getImage();
     if (img != null)
       offScreenGraphics.drawImage(
           img,
           0,
           0,
           srcRectWidthMag,
           srcRectHeightMag,
           srcRect.x,
           srcRect.y,
           srcRect.x + srcRect.width,
           srcRect.y + srcRect.height,
           null);
     if (overlay != null) drawOverlay(offScreenGraphics);
     if (showAllROIs) drawAllROIs(offScreenGraphics);
     if (roi != null) drawRoi(roi, offScreenGraphics);
     if (srcRect.width < imageWidth || srcRect.height < imageHeight)
       drawZoomIndicator(offScreenGraphics);
     if (IJ.debugMode) showFrameRate(offScreenGraphics);
     g.drawImage(offScreenImage, 0, 0, null);
   } catch (OutOfMemoryError e) {
     IJ.outOfMemory("Paint");
   }
 }
Esempio n. 6
0
 public void paint(Graphics g) {
   if (histogram != null) {
     if (os == null) {
       os = createImage(WIDTH, HEIGHT);
       osg = os.getGraphics();
       osg.setColor(Color.white);
       osg.fillRect(0, 0, WIDTH, HEIGHT);
       osg.setColor(Color.gray);
       for (int i = 0; i < WIDTH; i++) {
         if (hColors != null) osg.setColor(hColors[i]);
         osg.drawLine(i, HEIGHT, i, HEIGHT - ((int) (HEIGHT * histogram[i]) / hmax) - 4);
       }
       osg.dispose();
     }
     g.drawImage(os, 0, 0, this);
   } else {
     g.setColor(Color.white);
     g.fillRect(0, 0, WIDTH, HEIGHT);
   }
   g.setColor(Color.black);
   g.drawLine(0, HEIGHT - 4, 256, HEIGHT - 4);
   g.drawRect(0, 0, WIDTH, HEIGHT);
   g.drawRect((int) minHue, 1, (int) (maxHue - minHue), HEIGHT - 5);
 }
Esempio n. 7
0
  // Although it presently returns a boolean, that was only needed
  // during my aborted attempted at animated graphics primitives.
  // Until those become a reality the boolean value returned by this
  // routine is unnecessary
  public boolean animate(int sAt, boolean forward) {

    int x;
    LinkedList lt = null;
    animation_done =
        true; // May be re-set in paintComponent via indirect paintImmediately call at end

    // Was used in aborted attempted to
    // introduce animated primitives.  Now
    // it's probably excess baggage that
    // remains because I still have hopes
    // of eventually having animated
    // primitives

    if (getSize().width != 0 && getSize().height != 0) {
      my_width = getSize().width; // set dimensions
      my_height = getSize().height;
    } else {
      my_width = GaigsAV.preferred_width; // set dimensions
      my_height = GaigsAV.preferred_height;
    }

    // First capture the new image in a buffer called image2
    SnapAt = sAt;
    BufferedImage image2 = new BufferedImage(my_width, my_height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = (Graphics2D) image2.getGraphics(); // need a separate object each time?
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setColor(Color.WHITE);
    g2.fillRect(0, 0, my_width, my_height);
    // Set horizoff and vertoff to properly center the visualization in the
    // viewing window. This is not quite perfect because visualizations
    // that are not properly centered within their [0,1] localized
    // coordinates will not be perfectly centered, but it is much better
    // than it was previously.

    if (no_mouse_drag) {
      horizoff = (my_width - GaigsAV.preferred_width) / 2;
      vertoff = (my_height - GaigsAV.preferred_height) / 2;
    }

    list_of_snapshots.reset();
    x = 0;
    lt = new LinkedList();
    while (x < SnapAt && list_of_snapshots.hasMoreElements()) {
      lt = (LinkedList) list_of_snapshots.nextElement();
      x++;
    }
    lt.reset();
    animation_done = true;
    //        System.out.println("before loop " + horizoff);
    while (lt.hasMoreElements()) {
      obj tempObj = (obj) lt.nextElement();
      animation_done =
          animation_done && (tempObj.execute(g2 /*offscreen*/, zoom, vertoff, horizoff));
      //  System.out.println("in loop");
    }

    // Next capture the image we are coming from in a buffer called image1
    SnapAt = (forward ? sAt - 1 : sAt + 1);
    BufferedImage image1 = new BufferedImage(my_width, my_height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g1 = (Graphics2D) image1.getGraphics(); // need a separate object each time?
    g1.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g1.setColor(Color.WHITE);
    g1.fillRect(0, 0, my_width, my_height);
    // Set horizoff and vertoff to properly center the visualization in the
    // viewing window. This is not quite perfect because visualizations
    // that are not properly centered within their [0,1] localized
    // coordinates will not be perfectly centered, but it is much better
    // than it was previously.

    if (no_mouse_drag) {
      horizoff = (my_width - GaigsAV.preferred_width) / 2;
      vertoff = (my_height - GaigsAV.preferred_height) / 2;
    }

    list_of_snapshots.reset();
    x = 0;
    lt = new LinkedList();
    while (x < SnapAt && list_of_snapshots.hasMoreElements()) {
      lt = (LinkedList) list_of_snapshots.nextElement();
      x++;
    }
    lt.reset();
    animation_done = true;
    //        System.out.println("before loop " + horizoff);
    while (lt.hasMoreElements()) {
      obj tempObj = (obj) lt.nextElement();
      animation_done =
          animation_done && (tempObj.execute(g1 /*offscreen*/, zoom, vertoff, horizoff));
      //  System.out.println("in loop");
    }

    // Now slide from image1 to image2

    // From the gaff Visualizer by Chris Gaffney
    //        double step = 4;	// Adjust this for more/less granularity between images
    double step = 40; // Adjust this for more/less granularity between images

    Image buffer = getGraphicsConfiguration().createCompatibleVolatileImage(my_width, my_height);
    Graphics2D g2d = (Graphics2D) buffer.getGraphics();

    AffineTransform trans = AffineTransform.getTranslateInstance(step * (forward ? -1 : 1), 0);
    //        AffineTransform orig = g2d.getTransform();

    Shape mask = createMask(my_width, my_height);

    for (double i = 0; i < my_width; i += step) {
      if (i + step > my_width) // last time through loop, so adjust transform
      trans =
            AffineTransform.getTranslateInstance(((double) (my_width - i)) * (forward ? -1 : 1), 0);
      g2d.transform(trans);
      g2d.drawImage(image1, 0, 0, this);
      g2d.setColor(Color.BLACK);
      g2d.fill(mask);

      AffineTransform last = g2d.getTransform();
      g2d.transform(AffineTransform.getTranslateInstance(my_width * (-1 * (forward ? -1 : 1)), 0));
      g2d.drawImage(image2, 0, 0, this);
      g2d.setColor(Color.BLACK);
      g2d.fill(mask);

      g2d.setTransform(last);

      this.my_image = buffer;
      repaint();

      try {
        Thread.sleep(10);
      } catch (InterruptedException e) {

      }
    }
    Image b = getGraphicsConfiguration().createCompatibleImage(my_width, my_height);
    b.getGraphics().drawImage(buffer, 0, 0, null);
    this.my_image = b;

    return animation_done;
  }
Esempio n. 8
0
 public void initScreen() {
   offscreen = createImage(getWidth(), getHeight());
   if (offscreen != null) {
     offg = offscreen.getGraphics();
   }
 }