Java Code Examples for java.awt.Graphics2D.fill3DRect()

The following are Jave code examples for showing how to use fill3DRect() of the java.awt.Graphics2D class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: VASSAL-src   File: GamePieceLayout.java   View Source Code Vote up 4 votes
public Image buildImage(GamePieceImage defn) {
  // Create our base image
  final BufferedImage image = ImageUtils.createCompatibleTranslucentImage(
    Math.max(width,1),
    Math.max(height,1)
  );
  final Graphics2D g = image.createGraphics();

  // Fill in the sample Background color
  Color bgColor = defn.getBgColor().getColor();
  g.setColor(bgColor);

  if (getBorder().equals(BORDER_3D)) {
    if (bgColor != null) g.fill3DRect(0, 0, width, height, true);
  }
  else {
    if (bgColor != null) g.fillRect(0, 0, width, height);

    // Add Border
    if (getBorder().equals(BORDER_PLAIN) || getBorder().equals(BORDER_FANCY)) {
      Color bg = bgColor == null ? Color.WHITE : bgColor;
      g.setColor(defn.getBorderColor().getColor());
      g.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
      g.drawRect(0, 0, width - 1, height - 1);
      if (getBorder().equals(BORDER_FANCY)) {
        Color lt = new Color(bg.getRed()   / 2,
                             bg.getGreen() / 2,
                             bg.getBlue()  / 2);
        Color dk = new Color(bg.getRed()   + (255 - bg.getRed())   / 2,
                             bg.getGreen() + (255 - bg.getGreen()) / 2,
                             bg.getBlue()  + (255 - bg.getBlue())  / 2);
        g.setColor(dk);
        g.drawLine(1, 1, width - 3, 1);
        g.drawLine(1, 2, 1, height - 3);
        g.setColor(lt);
        g.drawLine(width - 2, 2, width - 2, height - 2);
        g.drawLine(2, height - 2, width - 3, height - 2);
      }
    }
  }

  // layer each item over the top
  for (Item item : items) {
    if (item != null) {
      item.draw(g, defn);
    }
  }

  g.dispose();

  return image;
}
 
Example 2
Project: BrainControl   File: MotivationsOverlay.java   View Source Code Vote up 2 votes
/**
 * Called from another thread, must be synchronized 
 */
@Override
public synchronized void drawOverlay(Graphics g, LevelScene levelScene, int playerIndex) {
	
	if(reservoirBars == null) {
		return;
	}
	if(agent != null && agent.getPlayerIndex() != GlobalOptions.playerGameWorldToDisplay) {
		return;
	}
	

	Image[] motivations= calculateImages();
	
	int imageSize = imageMaximumSize;
	int padding = 3;
	
	
	int boxWidth = (imageSize * motivations.length ) + (padding *  motivations.length );
	int boxHeight = (imageSize)+padding*2;
	
	int yTopleftCorner = GlobalOptions.yScreen -(boxHeight+1);
	int xTopleftCorner = 0;		
	

	
	Graphics2D g2d =(Graphics2D) g;

	
	
	
	g2d.setColor(new Color(255, 255, 255, 200));
	
	g2d.fill3DRect(xTopleftCorner,yTopleftCorner , boxWidth, boxHeight, true);
	g2d.setColor(Color.GRAY);
	g2d.draw3DRect(xTopleftCorner+1,yTopleftCorner+1 , boxWidth-1, boxHeight-1, true);
	

	g2d.setColor(null);
	for(int i = 0; i<motivations.length; i++) {
		
		int xOffset = (xTopleftCorner+ i*imageSize) +(  (boxWidth - (motivations.length*imageSize)) / motivations.length );
		int yOffset = (yTopleftCorner + ((boxHeight-motivations[i].getHeight(null))/2));
		g2d.drawImage(motivations[i], xOffset, yOffset, null);
	}
	
	

}