1 /** 2 * Jin - a chess client for internet chess servers. 3 * More information is available at http://www.jinchess.com/. 4 * Copyright (C) 2002 Alexander Maryanovsky. 5 * All rights reserved. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 */ 21 22 package free.jin.board.icc; 23 24 import java.awt.Color; 25 import java.awt.Dimension; 26 import java.awt.Graphics; 27 import java.awt.Polygon; 28 29 import free.chess.PiecePainter; 30 import free.chess.VectorPiecePainter; 31 32 33 /** 34 * An implementation of PiecePainter which draws blitzin-like vector pieces. 35 * Note that the vector pieces belong exlusively to chessclub.com - you may use 36 * them only as part of Jin and only with the chessclub.com server. You may 37 * *not* use them for any other purpose, commercial or otherwise. 38 */ 39 40 public final class BlitzinVectorPiecePainter extends VectorPiecePainter{ 41 42 43 44 /** 45 * Creates a new BlitzinVectorPiecePainter. White pieces will have the 46 * white color and black pieces the black color. 47 */ 48 BlitzinVectorPiecePainter()49 public BlitzinVectorPiecePainter(){ 50 super(); 51 } 52 53 54 55 /** 56 * Creates a new BlitzinVectorPiecePainter which will produce 57 * White and black pieces with the given colors. The outline of the 58 * pieces will have the opposite RGB values from the RGB values of 59 * the given colors (if the color for the white pieces is for example 60 * R=255 G=128 B=0 then the outline of the white pieces will be 61 * R=0 G=127 B=255). 62 * 63 * @param whiteColor The color for the white pieces. 64 * @param blackColor The color for the black pieces. 65 */ 66 BlitzinVectorPiecePainter(Color whiteColor, Color blackColor)67 public BlitzinVectorPiecePainter(Color whiteColor, Color blackColor){ 68 super(whiteColor, blackColor); 69 } 70 71 72 73 /** 74 * Creates a new BlitzinVectorPiecePainter which will produce 75 * white and black pieces with the given colors and the given 76 * outline colors. 77 * 78 * @param whiteColor The color for the white pieces. 79 * @param blackColor The color for the black pieces. 80 * @param whiteOutline The color for the outline of white pieces. 81 * @param blackOutline The color for the outline of black pieces. 82 */ 83 BlitzinVectorPiecePainter(Color whiteColor, Color blackColor, Color whiteOutline, Color blackOutline)84 public BlitzinVectorPiecePainter(Color whiteColor, Color blackColor, 85 Color whiteOutline, Color blackOutline){ 86 super(whiteColor, blackColor, whiteOutline, blackOutline); 87 } 88 89 90 91 /** 92 * Returns a new <code>BlitzinVectorPiecePainter</code>. 93 */ 94 freshInstance()95 public PiecePainter freshInstance(){ 96 return new BlitzinVectorPiecePainter(); 97 } 98 99 100 101 /** 102 * Returns 36x36. 103 */ 104 getPreferredPieceSize()105 public Dimension getPreferredPieceSize(){ 106 return new Dimension(36,36); 107 } 108 109 110 111 /** 112 * Creates and returns a Polygon for drawing a king. 113 */ 114 createKingPolygon(int width, int height)115 protected Polygon createKingPolygon(int width, int height){ 116 Polygon kingPolygon = new Polygon(); 117 kingPolygon.addPoint(12*width/37,34*height/37); 118 kingPolygon.addPoint(25*width/37,34*height/37); 119 kingPolygon.addPoint(27*width/37,33*height/37); 120 kingPolygon.addPoint(29*width/37,23*height/37); 121 kingPolygon.addPoint(32*width/37,22*height/37); 122 kingPolygon.addPoint(34*width/37,20*height/37); 123 kingPolygon.addPoint(35*width/37,17*height/37); 124 kingPolygon.addPoint(35*width/37,16*height/37); 125 kingPolygon.addPoint(34*width/37,13*height/37); 126 kingPolygon.addPoint(32*width/37,11*height/37); 127 kingPolygon.addPoint(28*width/37,10*height/37); 128 kingPolygon.addPoint(24*width/37,12*height/37); 129 kingPolygon.addPoint(23*width/37,13*height/37); 130 kingPolygon.addPoint(22*width/37,13*height/37); 131 kingPolygon.addPoint(22*width/37,11*height/37); 132 kingPolygon.addPoint((int)(19.4*width/37),8*height/37); 133 kingPolygon.addPoint((int)(19.4*width/37),(int)(6.4*height/37)); 134 kingPolygon.addPoint(21*width/37,(int)(6.4*height/37)); 135 kingPolygon.addPoint(21*width/37,(int)(4.6*height/37)); 136 kingPolygon.addPoint((int)(19.4*width/37),(int)(4.6*height/37)); 137 kingPolygon.addPoint((int)(19.4*width/37),3*height/37); 138 kingPolygon.addPoint((int)(17.6*width/37),3*height/37); 139 kingPolygon.addPoint((int)(17.6*width/37),(int)(4.6*height/37)); 140 kingPolygon.addPoint(16*width/37,(int)(4.6*height/37)); 141 kingPolygon.addPoint(16*width/37,(int)(6.4*height/37)); 142 kingPolygon.addPoint((int)(17.6*width/37),(int)(6.4*height/37)); 143 kingPolygon.addPoint((int)(17.6*width/37),8*height/37); 144 kingPolygon.addPoint(15*width/37,11*height/37); 145 kingPolygon.addPoint(15*width/37,13*height/37); 146 kingPolygon.addPoint(14*width/37,13*height/37); 147 kingPolygon.addPoint(13*width/37,12*height/37); 148 kingPolygon.addPoint(9*width/37,10*height/37); 149 kingPolygon.addPoint(5*width/37,11*height/37); 150 kingPolygon.addPoint(3*width/37,13*height/37); 151 kingPolygon.addPoint(2*width/37,16*height/37); 152 kingPolygon.addPoint(2*width/37,17*height/37); 153 kingPolygon.addPoint(3*width/37,20*height/37); 154 kingPolygon.addPoint(5*width/37,22*height/37); 155 kingPolygon.addPoint(8*width/37,23*height/37); 156 kingPolygon.addPoint(10*width/37,33*height/37); 157 158 return kingPolygon; 159 } 160 161 162 163 164 /** 165 * Paints an image of a king of the given size with the given color and 166 * outline color using the given Graphics. 167 */ 168 drawKingImage(Graphics g, int width, int height, Color pieceColor, Color outlineColor)169 protected void drawKingImage(Graphics g, int width, int height, Color pieceColor, Color outlineColor){ 170 super.drawKingImage(g, width, height, pieceColor, outlineColor); 171 172 g.setColor(outlineColor); 173 g.drawLine(10*width/37,31*height/37,18*width/37,30*height/37); 174 g.drawLine(18*width/37,30*height/37,19*width/37,30*height/37); 175 g.drawLine(19*width/37,30*height/37,27*width/37,31*height/37); 176 g.drawLine(9*width/37,28*height/37,16*width/37,27*height/37); 177 g.drawLine(16*width/37,27*height/37,21*width/37,27*height/37); 178 g.drawLine(21*width/37,27*height/37,28*width/37,28*height/37); 179 g.drawLine(20*width/37,22*height/37,28*width/37,22*height/37); 180 g.drawLine(28*width/37,22*height/37,30*width/37,21*height/37); 181 g.drawLine(30*width/37,21*height/37,31*width/37,20*height/37); 182 g.drawLine(31*width/37,20*height/37,32*width/37,17*height/37); 183 g.drawLine(32*width/37,17*height/37,32*width/37,16*height/37); 184 g.drawLine(32*width/37,16*height/37,31*width/37,13*height/37); 185 g.drawLine(31*width/37,13*height/37,30*width/37,12*height/37); 186 g.drawLine(30*width/37,12*height/37,27*width/37,12*height/37); 187 g.drawLine(27*width/37,12*height/37,20*width/37,19*height/37); 188 g.drawLine(20*width/37,19*height/37,20*width/37,22*height/37); 189 g.drawLine(17*width/37,22*height/37,9*width/37,22*height/37); 190 g.drawLine(9*width/37,22*height/37,7*width/37,21*height/37); 191 g.drawLine(7*width/37,21*height/37,6*width/37,20*height/37); 192 g.drawLine(6*width/37,20*height/37,5*width/37,17*height/37); 193 g.drawLine(5*width/37,17*height/37,5*width/37,16*height/37); 194 g.drawLine(5*width/37,16*height/37,6*width/37,13*height/37); 195 g.drawLine(6*width/37,13*height/37,7*width/37,12*height/37); 196 g.drawLine(7*width/37,12*height/37,10*width/37,12*height/37); 197 g.drawLine(10*width/37,12*height/37,17*width/37,19*height/37); 198 g.drawLine(17*width/37,19*height/37,17*width/37,22*height/37); 199 g.drawLine(19*width/37,11*height/37,20*width/37,14*height/37); 200 g.drawLine(20*width/37,14*height/37,19*width/37,15*height/37); 201 g.drawLine(19*width/37,15*height/37,18*width/37,15*height/37); 202 g.drawLine(18*width/37,15*height/37,17*width/37,14*height/37); 203 g.drawLine(17*width/37,14*height/37,18*width/37,11*height/37); 204 g.drawLine(18*width/37,11*height/37,19*width/37,11*height/37); 205 } 206 207 208 209 210 211 /** 212 * Creates and returns a Polygon for drawing a queen. 213 */ 214 createQueenPolygon(int width, int height)215 protected Polygon createQueenPolygon(int width, int height){ 216 Polygon queenPolygon = new Polygon(); 217 218 queenPolygon.addPoint(8*width/37,34*height/37); 219 queenPolygon.addPoint(29*width/37,34*height/37); 220 queenPolygon.addPoint(29*width/37,27*height/37); 221 queenPolygon.addPoint(32*width/37,13*height/37); 222 queenPolygon.addPoint(33*width/37,11*height/37); 223 queenPolygon.addPoint(35*width/37,9*height/37); 224 queenPolygon.addPoint(35*width/37,7*height/37); 225 queenPolygon.addPoint(34*width/37,6*height/37); 226 queenPolygon.addPoint(31*width/37,6*height/37); 227 queenPolygon.addPoint(30*width/37,7*height/37); 228 queenPolygon.addPoint(30*width/37,10*height/37); 229 queenPolygon.addPoint(31*width/37,11*height/37); 230 queenPolygon.addPoint(26*width/37,19*height/37); 231 queenPolygon.addPoint(24*width/37,8*height/37); 232 queenPolygon.addPoint(26*width/37,6*height/37); 233 queenPolygon.addPoint(26*width/37,4*height/37); 234 queenPolygon.addPoint(25*width/37,3*height/37); 235 queenPolygon.addPoint(22*width/37,3*height/37); 236 queenPolygon.addPoint(21*width/37,4*height/37); 237 queenPolygon.addPoint(21*width/37,7*height/37); 238 queenPolygon.addPoint(22*width/37,8*height/37); 239 queenPolygon.addPoint(19*width/37,17*height/37); 240 queenPolygon.addPoint(18*width/37,17*height/37); 241 queenPolygon.addPoint(15*width/37,8*height/37); 242 queenPolygon.addPoint(16*width/37,7*height/37); 243 queenPolygon.addPoint(16*width/37,4*height/37); 244 queenPolygon.addPoint(15*width/37,3*height/37); 245 queenPolygon.addPoint(12*width/37,3*height/37); 246 queenPolygon.addPoint(11*width/37,4*height/37); 247 queenPolygon.addPoint(11*width/37,6*height/37); 248 queenPolygon.addPoint(13*width/37,8*height/37); 249 queenPolygon.addPoint(11*width/37,19*height/37); 250 queenPolygon.addPoint(6*width/37,11*height/37); 251 queenPolygon.addPoint(7*width/37,10*height/37); 252 queenPolygon.addPoint(7*width/37,7*height/37); 253 queenPolygon.addPoint(6*width/37,6*height/37); 254 queenPolygon.addPoint(3*width/37,6*height/37); 255 queenPolygon.addPoint(2*width/37,7*height/37); 256 queenPolygon.addPoint(2*width/37,9*height/37); 257 queenPolygon.addPoint(4*width/37,11*height/37); 258 queenPolygon.addPoint(5*width/37,13*height/37); 259 queenPolygon.addPoint(8*width/37,27*height/37); 260 261 return queenPolygon; 262 } 263 264 265 266 267 268 /** 269 * Paints an image of a queen of the given size with the given color and 270 * outline color using the given Graphics. 271 */ 272 drawQueenImage(Graphics g, int width, int height, Color pieceColor, Color outlineColor)273 protected void drawQueenImage(Graphics g, int width, int height, Color pieceColor, Color outlineColor){ 274 super.drawQueenImage(g, width, height, pieceColor, outlineColor); 275 276 g.setColor(outlineColor); 277 g.drawLine(29*width/37,31*height/37,24*width/37,30*height/37); 278 g.drawLine(24*width/37,30*height/37,13*width/37,30*height/37); 279 g.drawLine(13*width/37,30*height/37,8*width/37,31*height/37); 280 g.drawLine(8*width/37,26*height/37,13*width/37,25*height/37); 281 g.drawLine(13*width/37,25*height/37,24*width/37,25*height/37); 282 g.drawLine(24*width/37,25*height/37,29*width/37,26*height/37); 283 } 284 285 286 287 288 289 /** 290 * Creates and returns a Polygon for drawing a rook. 291 */ 292 createRookPolygon(int width, int height)293 protected Polygon createRookPolygon(int width, int height){ 294 Polygon rookPolygon = new Polygon(); 295 296 rookPolygon.addPoint(5*width/37,34*height/37); 297 rookPolygon.addPoint(32*width/37,34*height/37); 298 rookPolygon.addPoint(32*width/37,32*height/37); 299 rookPolygon.addPoint(26*width/37,27*height/37); 300 rookPolygon.addPoint(26*width/37,12*height/37); 301 rookPolygon.addPoint(30*width/37,8*height/37); 302 rookPolygon.addPoint(30*width/37,3*height/37); 303 rookPolygon.addPoint(25*width/37,3*height/37); 304 rookPolygon.addPoint(25*width/37,6*height/37); 305 rookPolygon.addPoint(21*width/37,6*height/37); 306 rookPolygon.addPoint(21*width/37,3*height/37); 307 rookPolygon.addPoint(16*width/37,3*height/37); 308 rookPolygon.addPoint(16*width/37,6*height/37); 309 rookPolygon.addPoint(12*width/37,6*height/37); 310 rookPolygon.addPoint(12*width/37,3*height/37); 311 rookPolygon.addPoint(7*width/37,3*height/37); 312 rookPolygon.addPoint(7*width/37,8*height/37); 313 rookPolygon.addPoint(11*width/37,12*height/37); 314 rookPolygon.addPoint(11*width/37,27*height/37); 315 rookPolygon.addPoint(5*width/37,32*height/37); 316 317 return rookPolygon; 318 } 319 320 321 /** 322 * Paints an image of a rook of the given size with the given color and 323 * outline color using the given Graphics. 324 */ 325 drawRookImage(Graphics g, int width, int height, Color pieceColor, Color outlineColor)326 protected void drawRookImage(Graphics g, int width, int height, Color pieceColor, Color outlineColor){ 327 super.drawRookImage(g, width, height, pieceColor, outlineColor); 328 329 g.setColor(outlineColor); 330 g.drawLine(26*width/37,27*height/37,11*width/37,27*height/37); 331 g.drawLine(26*width/37,12*height/37,11*width/37,12*height/37); 332 } 333 334 335 336 337 338 /** 339 * Creates and returns a Polygon for drawing a bishop. 340 */ 341 createBishopPolygon(int width, int height)342 protected Polygon createBishopPolygon(int width, int height){ 343 Polygon bishopPolygon = new Polygon(); 344 345 bishopPolygon.addPoint(3*width/37,34*height/37); 346 bishopPolygon.addPoint(34*width/37,34*height/37); 347 bishopPolygon.addPoint(33*width/37,31*height/37); 348 bishopPolygon.addPoint(24*width/37,31*height/37); 349 bishopPolygon.addPoint(26*width/37,18*height/37); 350 bishopPolygon.addPoint(26*width/37,15*height/37); 351 bishopPolygon.addPoint(25*width/37,12*height/37); 352 bishopPolygon.addPoint(20*width/37,7*height/37); 353 bishopPolygon.addPoint(21*width/37,5*height/37); 354 bishopPolygon.addPoint(20*width/37,3*height/37); 355 bishopPolygon.addPoint(17*width/37,3*height/37); 356 bishopPolygon.addPoint(16*width/37,5*height/37); 357 bishopPolygon.addPoint(17*width/37,7*height/37); 358 bishopPolygon.addPoint(12*width/37,12*height/37); 359 bishopPolygon.addPoint(11*width/37,15*height/37); 360 bishopPolygon.addPoint(11*width/37,18*height/37); 361 bishopPolygon.addPoint(13*width/37,31*height/37); 362 bishopPolygon.addPoint(4*width/37,31*height/37); 363 364 return bishopPolygon; 365 } 366 367 368 369 370 /** 371 * Paints an image of a bishop of the given size with the given color and 372 * outline color using the given Graphics. 373 */ 374 drawBishopImage(Graphics g, int width, int height, Color pieceColor, Color outlineColor)375 protected void drawBishopImage(Graphics g, int width, int height, Color pieceColor, Color outlineColor){ 376 super.drawBishopImage(g, width, height, pieceColor, outlineColor); 377 378 g.setColor(outlineColor); 379 g.drawLine(24*width/37,31*height/37,22*width/37,29*height/37); 380 g.drawLine(22*width/37,29*height/37,15*width/37,29*height/37); 381 g.drawLine(15*width/37,29*height/37,13*width/37,31*height/37); 382 g.drawLine(25*width/37,25*height/37,12*width/37,25*height/37); 383 g.drawLine(18*width/37,19*height/37,19*width/37,19*height/37); 384 g.drawLine(19*width/37,19*height/37,19*width/37,16*height/37); 385 g.drawLine(19*width/37,16*height/37,21*width/37,16*height/37); 386 g.drawLine(21*width/37,16*height/37,21*width/37,15*height/37); 387 g.drawLine(21*width/37,15*height/37,19*width/37,15*height/37); 388 g.drawLine(19*width/37,15*height/37,19*width/37,13*height/37); 389 g.drawLine(19*width/37,13*height/37,18*width/37,13*height/37); 390 g.drawLine(18*width/37,13*height/37,18*width/37,15*height/37); 391 g.drawLine(18*width/37,15*height/37,16*width/37,15*height/37); 392 g.drawLine(16*width/37,15*height/37,16*width/37,16*height/37); 393 g.drawLine(16*width/37,16*height/37,18*width/37,16*height/37); 394 g.drawLine(18*width/37,16*height/37,18*width/37,19*height/37); 395 } 396 397 398 399 400 401 402 /** 403 * Creates and returns a Polygon for drawing a knight. 404 */ 405 createKnightPolygon(int width, int height)406 protected Polygon createKnightPolygon(int width, int height){ 407 Polygon knightPolygon = new Polygon(); 408 409 knightPolygon.addPoint(10*width/37,34*height/37); 410 knightPolygon.addPoint(34*width/37,34*height/37); 411 knightPolygon.addPoint(34*width/37,26*height/37); 412 knightPolygon.addPoint(31*width/37,14*height/37); 413 knightPolygon.addPoint(26*width/37,9*height/37); 414 knightPolygon.addPoint(21*width/37,7*height/37); 415 knightPolygon.addPoint(18*width/37,3*height/37); 416 knightPolygon.addPoint(17*width/37,3*height/37); 417 knightPolygon.addPoint(18*width/37,7*height/37); 418 knightPolygon.addPoint(14*width/37,3*height/37); 419 knightPolygon.addPoint(13*width/37,3*height/37); 420 knightPolygon.addPoint(14*width/37,7*height/37); 421 knightPolygon.addPoint(12*width/37,6*height/37); 422 knightPolygon.addPoint(9*width/37,9*height/37); 423 knightPolygon.addPoint(2*width/37,23*height/37); 424 knightPolygon.addPoint(6*width/37,27*height/37); 425 knightPolygon.addPoint(10*width/37,23*height/37); 426 knightPolygon.addPoint((int)(7.4*width/37),27*height/37); 427 knightPolygon.addPoint(8*width/37,27*height/37); 428 knightPolygon.addPoint(17*width/37,20*height/37); 429 knightPolygon.addPoint(18*width/37,22*height/37); 430 knightPolygon.addPoint(10*width/37,31*height/37); 431 432 return knightPolygon; 433 } 434 435 436 437 438 439 /** 440 * Paints an image of a knight of the given size with the given color and 441 * outline color using the given Graphics. 442 */ 443 drawKnightImage(Graphics g, int width, int height, Color pieceColor, Color outlineColor)444 protected void drawKnightImage(Graphics g, int width, int height, Color pieceColor, Color outlineColor){ 445 super.drawKnightImage(g, width, height, pieceColor, outlineColor); 446 447 g.setColor(outlineColor); 448 g.drawLine(12*width/37,11*height/37,11*width/37,11*height/37); 449 g.drawLine(11*width/37,11*height/37,10*width/37,12*height/37); 450 g.drawLine(10*width/37,12*height/37,9*width/37,14*height/37); 451 g.drawLine(9*width/37,14*height/37,11*width/37,13*height/37); 452 g.drawLine(11*width/37,13*height/37,12*width/37,12*height/37); 453 g.drawLine(12*width/37,12*height/37,12*width/37,11*height/37); 454 g.drawLine(21*width/37,10*height/37,27*width/37,15*height/37); 455 g.drawLine(27*width/37,15*height/37,30*width/37,32*height/37); 456 g.drawLine(30*width/37,32*height/37,32*width/37,32*height/37); 457 g.drawLine(32*width/37,32*height/37,28*width/37,15*height/37); 458 g.drawLine(28*width/37,15*height/37,22*width/37,10*height/37); 459 g.drawLine(22*width/37,10*height/37,21*width/37,10*height/37); 460 g.drawLine(5*width/37,20*height/37,4*width/37,23*height/37); 461 g.drawLine(4*width/37,23*height/37,5*width/37,24*height/37); 462 g.drawLine(5*width/37,24*height/37,6*width/37,21*height/37); 463 g.drawLine(6*width/37,21*height/37,5*width/37,20*height/37); 464 } 465 466 467 468 469 470 /** 471 * Creates and returns a Polygon for drawing a pawn. 472 */ 473 createPawnPolygon(int width, int height)474 protected Polygon createPawnPolygon(int width, int height){ 475 Polygon pawnPolygon = new Polygon(); 476 477 pawnPolygon.addPoint(6*width/37,31*height/37); 478 pawnPolygon.addPoint(31*width/37,31*height/37); 479 pawnPolygon.addPoint(31*width/37,27*height/37); 480 pawnPolygon.addPoint(28*width/37,23*height/37); 481 pawnPolygon.addPoint(22*width/37,19*height/37); 482 pawnPolygon.addPoint(25*width/37,17*height/37); 483 pawnPolygon.addPoint(25*width/37,13*height/37); 484 pawnPolygon.addPoint(23*width/37,11*height/37); 485 pawnPolygon.addPoint(21*width/37,11*height/37); 486 pawnPolygon.addPoint(23*width/37,9*height/37); 487 pawnPolygon.addPoint(23*width/37,6*height/37); 488 pawnPolygon.addPoint(21*width/37,4*height/37); 489 pawnPolygon.addPoint(16*width/37,4*height/37); 490 pawnPolygon.addPoint(14*width/37,6*height/37); 491 pawnPolygon.addPoint(14*width/37,9*height/37); 492 pawnPolygon.addPoint(16*width/37,11*height/37); 493 pawnPolygon.addPoint(14*width/37,11*height/37); 494 pawnPolygon.addPoint(12*width/37,13*height/37); 495 pawnPolygon.addPoint(12*width/37,17*height/37); 496 pawnPolygon.addPoint(15*width/37,19*height/37); 497 pawnPolygon.addPoint(9*width/37,23*height/37); 498 pawnPolygon.addPoint(6*width/37,27*height/37); 499 500 return pawnPolygon; 501 } 502 503 } 504