Preserve window width on board-format change
authorH.G. Muller <h.g.muller@hccnet.nl>
Fri, 21 Feb 2014 10:10:41 +0000 (11:10 +0100)
committerH.G. Muller <h.g.muller@hccnet.nl>
Sun, 2 Mar 2014 18:04:47 +0000 (19:04 +0100)
When a variant switch would cause recalculation of the board window,
we now first recalculate square size to keep the window width fixed.
Also adapt initial width on high boards.

draw.c
gtk/xboard.c
xaw/xboard.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;
 
index 60cbe0a..23e8951 100644 (file)
@@ -924,6 +924,8 @@ main (int argc, char **argv)
                    programName, appData.boardSize);
            exit(2);
        }
+       if(BOARD_WIDTH > 8)
+           squareSize = (squareSize*8 + BOARD_WIDTH/2)/BOARD_WIDTH; // scale height
        if (i < 7) {
            /* Find some defaults; use the nearest known size */
            SizeDefaults *szd, *nearest;
@@ -947,11 +949,11 @@ main (int argc, char **argv)
     } else {
         SizeDefaults *szd = sizeDefaults;
         if (*appData.boardSize == NULLCHAR) {
-            GdkScreen *screen = gtk_window_get_screen(GTK_WINDOW(mainwindow));
+            GdkScreen *screen = gtk_window_get_screen(GTK_WINDOW(mainwindow)); // TODO: this does not work, as no mainwindow yet
             guint screenwidth = gdk_screen_get_width(screen);
             guint screenheight = gdk_screen_get_height(screen);
-           while (screenwidth < szd->minScreenSize ||
-                  screenheight < szd->minScreenSize) {
+           while (screenwidth  < (szd->minScreenSize*BOARD_WIDTH  + 4)/8 ||
+                  screenheight < (szd->minScreenSize*BOARD_HEIGHT + 4)/8) {
              szd++;
            }
            if (szd->name == NULL) szd--;
index d6a9dae..8d0fb24 100644 (file)
@@ -1115,6 +1115,8 @@ main (int argc, char **argv)
                    programName, appData.boardSize);
            exit(2);
        }
+       if(BOARD_WIDTH > 8)
+           squareSize = (squareSize*8 + BOARD_WIDTH/2)/BOARD_WIDTH; // scale height
        if (i < 7) {
            /* Find some defaults; use the nearest known size */
            SizeDefaults *szd, *nearest;
@@ -1138,8 +1140,8 @@ main (int argc, char **argv)
     } else {
         SizeDefaults *szd = sizeDefaults;
         if (*appData.boardSize == NULLCHAR) {
-           while (DisplayWidth(xDisplay, xScreen) < szd->minScreenSize ||
-                  DisplayHeight(xDisplay, xScreen) < szd->minScreenSize) {
+           while (DisplayWidth(xDisplay, xScreen)  < (szd->minScreenSize*BOARD_WIDTH  + 4)/8 ||
+                  DisplayHeight(xDisplay, xScreen) < (szd->minScreenSize*BOARD_HEIGHT + 4)/8) {
              szd++;
            }
            if (szd->name == NULL) szd--;