コード例 #1
0
  private synchronized void render(Graphics g) {
    if (level != null) {
      int xScroll = (int) (player.pos.x - screen.w / 2);
      int yScroll = (int) (player.pos.y - (screen.h - 24) / 2);
      soundPlayer.setListenerPosition((float) player.pos.x, (float) player.pos.y);
      level.render(screen, xScroll, yScroll);
    }
    if (!menuStack.isEmpty()) {
      menuStack.peek().render(screen);
    }

    Font.draw(screen, "FPS: " + fps, 10, 10);
    // for (int p = 0; p < players.length; p++) {
    // if (players[p] != null) {
    // String msg = "P" + (p + 1) + ": " + players[p].getScore();
    // Font.draw(screen, msg, 320, screen.h - 24 + p * 8);
    // }
    // }
    if (player != null && menuStack.size() == 0) {
      Font.draw(screen, player.health + " / 10", 340, screen.h - 19);
      Font.draw(screen, "" + player.score, 340, screen.h - 33);
    }

    g.setColor(Color.BLACK);

    g.fillRect(0, 0, getWidth(), getHeight());
    g.translate((getWidth() - GAME_WIDTH * SCALE) / 2, (getHeight() - GAME_HEIGHT * SCALE) / 2);
    g.clipRect(0, 0, GAME_WIDTH * SCALE, GAME_HEIGHT * SCALE);

    if (!menuStack.isEmpty() || level != null) {

      // render mouse
      renderMouse(screen, mouseButtons);

      g.drawImage(screen.image, 0, 0, GAME_WIDTH * SCALE, GAME_HEIGHT * SCALE, null);
    }

    // String msg = "FPS: " + fps;
    // g.setColor(Color.LIGHT_GRAY);
    // g.drawString(msg, 11, 11);
    // g.setColor(Color.WHITE);
    // g.drawString(msg, 10, 10);

  }
コード例 #2
0
ファイル: ResourceIcon.java プロジェクト: jasonchaffee/VUE
  /*@Override*/ public void paintIcon(Component c, Graphics g, int x, int y) {
    final boolean expandToFit = (mWidth < 1);

    if (DEBUG.IMAGE && DEBUG.META)
      out(
          "paintIcon; onto="
              + GUI.name(c)
              + " painter="
              + GUI.name(mPainter)
              + "@"
              + Integer.toHexString((mPainter.hashCode())));

    if (mPainter == null) {
      // note this means repaint updates would stop in a new parent,
      // tho assuming it's loaded by then, regular paints would work fine.
      mPainter = c;
    }

    if (DrawBorder && !expandToFit) {
      g.setColor(Color.gray);
      g.drawRect(x, y, mWidth - 1, mHeight - 1);
    }

    if (mImage == null) {

      if (!isLoading /*&& mPreviewData != null*/) {
        synchronized (this) {
          if (!isLoading /*&& mPreviewData != null*/)
            VUE.invokeAfterAWT(ResourceIcon.this); // load the preview
        }
      }
      g.setColor(Color.gray);
      g.drawRect(x, y, mWidth - 1, mHeight - 1);
      return;
    }

    int fitWidth, fitHeight;
    final Dimension maxImageSize;

    if (expandToFit) {
      // fill the given component
      fitWidth = c.getWidth();
      fitHeight = c.getHeight();
      maxImageSize = c.getSize();
    } else {
      // paint at our fixed size
      fitWidth = mWidth;
      fitHeight = mHeight;

      if (DrawBorder)
        maxImageSize = new Dimension(fitWidth - BorderSpace * 2, fitHeight - BorderSpace * 2);
      else maxImageSize = new Dimension(fitWidth, fitHeight);

      if (DEBUG.IMAGE && DEBUG.META) out("paintIcon; into " + GUI.name(maxImageSize));
    }

    double zoomFit;
    if (mImage == NoImage && expandToFit) {
      zoomFit = 1;
    } else {
      Rectangle2D imageBounds;
      if (CropToSquare) {
        // square off image, then fit in icon (todo: better; crop to icon)
        int smallestAxis = mImageWidth > mImageHeight ? mImageHeight : mImageWidth;
        imageBounds = new Rectangle2D.Float(0, 0, smallestAxis, smallestAxis);
      } else {
        // fit entire image in icon
        imageBounds = new Rectangle2D.Float(0, 0, mImageWidth, mImageHeight);
      }
      zoomFit = ZoomTool.computeZoomFit(maxImageSize, 0, imageBounds, null, false);
      if (zoomFit > MaxZoom) zoomFit = MaxZoom;
    }

    final int drawW = (int) (mImageWidth * zoomFit + 0.5);
    final int drawH = (int) (mImageHeight * zoomFit + 0.5);

    int xoff = x;
    int yoff = y;

    // center if drawable area is bigger than image
    if (drawW != fitWidth) xoff += (fitWidth - drawW) / 2;
    if (drawH != fitHeight) yoff += (fitHeight - drawH) / 2;

    Shape oldClip = null;
    if (CropToSquare && !expandToFit) {
      oldClip = g.getClip();
      g.clipRect(x, y, mWidth, mHeight);
    }

    if (DEBUG.IMAGE && DEBUG.META)
      out("paintIcon; " + Util.tag(mImage) + " as " + drawW + "x" + drawH);
    g.drawImage(mImage, xoff, yoff, drawW, drawH, null);

    if (DEBUG.BOXES) {
      g.setColor(Color.green);
      ((Graphics2D) g)
          .setComposite(
              java.awt.AlphaComposite.getInstance(java.awt.AlphaComposite.SRC_OVER, 0.2f));
      g.drawRect(x, y, mWidth - 1, mHeight - 1);
      ((Graphics2D) g).setComposite(java.awt.AlphaComposite.SrcOver);
    }

    if (CropToSquare && !expandToFit) g.setClip(oldClip);
  }
