Save font settings based on initial square size
[xboard.git] / gtk / xboard.c
index c6df31a..a7b10ca 100644 (file)
@@ -63,7 +63,6 @@
 #include <pwd.h>
 #include <math.h>
 #include <cairo/cairo.h>
-#include <cairo/cairo-xlib.h>
 #include <gtk/gtk.h>
 
 #if !OMIT_SOCKETS
@@ -176,15 +175,12 @@ extern char *getenv();
 #  define IMG ".png"
    // redefine some defaults
 #  undef ICS_LOGON
-#  undef DATADIR
 #  undef LOCALEDIR
 #  undef SETTINGS_FILE
 #  define ICS_LOGON "Library/Preferences/XboardICS.conf"
-#  define DATADIR dataDir
 #  define LOCALEDIR localeDir
 #  define SETTINGS_FILE masterSettings
 #  define SYNC_MENUBAR gtkosx_application_sync_menubar(theApp)
-   char dataDir[MSG_SIZ]; // for expanding ~~
    char localeDir[MSG_SIZ];
    char masterSettings[MSG_SIZ];
 #else
@@ -213,11 +209,13 @@ RETSIGTYPE CmailSigHandler P((int sig));
 RETSIGTYPE IntSigHandler P((int sig));
 RETSIGTYPE TermSizeSigHandler P((int sig));
 char *InsertPxlSize P((char *pattern, int targetPxlSize));
+#ifdef TODO_GTK
 #if ENABLE_NLS
 XFontSet CreateFontSet P((char *base_fnt_lst));
 #else
 char *FindFont P((char *pattern, int targetPxlSize));
 #endif
+#endif
 void DelayedDrag P((void));
 void ICSInputBoxPopUp P((void));
 void MoveTypeInProc P((GdkEventKey *eventkey));
@@ -258,6 +256,7 @@ GtkAccelGroup *GtkAccelerators;
 typedef unsigned int BoardSize;
 BoardSize boardSize;
 Boolean chessProgram;
+static int initialSquareSize;
 
 int  minX, minY; // [HGM] placement: volatile limits on upper-left corner
 int smallLayout = 0, tinyLayout = 0,
@@ -518,9 +517,9 @@ SaveFontArg (FILE *f, ArgDescriptor *ad)
       return;
   }
   for(i=0; i<NUM_SIZES; i++) // [HGM] font: current font becomes standard for current size
