From: H.G. Muller Date: Thu, 18 Aug 2011 08:29:35 +0000 (+0200) Subject: Add -useBoardTexture and -usePieceFont options X-Git-Url: http://winboard.nl/cgi-bin?p=xboard.git;a=commitdiff_plain;h=c69beebf3decbe67eb92beab56bbc34c41c39831 Add -useBoardTexture and -usePieceFont options These options suppress the use of the given texture files or piece fonts without relying on the kludge to disable them by prefixing an asterisk to the file or font name. Checkboxes have been added to the Board dialog to control them. The user can now set piece font in WB font dialog. The sample text can be used to specify the -fontPieceToCharTable, the font name itself the -renderPiecesWithFont value. --- diff --git a/args.h b/args.h index 858ee44..32350ba 100644 --- a/args.h +++ b/args.h @@ -563,6 +563,8 @@ ArgDescriptor argDescriptors[] = { { "defaultPathEGTB", ArgFilename, (void *) &appData.defaultPathEGTB, TRUE, (ArgIniType) "c:\\egtb" }, { "language", ArgFilename, (void *) &appData.language, TRUE, (ArgIniType) "" }, { "userFileDirectory", ArgFilename, (void *) &homeDir, FALSE, (ArgIniType) installDir }, + { "usePieceFont", ArgBoolean, (void *) &appData.useFont, TRUE, (ArgIniType) FALSE }, + { "useBoardTexture", ArgBoolean, (void *) &appData.useBitmaps, TRUE, (ArgIniType) FALSE }, // [HGM] tournament options { "tourneyFile", ArgFilename, (void *) &appData.tourneyFile, FALSE, (ArgIniType) "" }, diff --git a/common.h b/common.h index 08d45e5..5f8f5f1 100644 --- a/common.h +++ b/common.h @@ -533,6 +533,8 @@ typedef struct { Boolean scoreIsAbsolute[ENGINES]; /* If true, engine score is always from white side */ Boolean saveExtendedInfoInPGN; /* If true, saved PGN games contain extended info */ Boolean hideThinkingFromHuman; /* If true, program thinking is generated but not displayed in human/computer matches */ + Boolean useBitmaps; + Boolean useFont; char * liteBackTextureFile; /* Name of texture bitmap for lite squares */ char * darkBackTextureFile; /* Name of texture bitmap for dark squares */ int liteBackTextureMode; diff --git a/winboard/resource.h b/winboard/resource.h index f124467..d1d0e9a 100644 --- a/winboard/resource.h +++ b/winboard/resource.h @@ -612,6 +612,11 @@ #define OPT_Subset 1966 #define OPT_Struct 1967 #define OPT_Material 1968 +#define OPT_Bitmaps 1976 +#define OPT_PieceFont 1977 +#define OPT_MessageFont8 1978 +#define OPT_SamplePieceFont 1979 +#define OPT_ChoosePieceFont 1980 // Next default values for new objects diff --git a/winboard/winboard.c b/winboard/winboard.c index e2ba141..0abb7e6 100644 --- a/winboard/winboard.c +++ b/winboard/winboard.c @@ -249,11 +249,11 @@ Boolean barbaric; // flag indicating if translation is needed #define ABOUTBOX -1 /* not sure why these are needed */ #define ABOUTBOX2 -1 -int dialogItems[][40] = { +int dialogItems[][41 ] = { { ABOUTBOX, IDOK, OPT_MESS, 400 }, { DLG_TimeControl, IDC_Babble, OPT_TCUseMoves, OPT_TCUseInc, OPT_TCUseFixed, OPT_TCtext1, OPT_TCtext2, OPT_TCitext1, OPT_TCitext2, OPT_TCftext, GPB_Factors, IDC_Factor1, IDC_Factor2, IDOK, IDCANCEL }, -{ DLG_LoadOptions, OPT_Autostep, OPT_AStext1, IDOK, IDCANCEL }, +{ DLG_LoadOptions, OPT_Autostep, OPT_AStext1, IDOK, IDCANCEL }, { DLG_SaveOptions, OPT_Autosave, OPT_AVPrompt, OPT_AVToFile, OPT_AVBrowse, 801, OPT_PGN, OPT_Old, OPT_OutOfBookInfo, IDOK, IDCANCEL }, { 1536, 1090, IDC_Directories, 1089, 1091, IDOK, IDCANCEL, 1038, IDC_IndexNr, 1037 }, @@ -301,7 +301,7 @@ int dialogItems[][40] = { OPT_ChooseLightSquareColor, OPT_ChooseDarkSquareColor, OPT_ChooseWhitePieceColor, OPT_ChooseBlackPieceColor, OPT_ChooseHighlightSquareColor, OPT_ChoosePremoveHighlightColor, OPT_Monochrome, OPT_AllWhite, OPT_UpsideDown, OPT_DefaultBoardColors, GPB_Colors, - IDC_Light, IDC_Dark, IDC_White, IDC_Black, IDC_High, IDC_PreHigh, GPB_Size }, + IDC_Light, IDC_Dark, IDC_White, IDC_Black, IDC_High, IDC_PreHigh, GPB_Size, OPT_Bitmaps, OPT_PieceFont }, { DLG_NewVariant, IDOK, IDCANCEL, OPT_VariantNormal, OPT_VariantFRC, OPT_VariantWildcastle, OPT_VariantNocastle, OPT_VariantLosers, OPT_VariantGiveaway, OPT_VariantSuicide, OPT_Variant3Check, OPT_VariantTwoKings, OPT_VariantAtomic, OPT_VariantCrazyhouse, @@ -313,7 +313,7 @@ int dialogItems[][40] = { IDC_Width, IDC_Hand, IDC_Pieces, IDC_Def }, { DLG_Fonts, IDOK, IDCANCEL, OPT_ChooseClockFont, OPT_ChooseMessageFont, OPT_ChooseCoordFont, OPT_ChooseTagFont, OPT_ChooseCommentsFont, OPT_ChooseConsoleFont, OPT_ChooseMoveHistoryFont, OPT_DefaultFonts, - OPT_ClockFont, OPT_MessageFont, OPT_CoordFont, OPT_EditTagsFont, + OPT_ClockFont, OPT_MessageFont, OPT_CoordFont, OPT_EditTagsFont, OPT_ChoosePieceFont, OPT_MessageFont8, OPT_SampleGameListFont, OPT_ChooseGameListFont, OPT_MessageFont7, OPT_CommentsFont, OPT_MessageFont5, GPB_Current, GPB_All, OPT_MessageFont6 }, { DLG_NewGameFRC, IDC_NFG_Label, IDC_NFG_Random, IDOK, IDCANCEL }, @@ -984,6 +984,31 @@ LoadLogo(ChessProgramState *cps, int n, Boolean ics) SetCurrentDirectory(dir); /* return to prev directory */ } +VOID +InitTextures() +{ + ZeroMemory( &backTextureSquareInfo, sizeof(backTextureSquareInfo) ); + backTextureSquareSize = 0; // kludge to force recalculation of texturemode + + if( appData.liteBackTextureFile && appData.liteBackTextureFile[0] != NULLCHAR && appData.liteBackTextureFile[0] != '*' ) { + liteBackTexture = LoadImage( 0, appData.liteBackTextureFile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE ); + liteBackTextureMode = appData.liteBackTextureMode; + + if (liteBackTexture == NULL && appData.debugMode) { + fprintf( debugFP, "Unable to load lite texture bitmap '%s'\n", appData.liteBackTextureFile ); + } + } + + if( appData.darkBackTextureFile && appData.darkBackTextureFile[0] != NULLCHAR && appData.darkBackTextureFile[0] != '*' ) { + darkBackTexture = LoadImage( 0, appData.darkBackTextureFile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE ); + darkBackTextureMode = appData.darkBackTextureMode; + + if (darkBackTexture == NULL && appData.debugMode) { + fprintf( debugFP, "Unable to load dark texture bitmap '%s'\n", appData.darkBackTextureFile ); + } + } +} + BOOL InitInstance(HINSTANCE hInstance, int nCmdShow, LPSTR lpCmdLine) { @@ -1067,25 +1092,7 @@ InitInstance(HINSTANCE hInstance, int nCmdShow, LPSTR lpCmdLine) buttonCount = GetSystemMetrics(SM_CMOUSEBUTTONS); /* [AS] Load textures if specified */ - ZeroMemory( &backTextureSquareInfo, sizeof(backTextureSquareInfo) ); - - if( appData.liteBackTextureFile && appData.liteBackTextureFile[0] != NULLCHAR && appData.liteBackTextureFile[0] != '*' ) { - liteBackTexture = LoadImage( 0, appData.liteBackTextureFile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE ); - liteBackTextureMode = appData.liteBackTextureMode; - - if (liteBackTexture == NULL && appData.debugMode) { - fprintf( debugFP, "Unable to load lite texture bitmap '%s'\n", appData.liteBackTextureFile ); - } - } - - if( appData.darkBackTextureFile && appData.darkBackTextureFile[0] != NULLCHAR && appData.darkBackTextureFile[0] != '*' ) { - darkBackTexture = LoadImage( 0, appData.darkBackTextureFile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE ); - darkBackTextureMode = appData.darkBackTextureMode; - - if (darkBackTexture == NULL && appData.debugMode) { - fprintf( debugFP, "Unable to load dark texture bitmap '%s'\n", appData.darkBackTextureFile ); - } - } + InitTextures(); mysrandom( (unsigned) time(NULL) ); @@ -1973,7 +1980,8 @@ void CreatePiecesFromFont() return; } - if( appData.renderPiecesWithFont == NULL || appData.renderPiecesWithFont[0] == NULLCHAR || appData.renderPiecesWithFont[0] == '*' ) { + if( !appData.useFont || appData.renderPiecesWithFont == NULL || + appData.renderPiecesWithFont[0] == NULLCHAR || appData.renderPiecesWithFont[0] == '*' ) { fontBitmapSquareSize = -1; return; } @@ -3322,7 +3330,7 @@ DrawBoardOnDC(HDC hdc, Board board, HDC tmphdc) DrawPieceOnDC(hdc, piece, piece_color, square_color, x, y, tmphdc); } } - else if( backTextureSquareInfo[row][column].mode > 0 ) { + else if( appData.useBitmaps && backTextureSquareInfo[row][column].mode > 0 ) { /* [AS] Draw the square using a texture bitmap */ HBITMAP hbm = SelectObject( texture_hdc, square_color ? liteBackTexture : darkBackTexture ); int r = row, c = column; // [HGM] do not flip board in flipView diff --git a/winboard/winboard.rc b/winboard/winboard.rc index 29b1f91..ee9c2a1 100644 --- a/winboard/winboard.rc +++ b/winboard/winboard.rc @@ -630,9 +630,13 @@ BEGIN CONTROL "Monochrome",OPT_Monochrome,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,210,64,10 CONTROL "All White",OPT_AllWhite,"Button",BS_AUTOCHECKBOX | - WS_TABSTOP,140,180,73,10 + WS_TABSTOP,140,179,73,10 CONTROL "Flip Black",OPT_UpsideDown,"Button",BS_AUTOCHECKBOX | - WS_TABSTOP,140,192,73,10 + WS_TABSTOP,140,191,73,10 + CONTROL "Use Board Textures",OPT_Bitmaps,"Button",BS_AUTOCHECKBOX | + WS_TABSTOP,140,203,73,10 + CONTROL "Use Piece Font",OPT_PieceFont,"Button",BS_AUTOCHECKBOX | + WS_TABSTOP,140,215,73,10 PUSHBUTTON "Defaults",OPT_DefaultBoardColors,80,206,50,15 EDITTEXT OPT_DarkSquareColor,80,112,25,15,ES_READONLY | WS_DISABLED | NOT WS_BORDER | NOT WS_TABSTOP @@ -743,13 +747,13 @@ BEGIN PUSHBUTTON "Cancel",IDCANCEL,170,232,50,14 END -DLG_Fonts DIALOG DISCARDABLE 0, 0, 266, 250 +DLG_Fonts DIALOG DISCARDABLE 0, 0, 266, 274 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Fonts" FONT 8, "MS Sans Serif" BEGIN - DEFPUSHBUTTON "OK",IDOK,156,232,50,14 - PUSHBUTTON "Cancel",IDCANCEL,212,232,50,14 + DEFPUSHBUTTON "OK",IDOK,156,256,50,14 + PUSHBUTTON "Cancel",IDCANCEL,212,256,50,14 PUSHBUTTON "Choose...",OPT_ChooseClockFont,212,15,45,15 PUSHBUTTON "Choose...",OPT_ChooseMessageFont,212,39,45,15 PUSHBUTTON "Choose...",OPT_ChooseCoordFont,212,63,45,15 @@ -758,7 +762,8 @@ BEGIN PUSHBUTTON "Choose...",OPT_ChooseConsoleFont,212,149,45,15 PUSHBUTTON "Choose...",OPT_ChooseMoveHistoryFont,212,174,45,15 PUSHBUTTON "Choose...",OPT_ChooseGameListFont,212,198,45,15 - PUSHBUTTON "&Defaults",OPT_DefaultFonts,3,232,50,15 + PUSHBUTTON "Choose...",OPT_ChoosePieceFont,212,222,45,15 + PUSHBUTTON "&Defaults",OPT_DefaultFonts,3,256,50,15 CONTROL "",OPT_SampleCoordFont,"RICHEDIT",ES_READONLY | WS_DISABLED | WS_BORDER,77,59,130,20 CONTROL "",OPT_SampleTagFont,"RICHEDIT",ES_READONLY | @@ -779,7 +784,7 @@ BEGIN CONTROL "",OPT_SampleMessageFont,"RICHEDIT",ES_READONLY | WS_DISABLED | WS_BORDER,77,35,130,20 GROUPBOX "Current Board Size",GPB_Current,3,1,259,83 - GROUPBOX "All Board Sizes",GPB_All,3,87,259,133 + GROUPBOX "All Board Sizes",GPB_All,3,87,259,157 CONTROL "",OPT_SampleMoveHistoryFont,"RICHEDIT",ES_READONLY | WS_DISABLED | WS_BORDER,77,170,130,20 LTEXT "Move History, Engine Output",OPT_MessageFont6,13,171,63,20,NOT @@ -788,6 +793,10 @@ BEGIN WS_DISABLED | WS_BORDER,77,194,130,20 LTEXT "Game List",OPT_MessageFont7,13,199,63,20,NOT WS_GROUP + CONTROL "",OPT_SamplePieceFont,"RICHEDIT", ES_AUTOHSCROLL | + WS_BORDER,77,218,130,20 + LTEXT "Piece Font",OPT_MessageFont8,13,223,63,20,NOT + WS_GROUP END DLG_NewGameFRC DIALOG DISCARDABLE 0, 0, 176, 47 diff --git a/winboard/woptions.c b/winboard/woptions.c index 94da5b8..d00d4f0 100644 --- a/winboard/woptions.c +++ b/winboard/woptions.c @@ -516,7 +516,7 @@ BoardOptionsWhichRadio(HWND hDlg) LRESULT CALLBACK BoardOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { - static Boolean mono, white, flip; + static Boolean mono, white, flip, fonts, bitmaps; static BoardSize size; static COLORREF lsc, dsc, wpc, bpc, hsc, phc; static HBITMAP pieces[3]; @@ -593,6 +593,12 @@ BoardOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) if (appData.upsideDown) CheckDlgButton(hDlg, OPT_UpsideDown, TRUE); + if (appData.useBitmaps) + CheckDlgButton(hDlg, OPT_Bitmaps, TRUE); + + if (appData.useFont) + CheckDlgButton(hDlg, OPT_PieceFont, TRUE); + pieces[0] = DoLoadBitmap(hInst, "n", SAMPLE_SQ_SIZE, "s"); pieces[1] = DoLoadBitmap(hInst, "n", SAMPLE_SQ_SIZE, "w"); pieces[2] = DoLoadBitmap(hInst, "n", SAMPLE_SQ_SIZE, "o"); @@ -607,6 +613,8 @@ BoardOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) white= appData.allWhite; flip = appData.upsideDown; size = boardSize; + bitmaps = appData.useBitmaps; + fonts = appData.useFont; SetBoardOptionEnables(hDlg); return TRUE; @@ -644,6 +652,8 @@ BoardOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) ChangeBoardSize(size); } + if (bitmaps && !appData.useBitmaps) InitTextures(); + if ((mono != appData.monoMode) || (lsc != lightSquareColor) || (dsc != darkSquareColor) || @@ -652,6 +662,8 @@ BoardOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) (hsc != highlightSquareColor) || (flip != appData.upsideDown) || (white != appData.allWhite) || + (fonts != appData.useFont) || + (bitmaps != appData.useBitmaps) || (phc != premoveHighlightColor)) { lightSquareColor = lsc; @@ -663,6 +675,8 @@ BoardOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) appData.monoMode = mono; appData.allWhite = white; appData.upsideDown = flip; + appData.useFont = fonts; + appData.useBitmaps = bitmaps; InitDrawingColors(); InitDrawingSizes(boardSize, 0); @@ -755,12 +769,18 @@ BoardOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) case OPT_AllWhite: white = !white; - SetBoardOptionEnables(hDlg); break; case OPT_UpsideDown: flip = !flip; - SetBoardOptionEnables(hDlg); + break; + + case OPT_Bitmaps: + bitmaps = !bitmaps; + break; + + case OPT_PieceFont: + fonts = !fonts; break; } break; @@ -1434,6 +1454,8 @@ IcsOptionsPopup(HWND hwnd) * \*---------------------------------------------------------------------------*/ +char *string; // sorry + VOID SetSampleFontText(HWND hwnd, int id, const MyFont *mf) { @@ -1451,7 +1473,9 @@ SetSampleFontText(HWND hwnd, int id, const MyFont *mf) mf->mfp.pointSize, mf->mfp.faceName, mf->mfp.bold ? " bold" : "", mf->mfp.italic ? " italic" : ""); + if(id != OPT_SamplePieceFont) SetDlgItemText(hwnd, id, buf); + else SetDlgItemText(hwnd, id, string); hControl = GetDlgItem(hwnd, id); hdc = GetDC(hControl); @@ -1488,6 +1512,7 @@ SetSampleFontText(HWND hwnd, int id, const MyFont *mf) /* format the text in the rich edit control */ SendMessage(hControl, EM_SETCHARFORMAT, SCF_ALL, (LPARAM) &cf); + if(id != OPT_SamplePieceFont) SendMessage(hControl, EM_SETRECT, (WPARAM)0, (LPARAM) &rectFormat); /* clean up */ @@ -1512,8 +1537,9 @@ CopyFont(MyFont *dest, const MyFont *src) LRESULT CALLBACK FontOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { - static MyFont workFont[NUM_FONTS]; + static MyFont workFont[NUM_FONTS+1]; static BOOL firstPaint; + static char pieceText[] = "ABCDEFGHIJKLMNOPQRSTUVWXZabcdefghijklmnopqrstuvwxyz"; int i; RECT rect; @@ -1523,6 +1549,9 @@ FontOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) /* copy the current font settings into a working copy */ for (i=0; i < NUM_FONTS; i++) CopyFont(&workFont[i], font[boardSize][i]); + strncpy(workFont[NUM_FONTS].mfp.faceName, appData.renderPiecesWithFont, sizeof(workFont[NUM_FONTS].mfp.faceName)); + workFont[NUM_FONTS].mfp.pointSize = 16.; + workFont[NUM_FONTS].mfp.charset = DEFAULT_CHARSET; Translate(hDlg, DLG_Fonts); if (!appData.icsActive) @@ -1552,6 +1581,8 @@ FontOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) SetSampleFontText(hDlg, OPT_SampleConsoleFont, &workFont[CONSOLE_FONT]); SetSampleFontText(hDlg, OPT_SampleMoveHistoryFont, &workFont[MOVEHISTORY_FONT]); SetSampleFontText(hDlg, OPT_SampleGameListFont, &workFont[GAMELIST_FONT]); + string = appData.fontToPieceTable; + SetSampleFontText(hDlg, OPT_SamplePieceFont, &workFont[NUM_FONTS]); firstPaint = FALSE; } break; @@ -1567,6 +1598,13 @@ FontOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) for (i=0; i < NUM_FONTS; i++) CopyFont(font[boardSize][i], &workFont[i]); + { // Make new piece-to-char table + char buf[MSG_SIZ]; + GetDlgItemText(hDlg, OPT_SamplePieceFont, buf, MSG_SIZ); + ASSIGN(appData.fontToPieceTable, buf); + } + ASSIGN(appData.renderPiecesWithFont, workFont[NUM_FONTS].mfp.faceName); // piece font + /* a sad necessity due to the original design of having a separate * console font, tags font, and comment font for each board size. IMHO * these fonts should not be dependent on the current board size. I'm @@ -1675,6 +1713,12 @@ FontOptionsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) SetSampleFontText(hDlg, OPT_SampleGameListFont, &workFont[GAMELIST_FONT]); break; + case OPT_ChoosePieceFont: + MyCreateFont(hDlg, &workFont[NUM_FONTS]); + string = pieceText; + SetSampleFontText(hDlg, OPT_SamplePieceFont, &workFont[NUM_FONTS]); + break; + case OPT_DefaultFonts: for (i=0; i