コード例 #3
0
ファイル: FieldView.java プロジェクト: CodeingBoy/Java8CN
 /**
  * Renders using the given rendering surface and area on that surface. The view may need to do
  * layout and create child views to enable itself to render into the given allocation.
  *
  * @param g the rendering surface to use
  * @param a the allocated region to render into
  * @see View#paint
  */
 public void paint(Graphics g, Shape a) {
   Rectangle r = (Rectangle) a;
   g.clipRect(r.x, r.y, r.width, r.height);
   super.paint(g, a);
 }
コード例 #4
0
 public final void paint(final Graphics g) {
   final Rectangle bounds = getBounds();
   if (myAnchor == ToolWindowAnchor.LEFT) {
     if (myDirection == 1) {
       g.setClip(null);
       g.clipRect(myOffset, 0, bounds.width - myOffset, bounds.height);
       UIUtil.drawImage(g, myBottomImage, 0, 0, null);
       g.setClip(null);
       g.clipRect(0, 0, myOffset, bounds.height);
       UIUtil.drawImage(g, myTopImage, myOffset - bounds.width, 0, null);
     } else {
       g.setClip(null);
       g.clipRect(bounds.width - myOffset, 0, myOffset, bounds.height);
       UIUtil.drawImage(g, myBottomImage, 0, 0, null);
       g.setClip(null);
       g.clipRect(0, 0, bounds.width - myOffset, bounds.height);
       UIUtil.drawImage(g, myTopImage, -myOffset, 0, null);
     }
     myTopImage.flush();
   } else if (myAnchor == ToolWindowAnchor.RIGHT) {
     if (myDirection == 1) {
       g.setClip(null);
       g.clipRect(0, 0, bounds.width - myOffset, bounds.height);
       UIUtil.drawImage(g, myBottomImage, 0, 0, null);
       g.setClip(null);
       g.clipRect(bounds.width - myOffset, 0, myOffset, bounds.height);
       UIUtil.drawImage(g, myTopImage, bounds.width - myOffset, 0, null);
     } else {
       g.setClip(null);
       g.clipRect(0, 0, myOffset, bounds.height);
       UIUtil.drawImage(g, myBottomImage, 0, 0, null);
       g.setClip(null);
       g.clipRect(myOffset, 0, bounds.width - myOffset, bounds.height);
       UIUtil.drawImage(g, myTopImage, myOffset, 0, null);
     }
   } else if (myAnchor == ToolWindowAnchor.TOP) {
     if (myDirection == 1) {
       g.setClip(null);
       g.clipRect(0, myOffset, bounds.width, bounds.height - myOffset);
       UIUtil.drawImage(g, myBottomImage, 0, 0, null);
       g.setClip(null);
       g.clipRect(0, 0, bounds.width, myOffset);
       UIUtil.drawImage(g, myTopImage, 0, -bounds.height + myOffset, null);
     } else {
       g.setClip(null);
       g.clipRect(0, bounds.height - myOffset, bounds.width, myOffset);
       UIUtil.drawImage(g, myBottomImage, 0, 0, null);
       g.setClip(null);
       g.clipRect(0, 0, bounds.width, bounds.height - myOffset);
       UIUtil.drawImage(g, myTopImage, 0, -myOffset, null);
     }
   } else if (myAnchor == ToolWindowAnchor.BOTTOM) {
     if (myDirection == 1) {
       g.setClip(null);
       g.clipRect(0, 0, bounds.width, bounds.height - myOffset);
       UIUtil.drawImage(g, myBottomImage, 0, 0, null);
       g.setClip(null);
       g.clipRect(0, bounds.height - myOffset, bounds.width, myOffset);
       UIUtil.drawImage(g, myTopImage, 0, bounds.height - myOffset, null);
     } else {
       g.setClip(null);
       g.clipRect(0, 0, bounds.width, myOffset);
       UIUtil.drawImage(g, myBottomImage, 0, 0, null);
       g.setClip(null);
       g.clipRect(0, myOffset, bounds.width, bounds.height - myOffset);
       UIUtil.drawImage(g, myTopImage, 0, myOffset, null);
     }
   }
 }
コード例 #5
0
 public void paintIcon(Component c, Graphics g, int x, int y) {
   Shape old = g.getClip();
   g.clipRect(x, y + myDelegate.getIconHeight() - 2 - myHeight, myWidth, myHeight + 2);
   myDelegate.paintIcon(c, g, x, y);
   g.setClip(old);
 }