2 * Copyright (c) 2018-2019. Developed by Hedgecode.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.hedgecode.chess.img.board;
19 import java.awt.Graphics;
20 import java.awt.image.BufferedImage;
22 import org.hedgecode.chess.position.Square;
27 * @author Dmitry Samoshin aka gotty
31 private SquarePair<BufferedImage> squares;
32 private int squareSize;
34 Board(SquarePair<BufferedImage> squares) {
35 this.squares = squares;
36 int width = Math.max(squares.getDark().getWidth(), squares.getLight().getWidth());
37 int height = Math.max(squares.getDark().getHeight(), squares.getLight().getHeight());
38 this.squareSize = Math.max(width, height);
41 public int squareSize() {
45 public int boardSize() {
46 return squareSize * Square.getSize();
49 public BufferedImage render() {
50 BufferedImage board = new BufferedImage(
51 squareSize * Square.getSize(),
52 squareSize * Square.getSize(),
53 BufferedImage.TYPE_INT_ARGB
55 Graphics boardGraphics = board.getGraphics();
56 for (int y = 0; y < Square.getSize(); ++y) {
57 for (int x = 0; x < Square.getSize(); ++x) {
58 boardGraphics.drawImage(
71 public static Board create(SquarePair<BufferedImage> squares) {
72 return new Board(squares);