From 95bcf4c69c5c7c40bcecdf5624ca622a9373701e Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Tue, 18 Feb 2014 22:37:31 +0100 Subject: [PATCH] Equip Board Options dialog with themes listbox The option -themeNames is made persistent for XBoard, and its value is displayed in a listbox added to the View -> Board dialog. The user can select themes from this, and manipulate the contents similar to the engine list in Load Engine. A textedit allows the user to define a theme name for the current settings, and doing so adds the theme to the -themeNames list. --- args.h | 2 +- dialogs.c | 60 ++++++++++++++++++++++++++++++++++++++++++++------------- gtk/xboard.c | 6 +++++ xaw/xboard.c | 6 +++++ 4 files changed, 59 insertions(+), 15 deletions(-) diff --git a/args.h b/args.h index cea60f1..48cb3d7 100644 --- a/args.h +++ b/args.h @@ -512,7 +512,7 @@ ArgDescriptor argDescriptors[] = { TRUE, (ArgIniType) FCP_NAMES }, { "secondChessProgramNames", ArgString, (void *) &secondChessProgramNames, !XBOARD, (ArgIniType) SCP_NAMES }, - { "themeNames", ArgString, (void *) &appData.themeNames, !XBOARD, (ArgIniType) "native -upf false -ub false -ubt false -pid \"\"\n" }, + { "themeNames", ArgString, (void *) &appData.themeNames, TRUE, (ArgIniType) "native -upf false -ub false -ubt false -pid \"\"\n" }, { "addMasterOption", ArgMaster, NULL, FALSE, INVALID }, { "installEngine", ArgInstall, (void *) &firstChessProgramNames, FALSE, (ArgIniType) "" }, { "initialMode", ArgString, (void *) &appData.initialMode, FALSE, (ArgIniType) "" }, diff --git a/dialogs.c b/dialogs.c index 9c7a28a..df53d8a 100644 --- a/dialogs.c +++ b/dialogs.c @@ -846,20 +846,20 @@ SoundOptionsProc () static void DefColor P((int n)); static void AdjustColor P((int i)); +static void ThemeSel P((int n, int sel)); +static int BoardOptionsOK P((int n)); static char oldPieceDir[MSG_SIZ]; +extern char *engineLine, *nickName; // defined later on -static int -BoardOptionsOK (int n) -{ - if(appData.overrideLineGap >= 0) lineGap = appData.overrideLineGap; else lineGap = defaultLineGap; - InitDrawingParams(strcmp(oldPieceDir, appData.pieceDirectory)); - InitDrawingSizes(-1, 0); - DrawPosition(True, NULL); - return 1; -} +#define THEMELIST 1 static Option boardOptions[] = { +{ 0,LR|T2T, 0, NULL, NULL, NULL, NULL, Label, N_("Selectable themes:") }, +{ 300,LR|TB,200, NULL, (void*) engineMnemonic, (char*) &ThemeSel, NULL, ListBox, "" }, +{ 0,LR|T2T, 0, NULL, NULL, NULL, NULL, Label, N_("New name for current theme:") }, +{ 0, 0, 0, NULL, (void*) &nickName, ".png", NULL, TextBox, "" }, +{ 0,SAME_ROW, 0, NULL, NULL, NULL, NULL, Break, NULL }, { 0, 0, 70, NULL, (void*) &appData.whitePieceColor, "", NULL, TextBox, N_("White Piece Color:") }, { 1000, SAME_ROW, 0, NULL, (void*) &DefColor, NULL, (char**) "#FFFFCC", Button, " " }, /* TRANSLATORS: R = single letter for the color red */ @@ -913,6 +913,16 @@ static Option boardOptions[] = { { 0, 0, 0, NULL, (void*) &BoardOptionsOK, "", NULL, EndMark , "" } }; +static int +BoardOptionsOK (int n) +{ + if(n && (n = SelectedListBoxItem(&boardOptions[THEMELIST])) > 0 && *engineList[n] != '#') { // called by pressing OK, and theme selected + ASSIGN(engineLine, engineList[n]); + } + LoadTheme(); + return 1; +} + static void SetColorText (int n, char *buf) { @@ -956,9 +966,32 @@ AdjustColor (int i) } void +ThemeSel (int n, int sel) +{ + int nr; + char buf[MSG_SIZ]; + if(sel < 1) buf[0] = NULLCHAR; // back to top level + else if(engineList[sel][0] == '#') safeStrCpy(buf, engineList[sel], MSG_SIZ); // group header, open group + else { // normal line, select engine + ASSIGN(engineLine, engineList[sel]); + LoadTheme(); + PopDown(TransientDlg); + return; + } + nr = NamesToList(appData.themeNames, engineList, engineMnemonic, buf); // replace list by only the group contents + ASSIGN(engineMnemonic[0], buf); + LoadListBox(&boardOptions[THEMELIST], _("# no themes are defined"), -1, -1); + HighlightWithScroll(&boardOptions[THEMELIST], 0, nr); +} + +void BoardOptionsProc () { strncpy(oldPieceDir, appData.pieceDirectory, MSG_SIZ-1); // to see if it changed + ASSIGN(engineLine, ""); + ASSIGN(nickName, ""); + ASSIGN(engineMnemonic[0], ""); + NamesToList(appData.themeNames, engineList, engineMnemonic, ""); GenericPopUp(boardOptions, _("Board Options"), TransientDlg, BoardWindow, MODAL, 0); } @@ -2886,10 +2919,9 @@ FileNamePopUp (char *label, char *def, char *filter, FileProc proc, char *openMo void ActivateTheme (int col) { + if(appData.overrideLineGap >= 0) lineGap = appData.overrideLineGap; else lineGap = defaultLineGap; + InitDrawingParams(strcmp(oldPieceDir, appData.pieceDirectory)); + InitDrawingSizes(-1, 0); + DrawPosition(True, NULL); } -char * -Col2Text (int n) -{ - return NULL; -} diff --git a/gtk/xboard.c b/gtk/xboard.c index 8537eaf..60cbe0a 100644 --- a/gtk/xboard.c +++ b/gtk/xboard.c @@ -425,6 +425,12 @@ ParseColor (int n, char *name) if(colorVariable[n]) *(char**)colorVariable[n] = strdup(name); } +char * +Col2Text (int n) +{ + return *(char**)colorVariable[n]; +} + void ParseTextAttribs (ColorClass cc, char *s) { diff --git a/xaw/xboard.c b/xaw/xboard.c index a944313..d6a9dae 100644 --- a/xaw/xboard.c +++ b/xaw/xboard.c @@ -537,6 +537,12 @@ ParseColor (int n, char *name) if(colorVariable[n]) *(char**)colorVariable[n] = strdup(name); } +char * +Col2Text (int n) +{ + return *(char**)colorVariable[n]; +} + void ParseTextAttribs (ColorClass cc, char *s) { -- 1.7.0.4