Preserve window width on board-format change
[xboard.git] / draw.c
diff --git a/draw.c b/draw.c
index f89468d..badd12b 100644 (file)
--- a/draw.c
+++ b/draw.c
@@ -175,10 +175,18 @@ InitDrawingSizes (BoardSize boardSize, int flags)
     int boardWidth, boardHeight;
     static int oldWidth, oldHeight;
     static VariantClass oldVariant;
-    static int oldTwoBoards = 0;
+    static int oldTwoBoards = 0, oldNrOfFiles = 0;
 
     if(!mainOptions[W_BOARD].handle) return;
 
+    if(boardSize == -2 && gameInfo.variant != oldVariant
+                       && oldNrOfFiles && oldNrOfFiles != BOARD_WIDTH) { // called because variant switch changed board format
+       squareSize = ((squareSize + lineGap) * oldNrOfFiles + 0.5*BOARD_WIDTH) / BOARD_WIDTH - lineGap; // keep total width fixed
+       CreatePNGPieces();
+        CreateGrid();
+    }
+    oldNrOfFiles = BOARD_WIDTH;
+
     if(oldTwoBoards && !twoBoards) PopDown(DummyDlg);
     oldTwoBoards = twoBoards;