From 51d2fca3f8d1d539b75c21ef49c84dd1d85b32e6 Mon Sep 17 00:00:00 2001 From: H.G.Muller Date: Fri, 1 Apr 2016 00:46:37 +0200 Subject: [PATCH] Add Fonts dialog A dialog is added to set the various window fonts, either by typing or by operating buttons for Bold, Italic, or adjusting the point size. --- dialogs.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gtk/xoptions.c | 17 ++++++++ menus.c | 1 + menus.h | 1 + ngamelist.c | 2 +- 5 files changed, 132 insertions(+), 1 deletions(-) diff --git a/dialogs.c b/dialogs.c index 19b69af..6239e6b 100644 --- a/dialogs.c +++ b/dialogs.c @@ -1620,6 +1620,118 @@ ShuffleMenuProc () GenericPopUp(shuffleOptions, _("New Shuffle Game"), TransientDlg, BoardWindow, MODAL, 0); } +//--------------------------------------------------- Fonts ------------------------------ + +static void AdjustFont P((int n)); + +static int +FontsOK (int n) +{ + extern Option historyOptions[], engoutOptions[], gamesOptions[]; + int i; + ApplyFont(&mainOptions[W_WHITE], appData.clockFont); + ApplyFont(&mainOptions[W_BLACK], appData.clockFont); + ApplyFont(&mainOptions[W_MESSG], NULL); + for(i=1; i<6; i++) ApplyFont(&mainOptions[W_BUTTON+i], NULL); + ApplyFont(&tagsOptions[1], NULL); + ApplyFont(&historyOptions[0], NULL); + ApplyFont(&engoutOptions[5], NULL); + ApplyFont(&engoutOptions[12], NULL); + ApplyFont(&gamesOptions[0], NULL); + DrawPosition(TRUE, NULL); // for coord font + return 1; +} + +static Option fontOptions[] = { + { 0, 0, 70, NULL, (void*) &appData.clockFont, "", NULL, TextBox, N_("Clocks:") }, + { 1, SAME_ROW, 0, NULL, (void*) &AdjustFont, NULL, NULL, Button, N_("+") }, + { 2, SAME_ROW, 0, NULL, (void*) &AdjustFont, NULL, NULL, Button, N_("-") }, + { 3, SAME_ROW, 0, NULL, (void*) &AdjustFont, NULL, NULL, Button, N_("B") }, + { 4, SAME_ROW, 0, NULL, (void*) &AdjustFont, NULL, NULL, Button, N_("I") }, + { 0, 0, 70, NULL, (void*) &appData.font, "", NULL, TextBox, N_("Message (above board):") }, + { 1, SAME_ROW, 0, NULL, (void*) &AdjustFont, NULL, NULL, Button, N_("+") }, + { 2, SAME_ROW, 0, NULL, (void*) &AdjustFont, NULL, NULL, Button, N_("-") }, + { 3, SAME_ROW, 0, NULL, (void*) &AdjustFont, NULL, NULL, Button, N_("B") }, + { 4, SAME_ROW, 0, NULL, (void*) &AdjustFont, NULL, NULL, Button, N_("I") }, + { 0, 0, 70, NULL, (void*) &appData.coordFont, "", NULL, TextBox, N_("Board coordinates:") }, + { 1, SAME_ROW, 0, NULL, (void*) &AdjustFont, NULL, NULL, Button, N_("+") }, + { 2, SAME_ROW, 0, NULL, (void*) &AdjustFont, NULL, NULL, Button, N_("-") }, + { 3, SAME_ROW, 0, NULL, (void*) &AdjustFont, NULL, NULL, Button, N_("B") }, + { 4, SAME_ROW, 0, NULL, (void*) &AdjustFont, NULL, NULL, Button, N_("I") }, + { 0, 0, 70, NULL, (void*) &appData.tagsFont, "", NULL, TextBox, N_("Edit tags / book / engine list:") }, + { 1, SAME_ROW, 0, NULL, (void*) &AdjustFont, NULL, NULL, Button, N_("+") }, + { 2, SAME_ROW, 0, NULL, (void*) &AdjustFont, NULL, NULL, Button, N_("-") }, + { 3, SAME_ROW, 0, NULL, (void*) &AdjustFont, NULL, NULL, Button, N_("B") }, + { 4, SAME_ROW, 0, NULL, (void*) &AdjustFont, NULL, NULL, Button, N_("I") }, + { 0, 0, 70, NULL, (void*) &appData.commentFont, "", NULL, TextBox, N_("Edit comments:") }, + { 1, SAME_ROW, 0, NULL, (void*) &AdjustFont, NULL, NULL, Button, N_("+") }, + { 2, SAME_ROW, 0, NULL, (void*) &AdjustFont, NULL, NULL, Button, N_("-") }, + { 3, SAME_ROW, 0, NULL, (void*) &AdjustFont, NULL, NULL, Button, N_("B") }, + { 4, SAME_ROW, 0, NULL, (void*) &AdjustFont, NULL, NULL, Button, N_("I") }, + { 0, 0, 70, NULL, (void*) &appData.historyFont, "", NULL, TextBox, N_("Move history / Engine Output:") }, + { 1, SAME_ROW, 0, NULL, (void*) &AdjustFont, NULL, NULL, Button, N_("+") }, + { 2, SAME_ROW, 0, NULL, (void*) &AdjustFont, NULL, NULL, Button, N_("-") }, + { 3, SAME_ROW, 0, NULL, (void*) &AdjustFont, NULL, NULL, Button, N_("B") }, + { 4, SAME_ROW, 0, NULL, (void*) &AdjustFont, NULL, NULL, Button, N_("I") }, + { 0, 0, 70, NULL, (void*) &appData.gameListFont, "", NULL, TextBox, N_("Game list:") }, + { 1, SAME_ROW, 0, NULL, (void*) &AdjustFont, NULL, NULL, Button, N_("+") }, + { 2, SAME_ROW, 0, NULL, (void*) &AdjustFont, NULL, NULL, Button, N_("-") }, + { 3, SAME_ROW, 0, NULL, (void*) &AdjustFont, NULL, NULL, Button, N_("B") }, + { 4, SAME_ROW, 0, NULL, (void*) &AdjustFont, NULL, NULL, Button, N_("I") }, + { 0, 0, 0, NULL, NULL, NULL, NULL, Label, N_("Generic type-face names are Sans, Monospace and Serif") }, + { 0, 0, 0, NULL, (void*) &FontsOK, "", NULL, EndMark , "" } +}; + +static char name[MSG_SIZ], *bold, *ital, points; + +static void +BreakUp (char *font) +{ + char *p = name; + safeStrCpy(name, font, MSG_SIZ); + bold = StrCaseStr(name, "bold"); + ital = StrCaseStr(name, "ital"); + points = 0; + while(p && *p && !(points = atoi(p))) p = strchr(p+1, ' '); + if(points) p[*p == ' '] = 0; + if(bold) *bold = 0; + if(ital) *ital = 0; +} + +static void +Collect () +{ + if(bold) strcat(name, "Bold "); + if(ital) strcat(name, "Italic "); + if(points) sprintf(name + strlen(name), " %d", points); else strcat(name, "%d"); +} + +static void +AdjustFont (int n) +{ + int button = fontOptions[n].value, base = n - button; + char *oldFont; + GetWidgetText(&fontOptions[base], &oldFont); + BreakUp(oldFont); // take apart old font name + switch(button) { + case 1: points++; break; + case 2: points--; break; + case 3: if(bold) bold = NULL; else bold = name; break; + case 4: if(ital) ital = NULL; else ital = name; break; + } + Collect(); + SetWidgetText(&fontOptions[base], name, TransientDlg); +// ApplyFont(&fontOptions[base], name); +} + +void +FontsProc () +{ + int i; + GenericPopUp(fontOptions, _("Fonts"), TransientDlg, BoardWindow, MODAL, 0); +// for(i=0; i<6; i++) ApplyFont(&fontOptions[5*i], *(char**)fontOptions[5*i].target); +} + //------------------------------------------------------ Time Control ----------------------------------- static int TcOK P((int n)); diff --git a/gtk/xoptions.c b/gtk/xoptions.c index 0424147..4f68db7 100644 --- a/gtk/xoptions.c +++ b/gtk/xoptions.c @@ -270,6 +270,23 @@ SetWidgetFont (GtkWidget *w, char **s) } void +ApplyFont (Option *opt, char *font) +{ + GtkWidget *w = NULL; + if(!font && opt->font) font = *opt->font; + if(!font) return; + switch(opt->type) { + case ListBox: + case Label: w = opt->handle; break; + case Button: if(opt->handle) w = gtk_bin_get_child(GTK_BIN(opt->handle)); break; + case TextBox: w = opt->textValue; break; + default: ; + } +printf("set font %s\n", font); + if(w && font) SetWidgetFont(w, &font); +} + +void SetListBoxItem (GtkListStore *store, int n, char *msg) { GtkTreeIter iter; diff --git a/menus.c b/menus.c index 71f9ae0..af8e33d 100644 --- a/menus.c +++ b/menus.c @@ -651,6 +651,7 @@ MenuItem viewMenu[] = { {N_("ICS/Chat Console"), NULL, "OpenChatWindow", ChatProc, CHECK}, {"----", NULL, NULL, NothingProc}, {N_("Board..."), NULL, "Board", BoardOptionsProc}, + {N_("Fonts..."), NULL, "Fonts", FontsProc}, {N_("Game List Tags..."), NULL, "GameListTags", GameListOptionsProc}, {NULL, NULL, NULL, NULL} }; diff --git a/menus.h b/menus.h index be19f6c..b088cc7 100644 --- a/menus.h +++ b/menus.h @@ -162,6 +162,7 @@ void SaveOptionsProc P((void)); void SaveSettings P((char *)); void EditBookProc P((void)); void InitMenuMarkers P((void)); +void FontsProc P((void)); void ShowGameListProc P((void)); // in ngamelist.c void HistoryShowProc P((void)); // in nhistory.c diff --git a/ngamelist.c b/ngamelist.c index 1004a92..3d2b417 100644 --- a/ngamelist.c +++ b/ngamelist.c @@ -81,7 +81,7 @@ static int GameListPrepare P((int byPos, int narrow)); static void GameListReplace P((int page)); static void GL_Button P((int n)); -static Option gamesOptions[] = { +Option gamesOptions[] = { { 200, LR|TB, 400, NULL, (void*) list, NULL, NULL, ListBox, "", &appData.gameListFont }, { 0, 0, 100, NULL, (void*) &filterPtr, "", NULL, TextBox, "" }, { 4, SAME_ROW, 0, NULL, (void*) &GL_Button, NULL, NULL, Button, N_("find position") }, -- 1.7.0.4