diff options
Diffstat (limited to 'src/jrummikub')
-rw-r--r-- | src/jrummikub/resource/wood.png | bin | 17920 -> 22975 bytes | |||
-rw-r--r-- | src/jrummikub/view/impl/Board.java | 40 | ||||
-rw-r--r-- | src/jrummikub/view/impl/StonePainter.java | 2 | ||||
-rw-r--r-- | src/jrummikub/view/impl/StonePanel.java | 4 | ||||
-rw-r--r-- | src/jrummikub/view/impl/View.java | 2 |
5 files changed, 36 insertions, 12 deletions
diff --git a/src/jrummikub/resource/wood.png b/src/jrummikub/resource/wood.png Binary files differindex ed9cf14..4f87ca0 100644 --- a/src/jrummikub/resource/wood.png +++ b/src/jrummikub/resource/wood.png 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())); diff --git a/src/jrummikub/view/impl/StonePainter.java b/src/jrummikub/view/impl/StonePainter.java index d5bc752..9cda8f6 100644 --- a/src/jrummikub/view/impl/StonePainter.java +++ b/src/jrummikub/view/impl/StonePainter.java @@ -26,7 +26,7 @@ class StonePainter { private static final float BRIGHTER_SCALE = 1.15f; - public static final float BOARD_SCALE = 75.0f*ASPECT_RATIO/DEFAULT_WIDTH; + public static final float PIXEL_SCALE = ASPECT_RATIO/DEFAULT_WIDTH; private float scale; diff --git a/src/jrummikub/view/impl/StonePanel.java b/src/jrummikub/view/impl/StonePanel.java index 9bcffae..b47c354 100644 --- a/src/jrummikub/view/impl/StonePanel.java +++ b/src/jrummikub/view/impl/StonePanel.java @@ -22,6 +22,10 @@ abstract class StonePanel extends JPanel implements IClickable { return stonePainter; } + public StonePanel() { + this(1); + } + public StonePanel(float scale) { super(true); // Set double buffered diff --git a/src/jrummikub/view/impl/View.java b/src/jrummikub/view/impl/View.java index 4e38a56..31235c6 100644 --- a/src/jrummikub/view/impl/View.java +++ b/src/jrummikub/view/impl/View.java @@ -17,7 +17,7 @@ public class View extends JFrame implements IView { private Table table; private PlayerPanel playerPanel; - private final static int PLAYER_PANEL_HEIGHT = 150; + private final static int PLAYER_PANEL_HEIGHT = 140; public ITable getTable() { |