diff options
Diffstat (limited to 'src/jrummikub/view/impl/Board.java')
-rw-r--r-- | src/jrummikub/view/impl/Board.java | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/src/jrummikub/view/impl/Board.java b/src/jrummikub/view/impl/Board.java index 0e41984..2d51cb2 100644 --- a/src/jrummikub/view/impl/Board.java +++ b/src/jrummikub/view/impl/Board.java @@ -5,6 +5,7 @@ import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Insets; import java.awt.RenderingHints; +import java.awt.image.BufferedImage; import java.util.Collection; import java.util.Collections; import java.util.Map; @@ -17,34 +18,53 @@ import jrummikub.view.IBoard; @SuppressWarnings("serial") public class Board extends StonePanel implements IBoard { - private final static ImageIcon BACKGROUND = new ImageIcon(Board.class.getResource("/jrummikub/resource/wood.png")); - private final static float DEFAULT_SCALE = StonePainter.BOARD_SCALE; - + private final static BufferedImage BACKGROUND; + static { + ImageIcon image = new ImageIcon( + Board.class.getResource("/jrummikub/resource/wood.png")); + BACKGROUND = new BufferedImage(image.getIconWidth(), image.getIconHeight(), + BufferedImage.TYPE_INT_RGB); + + image.paintIcon(null, BACKGROUND.createGraphics(), 0, 0); + } + private Map<Stone, Position> stones = Collections.emptyMap(); private Collection<Stone> selectedStones = Collections.emptyList(); Board() { - super(DEFAULT_SCALE); - setBorder(new CustomBorder(Color.DARK_GRAY, 0, 1, 0, 1)); } + private BufferedImage getScaledBackground(int size) { + BufferedImage scaled = new BufferedImage(size, size, BufferedImage.TYPE_INT_RGB); + Graphics2D g = scaled.createGraphics(); + g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); + + g.drawImage(BACKGROUND, 0, 0, size, size, null); + + return scaled; + } + @Override protected void paintComponent(Graphics g1) { Insets insets = getInsets(); int x = insets.left, y = insets.top, width = getWidth()-insets.left-insets.right, height = getHeight()-insets.top-insets.bottom; Graphics2D g = (Graphics2D)g1.create(x, y, width, height); + int size = height/2; + BufferedImage scaledBackground = getScaledBackground(size); - for(int xpos = 0; xpos < width; xpos += BACKGROUND.getIconWidth()) { - BACKGROUND.paintIcon(this, g, xpos, 0); + for(int xpos = 0; xpos < width; xpos += size) { + g.drawImage(scaledBackground, xpos, 0, null); } - for(int xpos = -32; xpos < width; xpos += BACKGROUND.getIconWidth()) { - BACKGROUND.paintIcon(this, g, xpos, 75); + for(int xpos = -size/3; xpos < width; xpos += size) { + g.drawImage(scaledBackground, xpos, size, null); } g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - + + getStonePainter().setScale(size*StonePainter.PIXEL_SCALE); + for (Map.Entry<Stone, Position> entry : stones.entrySet()) { getStonePainter().paintStone(g, entry.getKey(), entry.getValue(), selectedStones.contains(entry.getKey())); |