summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/view/impl/Board.java
blob: 1d7cc1a5db2121fa4ae8600a900b09498e35571a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package jrummikub.view.impl;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Insets;

import javax.swing.ImageIcon;
import javax.swing.JPanel;

import jrummikub.model.Stone;
import jrummikub.model.StoneColor;
import jrummikub.view.IBoard;

@SuppressWarnings("serial")
public class Board extends JPanel implements IBoard {
  private final static ImageIcon background = new ImageIcon(Board.class.getResource("/jrummikub/resource/wood.png"));

  Board() {
    super(true);
    
    setBorder(new CustomBorder(Color.DARK_GRAY, 0, 1, 0, 1));
  }
  
  @Override
  protected void paintComponent(Graphics g) {
    Insets insets = getInsets();
    int x = insets.left, y = insets.top, width = getWidth()-insets.left-insets.right, height = getHeight()-insets.top-insets.bottom;
    g = g.create(x, y, width, height);
    
    for(int xpos = 0; xpos < width; xpos += background.getIconWidth()) {
      background.paintIcon(this, g, xpos, 0);
    }
    for(int xpos = -32; xpos < width; xpos += background.getIconWidth()) {
      background.paintIcon(this, g, xpos, 75);
    }
    
    // TODO Rest of painting code
    
    // FIXME Test code
    StonePainter.paintStone(g, new Stone(1, StoneColor.ORANGE, false),
        0, 0, StonePainter.BOARD_SCALE);
    StonePainter.paintStone(g, new Stone(10, StoneColor.BLUE, false),
        1, 0, StonePainter.BOARD_SCALE);
    StonePainter.paintStone(g, new Stone(5, StoneColor.RED, false),
        0.5f, 1, StonePainter.BOARD_SCALE);
  }
}