From d91e42849d1a2d012335db5c5294ed573ec6d4d3 Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Sun, 21 Oct 2012 14:49:45 +0200 Subject: [PATCH] Fix variant-dependent pieces The code to select the actually used piece images from the available ones (from InitDrawingSizes) is now made into a subroutine, and also called after resizing the pieces. --- draw.c | 54 +++++++++++++++++++++++++++++++----------------------- 1 files changed, 31 insertions(+), 23 deletions(-) diff --git a/draw.c b/draw.c index 82c5582..d90d0e9 100644 --- a/draw.c +++ b/draw.c @@ -134,6 +134,33 @@ SwitchWindow () csBoardWindow = DRAWABLE(currBoard); } +void +SelectPieces(VariantClass v) +{ + int i; + for(i=0; i<2; i++) { + int p; + for(p=0; p<=(int)WhiteKing; p++) + pngPieceBitmaps[i][p] = pngPieceBitmaps2[i][p]; // defaults + if(v == VariantShogi) { + pngPieceBitmaps[i][(int)WhiteCannon] = pngPieceBitmaps2[i][(int)WhiteKing+1]; + pngPieceBitmaps[i][(int)WhiteNightrider] = pngPieceBitmaps2[i][(int)WhiteKing+2]; + pngPieceBitmaps[i][(int)WhiteSilver] = pngPieceBitmaps2[i][(int)WhiteKing+3]; + pngPieceBitmaps[i][(int)WhiteGrasshopper] = pngPieceBitmaps2[i][(int)WhiteKing+4]; + pngPieceBitmaps[i][(int)WhiteQueen] = pngPieceBitmaps2[i][(int)WhiteLance]; + } +#ifdef GOTHIC + if(v == VariantGothic) { + pngPieceBitmaps[i][(int)WhiteMarshall] = pngPieceBitmaps2[i][(int)WhiteSilver]; + } +#endif + if(v == VariantSChess) { + pngPieceBitmaps[i][(int)WhiteAngel] = pngPieceBitmaps2[i][(int)WhiteFalcon]; + pngPieceBitmaps[i][(int)WhiteMarshall] = pngPieceBitmaps2[i][(int)WhiteAlfil]; + } + } +} + #define BoardSize int void InitDrawingSizes (BoardSize boardSize, int flags) @@ -172,27 +199,8 @@ InitDrawingSizes (BoardSize boardSize, int flags) if(gameInfo.variant != oldVariant) { // and only if variant changed - for(i=0; i<2; i++) { - int p; - for(p=0; p<=(int)WhiteKing; p++) - pngPieceBitmaps[i][p] = pngPieceBitmaps2[i][p]; // defaults - if(gameInfo.variant == VariantShogi) { - pngPieceBitmaps[i][(int)WhiteCannon] = pngPieceBitmaps2[i][(int)WhiteKing+1]; - pngPieceBitmaps[i][(int)WhiteNightrider] = pngPieceBitmaps2[i][(int)WhiteKing+2]; - pngPieceBitmaps[i][(int)WhiteSilver] = pngPieceBitmaps2[i][(int)WhiteKing+3]; - pngPieceBitmaps[i][(int)WhiteGrasshopper] = pngPieceBitmaps2[i][(int)WhiteKing+4]; - pngPieceBitmaps[i][(int)WhiteQueen] = pngPieceBitmaps2[i][(int)WhiteLance]; - } -#ifdef GOTHIC - if(gameInfo.variant == VariantGothic) { - pngPieceBitmaps[i][(int)WhiteMarshall] = pngPieceBitmaps2[i][(int)WhiteSilver]; - } -#endif - if(gameInfo.variant == VariantSChess) { - pngPieceBitmaps[i][(int)WhiteAngel] = pngPieceBitmaps2[i][(int)WhiteFalcon]; - pngPieceBitmaps[i][(int)WhiteMarshall] = pngPieceBitmaps2[i][(int)WhiteAlfil]; - } - } + SelectPieces(gameInfo.variant); + oldMono = -10; // kludge to force recreation of animation masks oldVariant = gameInfo.variant; } @@ -243,7 +251,7 @@ LoadSVG (char *dir, int color, int piece) snprintf(buf, MSG_SIZ, "%s/%s%s.svg", dir, color ? "Black" : "White", pngPieceNames[piece]); - if(svg || *dir && (svg = rsvg_handle_new_from_file(buf,svgerror))) { + if(svg || *dir && (svg = rsvg_handle_new_from_file(buf, svgerror))) { rsvg_handle_get_dimensions(svg, &svg_dimensions); img = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, squareSize, squareSize); @@ -301,7 +309,6 @@ ScaleOnePiece (int color, int piece) // create new bitmap to hold scaled piece image (and remove any old) if(pngPieceBitmaps2[color][piece]) cairo_surface_destroy (pngPieceBitmaps2[color][piece]); pngPieceBitmaps2[color][piece] = cs = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, squareSize, squareSize); - if(piece <= WhiteKing) pngPieceBitmaps[color][piece] = cs; if(!img) return; @@ -348,6 +355,7 @@ CreatePNGPieces () ScaleOnePiece(0, p); ScaleOnePiece(1, p); } + SelectPieces(gameInfo.variant); } void -- 1.7.0.4