-    if(sizeDefaults[i].squareSize == squareSize) { // only for standard sizes!
-       fontTable[n][squareSize] = strdup(name);
-       fontValid[n][squareSize] = True;
+    if(sizeDefaults[i].squareSize == initialSquareSize) { // only for standard sizes!
+       fontTable[n][initialSquareSize] = strdup(name);
+       fontValid[n][initialSquareSize] = True;
        break;
   }
   for(i=0; i<MAX_SIZE; i++) if(fontValid[n][i]) // [HGM] font: store all standard fonts
@@ -891,6 +890,7 @@ main (int argc, char **argv)
         theApp = g_object_new(GTKOSX_TYPE_APPLICATION, NULL);
         snprintf(masterSettings, MSG_SIZ, "%s/Contents/Resources/etc/xboard.conf", path);
         snprintf(dataDir, MSG_SIZ, "%s/Contents/Resources/share/xboard", path);
+        snprintf(manDir, MSG_SIZ, "%s/Contents/Resources/share/man", path);
         snprintf(svgDir, MSG_SIZ, "%s/themes/default", dataDir);
         g_signal_connect(theApp, "NSApplicationOpenFile", G_CALLBACK(StartNewXBoard), NULL);
         g_signal_connect(theApp, "NSApplicationWillTerminate", G_CALLBACK(ExitEvent), NULL);
@@ -914,7 +914,8 @@ main (int argc, char **argv)
     if(argc > 1 && !strcmp(argv[1], "--show-config")) { // [HGM] install: called to print config info
        typedef struct {char *name, *value; } Config;
        static Config configList[] = {
-         { "Datadir", DATADIR },
+         { "Datadir", dataDir },
+         { "Mandir", manDir },
          { "Sysconfdir", SYSCONFDIR },
          { NULL }
        };
@@ -959,7 +960,7 @@ main (int argc, char **argv)
 
     { // [HGM] initstring: kludge to fix bad bug. expand '\n' characters in init string and computer string.
        static char buf[MSG_SIZ];
-       snprintf(buf, MSG_SIZ, appData.sysOpen, DATADIR);
+       snprintf(buf, MSG_SIZ, appData.sysOpen, dataDir);
        ASSIGN(appData.sysOpen, buf); // expand %s in -openCommand to DATADIR (usefull for OS X configuring)
        EscapeExpand(buf, appData.firstInitString);
        appData.firstInitString = strdup(buf);
@@ -1022,8 +1023,6 @@ 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;
@@ -1075,6 +1074,11 @@ main (int argc, char **argv)
        tinyLayout = szd->tinyLayout;
        // [HGM] font: use defaults from settings file if available and not overruled
     }
+    initialSquareSize = squareSize; // [HGM] remember for saving font info
+    if(BOARD_WIDTH != 8) {
+       squareSize = (squareSize*8 + BOARD_WIDTH/2)/BOARD_WIDTH; // keep width the same
+       lineGap = (squareSize < 37 ? 1 : squareSize < 59 ? 2 : squareSize < 116 ? 3 : 4);
+    }
 
     defaultLineGap = lineGap;
     if(appData.overrideLineGap >= 0) lineGap = appData.overrideLineGap;
@@ -1136,7 +1140,7 @@ main (int argc, char **argv)
     boardWidget      = optList[W_BOARD].handle;
     menuBarWidget    = optList[W_MENU].handle;
     dropMenu         = optList[W_DROP].handle;
-    titleWidget = optList[optList[W_TITLE].type != -1 ? W_TITLE : W_SMALL].handle;
+    titleWidget = optList[optList[W_TITLE].type != Skip ? W_TITLE : W_SMALL].handle;
 #ifdef TODO_GTK
     formWidget  = XtParent(boardWidget);
     XtSetArg(args[0], XtNbackground, &timerBackgroundPixel);
@@ -1695,6 +1699,12 @@ ReSize (WindowPlacement *wp)
        if(optList[W_BOARD].max   > w) optList[W_BOARD].max = w;
        if(optList[W_BOARD].value > h) optList[W_BOARD].value = h;
        first = appData.fixedSize;
+       if(twoBoards && shellUp[DummyDlg]) {
+           SlavePopUp(); dualOptions[3].max = 0; DoEvents(); // calls SlaveResize, kludge to force assigning new canvas
+           partnerUp = !partnerUp; flipView = !flipView;
+           DrawPosition(True, NULL);
+           partnerUp = !partnerUp; flipView = !flipView;
+       }
 }
 
 static guint delayedDragTag = 0;
@@ -1775,7 +1785,7 @@ void
 ModeHighlight ()
 {
     static int oldPausing = FALSE;
-    static GameMode oldmode = (GameMode) -1;
+    static GameMode oldMode = (GameMode) -1;
     char *wname;
     if (!boardWidget) return;
 
@@ -1793,7 +1803,7 @@ ModeHighlight ()
        }
     }
 
-    wname = ModeToWidgetName(oldmode);
+    wname = ModeToWidgetName(oldMode);
     if (wname != NULL) {
        MarkMenuItem(wname, False);
     }
@@ -1801,8 +1811,9 @@ ModeHighlight ()
     if (wname != NULL) {
        MarkMenuItem(wname, True);
     }
-    oldmode = gameMode;
+    if(oldMode == TwoMachinesPlay) EnableNamedMenuItem("Mode.MachineMatch", True);
     MarkMenuItem("Mode.MachineMatch", matchMode && matchGame < appData.matchGames);
+    oldMode = gameMode;
 
     /* Maybe all the enables should be handled here, not just this one */
     EnableNamedMenuItem("Mode.Training", gameMode == Training || gameMode == PlayFromGameFile);
@@ -1883,7 +1894,7 @@ PasteGameProc ()
 {
     gchar *text=NULL;
     GtkClipboard *cb;
-    guint len=0;
+    guint len=0; int flip = appData.flipView;
     FILE* f;
 
     // get game from clipboard
@@ -1907,7 +1918,9 @@ PasteGameProc ()
     fclose(f);
 
     // load from file
+    if(!appData.autoFlipView) appData.flipView = flipView;
     LoadGameFromFile(gamePasteFilename, 0, gamePasteFilename, TRUE);
+    appData.flipView = flip;
     return;
 }