From: H.G. Muller Date: Fri, 21 Feb 2014 10:10:41 +0000 (+0100) Subject: Preserve window width on board-format change X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=562bc6ef0a03544438acade21408653cfd1c4075;p=xboard.git Preserve window width on board-format change 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. --- diff --git a/draw.c b/draw.c index f89468d..badd12b 100644 --- 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; diff --git a/gtk/xboard.c b/gtk/xboard.c index 60cbe0a..23e8951 100644 --- a/gtk/xboard.c +++ b/gtk/xboard.c @@ -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--; diff --git a/xaw/xboard.c b/xaw/xboard.c index d6a9dae..8d0fb24 100644 --- a/xaw/xboard.c +++ b/xaw/xboard.c @@ -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--;